1 #ifndef _DECKLINK_CAPTURE_H
2 #define _DECKLINK_CAPTURE_H 1
4 #include <DeckLinkAPI.h>
13 #include "DeckLinkAPIModes.h"
14 #include "DeckLinkAPITypes.h"
16 #include "bmusb/bmusb.h"
19 class IDeckLinkConfiguration;
21 // TODO: Adjust CaptureInterface to be a little less bmusb-centric.
22 // There are too many member functions here that don't really do anything.
23 class DeckLinkCapture : public bmusb::CaptureInterface, IDeckLinkInputCallback
26 DeckLinkCapture(IDeckLink *card, int card_index); // Takes ownership of <card>.
29 IDeckLinkInput *get_input() const { return input; }
31 // IDeckLinkInputCallback.
32 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *) override;
33 ULONG STDMETHODCALLTYPE AddRef() override;
34 ULONG STDMETHODCALLTYPE Release() override;
35 HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
36 BMDVideoInputFormatChangedEvents,
37 IDeckLinkDisplayMode*,
38 BMDDetectedVideoInputFormatFlags) override;
39 HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
40 IDeckLinkVideoInputFrame *video_frame,
41 IDeckLinkAudioInputPacket *audio_frame) override;
44 void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override
46 video_frame_allocator = allocator;
47 if (owned_video_frame_allocator.get() != allocator) {
48 owned_video_frame_allocator.reset();
52 bmusb::FrameAllocator *get_video_frame_allocator() override
54 return video_frame_allocator;
57 // Does not take ownership.
58 void set_audio_frame_allocator(bmusb::FrameAllocator *allocator) override
60 audio_frame_allocator = allocator;
61 if (owned_audio_frame_allocator.get() != allocator) {
62 owned_audio_frame_allocator.reset();
66 bmusb::FrameAllocator *get_audio_frame_allocator() override
68 return audio_frame_allocator;
71 void set_frame_callback(bmusb::frame_callback_t callback) override
73 frame_callback = callback;
76 void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
78 dequeue_init_callback = init;
79 dequeue_cleanup_callback = cleanup;
80 has_dequeue_callbacks = true;
83 std::string get_description() const override
88 void configure_card() override;
89 void start_bm_capture() override;
90 void stop_dequeue_thread() override;
92 // TODO: Can the API communicate this to us somehow, for e.g. Thunderbolt cards?
93 bool get_disconnected() const override { return false; }
95 std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const override { return video_modes; }
96 void set_video_mode(uint32_t video_mode_id) override;
97 uint32_t get_current_video_mode() const override { return current_video_mode; }
99 std::set<bmusb::PixelFormat> get_available_pixel_formats() const override {
100 return std::set<bmusb::PixelFormat>{ bmusb::PixelFormat_8BitYCbCr, bmusb::PixelFormat_10BitYCbCr };
102 void set_pixel_format(bmusb::PixelFormat pixel_format) override;
103 bmusb::PixelFormat get_current_pixel_format() const override {
104 return current_pixel_format;
107 std::map<uint32_t, std::string> get_available_video_inputs() const override { return video_inputs; }
108 void set_video_input(uint32_t video_input_id) override;
109 uint32_t get_current_video_input() const override { return current_video_input; }
111 std::map<uint32_t, std::string> get_available_audio_inputs() const override { return audio_inputs; }
112 void set_audio_input(uint32_t audio_input_id) override;
113 uint32_t get_current_audio_input() const override { return current_audio_input; }
116 void set_video_mode_no_restart(uint32_t video_mode_id);
118 std::atomic<int> refcount{1};
119 bool done_init = false;
120 std::string description;
121 uint16_t timecode = 0;
124 bool has_dequeue_callbacks = false;
125 std::function<void()> dequeue_init_callback = nullptr;
126 std::function<void()> dequeue_cleanup_callback = nullptr;
128 bmusb::FrameAllocator *video_frame_allocator = nullptr;
129 bmusb::FrameAllocator *audio_frame_allocator = nullptr;
130 std::unique_ptr<bmusb::FrameAllocator> owned_video_frame_allocator;
131 std::unique_ptr<bmusb::FrameAllocator> owned_audio_frame_allocator;
132 bmusb::frame_callback_t frame_callback = nullptr;
134 IDeckLinkConfiguration *config = nullptr;
136 IDeckLink *card = nullptr;
137 IDeckLinkInput *input = nullptr;
138 BMDTimeValue frame_duration;
139 BMDTimeScale time_scale;
140 BMDFieldDominance field_dominance;
141 bool running = false;
142 bool supports_autodetect = false;
144 std::map<uint32_t, bmusb::VideoMode> video_modes;
145 BMDDisplayMode current_video_mode;
146 bmusb::PixelFormat current_pixel_format = bmusb::PixelFormat_8BitYCbCr;
148 std::map<uint32_t, std::string> video_inputs;
149 BMDVideoConnection current_video_input;
151 std::map<uint32_t, std::string> audio_inputs;
152 BMDAudioConnection current_audio_input;
155 #endif // !defined(_DECKLINK_CAPTURE_H)