@@ -738,12 +738,6 @@ pub struct MediaContext {
738
738
pub userdata : Option < Result < UserdataBox > > ,
739
739
}
740
740
741
- impl MediaContext {
742
- pub fn new ( ) -> MediaContext {
743
- Default :: default ( )
744
- }
745
- }
746
-
747
741
/// An ISOBMFF item as described by an iloc box. For the sake of avoiding copies,
748
742
/// this can either be represented by the `Location` variant, which indicates
749
743
/// where the data exists within a `MediaDataBox` stored separately, or the
@@ -2278,7 +2272,7 @@ pub fn read_mp4<T: Read>(f: &mut T) -> Result<MediaContext> {
2278
2272
debug ! ( "{:?}" , ftyp) ;
2279
2273
}
2280
2274
BoxType :: MovieBox => {
2281
- context = Some ( read_moov ( & mut b) ?) ;
2275
+ context = Some ( read_moov ( & mut b, context ) ?) ;
2282
2276
}
2283
2277
_ => skip_box_content ( & mut b) ?,
2284
2278
} ;
@@ -2301,6 +2295,8 @@ pub fn read_mp4<T: Read>(f: &mut T) -> Result<MediaContext> {
2301
2295
context. ok_or ( Error :: NoMoov )
2302
2296
}
2303
2297
2298
+ /// Parse a Movie Header Box
2299
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.2.2
2304
2300
fn parse_mvhd < T : Read > ( f : & mut BMFFBox < T > ) -> Result < Option < MediaTimeScale > > {
2305
2301
let mvhd = read_mvhd ( f) ?;
2306
2302
debug ! ( "{:?}" , mvhd) ;
@@ -2311,14 +2307,19 @@ fn parse_mvhd<T: Read>(f: &mut BMFFBox<T>) -> Result<Option<MediaTimeScale>> {
2311
2307
Ok ( timescale)
2312
2308
}
2313
2309
2314
- fn read_moov < T : Read > ( f : & mut BMFFBox < T > ) -> Result < MediaContext > {
2310
+ /// Parse a Movie Box
2311
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.2.1
2312
+ /// Note that despite the spec indicating "exactly one" moov box should exist at
2313
+ /// the file container level, we support reading and merging multiple moov boxes
2314
+ /// such as with tests/test_case_1185230.mp4.
2315
+ fn read_moov < T : Read > ( f : & mut BMFFBox < T > , context : Option < MediaContext > ) -> Result < MediaContext > {
2315
2316
let MediaContext {
2316
2317
mut timescale,
2317
2318
mut tracks,
2318
2319
mut mvex,
2319
2320
mut psshs,
2320
2321
mut userdata,
2321
- } = Default :: default ( ) ;
2322
+ } = context . unwrap_or_default ( ) ;
2322
2323
2323
2324
let mut iter = f. box_iter ( ) ;
2324
2325
while let Some ( mut b) = iter. next_box ( ) ? {
@@ -2396,6 +2397,8 @@ fn read_pssh<T: Read>(src: &mut BMFFBox<T>) -> Result<ProtectionSystemSpecificHe
2396
2397
} )
2397
2398
}
2398
2399
2400
+ /// Parse a Movie Extends Box
2401
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.8.1
2399
2402
fn read_mvex < T : Read > ( src : & mut BMFFBox < T > ) -> Result < MovieExtendsBox > {
2400
2403
let mut iter = src. box_iter ( ) ;
2401
2404
let mut fragment_duration = None ;
@@ -2421,6 +2424,8 @@ fn read_mehd<T: Read>(src: &mut BMFFBox<T>) -> Result<MediaScaledTime> {
2421
2424
Ok ( MediaScaledTime ( fragment_duration) )
2422
2425
}
2423
2426
2427
+ /// Parse a Track Box
2428
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.3.1.
2424
2429
fn read_trak < T : Read > ( f : & mut BMFFBox < T > , track : & mut Track ) -> Result < ( ) > {
2425
2430
let mut iter = f. box_iter ( ) ;
2426
2431
while let Some ( mut b) = iter. next_box ( ) ? {
@@ -3940,6 +3945,7 @@ fn read_schm<T: Read>(src: &mut BMFFBox<T>) -> Result<SchemeTypeBox> {
3940
3945
}
3941
3946
3942
3947
/// Parse a metadata box inside a moov, trak, or mdia box.
3948
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.10.1.
3943
3949
fn read_udta < T : Read > ( src : & mut BMFFBox < T > ) -> Result < UserdataBox > {
3944
3950
let mut iter = src. box_iter ( ) ;
3945
3951
let mut udta = UserdataBox { meta : None } ;
0 commit comments