Ejemplo n.º 1
0
Archivo: cam.c Proyecto: BotBot/ASV
CDevice* camEnumDevices() {
  CDevice* devices;
  unsigned int size = sizeof(CDevice)*camMAX_DEVICES, count = camMAX_DEVICES;
  check(c_enum_devices(camDevices,&size,&count));
  camNumDevices = count;
  return camDevices;
}
Ejemplo n.º 2
0
static CResult
list_devices ()
{
	CResult ret;
	unsigned int req_size = 0, buffer_size = 0, count = 0;
	CDevice *devices = NULL;
	int i;

	printf("Listing available devices:\n");

	do {
		// Allocate the required memory
		if(devices) free(devices);
		if(req_size) {		// No allocation the first time
			devices = (CDevice *)malloc(req_size);
			if(devices == NULL)
				return C_NO_MEMORY;
			buffer_size = req_size;
		}

		// Try to enumerate. If the buffer is not large enough, the required
		// size is returned.
		ret = c_enum_devices(devices, &req_size, &count);
		if(ret != C_SUCCESS && ret != C_BUFFER_TOO_SMALL)
			goto done;
	}
	while(buffer_size < req_size);

	if(count == 0) {
		printf("No devices found.\n");
		goto done;
	}

	// Print a list of all available devices
	for(i = 0; i < count; i++) {
		CDevice *device = &devices[i];
		print_device(device);

		ret = list_entities(device);
		if(ret != C_SUCCESS && ret != C_INVALID_ARG) {
			print_error("Unable to list device entities", ret);
			ret = C_SUCCESS;
		}
	}

done:
	if(devices) free(devices);
	if(ret)
		print_error("Unable to retrieve device list", ret);
	return ret;
}