X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavdevice%2Fdecklink_common.cpp;h=c3a1d5588c44c3b37f9622e7fd9e77edbcdf45c2;hb=f9a061a31c3d2d81b3ec1e1b9b37187a358cdd9e;hp=aab9d85b940027c15c6347f300279ad1af184c11;hpb=64425e005edf3bdd77c34c078c3e74ab5ecef557;p=ffmpeg diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index aab9d85b940..c3a1d5588c4 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -77,15 +77,25 @@ static IDeckLinkIterator *decklink_create_iterator(AVFormatContext *avctx) return iter; } -HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName) +static int decklink_get_attr_string(IDeckLink *dl, BMDDeckLinkAttributeID cfg_id, const char **s) { - DECKLINK_STR tmpDisplayName; - HRESULT hr = This->GetDisplayName(&tmpDisplayName); - if (hr != S_OK) - return hr; - *displayName = DECKLINK_STRDUP(tmpDisplayName); - DECKLINK_FREE(tmpDisplayName); - return hr; + DECKLINK_STR tmp; + HRESULT hr; + IDeckLinkProfileAttributes *attr; + *s = NULL; + if (dl->QueryInterface(IID_IDeckLinkProfileAttributes, (void **)&attr) != S_OK) + return AVERROR_EXTERNAL; + hr = attr->GetString(cfg_id, &tmp); + attr->Release(); + if (hr == S_OK) { + *s = DECKLINK_STRDUP(tmp); + DECKLINK_FREE(tmp); + if (!*s) + return AVERROR(ENOMEM); + } else if (hr == E_FAIL) { + return AVERROR_EXTERNAL; + } + return 0; } static int decklink_select_input(AVFormatContext *avctx, BMDDeckLinkConfigurationID cfg_id) @@ -139,11 +149,28 @@ int ff_decklink_set_configs(AVFormatContext *avctx, if (ctx->duplex_mode) { DECKLINK_BOOL duplex_supported = false; +#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000 + IDeckLinkProfileManager *manager = NULL; + if (ctx->dl->QueryInterface(IID_IDeckLinkProfileManager, (void **)&manager) == S_OK) + duplex_supported = true; +#else if (ctx->attr->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &duplex_supported) != S_OK) duplex_supported = false; +#endif if (duplex_supported) { +#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000 + IDeckLinkProfile *profile = NULL; + BMDProfileID bmd_profile_id = ctx->duplex_mode == 2 ? bmdProfileOneSubDeviceFullDuplex : bmdProfileTwoSubDevicesHalfDuplex; + res = manager->GetProfile(bmd_profile_id, &profile); + if (res == S_OK) { + res = profile->SetActive(); + profile->Release(); + } + manager->Release(); +#else res = ctx->cfg->SetInt(bmdDeckLinkConfigDuplexMode, ctx->duplex_mode == 2 ? bmdDuplexModeFull : bmdDuplexModeHalf); +#endif if (res != S_OK) av_log(avctx, AV_LOG_WARNING, "Setting duplex mode failed.\n"); else @@ -161,6 +188,11 @@ int ff_decklink_set_configs(AVFormatContext *avctx, if (ret < 0) return ret; } + if (direction == DIRECTION_OUT && cctx->timing_offset != INT_MIN) { + res = ctx->cfg->SetInt(bmdDeckLinkConfigReferenceInputTimingOffset, cctx->timing_offset); + if (res != S_OK) + av_log(avctx, AV_LOG_WARNING, "Setting timing offset failed.\n"); + } return 0; } @@ -172,7 +204,11 @@ int ff_decklink_set_format(AVFormatContext *avctx, { struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data; struct decklink_ctx *ctx = (struct decklink_ctx *)cctx->ctx; +#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000 + DECKLINK_BOOL support; +#else BMDDisplayModeSupport support; +#endif IDeckLinkDisplayModeIterator *itermode; IDeckLinkDisplayMode *mode; int i = 1; @@ -233,19 +269,53 @@ int ff_decklink_set_format(AVFormatContext *avctx, if (ctx->bmd_mode == bmdModeUnknown) return -1; + +#if BLACKMAGIC_DECKLINK_API_VERSION >= 0x0b000000 + if (direction == DIRECTION_IN) { + if (ctx->dli->DoesSupportVideoMode(ctx->video_input, ctx->bmd_mode, (BMDPixelFormat) cctx->raw_format, + bmdVideoInputFlagDefault, + &support) != S_OK) + return -1; + } else { + BMDDisplayMode actualMode = ctx->bmd_mode; + if (!ctx->supports_vanc || ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified, ctx->bmd_mode, ctx->raw_format, + bmdVideoOutputVANC, + &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode) { + /* Try without VANC enabled */ + if (ctx->dlo->DoesSupportVideoMode(bmdVideoConnectionUnspecified, ctx->bmd_mode, ctx->raw_format, + bmdVideoOutputFlagDefault, + &actualMode, &support) != S_OK || !support || ctx->bmd_mode != actualMode) { + return -1; + } + ctx->supports_vanc = 0; + } + + } + if (support) + return 0; +#else if (direction == DIRECTION_IN) { if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, (BMDPixelFormat) cctx->raw_format, bmdVideoOutputFlagDefault, &support, NULL) != S_OK) return -1; } else { - if (ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, bmdFormat8BitYUV, - bmdVideoOutputFlagDefault, - &support, NULL) != S_OK) - return -1; + if (!ctx->supports_vanc || ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format, + bmdVideoOutputVANC, + &support, NULL) != S_OK || support != bmdDisplayModeSupported) { + /* Try without VANC enabled */ + if (ctx->dlo->DoesSupportVideoMode(ctx->bmd_mode, ctx->raw_format, + bmdVideoOutputFlagDefault, + &support, NULL) != S_OK) { + return -1; + } + ctx->supports_vanc = 0; + } + } if (support == bmdDisplayModeSupported) return 0; +#endif return -1; } @@ -268,11 +338,17 @@ int ff_decklink_list_devices(AVFormatContext *avctx, while (ret == 0 && iter->Next(&dl) == S_OK) { IDeckLinkOutput *output_config; IDeckLinkInput *input_config; - const char *displayName; + const char *display_name = NULL; + const char *unique_name = NULL; AVDeviceInfo *new_device = NULL; int add = 0; - ff_decklink_get_display_name(dl, &displayName); + ret = decklink_get_attr_string(dl, BMDDeckLinkDisplayName, &display_name); + if (ret < 0) + goto next; + ret = decklink_get_attr_string(dl, BMDDeckLinkDeviceHandle, &unique_name); + if (ret < 0) + goto next; if (show_outputs) { if (dl->QueryInterface(IID_IDeckLinkOutput, (void **)&output_config) == S_OK) { @@ -295,8 +371,8 @@ int ff_decklink_list_devices(AVFormatContext *avctx, goto next; } - new_device->device_name = av_strdup(displayName); - new_device->device_description = av_strdup(displayName); + new_device->device_name = av_strdup(unique_name ? unique_name : display_name); + new_device->device_description = av_strdup(display_name); if (!new_device->device_name || !new_device->device_description || @@ -310,7 +386,8 @@ int ff_decklink_list_devices(AVFormatContext *avctx, } next: - av_freep(&displayName); + av_freep(&display_name); + av_freep(&unique_name); dl->Release(); } iter->Release(); @@ -335,7 +412,7 @@ void ff_decklink_list_devices_legacy(AVFormatContext *avctx, av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink %s devices:\n", show_inputs ? "input" : "output"); for (int i = 0; i < device_list->nb_devices; i++) { - av_log(avctx, AV_LOG_INFO, "\t'%s'\n", device_list->devices[i]->device_name); + av_log(avctx, AV_LOG_INFO, "\t'%s'\n", device_list->devices[i]->device_description); } } avdevice_free_list_devices(&device_list); @@ -419,14 +496,18 @@ int ff_decklink_init_device(AVFormatContext *avctx, const char* name) return AVERROR_EXTERNAL; while (iter->Next(&dl) == S_OK) { - const char *displayName; - ff_decklink_get_display_name(dl, &displayName); - if (!strcmp(name, displayName)) { - av_free((void *)displayName); + const char *display_name = NULL; + const char *unique_name = NULL; + decklink_get_attr_string(dl, BMDDeckLinkDisplayName, &display_name); + decklink_get_attr_string(dl, BMDDeckLinkDeviceHandle, &unique_name); + if (display_name && !strcmp(name, display_name) || unique_name && !strcmp(name, unique_name)) { + av_free((void *)unique_name); + av_free((void *)display_name); ctx->dl = dl; break; } - av_free((void *)displayName); + av_free((void *)display_name); + av_free((void *)unique_name); dl->Release(); } iter->Release(); @@ -439,7 +520,7 @@ int ff_decklink_init_device(AVFormatContext *avctx, const char* name) return AVERROR_EXTERNAL; } - if (ctx->dl->QueryInterface(IID_IDeckLinkAttributes, (void **)&ctx->attr) != S_OK) { + if (ctx->dl->QueryInterface(IID_IDeckLinkProfileAttributes, (void **)&ctx->attr) != S_OK) { av_log(avctx, AV_LOG_ERROR, "Could not get attributes interface for '%s'\n", name); ff_decklink_cleanup(avctx); return AVERROR_EXTERNAL;