From 4284fe953a8254a9a23f8c7d559ffd2d58591cc8 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Tue, 5 Nov 2024 18:51:20 +0100 Subject: [PATCH] transcriberbin: expose lateness property Directly mapped to the lateness property on the transcriber object. Part-of: --- docs/plugins/gst_plugins_cache.json | 14 +++++++++ video/closedcaption/src/transcriberbin/imp.rs | 29 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index edc6b65c..4a244161 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -7735,6 +7735,20 @@ "type": "guint", "writable": true }, + "lateness": { + "blurb": "Amount of milliseconds to pass as lateness to the transcriber", + "conditionally-available": false, + "construct": false, + "construct-only": false, + "controllable": false, + "default": "0", + "max": "-1", + "min": "0", + "mutable": "ready", + "readable": true, + "type": "guint", + "writable": true + }, "mode": { "blurb": "Which closed caption mode to operate in", "conditionally-available": false, diff --git a/video/closedcaption/src/transcriberbin/imp.rs b/video/closedcaption/src/transcriberbin/imp.rs index a896ed5d..3639b8d9 100644 --- a/video/closedcaption/src/transcriberbin/imp.rs +++ b/video/closedcaption/src/transcriberbin/imp.rs @@ -29,6 +29,7 @@ static CAT: LazyLock = LazyLock::new(|| { const DEFAULT_PASSTHROUGH: bool = false; const DEFAULT_LATENCY: gst::ClockTime = gst::ClockTime::from_seconds(4); +const DEFAULT_LATENESS: gst::ClockTime = gst::ClockTime::from_seconds(0); const DEFAULT_TRANSLATE_LATENCY: gst::ClockTime = gst::ClockTime::from_mseconds(500); const DEFAULT_ACCUMULATE: gst::ClockTime = gst::ClockTime::ZERO; const DEFAULT_MODE: Cea608Mode = Cea608Mode::RollUp2; @@ -100,6 +101,7 @@ struct State { struct Settings { cc_caps: gst::Caps, latency: gst::ClockTime, + lateness: gst::ClockTime, translate_latency: gst::ClockTime, accumulate_time: gst::ClockTime, caption_source: CaptionSource, @@ -113,6 +115,7 @@ impl Default for Settings { .field("format", "raw") .build(), latency: DEFAULT_LATENCY, + lateness: DEFAULT_LATENESS, translate_latency: DEFAULT_TRANSLATE_LATENCY, accumulate_time: DEFAULT_ACCUMULATE, caption_source: DEFAULT_CAPTION_SOURCE, @@ -517,16 +520,20 @@ impl TranscriberBin { if let Some(ref transcriber) = pad_state.transcriber { let latency_ms = settings.latency.mseconds() as u32; - if transcriber.has_property("transcribe-latency", None) { + if transcriber.has_property("transcribe-latency", Some(u32::static_type())) { transcriber.set_property("transcribe-latency", latency_ms); - } else if transcriber.has_property("latency", None) { + } else if transcriber.has_property("latency", Some(u32::static_type())) { transcriber.set_property("latency", latency_ms); } - if transcriber.has_property("translate-latency", None) { + if transcriber.has_property("translate-latency", Some(u32::static_type())) { let translate_latency_ms = settings.translate_latency.mseconds() as u32; transcriber.set_property("translate-latency", translate_latency_ms); } + if transcriber.has_property("lateness", Some(u32::static_type())) { + let lateness_ms = settings.lateness.mseconds() as u32; + transcriber.set_property("lateness", lateness_ms); + } } pad_state .queue_passthrough @@ -1372,6 +1379,12 @@ impl ObjectImpl for TranscriberBin { .default_value(DEFAULT_LATENCY.mseconds() as u32) .mutable_ready() .build(), + glib::ParamSpecUInt::builder("lateness") + .nick("Lateness") + .blurb("Amount of milliseconds to pass as lateness to the transcriber") + .default_value(DEFAULT_LATENESS.mseconds() as u32) + .mutable_ready() + .build(), glib::ParamSpecUInt::builder("accumulate-time") .nick("accumulate-time") .blurb("Cut-off time for textwrap accumulation, in milliseconds (0=do not accumulate). \ @@ -1439,6 +1452,12 @@ impl ObjectImpl for TranscriberBin { value.get::().expect("type checked upstream").into(), ); } + "lateness" => { + let mut settings = self.settings.lock().unwrap(); + settings.lateness = gst::ClockTime::from_mseconds( + value.get::().expect("type checked upstream").into(), + ); + } "accumulate-time" => { let mut settings = self.settings.lock().unwrap(); settings.accumulate_time = gst::ClockTime::from_mseconds( @@ -1516,6 +1535,10 @@ impl ObjectImpl for TranscriberBin { let settings = self.settings.lock().unwrap(); (settings.latency.mseconds() as u32).to_value() } + "lateness" => { + let settings = self.settings.lock().unwrap(); + (settings.lateness.mseconds() as u32).to_value() + } "accumulate-time" => { let settings = self.settings.lock().unwrap(); (settings.accumulate_time.mseconds() as u32).to_value()