-// Intensity Shuttle USB3 prototype capture driver, v0.3
+// Intensity Shuttle USB3 capture driver, v0.5.2
// Can download 8-bit and 10-bit UYVY/v210 frames from HDMI, quite stable
// (can do captures for hours at a time with no drops), except during startup
// 576p60/720p60/1080i60 works, 1080p60 does not work (firmware limitation)
#if HAS_MULTIVERSIONING
#include <immintrin.h>
#endif
-#include "bmusb.h"
+#include "bmusb/bmusb.h"
#include <algorithm>
#include <atomic>
namespace bmusb {
card_connected_callback_t BMUSBCapture::card_connected_callback = nullptr;
+bool BMUSBCapture::hotplug_existing_devices = false;
namespace {
#else // defined(HAS_MULTIVERSIONING)
+__attribute__((target("sse4.1")))
+const uint8_t *add_to_frame_fastpath_core(FrameAllocator::Frame *current_frame, const uint8_t *aligned_start, const uint8_t *limit, const char sync_char);
+
+__attribute__((target("avx2")))
const uint8_t *add_to_frame_fastpath_core(FrameAllocator::Frame *current_frame, const uint8_t *aligned_start, const uint8_t *limit, const char sync_char);
// Does a memcpy and memchr in one to reduce processing time.
printf("couldn't set realtime priority for USB thread: %s\n", strerror(errno));
}
while (!should_quit) {
- int rc = libusb_handle_events(nullptr);
+ timeval sec { 1, 0 };
+ int rc = libusb_handle_events_timeout(nullptr, &sec);
if (rc != LIBUSB_SUCCESS)
break;
}
}
+namespace {
+
struct USBCardDevice {
uint16_t product;
uint8_t bus, port;
return buf;
}
-libusb_device_handle *open_card(int card_index, string *description)
+vector<USBCardDevice> find_all_cards()
{
libusb_device **devices;
ssize_t num_devices = libusb_get_device_list(nullptr, &devices);
return a.port < b.port;
});
+ return found_cards;
+}
+
+libusb_device_handle *open_card(int card_index, string *description)
+{
+ vector<USBCardDevice> found_cards = find_all_cards();
+
for (size_t i = 0; i < found_cards.size(); ++i) {
string tmp_description = get_card_description(i, found_cards[i].bus, found_cards[i].port, found_cards[i].product);
fprintf(stderr, "%s\n", tmp_description.c_str());
return devh;
}
+} // namespace
+
+unsigned BMUSBCapture::num_cards()
+{
+ int rc = libusb_init(nullptr);
+ if (rc < 0) {
+ fprintf(stderr, "Error initializing libusb: %s\n", libusb_error_name(rc));
+ exit(1);
+ }
+
+ vector<USBCardDevice> found_cards = find_all_cards();
+ unsigned ret = found_cards.size();
+ for (size_t i = 0; i < found_cards.size(); ++i) {
+ libusb_unref_device(found_cards[i].device);
+ }
+ return ret;
+}
+
void BMUSBCapture::configure_card()
{
if (video_frame_allocator == nullptr) {
rc = libusb_set_interface_alt_setting(devh, /*interface=*/0, /*alternate_setting=*/1);
if (rc < 0) {
fprintf(stderr, "Error setting alternate 1: %s\n", libusb_error_name(rc));
+ if (rc == LIBUSB_ERROR_NOT_FOUND) {
+ fprintf(stderr, "This is usually because the card came up in USB2 mode.\n");
+ fprintf(stderr, "In particular, this tends to happen if you boot up with the\n");
+ fprintf(stderr, "card plugged in; just unplug and replug it, and it usually works.\n");
+ }
exit(1);
}
rc = libusb_set_interface_alt_setting(devh, /*interface=*/0, /*alternate_setting=*/2);
// 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");