From patchwork Sat Feb 25 19:22:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 2674 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.149 with SMTP id x21csp376888vsf; Sat, 25 Feb 2017 11:22:28 -0800 (PST) X-Received: by 10.223.134.151 with SMTP id 23mr8916046wrx.0.1488050548296; Sat, 25 Feb 2017 11:22:28 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w17si7308920wmw.22.2017.02.25.11.22.27; Sat, 25 Feb 2017 11:22:28 -0800 (PST) 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 9264F688377; Sat, 25 Feb 2017 21:22:15 +0200 (EET) 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 0CFEC68076D for ; Sat, 25 Feb 2017 21:22:09 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3FC2C102CE7; Sat, 25 Feb 2017 20:22:18 +0100 (CET) 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 5i+O2LrZ9i53; Sat, 25 Feb 2017 20:22:14 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 8B903100CBF; Sat, 25 Feb 2017 20:22:14 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 25 Feb 2017 20:22:09 +0100 Message-Id: <20170225192209.6560-1-cus@passwd.hu> X-Mailer: git-send-email 2.10.2 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCHv2 2/4] avdevice/decklink_enc: add support to specify field order 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" Changes: handle AV_FIELD_TB and AV_FIELD_BT as well. Signed-off-by: Marton Balint --- doc/outdevs.texi | 4 ++-- libavdevice/decklink_common.cpp | 29 +++++++++++++++++++++++------ libavdevice/decklink_common.h | 2 +- libavdevice/decklink_enc.cpp | 4 ++-- libavdevice/version.h | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/doc/outdevs.texi b/doc/outdevs.texi index e68653f..df41cc8 100644 --- a/doc/outdevs.texi +++ b/doc/outdevs.texi @@ -131,8 +131,8 @@ and @code{--extra-ldflags}. On Windows, you need to run the IDL files through @command{widl}. DeckLink is very picky about the formats it supports. Pixel format is always -uyvy422, framerate and video size must be determined for your device with -@command{-list_formats 1}. Audio sample rate is always 48 kHz. +uyvy422, framerate, field order and video size must be determined for your +device with @command{-list_formats 1}. Audio sample rate is always 48 kHz. @subsection Options diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index a3bc58d..8b499c5 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -130,9 +130,23 @@ static int decklink_select_input(AVFormatContext *avctx, BMDDeckLinkConfiguratio return 0; } +static DECKLINK_BOOL field_order_eq(enum AVFieldOrder field_order, BMDFieldDominance bmd_field_order) +{ + if (field_order == AV_FIELD_UNKNOWN) + return true; + if ((field_order == AV_FIELD_TT || field_order == AV_FIELD_TB) && bmd_field_order == bmdUpperFieldFirst) + return true; + if ((field_order == AV_FIELD_BB || field_order == AV_FIELD_BT) && bmd_field_order == bmdLowerFieldFirst) + return true; + if (field_order == AV_FIELD_PROGRESSIVE && (bmd_field_order == bmdProgressiveFrame || bmd_field_order == bmdProgressiveSegmentedFrame)) + return true; + return false; +} + 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, int num) { struct decklink_cctx *cctx = (struct decklink_cctx *)avctx->priv_data; @@ -143,8 +157,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, direction %d, mode number %d\n", - width, height, tb_num, tb_den, 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\n", + width, height, tb_num, tb_den, field_order, direction, num); if (ctx->duplex_mode) { DECKLINK_BOOL duplex_supported = false; @@ -187,18 +201,21 @@ int ff_decklink_set_format(AVFormatContext *avctx, BMDTimeValue bmd_tb_num, bmd_tb_den; int bmd_width = mode->GetWidth(); int bmd_height = mode->GetHeight(); + BMDFieldDominance bmd_field_dominance = mode->GetFieldDominance(); mode->GetFrameRate(&bmd_tb_num, &bmd_tb_den); AVRational mode_tb = av_make_q(bmd_tb_num, bmd_tb_den); - if ((bmd_width == width && bmd_height == height && - !av_cmp_q(mode_tb, target_tb)) || i == num) { + 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(); ctx->bmd_width = bmd_width; ctx->bmd_height = bmd_height; ctx->bmd_tb_den = bmd_tb_den; ctx->bmd_tb_num = bmd_tb_num; - ctx->bmd_field_dominance = mode->GetFieldDominance(); + ctx->bmd_field_dominance = bmd_field_dominance; av_log(avctx, AV_LOG_INFO, "Found Decklink mode %d x %d with rate %.2f%s\n", bmd_width, bmd_height, 1/av_q2d(mode_tb), (ctx->bmd_field_dominance==bmdLowerFieldFirst || ctx->bmd_field_dominance==bmdUpperFieldFirst)?"(i)":""); @@ -230,7 +247,7 @@ int ff_decklink_set_format(AVFormatContext *avctx, } int ff_decklink_set_format(AVFormatContext *avctx, decklink_direction_t direction, int num) { - return ff_decklink_set_format(avctx, 0, 0, 0, 0, direction, num); + return ff_decklink_set_format(avctx, 0, 0, 0, 0, AV_FIELD_UNKNOWN, direction, num); } int ff_decklink_list_devices(AVFormatContext *avctx) diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index bfa2b08..4753287 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -128,7 +128,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, decklink_direction_t direction = DIRECTION_OUT, int num = 0); +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_formats(AVFormatContext *avctx, decklink_direction_t direction = DIRECTION_OUT); diff --git a/libavdevice/decklink_enc.cpp b/libavdevice/decklink_enc.cpp index 944e9d3..8fb6a9c 100644 --- a/libavdevice/decklink_enc.cpp +++ b/libavdevice/decklink_enc.cpp @@ -105,8 +105,8 @@ static int decklink_setup_video(AVFormatContext *avctx, AVStream *st) return -1; } if (ff_decklink_set_format(avctx, c->width, c->height, - st->time_base.num, st->time_base.den)) { - av_log(avctx, AV_LOG_ERROR, "Unsupported video size or framerate!" + st->time_base.num, st->time_base.den, c->field_order)) { + av_log(avctx, AV_LOG_ERROR, "Unsupported video size, framerate or field order!" " Check available formats with -list_formats 1.\n"); return -1; } diff --git a/libavdevice/version.h b/libavdevice/version.h index 94f5659..ceec2d4 100644 --- a/libavdevice/version.h +++ b/libavdevice/version.h @@ -29,7 +29,7 @@ #define LIBAVDEVICE_VERSION_MAJOR 57 #define LIBAVDEVICE_VERSION_MINOR 2 -#define LIBAVDEVICE_VERSION_MICRO 100 +#define LIBAVDEVICE_VERSION_MICRO 101 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ LIBAVDEVICE_VERSION_MINOR, \