Skip to content

Commit 1eaaa49

Browse files
committed
core: convert pts to i64
1 parent 9bd9ba6 commit 1eaaa49

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

symphonia-core/src/formats/mod.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub struct Packet {
485485
/// this timestamp is relative to the end of the encoder delay.
486486
///
487487
/// This timestamp is in `TimeBase` units.
488-
pub pts: u64,
488+
pub pts: i64,
489489
/// The decoding timestamp (DTS) of the packet. Primarily used for video packets and is typically different
490490
/// from the PTS. Can be negative. For audio packets, the DTS is always equal to the PTS
491491
///
@@ -511,7 +511,7 @@ impl Packet {
511511
pub fn new_from_slice(track_id: u32, pts: u64, dur: u64, buf: &[u8]) -> Self {
512512
Packet {
513513
track_id,
514-
pts,
514+
pts: pts as i64,
515515
dts: pts as i64,
516516
dur,
517517
trim_start: 0,
@@ -522,13 +522,13 @@ impl Packet {
522522

523523
/// Create a new `Packet` from a boxed slice.
524524
pub fn new_from_boxed_slice(track_id: u32, pts: u64, dur: u64, data: Box<[u8]>) -> Self {
525-
Packet { track_id, pts, dts: pts as i64, dur, trim_start: 0, trim_end: 0, data }
525+
Packet { track_id, pts: pts as i64, dts: pts as i64, dur, trim_start: 0, trim_end: 0, data }
526526
}
527527

528528
/// Create a new `Packet` from a boxed slice.
529529
pub fn new_from_boxed_slice_v(
530530
track_id: u32,
531-
pts: u64,
531+
pts: i64,
532532
dts: i64,
533533
dur: u64,
534534
data: Box<[u8]>,
@@ -545,7 +545,15 @@ impl Packet {
545545
trim_end: u32,
546546
buf: &[u8],
547547
) -> Self {
548-
Packet { track_id, pts, dts: pts as i64, dur, trim_start, trim_end, data: Box::from(buf) }
548+
Packet {
549+
track_id,
550+
pts: pts as i64,
551+
dts: pts as i64,
552+
dur,
553+
trim_start,
554+
trim_end,
555+
data: Box::from(buf),
556+
}
549557
}
550558

551559
/// Create a new `Packet` with trimming information from a boxed slice.
@@ -557,7 +565,7 @@ impl Packet {
557565
trim_end: u32,
558566
data: Box<[u8]>,
559567
) -> Self {
560-
Packet { track_id, pts, dts: pts as i64, dur, trim_start, trim_end, data }
568+
Packet { track_id, pts: pts as i64, dts: pts as i64, dur, trim_start, trim_end, data }
561569
}
562570

563571
/// The track identifier of the track this packet belongs to.
@@ -569,7 +577,7 @@ impl Packet {
569577
///
570578
/// For audio packets, when gapless support is enabled,
571579
/// this timestamp is relative to the end of the encoder delay.
572-
pub fn pts(&self) -> u64 {
580+
pub fn pts(&self) -> i64 {
573581
self.pts
574582
}
575583

@@ -752,21 +760,21 @@ pub mod util {
752760
/// Given a `Packet`, the encoder delay in frames, and the number of non-delay or padding
753761
/// frames, adjust the packet's timestamp and duration, and populate the trim information.
754762
pub fn trim_packet(packet: &mut Packet, delay: u32, num_frames: Option<u64>) {
755-
packet.trim_start = if packet.pts < u64::from(delay) {
756-
let trim = (u64::from(delay) - packet.pts).min(packet.dur);
763+
packet.trim_start = if packet.pts < i64::from(delay) {
764+
let trim = (delay as u64 - packet.pts as u64).min(packet.dur);
757765
packet.pts = 0;
758766
packet.dts = 0;
759767
packet.dur -= trim;
760768
trim as u32
761769
}
762770
else {
763-
packet.pts -= u64::from(delay);
771+
packet.pts -= i64::from(delay);
764772
0
765773
};
766774

767775
if let Some(num_frames) = num_frames {
768-
packet.trim_end = if packet.pts + packet.dur > num_frames {
769-
let trim = (packet.pts + packet.dur - num_frames).min(packet.dur);
776+
packet.trim_end = if packet.pts as u64 + packet.dur > num_frames {
777+
let trim = (packet.pts as u64 + packet.dur - num_frames).min(packet.dur);
770778
packet.dur -= trim;
771779
trim as u32
772780
}

symphonia-format-ogg/src/demuxer.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ impl<'s> OggReader<'s> {
249249
let actual_ts = loop {
250250
match self.peek_logical_packet() {
251251
Some(packet) => {
252-
if packet.track_id() == serial && packet.pts + packet.dur >= required_ts {
253-
break packet.pts;
252+
if packet.track_id() == serial && packet.pts as u64 + packet.dur >= required_ts
253+
{
254+
break packet.pts as u64;
254255
}
255256

256257
self.discard_logical_packet();

symphonia-format-ogg/src/logical.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ impl LogicalStream {
198198

199199
for packet in self.packets.iter_mut().rev().take(num_new_packets) {
200200
page_dur = page_dur.saturating_add(packet.dur);
201-
packet.pts = page_end_ts.saturating_sub(page_dur);
202-
packet.dts = packet.pts as i64;
201+
packet.pts = page_end_ts.saturating_sub(page_dur) as i64;
202+
packet.dts = packet.pts;
203203
}
204204

205205
if self.gapless {

symphonia-play/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ fn play_track(
470470
// should be decoded and *samples* discarded up-to the exact *sample* indicated by
471471
// required_ts. The current approach will discard extra samples if seeking to a
472472
// sample within a packet.
473-
if packet.pts() >= opts.seek_ts {
473+
if packet.pts() as u64 >= opts.seek_ts {
474474
if !opts.no_progress {
475-
ui::print_progress(packet.pts(), dur, tb);
475+
ui::print_progress(packet.pts() as u64, dur, tb);
476476
}
477477

478478
if let Some(audio_output) = audio_output {

0 commit comments

Comments
 (0)