]> git.sesse.net Git - bmusb/commitdiff
Add very rudimentary stopping support.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 15 Sep 2015 22:51:44 +0000 (00:51 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Tue, 15 Sep 2015 22:51:44 +0000 (00:51 +0200)
bmusb.cpp
bmusb.h

index 4b5f75a6fb95f232293a0161d2db52cf4c0ceb85..4f64d6c443c0348dbc2386d94fb8bfbd2f45e824 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -21,6 +21,7 @@
 #include <condition_variable>
 #include <thread>
 #include <stack>
+#include <atomic>
 #include "bmusb.h"
 
 using namespace std;
@@ -58,6 +59,9 @@ condition_variable queues_not_empty;
 deque<QueuedFrame> pending_video_frames;
 deque<QueuedFrame> pending_audio_frames;
 
+thread usb_thread;
+atomic<bool> should_quit;
+
 FrameAllocator::~FrameAllocator() {}
 
 #define NUM_QUEUED_FRAMES 8
@@ -373,7 +377,7 @@ end:
        }
 }
 
-void usb_thread()
+void usb_thread_func()
 {
        printf("usb thread started\n");
 
@@ -383,7 +387,7 @@ void usb_thread()
        if (sched_setscheduler(0, SCHED_RR, &param) == -1) {
                printf("couldn't set realtime priority for USB thread: %s\n", strerror(errno));
        }
-       while (true) {
+       while (!should_quit) {
                int rc = libusb_handle_events(nullptr);
                if (rc != LIBUSB_SUCCESS)
                        break;
@@ -786,7 +790,7 @@ void start_bm_capture()
                }
        }
 
-       thread(usb_thread).detach();
+       usb_thread = thread(usb_thread_func);
 
 
 #if 0
@@ -798,3 +802,9 @@ out:
        return rc;
 #endif
 }
+
+void stop_bm_capture()
+{
+       should_quit = true;
+       usb_thread.join();
+}
diff --git a/bmusb.h b/bmusb.h
index 7cbbf14e1e56f3b97c792bd675394f906ea29416..fb6f87135f514158f0fcdcd9bbbd4b5ab24655c5 100644 (file)
--- a/bmusb.h
+++ b/bmusb.h
@@ -54,5 +54,6 @@ FrameAllocator *get_audio_frame_allocator();
 
 void set_frame_callback(frame_callback_t callback);
 void start_bm_capture();
+void stop_bm_capture();
 
 #endif