From: Steinar H. Gunderson Date: Tue, 15 Sep 2015 22:51:44 +0000 (+0200) Subject: Add very rudimentary stopping support. X-Git-Tag: 0.4~82 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=cbaa849e8d1cd73fc46ed63dc3146bff92b4a991;p=bmusb Add very rudimentary stopping support. --- diff --git a/bmusb.cpp b/bmusb.cpp index 4b5f75a..4f64d6c 100644 --- a/bmusb.cpp +++ b/bmusb.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "bmusb.h" using namespace std; @@ -58,6 +59,9 @@ condition_variable queues_not_empty; deque pending_video_frames; deque pending_audio_frames; +thread usb_thread; +atomic 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, ¶m) == -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 7cbbf14..fb6f871 100644 --- 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