From 6633cc4046aa1f5a22ba8e1ee39a101b9b9559c5 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Wed, 25 Oct 2023 12:11:01 +0200 Subject: livesync: Use fallback_duration for audio repeat buffers as well Don't depend on upstream giving us sanely-sized buffers if we want to repeat. Part-of: --- utils/livesync/src/livesync/imp.rs | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'utils') diff --git a/utils/livesync/src/livesync/imp.rs b/utils/livesync/src/livesync/imp.rs index 80730971b..f2732f639 100644 --- a/utils/livesync/src/livesync/imp.rs +++ b/utils/livesync/src/livesync/imp.rs @@ -1304,19 +1304,34 @@ impl LiveSync { let buffer = out_buffer.make_mut(); if !duplicate { + let duration = state.fallback_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 - })?; + let Some(size) = audio_info + .convert::>(duration) + .flatten() + .and_then(|bytes| usize::try_from(bytes).ok()) + else { + gst::error!(CAT, imp: self, "Failed to calculate size of repeat buffer"); + return Err(gst::FlowError::Error); + }; + + let mut mapped_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(map_info.as_mut_slice()); - } else { - let duration = state.fallback_duration; - buffer.set_duration(duration); - gst::debug!(CAT, imp: self, "Patched output buffer duration to {duration}"); + .fill_silence(mapped_memory.as_mut_slice()); + + buffer.replace_all_memory(mapped_memory.into_memory()); } + + buffer.set_duration(duration); + gst::debug!(CAT, imp: self, "Patched output buffer duration to {duration}"); } buffer.set_dts(dts); -- cgit v1.2.3