Skip to content

Commit

Permalink
Use the XML L254 metadata when generating
Browse files Browse the repository at this point in the history
  • Loading branch information
quietvoid committed Jan 7, 2022
1 parent 1d848df commit f08c702
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dolby_vision/src/rpu/extension_metadata/blocks/level254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl ExtMetadataBlockLevel254 {
Ok(())
}

pub fn cmv40_default() -> ExtMetadataBlockLevel254 {
pub fn cmv402_default() -> ExtMetadataBlockLevel254 {
ExtMetadataBlockLevel254 {
dm_mode: 0,
dm_version_index: 2,
Expand Down
11 changes: 9 additions & 2 deletions dolby_vision/src/rpu/extension_metadata/cmv40.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ impl CmV40DmData {
Ok(())
}

pub fn new_with_l254() -> Self {
pub fn new_with_l254_402() -> Self {
Self {
num_ext_blocks: 1,
ext_metadata_blocks: vec![ExtMetadataBlock::Level254(
ExtMetadataBlockLevel254::cmv40_default(),
ExtMetadataBlockLevel254::cmv402_default(),
)],
}
}

pub fn new_with_custom_l254(level254: &ExtMetadataBlockLevel254) -> Self {
Self {
num_ext_blocks: 1,
ext_metadata_blocks: vec![ExtMetadataBlock::Level254(level254.clone())],
}
}
}
6 changes: 6 additions & 0 deletions dolby_vision/src/rpu/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ pub struct GenerateConfig {
/// Defaults to 1000,0.0001
pub level6: ExtMetadataBlockLevel6,

/// In the case of XML generation, the L254 metadata can vary.
/// Not allowed to be deserialized because it's handled by the lib.
#[cfg_attr(feature = "serde_feature", serde(skip))]
pub level254: Option<ExtMetadataBlockLevel254>,

/// List of metadata blocks to use for every RPU generated.
///
/// Per-shot or per-frame metadata replaces the default
Expand Down Expand Up @@ -202,6 +207,7 @@ impl Default for GenerateConfig {
max_content_light_level: 0,
max_frame_average_light_level: 0,
},
level254: Default::default(),
shots: Default::default(),
}
}
Expand Down
11 changes: 8 additions & 3 deletions dolby_vision/src/rpu/vdr_dm_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,12 @@ impl VdrDmData {
}
CmVersion::V40 => {
vdr_dm_data.cmv29_metadata = Some(DmData::V29(CmV29DmData::default()));
vdr_dm_data.cmv40_metadata = Some(DmData::V40(CmV40DmData::new_with_l254()));

vdr_dm_data.cmv40_metadata = if let Some(level254) = &config.level254 {
Some(DmData::V40(CmV40DmData::new_with_custom_l254(level254)))
} else {
Some(DmData::V40(CmV40DmData::new_with_l254_402()))
}
}
}

Expand All @@ -462,12 +467,12 @@ impl VdrDmData {
))?;

if !config.default_metadata_blocks.is_empty() {
let level_block_list: &[u8] = &[5, 6, 254];
const LEVEL_BLOCK_LIST: &[u8] = &[5, 6, 254];

let allowed_default_blocks = config
.default_metadata_blocks
.iter()
.filter(|block| !level_block_list.contains(&block.level()));
.filter(|block| !LEVEL_BLOCK_LIST.contains(&block.level()));

for block in allowed_default_blocks {
self.replace_metadata_block(block.clone())?;
Expand Down
14 changes: 8 additions & 6 deletions dolby_vision/src/xml/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ impl CmXmlParser {
max_content_light_level,
max_frame_average_light_level,
};
parser.config.level254 = parser.parse_level254(&video);

parser.target_displays = parser.parse_target_displays(&video)?;

// TODO: Specify how?
let (dm_mode, dm_version_index) = parser.parse_level254(&video);

parser.config.shots = parser.parse_shots(&video)?;
parser.config.shots.sort_by_key(|s| s.start);

Expand Down Expand Up @@ -311,7 +309,7 @@ impl CmXmlParser {
Ok(targets)
}

fn parse_level254(&self, video: &Node) -> (u8, u8) {
fn parse_level254(&self, video: &Node) -> Option<ExtMetadataBlockLevel254> {
if let Some(node) = video.descendants().find(|e| e.has_tag_name("Level254")) {
let dm_mode = if let Some(dmm) = node.children().find(|e| e.has_tag_name("DMMode")) {
dmm.text().map_or(0, |e| e.parse::<u8>().unwrap())
Expand All @@ -326,9 +324,13 @@ impl CmXmlParser {
2
};

(dm_mode, dm_version_index)
Some(ExtMetadataBlockLevel254 {
dm_mode,
dm_version_index,
})
} else {
(0, 2)
// No L254 in the case of CM v2.9
None
}
}

Expand Down
20 changes: 20 additions & 0 deletions dolby_vision/src/xml/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ fn parse_cmv2_9() -> Result<()> {
assert_eq!(config.level6.max_content_light_level, 756);
assert_eq!(config.level6.max_frame_average_light_level, 97);

// No L254
assert!(config.level254.is_none());

let shot1 = &config.shots[0];
let shot1_blocks = &shot1.metadata_blocks;
assert_eq!(shot1.duration, 12);
Expand Down Expand Up @@ -79,6 +82,13 @@ fn parse_cmv4_0_2() -> Result<()> {
assert_eq!(config.level6.max_content_light_level, 3948);
assert_eq!(config.level6.max_frame_average_light_level, 120);

// XML L254
assert!(config.level254.is_some());

let level254 = config.level254.as_ref().unwrap();
assert_eq!(level254.dm_mode, 0);
assert_eq!(level254.dm_version_index, 2);

let shot1 = &config.shots[0];
let shot1_blocks = &shot1.metadata_blocks;
assert_eq!(shot1.duration, 120);
Expand All @@ -105,6 +115,16 @@ fn parse_cmv4_0_2() -> Result<()> {
assert_eq!(shot3.duration, 40);
assert_eq!(shot3_blocks.len(), 3);

let rpus = config.generate_rpu_list()?;
let rpu = &rpus[0];
let vdr_dm_data = rpu.vdr_dm_data.as_ref().unwrap();
let level254 = vdr_dm_data.get_block(254).unwrap();

if let ExtMetadataBlock::Level254(block) = &level254 {
assert_eq!(block.dm_mode, 0);
assert_eq!(block.dm_version_index, 2);
}

Ok(())
}

Expand Down
3 changes: 2 additions & 1 deletion src/dovi/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ impl EditConfig {

if let Some(ref mut vdr_dm_data) = rpu.vdr_dm_data {
if vdr_dm_data.cmv40_metadata.is_none() {
vdr_dm_data.cmv40_metadata = Some(DmData::V40(CmV40DmData::new_with_l254()));
vdr_dm_data.cmv40_metadata =
Some(DmData::V40(CmV40DmData::new_with_l254_402()));
}
}
}
Expand Down

0 comments on commit f08c702

Please sign in to comment.