]> git.sesse.net Git - bmusb/commitdiff
Add an option to get a textual description of each card.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 22 Jan 2016 00:18:41 +0000 (01:18 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 22 Jan 2016 00:18:41 +0000 (01:18 +0100)
bmusb.cpp
bmusb.h

index 2ea6407f6ce1bf230e31ee7aaeb363a8d407b784..3132c42f2718ae80d19f4ec175b7ecf2feb48d98 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -28,6 +28,7 @@
 #include <memory>
 #include <mutex>
 #include <stack>
+#include <string>
 #include <thread>
 
 using namespace std;
@@ -706,7 +707,7 @@ struct USBCardDevice {
        libusb_device *device;
 };
 
-libusb_device_handle *open_card(int card_index)
+libusb_device_handle *open_card(int card_index, string *description)
 {      
        libusb_device **devices;
        ssize_t num_devices = libusb_get_device_list(nullptr, &devices);
@@ -745,14 +746,22 @@ libusb_device_handle *open_card(int card_index)
        });
 
        for (size_t i = 0; i < found_cards.size(); ++i) {
-               fprintf(stderr, "Card %d: Bus %03u Device %03u ", int(i), found_cards[i].bus, found_cards[i].port);
+               const char *product_name = nullptr;
                if (found_cards[i].product == 0xbd3b) {
-                       fprintf(stderr, "Intensity Shuttle\n");
+                       product_name = "Intensity Shuttle";
                } else if (found_cards[i].product == 0xbd4f) {
-                       fprintf(stderr, "UltraStudio SDI\n");
+                       product_name = "UltraStudio SDI";
                } else {
                        assert(false);
                }
+
+               char buf[256];
+               snprintf(buf, sizeof(buf), "Card %d: Bus %03u Device %03u  %s",
+                       int(i), found_cards[i].bus, found_cards[i].port, product_name);
+               if (i == size_t(card_index)) {
+                       *description = buf;
+               }
+               fprintf(stderr, "%s\n", buf);
        }
 
        if (size_t(card_index) >= found_cards.size()) {
@@ -794,7 +803,7 @@ void BMUSBCapture::configure_card()
                exit(1);
        }
 
-       libusb_device_handle *devh = open_card(card_index);
+       libusb_device_handle *devh = open_card(card_index, &description);
        if (!devh) {
                fprintf(stderr, "Error finding USB device\n");
                exit(1);
diff --git a/bmusb.h b/bmusb.h
index d47ce8e85c4541be65dcd89c7b10ed727781b153..6fdddedeb6e1d5781d8a9128cf67b5525fd5ef33 100644 (file)
--- a/bmusb.h
+++ b/bmusb.h
@@ -7,6 +7,7 @@
 #include <deque>
 #include <functional>
 #include <mutex>
+#include <string>
 #include <thread>
 #include <vector>
 
@@ -104,6 +105,11 @@ class BMUSBCapture {
                has_dequeue_callbacks = true;
        }
 
+       // Only valid after configure_card().
+       std::string get_description() const {
+               return description;
+       }
+
        void configure_card();
        void start_bm_capture();
        void stop_dequeue_thread();
@@ -127,6 +133,8 @@ class BMUSBCapture {
        static void usb_thread_func();
        static void cb_xfr(struct libusb_transfer *xfr);
 
+       std::string description;
+
        FrameAllocator::Frame current_video_frame;
        FrameAllocator::Frame current_audio_frame;