From patchwork Thu Mar 16 14:06:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Hunstock X-Patchwork-Id: 2957 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp771531vsy; Thu, 16 Mar 2017 07:06:13 -0700 (PDT) X-Received: by 10.223.133.6 with SMTP id 6mr8481619wrh.57.1489673173575; Thu, 16 Mar 2017 07:06:13 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id k10si4685793wmg.97.2017.03.16.07.06.12; Thu, 16 Mar 2017 07:06:13 -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 6212568833E; Thu, 16 Mar 2017 16:05:53 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.annaberg6.de (mail.annaberg6.de [89.238.64.82]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A7E596882FB for ; Thu, 16 Mar 2017 16:05:46 +0200 (EET) Received: (qmail 12271 invoked from network); 16 Mar 2017 14:06:02 -0000 Received: from build.erfurt.vpn.annaberg6.de (10.0.8.11) by mail.annaberg6.de with ESMTPS (AES128-SHA encrypted); 16 Mar 2017 14:06:02 -0000 From: Matthias Hunstock To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Mar 2017 15:06:00 +0100 Message-Id: <1489673161-18533-3-git-send-email-atze@fem.tu-ilmenau.de> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1489673161-18533-1-git-send-email-atze@fem.tu-ilmenau.de> References: <1489673161-18533-1-git-send-email-atze@fem.tu-ilmenau.de> Subject: [FFmpeg-devel] [PATCH 2/3] decklink: new option 'format' to set video format by fourCC 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavdevice/decklink_common.cpp | 22 ++++++++++++++++++---- libavdevice/decklink_common_c.h | 1 + libavdevice/decklink_dec.cpp | 2 +- libavdevice/decklink_dec_c.c | 1 + 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index 131d186..548bf3b 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -143,6 +143,18 @@ static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDomin return false; } +static DECKLINK_BOOL fourcc_eq(char *fourcc_string, BMDDisplayMode fourcc) +{ + BMDDisplayMode fourcc_converted = 0; + if (!fourcc_string) return false; + if (!strcmp(fourcc_string, "pal") && fourcc == 0x70616C20) return true; + if (strlen(fourcc_string) < 4) return false; + fourcc_converted = ((uint8_t) fourcc_string[0] << 24) | ((uint8_t) fourcc_string[1] << 16) | + ((uint8_t) fourcc_string[2] << 8) | ((uint8_t) fourcc_string[3]); + if (fourcc_converted == fourcc) return true; + return false; +} + int ff_decklink_set_format(AVFormatContext *avctx, int width, int height, int tb_num, int tb_den, @@ -157,8 +169,8 @@ int ff_decklink_set_format(AVFormatContext *avctx, int i = 1; HRESULT res; - av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d\n", - width, height, tb_num, tb_den, field_order, direction, num); + av_log(avctx, AV_LOG_DEBUG, "Trying to find mode for frame size %dx%d, frame timing %d/%d, field order %d, direction %d, mode number %d, mode fourCC %s\n", + width, height, tb_num, tb_den, field_order, direction, num, cctx->format); if (ctx->duplex_mode) { DECKLINK_BOOL duplex_supported = false; @@ -202,6 +214,7 @@ int ff_decklink_set_format(AVFormatContext *avctx, int bmd_width = mode->GetWidth(); int bmd_height = mode->GetHeight(); BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance(); + BMDDisplayMode bmd_mode = mode->GetDisplayMode(); mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den); AVRational mode_tb = av_make_q(bmd_tb_num, bmd_tb_den); @@ -209,8 +222,9 @@ int ff_decklink_set_format(AVFormatContext *avctx, if ((bmd_width == width && bmd_height == height && !av_cmp_q(mode_tb, target_tb) && - field_order_eq(field_order, bmd_field_dominance)) || i == num) { - ctx->bmd_mode = mode->GetDisplayMode(); + field_order_eq(field_order, bmd_field_dominance)) + || i == num || fourcc_eq(cctx->format, bmd_mode)) { + ctx->bmd_mode = bmd_mode; ctx->bmd_width = bmd_width; ctx->bmd_height = bmd_height; ctx->bmd_tb_den = bmd_tb_den; diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h index d565631..161a48a 100644 --- a/libavdevice/decklink_common_c.h +++ b/libavdevice/decklink_common_c.h @@ -47,6 +47,7 @@ struct decklink_cctx { int audio_input; int video_input; int draw_bars; + char *format; }; #endif /* AVDEVICE_DECKLINK_COMMON_C_H */ diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index 7df841b..5948888 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -539,7 +539,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) goto error; } - if (mode_num > 0) { + if (mode_num > 0 || cctx->format) { if (ff_decklink_set_format(avctx, DIRECTION_IN, mode_num) < 0) { av_log(avctx, AV_LOG_ERROR, "Could not set mode %d for %s\n", mode_num, fname); ret = AVERROR(EIO); diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index 31818d2..07da7cc 100644 --- a/libavdevice/decklink_dec_c.c +++ b/libavdevice/decklink_dec_c.c @@ -31,6 +31,7 @@ static const AVOption options[] = { { "list_devices", "list available devices" , OFFSET(list_devices), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC }, { "list_formats", "list supported formats" , OFFSET(list_formats), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC }, + { "format", "set format by fourcc" , OFFSET(format), AV_OPT_TYPE_STRING, { .str = NULL}, 3, 4, DEC }, { "bm_v210", "v210 10 bit per channel" , OFFSET(v210), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC }, { "teletext_lines", "teletext lines bitmask", OFFSET(teletext_lines), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 0x7ffffffffLL, DEC, "teletext_lines"}, { "standard", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0x7fff9fffeLL}, 0, 0, DEC, "teletext_lines"},