1 #ifndef _DECKLINK_CAPTURE_H
2 #define _DECKLINK_CAPTURE_H 1
4 #include <DeckLinkAPI.h>
12 #include "DeckLinkAPIModes.h"
13 #include "DeckLinkAPITypes.h"
15 #include "bmusb/bmusb.h"
18 class IDeckLinkConfiguration;
20 // TODO: Adjust CaptureInterface to be a little less bmusb-centric.
21 // There are too many member functions here that don't really do anything.
22 class DeckLinkCapture : public bmusb::CaptureInterface, IDeckLinkInputCallback
25 DeckLinkCapture(IDeckLink *card, int card_index); // Takes ownership of <card>.
28 // IDeckLinkInputCallback.
29 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *) override;
30 ULONG STDMETHODCALLTYPE AddRef() override;
31 ULONG STDMETHODCALLTYPE Release() override;
32 HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
33 BMDVideoInputFormatChangedEvents,
34 IDeckLinkDisplayMode*,
35 BMDDetectedVideoInputFormatFlags) override;
36 HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
37 IDeckLinkVideoInputFrame *video_frame,
38 IDeckLinkAudioInputPacket *audio_frame) override;
41 void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override
43 video_frame_allocator = allocator;
44 if (owned_video_frame_allocator.get() != allocator) {
45 owned_video_frame_allocator.reset();
49 bmusb::FrameAllocator *get_video_frame_allocator() override
51 return video_frame_allocator;
54 // Does not take ownership.
55 void set_audio_frame_allocator(bmusb::FrameAllocator *allocator) override
57 audio_frame_allocator = allocator;
58 if (owned_audio_frame_allocator.get() != allocator) {
59 owned_audio_frame_allocator.reset();
63 bmusb::FrameAllocator *get_audio_frame_allocator() override
65 return audio_frame_allocator;
68 void set_frame_callback(bmusb::frame_callback_t callback) override
70 frame_callback = callback;
73 void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
75 dequeue_init_callback = init;
76 dequeue_cleanup_callback = cleanup;
77 has_dequeue_callbacks = true;
80 std::string get_description() const override
85 void configure_card() override;
86 void start_bm_capture() override;
87 void stop_dequeue_thread() override;
89 // TODO: Can the API communicate this to us somehow, for e.g. Thunderbolt cards?
90 bool get_disconnected() const override { return false; }
92 std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const override { return video_modes; }
93 void set_video_mode(uint32_t video_mode_id) override;
94 uint32_t get_current_video_mode() const override { return current_video_mode; }
96 std::map<uint32_t, std::string> get_available_video_inputs() const override { return video_inputs; }
97 void set_video_input(uint32_t video_input_id) override;
98 uint32_t get_current_video_input() const override { return current_video_input; }
100 std::map<uint32_t, std::string> get_available_audio_inputs() const override { return audio_inputs; }
101 void set_audio_input(uint32_t audio_input_id) override;
102 uint32_t get_current_audio_input() const override { return current_audio_input; }
105 void set_video_mode_no_restart(uint32_t video_mode_id);
107 std::atomic<int> refcount{1};
108 bool done_init = false;
109 std::string description;
110 uint16_t timecode = 0;
113 bool has_dequeue_callbacks = false;
114 std::function<void()> dequeue_init_callback = nullptr;
115 std::function<void()> dequeue_cleanup_callback = nullptr;
117 bmusb::FrameAllocator *video_frame_allocator = nullptr;
118 bmusb::FrameAllocator *audio_frame_allocator = nullptr;
119 std::unique_ptr<bmusb::FrameAllocator> owned_video_frame_allocator;
120 std::unique_ptr<bmusb::FrameAllocator> owned_audio_frame_allocator;
121 bmusb::frame_callback_t frame_callback = nullptr;
123 IDeckLinkConfiguration *config = nullptr;
125 IDeckLink *card = nullptr;
126 IDeckLinkInput *input = nullptr;
127 BMDTimeValue frame_duration;
128 BMDTimeScale time_scale;
130 std::map<uint32_t, bmusb::VideoMode> video_modes;
131 BMDDisplayMode current_video_mode;
133 std::map<uint32_t, std::string> video_inputs;
134 BMDVideoConnection current_video_input;
136 std::map<uint32_t, std::string> audio_inputs;
137 BMDAudioConnection current_audio_input;
140 #endif // !defined(_DECKLINK_CAPTURE_H)