pupil-labs / libuvc

a cross-platform library for USB video devices
https://int80k.com/libuvc/
Other
51 stars 30 forks source link

uvc_open: Not supported (-12) on Windows 10 64-bit #25

Closed micjansedge closed 6 years ago

micjansedge commented 6 years ago

I've tried using libuvc to access my See3CAM_CU40 camera. I've followed https://github.com/pupil-labs/libuvc/blob/master/INSTALL_WINDOWS.md. Then tried the below code:

int main()
{

    uvc_context_t *ctx;
    uvc_device_t *dev;
    uvc_device_handle_t *devh;
    uvc_stream_ctrl_t ctrl;
    uvc_error_t res;
    /* Initialize a UVC service context. Libuvc will set up its own libusb
    * context. Replace NULL with a libusb_context pointer to run libuvc
    * from an existing libusb context. */
    res = uvc_init(&ctx, NULL);
    if (res < 0) {
        uvc_perror(res, "uvc_init");
        return res;
    }
    puts("UVC initialized");

    // list_devices(ctx);

    /* Locates the first attached UVC device, stores in dev */
    res = uvc_find_device(
        ctx, &dev,
        0x2560, 0xc140, NULL); /* filter devices: vendor_id, product_id, "serial_num" */
    if (res < 0) {
        uvc_perror(res, "uvc_find_device"); /* no devices found */
    }
    else {
        puts("Device found");
        /* Try to open the device: requires exclusive access */
        res = uvc_open(dev, &devh);
        if (res < 0) {
            uvc_perror(res, "uvc_open"); /* unable to open device */
        }
        else {
            puts("Device opened");
            /* Print out a message containing all the information that libuvc
            * knows about the device */
            uvc_print_diag(devh, stderr);
            /* Try to negotiate a 640x480 30 fps YUYV stream profile */
            res = uvc_get_stream_ctrl_format_size(
                devh, &ctrl, /* result stored in ctrl */
                             // corresponds to 'Y16 '
                UVC_FRAME_FORMAT_GRAY16, /* YUV 422, aka YUV 4:2:2. try _COMPRESSED */
                672, 380, 300 /* width, height, fps */
            );
            /* Print out the result */
            uvc_print_stream_ctrl(&ctrl, stderr);
            if (res < 0) {
                uvc_perror(res, "get_mode"); /* device doesn't provide a matching stream */
            }
            else {
                /* Start the video stream. The library will call user function cb:
                *   cb(frame, (void*) 12345)
                */
                res = uvc_start_streaming(devh, &ctrl, cb, NULL, 0);
                if (res < 0) {
                    uvc_perror(res, "start_streaming"); /* unable to start stream */
                }
                else {
                    puts("Streaming...");
                    // uvc_set_ae_mode(devh, 1); /* e.g., turn on auto exposure */
#ifdef __unix__
                    sleep(3); /* stream for 10 seconds */
#else
                    Sleep(3000);
#endif
                    /* End the stream. Blocks until last callback is serviced */
                    uvc_stop_streaming(devh);
                    puts("Done streaming.");
                }
            }
            /* Release our handle on the device */
            uvc_close(devh);
            puts("Device closed");
        }
        /* Release the device descriptor */
        uvc_unref_device(dev);
    }

    /* Close the UVC context. This closes and cleans up any existing device handles,
    * and it closes the libusb context if one was not provided. */
    uvc_exit(ctx);
    puts("UVC exited");

    getchar();

    return 0;
}

I've compiled libusb following https://github.com/pupil-labs/libusb/blob/master/INSTALL_WIN.txt, with ENABLE_DEBUG_LOGGING. Here is what I'm getting when I run the above code:

