28 #include <DeckLinkAPIVersion.h>
29 #include <DeckLinkAPI.h>
30 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0e030000
31 #include <DeckLinkAPI_v14_2_1.h>
35 #include <DeckLinkAPI_i.c>
42 #pragma clang diagnostic push
43 #pragma clang diagnostic ignored "-Wmissing-prototypes"
45 #include <DeckLinkAPIDispatch.cpp>
47 #pragma clang diagnostic pop
63 IDeckLinkIterator *iter;
66 if (CoInitialize(
NULL) < 0) {
71 if (CoCreateInstance(CLSID_CDeckLinkIterator,
NULL, CLSCTX_ALL,
72 IID_IDeckLinkIterator, (
void**) &iter) != S_OK) {
76 iter = CreateDeckLinkIteratorInstance();
80 "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING
" or newer installed.\n");
82 IDeckLinkAPIInformation *api;
85 if (CoCreateInstance(CLSID_CDeckLinkAPIInformation,
NULL, CLSCTX_ALL,
86 IID_IDeckLinkAPIInformation, (
void**) &api) != S_OK) {
90 api = CreateDeckLinkAPIInformationInstance();
92 if (api && api->GetInt(BMDDeckLinkAPIVersion, &
version) == S_OK) {
93 if (
version < BLACKMAGIC_DECKLINK_API_VERSION)
94 av_log(avctx,
AV_LOG_WARNING,
"Installed DeckLink drivers are too old and may be incompatible with the SDK this module was built against. "
95 "Make sure you have DeckLink drivers " BLACKMAGIC_DECKLINK_API_VERSION_STRING
" or newer installed.\n");
114 hr = attr->GetString(cfg_id, &
tmp);
121 }
else if (hr == E_FAIL) {
131 BMDDeckLinkAttributeID attr_id = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ? BMDDeckLinkAudioInputConnections : BMDDeckLinkVideoInputConnections;
133 const char *type_name = (cfg_id == bmdDeckLinkConfigAudioInputConnection) ?
"audio" :
"video";
134 int64_t supported_connections = 0;
138 res =
ctx->attr->GetInt(attr_id, &supported_connections);
143 if ((supported_connections & bmd_input) != bmd_input) {
144 av_log(avctx,
AV_LOG_ERROR,
"Device does not support selected %s input.\n", type_name);
147 res =
ctx->cfg->SetInt(cfg_id, bmd_input);
164 if (field_order ==
AV_FIELD_PROGRESSIVE && (bmd_field_order == bmdProgressiveFrame || bmd_field_order == bmdProgressiveSegmentedFrame))
175 if (
ctx->duplex_mode) {
178 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
179 IDeckLinkProfileManager *manager =
NULL;
180 if (
ctx->dl->QueryInterface(IID_IDeckLinkProfileManager, (
void **)&manager) == S_OK)
181 duplex_supported =
true;
183 if (
ctx->attr->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &duplex_supported) != S_OK)
184 duplex_supported =
false;
187 if (duplex_supported) {
188 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
190 BMDProfileID bmd_profile_id;
194 bmd_profile_id = decklink_profile_id_map[
ctx->duplex_mode];
195 res = manager->GetProfile(bmd_profile_id, &
profile);
202 res =
ctx->cfg->SetInt(bmdDeckLinkConfigDuplexMode,
ctx->duplex_mode == 2 ? bmdDuplexModeFull : bmdDuplexModeHalf);
207 av_log(avctx,
AV_LOG_VERBOSE,
"Successfully set duplex mode to %s duplex.\n",
ctx->duplex_mode == 2 ||
ctx->duplex_mode == 4 ?
"full" :
"half");
222 res =
ctx->cfg->SetInt(bmdDeckLinkConfigReferenceInputTimingOffset, cctx->
timing_offset);
228 res =
ctx->cfg->SetInt(bmdDeckLinkConfigSDIOutputLinkConfiguration,
ctx->link);
233 if (
ctx->link == bmdLinkConfigurationQuadLink && cctx->
sqd >= 0) {
234 res =
ctx->cfg->SetFlag(bmdDeckLinkConfigQuadLinkSDIVideoOutputSquareDivisionSplit, cctx->
sqd);
245 if (
ctx->attr->GetFlag(BMDDeckLinkSupportsSMPTELevelAOutput, &level_a_supported) != S_OK)
246 level_a_supported =
false;
248 if (level_a_supported) {
249 res =
ctx->cfg->SetFlag(bmdDeckLinkConfigSMPTELevelAOutput, cctx->
level_a);
255 av_log(avctx,
AV_LOG_WARNING,
"Unable to set SMPTE levelA mode, because it is not supported.\n");
264 int tb_num,
int tb_den,
270 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
273 BMDDisplayModeSupport support;
275 IDeckLinkDisplayModeIterator *itermode;
276 IDeckLinkDisplayMode *
mode;
280 av_log(avctx,
AV_LOG_DEBUG,
"Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, format code %s\n",
284 res =
ctx->dli->GetDisplayModeIterator (&itermode);
286 res =
ctx->dlo->GetDisplayModeIterator (&itermode);
294 char format_buf[] =
" ";
297 BMDDisplayMode target_mode = (BMDDisplayMode)
AV_RB32(format_buf);
299 ctx->bmd_mode = bmdModeUnknown;
300 while ((
ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&
mode) == S_OK) {
301 BMDTimeValue bmd_tb_num, bmd_tb_den;
302 int bmd_width =
mode->GetWidth();
303 int bmd_height =
mode->GetHeight();
304 BMDDisplayMode bmd_mode =
mode->GetDisplayMode();
305 BMDFieldDominance bmd_field_dominance =
mode->GetFieldDominance();
307 mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den);
310 if ((bmd_width ==
width &&
314 || target_mode == bmd_mode) {
315 ctx->bmd_mode = bmd_mode;
316 ctx->bmd_width = bmd_width;
317 ctx->bmd_height = bmd_height;
318 ctx->bmd_tb_den = bmd_tb_den;
319 ctx->bmd_tb_num = bmd_tb_num;
320 ctx->bmd_field_dominance = bmd_field_dominance;
322 bmd_width, bmd_height, 1/
av_q2d(mode_tb),
323 (
ctx->bmd_field_dominance==bmdLowerFieldFirst ||
ctx->bmd_field_dominance==bmdUpperFieldFirst)?
"(i)":
"");
332 if (
ctx->bmd_mode == bmdModeUnknown)
335 #if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b050000
337 BMDDisplayMode actualMode =
ctx->bmd_mode;
338 if (
ctx->dli->DoesSupportVideoMode(
ctx->video_input,
ctx->bmd_mode,
ctx->raw_format,
339 bmdNoVideoInputConversion, bmdSupportedVideoModeDefault,
340 &actualMode, &support) != S_OK || !support ||
ctx->bmd_mode != actualMode)
343 BMDDisplayMode actualMode =
ctx->bmd_mode;
344 if (
ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified,
ctx->bmd_mode,
ctx->raw_format,
345 bmdNoVideoOutputConversion, bmdSupportedVideoModeDefault,
346 &actualMode, &support) != S_OK || !support ||
ctx->bmd_mode != actualMode)
350 #elif BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000
352 if (
ctx->dli->DoesSupportVideoMode(
ctx->video_input,
ctx->bmd_mode,
ctx->raw_format,
353 bmdSupportedVideoModeDefault,
357 BMDDisplayMode actualMode =
ctx->bmd_mode;
358 if (
ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified,
ctx->bmd_mode,
ctx->raw_format,
359 bmdSupportedVideoModeDefault,
360 &actualMode, &support) != S_OK || !support ||
ctx->bmd_mode != actualMode) {
369 if (
ctx->dli->DoesSupportVideoMode(
ctx->bmd_mode,
ctx->raw_format,
370 bmdVideoOutputFlagDefault,
371 &support,
NULL) != S_OK)
374 if (!
ctx->supports_vanc ||
ctx->dlo->DoesSupportVideoMode(
ctx->bmd_mode,
ctx->raw_format,
376 &support,
NULL) != S_OK || support != bmdDisplayModeSupported) {
378 if (
ctx->dlo->DoesSupportVideoMode(
ctx->bmd_mode,
ctx->raw_format,
379 bmdVideoOutputFlagDefault,
380 &support,
NULL) != S_OK) {
383 ctx->supports_vanc = 0;
387 if (support == bmdDisplayModeSupported)
429 unsigned long long size;
510 int show_inputs,
int show_outputs)
512 IDeckLink *dl =
NULL;
519 while (
ret == 0 && iter->Next(&dl) == S_OK) {
522 const char *display_name =
NULL;
523 const char *unique_name =
NULL;
536 output_config->Release();
543 input_config->Release();
582 int show_inputs,
int show_outputs)
594 show_inputs ?
"input" :
"output");
606 IDeckLinkDisplayModeIterator *itermode;
607 IDeckLinkDisplayMode *
mode;
619 res =
ctx->dli->GetDisplayModeIterator (&itermode);
621 res =
ctx->dlo->GetDisplayModeIterator (&itermode);
629 av_log(avctx,
AV_LOG_INFO,
"Supported formats for '%s':\n\tformat_code\tdescription",
631 while (itermode->Next(&
mode) == S_OK) {
632 BMDTimeValue tb_num, tb_den;
633 mode->GetFrameRate(&tb_num, &tb_den);
637 (
int) tb_den, (
int) tb_num);
638 switch (
mode->GetFieldDominance()) {
639 case bmdLowerFieldFirst:
641 case bmdUpperFieldFirst:
663 ctx->attr->Release();
674 IDeckLink *dl =
NULL;
679 while (iter->Next(&dl) == S_OK) {
680 const char *display_name =
NULL;
681 const char *unique_name =
NULL;
684 if (display_name && !strcmp(
name, display_name) || unique_name && !strcmp(
name, unique_name)) {
698 if (
ctx->dl->QueryInterface(IID_IDeckLinkConfiguration, (
void **)&
ctx->cfg) != S_OK) {