Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dolby_vision/src/rpu/dovi_rpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct DoviRpu {
impl DoviRpu {
pub fn validated_trimmed_data(data: &[u8]) -> Result<&[u8]> {
if data.len() < 25 {
bail!("Invalid RPU length: {}", &data.len());
bail!("Invalid RPU length: {}", data.len());
}

// Including 0x7C01 prepended
Expand Down
2 changes: 1 addition & 1 deletion dolby_vision/src/rpu/extension_metadata/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl ExtMetadataBlock {
ensure!(
T::ALLOWED_BLOCK_LEVELS.contains(&level),
"Metadata block level {} is not allowed",
&level
level
);

Ok(())
Expand Down
27 changes: 23 additions & 4 deletions src/dovi/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ pub struct EditConfig {
#[serde(deny_unknown_fields)]
pub struct ActiveArea {
#[serde(default)]
crop: bool,
pub crop: bool,

#[serde(skip_serializing_if = "Option::is_none")]
drop_l5: Option<String>,
pub drop_l5: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
presets: Option<Vec<ActiveAreaOffsets>>,
pub presets: Option<Vec<ActiveAreaOffsets>>,

#[serde(skip_serializing_if = "Option::is_none")]
edits: Option<HashMap<String, u16>>,
pub edits: Option<HashMap<String, u16>>,
}

#[derive(Serialize, Deserialize, Default, Debug, Clone)]
Expand Down Expand Up @@ -192,6 +192,13 @@ impl EditConfig {
Ok(config)
}

pub fn from_active_area(active_area: ActiveArea) -> Self {
Self {
active_area: Some(active_area),
..Default::default()
}
}

fn execute(&self, rpus: &mut [Option<DoviRpu>]) -> Result<()> {
// Drop metadata frames
if let Some(ranges) = &self.remove {
Expand Down Expand Up @@ -521,6 +528,18 @@ impl EditConfig {
}
}

impl ActiveAreaOffsets {
pub fn new(id: u16, meta: &ExtMetadataBlockLevel5) -> Self {
Self {
id,
left: meta.active_area_left_offset,
right: meta.active_area_right_offset,
top: meta.active_area_top_offset,
bottom: meta.active_area_bottom_offset,
}
}
}

impl ActiveArea {
fn execute(&self, rpus: &mut [Option<DoviRpu>]) -> Result<()> {
if let Some(edits) = &self.edits
Expand Down
40 changes: 19 additions & 21 deletions src/dovi/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use serde_json::json;
use dolby_vision::rpu::utils::parse_rpu_file;

use crate::commands::{ExportArgs, ExportData, ExportLevel, LevelsOutputFormat};
use crate::dovi::input_from_either;
use crate::dovi::{
editor::{ActiveArea, ActiveAreaOffsets, EditConfig},
input_from_either,
};

use super::DoviRpu;

Expand Down Expand Up @@ -190,28 +193,23 @@ impl Exporter {
let l5_presets = l5_presets
.iter()
.enumerate()
.map(|(id, l5)| {
json!({
"id": id,
"left": l5.active_area_left_offset,
"right": l5.active_area_right_offset,
"top": l5.active_area_top_offset,
"bottom": l5.active_area_bottom_offset
})
})
.map(|(id, l5)| ActiveAreaOffsets::new(id as u16, l5))
.collect::<Vec<_>>();
let l5_edits = l5_edits.iter().map(|(edit_range, id)| {
(
format!("{}-{}", edit_range.start, edit_range.end),
json!(id),
)
});
let l5_edits = serde_json::Value::Object(l5_edits.collect());
let l5_edits = l5_edits
.into_iter()
.map(|(edit_range, id)| {
(
format!("{}-{}", edit_range.start, edit_range.end),
id as u16,
)
})
.collect();

let edit_config = json!({
"crop": true,
"presets": l5_presets,
"edits": l5_edits,
let edit_config = EditConfig::from_active_area(ActiveArea {
crop: true,
presets: Some(l5_presets),
edits: Some(l5_edits),
..Default::default()
});
serde_json::to_writer_pretty(writer, &edit_config)?;

Expand Down
2 changes: 1 addition & 1 deletion src/dovi/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Generator {
self.config = Some(config);

if let Some(config) = self.config.as_mut() {
println!("Generating metadata: {}...", &config.profile);
println!("Generating metadata: {}...", config.profile);

// Correct L1 for sources other than XML
if self.xml_path.is_none() {
Expand Down