From db8e1da65d5fbf8ec5db32fa2df33f9ac8723fb0 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Wed, 11 Dec 2024 22:22:30 +1100 Subject: [PATCH] cea708overlay: clear more things on caption timeout Part-of: --- video/closedcaption/src/cea608utils.rs | 9 +++++++ video/closedcaption/src/cea708overlay/imp.rs | 2 ++ video/closedcaption/src/cea708utils.rs | 28 +++++++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/video/closedcaption/src/cea608utils.rs b/video/closedcaption/src/cea608utils.rs index e34fca71..3540444e 100644 --- a/video/closedcaption/src/cea608utils.rs +++ b/video/closedcaption/src/cea608utils.rs @@ -774,4 +774,13 @@ impl Cea608Renderer { self.rectangle = Some(rect.clone()); Some(rect) } + + pub fn clear(&mut self) { + self.state.reset(); + let channel = self.channel(); + self.frame.reset(); + if let Some(channel) = channel { + self.set_channel(channel); + } + } } diff --git a/video/closedcaption/src/cea708overlay/imp.rs b/video/closedcaption/src/cea708overlay/imp.rs index 6e5a603e..a6cefbe9 100644 --- a/video/closedcaption/src/cea708overlay/imp.rs +++ b/video/closedcaption/src/cea708overlay/imp.rs @@ -241,6 +241,7 @@ impl Cea708Overlay { } state.cea708_renderer.push_service(service); + self.reset_timeout(state, pts); } } @@ -296,6 +297,7 @@ impl Cea708Overlay { } fn reset_timeout(&self, state: &mut State, pts: gst::ClockTime) { + gst::trace!(CAT, "resetting timeout to {pts:?}"); state.last_cc_pts = Some(pts); } diff --git a/video/closedcaption/src/cea708utils.rs b/video/closedcaption/src/cea708utils.rs index 03b12847..73547629 100644 --- a/video/closedcaption/src/cea708utils.rs +++ b/video/closedcaption/src/cea708utils.rs @@ -399,6 +399,10 @@ impl Cea708Renderer { pub fn clear_composition(&mut self) { self.composition.take(); + if let Some(service) = self.service.as_mut() { + service.clear(); + } + self.cea608.clear(); } pub fn generate_composition(&mut self) -> Option { @@ -583,6 +587,14 @@ impl ServiceState { *self = Self::new(); } + fn clear(&mut self) { + for window in self.windows.iter_mut() { + window.lines.clear(); + window.pen_location = SetPenLocationArgs::default(); + window.rectangle.take(); + } + } + fn handle_code(&mut self, code: &Code) { match code { Code::DefineWindow(args) => self.define_window(args), @@ -1297,13 +1309,17 @@ impl Window { } }; - let buffer = match render_buffer() { - Ok(buffer) => buffer, - Err(e) => { - self.dump(); - gst::error!(CAT, "Failed to render buffer: \"{e}\""); - return None; + let buffer = if width > 0 && height > 0 { + match render_buffer() { + Ok(buffer) => buffer, + Err(e) => { + self.dump(); + gst::error!(CAT, "Failed to render buffer: \"{e}\""); + return None; + } } + } else { + return None; }; gst::trace!( CAT,