Skip to content

Commit 1a10e58

Browse files
committed
isomp4: use AudioSampleEntry to carry codec_specific information in a generic way
1 parent 664c71a commit 1a10e58

File tree

8 files changed

+114
-218
lines changed

8 files changed

+114
-218
lines changed

Diff for: symphonia-format-isomp4/src/atoms/alac.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

88
use symphonia_core::codecs::audio::well_known::CODEC_ID_ALAC;
9-
use symphonia_core::codecs::audio::AudioCodecParameters;
109
use symphonia_core::errors::{decode_error, unsupported_error, Result};
1110
use symphonia_core::io::ReadBytes;
1211

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

14+
use super::stsd::AudioSampleEntry;
15+
1516
#[allow(dead_code)]
1617
#[derive(Debug)]
1718
pub struct AlacAtom {
@@ -46,7 +47,8 @@ impl Atom for AlacAtom {
4647
}
4748

4849
impl AlacAtom {
49-
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
50-
codec_params.for_codec(CODEC_ID_ALAC).with_extra_data(self.extra_data.clone());
50+
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
51+
entry.codec_id = CODEC_ID_ALAC;
52+
entry.extra_data = Some(self.extra_data.clone());
5153
}
5254
}

Diff for: symphonia-format-isomp4/src/atoms/dac3.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

88
use symphonia_core::codecs::audio::well_known::CODEC_ID_AC3;
9-
use symphonia_core::codecs::audio::AudioCodecParameters;
109
use symphonia_core::errors::{Error, Result};
1110
use symphonia_core::io::ReadBytes;
1211

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

14+
use super::stsd::AudioSampleEntry;
15+
1516
#[allow(dead_code)]
1617
#[derive(Debug)]
1718
pub struct Dac3Atom {
@@ -33,7 +34,8 @@ impl Atom for Dac3Atom {
3334
}
3435

3536
impl Dac3Atom {
36-
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
37-
codec_params.for_codec(CODEC_ID_AC3).with_extra_data(self.extra_data.clone());
37+
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
38+
entry.codec_id = CODEC_ID_AC3;
39+
entry.extra_data = Some(self.extra_data.clone());
3840
}
3941
}

Diff for: symphonia-format-isomp4/src/atoms/dec3.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

88
use symphonia_core::codecs::audio::well_known::CODEC_ID_EAC3;
9-
use symphonia_core::codecs::audio::AudioCodecParameters;
109
use symphonia_core::errors::{Error, Result};
1110
use symphonia_core::io::ReadBytes;
1211

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

14+
use super::stsd::AudioSampleEntry;
15+
1516
#[allow(dead_code)]
1617
#[derive(Debug)]
1718
pub struct Dec3Atom {
@@ -33,7 +34,8 @@ impl Atom for Dec3Atom {
3334
}
3435

3536
impl Dec3Atom {
36-
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
37-
codec_params.for_codec(CODEC_ID_EAC3).with_extra_data(self.extra_data.clone());
37+
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
38+
entry.codec_id = CODEC_ID_EAC3;
39+
entry.extra_data = Some(self.extra_data.clone());
3840
}
3941
}

Diff for: symphonia-format-isomp4/src/atoms/esds.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// License, v. 2.0. If a copy of the MPL was not distributed with this
66
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

8-
use symphonia_core::codecs::audio::AudioCodecParameters;
98
use symphonia_core::codecs::video::{VideoExtraData, VIDEO_EXTRA_DATA_ID_NULL};
109
use symphonia_core::codecs::CodecId;
1110
use symphonia_core::errors::{decode_error, unsupported_error, Error, Result};
@@ -15,7 +14,7 @@ use crate::atoms::{Atom, AtomHeader};
1514

1615
use log::{debug, warn};
1716

18-
use super::stsd::VisualSampleEntry;
17+
use super::stsd::{AudioSampleEntry, VisualSampleEntry};
1918

