From cd4dd0ed2eaf14fc50f0601295c821a41b603490 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 22 Jan 2016 01:18:41 +0100 Subject: [PATCH] Add an option to get a textual description of each card. --- bmusb.cpp | 19 ++++++++++++++----- bmusb.h | 8 ++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/bmusb.cpp b/bmusb.cpp index 2ea6407..3132c42 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include 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 d47ce8e..6fddded 100644 --- a/bmusb.h +++ b/bmusb.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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; -- 2.39.2