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