forge
Explore
Log in

Don't you dare go Hollow

Packet::with_pts/with_duration builders

Browse files at this commit

ffd766f14e59c2e395d222df4e6b9030ef4afc13Ahmet Kaan GümüşParent: 1f445c1
  • feat
    • Packet::with_pts/with_duration builders
Show full message
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.rsmodified+14 -2
@@ -184,6 +184,19 @@ impl Packet {
184184 }
185185 }
186186
187+ /// Set the presentation timestamp, for the callers that build a packet in
188+ /// one expression.
189+ pub fn with_pts(mut self, pts: i64) -> Packet {
190+ self.pts = Some(pts);
191+ self
192+ }
193+
194+ /// Set the duration in `time_base` ticks.
195+ pub fn with_duration(mut self, duration: i64) -> Packet {
196+ self.duration = Some(duration);
197+ self
198+ }
199+
187200 /// `pts + duration`, when both are known.
188201 pub fn end_pts(&self) -> Option<i64> {
189202 self.pts?.checked_add(self.duration?)
@@ -225,8 +238,7 @@ mod tests {
225238 let mut p = Packet::new(0, tb, vec![0xff; 4]);
226239 assert!(!p.is_keyframe());
227240 assert_eq!(p.end_pts(), None);
228- p.pts = Some(1024);
229- p.duration = Some(1024);
241+ p = p.with_pts(1024).with_duration(1024);
230242 p.flags.keyframe = true;
231243 p.side_data
232244 .push(SideData::CodecConfig(Buf::copy_from_slice(&[0x12, 0x10])));