Skip to content

Commit

Permalink
isomp4: use AudioSampleEntry to carry codec_specific information in a…
Browse files Browse the repository at this point in the history
… generic way
  • Loading branch information
sscobici committed Oct 22, 2024
1 parent 34151ca commit b5a3ae9
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 218 deletions.
8 changes: 5 additions & 3 deletions symphonia-format-isomp4/src/atoms/alac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use symphonia_core::codecs::audio::well_known::CODEC_ID_ALAC;
use symphonia_core::codecs::audio::AudioCodecParameters;
use symphonia_core::errors::{decode_error, unsupported_error, Result};
use symphonia_core::io::ReadBytes;

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

use super::stsd::AudioSampleEntry;

#[allow(dead_code)]
#[derive(Debug)]
pub struct AlacAtom {
Expand Down Expand Up @@ -46,7 +47,8 @@ impl Atom for AlacAtom {
}

impl AlacAtom {
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
codec_params.for_codec(CODEC_ID_ALAC).with_extra_data(self.extra_data.clone());
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
entry.codec_id = CODEC_ID_ALAC;
entry.extra_data = Some(self.extra_data.clone());
}
}
8 changes: 5 additions & 3 deletions symphonia-format-isomp4/src/atoms/dac3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use symphonia_core::codecs::audio::well_known::CODEC_ID_AC3;
use symphonia_core::codecs::audio::AudioCodecParameters;
use symphonia_core::errors::{Error, Result};
use symphonia_core::io::ReadBytes;

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

use super::stsd::AudioSampleEntry;

#[allow(dead_code)]
#[derive(Debug)]
pub struct Dac3Atom {
Expand All @@ -33,7 +34,8 @@ impl Atom for Dac3Atom {
}

impl Dac3Atom {
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
codec_params.for_codec(CODEC_ID_AC3).with_extra_data(self.extra_data.clone());
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
entry.codec_id = CODEC_ID_AC3;
entry.extra_data = Some(self.extra_data.clone());
}
}
8 changes: 5 additions & 3 deletions symphonia-format-isomp4/src/atoms/dec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use symphonia_core::codecs::audio::well_known::CODEC_ID_EAC3;
use symphonia_core::codecs::audio::AudioCodecParameters;
use symphonia_core::errors::{Error, Result};
use symphonia_core::io::ReadBytes;

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

use super::stsd::AudioSampleEntry;

#[allow(dead_code)]
#[derive(Debug)]
pub struct Dec3Atom {
Expand All @@ -33,7 +34,8 @@ impl Atom for Dec3Atom {
}

impl Dec3Atom {
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
codec_params.for_codec(CODEC_ID_EAC3).with_extra_data(self.extra_data.clone());
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
entry.codec_id = CODEC_ID_EAC3;
entry.extra_data = Some(self.extra_data.clone());
}
}
25 changes: 7 additions & 18 deletions symphonia-format-isomp4/src/atoms/esds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// 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::audio::AudioCodecParameters;
use symphonia_core::codecs::video::{VideoExtraData, VIDEO_EXTRA_DATA_ID_NULL};
use symphonia_core::codecs::CodecId;
use symphonia_core::errors::{decode_error, unsupported_error, Error, Result};
Expand All @@ -15,7 +14,7 @@ use crate::atoms::{Atom, AtomHeader};

use log::{debug, warn};

use super::stsd::VisualSampleEntry;
use super::stsd::{AudioSampleEntry, VisualSampleEntry};