2019
const ES_DESCRIPTOR: u8 = 0x03;
2120
const DECODER_CONFIG_DESCRIPTOR: u8 = 0x04;
@@ -84,27 +83,22 @@ impl Atom for EsdsAtom {
8483

8584
impl EsdsAtom {
8685
/// If the elementary stream descriptor describes an audio stream, populate the provided
87-
/// audio codec parameters.
88-
pub fn fill_audio_codec_params(&self, codec_params: &mut AudioCodecParameters) -> Result<()> {
89-
use symphonia_core::codecs::audio::CODEC_ID_NULL_AUDIO;
90-
86+
/// audio sample entry.
87+
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) -> Result<()> {
9188
match get_codec_id_from_object_type(self.descriptor.dec_config.object_type_indication) {
9289
Some(CodecId::Audio(id)) => {
9390
// Object type indication identified an audio codec.
94-
codec_params.for_codec(id);
91+
entry.codec_id = id;
9592
}
9693
Some(_) => {
9794
// Object type indication identified a non-audio codec. This is unexpected.
9895
return decode_error("isomp4 (esds): expected an audio codec type");
9996
}
100-
None => {
101-
// Unknown object type indication.
102-
codec_params.for_codec(CODEC_ID_NULL_AUDIO);
103-
}
97+
None => {}
10498
}
10599

106100
if let Some(ds_config) = &self.descriptor.dec_config.dec_specific_info {
107-
codec_params.with_extra_data(ds_config.extra_data.clone());
101+
entry.extra_data = Some(ds_config.extra_data.clone());
108102
}
109103

110104
Ok(())
@@ -113,8 +107,6 @@ impl EsdsAtom {
113107
/// If the elementary stream descriptor describes an video stream, populate the provided
114108
/// video sample entry.
115109
pub fn fill_video_sample_entry(&self, entry: &mut VisualSampleEntry) -> Result<()> {
116-
use symphonia_core::codecs::video::CODEC_ID_NULL_VIDEO;
117-
118110
match get_codec_id_from_object_type(self.descriptor.dec_config.object_type_indication) {
119111
Some(CodecId::Video(id)) => {
120112
// Object type indication identified an video codec.
@@ -124,10 +116,7 @@ impl EsdsAtom {
124116
// Object type indication identified a non-video codec. This is unexpected.
125117
return decode_error("isomp4 (esds): expected a video codec type");
126118
}
127-
None => {
128-
// Unknown object type indication.
129-
entry.codec_id = CODEC_ID_NULL_VIDEO;
130-
}
119+
None => {}
131120
}
132121

133122
if let Some(ds_config) = &self.descriptor.dec_config.dec_specific_info {

Diff for: symphonia-format-isomp4/src/atoms/flac.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

88
use symphonia_core::codecs::audio::well_known::CODEC_ID_FLAC;
9-
use symphonia_core::codecs::audio::{AudioCodecParameters, VerificationCheck};
9+
use symphonia_core::codecs::audio::VerificationCheck;
1010
use symphonia_core::errors::{decode_error, unsupported_error, Result};
1111
use symphonia_core::io::{BufReader, ReadBytes};
1212

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

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

19+
use super::stsd::AudioSampleEntry;
20+
1921
/// FLAC atom.
2022
#[allow(dead_code)]
2123
#[derive(Debug)]
@@ -59,16 +61,15 @@ impl Atom for FlacAtom {
5961
}
6062

6163
impl FlacAtom {
62-
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
63-
codec_params
64-
.for_codec(CODEC_ID_FLAC)
65-
.with_sample_rate(self.stream_info.sample_rate)
66-
.with_bits_per_sample(self.stream_info.bits_per_sample)
67-
.with_channels(self.stream_info.channels.clone())
68-
.with_extra_data(self.extra_data.clone());
64+
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
65+
entry.codec_id = CODEC_ID_FLAC;
66+
entry.sample_rate = self.stream_info.sample_rate;
67+
entry.bits_per_sample = Some(self.stream_info.bits_per_sample);
68+
entry.channels = Some(self.stream_info.channels.clone());
69+
entry.extra_data = Some(self.extra_data.clone());
6970

7071
if let Some(md5) = self.stream_info.md5 {
71-
codec_params.with_verification_code(VerificationCheck::Md5(md5));
72+
entry.verification_check = Some(VerificationCheck::Md5(md5));
7273
}
7374
}
7475
}

Diff for: symphonia-format-isomp4/src/atoms/opus.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
// License, v. 2.0. If a copy of the MPL was not distributed with this
66
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
77

8-
use symphonia_core::codecs::audio::{well_known::CODEC_ID_OPUS, AudioCodecParameters};
8+
use symphonia_core::codecs::audio::well_known::CODEC_ID_OPUS;
99
use symphonia_core::errors::{decode_error, unsupported_error, Error, Result};
1010
use symphonia_core::io::ReadBytes;
1111

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

14+
use super::stsd::AudioSampleEntry;
15+
1416
/// Opus atom.
1517
#[allow(dead_code)]
1618
#[derive(Debug)]
@@ -64,7 +66,8 @@ impl Atom for OpusAtom {
6466
}
6567

6668
impl OpusAtom {
67-
pub fn fill_codec_params(&self, codec_params: &mut AudioCodecParameters) {
68-
codec_params.for_codec(CODEC_ID_OPUS).with_extra_data(self.extra_data.clone());
69+
pub fn fill_audio_sample_entry(&self, entry: &mut AudioSampleEntry) {
70+
entry.codec_id = CODEC_ID_OPUS;
71+
entry.extra_data = Some(self.extra_data.clone());
6972
}
7073
}

0 commit comments

Comments
 (0)