@@ -407,6 +407,8 @@ pub struct ES_Descriptor {
407407 pub extended_audio_object_type : Option < u16 > ,
408408 pub audio_sample_rate : Option < u32 > ,
409409 pub audio_channel_count : Option < u16 > ,
410+ #[ cfg( feature = "mp4v" ) ]
411+ pub video_codec : CodecType ,
410412 pub codec_esds : TryVec < u8 > ,
411413 pub decoder_specific_data : TryVec < u8 > , // Data in DECODER_SPECIFIC_TAG
412414}
@@ -3725,6 +3727,14 @@ fn get_audio_object_type(bit_reader: &mut BitReader) -> Result<u16> {
37253727
37263728/// See MPEG-4 Systems (ISO 14496-1:2010) § 7.2.6.7 and probably 14496-3 somewhere?
37273729fn read_ds_descriptor ( data : & [ u8 ] , esds : & mut ES_Descriptor ) -> Result < ( ) > {
3730+ #[ cfg( feature = "mp4v" ) ]
3731+ // Check if we are in a Visual esda Box.
3732+ if esds. video_codec != CodecType :: Unknown {
3733+ esds. decoder_specific_data . extend_from_slice ( data) ?;
3734+ return Ok ( ( ) ) ;
3735+ }
3736+
3737+ // We are in an Audio esda Box.
37283738 let frequency_table = vec ! [
37293739 ( 0x0 , 96000 ) ,
37303740 ( 0x1 , 88200 ) ,
@@ -3899,6 +3909,14 @@ fn read_dc_descriptor(data: &[u8], esds: &mut ES_Descriptor) -> Result<()> {
38993909 let des = & mut Cursor :: new ( data) ;
39003910 let object_profile = des. read_u8 ( ) ?;
39013911
3912+ #[ cfg( feature = "mp4v" ) ]
3913+ {
3914+ esds. video_codec = match object_profile {
3915+ 0x20 ..=0x24 => CodecType :: MP4V ,
3916+ _ => CodecType :: Unknown ,
3917+ } ;
3918+ }
3919+
39023920 // Skip uninteresting fields.
39033921 skip ( des, 12 ) ?;
39043922
@@ -4214,16 +4232,27 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
42144232 if name != BoxType :: MP4VideoSampleEntry || codec_specific. is_some ( ) {
42154233 return Err ( Error :: InvalidData ( "malformed video sample entry" ) ) ;
42164234 }
4217- let ( _, _) = read_fullbox_extra ( & mut b. content ) ?;
4218- // Subtract 4 extra to offset the members of fullbox not
4219- // accounted for in head.offset
4220- let esds_size = b
4221- . head
4222- . size
4223- . checked_sub ( b. head . offset + 4 )
4224- . expect ( "offset invalid" ) ;
4225- let esds = read_buf ( & mut b. content , esds_size) ?;
4226- codec_specific = Some ( VideoCodecSpecific :: ESDSConfig ( esds) ) ;
4235+ #[ cfg( not( feature = "mp4v" ) ) ]
4236+ {
4237+ let ( _, _) = read_fullbox_extra ( & mut b. content ) ?;
4238+ // Subtract 4 extra to offset the members of fullbox not
4239+ // accounted for in head.offset
4240+ let esds_size = b
4241+ . head
4242+ . size
4243+ . checked_sub ( b. head . offset + 4 )
4244+ . expect ( "offset invalid" ) ;
4245+ let esds = read_buf ( & mut b. content , esds_size) ?;
4246+ codec_specific = Some ( VideoCodecSpecific :: ESDSConfig ( esds) ) ;
4247+ }
4248+ #[ cfg( feature = "mp4v" ) ]
4249+ {
4250+ // Read ES_Descriptor inside an esds box.
4251+ // See ISOBMFF (ISO 14496-1:2010 §7.2.6.5)
4252+ let esds = read_esds ( & mut b) ?;
4253+ codec_specific =
4254+ Some ( VideoCodecSpecific :: ESDSConfig ( esds. decoder_specific_data ) ) ;
4255+ }
42274256 }
42284257 BoxType :: ProtectionSchemeInfoBox => {
42294258 if name != BoxType :: ProtectedVisualSampleEntry {
0 commit comments