From dae0dae8694ebf5e1255c17dca18dc03e4a0d961 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 12 Oct 2015 21:23:55 +0200 Subject: [PATCH] Add support for callbacks in the dequeue thread. The typical use for this would be setting up and tearing down an OpenGL context or similar. You can fake it easily enough for startup, but it's much worse for shutdown (which is coming soon). --- bmusb.cpp | 6 ++++++ bmusb.h | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bmusb.cpp b/bmusb.cpp index 16da5f0..b2de56f 100644 --- 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 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) diff --git a/bmusb.h b/bmusb.h index 301350f..c7a5224 100644 --- a/bmusb.h +++ b/bmusb.h @@ -95,6 +95,14 @@ class BMUSBCapture { frame_callback = callback; } + // Needs to be run before configure_card(). + void set_dequeue_thread_callbacks(std::function init, std::function cleanup) + { + dequeue_init_callback = init; + dequeue_cleanup_callback = cleanup; + has_dequeue_callbacks = true; + } + void configure_card(); void start_bm_capture(); @@ -129,6 +137,10 @@ class BMUSBCapture { FrameAllocator *audio_frame_allocator = nullptr; frame_callback_t frame_callback = nullptr; + bool has_dequeue_callbacks = false; + std::function dequeue_init_callback = nullptr; + std::function dequeue_cleanup_callback = nullptr; + int current_register = 0; static constexpr int NUM_BMUSB_REGISTERS = 60; -- 2.39.2