From ebcb8f220b3b5e681d781e04ff12df63d595977a Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 26 Feb 2025 18:24:57 +0100 Subject: [PATCH] transcriberbin: fix cea608mux start time selection cea608mux is set to force-live=true, which means it will not wait for a first buffer to select a start time. There was however a problem when manually syncing the state of its containing bin as we do: when doing so while the state of the containing bin is still transitioning to Playing, the element first gets a 0 base time distributed, before its containing bin finally gets the correct base time and redistributes it. In this interval cea608mux could pick a start time, then end up waiting for ever to timeout. This commit works around the issue by simply unlocking the state of the inner bins but not syncing it when in Paused, as the subsequent state change to Playing, if it happens, will trigger the state change of the elements anyway. Part-of: --- video/closedcaption/src/transcriberbin/imp.rs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/video/closedcaption/src/transcriberbin/imp.rs b/video/closedcaption/src/transcriberbin/imp.rs index 2ce4f8a9..fd1c4287 100644 --- a/video/closedcaption/src/transcriberbin/imp.rs +++ b/video/closedcaption/src/transcriberbin/imp.rs @@ -848,8 +848,17 @@ impl TranscriberBin { .link_pads(Some("src"), &state.cccombiner, Some("caption")) .unwrap(); + // We don't need to sync below playing as the state is now unlocked + // and the bin will transition when necessary. + // + // Trying to sync in PAUSED was causing issues with base time distribution, + // with cea608mux selecting an incorrect start time. + let do_sync = self.obj().current_state() == gst::State::Playing; + state.transcription_bin.set_locked_state(false); - state.transcription_bin.sync_state_with_parent().unwrap(); + if do_sync { + state.transcription_bin.sync_state_with_parent().unwrap(); + } for pad in state.audio_sink_pads.values() { let ps = pad.imp().state.lock().unwrap(); @@ -858,10 +867,14 @@ impl TranscriberBin { if !pad_settings.passthrough { pad_state.transcription_bin.set_locked_state(false); - pad_state - .transcription_bin - .sync_state_with_parent() - .unwrap(); + + if do_sync { + pad_state + .transcription_bin + .sync_state_with_parent() + .unwrap(); + } + let transcription_sink_pad = state.transcription_bin.static_pad(&pad.name()).unwrap(); // Might be linked already if "translation-languages" is set