]> git.sesse.net Git - bmusb/commitdiff
Support hotplugging existing devices.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Jul 2016 19:04:32 +0000 (21:04 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 27 Jul 2016 19:06:01 +0000 (21:06 +0200)
bmusb.cpp
bmusb/bmusb.h

index ec3eac2918313e36258649357f7f27385f42a111..09473fd9f6ca4f839435bedbc1e2838cd100b35e 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -51,6 +51,7 @@ using namespace std::placeholders;
 namespace bmusb {
 
 card_connected_callback_t BMUSBCapture::card_connected_callback = nullptr;
+bool BMUSBCapture::hotplug_existing_devices = false;
 
 namespace {
 
@@ -1346,7 +1347,7 @@ void BMUSBCapture::start_bm_thread()
        // coming back with errors, so only care about devices joining.
        if (card_connected_callback != nullptr) {
                if (libusb_hotplug_register_callback(
-                       nullptr, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, LIBUSB_HOTPLUG_NO_FLAGS,
+                       nullptr, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, hotplug_existing_devices ? LIBUSB_HOTPLUG_ENUMERATE : LIBUSB_HOTPLUG_NO_FLAGS,
                        USB_VENDOR_BLACKMAGIC, LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY,
                        &BMUSBCapture::cb_hotplug, nullptr, nullptr) < 0) {
                        fprintf(stderr, "libusb_hotplug_register_callback() failed\n");
index 506685dc4c6a7401d17143cdb611315981c7b187..21cbc408da0f1190db14cd6d45d94ddfab8ace1a 100644 (file)
@@ -251,9 +251,11 @@ class BMUSBCapture : public CaptureInterface {
        // The callback function transfers ownership. If you don't want to hold
        // on to the device given to you in the callback, you need to call
        // libusb_unref_device().
-       static void set_card_connected_callback(card_connected_callback_t callback)
+       static void set_card_connected_callback(card_connected_callback_t callback,
+                                               bool hotplug_existing_devices_arg = false)
        {
                card_connected_callback = callback;
+               hotplug_existing_devices = hotplug_existing_devices_arg;
        }
 
        // Similar to set_card_connected_callback(), with the same caveats.
@@ -299,6 +301,7 @@ class BMUSBCapture : public CaptureInterface {
        std::unique_ptr<FrameAllocator> owned_audio_frame_allocator;
        frame_callback_t frame_callback = nullptr;
        static card_connected_callback_t card_connected_callback;
+       static bool hotplug_existing_devices;
        card_disconnected_callback_t card_disconnected_callback = nullptr;
 
        std::thread dequeue_thread;