示例#1
0
static inline void
build_device_list(int iscapture, char ***devs, int *count)
{
    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
    free_device_list(devs, count);
    SDL_EnumUnixAudioDevices(flags, 0, test_for_mmap, devs, count);
}
示例#2
0
/*
 * close v4l2 devices list
 * args:
 *   none
 *
 * asserts:
 *   vd->list_devices is not null
 *
 * returns: void
 */
void v4l2core_close_v4l2_device_list()
{
	free_device_list();
	
	if (my_device_list.udev)
		udev_unref(my_device_list.udev);
}
示例#3
0
cl_int compile_program(cl_uint *num_devices_out, const char *src,
                       size_t src_size, cl_platform_id platform,
                       cl_uint platform_idx) {
  cl_int err = CL_SUCCESS;

  // Get the device list
  cl_device_id* devices = NULL;
  cl_uint num_devices = 0;
  get_device_list(&devices, &num_devices, platform);
  *num_devices_out = num_devices;

  // Create context
  cl_context_properties ctx_properties[] = {
    CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 0
  };

  cl_context ctx = clCreateContext(ctx_properties, num_devices, devices, NULL,
                                   NULL, &err);
  if (err != CL_SUCCESS) {
    goto cleanup;
  }

  // Create program
  cl_program program = clCreateProgramWithSource(ctx, 1, &src, &src_size, &err);
  if (err != CL_SUCCESS) {
    goto cleanup;
  }

  // Compile program
  err = clBuildProgram(program, num_devices, devices, NULL, NULL, NULL);
  if (err != CL_SUCCESS) {
    goto cleanup_program;
  }

  // Write the binaries
  write_binaries(program, num_devices, platform_idx);

cleanup_program:
  // Free the built program
  clReleaseProgram(program);

cleanup:
  // Free the device list
  free_device_list(devices, num_devices);

  return err;
}
示例#4
0
static void
build_device_list(int iscapture, COREAUDIO_DeviceList ** devices,
                  int *devCount)
{
    OSStatus result = noErr;
    UInt32 size = 0;
    AudioObjectPropertyAddress propaddr;
    AudioObjectID *devs = NULL;
    UInt32 i = 0;
    UInt32 max = 0;

    free_device_list(devices, devCount);

    propaddr.mSelector = kAudioHardwarePropertyDevices;
    propaddr.mScope = kAudioObjectPropertyScopeGlobal;
    propaddr.mElement = kAudioObjectPropertyElementMaster;
    
    result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, NULL, &size);
    
    if (result != kAudioHardwareNoError)
        return;

    devs = (AudioDeviceID *) alloca(size);
    if (devs == NULL)
        return;

    max = size / sizeof(AudioDeviceID);
    *devices = (COREAUDIO_DeviceList *) SDL_malloc(max * sizeof(**devices));
    if (*devices == NULL)
        return;
    
    result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, NULL, &size, devs);
    if (result != kAudioHardwareNoError)
        return;

    for (i = 0; i < max; i++) {
        CFStringRef cfstr = NULL;
        char *ptr = NULL;
        AudioObjectID dev = devs[i];
        AudioBufferList *buflist = NULL;
        int usable = 0;
        CFIndex len = 0;
        
        propaddr.mSelector = kAudioDevicePropertyStreamConfiguration;
        propaddr.mScope = iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
        propaddr.mElement = kAudioObjectPropertyElementMaster;
        
        result = AudioObjectGetPropertyDataSize(dev, &propaddr, 0, NULL, &size);
        if (result != noErr)
            continue;

        buflist = (AudioBufferList *) SDL_malloc(size);
        if (buflist == NULL)
            continue;
        
        result = AudioObjectGetPropertyData(dev, &propaddr, 0, NULL, &size, buflist);

        if (result == noErr) {
            UInt32 j;
            for (j = 0; j < buflist->mNumberBuffers; j++) {
                if (buflist->mBuffers[j].mNumberChannels > 0) {
                    usable = 1;
                    break;
                }
            }
        }
        
        SDL_free(buflist);
        
        if (!usable)
            continue;
        
        size = sizeof(CFStringRef);
        propaddr.mSelector = kAudioDevicePropertyDeviceNameCFString;
        propaddr.mScope = iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
        propaddr.mElement = kAudioObjectPropertyElementMaster;
        
        result = AudioObjectGetPropertyData(dev, &propaddr, 0, NULL, &size, &cfstr);
        
        if (result != kAudioHardwareNoError)
            continue;

        len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr),
                                                kCFStringEncodingUTF8);

        ptr = (char *) SDL_malloc(len + 1);
        usable = ((ptr != NULL) &&
                  (CFStringGetCString
                   (cfstr, ptr, len + 1, kCFStringEncodingUTF8)));

        CFRelease(cfstr);

        if (usable) {
            len = strlen(ptr);
            /* Some devices have whitespace at the end...trim it. */
            while ((len > 0) && (ptr[len - 1] == ' ')) {
                len--;
            }
            usable = (len > 0);
        }

        if (!usable) {
            SDL_free(ptr);
        } else {
            ptr[len] = '\0';

#if DEBUG_COREAUDIO
            printf("COREAUDIO: Found %s device #%d: '%s' (devid %d)\n",
                   ((iscapture) ? "capture" : "output"),
                   (int) *devCount, ptr, (int) dev);
#endif

            (*devices)[*devCount].id = dev;
            (*devices)[*devCount].name = ptr;
            (*devCount)++;
        }
    }
}
示例#5
0
static inline void
free_device_lists(void)
{
    free_device_list(&outputDevices, &outputDeviceCount);
    free_device_list(&inputDevices, &inputDeviceCount);
}
示例#6
0
/*
 * check for new devices
 * args:
 *   vd - pointer to device data (can be null)
 *
 * asserts:
 *   my_device_list.udev is not null
 *   my_device_list.udev_fd is valid (> 0)
 *   my_device_list.udev_mon is not null
 *
 * returns: true(1) if device list was updated, false(0) otherwise
 */
