]> git.sesse.net Git - nageru/blob - decklink_capture.h
Add support for DeckLink PCI cards through the official driver.
[nageru] / decklink_capture.h
1 #ifndef _DECKLINK_CAPTURE_H
2 #define _DECKLINK_CAPTURE_H 1
3
4 #include <DeckLinkAPI.h>
5 #include <stdint.h>
6 #include <atomic>
7 #include <functional>
8 #include <string>
9
10 #include "bmusb/bmusb.h"
11
12 class IDeckLink;
13 class IDeckLinkDisplayMode;
14
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 CaptureInterface, IDeckLinkInputCallback
18 {
19 public:
20         DeckLinkCapture(IDeckLink *card, int card_index);
21         ~DeckLinkCapture();
22
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;
34
35         // CaptureInterface.
36         void set_video_frame_allocator(FrameAllocator *allocator) override
37         {
38                 video_frame_allocator = allocator;
39         }
40
41         FrameAllocator *get_video_frame_allocator() override
42         {
43                 return video_frame_allocator;
44         }
45
46         // Does not take ownership.
47         void set_audio_frame_allocator(FrameAllocator *allocator) override
48         {
49                 audio_frame_allocator = allocator;
50         }
51
52         FrameAllocator *get_audio_frame_allocator() override
53         {
54                 return audio_frame_allocator;
55         }
56
57         void set_frame_callback(frame_callback_t callback) override
58         {
59                 frame_callback = callback;
60         }
61
62         void set_dequeue_thread_callbacks(std::function<void()> init, std::function<void()> cleanup) override
63         {
64                 dequeue_init_callback = init;
65                 dequeue_cleanup_callback = cleanup;
66                 has_dequeue_callbacks = true;
67         }
68
69         std::string get_description() const override
70         {
71                 return description;
72         }
73
74         void configure_card() override {}
75         void start_bm_capture() override;
76         void stop_dequeue_thread() override;
77
78 private:
79         std::atomic<int> refcount{1};
80         bool done_init = false;
81         std::string description;
82         uint16_t timecode = 0;
83
84         bool has_dequeue_callbacks = false;
85         std::function<void()> dequeue_init_callback = nullptr;
86         std::function<void()> dequeue_cleanup_callback = nullptr;
87
88         FrameAllocator *video_frame_allocator = nullptr;
89         FrameAllocator *audio_frame_allocator = nullptr;
90         frame_callback_t frame_callback = nullptr;
91
92         IDeckLinkInput *input = nullptr;
93         BMDTimeValue frame_duration;
94         BMDTimeScale time_scale;
95 };
96
97 #endif  // !defined(_DECKLINK_CAPTURE_H)