@@ -2417,7 +2417,7 @@ pub fn read_avif<T: Read>(f: &mut T, strictness: ParseStrictness) -> Result<Avif
2417
2417
if image_sequence. is_some ( ) {
2418
2418
return Status :: MoovBadQuantity . into ( ) ;
2419
2419
}
2420
- image_sequence = Some ( read_moov ( & mut b, None ) ?) ;
2420
+ image_sequence = Some ( read_moov ( & mut b, None , strictness ) ?) ;
2421
2421
}
2422
2422
BoxType :: MediaDataBox => {
2423
2423
let file_offset = b. offset ( ) ;
@@ -4058,7 +4058,7 @@ fn read_iloc<T: Read>(src: &mut BMFFBox<T>) -> Result<TryHashMap<ItemId, ItemLoc
4058
4058
}
4059
4059
4060
4060
/// Read the contents of a box, including sub boxes.
4061
- pub fn read_mp4 < T : Read > ( f : & mut T ) -> Result < MediaContext > {
4061
+ pub fn read_mp4 < T : Read > ( f : & mut T , strictness : ParseStrictness ) -> Result < MediaContext > {
4062
4062
let mut context = None ;
4063
4063
let mut found_ftyp = false ;
4064
4064
// TODO(kinetik): Top-level parsing should handle zero-sized boxes
@@ -4087,7 +4087,7 @@ pub fn read_mp4<T: Read>(f: &mut T) -> Result<MediaContext> {
4087
4087
debug ! ( "{:?}" , ftyp) ;
4088
4088
}
4089
4089
BoxType :: MovieBox => {
4090
- context = Some ( read_moov ( & mut b, context) ?) ;
4090
+ context = Some ( read_moov ( & mut b, context, strictness ) ?) ;
4091
4091
}
4092
4092
#[ cfg( feature = "meta-xml" ) ]
4093
4093
BoxType :: MetadataBox => {
@@ -4133,7 +4133,11 @@ fn parse_mvhd<T: Read>(f: &mut BMFFBox<T>) -> Result<Option<MediaTimeScale>> {
4133
4133
/// Note that despite the spec indicating "exactly one" moov box should exist at
4134
4134
/// the file container level, we support reading and merging multiple moov boxes
4135
4135
/// such as with tests/test_case_1185230.mp4.
4136
- fn read_moov < T : Read > ( f : & mut BMFFBox < T > , context : Option < MediaContext > ) -> Result < MediaContext > {
4136
+ fn read_moov < T : Read > (
4137
+ f : & mut BMFFBox < T > ,
4138
+ context : Option < MediaContext > ,
4139
+ strictness : ParseStrictness ,
4140
+ ) -> Result < MediaContext > {
4137
4141
let MediaContext {
4138
4142
mut timescale,
4139
4143
mut tracks,
@@ -4152,7 +4156,7 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>, context: Option<MediaContext>) -> Resu
4152
4156
}
4153
4157
BoxType :: TrackBox => {
4154
4158
let mut track = Track :: new ( tracks. len ( ) ) ;
4155
- read_trak ( & mut b, & mut track) ?;
4159
+ read_trak ( & mut b, & mut track, strictness ) ?;
4156
4160
tracks. push ( track) ?;
4157
4161
}
4158
4162
BoxType :: MovieExtendsBox => {
@@ -4262,7 +4266,11 @@ fn read_mehd<T: Read>(src: &mut BMFFBox<T>) -> Result<MediaScaledTime> {
4262
4266
4263
4267
/// Parse a Track Box
4264
4268
/// See ISOBMFF (ISO 14496-12:2020) § 8.3.1.
4265
- fn read_trak < T : Read > ( f : & mut BMFFBox < T > , track : & mut Track ) -> Result < ( ) > {
4269
+ fn read_trak < T : Read > (
4270
+ f : & mut BMFFBox < T > ,
4271
+ track : & mut Track ,
4272
+ strictness : ParseStrictness ,
4273
+ ) -> Result < ( ) > {
4266
4274
let mut iter = f. box_iter ( ) ;
4267
4275
while let Some ( mut b) = iter. next_box ( ) ? {
4268
4276
match b. head . name {
@@ -4273,7 +4281,7 @@ fn read_trak<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
4273
4281
debug ! ( "{:?}" , tkhd) ;
4274
4282
}
4275
4283
BoxType :: EditBox => read_edts ( & mut b, track) ?,
4276
- BoxType :: MediaBox => read_mdia ( & mut b, track) ?,
4284
+ BoxType :: MediaBox => read_mdia ( & mut b, track, strictness ) ?,
4277
4285
BoxType :: TrackReferenceBox => track. tref = Some ( read_tref ( & mut b) ?) ,
4278
4286
_ => skip_box_content ( & mut b) ?,
4279
4287
} ;
@@ -4346,7 +4354,11 @@ fn parse_mdhd<T: Read>(
4346
4354
Ok ( ( mdhd, duration, timescale) )
4347
4355
}
4348
4356
4349
- fn read_mdia < T : Read > ( f : & mut BMFFBox < T > , track : & mut Track ) -> Result < ( ) > {
4357
+ fn read_mdia < T : Read > (
4358
+ f : & mut BMFFBox < T > ,
4359
+ track : & mut Track ,
4360
+ strictness : ParseStrictness ,
4361
+ ) -> Result < ( ) > {
4350
4362
let mut iter = f. box_iter ( ) ;
4351
4363
while let Some ( mut b) = iter. next_box ( ) ? {
4352
4364
match b. head . name {
@@ -4369,7 +4381,7 @@ fn read_mdia<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
4369
4381
}
4370
4382
debug ! ( "{:?}" , hdlr) ;
4371
4383
}
4372
- BoxType :: MediaInformationBox => read_minf ( & mut b, track) ?,
4384
+ BoxType :: MediaInformationBox => read_minf ( & mut b, track, strictness ) ?,
4373
4385
_ => skip_box_content ( & mut b) ?,
4374
4386
} ;
4375
4387
check_parser_state ! ( b. content) ;
@@ -4403,24 +4415,32 @@ fn read_tref_auxl<T: Read>(f: &mut BMFFBox<T>) -> Result<TrackReference> {
4403
4415
Ok ( TrackReference { track_ids } )
4404
4416
}
4405
4417
4406
- fn read_minf < T : Read > ( f : & mut BMFFBox < T > , track : & mut Track ) -> Result < ( ) > {
4418
+ fn read_minf < T : Read > (
4419
+ f : & mut BMFFBox < T > ,
4420
+ track : & mut Track ,
4421
+ strictness : ParseStrictness ,
4422
+ ) -> Result < ( ) > {
4407
4423
let mut iter = f. box_iter ( ) ;
4408
4424
while let Some ( mut b) = iter. next_box ( ) ? {
4409
4425
match b. head . name {
4410
- BoxType :: SampleTableBox => read_stbl ( & mut b, track) ?,
4426
+ BoxType :: SampleTableBox => read_stbl ( & mut b, track, strictness ) ?,
4411
4427
_ => skip_box_content ( & mut b) ?,
4412
4428
} ;
4413
4429
check_parser_state ! ( b. content) ;
4414
4430
}
4415
4431
Ok ( ( ) )
4416
4432
}
4417
4433
4418
- fn read_stbl < T : Read > ( f : & mut BMFFBox < T > , track : & mut Track ) -> Result < ( ) > {
4434
+ fn read_stbl < T : Read > (
4435
+ f : & mut BMFFBox < T > ,
4436
+ track : & mut Track ,
4437
+ strictness : ParseStrictness ,
4438
+ ) -> Result < ( ) > {
4419
4439
let mut iter = f. box_iter ( ) ;
4420
4440
while let Some ( mut b) = iter. next_box ( ) ? {
4421
4441
match b. head . name {
4422
4442
BoxType :: SampleDescriptionBox => {
4423
- let stsd = read_stsd ( & mut b, track) ?;
4443
+ let stsd = read_stsd ( & mut b, track, strictness ) ?;
4424
4444
debug ! ( "{:?}" , stsd) ;
4425
4445
track. stsd = Some ( stsd) ;
4426
4446
}
@@ -4942,7 +4962,11 @@ fn read_flac_metadata<T: Read>(src: &mut BMFFBox<T>) -> Result<FLACMetadataBlock
4942
4962
}
4943
4963
4944
4964
/// See MPEG-4 Systems (ISO 14496-1:2010) § 7.2.6.5
4945
- fn find_descriptor ( data : & [ u8 ] , esds : & mut ES_Descriptor ) -> Result < ( ) > {
4965
+ fn find_descriptor (
4966
+ data : & [ u8 ] ,
4967
+ esds : & mut ES_Descriptor ,
4968
+ strictness : ParseStrictness ,
4969
+ ) -> Result < ( ) > {
4946
4970
// Tags for elementary stream description
4947
4971
const ESDESCR_TAG : u8 = 0x03 ;
4948
4972
const DECODER_CONFIG_TAG : u8 = 0x04 ;
@@ -4982,13 +5006,13 @@ fn find_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
4982
5006
4983
5007
match tag {
4984
5008
ESDESCR_TAG => {
4985
- read_es_descriptor ( descriptor, esds) ?;
5009
+ read_es_descriptor ( descriptor, esds, strictness ) ?;
4986
5010
}
4987
5011
DECODER_CONFIG_TAG => {
4988
- read_dc_descriptor ( descriptor, esds) ?;
5012
+ read_dc_descriptor ( descriptor, esds, strictness ) ?;
4989
5013
}
4990
5014
DECODER_SPECIFIC_TAG => {
4991
- read_ds_descriptor ( descriptor, esds) ?;
5015
+ read_ds_descriptor ( descriptor, esds, strictness ) ?;
4992
5016
}
4993
5017
_ => {
4994
5018
debug ! ( "Unsupported descriptor, tag {}" , tag) ;
@@ -5014,7 +5038,11 @@ fn get_audio_object_type(bit_reader: &mut BitReader) -> Result<u16> {
5014
5038
}
5015
5039
5016
5040
/// See MPEG-4 Systems (ISO 14496-1:2010) § 7.2.6.7 and probably 14496-3 somewhere?
5017
- fn read_ds_descriptor ( data : & [ u8 ] , esds : & mut ES_Descriptor ) -> Result < ( ) > {
5041
+ fn read_ds_descriptor (
5042
+ data : & [ u8 ] ,
5043
+ esds : & mut ES_Descriptor ,
5044
+ _strictness : ParseStrictness ,
5045
+ ) -> Result < ( ) > {
5018
5046
#[ cfg( feature = "mp4v" ) ]
5019
5047
// Check if we are in a Visual esda Box.
5020
5048
if esds. video_codec != CodecType :: Unknown {
@@ -5191,7 +5219,11 @@ fn read_surround_channel_count(bit_reader: &mut BitReader, channels: u8) -> Resu
5191
5219
}
5192
5220
5193
5221
/// See MPEG-4 Systems (ISO 14496-1:2010) § 7.2.6.6
5194
- fn read_dc_descriptor ( data : & [ u8 ] , esds : & mut ES_Descriptor ) -> Result < ( ) > {
5222
+ fn read_dc_descriptor (
5223
+ data : & [ u8 ] ,
5224
+ esds : & mut ES_Descriptor ,
5225
+ strictness : ParseStrictness ,
5226
+ ) -> Result < ( ) > {
5195
5227
let des = & mut Cursor :: new ( data) ;
5196
5228
let object_profile = des. read_u8 ( ) ?;
5197
5229
@@ -5207,7 +5239,11 @@ fn read_dc_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
5207
5239
skip ( des, 12 ) ?;
5208
5240
5209
5241
if data. len ( ) . to_u64 ( ) > des. position ( ) {
5210
- find_descriptor ( & data[ des. position ( ) . try_into ( ) ?..data. len ( ) ] , esds) ?;
5242
+ find_descriptor (
5243
+ & data[ des. position ( ) . try_into ( ) ?..data. len ( ) ] ,
5244
+ esds,
5245
+ strictness,
5246
+ ) ?;
5211
5247
}
5212
5248
5213
5249
esds. audio_codec = match object_profile {
@@ -5225,7 +5261,11 @@ fn read_dc_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
5225
5261
}
5226
5262
5227
5263
/// See MPEG-4 Systems (ISO 14496-1:2010) § 7.2.6.5
5228
- fn read_es_descriptor ( data : & [ u8 ] , esds : & mut ES_Descriptor ) -> Result < ( ) > {
5264
+ fn read_es_descriptor (
5265
+ data : & [ u8 ] ,
5266
+ esds : & mut ES_Descriptor ,
5267
+ strictness : ParseStrictness ,
5268
+ ) -> Result < ( ) > {
5229
5269
let des = & mut Cursor :: new ( data) ;
5230
5270
5231
5271
skip ( des, 2 ) ?;
@@ -5246,20 +5286,24 @@ fn read_es_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
5246
5286
}
5247
5287
5248
5288
if data. len ( ) . to_u64 ( ) > des. position ( ) {
5249
- find_descriptor ( & data[ des. position ( ) . try_into ( ) ?..data. len ( ) ] , esds) ?;
5289
+ find_descriptor (
5290
+ & data[ des. position ( ) . try_into ( ) ?..data. len ( ) ] ,
5291
+ esds,
5292
+ strictness,
5293
+ ) ?;
5250
5294
}
5251
5295
5252
5296
Ok ( ( ) )
5253
5297
}
5254
5298
5255
5299
/// See MP4 (ISO 14496-14:2020) § 6.7.2
5256
- fn read_esds < T : Read > ( src : & mut BMFFBox < T > ) -> Result < ES_Descriptor > {
5300
+ fn read_esds < T : Read > ( src : & mut BMFFBox < T > , strictness : ParseStrictness ) -> Result < ES_Descriptor > {
5257
5301
let ( _, _) = read_fullbox_extra ( src) ?;
5258
5302
5259
5303
let esds_array = read_buf ( src, src. bytes_left ( ) ) ?;
5260
5304
5261
5305
let mut es_data = ES_Descriptor :: default ( ) ;
5262
- find_descriptor ( & esds_array, & mut es_data) ?;
5306
+ find_descriptor ( & esds_array, & mut es_data, strictness ) ?;
5263
5307
5264
5308
es_data. codec_esds = esds_array;
5265
5309
@@ -5558,7 +5602,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
5558
5602
{
5559
5603
// Read ES_Descriptor inside an esds box.
5560
5604
// See ISOBMFF (ISO 14496-1:2010) § 7.2.6.5
5561
- let esds = read_esds ( & mut b) ?;
5605
+ let esds = read_esds ( & mut b, ParseStrictness :: Normal ) ?;
5562
5606
codec_specific =
5563
5607
Some ( VideoCodecSpecific :: ESDSConfig ( esds. decoder_specific_data ) ) ;
5564
5608
}
@@ -5621,13 +5665,16 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
5621
5665
)
5622
5666
}
5623
5667
5624
- fn read_qt_wave_atom < T : Read > ( src : & mut BMFFBox < T > ) -> Result < ES_Descriptor > {
5668
+ fn read_qt_wave_atom < T : Read > (
5669
+ src : & mut BMFFBox < T > ,
5670
+ strictness : ParseStrictness ,
5671
+ ) -> Result < ES_Descriptor > {
5625
5672
let mut codec_specific = None ;
5626
5673
let mut iter = src. box_iter ( ) ;
5627
5674
while let Some ( mut b) = iter. next_box ( ) ? {
5628
5675
match b. head . name {
5629
5676
BoxType :: ESDBox => {
5630
- let esds = read_esds ( & mut b) ?;
5677
+ let esds = read_esds ( & mut b, strictness ) ?;
5631
5678
codec_specific = Some ( esds) ;
5632
5679
}
5633
5680
_ => skip_box_content ( & mut b) ?,
@@ -5639,7 +5686,10 @@ fn read_qt_wave_atom<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
5639
5686
5640
5687
/// Parse an audio description inside an stsd box.
5641
5688
/// See ISOBMFF (ISO 14496-12:2020) § 12.2.3
5642
- fn read_audio_sample_entry < T : Read > ( src : & mut BMFFBox < T > ) -> Result < SampleEntry > {
5689
+ fn read_audio_sample_entry < T : Read > (
5690
+ src : & mut BMFFBox < T > ,
5691
+ strictness : ParseStrictness ,
5692
+ ) -> Result < SampleEntry > {
5643
5693
let name = src. get_header ( ) . name ;
5644
5694
5645
5695
// Skip uninteresting fields.
@@ -5713,7 +5763,7 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
5713
5763
{
5714
5764
return Status :: StsdBadAudioSampleEntry . into ( ) ;
5715
5765
}
5716
- let esds = read_esds ( & mut b) ?;
5766
+ let esds = read_esds ( & mut b, strictness ) ?;
5717
5767
codec_type = esds. audio_codec ;
5718
5768
codec_specific = Some ( AudioCodecSpecific :: ES_Descriptor ( esds) ) ;
5719
5769
}
@@ -5746,7 +5796,7 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
5746
5796
codec_specific = Some ( AudioCodecSpecific :: ALACSpecificBox ( alac) ) ;
5747
5797
}
5748
5798
BoxType :: QTWaveAtom => {
5749
- let qt_esds = read_qt_wave_atom ( & mut b) ?;
5799
+ let qt_esds = read_qt_wave_atom ( & mut b, strictness ) ?;
5750
5800
codec_type = qt_esds. audio_codec ;
5751
5801
codec_specific = Some ( AudioCodecSpecific :: ES_Descriptor ( qt_esds) ) ;
5752
5802
}
@@ -5799,7 +5849,11 @@ fn read_audio_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
5799
5849
/// Parse a stsd box.
5800
5850
/// See ISOBMFF (ISO 14496-12:2020) § 8.5.2
5801
5851
/// See MP4 (ISO 14496-14:2020) § 6.7.2
5802
- fn read_stsd < T : Read > ( src : & mut BMFFBox < T > , track : & Track ) -> Result < SampleDescriptionBox > {
5852
+ fn read_stsd < T : Read > (
5853
+ src : & mut BMFFBox < T > ,
5854
+ track : & Track ,
5855
+ strictness : ParseStrictness ,
5856
+ ) -> Result < SampleDescriptionBox > {
5803
5857
let ( _, flags) = read_fullbox_extra ( src) ?;
5804
5858
5805
5859
if flags != 0 {
@@ -5819,7 +5873,7 @@ fn read_stsd<T: Read>(src: &mut BMFFBox<T>, track: &Track) -> Result<SampleDescr
5819
5873
TrackType :: Video => read_video_sample_entry ( & mut b) ,
5820
5874
TrackType :: Picture => read_video_sample_entry ( & mut b) ,
5821
5875
TrackType :: AuxiliaryVideo => read_video_sample_entry ( & mut b) ,
5822
- TrackType :: Audio => read_audio_sample_entry ( & mut b) ,
5876
+ TrackType :: Audio => read_audio_sample_entry ( & mut b, strictness ) ,
5823
5877
TrackType :: Metadata => Err ( Error :: Unsupported ( "metadata track" ) ) ,
5824
5878
TrackType :: Unknown => Err ( Error :: Unsupported ( "unknown track type" ) ) ,
5825
5879
} ;
0 commit comments