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
This commit is contained in:
Mathieu Duponchelle 2021-06-16 23:43:30 +02:00 committed by Sebastian Dröge
parent d15e97efb8
commit d6f6f1a777

View file

@ -39,16 +39,19 @@ static CAT: Lazy<gst::DebugCategory> = 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::<gst_video::VideoCaptionMeta>() {
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<Vec<glib::ParamSpec>> = 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!(),
}
}