From d6f6f1a7778cf975a2309e77b3b91b852444cd2d Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 16 Jun 2021 23:43:30 +0200 Subject: [PATCH] cea608overlay: expose "black-background" property As stated in the spec: > In addition, the user must have the capability to select a black > background over which the captioned letters are displaced. The property is MUTABLE_PLAYING --- video/closedcaption/src/cea608overlay/imp.rs | 54 ++++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/video/closedcaption/src/cea608overlay/imp.rs b/video/closedcaption/src/cea608overlay/imp.rs index 612d6f3a..c9ea5a22 100644 --- a/video/closedcaption/src/cea608overlay/imp.rs +++ b/video/closedcaption/src/cea608overlay/imp.rs @@ -39,16 +39,19 @@ static CAT: Lazy = Lazy::new(|| { }); const DEFAULT_FIELD: i32 = -1; +const DEFAULT_BLACK_BACKGROUND: bool = false; #[derive(Debug)] struct Settings { field: i32, + black_background: bool, } impl Default for Settings { fn default() -> Self { Settings { field: DEFAULT_FIELD, + black_background: DEFAULT_BLACK_BACKGROUND, } } } @@ -150,6 +153,13 @@ impl Cea608Overlay { font_size += 1; } + if self.settings.lock().unwrap().black_background { + let attrs = pango::AttrList::new(); + let attr = pango::Attribute::new_background(0, 0, 0); + attrs.insert(attr); + layout.set_attributes(Some(&attrs)); + } + state.left_alignment = left_alignment; state.layout = Some(layout); @@ -306,7 +316,7 @@ impl Cea608Overlay { state.attach = upstream_has_meta || downstream_accepts_meta; - self.recalculate_layout(element, state)?; + let _ = state.layout.take(); if !self.srcpad.push_event(gst::event::Caps::new(&caps)) { Err(gst::FlowError::NotNegotiated) @@ -435,6 +445,10 @@ impl Cea608Overlay { self.negotiate(element, &mut state)?; } + if state.layout.is_none() { + self.recalculate_layout(element, &mut state)?; + } + for meta in buffer.iter_meta::() { if meta.caption_type() == gst_video::VideoCaptionType::Cea708Cdp { match extract_cdp(meta.data()) { @@ -578,15 +592,24 @@ impl ObjectSubclass for Cea608Overlay { impl ObjectImpl for Cea608Overlay { fn properties() -> &'static [glib::ParamSpec] { static PROPERTIES: Lazy> = Lazy::new(|| { - vec![glib::ParamSpec::new_int( - "field", - "Field", - "The field to render the caption for when available, (-1=automatic)", - -1, - 1, - DEFAULT_FIELD, - glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, - )] + vec![ + glib::ParamSpec::new_int( + "field", + "Field", + "The field to render the caption for when available, (-1=automatic)", + -1, + 1, + DEFAULT_FIELD, + glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, + ), + glib::ParamSpec::new_boolean( + "black-background", + "Black background", + "Whether a black background should be drawn behind text", + DEFAULT_BLACK_BACKGROUND, + glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, + ), + ] }); PROPERTIES.as_ref() @@ -610,6 +633,13 @@ impl ObjectImpl for Cea608Overlay { val => Some(val as u8), }; } + "black-background" => { + let mut settings = self.settings.lock().unwrap(); + let mut state = self.state.lock().unwrap(); + + settings.black_background = value.get().expect("type checked upstream"); + let _ = state.layout.take(); + } _ => unimplemented!(), } } @@ -620,6 +650,10 @@ impl ObjectImpl for Cea608Overlay { let settings = self.settings.lock().unwrap(); settings.field.to_value() } + "black-background" => { + let settings = self.settings.lock().unwrap(); + settings.black_background.to_value() + } _ => unimplemented!(), } }