From patchwork Thu Sep 20 22:05:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 10421 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp48973jap; Thu, 20 Sep 2018 15:05:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV60cWC43G4uXNuvykQm9wf7zrag+KINNGMSLPXkXsV23OfJxNWdL4JTofUEpx8j7zySSy9Di X-Received: by 2002:adf:8206:: with SMTP id 6-v6mr4088178wrb.160.1537481148485; Thu, 20 Sep 2018 15:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537481148; cv=none; d=google.com; s=arc-20160816; b=JNonwbdQN1vsTKA7yaW1fAGLqHlxyTJH9JT0uDvEGMjRrTUO2nnq2FXaEC84b9hjQ0 FxhnQSNfrhlTpGjmxSeVM9WT+rYX0RI+hyGcC6sQnuaNkm9oAtXRbv/Je1d/fX8ZXA9k OYZP0qbtORY2KLiMAdinqImdTTYt/1r9QvYis/MnSloJiSln9A2yo5VExyp21N0BeHpn n4HWtH7nBYDy8LQMu5kum9xvv62p1L0rSf8ZzR7MervwcsfPomcD9hVXO+Kvsa0pMbrR /kERcvAIkhoSdIp6+Lpj7DRdGPFE/Fl2NOOLeSIm31zU+ezvYqdCCNlwoS9enqwoQI84 FGpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=VB0F4mLMA0Q5NUgm4oF0XnZygh17EaitfQd0B+N2o2A=; b=epjGT9kMMO4cR9alWwqutE9kAf0zHZbT+F/tVQMZePNcXZ982Fso+AatwjnbaeLhww oRmYvH9xoBJ2vYqXR0rZJUpP3KJcuDdP5KHsSPwIa3YFYwmKDPvy7k4VV20qrS1DkvDe QefcB0Fl5KucxwcZnp9OToGJPPstFaaMNMvB6hh12v/E5ZI6ZUhAnMxeHd4/SXQ/oIpW yybJUD6fW+1dw0h+LYJ2jrvgmzcz76ipbIDrW9pjVR2vVWkY0ucr466/23O1o8PqZipr 5lQiaLLBQEG32h9RU7gigvtl87GmvaTRvHFOiMvnfO61mgGJiC/d/vy4XbY45jl4KHe1 wsmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d4-v6si571764wrm.214.2018.09.20.15.05.47; Thu, 20 Sep 2018 15:05:48 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0675068A596; Fri, 21 Sep 2018 01:05:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6F23A689A52 for ; Fri, 21 Sep 2018 01:05:25 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id D2886E0FC2; Fri, 21 Sep 2018 00:05:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oUuF22INn02B; Fri, 21 Sep 2018 00:05:37 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7463AE08BE; Fri, 21 Sep 2018 00:05:37 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Sep 2018 00:05:31 +0200 Message-Id: <20180920220531.1044-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH] avdevice/decklink: add support for selecting devices based on their unique ID X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Also bump the API version requirement to 10.9.5, because on olders versions there were some reports of crashes using the undocumented, yet available BMDDeckLinkDeviceHandle. Signed-off-by: Marton Balint --- configure | 2 +- doc/indevs.texi | 3 ++- doc/outdevs.texi | 3 ++- libavdevice/decklink_common.cpp | 59 ++++++++++++++++++++++++++++------------- libavdevice/decklink_common.h | 1 - 5 files changed, 45 insertions(+), 23 deletions(-) diff --git a/configure b/configure index 25120337de..64a519a8b3 100755 --- a/configure +++ b/configure @@ -6043,7 +6043,7 @@ done enabled cuda_sdk && require cuda_sdk cuda.h cuCtxCreate -lcuda enabled chromaprint && require chromaprint chromaprint.h chromaprint_get_version -lchromaprint enabled decklink && { require_headers DeckLinkAPI.h && - { test_cpp_condition DeckLinkAPIVersion.h "BLACKMAGIC_DECKLINK_API_VERSION >= 0x0a060100" || die "ERROR: Decklink API version must be >= 10.6.1."; } } + { test_cpp_condition DeckLinkAPIVersion.h "BLACKMAGIC_DECKLINK_API_VERSION >= 0x0a090500" || die "ERROR: Decklink API version must be >= 10.9.5."; } } enabled libndi_newtek && require_headers Processing.NDI.Lib.h enabled frei0r && require_headers frei0r.h enabled gmp && require gmp gmp.h mpz_export -lgmp diff --git a/doc/indevs.texi b/doc/indevs.texi index 5d4c02c597..ed2784be9f 100644 --- a/doc/indevs.texi +++ b/doc/indevs.texi @@ -267,7 +267,8 @@ audio track. @item list_devices If set to @option{true}, print a list of devices and exit. -Defaults to @option{false}. +Defaults to @option{false}. Alternatively you can use the @code{-sources} +option of ffmpeg to list the available input devices. @item list_formats If set to @option{true}, print a list of supported formats and exit. diff --git a/doc/outdevs.texi b/doc/outdevs.texi index 34c508a970..2518f9b559 100644 --- a/doc/outdevs.texi +++ b/doc/outdevs.texi @@ -140,7 +140,8 @@ device with @command{-list_formats 1}. Audio sample rate is always 48 kHz. @item list_devices If set to @option{true}, print a list of devices and exit. -Defaults to @option{false}. +Defaults to @option{false}. Alternatively you can use the @code{-sinks} +option of ffmpeg to list the available output devices. @item list_formats If set to @option{true}, print a list of supported formats and exit. diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index 503417bb35..b88d6c6219 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) +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; + IDeckLinkAttributes *attr; + *s = NULL; + if (dl->QueryInterface(IID_IDeckLinkAttributes, (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) @@ -276,11 +286,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) { @@ -303,8 +319,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 || @@ -318,7 +334,8 @@ int ff_decklink_list_devices(AVFormatContext *avctx, } next: - av_freep(&displayName); + av_freep(&display_name); + av_freep(&unique_name); dl->Release(); } iter->Release(); @@ -343,7 +360,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); @@ -427,14 +444,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(); diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index 128144f50d..d2fc3f79d5 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -191,7 +191,6 @@ static const BMDTimecodeFormat decklink_timecode_format_map[] = { bmdTimecodeSerial, }; -HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName); int ff_decklink_set_configs(AVFormatContext *avctx, decklink_direction_t direction); int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, enum AVFieldOrder field_order, decklink_direction_t direction = DIRECTION_OUT, int num = 0); int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num);