From patchwork Sat Jan 30 09:19:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Gisquet X-Patchwork-Id: 25274 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 350D244B489 for ; Sat, 30 Jan 2021 11:20:31 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 24A6268A78A; Sat, 30 Jan 2021 11:20:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99141688104 for ; Sat, 30 Jan 2021 11:20:21 +0200 (EET) Received: by mail-wr1-f44.google.com with SMTP id c4so8487275wru.9 for ; Sat, 30 Jan 2021 01:20:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=OkJDgYjHvMSMIxLggofJgLb8Ixk0Bbyzp0QOqj7jlPw=; b=Y4A96SQAqakrWwYABpwdOqYfEQoaEKnY19M73dcGjjN/qw9e06wMwbXA7c2Vsvt0Pp KVvDyCUfLxsi8hCQ7UcdHywsUmHBt3/w7qM/xqyMuFfnmxnUz7VS/Fvjg4YOg1jB2tse HxkTwhN1mNpxR5lT6UejPHw/tJ/kB+MNuYzwEBvQn9wmSFQK2ea5w+SS/2kSHSsi5cD7 eqDrRoNBsPXLIttjK/kUSY7k/crvIcolAztbjs/6UZe11xbnXc/S8L6yFNOAyFJ+nl+S HuKO/kny4t6N0o/fDlmMmPUgz5zpmEmmsaRGL4Y1/3qXAjrnuBeiXPV1NGpcMW63MYyw aVbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OkJDgYjHvMSMIxLggofJgLb8Ixk0Bbyzp0QOqj7jlPw=; b=gDEplL3FC+Q0T3QAwVYxHIGlJGsXrB9SERSNDCEmV1lK5KXFSJ0IjpWj/3Nl/+Cgf/ H4AGzBmNL/RfeQXaBMeLTkfJoSO6oV8UX+FZFHf/cZ10Q8sTVXqZkyLhZs85w2ZD8N3U Ws+n/DSNGzvqaUoHeKB3uX9tNuTx/1cvV3XtZEzT0Lm4YMIPoBcol6i1Ndtix08WI5vd lb0fWGNi/pYHEzk2aMqeQpeIHeARaFTrSwwKducO58kHDVg6ZGJI/IRx9kazFvHqr7sA bBMF5x7MKOhhjXx7PgE+KlBuqmtlKwcwSVoIwR+sB15gf4PFrFTYpduihBjCLFnRgAE5 G2Yg== X-Gm-Message-State: AOAM532oS47UOdO5Y1iTlSdq1YryVp/O5ErBVfI6rHU//1GM9kwPifQS fX4w/S4Bv9qtb7Zrc+FVpwtEL3oQIg== X-Google-Smtp-Source: ABdhPJwCQBMPCIaQtzf4RejXo7f18y6hps8+FpTHYM9+rulNND0kAl/19hsjDyILWC94VkyMP1iT4Q== X-Received: by 2002:a5d:5502:: with SMTP id b2mr8739659wrv.245.1611998421139; Sat, 30 Jan 2021 01:20:21 -0800 (PST) Received: from localhost.localdomain (lfbn-ren-1-785-160.w83-197.abo.wanadoo.fr. [83.197.112.160]) by smtp.gmail.com with ESMTPSA id w14sm16657582wro.86.2021.01.30.01.20.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Jan 2021 01:20:20 -0800 (PST) From: Christophe Gisquet To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 Jan 2021 09:19:04 +0000 Message-Id: <20210130091906.312-3-christophe.gisquet@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210130091906.312-1-christophe.gisquet@gmail.com> References: <20210130091906.312-1-christophe.gisquet@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] lav/dnxhd: CID 1256 is RGB, not BGR or YUV444 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Christophe Gisquet Fix the logic around checking the ACT flag per MB and row. This also requires adding a 444 path to swap channels into the ffmpeg formats, as they are GBR, and not RGB. --- libavcodec/dnxhddec.c | 64 +++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/libavcodec/dnxhddec.c b/libavcodec/dnxhddec.c index 359588f963..11da1c286c 100644 --- a/libavcodec/dnxhddec.c +++ b/libavcodec/dnxhddec.c @@ -249,12 +249,10 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame, return AVERROR_INVALIDDATA; } else if (bitdepth == 10) { ctx->decode_dct_block = dnxhd_decode_dct_block_10_444; - ctx->pix_fmt = ctx->act ? AV_PIX_FMT_YUV444P10 - : AV_PIX_FMT_GBRP10; + ctx->pix_fmt = ctx->act ? AV_PIX_FMT_GBRP10 : AV_PIX_FMT_YUV444P10; } else { ctx->decode_dct_block = dnxhd_decode_dct_block_12_444; - ctx->pix_fmt = ctx->act ? AV_PIX_FMT_YUV444P12 - : AV_PIX_FMT_GBRP12; + ctx->pix_fmt = ctx->act ? AV_PIX_FMT_GBRP12 : AV_PIX_FMT_YUV444P12; } } else if (bitdepth == 12) { ctx->decode_dct_block = dnxhd_decode_dct_block_12; @@ -504,19 +502,19 @@ static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row, qscale = get_bits(&row->gb, 11); } act = get_bits1(&row->gb); - if (act) { - if (!ctx->act) { - static int act_warned; - if (!act_warned) { - act_warned = 1; - av_log(ctx->avctx, AV_LOG_ERROR, - "ACT flag set, in violation of frame header.\n"); - } - } else if (row->format == -1) { + if (ctx->act) { + if (row->format == -1) { row->format = act; } else if (row->format != act) { row->format = 2; // Variable } + } else if (act) { + static int act_warned; + if (!act_warned) { + act_warned = 1; + av_log(ctx->avctx, AV_LOG_ERROR, + "ACT flag set, in violation of frame header.\n"); + } } if (qscale != row->last_qscale) { @@ -569,6 +567,21 @@ static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row, } break; case DNX_CHROMAFORMAT_444: + if (ctx->avctx->profile == FF_PROFILE_DNXHD) { + ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->blocks[2]); + ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->blocks[3]); + ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->blocks[8]); + ctx->idsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[9]); + + ctx->idsp.idct_put(dest_u, dct_linesize_luma, row->blocks[4]); + ctx->idsp.idct_put(dest_u + dct_x_offset, dct_linesize_luma, row->blocks[5]); + ctx->idsp.idct_put(dest_u + dct_y_offset, dct_linesize_luma, row->blocks[10]); + ctx->idsp.idct_put(dest_u + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[11]); + ctx->idsp.idct_put(dest_v, dct_linesize_luma, row->blocks[0]); + ctx->idsp.idct_put(dest_v + dct_x_offset, dct_linesize_luma, row->blocks[1]); + ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_luma, row->blocks[6]); + ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_luma, row->blocks[7]); + } else { ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->blocks[0]); ctx->idsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, row->blocks[1]); ctx->idsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, row->blocks[6]); @@ -585,6 +598,7 @@ static int dnxhd_decode_macroblock(const DNXHDContext *ctx, RowContext *row, ctx->idsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, row->blocks[10]); ctx->idsp.idct_put(dest_v + dct_y_offset + dct_x_offset, dct_linesize_chroma, row->blocks[11]); } + } break; case DNX_CHROMAFORMAT_420: ctx->idsp.idct_put(dest_y, dct_linesize_luma, row->blocks[0]); @@ -610,6 +624,8 @@ static int dnxhd_decode_row(AVCodecContext *avctx, void *data, RowContext *row = ctx->rows + threadnb; int x, ret; + row->format = -1; + row->last_dc[0] = row->last_dc[1] = row->last_dc[2] = 1 << (ctx->bit_depth + 2); // for levels +2^(bitdepth-1) @@ -694,14 +710,21 @@ decode_coding_unit: static int act_warned; int format = ctx->rows[0].format; for (i = 1; i < avctx->thread_count; i++) { - if (ctx->rows[i].format != format && - ctx->rows[i].format != -1 /* not run */) { + if (ctx->rows[i].format == -1) + continue; + if (format == -1) { + format = ctx->rows[i].format; + continue; + } + if (ctx->rows[i].format != format) { + av_log(ctx->avctx, AV_LOG_ERROR, + "Format changed from %d to %d.\n", format, ctx->rows[i].format); format = 2; break; } } + switch (format) { - case -1: case 2: if (!act_warned) { act_warned = 1; @@ -709,6 +732,7 @@ decode_coding_unit: "Unsupported: variable ACT flag.\n"); } break; + case -1: case 0: ctx->pix_fmt = ctx->bit_depth==10 ? AV_PIX_FMT_GBRP10 : AV_PIX_FMT_GBRP12; @@ -719,12 +743,18 @@ decode_coding_unit: break; } } - avctx->pix_fmt = ctx->pix_fmt; if (ret) { av_log(ctx->avctx, AV_LOG_ERROR, "%d lines with errors\n", ret); return AVERROR_INVALIDDATA; } + if (avctx->pix_fmt != ctx->pix_fmt) { + picture->format = avctx->pix_fmt = ctx->pix_fmt; + ret = ff_set_dimensions(avctx, ctx->width, ctx->height); + if (ret < 0) + return ret; + } + *got_frame = 1; return avpkt->size; }