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 // IDeckLinkInputCallback.
30 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, LPVOID *) override;
31 ULONG STDMETHODCALLTYPE AddRef() override;
32 ULONG STDMETHODCALLTYPE Release() override;
33 HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
34 BMDVideoInputFormatChangedEvents,
35 IDeckLinkDisplayMode*,
36 BMDDetectedVideoInputFormatFlags) override;
37 HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
38 IDeckLinkVideoInputFrame *video_frame,
39 IDeckLinkAudioInputPacket *audio_frame) override;
42 void set_video_frame_allocator(bmusb::FrameAllocator *allocator) override
44 video_frame_allocator = allocator;
45 if (owned_video_frame_allocator.get() != allocator) {
46 owned_video_frame_allocator.reset();
50 bmusb::FrameAllocator *get_video_frame_allocator() override
52 return video_frame_allocator;
55 // Does not take ownership.
56 void set_audio_frame_allocator(bmusb::FrameAllocator *allocator) override
58 audio_frame_allocator = allocator;
59 if (owned_audio_frame_allocator.get() != allocator) {
60 owned_audio_frame_allocator.reset();
64 bmusb::FrameAllocator *get_audio_frame_allocator() override
66 return audio_frame_allocator;
69 void set_frame_callback(bmusb::frame_callback_t callback) override
71 frame_callback = callback;
74 void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
76 dequeue_init_callback = init;
77 dequeue_cleanup_callback = cleanup;
78 has_dequeue_callbacks = true;
81 std::string get_description() const override
86 void configure_card() override;
87 void start_bm_capture() override;
88 void stop_dequeue_thread() override;
90 // TODO: Can the API communicate this to us somehow, for e.g. Thunderbolt cards?
91 bool get_disconnected() const override { return false; }
93 std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const override { return video_modes; }
94 void set_video_mode(uint32_t video_mode_id) override;
95 uint32_t get_current_video_mode() const override { return current_video_mode; }
97 std::set<bmusb::PixelFormat> get_available_pixel_formats() const override {
98 return std::set<bmusb::PixelFormat>{ bmusb::PixelFormat_8BitYCbCr, bmusb::PixelFormat_10BitYCbCr };
100 void set_pixel_format(bmusb::PixelFormat pixel_format) override;
101 bmusb::PixelFormat get_current_pixel_format() const override {
102 return current_pixel_format;
105 std::map<uint32_t, std::string> get_available_video_inputs() const override { return video_inputs; }
106 void set_video_input(uint32_t video_input_id) override;
107 uint32_t get_current_video_input() const override { return current_video_input; }
109 std::map<uint32_t, std::string> get_available_audio_inputs() const override { return audio_inputs; }
110 void set_audio_input(uint32_t audio_input_id) override;
111 uint32_t get_current_audio_input() const override { return current_audio_input; }
114 void set_video_mode_no_restart(uint32_t video_mode_id);
116 std::atomic<int> refcount{1};
117 bool done_init = false;
118 std::string description;
119 uint16_t timecode = 0;
122 bool has_dequeue_callbacks = false;
123 std::function<void()> dequeue_init_callback = nullptr;
124 std::function<void()> dequeue_cleanup_callback = nullptr;
126 bmusb::FrameAllocator *video_frame_allocator = nullptr;
127 bmusb::FrameAllocator *audio_frame_allocator = nullptr;
128 std::unique_ptr<bmusb::FrameAllocator> owned_video_frame_allocator;
129 std::unique_ptr<bmusb::FrameAllocator> owned_audio_frame_allocator;
130 bmusb::frame_callback_t frame_callback = nullptr;
132 IDeckLinkConfiguration *config = nullptr;
134 IDeckLink *card = nullptr;
135 IDeckLinkInput *input = nullptr;
136 BMDTimeValue frame_duration;
137 BMDTimeScale time_scale;
138 BMDFieldDominance field_dominance;
139 bool running = false;
140 bool supports_autodetect = false;
142 std::map<uint32_t, bmusb::VideoMode> video_modes;
143 BMDDisplayMode current_video_mode;
144 bmusb::PixelFormat current_pixel_format = bmusb::PixelFormat_8BitYCbCr;
146 std::map<uint32_t, std::string> video_inputs;
147 BMDVideoConnection current_video_input;
149 std::map<uint32_t, std::string> audio_inputs;
150 BMDAudioConnection current_audio_input;
153 #endif // !defined(_DECKLINK_CAPTURE_H)