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>
This commit is contained in:
Jan Alexander Steffens (heftig) 2023-10-25 00:00:53 +02:00 committed by Sebastian Dröge
parent 7a70863152
commit ab84da6d32

View file

@ -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()