From 3a32790159fec76a916bb004a26ba275eea240dd Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Fri, 11 Feb 2022 16:27:01 +0100 Subject: [PATCH] transcriberbin: always cycle transcriber state on passthrough Users may want to restart the transcriber, for instance AWS transcribe has a 4-hour limit and it may be desirable to start a new session before that deadline by toggling passthrough on and immediately off. --- video/closedcaption/src/transcriberbin/imp.rs | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/video/closedcaption/src/transcriberbin/imp.rs b/video/closedcaption/src/transcriberbin/imp.rs index 0b804eb4..f1e4dd5f 100644 --- a/video/closedcaption/src/transcriberbin/imp.rs +++ b/video/closedcaption/src/transcriberbin/imp.rs @@ -258,27 +258,40 @@ impl TranscriberBin { if let Some(ref mut state) = state.as_mut() { state.tearing_down = false; + gst_debug!(CAT, obj: element, "disabling transcription bin"); + + let bin_sink_pad = state.transcription_bin.static_pad("sink").unwrap(); + if let Some(audio_tee_pad) = bin_sink_pad.peer() { + audio_tee_pad.unlink(&bin_sink_pad).unwrap(); + state.audio_tee.release_request_pad(&audio_tee_pad); + } + + let bin_src_pad = state.transcription_bin.static_pad("src").unwrap(); + if let Some(cccombiner_pad) = bin_src_pad.peer() { + bin_src_pad.unlink(&cccombiner_pad).unwrap(); + state.cccombiner.release_request_pad(&cccombiner_pad); + } + + state.transcription_bin.set_locked_state(true); + state.transcription_bin.set_state(gst::State::Null).unwrap(); + // At this point, we want to check whether passthrough // has been unset in the meantime let passthrough = self.settings.lock().unwrap().passthrough; - if passthrough { - gst_debug!(CAT, obj: element, "disabling transcription bin"); + if !passthrough { + gst_debug!(CAT, obj: element, "reenabling transcription bin"); - let bin_sink_pad = state.transcription_bin.static_pad("sink").unwrap(); - if let Some(audio_tee_pad) = bin_sink_pad.peer() { - audio_tee_pad.unlink(&bin_sink_pad).unwrap(); - state.audio_tee.release_request_pad(&audio_tee_pad); - } - - let bin_src_pad = state.transcription_bin.static_pad("src").unwrap(); - if let Some(cccombiner_pad) = bin_src_pad.peer() { - bin_src_pad.unlink(&cccombiner_pad).unwrap(); - state.cccombiner.release_request_pad(&cccombiner_pad); - } + let audio_tee_pad = state.audio_tee.request_pad_simple("src_%u").unwrap(); + let transcription_sink_pad = state.transcription_bin.static_pad("sink").unwrap(); + audio_tee_pad.link(&transcription_sink_pad).unwrap(); - state.transcription_bin.set_locked_state(true); - state.transcription_bin.set_state(gst::State::Null).unwrap(); + state + .transcription_bin + .link_pads(Some("src"), &state.cccombiner, Some("caption")) + .unwrap(); + state.transcription_bin.set_locked_state(false); + state.transcription_bin.sync_state_with_parent().unwrap(); } } } @@ -287,7 +300,10 @@ impl TranscriberBin { let mut s = self.state.lock().unwrap(); if let Some(ref mut state) = s.as_mut() { - if passthrough { + if state.tearing_down { + // Do nothing, wait for the previous transcription bin + // to finish tearing down + } else if passthrough { let sinkpad = state.transcription_bin.static_pad("sink").unwrap(); let element_weak = element.downgrade(); state.tearing_down = true; @@ -309,10 +325,9 @@ impl TranscriberBin { gst::PadProbeReturn::Remove }, ); - } else if state.tearing_down { - // Do nothing, wait for the previous transcription bin - // to finish tearing down } else { + gst_debug!(CAT, obj: element, "enabling transcription bin"); + let audio_tee_pad = state.audio_tee.request_pad_simple("src_%u").unwrap(); let transcription_sink_pad = state.transcription_bin.static_pad("sink").unwrap(); audio_tee_pad.link(&transcription_sink_pad).unwrap(); -- GitLab