textwrap: Don't panic on empty buffers

Simply don't calculate with any duration per word for this buffer.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/990>
This commit is contained in:
Sebastian Dröge 2022-11-28 18:44:04 +02:00 committed by GStreamer Marge Bot
parent 5bbe0eab25
commit 76eeaffbb2

View file

@ -176,8 +176,8 @@ impl TextWrap {
state.end_ts = None;
}
let duration_per_word: gst::ClockTime =
duration / data.split_whitespace().count() as u64;
let num_words = data.split_whitespace().count() as u64;
let duration_per_word = (num_words != 0).then(|| duration / num_words);
if state.start_ts.is_none() {
state.start_ts = buffer.pts();