diff options
author | Mathieu Duponchelle <mathieu@centricular.com> | 2021-02-10 23:18:13 +0300 |
---|---|---|
committer | GStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-02-15 22:25:18 +0300 |
commit | 20607fe3465e1b2f2524e1a0e733cc06230b1704 (patch) | |
tree | 4c5601659af0cf216f0e5e624b89100f99858abc | |
parent | 126df546c052f679c681cbaa00eb6df60bc222f4 (diff) |
tttocea608: expose origin-column and origin-row properties
These can be controlled more precisely using json as the input
format, but exposing them as properties is still useful when
the input format is text.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/474>
-rw-r--r-- | video/closedcaption/src/tttocea608/imp.rs | 92 |
1 files changed, 76 insertions, 16 deletions
diff --git a/video/closedcaption/src/tttocea608/imp.rs b/video/closedcaption/src/tttocea608/imp.rs index d0af74e2c..50be30821 100644 --- a/video/closedcaption/src/tttocea608/imp.rs +++ b/video/closedcaption/src/tttocea608/imp.rs @@ -94,15 +94,23 @@ const DEFAULT_FPS_N: i32 = 30; const DEFAULT_FPS_D: i32 = 1; const DEFAULT_MODE: Cea608Mode = Cea608Mode::RollUp2; +const DEFAULT_ORIGIN_ROW: i32 = -1; +const DEFAULT_ORIGIN_COLUMN: u32 = 0; #[derive(Debug, Clone)] struct Settings { mode: Cea608Mode, + origin_row: i32, + origin_column: u32, } impl Default for Settings { fn default() -> Self { - Settings { mode: DEFAULT_MODE } + Settings { + mode: DEFAULT_MODE, + origin_row: DEFAULT_ORIGIN_ROW, + origin_column: DEFAULT_ORIGIN_COLUMN, + } } } @@ -455,7 +463,7 @@ impl TtToCea608 { Cea608Mode::RollUp2 | Cea608Mode::RollUp3 | Cea608Mode::RollUp4 => { if let Some(carriage_return) = carriage_return { if carriage_return { - *col = 0; + *col = self.settings.lock().unwrap().origin_column; state.carriage_return(element, bufferlist); true } else { @@ -572,7 +580,7 @@ impl TtToCea608 { Cea608Mode::RollUp2 | Cea608Mode::RollUp3 | Cea608Mode::RollUp4 => { state.send_roll_up_preamble = true; } - _ => col = 0, + _ => col = self.settings.lock().unwrap().origin_column, } } } @@ -584,7 +592,7 @@ impl TtToCea608 { if state.mode != Cea608Mode::PopOn && state.mode != Cea608Mode::PaintOn { state.send_roll_up_preamble = true; } - col = 0; + col = self.settings.lock().unwrap().origin_column; } } @@ -624,7 +632,7 @@ impl TtToCea608 { } col = line_column; } else if state.mode == Cea608Mode::PopOn || state.mode == Cea608Mode::PaintOn { - col = 0; + col = self.settings.lock().unwrap().origin_column; } for (j, chunk) in line.chunks.iter().enumerate() { @@ -818,7 +826,15 @@ impl TtToCea608 { })?; let phrases: Vec<&str> = data.split('\n').collect(); - let mut row = (std::cmp::max(0, 15 - phrases.len())) as u32; + let mut row = match settings.origin_row { + -1 => match settings.mode { + Cea608Mode::PopOn | Cea608Mode::PaintOn => { + 15u32.saturating_sub(phrases.len() as u32) + } + Cea608Mode::RollUp2 | Cea608Mode::RollUp3 | Cea608Mode::RollUp4 => 14, + }, + _ => settings.origin_row as u32, + }; for phrase in &phrases { lines.lines.push(Line { @@ -831,7 +847,9 @@ impl TtToCea608 { text: phrase.to_string(), }], }); - row += 1; + if settings.mode == Cea608Mode::PopOn || settings.mode == Cea608Mode::PaintOn { + row += 1; + } } } true => { @@ -994,14 +1012,34 @@ impl ObjectSubclass for TtToCea608 { impl ObjectImpl for TtToCea608 { fn properties() -> &'static [glib::ParamSpec] { static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| { - vec![glib::ParamSpec::enum_( - "mode", - "Mode", - "Which mode to operate in", - Cea608Mode::static_type(), - DEFAULT_MODE as i32, - glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, - )] + vec![ + glib::ParamSpec::enum_( + "mode", + "Mode", + "Which mode to operate in", + Cea608Mode::static_type(), + DEFAULT_MODE as i32, + glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, + ), + glib::ParamSpec::int( + "origin-row", + "Origin row", + "Origin row, (-1=automatic)", + -1, + 14, + DEFAULT_ORIGIN_ROW, + glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, + ), + glib::ParamSpec::uint( + "origin-column", + "Origin column", + "Origin column", + 0, + 31, + DEFAULT_ORIGIN_COLUMN, + glib::ParamFlags::READWRITE | gst::PARAM_FLAG_MUTABLE_PLAYING, + ), + ] }); PROPERTIES.as_ref() @@ -1029,6 +1067,18 @@ impl ObjectImpl for TtToCea608 { .expect("type checked upstream"); self.state.lock().unwrap().force_clear = true; } + "origin-row" => { + let mut settings = self.settings.lock().unwrap(); + settings.origin_row = value.get_some().expect("type checked upstream"); + self.state.lock().unwrap().force_clear = true; + } + "origin-column" => { + let mut settings = self.settings.lock().unwrap(); + settings.origin_column = value.get_some().expect("type checked upstream"); + let mut state = self.state.lock().unwrap(); + state.force_clear = true; + state.column = settings.origin_column; + } _ => unimplemented!(), } } @@ -1039,6 +1089,14 @@ impl ObjectImpl for TtToCea608 { let settings = self.settings.lock().unwrap(); settings.mode.to_value() } + "origin-row" => { + let settings = self.settings.lock().unwrap(); + settings.origin_row.to_value() + } + "origin-column" => { + let settings = self.settings.lock().unwrap(); + settings.origin_column.to_value() + } _ => unimplemented!(), } } @@ -1115,11 +1173,13 @@ impl ElementImpl for TtToCea608 { match transition { gst::StateChange::ReadyToPaused => { let mut state = self.state.lock().unwrap(); + let settings = self.settings.lock().unwrap(); *state = State::default(); state.force_clear = false; - state.mode = self.settings.lock().unwrap().mode; + state.mode = settings.mode; if state.mode != Cea608Mode::PopOn { state.send_roll_up_preamble = true; + state.column = settings.origin_column; } } _ => (), |