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 24, 2024
1 parent 2a74330 commit 761d505
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
34 changes: 34 additions & 0 deletions symphonia-common/src/mpeg/video/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,37 @@ impl HEVCDecoderConfigurationRecord {
})
}
}

#[derive(Debug, Default)]
pub struct DOVIDecoderConfigurationRecord {
pub dv_version_major: u8,
pub dv_version_minor: u8,
pub dv_profile: u8,
pub dv_level: u8,
pub rpu_present_flag: bool,
pub el_present_flag: bool,
pub bl_present_flag: bool,
pub dv_bl_signal_compatibility_id: u8,
}

impl DOVIDecoderConfigurationRecord {
pub fn read(buf: &[u8]) -> Result<Self> {
let mut br = BitReaderLtr::new(buf);

// Parse the 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

let config = DOVIDecoderConfigurationRecord {
dv_version_major: br.read_bits_leq32(8)? as u8,
dv_version_minor: br.read_bits_leq32(8)? as u8,
dv_profile: br.read_bits_leq32(7)? as u8,
dv_level: br.read_bits_leq32(6)? as u8,
rpu_present_flag: br.read_bit()? != 0,
el_present_flag: br.read_bit()? != 0,
bl_present_flag: br.read_bit()? != 0,
dv_bl_signal_compatibility_id: br.read_bits_leq32(4)? as u8,
};

Ok(config)
}
}
43 changes: 43 additions & 0 deletions symphonia-format-isomp4/src/atoms/dovi.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 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)
let len = header
.data_len()
.ok_or_else(|| Error::DecodeError("isomp4 (dovi): 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 as usize)?,
};

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());
}
}
4 changes: 4 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 @@ -141,6 +142,7 @@ pub enum AtomType {
DateTag,
DescriptionTag,
DiskNumberTag,
DolbyVisionConfiguration,
Eac3Config,
Edit,
EditList,
Expand Down Expand Up @@ -250,8 +252,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
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 @@ -35,6 +35,7 @@ use crate::atoms::{
};
use crate::fp::FpU16;

use super::dovi::DoviAtom;
use super::{AtomIterator, AvcCAtom, HvcCAtom};

/// Sample description atom.
Expand Down Expand Up @@ -552,6 +553,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 761d505

Please sign in to comment.