X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bmusb%2Ffake_capture.h;fp=bmusb%2Ffake_capture.h;h=48dca063ae7d6b18e21e3554478b4aa1532f1000;hb=0d48ad939040ec561e67ab2329e3961843b3cf74;hp=0000000000000000000000000000000000000000;hpb=8e0a25a2663844905f3daf8fcf9bf9ec995d1074;p=bmusb diff --git a/bmusb/fake_capture.h b/bmusb/fake_capture.h new file mode 100644 index 0000000..48dca06 --- /dev/null +++ b/bmusb/fake_capture.h @@ -0,0 +1,104 @@ +#ifndef _FAKE_CAPTURE_H +#define _FAKE_CAPTURE_H 1 + +#include +#include +#include + +#include "bmusb/bmusb.h" + +namespace bmusb { + +class FakeCapture : public CaptureInterface +{ +public: + FakeCapture(unsigned width, unsigned height, unsigned fps, unsigned audio_frequency, int card_index); + ~FakeCapture(); + + // CaptureInterface. + void set_video_frame_allocator(FrameAllocator *allocator) override + { + video_frame_allocator = allocator; + if (owned_video_frame_allocator.get() != allocator) { + owned_video_frame_allocator.reset(); + } + } + + FrameAllocator *get_video_frame_allocator() override + { + return video_frame_allocator; + } + + // Does not take ownership. + void set_audio_frame_allocator(FrameAllocator *allocator) override + { + audio_frame_allocator = allocator; + if (owned_audio_frame_allocator.get() != allocator) { + owned_audio_frame_allocator.reset(); + } + } + + FrameAllocator *get_audio_frame_allocator() override + { + return audio_frame_allocator; + } + + void set_frame_callback(frame_callback_t callback) override + { + frame_callback = callback; + } + + void set_dequeue_thread_callbacks(std::function init, std::function cleanup) override + { + dequeue_init_callback = init; + dequeue_cleanup_callback = cleanup; + has_dequeue_callbacks = true; + } + + std::string get_description() const override + { + return description; + } + + void configure_card() override; + void start_bm_capture() override; + void stop_dequeue_thread() override; + bool get_disconnected() const override { return false; } + + std::map get_available_video_modes() const override; + void set_video_mode(uint32_t video_mode_id) override; + uint32_t get_current_video_mode() const override { return 0; } + + std::map get_available_video_inputs() const override; + void set_video_input(uint32_t video_input_id) override; + uint32_t get_current_video_input() const override { return 0; } + + std::map get_available_audio_inputs() const override; + void set_audio_input(uint32_t audio_input_id) override; + uint32_t get_current_audio_input() const override { return 0; } + +private: + void producer_thread_func(); + + unsigned width, height, fps, audio_frequency; + uint8_t y, cb, cr; + + bool has_dequeue_callbacks = false; + std::function dequeue_init_callback = nullptr; + std::function dequeue_cleanup_callback = nullptr; + + FrameAllocator *video_frame_allocator = nullptr; + FrameAllocator *audio_frame_allocator = nullptr; + std::unique_ptr owned_video_frame_allocator; + std::unique_ptr owned_audio_frame_allocator; + frame_callback_t frame_callback = nullptr; + + std::string description; + + std::atomic producer_thread_should_quit{false}; + std::thread producer_thread; +}; + +} // namespace bmusb + +#endif // !defined(_FAKE_CAPTURE_H)