diff options
author | Jan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com> | 2023-10-25 01:00:53 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2023-11-10 18:47:41 +0300 |
commit | ab84da6d325e08734f6d79e7890a68e39c9903fd (patch) | |
tree | 41fcec32784ca05fe593abbe002a7fce127ce941 | |
parent | 7a708631527a508dd39164433832dfd24ed2038d (diff) |
livesync: Improve audio duration fixups
- An entirely missing duration is now only logged at debug level instead
of pretending the duration was zero and warning about it.
- Silently fix up a duration difference up to one sample.
- Error when we fail to calculate the duration; don't try to apply the
`fallback_duration` to a non-video stream.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1387>
-rw-r--r-- | utils/livesync/src/livesync/imp.rs | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/utils/livesync/src/livesync/imp.rs b/utils/livesync/src/livesync/imp.rs index 0ea08d0dd..a031bca95 100644 --- a/utils/livesync/src/livesync/imp.rs +++ b/utils/livesync/src/livesync/imp.rs @@ -852,20 +852,33 @@ impl LiveSync { } if let Some(audio_info) = &state.in_audio_info { - let buf_duration = buf_mut.duration().unwrap_or_default(); - if let Some(calc_duration) = audio_info - .convert::<Option<gst::ClockTime>>(Some(gst::format::Bytes::from_usize( - buf_mut.size(), - ))) + let calc_duration = if let Some(calc_duration) = audio_info + .convert::<Option<gst::ClockTime>>(gst::format::Bytes::from_usize(buf_mut.size())) .flatten() { + calc_duration + } else { + gst::error!( + CAT, + imp: self, + "Failed to calculate duration of {:?}", + buf_mut, + ); + return Err(gst::FlowError::Error); + }; + + if let Some(buf_duration) = buf_mut.duration() { let diff = if buf_duration < calc_duration { calc_duration - buf_duration } else { buf_duration - calc_duration }; - if diff.nseconds() > 1 { + let sample_duration = gst::ClockTime::SECOND + .mul_div_round(1, audio_info.rate().into()) + .unwrap(); + + if diff > sample_duration { gst::warning!( CAT, imp: self, @@ -873,16 +886,15 @@ impl LiveSync { buf_duration, calc_duration, ); - buf_mut.set_duration(calc_duration); } } else { - gst::debug!( - CAT, - imp: self, - "Failed to calculate duration of {:?}", - buf_mut, - ); + gst::debug!(CAT, imp: self, "Incoming buffer without duration"); } + + buf_mut.set_duration(calc_duration); + } else if buf_mut.duration().is_none() { + gst::debug!(CAT, imp: self, "Incoming buffer without duration"); + buf_mut.set_duration(state.fallback_duration); } // At this stage we should really really have a segment @@ -907,11 +919,6 @@ impl LiveSync { buf_mut.set_pts(pts.map(|t| t + state.latency)); } - if buf_mut.duration().is_none() { - gst::debug!(CAT, imp: self, "Incoming buffer without duration"); - buf_mut.set_duration(Some(state.fallback_duration)); - } - if state .out_buffer .as_ref() |