Skip to content

Commit 639f783

Browse files
committed
Fixed a bug related to processing metadata OBU with Dolby Vision RPU
Signed-off-by: Cecilia Chen <Cecilia.chen@dolby.com>
1 parent 5ed98e0 commit 639f783

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

include/gpac/internal/media_dev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,9 @@ typedef struct
10541054
//set to one if a temporal delim is found when calling aom_av1_parse_temporal_unit_from_section5
10551055
u8 has_temporal_delim;
10561056
u8 has_frame_data;
1057+
1058+
// detected rpu data in current access unit
1059+
Bool dolby_rpu_detected;
10571060
} AV1State;
10581061

10591062
GF_Err aom_av1_parse_temporal_unit_from_section5(GF_BitStream *bs, AV1State *state);

src/media_tools/av_parsers.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2673,7 +2673,7 @@ static void av1_add_obu_internal(GF_BitStream *bs, u64 pos, u64 obu_length, ObuT
26732673

26742674
static void av1_populate_state_from_obu(GF_BitStream *bs, u64 pos, u64 obu_length, ObuType obu_type, AV1State *state)
26752675
{
2676-
if (av1_is_obu_header(obu_type)) {
2676+
if (av1_is_obu_header(obu_type) && !(obu_type == OBU_METADATA && state->dolby_rpu_detected)) {
26772677
if (obu_type == OBU_METADATA) {
26782678
u64 cur_pos = gf_bs_get_position(bs);
26792679
gf_bs_seek(bs, pos);
@@ -4376,12 +4376,43 @@ static void av1_parse_timecode_obu(GF_SEIInfo *sei, GF_BitStream *bs)
43764376
}
43774377
}
43784378

4379+
static void av1_parse_itu_t_t35_metadata(GF_BitStream *bs, AV1State *state)
4380+
{
4381+
u8 country_code;
4382+
u16 terminal_provider_code;
4383+
u32 terminal_provider_oriented_code;
4384+
4385+
country_code = gf_bs_read_int(bs, 8);
4386+
terminal_provider_code = gf_bs_read_int(bs, 16);
4387+
terminal_provider_oriented_code = gf_bs_read_int(bs, 32);
4388+
4389+
// Dolby Vision Video Elementary Stream Multiplexing Spec version 2.0 Section 3
4390+
if (country_code == 0xB5 && terminal_provider_code == 0x003B & terminal_provider_oriented_code == 0x00000800) {
4391+
const u8 dovi_emdf_hdr[] = {0x37, 0xCD, 0x08};
4392+
if (gf_bs_read_u8(bs) == dovi_emdf_hdr[0] &&
4393+
gf_bs_read_u8(bs) == dovi_emdf_hdr[1] &&
4394+
gf_bs_read_u8(bs) == dovi_emdf_hdr[2]) {
4395+
4396+
if (state->frame_state.show_frame == 1 || state->frame_state.show_existing_frame == 1) {
4397+
GF_LOG(GF_LOG_WARNING, GF_LOG_CODING, ("[AV1] Warning: Dolby Vision metadata OBU must appear before the first shown frame OBU. This content may be non-compliant with the Dolby Vision specification.\n"));
4398+
}
4399+
if (state->dolby_rpu_detected) {
4400+
GF_LOG(GF_LOG_WARNING, GF_LOG_CODING, ("[AV1] Warning: Each AV1 Temporal Unit must contain exactly one Dolby Vision metadata OBU. This content may be non-compliant with the Dolby Vision specification.\n"));
4401+
}
4402+
4403+
state->dolby_rpu_detected = GF_TRUE;
4404+
}
4405+
}
4406+
return;
4407+
}
4408+
43794409
static void av1_parse_obu_metadata(AV1State *state, GF_BitStream *bs)
43804410
{
43814411
ObuMetadataType metadata_type = (ObuMetadataType)gf_av1_leb128_read(bs, NULL);
43824412

43834413
switch (metadata_type) {
43844414
case OBU_METADATA_TYPE_ITUT_T35:
4415+
av1_parse_itu_t_t35_metadata(bs, state);
43854416
break;
43864417
case OBU_METADATA_TYPE_HDR_CLL:
43874418
gf_bs_read_data(bs, state->sei.clli_data, 4);
@@ -4528,6 +4559,23 @@ GF_Err gf_av1_parse_obu(GF_BitStream *bs, ObuType *obu_type, u64 *obu_size, u32
45284559
gf_bs_seek(bs, pos + *obu_size);
45294560
break;
45304561
}
4562+
// Dolby Vision Video Elementary Stream Multiplexing Spec version 2.0 Section 3
4563+
if (state->dolby_rpu_detected) {
4564+
switch(*obu_type) {
4565+
case OBU_TEMPORAL_DELIMITER:
4566+
state->dolby_rpu_detected = GF_FALSE;
4567+
break;
4568+
case OBU_FRAME_HEADER:
4569+
case OBU_REDUNDANT_FRAME_HEADER:
4570+
case OBU_FRAME:
4571+
if (state->frame_state.show_frame == 0 && state->frame_state.show_existing_frame == 0) {
4572+
GF_LOG(GF_LOG_WARNING, GF_LOG_CODING, ("[AV1] Warning: Dolby Vision metadata OBU must appear after all non-shown frames. This content may be non-compliant with the Dolby Vision specification.\n"));
4573+
}
4574+
break;
4575+
default:
4576+
break;
4577+
}
4578+
}
45314579
return e;
45324580
}
45334581

0 commit comments

Comments
 (0)