From patchwork Mon Sep 4 09:47:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gildas Fargeas X-Patchwork-Id: 4974 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp2945550jao; Mon, 4 Sep 2017 02:47:49 -0700 (PDT) X-Google-Smtp-Source: ADKCNb4uiIPuX/xTgItcMhvzP8UmnIh639PrU6wtHoQk5VuUpDCz8/ptMcgHa26SCgnDTm27s8yh X-Received: by 10.223.192.3 with SMTP id z3mr5242744wre.28.1504518469121; Mon, 04 Sep 2017 02:47:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504518469; cv=none; d=google.com; s=arc-20160816; b=vVcC8gWfp6w9q3t0FKeYfDw3hia9+H0IZT0YgGg4CZ9Du5yM0+jwwqJXinPzSIQPsb EThC0B5K2K8c2KBUKSE2HHub/tr98tsF8K6Ljm3d9XSbheAiYq60iJnWJrBCGJEMmh1j /QuQkZKNxIAo4AZnt/BHk5nuUTrJ3NPw5NR5qhNyjOiKPeAyaxdRc77cbqXOCCJkMYC/ botYv1nMm5m/eIthh3IWi7XtSxoBW9lezjQgx7UbuMn6Ff2lz2/fyJKUYjmnDGrJ3Y+o CbkXDTEXiMX3jLXwDkTwSbWXuyUfRw3bpZBe4W1LkgHjQ2E1BRODEg2ppSMU2RhtA3+D 6Czw== 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 :arc-authentication-results; bh=agY955QOFxWbGZcRFNhW8S4nJo3bdXLmJDBfqqIJHpk=; b=y9qcU8YoX9bIzXCUqzqKzhd63qLV3UDV5J1W+Db95nQxx5S2EfU8KHetEP5pBlhxF2 f6oykyQ2Poe//7/OexEnQGe2oLz/M25vhgry3zcUSaU27eBAZI7Xx3yUpa/1iRe5Xclz NslHBIwAJn4CsRb4QJzD6t08JBPQPMvS9mWsT9O5dR2T2r3a680iPFiJYsehSaoGTlF2 kKg00e19Y5n7BnjdjHHKfhCOMpMPctiWN+OR6Iid9t46Go+DPKLeuRkv7Jxdzib0R0B9 WJc4seevPaYHy7ZezZKqpkyCGCy/Zhm1wpcllTb8axSowSjIbWmldvJ6oCM9tD8vnHaD Z5Gw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q14si4730329wrc.485.2017.09.04.02.47.48; Mon, 04 Sep 2017 02:47:49 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8B29168A236; Mon, 4 Sep 2017 12:47:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.nerd.lan (unknown [185.84.18.22]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AD69668A1EC for ; Mon, 4 Sep 2017 12:47:36 +0300 (EEST) Received: from WKS-41L8CC2-LN.nerd.lan (wks-41l8cc2-ln.nerd.lan [10.100.1.3]) by mail.nerd.lan (Postfix) with ESMTP id 0E27F180672; Mon, 4 Sep 2017 11:47:38 +0200 (CEST) From: Gildas Fargeas To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Sep 2017 11:47:30 +0200 Message-Id: <20170904094730.32547-1-fargeas.gildas@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avdevice/decklink: new options 'list_pixelformats' and 'pixelformat_code' to allow pixelformat selection by code 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: Gildas Fargeas MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Thanks for the feedback. Here are the changes: - renamed pixelformat_option in raw_format - restored bm_v210 options (if set, it overrides the raw_format option) - removed list_pixelformats and only mention supported raw codes in help. - restore previous handling of output Regarding the special handling of ARGB; the DeckLink API declares the ARGB enum with a value of 32 which cannot be casted to the string ARGB. (refer to DeckLinkAPIModes.h:132 v10.9.5) It is not ideal but that seemed to be an appropriate way to map the value. Let me know if you have something better in mind. Signed-off-by: Gildas Fargeas --- libavdevice/decklink_common.cpp | 17 ++++++++++++++++- libavdevice/decklink_common.h | 1 + libavdevice/decklink_common_c.h | 1 + libavdevice/decklink_dec.cpp | 40 ++++++++++++++++++++++++++++++++-------- libavdevice/decklink_dec_c.c | 1 + 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/libavdevice/decklink_common.cpp b/libavdevice/decklink_common.cpp index cbb591ce64..d0a80c1897 100644 --- a/libavdevice/decklink_common.cpp +++ b/libavdevice/decklink_common.cpp @@ -203,6 +203,21 @@ int ff_decklink_set_format(AVFormatContext *avctx, if (cctx->format_code) memcpy(format_buf, cctx->format_code, FFMIN(strlen(cctx->format_code), sizeof(format_buf))); BMDDisplayMode target_mode = (BMDDisplayMode)AV_RB32(format_buf); + + char pixel_buf[] = " "; + ctx->bmd_pixel= bmdFormat8BitYUV; + if (!strcmp(cctx->raw_format, "ARGB")) { + /* DeckLink API value (32) for this one cannot be casted back into the string ARGB. */ + ctx->bmd_pixel = bmdFormat8BitARGB; + } else { + memcpy(pixel_buf, cctx->raw_format, FFMIN(strlen(cctx->raw_format), sizeof(pixel_buf))); + ctx->bmd_pixel = (BMDPixelFormat)AV_RB32(pixel_buf); + } + + if (cctx->v210) { + ctx->bmd_pixel = bmdFormat10BitYUV; + } + AVRational target_tb = av_make_q(tb_num, tb_den); ctx->bmd_mode = bmdModeUnknown; while ((ctx->bmd_mode == bmdModeUnknown) && itermode->Next(&mode) == S_OK) { @@ -241,7 +256,7 @@ int ff_decklink_set_format(AVFormatContext *avctx, if (ctx->bmd_mode == bmdModeUnknown) return -1; if (direction == DIRECTION_IN) { - if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, bmdFormat8BitYUV, + if (ctx->dli->DoesSupportVideoMode(ctx->bmd_mode, ctx->bmd_pixel, bmdVideoOutputFlagDefault, &support, NULL) != S_OK) return -1; diff --git a/libavdevice/decklink_common.h b/libavdevice/decklink_common.h index 749eb0f8b8..770888a00b 100644 --- a/libavdevice/decklink_common.h +++ b/libavdevice/decklink_common.h @@ -56,6 +56,7 @@ struct decklink_ctx { BMDTimeValue bmd_tb_den; BMDTimeValue bmd_tb_num; BMDDisplayMode bmd_mode; + BMDPixelFormat bmd_pixel; BMDVideoConnection video_input; BMDAudioConnection audio_input; int bmd_width; diff --git a/libavdevice/decklink_common_c.h b/libavdevice/decklink_common_c.h index e263480474..a1eb225fbd 100644 --- a/libavdevice/decklink_common_c.h +++ b/libavdevice/decklink_common_c.h @@ -49,6 +49,7 @@ struct decklink_cctx { int video_input; int draw_bars; char *format_code; + char *raw_format; int64_t queue_size; }; diff --git a/libavdevice/decklink_dec.cpp b/libavdevice/decklink_dec.cpp index c271ff3639..df12d41050 100644 --- a/libavdevice/decklink_dec.cpp +++ b/libavdevice/decklink_dec.cpp @@ -680,8 +680,8 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) if (mode_num > 0 || cctx->format_code) { if (ff_decklink_set_format(avctx, DIRECTION_IN, mode_num) < 0) { - av_log(avctx, AV_LOG_ERROR, "Could not set mode number %d or format code %s for %s\n", - mode_num, (cctx->format_code) ? cctx->format_code : "(unset)", fname); + av_log(avctx, AV_LOG_ERROR, "Could not set mode number %d, format code %s or pixel format %s for %s\n", + mode_num, (cctx->format_code) ? cctx->format_code : "(unset)", cctx->raw_format, fname); ret = AVERROR(EIO); goto error; } @@ -723,15 +723,39 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) st->time_base.num = ctx->bmd_tb_num; av_stream_set_r_frame_rate(st, av_make_q(st->time_base.den, st->time_base.num)); - if (cctx->v210) { + switch(ctx->bmd_pixel) { + case bmdFormat8BitYUV: + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->format = AV_PIX_FMT_UYVY422; + st->codecpar->bit_rate = av_rescale(ctx->bmd_width * ctx->bmd_height * 16, st->time_base.den, st->time_base.num); + break; + case bmdFormat10BitYUV: st->codecpar->codec_id = AV_CODEC_ID_V210; st->codecpar->codec_tag = MKTAG('V', '2', '1', '0'); + st->codecpar->bits_per_coded_sample = 10; st->codecpar->bit_rate = av_rescale(ctx->bmd_width * ctx->bmd_height * 64, st->time_base.den, st->time_base.num * 3); - } else { + + break; + case bmdFormat8BitARGB: st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; - st->codecpar->format = AV_PIX_FMT_UYVY422; - st->codecpar->codec_tag = MKTAG('U', 'Y', 'V', 'Y'); - st->codecpar->bit_rate = av_rescale(ctx->bmd_width * ctx->bmd_height * 16, st->time_base.den, st->time_base.num); + st->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag((enum AVPixelFormat)st->codecpar->format); + st->codecpar->format = AV_PIX_FMT_ARGB; + break; + case bmdFormat8BitBGRA: + st->codecpar->codec_id = AV_CODEC_ID_RAWVIDEO; + st->codecpar->codec_tag = avcodec_pix_fmt_to_codec_tag((enum AVPixelFormat)st->codecpar->format); + st->codecpar->format = AV_PIX_FMT_BGRA; + break; + case bmdFormat10BitRGB: + st->codecpar->codec_id = AV_CODEC_ID_R210; + st->codecpar->format = AV_PIX_FMT_RGB48LE; + st->codecpar->codec_tag = MKTAG('R', '2', '1', '0'); + st->codecpar->bits_per_coded_sample = 10; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Raw Format %s not supported\n", cctx->raw_format); + ret = AVERROR(EINVAL); + goto error; } switch (ctx->bmd_field_dominance) { @@ -776,7 +800,7 @@ av_cold int ff_decklink_read_header(AVFormatContext *avctx) } result = ctx->dli->EnableVideoInput(ctx->bmd_mode, - cctx->v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV, + ctx->bmd_pixel, bmdVideoInputFlagDefault); if (result != S_OK) { diff --git a/libavdevice/decklink_dec_c.c b/libavdevice/decklink_dec_c.c index e2118a619c..881f52b4ae 100644 --- a/libavdevice/decklink_dec_c.c +++ b/libavdevice/decklink_dec_c.c @@ -34,6 +34,7 @@ static const AVOption options[] = { { "list_formats", "list supported formats" , OFFSET(list_formats), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC }, { "format_code", "set format by fourcc" , OFFSET(format_code), AV_OPT_TYPE_STRING, { .str = NULL}, 0, 0, DEC }, { "bm_v210", "v210 10 bit per channel" , OFFSET(v210), AV_OPT_TYPE_INT , { .i64 = 0 }, 0, 1, DEC }, + { "raw_format", "set raw_format (2vuy, v210, ARGB, BGRA, r210)" , OFFSET(raw_format), AV_OPT_TYPE_STRING, { .str = "2vuy"}, 0, 0, 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"}, { "all", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0x7ffffffffLL}, 0, 0, DEC, "teletext_lines"},