[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000000] [00003064] libusb: debug [libusb_init] created default context
[ 0.000000] [00003064] libusb: debug [libusb_init] libusb v1.0.21.11156
[ 0.000000] [00003064] libusb: debug [windows_init] Windows 8 64-bit
[ 0.000000] [00003064] libusb: debug [setup_cancel_io] Will use CancelIoEx for I/O cancellation
[ 0.031215] [00003064] libusb: debug [winusbx_init] using libusbK DLL for universal access
[ 0.031215] [00003064] libusb: debug [winusbx_init] libusbK version: 3.0.7.0
[ 0.046842] [00003064] libusb: debug [winusbx_init] initalized sub API libusbK
[ 0.046842] [00003064] libusb: debug [winusbx_init] initalized sub API libusb0
[ 0.046842] [00003064] libusb: debug [winusbx_init] initalized sub API WinUSB
[ 0.046842] [00003064] libusb: debug [windows_init_clock] hires timer available (Frequency: 2531250 Hz)
[ 0.046842] [00003064] libusb: debug [windows_init_clock] timer thread will run on core #0
[ 0.062469] [00003064] libusb: debug [htab_create] using 1021 entries hash table
[ 0.062469] [00003064] libusb: debug [usbi_add_pollfd] add fd 0 events 1
UVC initialized
[ 0.062469] [00003064] libusb: debug [libusb_get_device_list]
[ 0.062469] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [91]
[ 0.062469] [00003064] libusb: debug [get_api_type] driver(s): USBHUB3
[ 0.062469] [00003064] libusb: debug [get_api_type] matched driver name against HUB API
[ 0.062469] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [3D4]
[ 0.062469] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [B7]
[ 0.062469] [00003064] libusb: debug [init_device] got bus number from ancestor #2
[ 0.062469] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.062469] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 700 bytes)
[ 0.062469] [00003064] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 4): '\\.\USB#VID_174F&PID_2407#5&3279CB56&0&4'
[ 0.062469] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [33]
[ 0.062469] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.062469] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.078095] [00003064] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 2): '\\.\USB#VID_046D&PID_C52F&MI_00#6&247989BB&0&0000'
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [1E7]
[ 0.078095] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.078095] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 177 bytes)
[ 0.078095] [00003064] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 7): '\\.\USB#VID_8087&PID_0A2A#5&3279CB56&0&7'
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [2CC]
[ 0.078095] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.078095] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.078095] [00003064] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 2): '\\.\USB#VID_046D&PID_C52F#5&3279CB56&0&2'
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] found existing device for session [3D4] (1.0)
[ 0.078095] [00003064] libusb: debug [init_device] (bus: 1, addr: 1, depth: 0, port: 0): '\\.\USB#ROOT_HUB30#4&2A97E603&0&0'
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] extra GUID: {5CD1E681-C2D8-427D-8AD2-EE2C9B43DA98}
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [3E8]
[ 0.078095] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.078095] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 373 bytes)
[ 0.078095] [00003064] libusb: debug [init_device] (bus: 1, addr: 10, depth: 1, port: 14): '\\.\USB#VID_2560&PID_C140&MI_00#6&2887BC08&1&0000'
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [232]
[ 0.078095] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.078095] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 373 bytes)
[ 0.078095] [00003064] libusb: debug [init_device] (bus: 1, addr: 10, depth: 1, port: 14): '\\.\USB#VID_2560&PID_C140#181F9503'
[ 0.078095] [00003064] libusb: debug [windows_get_device_list] allocating new device for session [F2]
[ 0.093722] [00003064] libusb: debug [init_device] found 1 configurations (active conf: 1)
[ 0.093722] [00003064] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 39 bytes)
[ 0.093722] [00003064] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 5): '\\.\USB#VID_0BDA&PID_0129#20100201396000000'
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] extra GUID: {4BA2D189-D0F3-499B-AAFC-2B5293C627D9}
[ 0.093722] [00003064] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.093722] [00003064] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] found existing device for session [B7] (1.3)
[ 0.093722] [00003064] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.093722] [00003064] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] found existing device for session [2CC] (1.2)
[ 0.093722] [00003064] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.093722] [00003064] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] found existing device for session [1E7] (1.5)
[ 0.093722] [00003064] libusb: debug [get_api_type] driver(s): RTSUER
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] found existing device for session [F2] (1.4)
[ 0.093722] [00003064] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.093722] [00003064] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] found existing device for session [232] (1.10)
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] setting composite interface for [2CC]:
[ 0.093722] [00003064] libusb: debug [set_composite_interface] interface[1] = \\.\HID#VID_046D&PID_C52F&MI_01&COL01#7&2246F788&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] setting composite interface for [2CC]:
[ 0.093722] [00003064] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: \\.\HID#VID_046D&PID_C52F&MI_01&COL02#7&2246F788&0&0001
[ 0.093722] [00003064] libusb: debug [windows_get_device_list] setting composite interface for [2CC]:
[ 0.109348] [00003064] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: \\.\HID#VID_046D&PID_C52F&MI_01&COL03#7&2246F788&0&0002
[ 0.109348] [00003064] libusb: debug [windows_get_device_list] unlisted ancestor for '\\.\HID#LENOVOVHID#1&632D18&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.109348] [00003064] libusb: debug [get_api_type] driver(s): libusbK
[ 0.109348] [00003064] libusb: debug [get_api_type] matched driver name against libusbK
[ 0.109348] [00003064] libusb: debug [windows_get_device_list] setting composite interface for [232]:
[ 0.109348] [00003064] libusb: debug [set_composite_interface] interface[0] = \\.\USB#VID_2560&PID_C140&MI_00#6&2887BC08&1&0000#{5CD1E681-C2D8-427D-8AD2-EE2C9B43DA98}
[ 0.109348] [00003064] libusb: debug [get_api_type] driver(s): libusbK
[ 0.109348] [00003064] libusb: debug [get_api_type] matched driver name against libusbK
[ 0.109348] [00003064] libusb: debug [windows_get_device_list] setting composite interface for [232]:
[ 0.109348] [00003064] libusb: debug [set_composite_interface] interface[2] = \\.\USB#VID_2560&PID_C140&MI_02#6&2887BC08&1&0002#{4BA2D189-D0F3-499B-AAFC-2B5293C627D9}
[ 0.109348] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.109348] [00003064] libusb: debug [parse_configuration] skipping descriptor 0xb
[ 0.109348] [00003064] libusb: debug [parse_endpoint] skipping descriptor 25
[ 0.109348] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.109348] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.109348] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.109348] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.109348] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.109348] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.109348] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.109348] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.124975] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.124975] [00003064] libusb: debug [parse_configuration] skipping descriptor 0xb
[ 0.124975] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.124975] [00003064] libusb: debug [parse_endpoint] skipping descriptor 25
[ 0.124975] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.124975] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.124975] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.124975] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.124975] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.140602] [00003064] libusb: debug [parse_configuration] skipping descriptor 0xb
[ 0.140602] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.140602] [00003064] libusb: debug [parse_endpoint] skipping descriptor 25
[ 0.140602] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.140602] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.140602] [00003064] libusb: debug [parse_endpoint] skipping descriptor 30
[ 0.140602] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.140602] [00003064] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.140602] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.140602] [00003064] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.140602] [00003064] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.140602] [00003064] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.140602] [00003064] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.140602] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.140602] [00003064] libusb: debug [libusb_open] open 1.3
[ 0.156229] [00003064] libusb: debug [libusb_open] open 1.3 returns -5
[ 0.156229] [00003064] libusb: debug [libusb_get_device_descriptor]
[ 0.156229] [00003064] libusb: debug [libusb_open] open 1.10
[ 0.156229] [00003064] libusb: debug [unsupported_open] unsupported API call for 'open' (unrecognized device driver)
[ 0.156229] [00003064] libusb: debug [libusb_open] open 1.10 returns -12
[ 0.156229] [00003064] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.171855] [00003064] libusb: debug [libusb_unref_device] destroy device 1.10
Device found
[ 0.171855] [00003064] libusb: debug [libusb_open] open 1.10
[ 0.171855] [00003064] libusb: debug [unsupported_open] unsupported API call for 'open' (unrecognized device driver)
[ 0.171855] [00003064] libusb: debug [libusb_open] open 1.10 returns -12
uvc_open: Not supported (-12)
[ 0.171855] [00003064] libusb: debug [libusb_unref_device] destroy device 1.10
[ 0.171855] [00003064] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.171855] [00003064] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.171855] [00003064] libusb: debug [libusb_exit]
[ 0.171855] [00003064] libusb: debug [libusb_exit] destroying default context
[ 0.171855] [00003064] libusb: debug [usbi_remove_pollfd] remove fd 0
[ 0.201649] [000006b4] libusb: debug [windows_clock_gettime_threaded] timer thread quitting
UVC exited

I've made sure I've installed the libusbK driver with the Zadig program. I've verified my camera appears under "libusbK USB Devices" in the Device Manager.

Any clues please?

mcuee commented 6 years ago

You may need to install libusbk to replace the composite parent (used as the driver of the whole device).

micjansedge commented 6 years ago

You're right. The trick was to untick "ignore hubs or composite parents" in the Zadig UI, select the composite parent entry from the drop down, then install libusbK in place of the default driver. Thanks a lot!

skywu commented 3 years ago

You're right. The trick was to untick "ignore hubs or composite parents" in the Zadig UI, select the composite parent entry from the drop down, then install libusbK in place of the default driver. Thanks a lot!

Indeed, this treatment can turn on my camera device, but I don’t understand why I want to do this?