Packet::with_pts/with_duration builders
Browse files at this commitffd766f14e59c2e395d222df4e6b9030ef4afc13Parent: 1f445c1- feat
- Packet::with_pts/with_duration builders
1 changed file +14 -2
- crates/ec-core/src/packet.rs +14 -2
crates/ec-core/src/packet.rsmodified+14 -2
| @@ -184,6 +184,19 @@ impl Packet { | ||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 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 | + | |
| 187 | 200 | /// `pts + duration`, when both are known. |
| 188 | 201 | pub fn end_pts(&self) -> Option<i64> { |
| 189 | 202 | self.pts?.checked_add(self.duration?) |
| @@ -225,8 +238,7 @@ mod tests { | ||
| 225 | 238 | let mut p = Packet::new(0, tb, vec![0xff; 4]); |
| 226 | 239 | assert!(!p.is_keyframe()); |
| 227 | 240 | 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); | |
| 230 | 242 | p.flags.keyframe = true; |
| 231 | 243 | p.side_data |
| 232 | 244 | .push(SideData::CodecConfig(Buf::copy_from_slice(&[0x12, 0x10]))); |