From patchwork Mon Sep 16 05:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: martin schitter X-Patchwork-Id: 51618 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9fc3:0:b0:48e:c0f8:d0de with SMTP id k3csp1073738vqy; Sun, 15 Sep 2024 23:04:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXRL/A91cDtCcD8CMv7A2pnMOT7Wn1bdKvU85UoPoVaeNK22v7DbVFtjsgg4qMMZK1Tecza73TNyKVf7DmN//4l@gmail.com X-Google-Smtp-Source: AGHT+IF5H8LvrEjAgY1owCkrDALcrx1mtCiT27GJBFRhfQ3tKpLmKysJRPQqjPqCm22lgmL7xxlS X-Received: by 2002:a05:651c:502:b0:2f1:a19b:d5a4 with SMTP id 38308e7fff4ca-2f787ed88cbmr67483891fa.22.1726466654253; Sun, 15 Sep 2024 23:04:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726466654; cv=none; d=google.com; s=arc-20240605; b=Uu8Q/r4B1TeGXvj5wp1jhUt/hstrJ4z67Wu8DGAA/DWe44KX/LWj5xSAw09ofDZNq1 AtEzJ6kNZBoWID3EOKLi+bF8/ScIem+KHiqSohxf8w7kw0iZmuzNBhmgqtOU/bs/WFhZ 16O9fYdwvUdxHIe5SThvNaQUkqXvFe0ZGv35memUB2zIhaBxt5ZftW3Ty3VuT3NyzZ6m gvhMg/z11y6z0kbmgOJU5tEPNnoFJXUo0BsSQPwOp6SX4VHJsLhn8mrR4AIzSoqQtasj ses4lIvxkJcl/SapL0EX6AzdGyc9XBvUhi2mmLFrgq209mBrcR3mK5BzlqLaOoEn0UqF pX1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=QLi+c17U5rQLyGB3oR8RjegSufCdkSU7GY9T9KxDNaY=; fh=igg3JDwkSkAbPTwY6V0OsEq0RUkG4DKWC8fVJg4GhMY=; b=g8DSAnzYBk9kmCR14dVDhvbj8TW2gbv3Z5ycZYQD5jPmrpAr+RG+cjO2RH6a9Z4ADg EeQycnsv/LS8s4hiZ3Ats92Xo7BJ4LEeHvgwGyb48mdc/eM/L0H/zyUGI9dNsuSFUY/a CMigT8CWslDvGeJKuDjojbpxdGaP3q2kmyrGE+K+xVTVjnkPSIoigGlAzrQm2Vwn3pmd b7aOIylr/slEzQ/k5uuPbEXfXzd2VZ2g7bLTLuKPsgXBsDAMW0hsfNguPRl/Omw3KpXF P7Kc6gtxxftpaCqLdSz5jCGlJ/F/ggw3GuaZAqKtbBdcyZ8u3WQp20CPa5sv7cOq908+ Im2w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=C0wW3pVG; 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=mur.at Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2f79d378ec4si13568151fa.356.2024.09.15.23.04.13; Sun, 15 Sep 2024 23:04:14 -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; dkim=neutral (body hash did not verify) header.i=@mur.at header.s=dkim2 header.b=C0wW3pVG; 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=mur.at Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A060F68DCB3; Mon, 16 Sep 2024 08:54:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7BEC368DC83 for ; Mon, 16 Sep 2024 08:54:41 +0300 (EEST) Received: from localhost.localdomain (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 143B646366; Mon, 16 Sep 2024 07:54:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1726466081; bh=AV0+Nv8sLEZkU2hgu2ecGbyrVazOdCLGe11FQ4qCeDs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C0wW3pVG3wCHuIAcNJUdUqd9YWPtnn25SoyJqLNV2jsnt4jOw0YotsX/WAvcBVxd5 FrIMuiHdz6ZG0VArMEbprpfwxEv1XqXIqTCMTXnnYWgxhT+4CT+XjlZi90/TFVuEVd A2ipBo7bY/cvrb5FVOQvf+Tu/azR5wNhsIvwORf1JU0B5ZXiiMWpzvR2H7vj/xmOnx iyPrnl3UW6u4ZaL1LKR8EuUwPx2CRw/pxd/IaUWBMf9xOU1wVYT0WgqBsQBFyfnc72 850+uTl+5GUkAXQPjLAFopul+uArr9dC0hOkr64Apl9SW/zO6Ip5uNsUHd9Kzvh7gW pfHUCODWnitWqCjPsitP7UjUlntZ4SnT3lCYBaLbRImeTCaVvSEaSRV3/0DTLM/iWj xPfJtnKGDH9zOjSPNG9JZNuTbdUgVS6p6uKLJ9k+FlRBnwNUGFHDYk6VceAx7KGGNi CAcarGp0OzEbgpaSN4wKegcDnLA6F2IoJJo1BVc6p0yPn2q9FxU From: Martin Schitter To: ffmpeg-devel@ffmpeg.org Date: Mon, 16 Sep 2024 07:52:49 +0200 Message-ID: <20240916055250.1559817-5-ms+git@mur.at> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240916055250.1559817-2-ms+git@mur.at> References: <20240916055250.1559817-2-ms+git@mur.at> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v7 4/6] libavcodec/dnxucdec: DNxUncompressed decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Martin Schitter Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: CSY1L8nSxSK+ --- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/dnxucdec.c | 391 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 393 insertions(+) create mode 100644 libavcodec/dnxucdec.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 55444cb..b2f00af 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -325,6 +325,7 @@ OBJS-$(CONFIG_DFPWM_DECODER) += dfpwmdec.o OBJS-$(CONFIG_DFPWM_ENCODER) += dfpwmenc.o OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o +OBJS-$(CONFIG_DNXUC_DECODER) += dnxucdec.o OBJS-$(CONFIG_DOLBY_E_DECODER) += dolby_e.o dolby_e_parse.o kbdwin.o OBJS-$(CONFIG_DPX_DECODER) += dpx.o OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index d773ac3..1a3c084 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -93,6 +93,7 @@ extern const FFCodec ff_dfa_decoder; extern const FFCodec ff_dirac_decoder; extern const FFCodec ff_dnxhd_encoder; extern const FFCodec ff_dnxhd_decoder; +extern const FFCodec ff_dnxuc_decoder; extern const FFCodec ff_dpx_encoder; extern const FFCodec ff_dpx_decoder; extern const FFCodec ff_dsicinvideo_decoder; diff --git a/libavcodec/dnxucdec.c b/libavcodec/dnxucdec.c new file mode 100644 index 0000000..8fffd0a --- /dev/null +++ b/libavcodec/dnxucdec.c @@ -0,0 +1,391 @@ +/* + * Avid DNxUncomressed / SMPTE RDD 50 decoder + * Copyright (c) 2024 Martin Schitter + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/* + This decoder for DNxUncompressed video data is mostly based on + reverse engineering of output generated by DaVinci Resolve 19 + but was later also checked against the SMPTE RDD 50 specification. + + Not all DNxUncompressed pixel format variants are supported, + but at least an elementary base set is already usable: + + - YUV 4:2:2 8/10/12bit + - RGB 8/10/12bit/half/float + +*/ + +#include "avcodec.h" +#include "codec_internal.h" +#include "decode.h" +#include "libavutil/imgutils.h" +#include "thread.h" + +static av_cold int dnxuc_decode_init(AVCodecContext *avctx) +{ + return 0; +} + + +static int pass_though(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt) +{ + /* there is no need to copy as the data already match + * a known pixel format */ + + frame->buf[0] = av_buffer_ref(avpkt->buf); + + if (!frame->buf[0]) { + return AVERROR(ENOMEM); + } + + return av_image_fill_arrays(frame->data, frame->linesize, avpkt->data, + avctx->pix_fmt, avctx->width, avctx->height, 1); +} + +static int float2planes(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw; + const size_t sof = 4; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + memcpy(&frame->data[2][sof*(lw*y + x)], &pkt->data[sof* 3*(lw*y + x)], sof); + memcpy(&frame->data[0][sof*(lw*y + x)], &pkt->data[sof*(3*(lw*y + x) + 1)], sof); + memcpy(&frame->data[1][sof*(lw*y + x)], &pkt->data[sof*(3*(lw*y + x) + 2)], sof); + } + } + return pkt->size; +} + +static int half_add_alpha(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + /* ffmpeg doesn't provide RGB half bit depth without alpha channel right now + * we simply add an opaque alpha layer as workaround */ + + int x, y, lw; + const size_t soh = 2; + const uint16_t opaque = 0x3c00; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + memcpy(&frame->data[0][soh*4*(lw*y + x)], &pkt->data[soh*3*(lw*y + x)], soh*3); + memcpy(&frame->data[0][soh*(4*(lw*y + x) + 3)], &opaque, soh); + } + } + return pkt->size; +} + +/* DNxUncompressed utilizes a very dense bitpack representation of 10bit and 12bit pixel data. + +Lines of Image data, which look like in their ordinary 8bit counterpart, contain the most +significant upper bits of the pixel data. These sections alternate with shorter segments in +which the complementary least significant bits of information get packed in a gapless sequence. + ++----------------------+ +----------------------+ +------------------------+ +----------~ +| 8 m.s.bits of R[1] | | 8 m.s.bits of G[1] | | 8 m.s.bits of B[1] | | msb R[2] ... one line ++----------------------+ +----------------------+ +------------------------+ +----------~ + ++---------------------------------------------------------------+ +-----------~ +| +------------+ +------------+ +------------+ +--------------+ | | +--------~ +| | 2 lsb R[2] | | 2 lsb B[1] | | 2 lsb G[1] | | 2 lsb R[1] | | | | G[3]lsb ... LSB bits for line +| +------------+ +------------+ +------------+ +--------------+ | | +--------~ ++---------------------------- one byte ------------------------ + +-----------~ + +next line of MSB bytes... */ + +static int unpack_rg10(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t r,g,b; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + msp = pkt->data[y*3*(lw + lw/4) + 3*x]; + p_off = y*(3*(lw + lw/4)) + 3*lw + 3*x/4; + pack = pkt->data[p_off]; + lsp = (pack >> (3*x%4)*2) & 0x3; + r = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "r: %04x, %02x, %02x, %02x, %d\n", + // r, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/4) + 3*x + 1]; + p_off = y*(3*(lw + lw/4)) + 3*lw + (3*x+1)/4; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+1)%4)*2) & 0x3; + g = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "g: %04x, %02x, %02x, %02x, %d\n", + // g, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/4) + 3*x + 2]; + p_off = y*(3*(lw + lw/4)) + 3*lw + (3*x+2)/4; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+2)%4)*2) & 0x3; + b = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "b: %04x, %02x, %02x, %02x, %d\n\n", + // b, msp, lsp, pack, p_off); + + memcpy(&frame->data[2][2*(y*lw + x)], &r, 2); + memcpy(&frame->data[0][2*(y*lw + x)], &g, 2); + memcpy(&frame->data[1][2*(y*lw + x)], &b, 2); + } + } + return pkt->size; +} + +static int unpack_rg12(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t r,g,b; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x++){ + msp = pkt->data[y*3*(lw + lw/2) + 3*x]; + p_off = y*(3*(lw + lw/2)) + 3*lw + 3*x/2; + pack = pkt->data[p_off]; + lsp = (pack >> (3*x%2)*4) & 0xf; + r = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "r: %04x, %02x, %02x, %02x, %d\n", + // r, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/2) + 3*x + 1]; + p_off =y*(3*(lw + lw/2)) + 3*lw + (3*x+1)/2; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+1)%2)*4) & 0xf; + g = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "g: %04x, %02x, %02x, %02x, %d\n", + // g, msp, lsp, pack, p_off); + + msp = pkt->data[y*3*(lw + lw/2) + 3*x + 2]; + p_off = y*(3*(lw + lw/2)) + 3*lw + (3*x+2)/2; + pack = pkt->data[p_off]; + lsp = (pack >> ((3*x+2)%2)*4) & 0xf; + b = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "b: %04x, %02x, %02x, %02x, %d\n\n", + // b, msp, lsp, pack, p_off); + + memcpy(&frame->data[2][2*(y*lw + x)], &r, 2); + memcpy(&frame->data[0][2*(y*lw + x)], &g, 2); + memcpy(&frame->data[1][2*(y*lw + x)], &b, 2); + } + } + return pkt->size; +} + + +static int unpack_y210(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t y1, y2, u, v; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x += 2){ + + p_off = y*(2*(lw + lw/4)) + 2*lw + x/2; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/4) + 2*x]; + lsp = pack & 0x3; + u = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, " u: %04x, %02x, %02x, %02x, %d\n", + // u, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 1]; + lsp = (pack >> 2) & 0x3; + y1 = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "y1: %04x, %02x, %02x, %02x, %d\n", + // y1, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 2]; + lsp = (pack >> 4) & 0x3; + v = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, " v: %04x, %02x, %02x, %02x, %d\n", + // v, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/4) + 2*x + 3]; + lsp = (pack >> 6) & 0x3; + y2 = (msp << 2) + lsp; + // av_log(0, AV_LOG_DEBUG, "y2: %04x, %02x, %02x, %02x, %d\n\n", + // y2, msp, lsp, pack, p_off); + + memcpy(&frame->data[0][2*(y*lw + x)], &y1, 2); + memcpy(&frame->data[0][2*(y*lw + x+1)], &y2, 2); + memcpy(&frame->data[1][2*(y*lw/2 + x/2)], &u, 2); + memcpy(&frame->data[2][2*(y*lw/2 + x/2)], &v, 2); + } + } + return pkt->size; +} + + +static int unpack_y212(AVCodecContext *avctx, AVFrame *frame, const AVPacket *pkt) +{ + int x, y, lw, msp, pack, lsp, p_off; + uint16_t y1, y2, u, v; + + lw = frame->width; + + for(y = 0; y < frame->height; y++){ + for(x = 0; x < frame->width; x += 2){ + + p_off = y*(2*(lw + lw/2)) + 2*lw + x; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/2) + 2*x]; + lsp = pack & 0xf; + u = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, " u: %04x, %02x, %02x, %02x, %d\n", + // u, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 1]; + lsp = (pack >> 4) & 0xf; + y1 = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "y1: %04x, %02x, %02x, %02x, %d\n", + // y1, msp, lsp, pack, p_off); + + p_off = y*(2*(lw + lw/2)) + 2*lw + x+1; + pack = pkt->data[p_off]; + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 2]; + lsp = pack & 0xf; + v = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, " v: %04x, %02x, %02x, %02x, %d\n", + // v, msp, lsp, pack, p_off); + + msp = pkt->data[y*2*(lw + lw/2) + 2*x + 3]; + lsp = (pack >> 4) & 0xf; + y2 = (msp << 4) + lsp; + // av_log(0, AV_LOG_DEBUG, "y2: %04x, %02x, %02x, %02x, %d\n\n", + // y2, msp, lsp, pack, p_off); + + memcpy(&frame->data[0][2*(y*lw + x)], &y1, 2); + memcpy(&frame->data[0][2*(y*lw + x+1)], &y2, 2); + memcpy(&frame->data[1][2*(y*lw/2 + x/2)], &u, 2); + memcpy(&frame->data[2][2*(y*lw/2 + x/2)], &v, 2); + } + } + return pkt->size; +} + +static int check_pkt_size(AVCodecContext *avctx, AVPacket *avpkt, int bpp) +{ + int needed = ((avctx->width * bpp + 7) / 8) * avctx->height; + if (avpkt->size < needed){ + av_log(avctx, AV_LOG_ERROR, + "Insufficient size of AVPacket data (pkg size: %d needed: %d)\n", avpkt->size, needed); + return AVERROR_EXIT; + } + return 0; +} + +static int fmt_frame(AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt, + enum AVPixelFormat pix_fmt, int src_bpp, + int (*frame_handler)(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt)) +{ + int ret; + avctx->pix_fmt = pix_fmt; + + ret = check_pkt_size(avctx, avpkt, src_bpp); + if (ret) + return ret; + + ret = ff_thread_get_buffer(avctx, frame, 0); + if (ret < 0) + return ret; + + return frame_handler(avctx, frame, avpkt); +} + +static int dnxuc_decode_frame(AVCodecContext *avctx, AVFrame *frame, + int *got_frame, AVPacket *avpkt) +{ + char fourcc_buf[5]; + int ret; + + av_fourcc_make_string(fourcc_buf, avctx->codec_tag); + if ((avctx->width % 2) && ((fourcc_buf[0] == 'y' && fourcc_buf[1] == '2') + ||(fourcc_buf[1] == 'y' && fourcc_buf[2] == '2'))){ + av_log(avctx, AV_LOG_ERROR, + "Image width must be a multiple of 2 for YUV 4:2:2 DNxUncompressed!\n"); + return AVERROR_EXIT; + } + + switch (avctx->codec_tag) { + case MKTAG('r','g','0','8'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_RGB24, 24, pass_though); + break; + case MKTAG('r','g','1','0'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRP10LE, 30, unpack_rg10); + break; + case MKTAG('r','g','1','2'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRP12LE, 36, unpack_rg12); + break; + case MKTAG(' ','r','g','h'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_RGBAF16LE, 48, half_add_alpha); + break; + case MKTAG(' ','r','g','f'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_GBRPF32LE, 96, float2planes); + break; + + case MKTAG('y','2','0','8'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_UYVY422, 16, pass_though); + break; + case MKTAG('y','2','1','0'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_YUV422P10LE, 20, unpack_y210); + break; + case MKTAG('y','2','1','2'): + ret = fmt_frame(avctx, frame, avpkt, AV_PIX_FMT_YUV422P12LE, 24, unpack_y212); + break; + + default: + av_log(avctx, AV_LOG_ERROR, + "Unsupported DNxUncompressed pixel format variant: '%s'\n", + fourcc_buf); + return AVERROR(ENOSYS); + } + + if (ret < 0) { + av_buffer_unref(&frame->buf[0]); + return ret; + } + + *got_frame = 1; + + return avpkt->size; +} + +const FFCodec ff_dnxuc_decoder = { + .p.name = "dnxuc", + CODEC_LONG_NAME("DNxUncompressed (SMPTE RDD 50)"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_DNXUC, + .init = dnxuc_decode_init, + FF_CODEC_DECODE_CB(dnxuc_decode_frame), + .p.capabilities = AV_CODEC_CAP_FRAME_THREADS, +};