#include <condition_variable>
#include <thread>
#include <stack>
+#include <atomic>
#include "bmusb.h"
using namespace std;
deque<QueuedFrame> pending_video_frames;
deque<QueuedFrame> pending_audio_frames;
+thread usb_thread;
+atomic<bool> should_quit;
+
FrameAllocator::~FrameAllocator() {}
#define NUM_QUEUED_FRAMES 8
}
}
-void usb_thread()
+void usb_thread_func()
{
printf("usb thread started\n");
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;
}
}
- thread(usb_thread).detach();
+ usb_thread = thread(usb_thread_func);
#if 0
return rc;
#endif
}
+
+void stop_bm_capture()
+{
+ should_quit = true;
+ usb_thread.join();
+}