Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>2023-10-25 01:00:53 +0300
committerJan Alexander Steffens (heftig) <jan.steffens@ltnglobal.com>2023-10-25 12:52:40 +0300
commit6567041a3d2948685368920954eabf0f26d0c0f6 (patch)
treea8fc896af27abba3d383f91b86cb88cf9ba04b98 /utils
parent0a45f776e0a38b994b3e49bab390c64602f2de8b (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/1369>
Diffstat (limited to 'utils')
-rw-r--r--utils/livesync/src/livesync/imp.rs43
1 files changed, 24 insertions, 19 deletions
diff --git a/utils/livesync/src/livesync/imp.rs b/utils/livesync/src/livesync/imp.rs
index 418862dbb..15e922ee2 100644
--- a/utils/livesync/src/livesync/imp.rs
+++ b/utils/livesync/src/livesync/imp.rs
@@ -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()