From ffd766f14e59c2e395d222df4e6b9030ef4afc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 14 Aug 2026 09:00:52 +0300 Subject: [PATCH] feat(core): Packet::with_pts/with_duration builders The Ogg shim's caller builds a packet in one expression; these are the two setters that chain. --- crates/ec-core/src/packet.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/ec-core/src/packet.rs b/crates/ec-core/src/packet.rs index 9c93fca7..b91892d6 100644 --- a/crates/ec-core/src/packet.rs +++ b/crates/ec-core/src/packet.rs @@ -184,6 +184,19 @@ impl Packet { } } + /// Set the presentation timestamp, for the callers that build a packet in + /// one expression. + pub fn with_pts(mut self, pts: i64) -> Packet { + self.pts = Some(pts); + self + } + + /// Set the duration in `time_base` ticks. + pub fn with_duration(mut self, duration: i64) -> Packet { + self.duration = Some(duration); + self + } + /// `pts + duration`, when both are known. pub fn end_pts(&self) -> Option { self.pts?.checked_add(self.duration?) @@ -225,8 +238,7 @@ mod tests { let mut p = Packet::new(0, tb, vec![0xff; 4]); assert!(!p.is_keyframe()); assert_eq!(p.end_pts(), None); - p.pts = Some(1024); - p.duration = Some(1024); + p = p.with_pts(1024).with_duration(1024); p.flags.keyframe = true; p.side_data .push(SideData::CodecConfig(Buf::copy_from_slice(&[0x12, 0x10])));