diff mbox series

[FFmpeg-devel,2/8] avcodec/dovi_rpuenc: also copy ext blocks to dovi ctx

Message ID 20240618194221.26073-3-ffmpeg@haasn.xyz
State New
Headers show
Series DoVi metadata compression | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Niklas Haas June 18, 2024, 7:35 p.m. UTC
From: Niklas Haas <git@haasn.dev>

As the comment implies, DOVIContext.ext_blocks should also reflect the
current state after ff_dovi_rpu_generate().

Fluff for now, but will be needed once we start implementing metadata
compression for extension blocks as well.
---
 libavcodec/dovi_rpuenc.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index a6262844d4..45fcd9a86c 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -506,6 +506,12 @@  int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
         }
     }
 
+    if (metadata->num_ext_blocks && !s->ext_blocks) {
+        s->ext_blocks = ff_refstruct_allocz(sizeof(AVDOVIDmData) * AV_DOVI_MAX_EXT_BLOCKS);
+        if (!s->ext_blocks)
+            return AVERROR(ENOMEM);
+    }
+
     vdr_dm_metadata_present = memcmp(color, &ff_dovi_color_default, sizeof(*color));
     use_prev_vdr_rpu = !memcmp(s->vdr[vdr_rpu_id], mapping, sizeof(*mapping));
     if (num_ext_blocks_v1 || num_ext_blocks_v2)
@@ -635,6 +641,7 @@  int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
     }
 
     if (vdr_dm_metadata_present) {
+        size_t ext_sz;
         const int denom = profile == 4 ? (1 << 30) : (1 << 28);
         set_ue_golomb(pb, color->dm_metadata_id); /* affected_dm_id */
         set_ue_golomb(pb, color->dm_metadata_id); /* current_dm_id */
@@ -672,6 +679,11 @@  int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
             for (int i = 0; i < metadata->num_ext_blocks; i++)
                 generate_ext_v2(pb, av_dovi_get_ext(metadata, i));
         }
+
+        ext_sz = FFMIN(sizeof(AVDOVIDmData), metadata->ext_block_size);
+        for (int i = 0; i < metadata->num_ext_blocks; i++)
+            memcpy(&s->ext_blocks[i], av_dovi_get_ext(metadata, i), ext_sz);
+        s->num_ext_blocks = metadata->num_ext_blocks;
     } else {
         s->color = &ff_dovi_color_default;
         s->num_ext_blocks = 0;