avcodec/dovi_rpu: guard ext blocks by dm_metadata_present

In the spec, dm_metadata_present also toggles all extension blocks, so
we need to move them inside the branch.
This commit is contained in:
Niklas Haas 2024-06-09 16:45:56 +02:00
parent 5e778cbfd5
commit d9f902d3a4
2 changed files with 28 additions and 23 deletions

View File

@ -625,22 +625,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;

View File

@ -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,20 +659,22 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata,
memcpy(s->dm, color, sizeof(*color));
s->color = s->dm;
} else {
s->color = &ff_dovi_color_default;
}
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));
}
} else {
s->color = &ff_dovi_color_default;
s->num_ext_blocks = 0;
}
flush_put_bits(pb);