[FFmpeg-devel] [PATCH 6/8] avcodec/dovi_rpu: guard ext blocks by dm_metadata_present
Niklas Haas
ffmpeg at haasn.xyz
Sun Jun 9 18:05:51 EEST 2024
From: Niklas Haas <git at haasn.dev>
In the spec, dm_metadata_present also toggles all extension blocks, so
we need to move them inside the branch.
---
libavcodec/dovi_rpudec.c | 25 +++++++++++++------------
libavcodec/dovi_rpuenc.c | 21 ++++++++++++---------
2 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c
index 51f824d126..064d74575f 100644
--- a/libavcodec/dovi_rpudec.c
+++ b/libavcodec/dovi_rpudec.c
@@ -613,22 +613,23 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
color->source_min_pq = get_bits(gb, 12);
color->source_max_pq = get_bits(gb, 12);
color->source_diagonal = get_bits(gb, 10);
- } else {
- s->color = &ff_dovi_color_default;
- }
-
- /* Parse extension blocks */
- s->num_ext_blocks = 0;
- if ((ret = parse_ext_blocks(s, gb, 1)) < 0) {
- ff_dovi_ctx_unref(s);
- return ret;
- }
- if (get_bits_left(gb) > 48 /* padding + CRC32 + terminator */) {
- if ((ret = parse_ext_blocks(s, gb, 2)) < 0) {
+ /* Parse extension blocks */
+ s->num_ext_blocks = 0;
+ if ((ret = parse_ext_blocks(s, gb, 1)) < 0) {
ff_dovi_ctx_unref(s);
return ret;
}
+
+ if (get_bits_left(gb) > 48 /* padding + CRC32 + terminator */) {
+ if ((ret = parse_ext_blocks(s, gb, 2)) < 0) {
+ ff_dovi_ctx_unref(s);
+ return ret;
+ }
+ }
+ } else {
+ s->color = &ff_dovi_color_default;
+ s->num_ext_blocks = 0;
}
return 0;
diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c
index 8fceefe2c1..f7d11c9042 100644
--- a/libavcodec/dovi_rpuenc.c
+++ b/libavcodec/dovi_rpuenc.c
@@ -508,6 +508,8 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
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)
+ vdr_dm_metadata_present = 1;
if (vdr_dm_metadata_present && !s->dm) {
s->dm = ff_refstruct_allocz(sizeof(AVDOVIColorMetadata));
@@ -657,18 +659,19 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
memcpy(s->dm, color, sizeof(*color));
s->color = s->dm;
- }
-
- set_ue_golomb(pb, num_ext_blocks_v1);
- align_put_bits(pb);
- for (int i = 0; i < metadata->num_ext_blocks; i++)
- generate_ext_v1(pb, av_dovi_get_ext(metadata, i));
- if (num_ext_blocks_v2) {
- set_ue_golomb(pb, num_ext_blocks_v2);
+ /* Extension blocks */
+ set_ue_golomb(pb, num_ext_blocks_v1);
align_put_bits(pb);
for (int i = 0; i < metadata->num_ext_blocks; i++)
- generate_ext_v2(pb, av_dovi_get_ext(metadata, i));
+ generate_ext_v1(pb, av_dovi_get_ext(metadata, i));
+
+ if (num_ext_blocks_v2) {
+ set_ue_golomb(pb, num_ext_blocks_v2);
+ align_put_bits(pb);
+ for (int i = 0; i < metadata->num_ext_blocks; i++)
+ generate_ext_v2(pb, av_dovi_get_ext(metadata, i));
+ }
}
flush_put_bits(pb);
--
2.45.1
More information about the ffmpeg-devel
mailing list