Skip to main content

openipc_video/api/
decoder.rs

1use super::{
2    CodecConfig, DecodedFrame, DecodedSurface, DecoderCapabilities, DecoderStats,
3    EncodedAccessUnit, VideoError,
4};
5
6/// Result of offering an access unit to a low-latency decoder.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum SubmitOutcome {
9    /// Frame was accepted by the platform decoder.
10    Submitted,
11    /// Parameter sets have not yet formed a complete decoder configuration.
12    WaitingForConfiguration,
13    /// Decoder was reconfigured and accepted this frame.
14    Reconfigured,
15    /// A delta frame was intentionally skipped until the next keyframe.
16    WaitingForKeyframe,
17    /// Decoder queue was full and the frame was dropped.
18    DroppedForBackpressure,
19}
20
21/// Common behavior implemented by platform video decoders.
22pub trait VideoDecoder {
23    /// Native decoded surface type produced by this backend.
24    type Surface: DecodedSurface;
25
26    /// Query decoder support on the current machine.
27    fn capabilities(&self) -> DecoderCapabilities;
28
29    /// Explicitly configure or reconfigure the platform decoder.
30    fn configure(&mut self, config: CodecConfig) -> Result<(), VideoError>;
31
32    /// Submit one complete encoded Annex-B access unit.
33    fn submit(&mut self, frame: EncodedAccessUnit) -> Result<SubmitOutcome, VideoError>;
34
35    /// Take the newest decoded frame, if one is ready.
36    fn latest_frame(&mut self) -> Option<DecodedFrame<Self::Surface>>;
37
38    /// Clear decoder state and queued work.
39    ///
40    /// Native backends finish work when their platform API supports a
41    /// synchronous drain. WebCodecs closes immediately; use
42    /// `WebDecoder::flush_async` when browser output must be drained first.
43    fn flush(&mut self) -> Result<(), VideoError>;
44
45    /// Read cumulative decoder statistics.
46    fn stats(&self) -> DecoderStats;
47}