From e1cd52178edb795a82e1c5f92091413f9d14ac0d Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 12 Dec 2023 14:20:43 +1100 Subject: [PATCH] transcriberbin: also support 608 inside 708 Part-of: --- docs/plugins/gst_plugins_cache.json | 17 +++++++++- video/closedcaption/src/transcriberbin/imp.rs | 33 +++++++++---------- video/closedcaption/src/transcriberbin/mod.rs | 14 +++++++- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/docs/plugins/gst_plugins_cache.json b/docs/plugins/gst_plugins_cache.json index 09c9e8df..50f43130 100644 --- a/docs/plugins/gst_plugins_cache.json +++ b/docs/plugins/gst_plugins_cache.json @@ -5566,7 +5566,7 @@ "mux-method": { "blurb": "The method for muxing multiple transcription streams", "conditionally-available": false, - "construct": false, + "construct": true, "construct-only": false, "controllable": false, "default": "cea608 (0)", @@ -5906,6 +5906,21 @@ } ] }, + "GstTranscriberBinMuxMethod": { + "kind": "enum", + "values": [ + { + "desc": "Cea608", + "name": "cea608", + "value": "0" + }, + { + "desc": "Cea708", + "name": "cea708", + "value": "1" + } + ] + }, "GstTtToCea608Mode": { "kind": "enum", "values": [ diff --git a/video/closedcaption/src/transcriberbin/imp.rs b/video/closedcaption/src/transcriberbin/imp.rs index 5ebf4969..7b85b946 100644 --- a/video/closedcaption/src/transcriberbin/imp.rs +++ b/video/closedcaption/src/transcriberbin/imp.rs @@ -17,7 +17,7 @@ use std::sync::Mutex; use once_cell::sync::Lazy; -use super::CaptionSource; +use super::{CaptionSource, MuxMethod}; static CAT: Lazy = Lazy::new(|| { gst::DebugCategory::new( @@ -38,15 +38,6 @@ const DEFAULT_MUX_METHOD: MuxMethod = MuxMethod::Cea608; const CEAX08MUX_LATENCY: gst::ClockTime = gst::ClockTime::from_mseconds(100); -#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, glib::Enum)] -#[repr(u32)] -#[enum_type(name = "GstTranscriberBinMuxMethod")] -enum MuxMethod { - #[default] - Cea608, - Cea708, -} - /* One per language, including original */ struct TranscriptionChannel { bin: gst::Bin, @@ -176,7 +167,14 @@ impl TranscriberBin { "Multiple CEA-608 streams for a language are not supported" ); } - cea608_channel = Some(cea608.parse::()?); + let channel = cea608.parse::()?; + if (1..=4).contains(&channel) { + cea608_channel = Some(channel); + } else { + anyhow::bail!( + "CEA-608 channels only support values between 1 and 4 inclusive" + ); + } } else if let Some(cea708_service) = cc.strip_prefix("708_") { if service_no.is_some() { anyhow::bail!( @@ -191,13 +189,12 @@ impl TranscriberBin { } } let service_no = service_no.ok_or(anyhow!("No 708 caption service provided"))?; - // TODO: handle cea608 - ( - gst::ElementFactory::make("tttocea708") - .property("service-number", service_no) - .build()?, - format!("sink_{}", service_no), - ) + let mut builder = + gst::ElementFactory::make("tttocea708").property("service-number", service_no); + if let Some(channel) = cea608_channel { + builder = builder.property("cea608-channel", channel); + } + (builder.build()?, format!("sink_{}", service_no)) } }; let capsfilter = gst::ElementFactory::make("capsfilter").build()?; diff --git a/video/closedcaption/src/transcriberbin/mod.rs b/video/closedcaption/src/transcriberbin/mod.rs index 618becb7..0d115e02 100644 --- a/video/closedcaption/src/transcriberbin/mod.rs +++ b/video/closedcaption/src/transcriberbin/mod.rs @@ -20,13 +20,25 @@ pub enum CaptionSource { Inband, } +#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, glib::Enum)] +#[repr(u32)] +#[enum_type(name = "GstTranscriberBinMuxMethod")] +enum MuxMethod { + #[default] + Cea608, + Cea708, +} + glib::wrapper! { pub struct TranscriberBin(ObjectSubclass) @extends gst::Bin, gst::Element, gst::Object; } pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> { #[cfg(feature = "doc")] - CaptionSource::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty()); + { + CaptionSource::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty()); + MuxMethod::static_type().mark_as_plugin_api(gst::PluginAPIFlags::empty()); + } gst::Element::register( Some(plugin),