]> git.sesse.net Git - bmusb/blobdiff - bmusb.cpp
Add support for callbacks in the dequeue thread.
[bmusb] / bmusb.cpp
index 93ce2733572267083fc3318f91f1a406f36624c2..b2de56f2b2cee588bc4a1c01252ffa2154045a48 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -146,6 +146,9 @@ void dump_audio_block(uint8_t *audio_start, size_t audio_len)
 
 void BMUSBCapture::dequeue_thread()
 {
+       if (has_dequeue_callbacks) {
+               dequeue_init_callback();
+       }
        for ( ;; ) {
                unique_lock<mutex> lock(queue_lock);
                queues_not_empty.wait(lock, [this]{ return !pending_video_frames.empty() && !pending_audio_frames.empty(); });
@@ -181,6 +184,9 @@ void BMUSBCapture::dequeue_thread()
                                       audio_frame.frame, AUDIO_HEADER_SIZE, audio_frame.format);
                }
        }
+       if (has_dequeue_callbacks) {
+               dequeue_cleanup_callback();
+       }
 }
 
 void BMUSBCapture::start_new_frame(const uint8_t *start)
@@ -607,8 +613,6 @@ void BMUSBCapture::cb_xfr(struct libusb_transfer *xfr)
 
 void BMUSBCapture::usb_thread_func()
 {
-       printf("usb thread started\n");
-
        sched_param param;
        memset(&param, 0, sizeof(param));
        param.sched_priority = 1;
@@ -684,6 +688,9 @@ void BMUSBCapture::configure_card()
        // Alternate setting 1 is output, alternate setting 2 is input.
        // Card is reset when switching alternates, so the driver uses
        // this “double switch” when it wants to reset.
+       //
+       // There's also alternate settings 3 and 4, which seem to be
+       // like 1 and 2 except they advertise less bandwidth needed.
        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));