Skip to content

Commit

Permalink
isomp4: parse Dolby Vision configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
sscobici committed Nov 2, 2024
1 parent 9c87c1f commit 168dbde
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
49 changes: 49 additions & 0 deletions symphonia-format-isomp4/src/atoms/dovi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Symphonia
// Copyright (c) 2019-2022 The Project Symphonia Developers.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use symphonia_core::codecs::video::well_known::extra_data::VIDEO_EXTRA_DATA_ID_DOLBY_VISION_CONFIG;
use symphonia_core::codecs::video::VideoExtraData;
use symphonia_core::errors::{decode_error, Result};
use symphonia_core::io::ReadBytes;

use crate::atoms::stsd::VisualSampleEntry;
use crate::atoms::{Atom, AtomHeader};

const DOVI_CONFIG_SIZE: u64 = 24;

#[allow(dead_code)]
#[derive(Debug)]
pub struct DoviAtom {
extra_data: VideoExtraData,
}

impl Atom for DoviAtom {
fn read<B: ReadBytes>(reader: &mut B, header: AtomHeader) -> Result<Self> {
// The Dolby Vision Configuration atom payload (dvvC and dvcC).
// Contains DOVIDecoderConfigurationRecord, point 3.2 from
// https://professional.dolby.com/siteassets/content-creation/dolby-vision-for-content-creators/dolby_vision_bitstreams_within_the_iso_base_media_file_format_dec2017.pdf
// It should be 24 bytes
let len = match header.data_len() {
Some(len @ DOVI_CONFIG_SIZE) => len as usize,
Some(_) => return decode_error("isomp4 (dvcC/dvvC): atom size is not 24 bytes"),
None => return decode_error("isomp4 (dvcC/dvvC): expected atom size to be known"),
};

let dovi_data = VideoExtraData {
id: VIDEO_EXTRA_DATA_ID_DOLBY_VISION_CONFIG,
data: reader.read_boxed_slice_exact(len)?,
};

Ok(Self { extra_data: dovi_data })
}
}

impl DoviAtom {
pub fn fill_video_sample_entry(&self, entry: &mut VisualSampleEntry) {
entry.extra_data.push(self.extra_data.clone());
}
}
5 changes: 5 additions & 0 deletions symphonia-format-isomp4/src/atoms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) mod co64;
pub(crate) mod ctts;
pub(crate) mod dac3;
pub(crate) mod dec3;
pub(crate) mod dovi;
pub(crate) mod edts;
pub(crate) mod elst;
pub(crate) mod esds;
Expand Down Expand Up @@ -61,6 +62,7 @@ pub use co64::Co64Atom;
pub use ctts::CttsAtom;
pub use dac3::Dac3Atom;
pub use dec3::Dec3Atom;
pub use dovi::DoviAtom;
pub use edts::EdtsAtom;
pub use elst::ElstAtom;
pub use esds::EsdsAtom;
Expand Down Expand Up @@ -141,6 +143,7 @@ pub enum AtomType {
DateTag,
DescriptionTag,
DiskNumberTag,
DolbyVisionConfiguration,
Eac3Config,
Edit,
EditList,
Expand Down Expand Up @@ -250,8 +253,10 @@ impl From<[u8; 4]> for AtomType {
b"data" => AtomType::MetaTagData,
b"dfLa" => AtomType::FlacDsConfig,
b"dOps" => AtomType::OpusDsConfig,
b"dvcC" => AtomType::DolbyVisionConfiguration,
b"dvh1" => AtomType::VisualSampleEntryDvh1,
b"dvhe" => AtomType::VisualSampleEntryDvhe,
b"dvvC" => AtomType::DolbyVisionConfiguration,
b"edts" => AtomType::Edit,
b"elst" => AtomType::EditList,
b"esds" => AtomType::Esds,
Expand Down
8 changes: 6 additions & 2 deletions symphonia-format-isomp4/src/atoms/stsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use symphonia_core::errors::{decode_error, unsupported_error, Result};
use symphonia_core::io::ReadBytes;

use crate::atoms::{
AlacAtom, Atom, AtomHeader, AtomIterator, AtomType, AvcCAtom, Dac3Atom, Dec3Atom, EsdsAtom,
FlacAtom, HvcCAtom, OpusAtom, WaveAtom,
AlacAtom, Atom, AtomHeader, AtomIterator, AtomType, AvcCAtom, Dac3Atom, Dec3Atom, DoviAtom,
EsdsAtom, FlacAtom, HvcCAtom, OpusAtom, WaveAtom,
};
use crate::fp::FpU16;

Expand Down Expand Up @@ -550,6 +550,10 @@ fn read_visual_sample_entry<B: ReadBytes>(
let atom = iter.read_atom::<HvcCAtom>()?;
atom.fill_video_sample_entry(&mut entry);
}
AtomType::DolbyVisionConfiguration => {
let atom = iter.read_atom::<DoviAtom>()?;
atom.fill_video_sample_entry(&mut entry);
}
_ => {
debug!("unknown visual sample entry sub-atom: {:?}.", entry_header.atom_type());
}
Expand Down

0 comments on commit 168dbde

Please sign in to comment.