mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 02:26:35 +00:00
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/1369>
This commit is contained in:
parent
0a45f776e0
commit
6567041a3d
1 changed files with 24 additions and 19 deletions
|
@ -850,20 +850,31 @@ 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 Some(calc_duration) = audio_info
|
||||
.convert::<Option<gst::ClockTime>>(gst::format::Bytes::from_usize(buf_mut.size()))
|
||||
.flatten()
|
||||
{
|
||||
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,
|
||||
|
@ -871,16 +882,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
|
||||
|
@ -905,11 +915,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()
|
||||
|
|
Loading…
Reference in a new issue