From 1757d24e78ad81f03b22351e9cfb691b2a6cf235 Mon Sep 17 00:00:00 2001 From: John Calhoun Date: Sat, 4 Jul 2020 09:45:26 -0700 Subject: [PATCH] =?UTF-8?q?Per=20ISO=2014496-1=20=C2=A7=207.2.6.7.2,=20the?= =?UTF-8?q?=20semantics=20of=20decoder=20specific=20information=20depend?= =?UTF-8?q?=20on=20the=20value=20of=20DecoderConfigDescriptor.objectTypeIn?= =?UTF-8?q?dication.=20But=20for=20audio,=20mp4parse=20treats=20all=20deco?= =?UTF-8?q?der=20specific=20information=20as=20if=20it=20has=20the=20bit?= =?UTF-8?q?=20syntax=20defined=20for=20object=20type=20indication=200x40.?= =?UTF-8?q?=20This=20is=20not=20the=20case=20for=20object=20type=20indicat?= =?UTF-8?q?ions=200x69=20and=200x6B,=20which=20now=20have=20more=20recentl?= =?UTF-8?q?y=20defined=20decoder=20specific=20information=20with=20a=20dis?= =?UTF-8?q?tinct=20bit=20syntax,=20which=20Mozilla=20code=20can=20disregar?= =?UTF-8?q?d.=20This=20allows=20tracks=20carrying=20MP3=20audio=20to=20be?= =?UTF-8?q?=20parsed=20correctly=20when=20the=20new=20decoder=20specific?= =?UTF-8?q?=20info=20is=20present.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mp4parse/src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/mp4parse/src/lib.rs b/mp4parse/src/lib.rs index 9942288a..948eeffb 100644 --- a/mp4parse/src/lib.rs +++ b/mp4parse/src/lib.rs @@ -379,6 +379,7 @@ pub enum SampleEntry { #[allow(non_camel_case_types)] #[derive(Debug, Default)] pub struct ES_Descriptor { + pub object_profile: u8, pub audio_codec: CodecType, pub audio_object_type: Option, pub extended_audio_object_type: Option, @@ -2452,7 +2453,16 @@ fn find_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> { read_dc_descriptor(descriptor, esds)?; } DECODER_SPECIFIC_TAG => { - read_ds_descriptor(descriptor, esds)?; + match esds.object_profile { + 0x69 | 0x6B => { + // Could parse these object types' decoder specific info + // to discover the MPEG audio layer, etc., if needed. + break; + } + _ => { + read_ds_descriptor(descriptor, esds)?; + } + }; } _ => { debug!("Unsupported descriptor, tag {}", tag); @@ -2647,7 +2657,7 @@ fn read_surround_channel_count(bit_reader: &mut BitReader, channels: u8) -> Resu /// See ISO 14496-1:2010 ยง 7.2.6.6 fn read_dc_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> { let des = &mut Cursor::new(data); - let object_profile = des.read_u8()?; + esds.object_profile = des.read_u8()?; // Skip uninteresting fields. skip(des, 12)?; @@ -2656,9 +2666,9 @@ fn read_dc_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> { find_descriptor(&data[des.position().try_into()?..data.len()], esds)?; } - esds.audio_codec = match object_profile { + esds.audio_codec = match esds.object_profile { 0x40 | 0x41 => CodecType::AAC, - 0x6B => CodecType::MP3, + 0x69 | 0x6B => CodecType::MP3, _ => CodecType::Unknown, };