]> git.sesse.net Git - nageru/blob - decklink_util.cpp
Add a mode to run in full screen.
[nageru] / decklink_util.cpp
1 #include <DeckLinkAPI.h>
2 #include <DeckLinkAPIModes.h>
3
4 #include <assert.h>
5
6 #include "decklink_util.h"
7 #include "flags.h"
8
9 using namespace bmusb;
10 using namespace std;
11
12 map<uint32_t, VideoMode> summarize_video_modes(IDeckLinkDisplayModeIterator *mode_it, unsigned card_index)
13 {
14         map<uint32_t, VideoMode> video_modes;
15
16         for (IDeckLinkDisplayMode *mode_ptr; mode_it->Next(&mode_ptr) == S_OK; mode_ptr->Release()) {
17                 VideoMode mode;
18
19                 const char *mode_name;
20                 if (mode_ptr->GetName(&mode_name) != S_OK) {
21                         mode.name = "Unknown mode";
22                 } else {
23                         mode.name = mode_name;
24                         free((char *)mode_name);
25                 }
26
27                 mode.autodetect = false;
28
29                 mode.width = mode_ptr->GetWidth();
30                 mode.height = mode_ptr->GetHeight();
31
32                 BMDTimeScale frame_rate_num;
33                 BMDTimeValue frame_rate_den;
34                 if (mode_ptr->GetFrameRate(&frame_rate_den, &frame_rate_num) != S_OK) {
35                         fprintf(stderr, "Could not get frame rate for mode '%s' on card %d\n", mode.name.c_str(), card_index);
36                         exit(1);
37                 }
38                 mode.frame_rate_num = frame_rate_num;
39                 mode.frame_rate_den = frame_rate_den;
40
41                 // TODO: Respect the TFF/BFF flag.
42                 mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst);
43
44                 uint32_t id = mode_ptr->GetDisplayMode();
45                 video_modes.insert(make_pair(id, mode));
46         }
47
48         return video_modes;
49 }
50
51 BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAttributeID attribute_id, unsigned card_index)
52 {
53         assert(attribute_id == BMDDeckLinkVideoInputConnections ||
54                attribute_id == BMDDeckLinkVideoOutputConnections);
55
56         IDeckLinkAttributes *attr;
57         if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) {
58                 fprintf(stderr, "Card %u has no attributes\n", card_index);
59                 exit(1);
60         }
61
62         int64_t connection_mask;
63         if (attr->GetInt(attribute_id, &connection_mask) != S_OK) {
64                 if (attribute_id == BMDDeckLinkVideoInputConnections) {
65                         fprintf(stderr, "Failed to enumerate video inputs for card %u\n", card_index);
66                 } else {
67                         fprintf(stderr, "Failed to enumerate video outputs for card %u\n", card_index);
68                 }
69                 exit(1);
70         }
71         attr->Release();
72         if (connection_mask == 0) {
73                 if (attribute_id == BMDDeckLinkVideoInputConnections) {
74                         fprintf(stderr, "Card %u has no input connections\n", card_index);
75                 } else {
76                         fprintf(stderr, "Card %u has no output connections\n", card_index);
77                 }
78                 exit(1);
79         }
80
81         if ((connection_mask & bmdVideoConnectionHDMI) &&
82             global_flags.default_hdmi_input) {
83                 return bmdVideoConnectionHDMI;
84         } else if (connection_mask & bmdVideoConnectionSDI) {
85                 return bmdVideoConnectionSDI;
86         } else if (connection_mask & bmdVideoConnectionHDMI) {
87                 return bmdVideoConnectionHDMI;
88         } else {
89                 // Fallback: Return lowest-set bit, whatever that might be.
90                 return connection_mask & (-connection_mask);
91         }
92 }