1 #include <DeckLinkAPI.h>
2 #include <DeckLinkAPIModes.h>
6 #include "decklink_util.h"
11 map<uint32_t, VideoMode> summarize_video_modes(IDeckLinkDisplayModeIterator *mode_it, unsigned card_index)
13 map<uint32_t, VideoMode> video_modes;
15 for (IDeckLinkDisplayMode *mode_ptr; mode_it->Next(&mode_ptr) == S_OK; mode_ptr->Release()) {
18 const char *mode_name;
19 if (mode_ptr->GetName(&mode_name) != S_OK) {
20 mode.name = "Unknown mode";
22 mode.name = mode_name;
23 free((char *)mode_name);
26 mode.autodetect = false;
28 mode.width = mode_ptr->GetWidth();
29 mode.height = mode_ptr->GetHeight();
31 BMDTimeScale frame_rate_num;
32 BMDTimeValue frame_rate_den;
33 if (mode_ptr->GetFrameRate(&frame_rate_den, &frame_rate_num) != S_OK) {
34 fprintf(stderr, "Could not get frame rate for mode '%s' on card %d\n", mode.name.c_str(), card_index);
37 mode.frame_rate_num = frame_rate_num;
38 mode.frame_rate_den = frame_rate_den;
40 // TODO: Respect the TFF/BFF flag.
41 mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst);
43 uint32_t id = mode_ptr->GetDisplayMode();
44 video_modes.insert(make_pair(id, mode));
50 BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAttributeID attribute_id, unsigned card_index)
52 assert(attribute_id == BMDDeckLinkVideoInputConnections ||
53 attribute_id == BMDDeckLinkVideoOutputConnections);
55 IDeckLinkAttributes *attr;
56 if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) {
57 fprintf(stderr, "Card %u has no attributes\n", card_index);
61 int64_t connection_mask;
62 if (attr->GetInt(attribute_id, &connection_mask) != S_OK) {
63 if (attribute_id == BMDDeckLinkVideoInputConnections) {
64 fprintf(stderr, "Failed to enumerate video inputs for card %u\n", card_index);
66 fprintf(stderr, "Failed to enumerate video outputs for card %u\n", card_index);
71 if (connection_mask == 0) {
72 if (attribute_id == BMDDeckLinkVideoInputConnections) {
73 fprintf(stderr, "Card %u has no input connections\n", card_index);
75 fprintf(stderr, "Card %u has no outpu connectionss\n", card_index);
80 if (connection_mask & bmdVideoConnectionHDMI) {
81 return bmdVideoConnectionHDMI;
82 } else if (connection_mask & bmdVideoConnectionSDI) {
83 return bmdVideoConnectionSDI;
85 // Fallback: Return lowest-set bit, whatever that might be.
86 return connection_mask & (-connection_mask);