pub trait VideoDecoder: Send {
// Required methods
fn submit(
&mut self,
sample: &EncodedVideoSample,
cancellation: &CancellationToken,
) -> Result<Vec<DecodedVideoFrame>>;
fn drain(
&mut self,
cancellation: &CancellationToken,
) -> Result<Vec<DecodedVideoFrame>>;
fn reset(&mut self) -> Result<()>;
// Provided method
fn set_output_wanted(&mut self, _wanted: bool) { ... }
}Expand description
A stateful video decoder that may retain reference and reorder state.
Requires Send so an ExactFrameReader (and the decoder it owns) can be moved to a
background thread, which native examples rely on to decode without stalling rendering.
Required Methods§
fn submit( &mut self, sample: &EncodedVideoSample, cancellation: &CancellationToken, ) -> Result<Vec<DecodedVideoFrame>>
fn drain( &mut self, cancellation: &CancellationToken, ) -> Result<Vec<DecodedVideoFrame>>
fn reset(&mut self) -> Result<()>
Provided Methods§
Sourcefn set_output_wanted(&mut self, _wanted: bool)
fn set_output_wanted(&mut self, _wanted: bool)
Whether the caller wants the pictures the next samples decode to, or is only decoding them because a later frame references them.
Reaching a frame in the middle of a long group of pictures means decoding every sample before it, and on the way there nothing looks at those pictures. What they cost is not the decoding: a hardware backend hands back NV12 and every one of these decoders then converts a whole picture to RGBA on the CPU and allocates the frame that holds it. On the bundled 1080p sample that conversion is 6.6 ms of the 9.6 ms a frame takes through VideoToolbox, so a seek that skips it for the frames it passes costs a third of what it did.
A decoder must still decode a suppressed sample - the frames after it reference the
picture - and must still account for its presentation identity; what it may skip is
producing the DecodedVideoFrame, which it reports by returning fewer frames than it
was given samples.
The default implementation ignores the hint, which is always correct: a decoder that
keeps producing every frame is a decoder that is merely no faster. ExactFrameReader
tracks what it was actually handed rather than what it asked for, so a backend that
implements this and one that does not answer the same frames.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".