diff options
author | François Laignel <francois@centricular.com> | 2023-02-28 19:38:20 +0300 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2023-03-01 11:47:58 +0300 |
commit | f1a080c94e5ec4c5b9f21b1606dd507ccd34cea5 (patch) | |
tree | c3867e5df44fe258993c6b820bf86c3a96f3fc06 /net/aws | |
parent | 36ae29d7465e62b0c1f08b713597898074356726 (diff) |
net/aws/transcriber: own transcription items
So that we can avoid copying the content.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1104>
Diffstat (limited to 'net/aws')
-rw-r--r-- | net/aws/src/transcriber/imp.rs | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/net/aws/src/transcriber/imp.rs b/net/aws/src/transcriber/imp.rs index ae766615..63f1c0e3 100644 --- a/net/aws/src/transcriber/imp.rs +++ b/net/aws/src/transcriber/imp.rs @@ -299,7 +299,12 @@ impl Transcriber { /// Enqueues a buffer for each of the provided stable items. /// /// Returns `true` if at least one buffer was enqueued. - fn enqueue(&self, items: &[model::Item], partial: bool, lateness: gst::ClockTime) -> bool { + fn enqueue( + &self, + mut items: Vec<model::Item>, + partial: bool, + lateness: gst::ClockTime, + ) -> bool { let mut state = self.state.lock().unwrap(); if items.len() <= state.partial_index { @@ -320,12 +325,12 @@ impl Transcriber { let mut enqueued = false; - for item in &items[state.partial_index..] { + for item in items.drain(state.partial_index..) { if !item.stable().unwrap_or(false) { break; } - let Some(content) = item.content() else { continue }; + let Some(content) = item.content else { continue }; let start_time = ((item.start_time * 1_000_000_000.0) as u64).nseconds() + lateness; let end_time = ((item.end_time * 1_000_000_000.0) as u64).nseconds() + lateness; @@ -337,7 +342,7 @@ impl Transcriber { "Item is ready for queuing: {content}, PTS {start_time}", ); - let mut buf = gst::Buffer::from_mut_slice(content.to_string().into_bytes()); + let mut buf = gst::Buffer::from_mut_slice(content.into_bytes()); { let buf = buf.get_mut().unwrap(); @@ -825,9 +830,8 @@ impl Transcriber { if let Some(result) = transcript_evt .transcript - .as_ref() - .and_then(|transcript| transcript.results()) - .and_then(|results| results.get(0)) + .and_then(|transcript| transcript.results) + .and_then(|mut results| results.drain(..).next()) { let Some(imp) = imp_weak.upgrade() else { break }; @@ -835,10 +839,9 @@ impl Transcriber { if let Some(alternative) = result .alternatives - .as_ref() - .and_then(|alternatives| alternatives.get(0)) + .and_then(|mut alternatives| alternatives.drain(..).next()) { - if let Some(items) = alternative.items() { + if let Some(items) = alternative.items { enqueued = imp.enqueue(items, result.is_partial, lateness); } } |