bool DeckLinkController::selectDevice(int index) { IDeckLinkAttributes* deckLinkAttributes = NULL; IDeckLinkDisplayModeIterator* displayModeIterator = NULL; IDeckLinkDisplayMode* displayMode = NULL; bool result = false; // Check index if (index >= deviceList.size()) { ofLogError("DeckLinkController") << "This application was unable to select the device."; goto bail; } // A new device has been selected. // Release the previous selected device and mode list if (deckLinkInput != NULL) deckLinkInput->Release(); while(modeList.size() > 0) { modeList.back()->Release(); modeList.pop_back(); } // Get the IDeckLinkInput for the selected device if ((deviceList[index]->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput) != S_OK)) { ofLogError("DeckLinkController") << "This application was unable to obtain IDeckLinkInput for the selected device."; deckLinkInput = NULL; goto bail; } // // Retrieve and cache mode list if (deckLinkInput->GetDisplayModeIterator(&displayModeIterator) == S_OK) { while (displayModeIterator->Next(&displayMode) == S_OK) modeList.push_back(displayMode); displayModeIterator->Release(); } // // Check if input mode detection format is supported. supportFormatDetection = false; // assume unsupported until told otherwise if (deviceList[index]->QueryInterface(IID_IDeckLinkAttributes, (void**) &deckLinkAttributes) == S_OK) { if (deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supportFormatDetection) != S_OK) supportFormatDetection = false; deckLinkAttributes->Release(); } result = true; bail: return result; }
// Call init() before any other method. if init() fails, destroy the object bool PlaybackHelper::init() { IDeckLinkAttributes* attributes = NULL; bool hasBypass; bool result = false; // Get the IDeckLinkAttributes interface if (m_deckLink->QueryInterface(IID_IDeckLinkAttributes, (void **)&attributes) != S_OK) { printf("Could not get the IdeckLinkAttributes interface\n"); goto bail; } // Make sure the DeckLink device has a bypass if ((attributes->GetFlag(BMDDeckLinkHasBypass, &hasBypass) != S_OK) || ! hasBypass) { printf("The DeckLink device does not have a bypass\n"); goto bail; } // Get the IDeckLinkConfiguration interface if (m_deckLink->QueryInterface(IID_IDeckLinkConfiguration, (void **)&m_configuration) != S_OK) { printf("Could not get the IDeckLinkConfiguration interface\n"); m_configuration = NULL; } // Get the IDeckLinkOutput interface if (m_deckLink->QueryInterface(IID_IDeckLinkOutput, (void **)&m_deckLinkOutput) != S_OK) { printf("Could not get DeckLink Output interface\n"); m_deckLinkOutput = NULL; goto bail; } result = true; bail: if (attributes) attributes->Release(); return result; }
OFX_DECKLINK_API_BEGIN_NAMESPACE vector<Device> listDevice() { vector<Device> devinfo; IDeckLinkIterator* deckLinkIterator = CreateDeckLinkIteratorInstance(); if (deckLinkIterator == NULL) { ofLogError("ofxDeckLinkAPI::Monitor") << "This application requires the DeckLink drivers installed." << "\n" << "Please install the Blackmagic DeckLink drivers to use the features of this application."; } cout << "==== ofxDeckLinkAPI::listDevice() ====" << endl; IDeckLink* deckLink = NULL; HRESULT result; int num_device = 0; while (deckLinkIterator->Next(&deckLink) == S_OK) { Device dev; CFStringRef deviceNameCFString = NULL; result = deckLink->GetModelName(&deviceNameCFString); if (result == S_OK) { char deviceName[64]; CFStringGetCString(deviceNameCFString, deviceName, sizeof(deviceName), kCFStringEncodingUTF8); cout << num_device << ": " << deviceName; CFRelease(deviceNameCFString); dev.model_name = (string)deviceName; } IDeckLinkAttributes* attr = NULL; deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr); if (attr != NULL) { { int64_t v = 0; if (attr->GetInt(BMDDeckLinkPersistentID, &v) == S_OK) { dev.persistent_id = v; cout << ", pid:" << v; } } { int64_t v = 0; if (attr->GetInt(BMDDeckLinkTopologicalID, &v) == S_OK) { dev.topological_id = v; cout << ", tid:" << v; } } } cout << endl; devinfo.push_back(dev); deckLink->Release(); num_device++; } if (num_device == 0) cout << "device not found" << endl; cout << "======================================" << endl << endl; if (deckLinkIterator != NULL) { deckLinkIterator->Release(); deckLinkIterator = NULL; } return devinfo; }
int query_display_mode(DecklinkConf *c) { DecklinkCapture *capture = (DecklinkCapture *)calloc(1, sizeof(*capture)); BMDPixelFormat pix[] = { bmdFormat8BitYUV, bmdFormat10BitYUV, bmdFormat8BitARGB, bmdFormat10BitRGB, bmdFormat8BitBGRA }; BMDDisplayMode display_mode = -1; QueryDelegate *delegate; HRESULT ret; int i = 0; int result = -1; IDeckLinkAttributes* deckLinkAttributes; bool formatDetectionSupported; if (!capture) goto fail; capture->it = CreateDeckLinkIteratorInstance(); if (!capture->it) goto fail; switch (c->audio_channels) { case 0: c->audio_channels = 2; case 2: case 8: case 16: break; default: goto fail; } switch (c->audio_sample_depth) { case 0: c->audio_sample_depth = 16; case 16: case 32: break; default: goto fail; } if (c->pixel_format >= sizeof(pix)) goto fail; do { ret = capture->it->Next(&capture->dl); } while (i++ < c->instance); if (ret != S_OK) goto fail; ret = capture->dl->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (ret != S_OK) { goto fail; } ret = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &formatDetectionSupported); if (ret != S_OK) { goto fail; } if (!formatDetectionSupported) { goto fail; } ret = capture->dl->QueryInterface(IID_IDeckLinkInput, (void**)&capture->in); if (ret != S_OK) goto fail; ret = capture->dl->QueryInterface(IID_IDeckLinkConfiguration, (void**)&capture->conf); switch (c->audio_connection) { case 1: ret = capture->conf->SetInt(bmdDeckLinkConfigAudioInputConnection, bmdAudioConnectionAnalog); break; case 2: ret = capture->conf->SetInt(bmdDeckLinkConfigAudioInputConnection, bmdAudioConnectionEmbedded); break; default: // do not change it break; } if (ret != S_OK) { goto fail; } switch (c->video_connection) { case 1: ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection, bmdVideoConnectionComposite); break; case 2: ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection, bmdVideoConnectionComponent); break; case 3: ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection, bmdVideoConnectionHDMI); break; case 4: ret = capture->conf->SetInt(bmdDeckLinkConfigVideoInputConnection, bmdVideoConnectionSDI); break; default: // do not change it break; } if (ret != S_OK) { goto fail; } ret = capture->in->GetDisplayModeIterator(&capture->dm_it); if (ret != S_OK) { goto fail; } i = 0; while (true) { if (capture->dm_it->Next(&capture->dm) != S_OK) { capture->dm->Release(); } else { result = i; break; } i++; } if (result == -1) { return -1; } c->width = capture->dm->GetWidth(); c->height = capture->dm->GetHeight(); switch (capture->dm->GetFieldDominance()) { case bmdUnknownFieldDominance: c->field_mode = 0; break; case bmdLowerFieldFirst: c->field_mode = 1; break; case bmdUpperFieldFirst: c->field_mode = 2; break; case bmdProgressiveFrame: c->field_mode = 3; break; case bmdProgressiveSegmentedFrame: c->field_mode = 4; break; default: goto fail; } capture->dm->GetFrameRate(&c->tb_num, &c->tb_den); delegate = new QueryDelegate(capture->dm->GetDisplayMode()); if (!delegate) goto fail; capture->in->SetCallback(delegate); ret = capture->in->EnableVideoInput(capture->dm->GetDisplayMode(), pix[c->pixel_format], bmdVideoInputEnableFormatDetection); ret = capture->in->StartStreams(); if (ret != S_OK) { goto fail; } while (!delegate->isDone()) { usleep(20000); } ret = capture->in->StopStreams(); if (ret != S_OK) { goto fail; } if (delegate->GetDisplayMode()) { ret = capture->in->GetDisplayModeIterator(&capture->dm_it); if (ret != S_OK) { goto fail; } i = 0; while (capture->dm_it->Next(&capture->dm) == S_OK) { BMDDisplayMode display_mode = capture->dm->GetDisplayMode(); capture->dm->Release(); if (display_mode == delegate->GetDisplayMode()) { result = i; } i++; } } fail: decklink_capture_free(capture); return result; }
static void print_capabilities (IDeckLink* deckLink) { IDeckLinkAttributes* deckLinkAttributes = NULL; int64_t ports; int itemCount; HRESULT result; // Query the DeckLink for its configuration interface result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (result != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface - result = %08x\n", result); goto bail; } printf("Supported video output connections:\n "); itemCount = 0; result = deckLinkAttributes->GetInt(BMDDeckLinkVideoOutputConnections, &ports); if (result == S_OK) { if (ports & bmdVideoConnectionSDI) { itemCount++; printf("SDI"); } if (ports & bmdVideoConnectionHDMI) { if (itemCount++ > 0) printf(", "); printf("HDMI"); } if (ports & bmdVideoConnectionOpticalSDI) { if (itemCount++ > 0) printf(", "); printf("Optical SDI"); } if (ports & bmdVideoConnectionComponent) { if (itemCount++ > 0) printf(", "); printf("Component"); } if (ports & bmdVideoConnectionComposite) { if (itemCount++ > 0) printf(", "); printf("Composite"); } if (ports & bmdVideoConnectionSVideo) { if (itemCount++ > 0) printf(", "); printf("S-Video"); } } else { fprintf(stderr, "Could not obtain the list of output ports - result = %08x\n", result); goto bail; } printf("\n\n"); printf("Supported video input connections:\n "); itemCount = 0; result = deckLinkAttributes->GetInt(BMDDeckLinkVideoInputConnections, &ports); if (result == S_OK) { if (ports & bmdVideoConnectionSDI) { itemCount++; printf("SDI"); } if (ports & bmdVideoConnectionHDMI) { if (itemCount++ > 0) printf(", "); printf("HDMI"); } if (ports & bmdVideoConnectionOpticalSDI) { if (itemCount++ > 0) printf(", "); printf("Optical SDI"); } if (ports & bmdVideoConnectionComponent) { if (itemCount++ > 0) printf(", "); printf("Component"); } if (ports & bmdVideoConnectionComposite) { if (itemCount++ > 0) printf(", "); printf("Composite"); } if (ports & bmdVideoConnectionSVideo) { if (itemCount++ > 0) printf(", "); printf("S-Video"); } } else { fprintf(stderr, "Could not obtain the list of input ports - result = %08x\n", result); goto bail; } printf("\n"); bail: if (deckLinkAttributes != NULL) deckLinkAttributes->Release(); }
/** * process the arugments * return negative value of failed */ int Window::processArguments(int argc, char* argv[]){ IDeckLinkAttributes *deckLinkAttributes = NULL; DeckLinkCaptureDelegate *delegate; IDeckLinkDisplayMode *displayMode; BMDVideoInputFlags inputFlags = 0; BMDDisplayMode selectedDisplayMode = bmdModeNTSC; BMDPixelFormat pixelFormat = bmdFormat8BitYUV; int displayModeCount = 0; int exitStatus = 1; int ch; bool foundDisplayMode = false; HRESULT result; int dnum = 0; IDeckLink *tempLink = NULL; int found = 0; bool supported = 0; int64_t ports; int itemCount; int vinput = 0; int64_t vport = 0; IDeckLinkConfiguration *deckLinkConfiguration = NULL; bool flickerremoval = true; bool pnotpsf = true; // Parse command line options while ((ch = getopt(argc, argv, "?h3c:d:s:f:a:m:n:p:t:u::vi:jy")) != -1) { switch (ch) { case 'i': vinput = atoi(optarg); break; case 'd': card = atoi(optarg); break; case 'm': g_videoModeIndex = atoi(optarg); break; case 'n': g_maxFrames = atoi(optarg); break; case '3': inputFlags |= bmdVideoInputDualStream3D; break; case 'p': switch(atoi(optarg)) { case 0: pixelFormat = bmdFormat8BitYUV; break; case 1: pixelFormat = bmdFormat10BitYUV; break; case 2: pixelFormat = bmdFormat10BitRGB; break; default: fprintf(stderr, "Invalid argument: Pixel format %d is not valid", atoi(optarg)); exit(1); } break; case 't': if (!strcmp(optarg, "rp188")) g_timecodeFormat = bmdTimecodeRP188Any; else if (!strcmp(optarg, "vitc")) g_timecodeFormat = bmdTimecodeVITC; else if (!strcmp(optarg, "serial")) g_timecodeFormat = bmdTimecodeSerial; else { fprintf(stderr, "Invalid argument: Timecode format \"%s\" is invalid\n", optarg); exit(1); } break; case '?': case 'h': usage(); } } if (!deckLinkIterator) { fprintf(stderr, "This application requires the DeckLink drivers installed.\n"); return -1; } /* Connect to the first DeckLink instance */ while (deckLinkIterator->Next(&tempLink) == S_OK) { if (card != dnum) { dnum++; // Release the IDeckLink instance when we've finished with it to prevent leaks tempLink->Release(); continue; } else { deckLink = tempLink; found = 1; } dnum++; } if (! found ) { fprintf(stderr, "No DeckLink PCI cards found.\n"); return -1; } if (deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput) != S_OK) return -1; // Query the DeckLink for its attributes interface result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (result != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface - result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supported); if (result == S_OK) { fprintf(stderr, " %-40s %s\n", "Input mode detection supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the input mode detection attribute- result = %08x\n", result); } fprintf(stderr, "Supported video input connections (-i [input #]:\n "); itemCount = 0; result = deckLinkAttributes->GetInt(BMDDeckLinkVideoInputConnections, &ports); if (result == S_OK) { if (ports & bmdVideoConnectionSDI) { fprintf(stderr, "%d: SDI, ", bmdVideoConnectionSDI); itemCount++; } if (ports & bmdVideoConnectionHDMI) { fprintf(stderr, "%d: HDMI, ", bmdVideoConnectionHDMI); itemCount++; } if (ports & bmdVideoConnectionOpticalSDI) { fprintf(stderr, "%d: Optical SDI, ", bmdVideoConnectionOpticalSDI); itemCount++; } if (ports & bmdVideoConnectionComponent) { fprintf(stderr, "%d: Component, ", bmdVideoConnectionComponent); itemCount++; } if (ports & bmdVideoConnectionComposite) { fprintf(stderr, "%d: Composite, ", bmdVideoConnectionComposite); itemCount++; } if (ports & bmdVideoConnectionSVideo) { fprintf(stderr, "%d: S-Video, ", bmdVideoConnectionSVideo); itemCount++; } } fprintf(stderr, "\n"); //glWidget->initShaderProgram(); delegate = new DeckLinkCaptureDelegate(glWidget); connect(delegate, SIGNAL(updateGLSignal()), glWidget, SLOT(updateGLSlot())); deckLinkInput->SetCallback(delegate); // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator); if (result != S_OK) { fprintf(stderr, "Could not obtain the video output display mode iterator - result = %08x\n", result); return -1; } if (g_videoModeIndex < 0) { fprintf(stderr, "No video mode specified\n"); usage(); return -1; } while (displayModeIterator->Next(&displayMode) == S_OK) { if (g_videoModeIndex == displayModeCount) { BMDDisplayModeSupport result; const char *displayModeName; foundDisplayMode = true; displayMode->GetName(&displayModeName); selectedDisplayMode = displayMode->GetDisplayMode(); deckLinkInput->DoesSupportVideoMode(selectedDisplayMode, pixelFormat, bmdVideoInputFlagDefault, &result, NULL); if (result == bmdDisplayModeNotSupported) { fprintf(stderr, "The display mode %s is not supported with the selected pixel format\n", displayModeName); return -1; } if (inputFlags & bmdVideoInputDualStream3D) { if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D)) { fprintf(stderr, "The display mode %s is not supported with 3D\n", displayModeName); return -1; } } fprintf(stderr, "Selecting mode: %s\n", displayModeName); break; } displayModeCount++; displayMode->Release(); } if (!foundDisplayMode) { fprintf(stderr, "Invalid mode %d specified\n", g_videoModeIndex); return -1; } // Query the DeckLink for its configuration interface result = deckLinkInput->QueryInterface(IID_IDeckLinkConfiguration, (void**)&deckLinkConfiguration); if (result != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkConfiguration interface: %08x\n", result); } BMDVideoConnection conn; switch (vinput) { case 0: conn = bmdVideoConnectionSDI; break; case 1: conn = bmdVideoConnectionHDMI; break; case 2: conn = bmdVideoConnectionComponent; break; case 3: conn = bmdVideoConnectionComposite; break; case 4: conn = bmdVideoConnectionSVideo; break; case 5: conn = bmdVideoConnectionOpticalSDI; break; default: break; } conn = vinput; // Set the input desired result = deckLinkConfiguration->SetInt(bmdDeckLinkConfigVideoInputConnection, conn); if(result != S_OK) { fprintf(stderr, "Cannot set the input to [%d]\n", conn); return -1; } // check input result = deckLinkConfiguration->GetInt(bmdDeckLinkConfigVideoInputConnection, &vport); if (vport == bmdVideoConnectionSDI) fprintf(stderr, "Before Input configured for SDI\n"); if (vport == bmdVideoConnectionHDMI) fprintf(stderr, "Before Input configured for HDMI\n"); if (deckLinkConfiguration->SetFlag(bmdDeckLinkConfigFieldFlickerRemoval, flickerremoval) == S_OK) { fprintf(stderr, "Flicker removal set : %d\n", flickerremoval); } else { fprintf(stderr, "Flicker removal NOT set\n"); } if (deckLinkConfiguration->SetFlag(bmdDeckLinkConfigUse1080pNotPsF, pnotpsf) == S_OK) { fprintf(stderr, "bmdDeckLinkConfigUse1080pNotPsF: %d\n", pnotpsf); } else { fprintf(stderr, "bmdDeckLinkConfigUse1080pNotPsF NOT set\n"); } //if (deckLinkConfiguration->SetFlag(bmdDeckLinkConfigVideoInputConnection, conn) == S_OK) { //fprintf(stderr, "Input set to: %d\n", vinput); //} result = deckLinkConfiguration->GetInt(bmdDeckLinkConfigVideoInputConnection, &vport); if (vport == bmdVideoConnectionSDI) fprintf(stderr, "After Input configured for SDI\n"); if (vport == bmdVideoConnectionHDMI) fprintf(stderr, "After Input configured for HDMI\n"); result = deckLinkInput->EnableVideoInput(selectedDisplayMode, pixelFormat, inputFlags); if(result != S_OK) { fprintf(stderr, "Failed to enable video input. Is another application using the card?\n"); return -1; } displayWidth = displayMode->GetWidth(); displayHeight = displayMode->GetHeight(); displayMode->GetFrameRate(&frameRateDuration, &frameRateScale); displayFPS = (double)frameRateScale / (double)frameRateDuration; //set to delegate delegate->setWidth(displayWidth); delegate->setHeight(displayHeight); delegate->setFPS(displayFPS); delegate->setFrameRateDuration(frameRateDuration); delegate->setFrameRateScale(frameRateScale); //set texture width and height glWidget->setTextureWidth(displayWidth); glWidget->setTextureHeight(displayHeight); glWidget->initBuffer(); fprintf(stderr, "GetFrameRate: %10ld %10ld --> fps %g\n", (long)frameRateScale, (long)frameRateDuration, displayFPS); result = deckLinkInput->StartStreams(); if(result != S_OK){ fprintf(stderr, "Cannot start streams...\n"); return -1; } fprintf(stderr, "Finish procesing arguments \n"); }
static void print_attributes (IDeckLink* deckLink) { IDeckLinkAttributes* deckLinkAttributes = NULL; bool supported; int64_t count; char * serialPortName = NULL; HRESULT result; // Query the DeckLink for its attributes interface result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (result != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface - result = %08x\n", result); goto bail; } // List attributes and their value printf("Attribute list:\n"); result = deckLinkAttributes->GetFlag(BMDDeckLinkHasSerialPort, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Serial port present ?", (supported == true) ? "Yes" : "No"); if (supported) { CFStringRef serialPortNameString = CFStringCreateWithCString(kCFAllocatorDefault, serialPortName, kCFStringEncodingMacRoman); result = deckLinkAttributes->GetString(BMDDeckLinkSerialPortDeviceName, &serialPortNameString); if (result == S_OK) { printf(" %-40s %s\n", "Serial port name: ", serialPortName); free(serialPortName); } else { fprintf(stderr, "Could not query the serial port presence attribute- result = %08x\n", result); } } } else { fprintf(stderr, "Could not query the serial port presence attribute- result = %08x\n", result); } result = deckLinkAttributes->GetInt(BMDDeckLinkNumberOfSubDevices, &count); if (result == S_OK) { printf(" %-40s %lld\n", "Number of sub-devices:", count); if (count != 0) { result = deckLinkAttributes->GetInt(BMDDeckLinkSubDeviceIndex, &count); if (result == S_OK) { printf(" %-40s %lld\n", "Sub-device index:", count); } else { fprintf(stderr, "Could not query the sub-device index attribute- result = %08x\n", result); } } } else { fprintf(stderr, "Could not query the number of sub-device attribute- result = %08x\n", result); } result = deckLinkAttributes->GetInt(BMDDeckLinkMaximumAudioChannels, &count); if (result == S_OK) { printf(" %-40s %lld\n", "Number of audio channels:", count); } else { fprintf(stderr, "Could not query the number of supported audio channels attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Input mode detection supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the input mode detection attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInternalKeying, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Internal keying supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the internal keying attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsExternalKeying, &supported); if (result == S_OK) { printf(" %-40s %s\n", "External keying supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the external keying attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsHDKeying, &supported); if (result == S_OK) { printf(" %-40s %s\n", "HD-mode keying supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the HD-mode keying attribute- result = %08x\n", result); } bail: printf("\n"); if(deckLinkAttributes != NULL) deckLinkAttributes->Release(); }
int main(int argc, char *argv[]) { HRESULT result; int exitStatus = 1; int idx; IDeckLinkIterator* deckLinkIterator = NULL; IDeckLink* deckLink = NULL; IDeckLinkAttributes* deckLinkAttributes = NULL; bool formatDetectionSupported; IDeckLinkDisplayModeIterator* displayModeIterator = NULL; IDeckLinkDisplayMode* displayMode = NULL; char* displayModeName = NULL; BMDDisplayModeSupport displayModeSupported; DeckLinkCaptureDelegate* delegate = NULL; pthread_mutex_init(&g_sleepMutex, NULL); pthread_cond_init(&g_sleepCond, NULL); signal(SIGINT, sigfunc); signal(SIGTERM, sigfunc); signal(SIGHUP, sigfunc); // Network g_video_sock = socket(AF_INET, SOCK_STREAM, 0); g_video_addr.sin_family = AF_INET; g_video_addr.sin_port = htons(62310); g_video_addr.sin_addr.s_addr = inet_addr("192.168.100.31"); connect(g_video_sock, (struct sockaddr *)&g_video_addr, sizeof(g_video_addr)); g_audio_sock = socket(AF_INET, SOCK_STREAM, 0); g_audio_addr.sin_family = AF_INET; g_audio_addr.sin_port = htons(62311); g_audio_addr.sin_addr.s_addr = inet_addr("192.168.100.31"); connect(g_audio_sock, (struct sockaddr *)&g_audio_addr, sizeof(g_audio_addr)); // Process the command line arguments if (!g_config.ParseArguments(argc, argv)) { g_config.DisplayUsage(exitStatus); goto bail; } // Get the DeckLink device deckLinkIterator = CreateDeckLinkIteratorInstance(); if (!deckLinkIterator) { fprintf(stderr, "This application requires the DeckLink drivers installed.\n"); goto bail; } idx = g_config.m_deckLinkIndex; while ((result = deckLinkIterator->Next(&deckLink)) == S_OK) { if (idx == 0) break; --idx; deckLink->Release(); } if (result != S_OK || deckLink == NULL) { fprintf(stderr, "Unable to get DeckLink device %u\n", g_config.m_deckLinkIndex); goto bail; } // Get the input (capture) interface of the DeckLink device result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&g_deckLinkInput); if (result != S_OK) goto bail; // Get the display mode if (g_config.m_displayModeIndex == -1) { // Check the card supports format detection result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (result == S_OK) { result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &formatDetectionSupported); if (result != S_OK || !formatDetectionSupported) { fprintf(stderr, "Format detection is not supported on this device\n"); goto bail; } } g_config.m_inputFlags |= bmdVideoInputEnableFormatDetection; // Format detection still needs a valid mode to start with idx = 0; } else { idx = g_config.m_displayModeIndex; } result = g_deckLinkInput->GetDisplayModeIterator(&displayModeIterator); if (result != S_OK) { goto bail; } while ((result = displayModeIterator->Next(&displayMode)) == S_OK) { if (idx == 0) { break; } --idx; displayMode->Release(); } if (result != S_OK || displayMode == NULL) { fprintf(stderr, "Unable to get display mode %d\n", g_config.m_displayModeIndex); goto bail; } // Get display mode name result = displayMode->GetName((const char**)&displayModeName); if (result != S_OK) { displayModeName = (char *)malloc(32); snprintf(displayModeName, 32, "[index %d]", g_config.m_displayModeIndex); } // Check display mode is supported with given options result = g_deckLinkInput->DoesSupportVideoMode(displayMode->GetDisplayMode(), g_config.m_pixelFormat, bmdVideoInputFlagDefault, &displayModeSupported, NULL); if (result != S_OK) goto bail; if (displayModeSupported == bmdDisplayModeNotSupported) { fprintf(stderr, "The display mode %s is not supported with the selected pixel format\n", displayModeName); goto bail; } if (g_config.m_inputFlags & bmdVideoInputDualStream3D) { if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D)) { fprintf(stderr, "The display mode %s is not supported with 3D\n", displayModeName); goto bail; } } // Print the selected configuration g_config.DisplayConfiguration(); // Configure the capture callback delegate = new DeckLinkCaptureDelegate(); g_deckLinkInput->SetCallback(delegate); // Open output files // if (g_config.m_videoOutputFile != NULL) // { // g_videoOutputFile = open(g_config.m_videoOutputFile, O_WRONLY|O_CREAT|O_TRUNC, 0664); // if (g_videoOutputFile < 0) // { // fprintf(stderr, "Could not open video output file \"%s\"\n", g_config.m_videoOutputFile); // goto bail; // } // } // // if (g_config.m_audioOutputFile != NULL) // { // g_audioOutputFile = open(g_config.m_audioOutputFile, O_WRONLY|O_CREAT|O_TRUNC, 0664); // if (g_audioOutputFile < 0) // { // fprintf(stderr, "Could not open audio output file \"%s\"\n", g_config.m_audioOutputFile); // goto bail; // } // } // Block main thread until signal occurs while (!g_do_exit) { // Start capturing result = g_deckLinkInput->EnableVideoInput(displayMode->GetDisplayMode(), g_config.m_pixelFormat, g_config.m_inputFlags); if (result != S_OK) { fprintf(stderr, "Failed to enable video input. Is another application using the card?\n"); goto bail; } result = g_deckLinkInput->EnableAudioInput(bmdAudioSampleRate48kHz, g_config.m_audioSampleDepth, g_config.m_audioChannels); if (result != S_OK) goto bail; result = g_deckLinkInput->StartStreams(); if (result != S_OK) goto bail; // All Okay. exitStatus = 0; pthread_mutex_lock(&g_sleepMutex); pthread_cond_wait(&g_sleepCond, &g_sleepMutex); pthread_mutex_unlock(&g_sleepMutex); fprintf(stderr, "Stopping Capture\n"); g_deckLinkInput->StopStreams(); g_deckLinkInput->DisableAudioInput(); g_deckLinkInput->DisableVideoInput(); } bail: if (g_videoOutputFile != 0) close(g_videoOutputFile); if (g_audioOutputFile != 0) close(g_audioOutputFile); if (displayModeName != NULL) free(displayModeName); if (displayMode != NULL) displayMode->Release(); if (displayModeIterator != NULL) displayModeIterator->Release(); if (g_deckLinkInput != NULL) { g_deckLinkInput->Release(); g_deckLinkInput = NULL; } if (deckLinkAttributes != NULL) deckLinkAttributes->Release(); if (deckLink != NULL) deckLink->Release(); if (deckLinkIterator != NULL) deckLinkIterator->Release(); close(g_video_sock); close(g_audio_sock); return exitStatus; }
bool start( mlt_profile profile = 0 ) { if ( m_started ) return false; try { // Initialize some members m_vancLines = mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( getProducer() ), "vanc" ); if ( m_vancLines == -1 ) m_vancLines = profile->height <= 512 ? 26 : 32; if ( !profile ) profile = mlt_service_profile( MLT_PRODUCER_SERVICE( getProducer() ) ); // Get the display mode BMDDisplayMode displayMode = getDisplayMode( profile, m_vancLines ); if ( displayMode == (BMDDisplayMode) bmdDisplayModeNotSupported ) { mlt_log_info( getProducer(), "profile = %dx%d %f fps %s\n", profile->width, profile->height, mlt_profile_fps( profile ), profile->progressive? "progressive" : "interlace" ); throw "Profile is not compatible with decklink."; } // Determine if supports input format detection #ifdef WIN32 BOOL doesDetectFormat = FALSE; #else bool doesDetectFormat = false; #endif IDeckLinkAttributes *decklinkAttributes = 0; if ( m_decklink->QueryInterface( IID_IDeckLinkAttributes, (void**) &decklinkAttributes ) == S_OK ) { if ( decklinkAttributes->GetFlag( BMDDeckLinkSupportsInputFormatDetection, &doesDetectFormat ) != S_OK ) doesDetectFormat = false; SAFE_RELEASE( decklinkAttributes ); } mlt_log_verbose( getProducer(), "%s format detection\n", doesDetectFormat ? "supports" : "does not support" ); // Enable video capture BMDPixelFormat pixelFormat = bmdFormat8BitYUV; BMDVideoInputFlags flags = doesDetectFormat ? bmdVideoInputEnableFormatDetection : bmdVideoInputFlagDefault; if ( S_OK != m_decklinkInput->EnableVideoInput( displayMode, pixelFormat, flags ) ) throw "Failed to enable video capture."; // Enable audio capture BMDAudioSampleRate sampleRate = bmdAudioSampleRate48kHz; BMDAudioSampleType sampleType = bmdAudioSampleType16bitInteger; int channels = mlt_properties_get_int( MLT_PRODUCER_PROPERTIES( getProducer() ), "channels" ); if ( S_OK != m_decklinkInput->EnableAudioInput( sampleRate, sampleType, channels ) ) throw "Failed to enable audio capture."; // Start capture m_dropped = 0; mlt_properties_set_int( MLT_PRODUCER_PROPERTIES( getProducer() ), "dropped", m_dropped ); m_started = m_decklinkInput->StartStreams() == S_OK; if ( !m_started ) throw "Failed to start capture."; } catch ( const char *error ) { m_decklinkInput->DisableVideoInput(); mlt_log_error( getProducer(), "%s\n", error ); return false; } return true; }
void BMDConfig::DisplayUsage(int status) { HRESULT result = E_FAIL; IDeckLinkIterator* deckLinkIterator = CreateDeckLinkIteratorInstance(); IDeckLinkDisplayModeIterator* displayModeIterator = NULL; IDeckLink* deckLink = NULL; IDeckLink* deckLinkSelected = NULL; int deckLinkCount = 0; char* deckLinkName = NULL; IDeckLinkAttributes* deckLinkAttributes = NULL; bool formatDetectionSupported; IDeckLinkInput* deckLinkInput = NULL; IDeckLinkDisplayMode* displayModeUsage; int displayModeCount = 0; char* displayModeName; fprintf(stderr, "Usage: Capture -d <device id> -m <mode id> [OPTIONS]\n" "\n" " -d <device id>:\n" ); // Loop through all available devices while (deckLinkIterator->Next(&deckLink) == S_OK) { result = deckLink->GetModelName((const char**)&deckLinkName); if (result == S_OK) { fprintf(stderr, " %2d: %s%s\n", deckLinkCount, deckLinkName, deckLinkCount == m_deckLinkIndex ? " (selected)" : "" ); free(deckLinkName); } if (deckLinkCount == m_deckLinkIndex) deckLinkSelected = deckLink; else deckLink->Release(); ++deckLinkCount; } if (deckLinkCount == 0) fprintf(stderr, " No DeckLink devices found. Is the driver loaded?\n"); deckLinkName = NULL; if (deckLinkSelected != NULL) deckLinkSelected->GetModelName((const char**)&deckLinkName); fprintf(stderr, " -m <mode id>: (%s)\n", deckLinkName ? deckLinkName : "" ); if (deckLinkName != NULL) free(deckLinkName); // Loop through all available display modes on the delected DeckLink device if (deckLinkSelected == NULL) { fprintf(stderr, " No DeckLink device selected\n"); goto bail; } result = deckLinkSelected->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (result == S_OK) { result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &formatDetectionSupported); if (result == S_OK && formatDetectionSupported) fprintf(stderr, " -1: auto detect format\n"); } result = deckLinkSelected->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput); if (result != S_OK) goto bail; result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator); if (result != S_OK) goto bail; while (displayModeIterator->Next(&displayModeUsage) == S_OK) { result = displayModeUsage->GetName((const char **)&displayModeName); if (result == S_OK) { BMDTimeValue frameRateDuration; BMDTimeValue frameRateScale; displayModeUsage->GetFrameRate(&frameRateDuration, &frameRateScale); fprintf(stderr, " %2d: %-20s \t %li x %li \t %g FPS\n", displayModeCount, displayModeName, displayModeUsage->GetWidth(), displayModeUsage->GetHeight(), (double)frameRateScale / (double)frameRateDuration ); free(displayModeName); } displayModeUsage->Release(); ++displayModeCount; } bail: fprintf(stderr, " -p <pixelformat>\n" " 0: 8 bit YUV (4:2:2) (default)\n" " 1: 10 bit YUV (4:2:2)\n" " 2: 10 bit RGB (4:4:4)\n" " -t <format> Print timecode\n" " rp188: RP 188\n" " vitc: VITC\n" " serial: Serial Timecode\n" " -v <filename> Filename raw video will be written to\n" " -a <filename> Filename raw audio will be written to\n" " -l <lcm channel> Channel name to publish images to LCM\n" " -q <jpeg quality> JPEG compression quality for LCM images (1-100 - default is 90)\n" " -c <channels> Audio Channels (2, 8 or 16 - default is 2)\n" " -s <depth> Audio Sample Depth (16 or 32 - default is 16)\n" " -n <frames> Number of frames to capture (default is unlimited)\n" " -3 Capture Stereoscopic 3D (Requires 3D Hardware support)\n" "\n" "Capture video and/or audio to a file. Raw video and/or audio can be viewed with mplayer eg:\n" "\n" " Capture -d 0 -m 2 -n 50 -v video.raw -a audio.raw\n" " mplayer video.raw -demuxer rawvideo -rawvideo pal:uyvy -audiofile audio.raw -audio-demuxer 20 -rawaudio rate=48000\n" "\n" "LCM capture example command line:\n" "\n" " DecklinkCapture -d 0 -m 14 -q 95 -l DECKLINK_VIDEO_CAPTURE\n" "\n" ); if (deckLinkIterator != NULL) deckLinkIterator->Release(); if (displayModeIterator != NULL) displayModeIterator->Release(); if (deckLinkInput != NULL) deckLinkInput->Release(); if (deckLinkAttributes != NULL) deckLinkAttributes->Release(); if (deckLinkSelected != NULL) deckLinkSelected->Release(); exit(status); }
int _tmain(int argc, _TCHAR* argv[]) { int numDevices = 0; HRESULT result; IDeckLinkAttributes *deckLinkAttributes = NULL; HRESULT attributeResult; BOOL keyingSupported; BOOL HDkeyingSupported; int selectedMode = 0; printf("GDI Keyer Sample Application\n\n"); // Initialize COM on this thread result = CoInitialize(NULL); if (FAILED(result)) { fprintf(stderr, "Initialization of COM failed - result = %08x.\n", result); return 1; } // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system result = CoCreateInstance(CLSID_CDeckLinkIterator, NULL, CLSCTX_ALL, IID_IDeckLinkIterator, (void**)&deckLinkIterator); if (FAILED(result)) { fprintf(stderr, "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.\n"); return 1; } // Enumerate all cards in this system while (deckLinkIterator->Next(&deckLink) == S_OK) { BSTR deviceNameBSTR = NULL; // Increment the total number of DeckLink cards found numDevices++; if (numDevices > 1) printf("\n\n"); // *** Print the model name of the DeckLink card result = deckLink->GetModelName(&deviceNameBSTR); if (result == S_OK) { _bstr_t deviceName(deviceNameBSTR); printf("Found Blackmagic device: %s\n", (char*)deviceName); attributeResult = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (attributeResult != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface"); return 1; } else { attributeResult = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInternalKeying, &keyingSupported); // is keying supported on this device? if (attributeResult == S_OK && keyingSupported) { IDeckLinkDisplayModeIterator* displayModeIterator = NULL; IDeckLinkDisplayMode* deckLinkDisplayMode = NULL; attributeResult = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsHDKeying, &HDkeyingSupported); if (attributeResult == S_OK && HDkeyingSupported) printf("HD Mode keying supported.\n"); else printf("SD Mode Keying supported.\n"); // check if automode detection support - if so, use it for autodetection if (CheckFormatDetect(deckLinkAttributes) == 0) { fprintf(stderr, "Input mode detection not supported\n"); if (deckLink->QueryInterface(IID_IDeckLinkOutput, (void**)&deckLinkOutput) != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkOutput interface\n"); } else { int index = 0; if (deckLinkOutput->GetDisplayModeIterator(&displayModeIterator) != S_OK) { fprintf(stderr, "Could not obtain the display mode iterator\n"); } else { printf("\n"); while (displayModeIterator->Next(&deckLinkDisplayMode) == S_OK) { BSTR displayModeBSTR = NULL; int modeWidth; int modeHeight; BMDTimeValue frameRateDuration; BMDTimeScale frameRateScale; // Obtain the display mode's properties modeWidth = deckLinkDisplayMode->GetWidth(); modeHeight = deckLinkDisplayMode->GetHeight(); deckLinkDisplayMode->GetFrameRate(&frameRateDuration, &frameRateScale); if ((deckLinkDisplayMode->GetWidth() > 720) && !HDkeyingSupported) continue; if (deckLinkDisplayMode->GetName(&displayModeBSTR) == S_OK) { _bstr_t modeName(displayModeBSTR, false); // Skip HD modes on cards such as DeckLink SDI (only PAL/NTSC are supported for keying) printf("%d %-20s \t %d x %d \t %g FPS\n", index, (char*)modeName, modeWidth, modeHeight, (double)frameRateScale / (double)frameRateDuration); } deckLinkDisplayMode->Release(); index++; } displayModeIterator->Release(); printf("Select Mode (0-%d):\n", index-1); scanf_s("%d", &selectedMode); printf("Mode selected: %d\n", selectedMode); if(selectedMode < index) { int modeCount = 0; if (deckLinkOutput->GetDisplayModeIterator(&displayModeIterator) != S_OK) { fprintf(stderr, "Could not obtain the display mode iterator\n"); } else { while(displayModeIterator->Next(&deckLinkDisplayMode) == S_OK) { if (selectedMode == modeCount) { OutputGraphic(deckLinkDisplayMode); deckLinkDisplayMode->Release(); break; } deckLinkDisplayMode->Release(); modeCount++; } displayModeIterator->Release(); } } else { printf("Illegal video mode selected\n"); } } deckLinkOutput->Release(); } } } deckLinkAttributes->Release(); printf("Press Enter key to exit.\n"); _getch(); } } deckLink->Release(); // Release the IDeckLink instance when we've finished with it to prevent leaks } if (deckLinkIterator != NULL) deckLinkIterator->Release(); // If no DeckLink cards were found in the system, inform the users if (numDevices == 0) printf("No Blackmagic Design devices were found.\n"); // Uninitalize COM on this thread CoUninitialize(); return 0; }
int main (int argc, char* argv[]) { printf("DeckControl Test Application\n\n"); IDeckLinkIterator* deckLinkIterator; IDeckLink* deckLink; int numDevices = 0; HRESULT result; fdSerial = -1; // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system deckLinkIterator = CreateDeckLinkIteratorInstance(); if (deckLinkIterator == NULL) { fprintf(stderr, "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.\n"); return 1; } // Enumerate all cards in this system while (deckLinkIterator->Next(&deckLink) == S_OK) { CFStringRef deviceNameCFString = NULL; // Increment the total number of DeckLink cards found numDevices++; if (numDevices > 1) printf("\n\n"); // *** Print the model name of the DeckLink card result = deckLink->GetModelName(&deviceNameCFString); if (result == S_OK) { IDeckLinkAttributes* deckLinkAttributes; char deviceName[64]; HRESULT attributeResult; CFStringRef serialName; bool serialSupported; CFStringGetCString(deviceNameCFString, deviceName, sizeof(deviceName), kCFStringEncodingMacRoman); printf("Found Blackmagic device: %s\n", deviceName); attributeResult = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (attributeResult != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface"); } else { attributeResult = deckLinkAttributes->GetFlag(BMDDeckLinkHasSerialPort, &serialSupported); // are serial ports supported on device? if (attributeResult == S_OK && serialSupported) { attributeResult = deckLinkAttributes->GetString(BMDDeckLinkSerialPortDeviceName, &serialName); // get serial port name if (attributeResult == S_OK) { char portName[64]; CFStringGetCString(serialName, portName, sizeof(portName), kCFStringEncodingMacRoman); printf("Serial port name: %s\n",portName); if (openSerialDevice((char*)&portName)== true) // open serial port { printf("Device opened\n"); playCommand(); // Play deck, printf("Delay 3 seconds\n"); sleep(3); timeCodeCommand(); // DisplayTC printf("Delay 3 seconds\n"); sleep(3); stopCommand(); // Stop deck closeSerialDevice(); // close serial port } else printf("Device open fail\n"); CFRelease(serialName); } else printf("Unable to get serial port device name\n"); } else printf("Serial port not supported\n"); } CFRelease(deviceNameCFString); // Release the IDeckLink instance when we've finished with it to prevent leaks } deckLink->Release(); } if (deckLinkIterator) deckLinkIterator->Release(); // If no DeckLink cards were found in the system, inform the user if (numDevices == 0) printf("No Blackmagic Design devices were found.\n"); printf("\n"); return 0; }
DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index) : card_index(card_index) { { const char *model_name; char buf[256]; if (card->GetModelName(&model_name) == S_OK) { snprintf(buf, sizeof(buf), "PCI card %d: %s", card_index, model_name); } else { snprintf(buf, sizeof(buf), "PCI card %d: Unknown DeckLink card", card_index); } description = buf; } if (card->QueryInterface(IID_IDeckLinkInput, (void**)&input) != S_OK) { fprintf(stderr, "Card %d has no inputs\n", card_index); exit(1); } IDeckLinkAttributes *attr; if (card->QueryInterface(IID_IDeckLinkAttributes, (void**)&attr) != S_OK) { fprintf(stderr, "Card %d has no attributes\n", card_index); exit(1); } // Get the list of available video inputs. int64_t video_input_mask; if (attr->GetInt(BMDDeckLinkVideoInputConnections, &video_input_mask) != S_OK) { fprintf(stderr, "Failed to enumerate video inputs for card %d\n", card_index); exit(1); } const vector<pair<BMDVideoConnection, string>> video_input_types = { { bmdVideoConnectionSDI, "SDI" }, { bmdVideoConnectionHDMI, "HDMI" }, { bmdVideoConnectionOpticalSDI, "Optical SDI" }, { bmdVideoConnectionComponent, "Component" }, { bmdVideoConnectionComposite, "Composite" }, { bmdVideoConnectionSVideo, "S-Video" } }; for (const auto &video_input : video_input_types) { if (video_input_mask & video_input.first) { video_inputs.emplace(video_input.first, video_input.second); } } // And then the available audio inputs. int64_t audio_input_mask; if (attr->GetInt(BMDDeckLinkAudioInputConnections, &audio_input_mask) != S_OK) { fprintf(stderr, "Failed to enumerate audio inputs for card %d\n", card_index); exit(1); } const vector<pair<BMDAudioConnection, string>> audio_input_types = { { bmdAudioConnectionEmbedded, "Embedded" }, { bmdAudioConnectionAESEBU, "AES/EBU" }, { bmdAudioConnectionAnalog, "Analog" }, { bmdAudioConnectionAnalogXLR, "Analog XLR" }, { bmdAudioConnectionAnalogRCA, "Analog RCA" }, { bmdAudioConnectionMicrophone, "Microphone" }, { bmdAudioConnectionHeadphones, "Headphones" } }; for (const auto &audio_input : audio_input_types) { if (audio_input_mask & audio_input.first) { audio_inputs.emplace(audio_input.first, audio_input.second); } } attr->Release(); /* Set up the video and audio sources. */ if (card->QueryInterface(IID_IDeckLinkConfiguration, (void**)&config) != S_OK) { fprintf(stderr, "Failed to get configuration interface for card %d\n", card_index); exit(1); } set_video_input(bmdVideoConnectionHDMI); set_audio_input(bmdAudioConnectionEmbedded); IDeckLinkDisplayModeIterator *mode_it; if (input->GetDisplayModeIterator(&mode_it) != S_OK) { fprintf(stderr, "Failed to enumerate display modes for card %d\n", card_index); exit(1); } for (IDeckLinkDisplayMode *mode_ptr; mode_it->Next(&mode_ptr) == S_OK; mode_ptr->Release()) { VideoMode mode; const char *mode_name; if (mode_ptr->GetName(&mode_name) != S_OK) { mode.name = "Unknown mode"; } else { mode.name = mode_name; } mode.autodetect = false; mode.width = mode_ptr->GetWidth(); mode.height = mode_ptr->GetHeight(); BMDTimeScale frame_rate_num; BMDTimeValue frame_rate_den; if (mode_ptr->GetFrameRate(&frame_rate_den, &frame_rate_num) != S_OK) { fprintf(stderr, "Could not get frame rate for mode '%s' on card %d\n", mode.name.c_str(), card_index); exit(1); } mode.frame_rate_num = frame_rate_num; mode.frame_rate_den = frame_rate_den; // TODO: Respect the TFF/BFF flag. mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst); uint32_t id = mode_ptr->GetDisplayMode(); video_modes.insert(make_pair(id, mode)); } set_video_mode_no_restart(bmdModeHD720p5994); if (input->EnableAudioInput(48000, bmdAudioSampleType32bitInteger, 2) != S_OK) { fprintf(stderr, "Failed to enable audio input for card %d\n", card_index); exit(1); } input->SetCallback(this); }
void print_attributes (IDeckLink* deckLink) { IDeckLinkAttributes* deckLinkAttributes = NULL; bool supported; int64_t value; char * serialPortName = NULL; HRESULT result; // Query the DeckLink for its attributes interface result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes); if (result != S_OK) { fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface - result = %08x\n", result); goto bail; } // List attributes and their value printf("Attribute list:\n"); result = deckLinkAttributes->GetFlag(BMDDeckLinkHasSerialPort, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Serial port present ?", (supported == true) ? "Yes" : "No"); if (supported) { result = deckLinkAttributes->GetString(BMDDeckLinkSerialPortDeviceName, (const char **) &serialPortName); if (result == S_OK) { printf(" %-40s %s\n", "Serial port name: ", serialPortName); free(serialPortName); } else { fprintf(stderr, "Could not query the serial port presence attribute- result = %08x\n", result); } } } else { fprintf(stderr, "Could not query the serial port presence attribute- result = %08x\n", result); } result = deckLinkAttributes->GetInt(BMDDeckLinkPersistentID, &value); if (result == S_OK) { printf(" %-40s %llx\n", "Device Persistent ID:", value); } else { printf(" %-40s %s\n", "Device Persistent ID:", "Not Supported on this device"); } result = deckLinkAttributes->GetInt(BMDDeckLinkTopologicalID, &value); if (result == S_OK) { printf(" %-40s %llx\n", "Device Topological ID:", value); } else { printf(" %-40s %s\n", "Device Topological ID:", "Not Supported on this device"); } result = deckLinkAttributes->GetInt(BMDDeckLinkNumberOfSubDevices, &value); if (result == S_OK) { printf(" %-40s %" PRId64 "\n", "Number of sub-devices:", value); if (value != 0) { result = deckLinkAttributes->GetInt(BMDDeckLinkSubDeviceIndex, &value); if (result == S_OK) { printf(" %-40s %" PRId64 "\n", "Sub-device index:", value); } else { fprintf(stderr, "Could not query the sub-device index attribute- result = %08x\n", result); } } } else { fprintf(stderr, "Could not query the number of sub-device attribute- result = %08x\n", result); } result = deckLinkAttributes->GetInt(BMDDeckLinkMaximumAudioChannels, &value); if (result == S_OK) { printf(" %-40s %" PRId64 "\n", "Number of audio channels:", value); } else { fprintf(stderr, "Could not query the number of supported audio channels attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInputFormatDetection, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Input mode detection supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the input mode detection attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsFullDuplex, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Full duplex operation supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the full duplex operation supported attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsInternalKeying, &supported); if (result == S_OK) { printf(" %-40s %s\n", "Internal keying supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the internal keying attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsExternalKeying, &supported); if (result == S_OK) { printf(" %-40s %s\n", "External keying supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the external keying attribute- result = %08x\n", result); } result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsHDKeying, &supported); if (result == S_OK) { printf(" %-40s %s\n", "HD-mode keying supported ?", (supported == true) ? "Yes" : "No"); } else { fprintf(stderr, "Could not query the HD-mode keying attribute- result = %08x\n", result); } bail: printf("\n"); if(deckLinkAttributes != NULL) deckLinkAttributes->Release(); }