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 Oct 20, 2024
1 parent 58b5718 commit f3d413b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
43 changes: 43 additions & 0 deletions symphonia-format-isomp4/src/atoms/dvvc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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::{Error, Result};
use symphonia_core::io::ReadBytes;

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

use super::stsd::VisualSampleEntry;

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

impl Atom for DvvCAtom {
fn read<B: ReadBytes>(reader: &mut B, header: AtomHeader) -> Result<Self> {
// The Dolby Vision Configuration atom payload
let len = header
.data_len()
.ok_or_else(|| Error::DecodeError("isomp4 (dvvC): expected atom size to be known"))?;

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

Ok(Self { extra_data: dv_data })
}
}

impl DvvCAtom {
pub fn fill_video_sample_entry(&self, entry: &mut VisualSampleEntry) {
entry.extra_data.push(self.extra_data.clone());
}
}
3 changes: 3 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 dvvc;
pub(crate) mod edts;
pub(crate) mod elst;
pub(crate) mod esds;
Expand Down Expand Up @@ -141,6 +142,7 @@ pub enum AtomType {
DateTag,
DescriptionTag,
DiskNumberTag,
DolbyVisionConfiguration,
Eac3Config,
Edit,
EditList,
Expand Down Expand Up @@ -252,6 +254,7 @@ impl From<[u8; 4]> for AtomType {
b"dOps" => AtomType::OpusDsConfig,
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
5 changes: 5 additions & 0 deletions symphonia-format-isomp4/src/atoms/stsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::atoms::{
};
use crate::fp::FpU16;

use super::dvvc::DvvCAtom;
use super::{AtomIterator, AvcCAtom, HvcCAtom};

/// Sample description atom.
Expand Down Expand Up @@ -660,6 +661,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::<DvvCAtom>()?;
atom.fill_video_sample_entry(&mut entry);
}
_ => {
debug!("unknown visual sample entry sub-atom: {:?}.", entry_header.atom_type());
}
Expand Down

0 comments on commit f3d413b

Please sign in to comment.