+
+BMDVideoConnection pick_default_video_connection(IDeckLink *card, BMDDeckLinkAttributeID attribute_id, unsigned card_index)
+{
+ assert(attribute_id == BMDDeckLinkVideoInputConnections ||
+ attribute_id == BMDDeckLinkVideoOutputConnections);
+
+ IDeckLinkAttributes *attr;
+ if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) {
+ fprintf(stderr, "Card %u has no attributes\n", card_index);
+ exit(1);
+ }
+
+ int64_t connection_mask;
+ if (attr->GetInt(attribute_id, &connection_mask) != S_OK) {
+ if (attribute_id == BMDDeckLinkVideoInputConnections) {
+ fprintf(stderr, "Failed to enumerate video inputs for card %u\n", card_index);
+ } else {
+ fprintf(stderr, "Failed to enumerate video outputs for card %u\n", card_index);
+ }
+ exit(1);
+ }
+ attr->Release();
+ if (connection_mask == 0) {
+ if (attribute_id == BMDDeckLinkVideoInputConnections) {
+ fprintf(stderr, "Card %u has no input connections\n", card_index);
+ } else {
+ fprintf(stderr, "Card %u has no outpu connectionss\n", card_index);
+ }
+ exit(1);
+ }
+
+ if (connection_mask & bmdVideoConnectionHDMI) {
+ return bmdVideoConnectionHDMI;
+ } else if (connection_mask & bmdVideoConnectionSDI) {
+ return bmdVideoConnectionSDI;
+ } else {
+ // Fallback: Return lowest-set bit, whatever that might be.
+ return connection_mask & (-connection_mask);
+ }
+}