gstreamer/clock: Add ClockID::wait_async_stream()

This provides an async stream with the values of each timeout.
This commit is contained in:
Sebastian Dröge 2020-10-01 10:13:52 +03:00
parent 4120ded424
commit c01f7072fb

View file

@ -25,6 +25,9 @@ use ClockSuccess;
use ClockTime;
use ClockTimeDiff;
use futures_core::Stream;
use std::marker::Unpin;
use std::pin::Pin;
use std::sync::atomic;
use std::sync::atomic::AtomicI32;
@ -102,6 +105,24 @@ impl ClockId {
ret.into_result()
}
#[allow(clippy::type_complexity)]
pub fn wait_async_stream(
&self,
) -> Result<
Pin<Box<dyn Stream<Item = (ClockTime, ClockId)> + Unpin + Send + 'static>>,
ClockError,
> {
use futures_channel::mpsc;
let (sender, receiver) = mpsc::unbounded();
self.wait_async(move |_clock, jitter, id| {
let _ = sender.unbounded_send((jitter, id.clone()));
})?;
Ok(Box::pin(receiver))
}
pub fn compare_by_time(&self, other: &Self) -> cmp::Ordering {
unsafe {
let res =