int check_device_list_events(v4l2_dev_t *vd)
{
	/*assertions*/
	assert(my_device_list.udev != NULL);
	assert(my_device_list.udev_fd > 0);
	assert(my_device_list.udev_mon != NULL);

    fd_set fds;
    struct timeval tv;
    int ret = 0;

    FD_ZERO(&fds);
    FD_SET(my_device_list.udev_fd, &fds);
    tv.tv_sec = 0;
    tv.tv_usec = 0;

    ret = select(my_device_list.udev_fd+1, &fds, NULL, NULL, &tv);

    /* Check if our file descriptor has received data. */
    if (ret > 0 && FD_ISSET(my_device_list.udev_fd, &fds))
    {
        /*
         * Make the call to receive the device.
         *   select() ensured that this will not block.
         */
        struct udev_device *dev = udev_monitor_receive_device(my_device_list.udev_mon);
        if (dev)
        {
            if (verbosity > 0)
            {
                printf("V4L2_CORE: Got Device event\n");
                printf("          Node: %s\n", udev_device_get_devnode(dev));
                printf("     Subsystem: %s\n", udev_device_get_subsystem(dev));
                printf("       Devtype: %s\n", udev_device_get_devtype(dev));
                printf("        Action: %s\n", udev_device_get_action(dev));
            }

            /*update device list*/
            if(my_device_list.list_devices != NULL)
				free_device_list();
            enum_v4l2_devices();
            
            /*update the current device index*/
            if(vd)
            {
				vd->this_device = v4l2core_get_device_index(vd->videodevice);
				if(vd->this_device < 0)
					vd->this_device = 0;
	
				if(my_device_list.list_devices)
					my_device_list.list_devices[vd->this_device].current = 1;
			}
			
            udev_device_unref(dev);

            return(1);
        }
        else
            fprintf(stderr, "V4L2_CORE: No Device from receive_device(). An error occured.\n");
    }

    return(0);
}