Skip to content

Commit

Permalink
Parse ext_mapping_idc from el_bit_depth_minus8
Browse files Browse the repository at this point in the history
And write it back properly.

Fixes #263
  • Loading branch information
quietvoid committed Jun 22, 2024
1 parent cdc64e3 commit 8fc10c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
Binary file added assets/tests/profile20_apple.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions dolby_vision/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
26 changes: 24 additions & 2 deletions dolby_vision/src/rpu/rpu_data_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down
12 changes: 12 additions & 0 deletions src/tests/rpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 8fc10c8

Please sign in to comment.