]> git.sesse.net Git - nageru/blob - fake_capture.h
c517257edc7cbf838c74a34f33c2c4a76317589b
[nageru] / fake_capture.h
1 #ifndef _FAKE_CAPTURE_H
2 #define _FAKE_CAPTURE_H 1
3
4 #include <stdint.h>
5 #include <functional>
6 #include <string>
7
8 #include "bmusb/bmusb.h"
9
10 class FakeCapture : public CaptureInterface
11 {
12 public:
13         FakeCapture(int card_index);
14         ~FakeCapture();
15
16         // CaptureInterface.
17         void set_video_frame_allocator(FrameAllocator *allocator) override
18         {
19                 video_frame_allocator = allocator;
20                 if (owned_video_frame_allocator.get() != allocator) {
21                         owned_video_frame_allocator.reset();
22                 }
23         }
24
25         FrameAllocator *get_video_frame_allocator() override
26         {
27                 return video_frame_allocator;
28         }
29
30         // Does not take ownership.
31         void set_audio_frame_allocator(FrameAllocator *allocator) override
32         {
33                 audio_frame_allocator = allocator;
34                 if (owned_audio_frame_allocator.get() != allocator) {
35                         owned_audio_frame_allocator.reset();
36                 }
37         }
38
39         FrameAllocator *get_audio_frame_allocator() override
40         {
41                 return audio_frame_allocator;
42         }
43
44         void set_frame_callback(frame_callback_t callback) override
45         {
46                 frame_callback = callback;
47         }
48
49         void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
50         {
51                 dequeue_init_callback = init;
52                 dequeue_cleanup_callback = cleanup;
53                 has_dequeue_callbacks = true;
54         }
55
56         std::string get_description() const override
57         {
58                 return description;
59         }
60
61         void configure_card() override;
62         void start_bm_capture() override;
63         void stop_dequeue_thread() override;
64         bool get_disconnected() const override { return false; }
65
66         std::map<uint32_t, VideoMode> get_available_video_modes() const override;
67         void set_video_mode(uint32_t video_mode_id) override;
68         uint32_t get_current_video_mode() const override { return 0; }
69
70         std::map<uint32_t, std::string> get_available_video_inputs() const override;
71         void set_video_input(uint32_t video_input_id) override;
72         uint32_t get_current_video_input() const override { return 0; }
73
74         std::map<uint32_t, std::string> get_available_audio_inputs() const override;
75         void set_audio_input(uint32_t audio_input_id) override;
76         uint32_t get_current_audio_input() const override { return 0; }
77
78 private:
79         void producer_thread_func();
80
81         uint8_t y, cb, cr;
82
83         bool has_dequeue_callbacks = false;
84         std::function<void()> dequeue_init_callback = nullptr;
85         std::function<void()> dequeue_cleanup_callback = nullptr;
86
87         FrameAllocator *video_frame_allocator = nullptr;
88         FrameAllocator *audio_frame_allocator = nullptr;
89         std::unique_ptr<FrameAllocator> owned_video_frame_allocator;
90         std::unique_ptr<FrameAllocator> owned_audio_frame_allocator;
91         frame_callback_t frame_callback = nullptr;
92
93         std::string description;
94
95         std::atomic<bool> producer_thread_should_quit{false};
96         std::thread producer_thread;
97 };
98
99 #endif  // !defined(_FAKE_CAPTURE_H)