From patchwork Tue Sep 26 16:06:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Heitmueller X-Patchwork-Id: 5293 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp4002112jaa; Tue, 26 Sep 2017 09:07:05 -0700 (PDT) X-Google-Smtp-Source: AOwi7QC27Qn2c8ztuMVgIV1WStfS35/UkJk4T1Qn4OC+VEZqMuvTwAkuHyZJallXyIxgxPqaCML8 X-Received: by 10.28.45.5 with SMTP id t5mr3417168wmt.108.1506442025888; Tue, 26 Sep 2017 09:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506442025; cv=none; d=google.com; s=arc-20160816; b=DgW2CqIVOXYIsLJO0Wc2cY+WgUgCQIxAbyEbdH/ZagsIfclhfRcqMhUYoPihQRSZbo BaeyIN52x3IlLm7xkGlWOYkeI2ZIqpflA4JITlP+Lq77s2BMRZCGuwmCy2UXTmZ5sOaw xrW6zlQx64M71m8zb2/0NHnvIYmPZsm0IeUnLyVWWvWM9+qe9QNKmHhkXNt8TmZcVHhc Q43nRKninP/3RzvwPbeVwLRdDmM8/1wmuwqOEz5cISEc9o5y7wji47tj6uwHZZbJ990O iLXaiMIZ/0lYwdtDtaj1j4r3p6+yK0TFxQ3Eqozz1jQDeYF/01DOIBFahyh5mhBVc40T cUQg== 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:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=oNHbdi42+PBogMh1hFRE4/XpxG0eCUi/BSkisHbHUOQ=; b=IeC9+2ufQCoo3lZoY8mE8hUMJC/ouiCkGLXSd4886Wdme6prHy/RdaWhKq+hm2GjMs w17NIIgKB5PI+lK2L65YMZ3p4UICWYhZOb93t6dFxFxevz8F0UxFcXHzt68ykmjxURqG 9YehoRXB6qkGrBbD2osrlgiZV1Y/3GRLFWJAqMuMG/iG09CIS39yylpaA72EpgshiAD7 dtPcg4lzadS3Rhv2Yf701i1Lzii7nR5Q0xw3Pa01oxGmB1td59yotpxlXX9S90hyx/hj RvmC2D1ywSQ1KI+tA++UMZgYhDw1VG7wRQ/I6a5zJBau0WFjoJAa6SFmMrw9fEal+xAU BaLg== 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 y6si7430202wrg.404.2017.09.26.09.07.05; Tue, 26 Sep 2017 09:07:05 -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 29F0E688399; Tue, 26 Sep 2017 19:06:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from was-smtp1.livetimenet.net (50-206-97-56-static.hfc.comcastbusiness.net [50.206.97.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40D7E680D29 for ; Tue, 26 Sep 2017 19:06:35 +0300 (EEST) Received: by was-smtp1.livetimenet.net with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.84_2) (envelope-from ) id 1dwsNh-00055P-A6; Tue, 26 Sep 2017 12:06:46 -0400 From: Devin Heitmueller To: ffmpeg-devel@ffmpeg.org Date: Tue, 26 Sep 2017 12:06:21 -0400 Message-Id: <20170926160623.1257-3-dheitmueller@ltnglobal.com> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170926160623.1257-1-dheitmueller@ltnglobal.com> References: <20170926160623.1257-1-dheitmueller@ltnglobal.com> X-Spam-Score: -1.9 (-) Subject: [FFmpeg-devel] [PATCH 2/4] libavdevice/decklink: add support for -sources and -sinks arguments 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: Devin Heitmueller MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add support for enumerating the sources/sinks via the ffmpeg command line options, as opposed to having to create a real pipeline and use the "-list_devices" option which does exit() after dumping out the options. Note that this patch preserves the existing "-list_devices" option, but now shares common code for the actual enumeration. Signed-off-by: Devin Heitmueller --- libavdevice/decklink_common.cpp | 52 +++++++++++++++++++++++++++++++++++++---- libavdevice/decklink_common.h | 2 +- libavdevice/decklink_dec.cpp | 22 ++++++++++++++++- libavdevice/decklink_dec.h | 1 + libavdevice/decklink_dec_c.c | 1 + libavdevice/decklink_enc.cpp | 22 ++++++++++++++++- libavdevice/decklink_enc.h | 1 + libavdevice/decklink_enc_c.c | 1 + 8 files changed, 95 insertions(+), 7 deletions(-) diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index 7745575d0e..86d6fbb74b 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -37,6 +37,7 @@ extern "C" { #include "libavutil/imgutils.h" #include "libavutil/intreadwrite.h" #include "libavutil/bswap.h" +#include "avdevice.h" } #include "decklink_common.h" @@ -261,24 +262,67 @@ int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t directio return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, direction, num); } -int ff_decklink_list_devices(AVFormatContext *avctx) +int ff_decklink_list_devices(AVFormatContext *avctx, + struct AVDeviceInfoList *device_list, + int show_inputs, int show_outputs) { IDeckLink *dl = NULL; IDeckLinkIterator *iter = CreateDeckLinkIteratorInstance(); + int ret = 0; + if (!iter) { av_log(avctx, AV_LOG_ERROR, "Could not create DeckLink iterator\n"); return AVERROR(EIO); } - av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink devices:\n"); + while (iter->Next(&dl) == S_OK) { + IDeckLinkOutput *output_config; + IDeckLinkInput *input_config; const char *displayName; + AVDeviceInfo *new_device = NULL; + int add = 0; + ff_decklink_get_display_name(dl, &displayName); - av_log(avctx, AV_LOG_INFO, "\t'%s'\n", displayName); + + if (show_outputs) { + if (dl->QueryInterface(IID_IDeckLinkOutput, (void **)&output_config) == S_OK) { + output_config->Release(); + add = 1; + } + } + + if (show_inputs) { + if (dl->QueryInterface(IID_IDeckLinkInput, (void **)&input_config) == S_OK) { + input_config->Release(); + add = 1; + } + } + + if (add == 1) { + new_device = (AVDeviceInfo *) av_mallocz(sizeof(AVDeviceInfo)); + if (!new_device) { + ret = AVERROR(ENOMEM); + goto next; + } + new_device->device_name = av_strdup(displayName); + new_device->device_description = av_strdup(displayName); + if (!new_device->device_description || !new_device->device_name) { + ret = AVERROR(ENOMEM); + goto next; + } + + if ((ret = av_dynarray_add_nofree(&device_list->devices, + &device_list->nb_devices, new_device)) < 0) { + goto next; + } + } + + next: av_free((void *) displayName); dl->Release(); } iter->Release(); - return 0; + return ret; } int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction) diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index 749eb0f8b8..f81b33ada4 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -135,7 +135,7 @@ static const BMDVideoConnection decklink_video_connection_map[] = { HRESULT ff_decklink_get_display_name(IDeckLink *This, const char **displayName); 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); -int ff_decklink_list_devices(AVFormatContext *avctx); +int ff_decklink_list_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list, int show_inputs, int show_outputs); int ff_decklink_list_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT); void ff_decklink_cleanup(AVFormatContext *avctx); int ff_decklink_init_device(AVFormatContext *avctx, const char* name); diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index c271ff3639..cb282055c6 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -38,6 +38,7 @@ extern "C" { #include "libavutil/time.h" #include "libavutil/mathematics.h" #include "libavutil/reverse.h" +#include "avdevice.h" #if CONFIG_LIBZVBI #include #endif @@ -647,7 +648,21 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) /* List available devices. */ if (ctx->list_devices) { - ff_decklink_list_devices(avctx); + struct AVDeviceInfoList *device_list = NULL; + int ret; + + device_list = (struct AVDeviceInfoList *) av_mallocz(sizeof(AVDeviceInfoList)); + if (!device_list) + return AVERROR(ENOMEM); + + ret = ff_decklink_list_devices(avctx, device_list, 1, 0); + if (ret == 0) { + av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink input devices:\n"); + 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); + } + } + avdevice_free_list_devices(&device_list); return AVERROR_EXIT; } @@ -810,4 +825,9 @@ int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt) return 0; } +int ff_decklink_list_input_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list) +{ + return ff_decklink_list_devices(avctx, device_list, 1, 0); +} + } /* extern "C" */ diff --git a/libavdevice/decklink_dec.h b/libavdevice/decklink_dec.h index 9b71870deb..fbfbe6280e 100644 --- a/libavdevice/decklink_dec.h +++ b/libavdevice/decklink_dec.h @@ -29,6 +29,7 @@ extern "C" { int ff_decklink_read_header(AVFormatContext *avctx); int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt); int ff_decklink_read_close(AVFormatContext *avctx); +int ff_decklink_list_input_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list); #ifdef __cplusplus } /* extern "C" */ diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index e2118a619c..992c21a160 100644 --- a/libavdevice/decklink_dec_c.c +++ b/libavdevice/decklink_dec_c.c @@ -83,6 +83,7 @@ AVInputFormat ff_decklink_demuxer = { .flags = AVFMT_NOFILE, .priv_class = &decklink_demuxer_class, .priv_data_size = sizeof(struct decklink_cctx), + .get_device_list = ff_decklink_list_input_devices, .read_header = ff_decklink_read_header, .read_packet = ff_decklink_read_packet, .read_close = ff_decklink_read_close, diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp index 25ce7d026c..0f654faa19 100644 --- a/libavdevice/decklink_enc.cpp +++ b/libavdevice/decklink_enc.cpp @@ -33,6 +33,7 @@ extern "C" { extern "C" { #include "libavformat/avformat.h" #include "libavutil/imgutils.h" +#include "avdevice.h" } #include "decklink_common.h" @@ -337,7 +338,21 @@ av_cold int ff_decklink_write_header(AVFormatContext *avctx) /* List available devices. */ if (ctx->list_devices) { - ff_decklink_list_devices(avctx); + struct AVDeviceInfoList *device_list = NULL; + int ret; + + device_list = (struct AVDeviceInfoList *) av_mallocz(sizeof(AVDeviceInfoList)); + if (!device_list) + return AVERROR(ENOMEM); + + ret = ff_decklink_list_devices(avctx, device_list, 0, 1); + if (ret == 0) { + av_log(avctx, AV_LOG_INFO, "Blackmagic DeckLink output devices:\n"); + 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); + } + } + avdevice_free_list_devices(&device_list); return AVERROR_EXIT; } @@ -400,4 +415,9 @@ int ff_decklink_write_packet(AVFormatContext *avctx, AVPacket *pkt) return AVERROR(EIO); } +int ff_decklink_list_output_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list) +{ + return ff_decklink_list_devices(avctx, device_list, 0, 1); +} + } /* extern "C" */ diff --git a/libavdevice/decklink_enc.h b/libavdevice/decklink_enc.h index 5ffc05cd68..39237673b4 100644 --- a/libavdevice/decklink_enc.h +++ b/libavdevice/decklink_enc.h @@ -29,6 +29,7 @@ extern "C" { int ff_decklink_write_header(AVFormatContext *avctx); int ff_decklink_write_packet(AVFormatContext *avctx, AVPacket *pkt); int ff_decklink_write_trailer(AVFormatContext *avctx); +int ff_decklink_list_output_devices(AVFormatContext *avctx, struct AVDeviceInfoList *device_list); #ifdef __cplusplus } /* extern "C" */ diff --git a/libavdevice/decklink_enc_c.c b/libavdevice/decklink_enc_c.c index 03734f8507..360535cfda 100644 --- a/libavdevice/decklink_enc_c.c +++ b/libavdevice/decklink_enc_c.c @@ -49,6 +49,7 @@ AVOutputFormat ff_decklink_muxer = { .video_codec = AV_CODEC_ID_WRAPPED_AVFRAME, .subtitle_codec = AV_CODEC_ID_NONE, .flags = AVFMT_NOFILE, + .get_device_list = ff_decklink_list_output_devices, .priv_class = &decklink_muxer_class, .priv_data_size = sizeof(struct decklink_cctx), .write_header = ff_decklink_write_header,