From patchwork Wed Apr 3 15:43:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 47753 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp485189pzb; Wed, 3 Apr 2024 08:43:54 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWI5l4T9IMAPZzCAHkourhrFwwuYNsV5q8g7yH5FKa0XrwqCoGh8WPnwAB4weQm02/QdfOixeXC+vMgM21dux9H1YIEqGuFmmzbIQ== X-Google-Smtp-Source: AGHT+IEhtUsk1UfBTQqtF0zjCrRMF1tS7qeeUUtBoDDY4gq4Ovh21UfX/f01qu4rj2nkbunAWq2B X-Received: by 2002:a17:906:4685:b0:a51:80d9:56de with SMTP id a5-20020a170906468500b00a5180d956demr97876ejr.5.1712159033849; Wed, 03 Apr 2024 08:43:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712159033; cv=none; d=google.com; s=arc-20160816; b=NNA3oMNwNm/97HCf4V1WFvRnQ8CRsMv6gns1YN4WuRppAkL+rXaIT7pRVMXBVruBl7 lVbdHzahDt22OL4qeaeS6m5789HrIeuRCJaJMGr9iO0FTnmiP1xyh9VRnuiapLwGuOQ7 yjrbdkmYbytthw3oeqVNoddrOfX8F3S3HCVVw36QICRmULyJSh4j19kpI3zlu+4VYrxY CL6jaM5UcR+iZ+qKaIha6Fs+Dj+93aSujzelMdDgbr0EAnwMHMztcZftk0OLlole9AG/ 0z4EVEawyQFx+K+VkFHn27+1q7n65P8MnOoMGGZmnkU+fKS4pnWPEzMGJry6Lzz94UXi m+cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=W+XNg0XMtRcfeo3ddIQWe94c8SFrFOY93o3X5el+KZA=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=KjjYp6RqjAMEnEXRW6/GnhgZm2yIcLoFOYa/zNo9WKW82USeYiYmL/HFTApP0Rd0Cg 1KiD1ATjZ9chIabI7QCNAct/jl84MLK+Pda4vUQ/8fkmm/UtW7taL+FzMhkO/BmaCqjF 8lqXxlRodXaZvQjW/pcY02bBp1BXnLX9A5O9HgangURf9hwjozNwaAbcOZTzc4LQB1+F s58cv3IFWeA/DgJ/Ug/Lr91vxbAjRDVHj/qlAzWcart5yrymvlcl+UICQuu+Lf6bzG7I cEt1i1Ll5hdZSo7j7fdBkkO9McWjXACN2hWAthGRviqoV0G6it0MTVl7bpLHnMlSi+mm f0mA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Tknzz8RT; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qu19-20020a170907111300b00a4df0d7789bsi6992169ejb.514.2024.04.03.08.43.53; Wed, 03 Apr 2024 08:43:53 -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=@haasn.xyz header.s=mail header.b=Tknzz8RT; 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 8793768D131; Wed, 3 Apr 2024 18:43:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4FB0668CE36 for ; Wed, 3 Apr 2024 18:43:34 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1712159014; bh=nYFw/fg0gv1zW1Avp5DH84erwqua5au5RGGis94z1S4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tknzz8RTTgmHbb8z9dMFx8xIrv9QoglFh9xz8rmsezjzyj8PAMDw5kaYm7YWehlsQ Yq0lF696VmOKGEqCWFKjjEcp5E9oS0h/F0AvWvx0rsyWGpZDe9SAMw9m4c8nDypgMV 4Em7nUkGbkNs18iXxHEhqxXO9MJDuACoujTymKZs= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id E01C741EC3; Wed, 3 Apr 2024 17:43:33 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Apr 2024 17:43:22 +0200 Message-ID: <20240403154330.71585-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240403154330.71585-1-ffmpeg@haasn.xyz> References: <20240403154330.71585-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/10] avcodec/dovi_rpu: store entire config record 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: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ih5czSrNSJLl From: Niklas Haas And make it public. For encoding, users may also be interested in the configured level and compatibility ID. So generalize the dv_profile field and just expose the whole configuration record. This makes the already rather reductive ff_dovi_update_cfg() function almost wholly redundant, since users can just directly assign DOVIContext.cfg. --- libavcodec/av1dec.c | 6 +++--- libavcodec/dovi_rpu.c | 16 ++++------------ libavcodec/dovi_rpu.h | 21 ++++++++++++--------- libavcodec/hevcdec.c | 13 ++++++------- libavcodec/libdav1d.c | 6 +++--- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 824725c031f..4c1405df779 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -888,10 +888,10 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) } s->dovi.logctx = avctx; - s->dovi.dv_profile = 10; // default for AV1 + s->dovi.cfg.dv_profile = 10; // default for AV1 sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); - if (sd && sd->size > 0) - ff_dovi_update_cfg(&s->dovi, (AVDOVIDecoderConfigurationRecord *) sd->data); + if (sd && sd->size >= sizeof(s->dovi.cfg)) + s->dovi.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; return ret; } diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c index 9f7a6b00664..d95c7e03af9 100644 --- a/libavcodec/dovi_rpu.c +++ b/libavcodec/dovi_rpu.c @@ -64,7 +64,7 @@ void ff_dovi_ctx_flush(DOVIContext *s) *s = (DOVIContext) { .logctx = s->logctx, - .dv_profile = s->dv_profile, + .cfg = s->cfg, /* preserve temporary buffer */ .rpu_buf = s->rpu_buf, .rpu_buf_sz = s->rpu_buf_sz, @@ -74,22 +74,14 @@ void ff_dovi_ctx_flush(DOVIContext *s) void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) { s->logctx = s0->logctx; + s->cfg = s0->cfg; s->mapping = s0->mapping; s->color = s0->color; - s->dv_profile = s0->dv_profile; for (int i = 0; i <= DOVI_MAX_DM_ID; i++) ff_refstruct_replace(&s->vdr[i], s0->vdr[i]); ff_refstruct_replace(&s->ext_blocks, s0->ext_blocks); } -void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg) -{ - if (!cfg) - return; - - s->dv_profile = cfg->dv_profile; -} - int ff_dovi_attach_side_data(DOVIContext *s, AVFrame *frame) { AVFrameSideData *sd; @@ -392,7 +384,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, goto fail; /* Container */ - if (s->dv_profile == 10 /* dav1.10 */) { + if (s->cfg.dv_profile == 10 /* dav1.10 */) { /* DV inside AV1 re-uses an EMDF container skeleton, but with fixed * values - so we can effectively treat this as a magic byte sequence. * @@ -517,7 +509,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, use_prev_vdr_rpu = get_bits1(gb); use_nlq = (hdr->rpu_format & 0x700) == 0 && !hdr->disable_residual_flag; - profile = s->dv_profile ? s->dv_profile : guess_profile(hdr); + profile = s->cfg.dv_profile ? s->cfg.dv_profile : guess_profile(hdr); if (profile == 5 && use_nlq) { av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n"); goto fail; diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h index 9f26f332ceb..9a68e45bf1b 100644 --- a/libavcodec/dovi_rpu.h +++ b/libavcodec/dovi_rpu.h @@ -31,6 +31,16 @@ typedef struct DOVIContext { void *logctx; + /** + * Currently active dolby vision configuration, or {0} for none. + * Set by the user when decoding. + * + * Note: sizeof(cfg) is not part of the libavutil ABI, so users should + * never pass &cfg to any other library calls. This is included merely as + * a way to look up the values of fields known at compile time. + */ + AVDOVIDecoderConfigurationRecord cfg; + /** * Currently active RPU data header, updates on every dovi_rpu_parse(). */ @@ -56,7 +66,6 @@ typedef struct DOVIContext { struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references uint8_t *rpu_buf; ///< temporary buffer unsigned rpu_buf_sz; - uint8_t dv_profile; } DOVIContext; @@ -68,17 +77,11 @@ void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0); void ff_dovi_ctx_unref(DOVIContext *s); /** - * Partially reset the internal state. Resets per-frame state while preserving - * fields parsed from the configuration record. + * Partially reset the internal state. Resets per-frame state, but preserves + * the stream-wide configuration record. */ void ff_dovi_ctx_flush(DOVIContext *s); -/** - * Read the contents of an AVDOVIDecoderConfigurationRecord (usually provided - * by stream side data) and update internal state accordingly. - */ -void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg); - /** * Parse the contents of a Dovi RPU NAL and update the parsed values in the * DOVIContext struct. diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 727b02f0f40..4bc9e2afc1d 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3364,14 +3364,13 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe, } sd = av_packet_get_side_data(avpkt, AV_PKT_DATA_DOVI_CONF, &sd_size); - if (sd && sd_size > 0) { - int old = s->dovi_ctx.dv_profile; - - ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd); + if (sd && sd_size >= sizeof(s->dovi_ctx.cfg)) { + int old = s->dovi_ctx.cfg.dv_profile; + s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd; if (old) av_log(avctx, AV_LOG_DEBUG, "New DOVI configuration record from input packet (profile %d -> %u).\n", - old, s->dovi_ctx.dv_profile); + old, s->dovi_ctx.cfg.dv_profile); } s->ref = s->collocated_ref = NULL; @@ -3661,8 +3660,8 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx) } sd = ff_get_coded_side_data(avctx, AV_PKT_DATA_DOVI_CONF); - if (sd && sd->size > 0) - ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd->data); + if (sd && sd->size >= sizeof(s->dovi_ctx.cfg)) + s->dovi_ctx.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; } return 0; diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c index f022a4ad05c..a2f44c65e34 100644 --- a/libavcodec/libdav1d.c +++ b/libavcodec/libdav1d.c @@ -290,10 +290,10 @@ static av_cold int libdav1d_init(AVCodecContext *c) #endif dav1d->dovi.logctx = c; - dav1d->dovi.dv_profile = 10; // default for AV1 + dav1d->dovi.cfg.dv_profile = 10; // default for AV1 sd = ff_get_coded_side_data(c, AV_PKT_DATA_DOVI_CONF); - if (sd && sd->size > 0) - ff_dovi_update_cfg(&dav1d->dovi, (AVDOVIDecoderConfigurationRecord *) sd->data); + if (sd && sd->size >= sizeof(dav1d->dovi.cfg)) + dav1d->dovi.cfg = *(AVDOVIDecoderConfigurationRecord *) sd->data; return 0; }