@@ -481,11 +481,16 @@ fn matches_track_type(track: &Track, track_type: TrackType) -> bool {
481
481
pub struct Packet {
482
482
/// The track ID.
483
483
track_id : u32 ,
484
- /// The presentation timestamp of the packet. When gapless support is enabled, this timestamp is relative to
485
- /// the end of the encoder delay.
484
+ /// The presentation timestamp (PTS) of the packet. For audio packets, when gapless support is enabled,
485
+ /// this timestamp is relative to the end of the encoder delay.
486
486
///
487
487
/// This timestamp is in `TimeBase` units.
488
488
pub pts : u64 ,
489
+ /// The decoding timestamp (DTS) of the packet. Primarily used for video packets and is typically different
490
+ /// from the PTS. Can be negative. For audio packets, the DTS is always equal to the PTS
491
+ ///
492
+ /// This timestamp is in `TimeBase` units.
493
+ pub dts : i64 ,
489
494
/// The duration of the packet. When gapless support is enabled, the duration does not include
490
495
/// the encoder delay or padding.
491
496
///
@@ -504,12 +509,31 @@ pub struct Packet {
504
509
impl Packet {
505
510
/// Create a new `Packet` from a slice.
506
511
pub fn new_from_slice ( track_id : u32 , pts : u64 , dur : u64 , buf : & [ u8 ] ) -> Self {
507
- Packet { track_id, pts, dur, trim_start : 0 , trim_end : 0 , data : Box :: from ( buf) }
512
+ Packet {
513
+ track_id,
514
+ pts,
515
+ dts : pts as i64 ,
516
+ dur,
517
+ trim_start : 0 ,
518
+ trim_end : 0 ,
519
+ data : Box :: from ( buf) ,
520
+ }
508
521
}
509
522
510
523
/// Create a new `Packet` from a boxed slice.
511
524
pub fn new_from_boxed_slice ( track_id : u32 , pts : u64 , dur : u64 , data : Box < [ u8 ] > ) -> Self {
512
- Packet { track_id, pts, dur, trim_start : 0 , trim_end : 0 , data }
525
+ Packet { track_id, pts, dts : pts as i64 , dur, trim_start : 0 , trim_end : 0 , data }
526
+ }
527
+
528
+ /// Create a new `Packet` from a boxed slice.
529
+ pub fn new_from_boxed_slice_v (
530
+ track_id : u32 ,
531
+ pts : u64 ,
532
+ dts : i64 ,
533
+ dur : u64 ,
534
+ data : Box < [ u8 ] > ,
535
+ ) -> Self {
536
+ Packet { track_id, pts, dts, dur, trim_start : 0 , trim_end : 0 , data }
513
537
}
514
538
515
539
/// Create a new `Packet` with trimming information from a slice.
@@ -521,7 +545,7 @@ impl Packet {
521
545
trim_end : u32 ,
522
546
buf : & [ u8 ] ,
523
547
) -> Self {
524
- Packet { track_id, pts, dur, trim_start, trim_end, data : Box :: from ( buf) }
548
+ Packet { track_id, pts, dts : pts as i64 , dur, trim_start, trim_end, data : Box :: from ( buf) }
525
549
}
526
550
527
551
/// Create a new `Packet` with trimming information from a boxed slice.
@@ -533,22 +557,30 @@ impl Packet {
533
557
trim_end : u32 ,
534
558
data : Box < [ u8 ] > ,
535
559
) -> Self {
536
- Packet { track_id, pts, dur, trim_start, trim_end, data }
560
+ Packet { track_id, pts, dts : pts as i64 , dur, trim_start, trim_end, data }
537
561
}
538
562
539
563
/// The track identifier of the track this packet belongs to.
540
564
pub fn track_id ( & self ) -> u32 {
541
565
self . track_id
542
566
}
543
567
544
- /// Get the presentation timestamp of the packet in `TimeBase` units.
568
+ /// Get the presentation timestamp (PTS) of the packet in `TimeBase` units.
545
569
///
546
- /// If gapless support is enabled, then this timestamp is relative to the end of the encoder
547
- /// delay.
570
+ /// For audio packets, when gapless support is enabled,
571
+ /// this timestamp is relative to the end of the encoder delay.
548
572
pub fn pts ( & self ) -> u64 {
549
573
self . pts
550
574
}
551
575
576
+ /// Get the decoding timestamp (DTS) of the packet in `TimeBase` units.
577
+ ///
578
+ /// Primarily used for video packets and is typically different
579
+ /// from the PTS. Can be negative. For audio packets, the DTS is always equal to the PTS
580
+ pub fn dts ( & self ) -> i64 {
581
+ self . dts
582
+ }
583
+
552
584
/// Get the duration of the packet in `TimeBase` units.
553
585
///
554
586
/// If gapless support is enabled, then this is the duration after the encoder delay and padding
@@ -723,6 +755,7 @@ pub mod util {
723
755
packet. trim_start = if packet. pts < u64:: from ( delay) {
724
756
let trim = ( u64:: from ( delay) - packet. pts ) . min ( packet. dur ) ;
725
757
packet. pts = 0 ;
758
+ packet. dts = 0 ;
726
759
packet. dur -= trim;
727
760
trim as u32
728
761
}
0 commit comments