Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH v3 01/13] avcodec/dovi_rpu: store entire config record
Date: Fri, 12 Apr 2024 13:35:15 +0200
Message-ID: <20240412113620.84013-2-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240412113620.84013-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

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 824725c031..4c1405df77 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 9f7a6b0066..d95c7e03af 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 9f26f332ce..9a68e45bf1 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 007eae6a1e..7825efe2e6 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3365,14 +3365,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;
@@ -3666,8 +3665,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 93c77ed9c6..09fe767fb8 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;
 }
 
-- 
2.44.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2024-04-12 11:36 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 11:35 [FFmpeg-devel] [PATCH v3 00/13] avcodec: add Dolby Vision encoding Niklas Haas
2024-04-12 11:35 ` Niklas Haas [this message]
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 02/13] avcodec/dovi_rpu: properly replace context header Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 03/13] avcodec/dovi_rpu: clarify error on missing RPU VDR Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 04/13] avcodec/dovi_rpu: expose guess_profile(), clarify semantics Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 05/13] configure: rename dovi_rpu subsystem to dovi_rpudec Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 06/13] avcodec/dovi_rpu: split into dovi_rpu.c and dovi_rpudec.c Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 07/13] avcodec/dovi_rpuenc: add ff_dovi_configure() Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 08/13] avcodec/dovi_rpudec: make `enable` also affect decoding Niklas Haas
2024-04-18 11:30   ` Andreas Rheinhardt
2024-04-18 12:23     ` Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 09/13] avcodec/dovi_rpuenc: add ff_dovi_rpu_generate() Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 10/13] avformat/movenc: warn if dovi cfg ignored Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 11/13] avcodec/libaomenc: implement dolby vision coding Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 12/13] avcodec/libx265: " Niklas Haas
2024-04-12 11:35 ` [FFmpeg-devel] [PATCH v3 13/13] avcodec/libsvtav1: " Niklas Haas
2024-04-17 12:22 ` [FFmpeg-devel] [PATCH v3 00/13] avcodec: add Dolby Vision encoding Niklas Haas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240412113620.84013-2-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git