diff options
author | Mathieu Duponchelle <mathieu@centricular.com> | 2021-02-10 19:01:32 +0300 |
---|---|---|
committer | GStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-02-15 22:25:18 +0300 |
commit | 75170e5162f6d3a9a9bca0ba8a4c0591e0110b15 (patch) | |
tree | f9faadc7a7fbd4565faa1fe12fef40720fdd0c86 | |
parent | ab251ec5736620efbed67d87f90410719a160eb1 (diff) |
textwrap: use the lines property in accumulate mode too
In that mode, textwrap accumulates and pushs out lines of text
up to accumulate-time. We can still make use of the lines property
in that mode, and accumulate as many lines of text as specified.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/474>
-rw-r--r-- | text/wrap/src/gsttextwrap/imp.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/text/wrap/src/gsttextwrap/imp.rs b/text/wrap/src/gsttextwrap/imp.rs index 9c381cfdd..083ae66b2 100644 --- a/text/wrap/src/gsttextwrap/imp.rs +++ b/text/wrap/src/gsttextwrap/imp.rs @@ -180,6 +180,7 @@ impl TextWrap { if accumulate_time.is_some() { let mut bufferlist = gst::BufferList::new(); + let n_lines = std::cmp::max(self.settings.lock().unwrap().lines, 1); if state.end_ts.is_some() && state.end_ts + accumulate_time < buffer.get_pts() { let mut buf = gst::Buffer::from_mut_slice( @@ -220,14 +221,31 @@ impl TextWrap { .expect("We should have a wrapper by now"); let lines = textwrap::wrap(¤t_text, options); - let len = lines.len(); + let mut chunks = lines.chunks(n_lines as usize).peekable(); let mut trailing = "".to_string(); - for (i, line) in lines.iter().enumerate() { - if i + 1 == len { - trailing = line.to_string(); + while let Some(chunk) = chunks.next() { + if chunks.peek().is_none() { + trailing = chunk + .iter() + .map(|l| l.to_string()) + .collect::<Vec<String>>() + .join("\n"); } else { - let mut buf = gst::Buffer::from_mut_slice(line.to_string().into_bytes()); + let contents = chunk + .iter() + .map(|l| l.to_string()) + .collect::<Vec<String>>() + .join("\n"); + gst_info!( + CAT, + obj: element, + "Outputting contents {}, ts: {}, duration: {}", + contents.to_string(), + state.start_ts, + state.end_ts - state.start_ts + ); + let mut buf = gst::Buffer::from_mut_slice(contents.into_bytes()); { let buf_mut = buf.get_mut().unwrap(); buf_mut.set_pts(state.start_ts); @@ -280,6 +298,7 @@ impl TextWrap { let data = chunk.join("\n"); let duration: gst::ClockTime = duration_per_word * data.split_whitespace().count() as u64; + gst_info!(CAT, "Pushing lines {}", data); let mut buf = gst::Buffer::from_mut_slice(data.into_bytes()); { |