const ES_DESCRIPTOR: u8 = 0x03;
const DECODER_CONFIG_DESCRIPTOR: u8 = 0x04;
Expand Down Expand Up @@ -84,27 +83,22 @@ impl Atom for EsdsAtom {

impl EsdsAtom {
/// If the elementary stream descriptor describes an audio stream, populate the provided
/// audio codec parameters.
pub fn fill_audio_codec_params(&self, codec_params: &mut AudioCodecParameters) -> Result<()> {
use symphonia_core::codecs::audio::CODEC_ID_NULL_AUDIO;

/// audio sample entry.
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) -> Result<()> {
match get_codec_id_from_object_type(self.descriptor.dec_config.object_type_indication) {
Some(CodecId::Audio(id)) => {
// Object type indication identified an audio codec.
codec_params.for_codec(id);
entry.codec_id = id;
}
Some(_) => {
// Object type indication identified a non-audio codec. This is unexpected.
return decode_error("isomp4 (esds): expected an audio codec type");
}
None => {
// Unknown object type indication.
codec_params.for_codec(CODEC_ID_NULL_AUDIO);
}
None => {}
}

if let Some(ds_config) = &self.descriptor.dec_config.dec_specific_info {
codec_params.with_extra_data(ds_config.extra_data.clone());
entry.extra_data = Some(ds_config.extra_data.clone());
}

Ok(())
Expand All @@ -113,8 +107,6 @@ impl EsdsAtom {
/// If the elementary stream descriptor describes an video stream, populate the provided
/// video sample entry.
pub fn fill_video_sample_entry(&self, entry: &mut VisualSampleEntry) -> Result<()> {
use symphonia_core::codecs::video::CODEC_ID_NULL_VIDEO;

match get_codec_id_from_object_type(self.descriptor.dec_config.object_type_indication) {
Some(CodecId::Video(id)) => {
// Object type indication identified an video codec.
Expand All @@ -124,10 +116,7 @@ impl EsdsAtom {
// Object type indication identified a non-video codec. This is unexpected.
return decode_error("isomp4 (esds): expected a video codec type");
}
None => {
// Unknown object type indication.
entry.codec_id = CODEC_ID_NULL_VIDEO;
}
None => {}
}

if let Some(ds_config) = &self.descriptor.dec_config.dec_specific_info {
Expand Down
19 changes: 10 additions & 9 deletions symphonia-format-isomp4/src/atoms/flac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use symphonia_core::codecs::audio::well_known::CODEC_ID_FLAC;
use symphonia_core::codecs::audio::{AudioCodecParameters, VerificationCheck};
use symphonia_core::codecs::audio::VerificationCheck;
use symphonia_core::errors::{decode_error, unsupported_error, Result};
use symphonia_core::io::{BufReader, ReadBytes};

Expand All @@ -16,6 +16,8 @@ use symphonia_common::xiph::audio::flac::metadata::{

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

use super::stsd::AudioSampleEntry;

/// FLAC atom.
#[allow(dead_code)]
#[derive(Debug)]
Expand Down Expand Up @@ -59,16 +61,15 @@ impl Atom for FlacAtom {
}

impl FlacAtom {
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
codec_params
.for_codec(CODEC_ID_FLAC)
.with_sample_rate(self.stream_info.sample_rate)
.with_bits_per_sample(self.stream_info.bits_per_sample)
.with_channels(self.stream_info.channels.clone())
.with_extra_data(self.extra_data.clone());
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
entry.codec_id = CODEC_ID_FLAC;
entry.sample_rate = self.stream_info.sample_rate;
entry.bits_per_sample = Some(self.stream_info.bits_per_sample);
entry.channels = Some(self.stream_info.channels.clone());
entry.extra_data = Some(self.extra_data.clone());

if let Some(md5) = self.stream_info.md5 {
codec_params.with_verification_code(VerificationCheck::Md5(md5));
entry.verification_check = Some(VerificationCheck::Md5(md5));
}
}
}
9 changes: 6 additions & 3 deletions symphonia-format-isomp4/src/atoms/opus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
// 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::audio::{well_known::CODEC_ID_OPUS, AudioCodecParameters};
use symphonia_core::codecs::audio::well_known::CODEC_ID_OPUS;
use symphonia_core::errors::{decode_error, unsupported_error, Error, Result};
use symphonia_core::io::ReadBytes;

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

use super::stsd::AudioSampleEntry;

/// Opus atom.
#[allow(dead_code)]
#[derive(Debug)]
Expand Down Expand Up @@ -64,7 +66,8 @@ impl Atom for OpusAtom {
}

impl OpusAtom {
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
codec_params.for_codec(CODEC_ID_OPUS).with_extra_data(self.extra_data.clone());
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
entry.codec_id = CODEC_ID_OPUS;
entry.extra_data = Some(self.extra_data.clone());
}
}
Loading

0 comments on commit b5a3ae9

Please sign in to comment.