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; }
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(); }
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(); }
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; }
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; }
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(); }