Skip to content

Commit 4ba1e25

Browse files
committed
core: add dts to packet for video
1 parent ddbd12f commit 4ba1e25

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

symphonia-core/src/formats/mod.rs

+42-9
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,16 @@ fn matches_track_type(track: &Track, track_type: TrackType) -> bool {
481481
pub struct Packet {
482482
/// The track ID.
483483
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.
486486
///
487487
/// This timestamp is in `TimeBase` units.
488488
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,
489494
/// The duration of the packet. When gapless support is enabled, the duration does not include
490495
/// the encoder delay or padding.
491496
///
@@ -504,12 +509,31 @@ pub struct Packet {
504509
impl Packet {
505510
/// Create a new `Packet` from a slice.
506511
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+
}
508521
}
509522

510523
/// Create a new `Packet` from a boxed slice.
511524
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 }
513537
}
514538

515539
/// Create a new `Packet` with trimming information from a slice.
@@ -521,7 +545,7 @@ impl Packet {
521545
trim_end: u32,
522546
buf: &[u8],
523547
) -> 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) }
525549
}
526550

527551
/// Create a new `Packet` with trimming information from a boxed slice.
@@ -533,22 +557,30 @@ impl Packet {
533557
trim_end: u32,
534558
data: Box<[u8]>,
535559
) -> 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 }
537561
}
538562

539563
/// The track identifier of the track this packet belongs to.
540564
pub fn track_id(&self) -> u32 {
541565
self.track_id
542566
}
543567

544-
/// Get the presentation timestamp of the packet in `TimeBase` units.
568+
/// Get the presentation timestamp (PTS) of the packet in `TimeBase` units.
545569
///
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.
548572
pub fn pts(&self) -> u64 {
549573
self.pts
550574
}
551575

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+
552584
/// Get the duration of the packet in `TimeBase` units.
553585
///
554586
/// If gapless support is enabled, then this is the duration after the encoder delay and padding
@@ -723,6 +755,7 @@ pub mod util {
723755
packet.trim_start = if packet.pts < u64::from(delay) {
724756
let trim = (u64::from(delay) - packet.pts).min(packet.dur);
725757
packet.pts = 0;
758+
packet.dts = 0;
726759
packet.dur -= trim;
727760
trim as u32
728761
}

symphonia-format-ogg/src/logical.rs

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ impl LogicalStream {
199199
for packet in self.packets.iter_mut().rev().take(num_new_packets) {
200200
page_dur = page_dur.saturating_add(packet.dur);
201201
packet.pts = page_end_ts.saturating_sub(page_dur);
202+
packet.dts = packet.pts as i64;
202203
}
203204

204205
if self.gapless {

0 commit comments

Comments
 (0)