aws_transcriber: sanity check alternative length

The design of the element is based on the assumption that when
receiving a partial result, the following result will contain
at least as many items as there were stable items in the previous
result.

This patch adds a sanity check to make sure our "partial index"
isn't larger than the new received result, and errors out otherwise.

partial_index will eventually be reset to 0 once we receive a
new non-partial result.
This commit is contained in:
Mathieu Duponchelle 2021-11-24 13:57:15 +01:00 committed by Sebastian Dröge
parent 3cf2ad3b77
commit 97e6a89cac

View file

@ -379,6 +379,22 @@ impl Transcriber {
) {
let lateness = self.settings.lock().unwrap().lateness;
if alternative.items.len() <= state.partial_index {
gst_error!(
CAT,
obj: element,
"sanity check failed, alternative length {} < partial_index {}",
alternative.items.len(),
state.partial_index
);
if !partial {
state.partial_index = 0;
}
return;
}
for item in &alternative.items[state.partial_index..] {
let start_time =
gst::ClockTime::from_nseconds((item.start_time as f64 * 1_000_000_000.0) as u64)