pub struct Sink(/* private fields */);Expand description
A Decoder confined to one thread, driven from anywhere.
Same shape as Decoder, except that
decode and flush are async and decode
takes its payload by value (it may cross a thread). receive
stays synchronous: each decode and flush has already moved what the codec
readied to this side. 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 request
runs whether or not anyone is still waiting, so dropping the future (racing it
in a select!, giving it a timeout) can leave the decoder a step ahead of the
caller. 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.
Apple platforms never refuse, 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 elsewhere.
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<(), Error>
pub async fn decode( &mut self, payload: Bytes, timestamp: Timestamp, keyframe: bool, ) -> Result<(), Error>
Submit one access unit, waiting until the codec has taken it.
Otherwise Decoder::decode: its pictures come out
of receive, zero or more of them, since a backend that
reorders holds pictures back. payload is a Bytes, so handing it over
is a refcount rather than a copy.