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;
25 mode.autodetect = false;
27 mode.width = mode_ptr->GetWidth();
28 mode.height = mode_ptr->GetHeight();
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);
36 mode.frame_rate_num = frame_rate_num;
37 mode.frame_rate_den = frame_rate_den;
39 // TODO: Respect the TFF/BFF flag.
40 mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst);
42 uint32_t id = mode_ptr->GetDisplayMode();
43 video_modes.insert(make_pair(id, mode));
49 BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAttributeID attribute_id, unsigned card_index)
51 assert(attribute_id == BMDDeckLinkVideoInputConnections ||
52 attribute_id == BMDDeckLinkVideoOutputConnections);
54 IDeckLinkAttributes *attr;
55 if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) {
56 fprintf(stderr, "Card %u has no attributes\n", card_index);
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);
65 fprintf(stderr, "Failed to enumerate video outputs for card %u\n", card_index);
70 if (connection_mask == 0) {
71 if (attribute_id == BMDDeckLinkVideoInputConnections) {
72 fprintf(stderr, "Card %u has no input connections\n", card_index);
74 fprintf(stderr, "Card %u has no outpu connectionss\n", card_index);
79 if (connection_mask & bmdVideoConnectionHDMI) {
80 return bmdVideoConnectionHDMI;
81 } else if (connection_mask & bmdVideoConnectionSDI) {
82 return bmdVideoConnectionSDI;
84 // Fallback: Return lowest-set bit, whatever that might be.
85 return connection_mask & (-connection_mask);