1 #ifndef _DECKLINK_CAPTURE_H
2 #define _DECKLINK_CAPTURE_H 1
4 #include <DeckLinkAPI.h>
10 #include "bmusb/bmusb.h"
13 class IDeckLinkDisplayMode;
15 // TODO: Adjust CaptureInterface to be a little less bmusb-centric.
16 // There are too many member functions here that don't really do anything.
17 class DeckLinkCapture : public bmusb::CaptureInterface, IDeckLinkInputCallback
20 DeckLinkCapture(IDeckLink *card, int card_index); // Takes ownership of <card>.
23 // IDeckLinkInputCallback.
24 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *) override;
25 ULONG STDMETHODCALLTYPE AddRef() override;
26 ULONG STDMETHODCALLTYPE Release() override;
27 HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
28 BMDVideoInputFormatChangedEvents,
29 IDeckLinkDisplayMode*,
30 BMDDetectedVideoInputFormatFlags) override;
31 HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
32 IDeckLinkVideoInputFrame *video_frame,
33 IDeckLinkAudioInputPacket *audio_frame) override;
36 void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override
38 video_frame_allocator = allocator;
39 if (owned_video_frame_allocator.get() != allocator) {
40 owned_video_frame_allocator.reset();
44 bmusb::FrameAllocator *get_video_frame_allocator() override
46 return video_frame_allocator;
49 // Does not take ownership.
50 void set_audio_frame_allocator(bmusb::FrameAllocator *allocator) override
52 audio_frame_allocator = allocator;
53 if (owned_audio_frame_allocator.get() != allocator) {
54 owned_audio_frame_allocator.reset();
58 bmusb::FrameAllocator *get_audio_frame_allocator() override
60 return audio_frame_allocator;
63 void set_frame_callback(bmusb::frame_callback_t callback) override
65 frame_callback = callback;
68 void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
70 dequeue_init_callback = init;
71 dequeue_cleanup_callback = cleanup;
72 has_dequeue_callbacks = true;
75 std::string get_description() const override
80 void configure_card() override;
81 void start_bm_capture() override;
82 void stop_dequeue_thread() override;
84 // TODO: Can the API communicate this to us somehow, for e.g. Thunderbolt cards?
85 bool get_disconnected() const override { return false; }
87 std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const override { return video_modes; }
88 void set_video_mode(uint32_t video_mode_id) override;
89 uint32_t get_current_video_mode() const override { return current_video_mode; }
91 std::map<uint32_t, std::string> get_available_video_inputs() const override { return video_inputs; }
92 void set_video_input(uint32_t video_input_id) override;
93 uint32_t get_current_video_input() const override { return current_video_input; }
95 std::map<uint32_t, std::string> get_available_audio_inputs() const override { return audio_inputs; }
96 void set_audio_input(uint32_t audio_input_id) override;
97 uint32_t get_current_audio_input() const override { return current_audio_input; }
100 void set_video_mode_no_restart(uint32_t video_mode_id);
102 std::atomic<int> refcount{1};
103 bool done_init = false;
104 std::string description;
105 uint16_t timecode = 0;
108 bool has_dequeue_callbacks = false;
109 std::function<void()> dequeue_init_callback = nullptr;
110 std::function<void()> dequeue_cleanup_callback = nullptr;
112 bmusb::FrameAllocator *video_frame_allocator = nullptr;
113 bmusb::FrameAllocator *audio_frame_allocator = nullptr;
114 std::unique_ptr<bmusb::FrameAllocator> owned_video_frame_allocator;
115 std::unique_ptr<bmusb::FrameAllocator> owned_audio_frame_allocator;
116 bmusb::frame_callback_t frame_callback = nullptr;
118 IDeckLinkConfiguration *config = nullptr;
120 IDeckLink *card = nullptr;
121 IDeckLinkInput *input = nullptr;
122 BMDTimeValue frame_duration;
123 BMDTimeScale time_scale;
125 std::map<uint32_t, bmusb::VideoMode> video_modes;
126 BMDDisplayMode current_video_mode;
128 std::map<uint32_t, std::string> video_inputs;
129 BMDVideoConnection current_video_input;
131 std::map<uint32_t, std::string> audio_inputs;
132 BMDAudioConnection current_audio_input;
135 #endif // !defined(_DECKLINK_CAPTURE_H)