diff --git a/assets/tests/profile20_apple.bin b/assets/tests/profile20_apple.bin new file mode 100644 index 0000000..cd931e2 Binary files /dev/null and b/assets/tests/profile20_apple.bin differ diff --git a/dolby_vision/CHANGELOG.md b/dolby_vision/CHANGELOG.md index bd3540c..9a9ae42 100644 --- a/dolby_vision/CHANGELOG.md +++ b/dolby_vision/CHANGELOG.md @@ -1,4 +1,7 @@ ## Unreleased +- Added support for parsing `ext_mapping_idc` in `RpuDataHeader`. + - `ext_mapping_idc_0_4` represents the 5 lowest bits, and `ext_mapping_idc_5_7` the 3 remaining bits. + C API: - Added `dovi_parse_itu_t35_dovi_metadata_obu` function. diff --git a/dolby_vision/src/rpu/rpu_data_header.rs b/dolby_vision/src/rpu/rpu_data_header.rs index ea34f2e..30327a3 100644 --- a/dolby_vision/src/rpu/rpu_data_header.rs +++ b/dolby_vision/src/rpu/rpu_data_header.rs @@ -33,6 +33,13 @@ pub struct RpuDataHeader { // [8, 16] pub bl_bit_depth_minus8: u64, pub el_bit_depth_minus8: u64, + + /// Extended base layer inverse mapping indicator + pub ext_mapping_idc_0_4: u8, + /// Reserved + pub ext_mapping_idc_5_7: u8, + + // [8, 16] pub vdr_bit_depth_minus8: u64, pub spatial_resampling_filter_flag: bool, @@ -80,7 +87,17 @@ impl RpuDataHeader { if header.rpu_format & 0x700 == 0 { header.bl_bit_depth_minus8 = reader.get_ue()?; - header.el_bit_depth_minus8 = reader.get_ue()?; + + let el_bit_depth_minus8 = reader.get_ue()?; + // 8 lowest bits + header.el_bit_depth_minus8 = el_bit_depth_minus8 & 0xFF; + + // Next 8 bits + let ext_mapping_idc = (el_bit_depth_minus8 >> 8) as u8; + // Lowest 5 bits + header.ext_mapping_idc_0_4 = ext_mapping_idc & 0x1F; + header.ext_mapping_idc_5_7 = ext_mapping_idc >> 5; + header.vdr_bit_depth_minus8 = reader.get_ue()?; header.spatial_resampling_filter_flag = reader.get()?; header.reserved_zero_3bits = reader.get_n(3)?; @@ -205,7 +222,12 @@ impl RpuDataHeader { if self.rpu_format & 0x700 == 0 { writer.write_ue(&self.bl_bit_depth_minus8)?; - writer.write_ue(&self.el_bit_depth_minus8)?; + + let ext_mapping_idc = + ((self.ext_mapping_idc_5_7 << 5) | self.ext_mapping_idc_0_4) as u64; + let el_bit_depth_minus8 = (ext_mapping_idc << 8) | self.el_bit_depth_minus8; + writer.write_ue(&el_bit_depth_minus8)?; + writer.write_ue(&self.vdr_bit_depth_minus8)?; writer.write(self.spatial_resampling_filter_flag)?; writer.write_n(&self.reserved_zero_3bits, 3)?; diff --git a/src/tests/rpu.rs b/src/tests/rpu.rs index 80dd4a9..5157572 100644 --- a/src/tests/rpu.rs +++ b/src/tests/rpu.rs @@ -1122,3 +1122,15 @@ fn source_p5_to_p8_001_end_crc32() -> Result<()> { Ok(()) } + +#[test] +fn profile20_apple() -> Result<()> { + let (original_data, dovi_rpu) = + _parse_file(PathBuf::from("./assets/tests/profile20_apple.bin"))?; + assert_eq!(dovi_rpu.dovi_profile, 5); + let parsed_data = dovi_rpu.write_hevc_unspec62_nalu()?; + + assert_eq!(&original_data[4..], &parsed_data[2..]); + + Ok(()) +}