@@ -42,9 +42,7 @@ use std::io::Read;
42
42
43
43
// Symbols we need from our rust api.
44
44
use mp4parse:: serialize_opus_header;
45
- use mp4parse:: unstable:: {
46
- create_sample_table, media_time_to_us, track_time_to_us, CheckedInteger , Indice , Microseconds ,
47
- } ;
45
+ use mp4parse:: unstable:: { create_sample_table, CheckedInteger , Indice } ;
48
46
use mp4parse:: AV1ConfigBox ;
49
47
use mp4parse:: AudioCodecSpecific ;
50
48
use mp4parse:: AvifContext ;
@@ -127,10 +125,8 @@ pub struct Mp4parseTrackInfo {
127
125
pub track_type : Mp4parseTrackType ,
128
126
pub track_id : u32 ,
129
127
pub duration : u64 ,
130
- pub media_time : CheckedInteger < i64 > , // wants to be u64? understand how elst adjustment works
131
- // TODO(kinetik): include crypto guff
132
- // If this changes to u64, we can get rid of the strange
133
- // impl Sub for CheckedInteger<u64>
128
+ pub media_time : CheckedInteger < i64 > ,
129
+ pub time_scale : u32 ,
134
130
}
135
131
136
132
#[ repr( C ) ]
@@ -278,9 +274,9 @@ impl Default for Mp4parseTrackVideoInfo {
278
274
#[ repr( C ) ]
279
275
#[ derive( Default , Debug ) ]
280
276
pub struct Mp4parseFragmentInfo {
281
- pub fragment_duration : u64 ,
282
- // TODO:
283
- // info in trex box.
277
+ pub fragment_duration : u64 , // in ticks
278
+ // TODO:
279
+ // info in trex box.
284
280
}
285
281
286
282
#[ derive( Default ) ]
@@ -631,46 +627,34 @@ pub unsafe extern "C" fn mp4parse_get_track_info(
631
627
632
628
let track = & context. tracks [ track_index] ;
633
629
634
- if let ( Some ( track_timescale) , Some ( context_timescale) ) = ( track. timescale , context. timescale ) {
635
- let media_time: CheckedInteger < _ > = match track
630
+ if let ( Some ( timescale) , Some ( _) ) = ( track. timescale , context. timescale ) {
631
+ info. time_scale = timescale. 0 as u32 ;
632
+ let media_time: CheckedInteger < u64 > = track
636
633
. media_time
637
- . map_or ( Some ( Microseconds ( 0 ) ) , |media_time| {
638
- track_time_to_us ( media_time, track_timescale)
639
- } ) {
640
- Some ( time) => time. 0 . into ( ) ,
641
- None => return Mp4parseStatus :: Invalid ,
642
- } ;
643
- let empty_duration: CheckedInteger < _ > = match track
634
+ . map_or ( 0 . into ( ) , |media_time| media_time. 0 . into ( ) ) ;
635
+
636
+ let empty_duration: CheckedInteger < u64 > = track
644
637
. empty_duration
645
- . map_or ( Some ( Microseconds ( 0 ) ) , |empty_duration| {
646
- media_time_to_us ( empty_duration, context_timescale)
647
- } ) {
648
- Some ( time) => time. 0 . into ( ) ,
649
- None => return Mp4parseStatus :: Invalid ,
650
- } ;
638
+ . map_or ( 0 . into ( ) , |empty_duration| empty_duration. 0 . into ( ) ) ;
639
+
651
640
info. media_time = match media_time - empty_duration {
652
641
Some ( difference) => difference,
653
642
None => return Mp4parseStatus :: Invalid ,
654
643
} ;
655
644
656
- if let Some ( track_duration) = track. duration {
657
- match track_time_to_us ( track_duration, track_timescale) {
658
- Some ( duration) => info. duration = duration. 0 ,
659
- None => return Mp4parseStatus :: Invalid ,
645
+ match track. duration {
646
+ Some ( duration) => info. duration = duration. 0 ,
647
+ None => {
648
+ // Duration unknown; stagefright returns 0 for this.
649
+ info. duration = 0
660
650
}
661
- } else {
662
- // Duration unknown; stagefright returns 0 for this.
663
- info. duration = 0
664
651
}
665
- } else {
666
- return Mp4parseStatus :: Invalid ;
667
- }
652
+ } ;
668
653
669
654
info. track_id = match track. track_id {
670
655
Some ( track_id) => track_id,
671
656
None => return Mp4parseStatus :: Invalid ,
672
657
} ;
673
-
674
658
Mp4parseStatus :: Ok
675
659
}
676
660
@@ -1355,20 +1339,15 @@ fn get_indice_table(
1355
1339
return Ok ( ( ) ) ;
1356
1340
}
1357
1341
1358
- let media_time = match ( & track. media_time , & track. timescale ) {
1359
- ( & Some ( t) , & Some ( s) ) => track_time_to_us ( t, s)
1360
- . and_then ( |v| i64:: try_from ( v. 0 ) . ok ( ) )
1361
- . map ( Into :: into) ,
1342
+ let media_time = match & track. media_time {
1343
+ & Some ( t) => i64:: try_from ( t. 0 ) . ok ( ) . map ( Into :: into) ,
1362
1344
_ => None ,
1363
1345
} ;
1364
1346
1365
- let empty_duration: Option < CheckedInteger < _ > > =
1366
- match ( & track. empty_duration , & context. timescale ) {
1367
- ( & Some ( e) , & Some ( s) ) => media_time_to_us ( e, s)
1368
- . and_then ( |v| i64:: try_from ( v. 0 ) . ok ( ) )
1369
- . map ( Into :: into) ,
1370
- _ => None ,
1371
- } ;
1347
+ let empty_duration: Option < CheckedInteger < _ > > = match & track. empty_duration {
1348
+ & Some ( e) => i64:: try_from ( e. 0 ) . ok ( ) . map ( Into :: into) ,
1349
+ _ => None ,
1350
+ } ;
1372
1351
1373
1352
// Find the track start offset time from 'elst'.
1374
1353
// 'media_time' maps start time onward, 'empty_duration' adds time offset
@@ -1420,12 +1399,12 @@ pub unsafe extern "C" fn mp4parse_get_fragment_info(
1420
1399
None => return Mp4parseStatus :: Invalid ,
1421
1400
} ;
1422
1401
1423
- if let ( Some ( time) , Some ( scale) ) = ( duration, context. timescale ) {
1424
- info. fragment_duration = match media_time_to_us ( time, scale) {
1425
- Some ( time_us) => time_us. 0 ,
1426
- None => return Mp4parseStatus :: Invalid ,
1402
+ match duration {
1403
+ Some ( duration_ticks) => {
1404
+ info. fragment_duration = duration_ticks. 0 ;
1427
1405
}
1428
- }
1406
+ None => return Mp4parseStatus :: Invalid ,
1407
+ } ;
1429
1408
1430
1409
Mp4parseStatus :: Ok
1431
1410
}
@@ -1741,16 +1720,16 @@ fn minimal_mp4_get_track_info() {
1741
1720
} ) ;
1742
1721
assert_eq ! ( info. track_type, Mp4parseTrackType :: Video ) ;
1743
1722
assert_eq ! ( info. track_id, 1 ) ;
1744
- assert_eq ! ( info. duration, 40000 ) ;
1723
+ assert_eq ! ( info. duration, 512 ) ;
1745
1724
assert_eq ! ( info. media_time, 0 ) ;
1746
1725
1747
1726
assert_eq ! ( Mp4parseStatus :: Ok , unsafe {
1748
1727
mp4parse_get_track_info( parser, 1 , & mut info)
1749
1728
} ) ;
1750
1729
assert_eq ! ( info. track_type, Mp4parseTrackType :: Audio ) ;
1751
1730
assert_eq ! ( info. track_id, 2 ) ;
1752
- assert_eq ! ( info. duration, 61333 ) ;
1753
- assert_eq ! ( info. media_time, 21333 ) ;
1731
+ assert_eq ! ( info. duration, 2944 ) ;
1732
+ assert_eq ! ( info. media_time, 1024 ) ;
1754
1733
1755
1734
unsafe {
1756
1735
mp4parse_free ( parser) ;
0 commit comments