mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-18 05:45:14 +00:00
livesync: Keep existing buffer duration in some cases
Resize a repeat buffer only if caps gave us a duration to use, or we
consider its current duration unreasonable.
In particular, for audio streams we should prefer reusing the buffer
size upstream gave us, as we did before 6633cc4046
.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1372>
This commit is contained in:
parent
59beade079
commit
f1ba498b52
1 changed files with 31 additions and 24 deletions
|
@ -1302,6 +1302,13 @@ impl LiveSync {
|
||||||
let buffer = out_buffer.make_mut();
|
let buffer = out_buffer.make_mut();
|
||||||
|
|
||||||
if !duplicate {
|
if !duplicate {
|
||||||
|
let duration_is_valid =
|
||||||
|
(MINIMUM_DURATION..=MAXIMUM_DURATION).contains(&buffer.duration().unwrap());
|
||||||
|
|
||||||
|
if state.out_duration.is_some() || !duration_is_valid {
|
||||||
|
// Resize the buffer if caps gave us a duration
|
||||||
|
// or the current duration is unreasonable
|
||||||
|
|
||||||
let duration = state.out_duration.map_or(DEFAULT_DURATION, |dur| {
|
let duration = state.out_duration.map_or(DEFAULT_DURATION, |dur| {
|
||||||
dur.clamp(MINIMUM_DURATION, MAXIMUM_DURATION)
|
dur.clamp(MINIMUM_DURATION, MAXIMUM_DURATION)
|
||||||
});
|
});
|
||||||
|
@ -1316,24 +1323,24 @@ impl LiveSync {
|
||||||
return Err(gst::FlowError::Error);
|
return Err(gst::FlowError::Error);
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut mapped_memory = gst::Memory::with_size(size)
|
buffer.replace_all_memory(gst::Memory::with_size(size));
|
||||||
.into_mapped_memory_writable()
|
|
||||||
.map_err(|_| {
|
|
||||||
gst::error!(CAT, imp: self, "Failed to map memory");
|
|
||||||
gst::FlowError::Error
|
|
||||||
})?;
|
|
||||||
|
|
||||||
audio_info
|
|
||||||
.format_info()
|
|
||||||
.fill_silence(mapped_memory.as_mut_slice());
|
|
||||||
|
|
||||||
buffer.replace_all_memory(mapped_memory.into_memory());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.set_duration(duration);
|
buffer.set_duration(duration);
|
||||||
gst::debug!(CAT, imp: self, "Patched output buffer duration to {duration}");
|
gst::debug!(CAT, imp: self, "Patched output buffer duration to {duration}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(audio_info) = &state.out_audio_info {
|
||||||
|
let mut map_info = buffer.map_writable().map_err(|e| {
|
||||||
|
gst::error!(CAT, imp: self, "Failed to map buffer: {}", e);
|
||||||
|
gst::FlowError::Error
|
||||||
|
})?;
|
||||||
|
audio_info
|
||||||
|
.format_info()
|
||||||
|
.fill_silence(map_info.as_mut_slice());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
buffer.set_dts(dts);
|
buffer.set_dts(dts);
|
||||||
buffer.set_pts(pts);
|
buffer.set_pts(pts);
|
||||||
buffer.set_flags(gst::BufferFlags::GAP);
|
buffer.set_flags(gst::BufferFlags::GAP);
|
||||||
|
|
Loading…
Reference in a new issue