pub struct Sink(/* private fields */);Expand description
A Decoder confined to one thread, driven from anywhere.
Same shape as Decoder, except that
decode is async and takes its payload by value (it may
cross a thread). Reach for this instead of a Decoder whenever the decoder
outlives a single thread’s stack: a spawned task, an object shared across
threads, an FFI handle. A Decoder you build, drive, and drop inside one
function needs none of it.
Consumer is built on one, so a caller reading a
subscribed track from a task already gets this and needs nothing here.
§Cancellation
Not cancel-safe, and it says so rather than letting it slide. A queued decode
runs whether or not anyone is still waiting, so dropping the future (racing it
in a select!, giving it a timeout) leaves the decoder a step ahead of the
stream, holding frames nobody received. Rather than let the next call carry on
against a decoder that has moved, the sink refuses every call after a
cancelled one. Drop it and open another.
macOS never refuses, because there is no thread to run ahead: the decoder runs inline, so a dropped future either had not started the call or had already finished it. Write to the contract above regardless, or the same code loses frames off macOS.
Implementations§
Source§impl Sink
impl Sink
Sourcepub async fn open(catalog: &VideoConfig, config: &Config) -> Result<Self, Error>
pub async fn open(catalog: &VideoConfig, config: &Config) -> Result<Self, Error>
Open a decoder for catalog on its own thread. Returns once the decoder
is built (or its construction fails), so an unsupported codec surfaces
here rather than on the first frame.
Sourcepub async fn decode(
&mut self,
payload: Bytes,
timestamp: Timestamp,
keyframe: bool,
) -> Result<Vec<Frame>, Error>
pub async fn decode( &mut self, payload: Bytes, timestamp: Timestamp, keyframe: bool, ) -> Result<Vec<Frame>, Error>
Decode one access unit, waiting for whatever pictures it yields.
Otherwise Decoder::decode: zero or more frames,
since a backend that reorders holds pictures back. payload is a Bytes,
so handing it over is a refcount rather than a copy.