diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c index b26c19dd5e..91134e031d 100644 --- a/libavcodec/dovi_rpu.c +++ b/libavcodec/dovi_rpu.c @@ -86,3 +86,46 @@ int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr) return 0; /* unknown */ } + +const AVDOVIColorMetadata ff_dovi_color_default = { + .dm_metadata_id = 0, + .scene_refresh_flag = 0, + .ycc_to_rgb_matrix = { + { 9575, 8192 }, + { 0, 8192 }, + { 14742, 8192 }, + { 9575, 8192 }, + { 1754, 8192 }, + { 4383, 8192 }, + { 9575, 8192 }, + { 17372, 8192 }, + { 0, 8192 }, + }, + .ycc_to_rgb_offset = { + { 1, 4 }, + { 2, 1 }, + { 2, 1 }, + }, + .rgb_to_lms_matrix = { + { 5845, 16384 }, + { 9702, 16384 }, + { 837, 16384 }, + { 2568, 16384 }, + { 12256, 16384 }, + { 1561, 16384 }, + { 0, 16384 }, + { 679, 16384 }, + { 15705, 16384 }, + }, + .signal_eotf = 39322, + .signal_eotf_param0 = 15867, + .signal_eotf_param1 = 228, + .signal_eotf_param2 = 1383604, + .signal_bit_depth = 14, + .signal_color_space = 0, + .signal_chroma_format = 0, + .signal_full_range_flag = 1, + .source_min_pq = 62, + .source_max_pq = 3696, + .source_diagonal = 42, +}; diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h index 8ce0c88e9d..c784afbe4b 100644 --- a/libavcodec/dovi_rpu.h +++ b/libavcodec/dovi_rpu.h @@ -157,4 +157,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, */ int ff_dovi_guess_profile_hevc(const AVDOVIRpuDataHeader *hdr); +/* Default values for AVDOVIColorMetadata */ +extern const AVDOVIColorMetadata ff_dovi_color_default; + #endif /* AVCODEC_DOVI_RPU_H */ diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c index 109cef5742..c577b521fb 100644 --- a/libavcodec/dovi_rpudec.c +++ b/libavcodec/dovi_rpudec.c @@ -628,6 +628,8 @@ 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 */ diff --git a/libavcodec/dovi_rpuenc.c b/libavcodec/dovi_rpuenc.c index dacb8b54e7..5d4945c345 100644 --- a/libavcodec/dovi_rpuenc.c +++ b/libavcodec/dovi_rpuenc.c @@ -441,7 +441,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, const AVDOVIRpuDataHeader *hdr; const AVDOVIDataMapping *mapping; const AVDOVIColorMetadata *color; - int vdr_dm_metadata_changed, vdr_rpu_id, use_prev_vdr_rpu, profile, + int vdr_dm_metadata_present, vdr_rpu_id, use_prev_vdr_rpu, profile, buffer_size, rpu_size, pad, zero_run; int num_ext_blocks_v1, num_ext_blocks_v2; uint32_t crc; @@ -512,7 +512,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, } } - vdr_dm_metadata_changed = !s->color || memcmp(s->color, color, sizeof(*color)); + vdr_dm_metadata_present = memcmp(color, &ff_dovi_color_default, sizeof(*color)); use_prev_vdr_rpu = !memcmp(&s->vdr[vdr_rpu_id]->mapping, mapping, sizeof(*mapping)); buffer_size = 12 /* vdr seq info */ + 5 /* CRC32 + terminator */; @@ -529,7 +529,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, } } } - if (vdr_dm_metadata_changed) + if (vdr_dm_metadata_present) buffer_size += 67; av_fast_padded_malloc(&s->rpu_buf, &s->rpu_buf_sz, buffer_size); @@ -560,7 +560,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, } s->header = *hdr; - put_bits(pb, 1, vdr_dm_metadata_changed); + put_bits(pb, 1, vdr_dm_metadata_present); put_bits(pb, 1, use_prev_vdr_rpu); set_ue_golomb(pb, vdr_rpu_id); s->mapping = &s->vdr[vdr_rpu_id]->mapping; @@ -632,7 +632,7 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, memcpy(&s->vdr[vdr_rpu_id]->mapping, mapping, sizeof(*mapping)); } - if (vdr_dm_metadata_changed) { + if (vdr_dm_metadata_present) { 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 */ @@ -657,6 +657,8 @@ int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, memcpy(&s->vdr[color->dm_metadata_id]->color, color, sizeof(*color)); s->color = &s->vdr[color->dm_metadata_id]->color; + } else { + s->color = &ff_dovi_color_default; } set_ue_golomb(pb, num_ext_blocks_v1);