diff options
author | François Laignel <fengalin@free.fr> | 2021-06-04 20:06:24 +0300 |
---|---|---|
committer | François Laignel <fengalin@free.fr> | 2021-06-05 11:36:21 +0300 |
commit | e16cad7c8f4000ab5b1d649e54b8d6f8e19cf154 (patch) | |
tree | 4dfa96ee5452d77320399452e3d87d9f56217a7a /video/webp | |
parent | c2de0649a736fde8435434e0e6483c5ad96fdfe2 (diff) |
video: migrate to new ClockTime design
Diffstat (limited to 'video/webp')
-rw-r--r-- | video/webp/src/dec/imp.rs | 9 | ||||
-rw-r--r-- | video/webp/tests/webpdec.rs | 8 |
2 files changed, 10 insertions, 7 deletions
diff --git a/video/webp/src/dec/imp.rs b/video/webp/src/dec/imp.rs index 88729e4be..d5ad0e376 100644 --- a/video/webp/src/dec/imp.rs +++ b/video/webp/src/dec/imp.rs @@ -169,7 +169,7 @@ impl WebPDec { } fn decode(&self, _element: &super::WebPDec) -> Result<(), gst::ErrorMessage> { - let mut prev_timestamp: gst::ClockTime = 0.into(); + let mut prev_timestamp: Option<gst::ClockTime> = Some(gst::ClockTime::ZERO); let mut state = self.state.lock().unwrap(); if state.buffers.is_empty() { @@ -223,8 +223,9 @@ impl WebPDec { gst::error_msg!(gst::StreamError::Decode, ["Failed to get next frame"]) })?; - let timestamp = frame.timestamp as u64 * gst::MSECOND; - let duration = timestamp - prev_timestamp; + let timestamp = frame.timestamp as u64 * gst::ClockTime::MSECOND; + let duration = + prev_timestamp.and_then(|prev_timestamp| timestamp.checked_sub(prev_timestamp)); let mut out_buf = gst::Buffer::with_size((info.width * info.height * 4) as usize).unwrap(); @@ -235,7 +236,7 @@ impl WebPDec { out_buf_mut.set_duration(duration); } - prev_timestamp = timestamp; + prev_timestamp = Some(timestamp); match self.srcpad.push(out_buf) { Ok(_) => (), diff --git a/video/webp/tests/webpdec.rs b/video/webp/tests/webpdec.rs index 24edec9c4..6dfb04656 100644 --- a/video/webp/tests/webpdec.rs +++ b/video/webp/tests/webpdec.rs @@ -40,15 +40,17 @@ fn test_decode() { assert_eq!(h.push(buf), Ok(gst::FlowSuccess::Ok)); h.push_event(gst::event::Eos::new()); - let mut expected_timestamp: gst::ClockTime = 0.into(); + let mut expected_timestamp: Option<gst::ClockTime> = Some(gst::ClockTime::ZERO); let mut count = 0; - let expected_duration: gst::ClockTime = 40_000_000.into(); + let expected_duration: Option<gst::ClockTime> = Some(gst::ClockTime::from_nseconds(40_000_000)); while let Some(buf) = h.try_pull() { assert_eq!(buf.pts(), expected_timestamp); assert_eq!(buf.duration(), expected_duration); - expected_timestamp += expected_duration; + expected_timestamp = expected_timestamp + .zip(expected_duration) + .map(|(ts, duration)| ts + duration); count += 1; } |