mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-12-23 02:26:35 +00:00
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>
This commit is contained in:
parent
ab251ec573
commit
75170e5162
1 changed files with 24 additions and 5 deletions
|
@ -180,6 +180,7 @@ impl TextWrap {
|
||||||
|
|
||||||
if accumulate_time.is_some() {
|
if accumulate_time.is_some() {
|
||||||
let mut bufferlist = gst::BufferList::new();
|
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() {
|
if state.end_ts.is_some() && state.end_ts + accumulate_time < buffer.get_pts() {
|
||||||
let mut buf = gst::Buffer::from_mut_slice(
|
let mut buf = gst::Buffer::from_mut_slice(
|
||||||
|
@ -220,14 +221,31 @@ impl TextWrap {
|
||||||
.expect("We should have a wrapper by now");
|
.expect("We should have a wrapper by now");
|
||||||
|
|
||||||
let lines = textwrap::wrap(¤t_text, options);
|
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();
|
let mut trailing = "".to_string();
|
||||||
|
|
||||||
for (i, line) in lines.iter().enumerate() {
|
while let Some(chunk) = chunks.next() {
|
||||||
if i + 1 == len {
|
if chunks.peek().is_none() {
|
||||||
trailing = line.to_string();
|
trailing = chunk
|
||||||
|
.iter()
|
||||||
|
.map(|l| l.to_string())
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join("\n");
|
||||||
} else {
|
} 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();
|
let buf_mut = buf.get_mut().unwrap();
|
||||||
buf_mut.set_pts(state.start_ts);
|
buf_mut.set_pts(state.start_ts);
|
||||||
|
@ -280,6 +298,7 @@ impl TextWrap {
|
||||||
let data = chunk.join("\n");
|
let data = chunk.join("\n");
|
||||||
let duration: gst::ClockTime =
|
let duration: gst::ClockTime =
|
||||||
duration_per_word * data.split_whitespace().count() as u64;
|
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());
|
let mut buf = gst::Buffer::from_mut_slice(data.into_bytes());
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue