1 #include <DeckLinkAPI.h>
2 #include <DeckLinkAPIModes.h>
6 #include "decklink_util.h"
12 map<uint32_t, VideoMode> summarize_video_modes(IDeckLinkDisplayModeIterator *mode_it, unsigned card_index)
14 map<uint32_t, VideoMode> video_modes;
16 for (IDeckLinkDisplayMode *mode_ptr; mode_it->Next(&mode_ptr) == S_OK; mode_ptr->Release()) {
19 const char *mode_name;
20 if (mode_ptr->GetName(&mode_name) != S_OK) {
21 mode.name = "Unknown mode";
23 mode.name = mode_name;
24 free((char *)mode_name);
27 mode.autodetect = false;
29 mode.width = mode_ptr->GetWidth();
30 mode.height = mode_ptr->GetHeight();
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);
38 mode.frame_rate_num = frame_rate_num;
39 mode.frame_rate_den = frame_rate_den;
41 // TODO: Respect the TFF/BFF flag.
42 mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst);
44 uint32_t id = mode_ptr->GetDisplayMode();
45 video_modes.insert(make_pair(id, mode));
51 BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAttributeID attribute_id, unsigned card_index)
53 assert(attribute_id == BMDDeckLinkVideoInputConnections ||
54 attribute_id == BMDDeckLinkVideoOutputConnections);
56 IDeckLinkAttributes *attr;
57 if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) {
58 fprintf(stderr, "Card %u has no attributes\n", card_index);
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);
67 fprintf(stderr, "Failed to enumerate video outputs for card %u\n", card_index);
72 if (connection_mask == 0) {
73 if (attribute_id == BMDDeckLinkVideoInputConnections) {
74 fprintf(stderr, "Card %u has no input connections\n", card_index);
76 fprintf(stderr, "Card %u has no output connections\n", card_index);
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;
89 // Fallback: Return lowest-set bit, whatever that might be.
90 return connection_mask & (-connection_mask);