Skip to content

Commit 1ff597d

Browse files
committed
Allow multiple audio DecoderSpecificInfo entries outside of strict mode.
1 parent b148a6a commit 1ff597d

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

mp4parse/src/lib.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub enum Status {
200200
ElstBadVersion,
201201
EsdsBadAudioSampleEntry,
202202
EsdsBadDescriptor,
203-
EsdsDecSpecificIntoTagQuantity,
203+
EsdsDecSpecificInfoTagQuantity,
204204
FtypBadSize,
205205
FtypNotFirst,
206206
HdlrNameNoNul,
@@ -514,7 +514,7 @@ impl From<Status> for &str {
514514
Status::EsdsBadDescriptor => {
515515
"Invalid descriptor."
516516
}
517-
Status::EsdsDecSpecificIntoTagQuantity => {
517+
Status::EsdsDecSpecificInfoTagQuantity => {
518518
"There can be only one DecSpecificInfoTag descriptor"
519519
}
520520
Status::FtypBadSize => {
@@ -5041,7 +5041,7 @@ fn get_audio_object_type(bit_reader: &mut BitReader) -> Result<u16> {
50415041
fn read_ds_descriptor(
50425042
data: &[u8],
50435043
esds: &mut ES_Descriptor,
5044-
_strictness: ParseStrictness,
5044+
strictness: ParseStrictness,
50455045
) -> Result<()> {
50465046
#[cfg(feature = "mp4v")]
50475047
// Check if we are in a Visual esda Box.
@@ -5198,7 +5198,10 @@ fn read_ds_descriptor(
51985198
esds.audio_sample_rate = Some(sample_frequency_value);
51995199
esds.audio_channel_count = Some(channel_counts);
52005200
if !esds.decoder_specific_data.is_empty() {
5201-
return Status::EsdsDecSpecificIntoTagQuantity.into();
5201+
fail_with_status_if(
5202+
strictness == ParseStrictness::Strict,
5203+
Status::EsdsDecSpecificInfoTagQuantity,
5204+
)?;
52025205
}
52035206
esds.decoder_specific_data.extend_from_slice(data)?;
52045207

mp4parse/src/tests.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,30 @@ fn read_esds_redundant_descriptor() {
13181318
}
13191319
}
13201320

1321+
#[test]
1322+
fn read_esds_multiple_descriptors() {
1323+
// Permit multiple descriptors in non-strict mode.
1324+
// Extracted from BMO #1936124 using Bento4.
1325+
// "mp4extract --payload-only moov/trak[0]/mdia/minf/stbl/stsd/mp4a/esds bug1936124.mp4 /dev/stdout | xxd -i -c 15"
1326+
let esds = vec![
1327+
0x03, 0x1d, 0x00, 0x00, 0x00, 0x04, 0x15, 0x40, 0x15, 0x00, 0x06, 0x00, 0x00, 0x01, 0x77,
1328+
0x00, 0x00, 0x01, 0x77, 0x00, 0x05, 0x02, 0x11, 0x90, 0x05, 0x02, 0x11, 0x90, 0x06, 0x01,
1329+
0x02,
1330+
];
1331+
1332+
let mut stream = make_box(BoxSize::Auto, b"esds", |s| {
1333+
s.B32(0) // reserved
1334+
.append_bytes(esds.as_slice())
1335+
});
1336+
let mut iter = super::BoxIter::new(&mut stream);
1337+
let mut stream = iter.next_box().unwrap().unwrap();
1338+
1339+
match super::read_esds(&mut stream, ParseStrictness::Normal) {
1340+
Ok(esds) => assert_eq!(esds.audio_codec, super::CodecType::AAC),
1341+
_ => panic!("unexpected result with multiple descriptors"),
1342+
}
1343+
}
1344+
13211345
#[test]
13221346
fn read_stsd_lpcm() {
13231347
// Extract from sample converted by ffmpeg.

0 commit comments

Comments
 (0)