euv_core/media/video/trait.rs
1use super::*;
2
3/// Pluggable hardware or software video decoder backend interface.
4#[cfg(not(target_arch = "wasm32"))]
5pub trait VideoDecoderBackend: Send {
6 /// Returns the backend identifier (`VideoToolbox`, `MediaCodec`, `Vaapi`, `Dxva`, `WebCodecs`, or `SoftwareFallback`).
7 ///
8 /// # Arguments
9 ///
10 /// - `&Self` - Decoder backend reference.
11 ///
12 /// # Returns
13 ///
14 /// - `HardwareDecoderKind` - Active backend kind.
15 fn backend_kind(&self) -> HardwareDecoderKind;
16
17 /// Reports codec, resolution, HDR, and zero-copy capabilities supported by this backend.
18 ///
19 /// # Arguments
20 ///
21 /// - `&Self` - Decoder backend reference.
22 ///
23 /// # Returns
24 ///
25 /// - `HardwareDecoderCapabilities` - Backend capability descriptor.
26 fn capabilities(&self) -> HardwareDecoderCapabilities;
27
28 /// Configures or reconfigures the decoder for a video track descriptor.
29 ///
30 /// # Arguments
31 ///
32 /// - `&Self` - Mutable decoder backend.
33 /// - `&VideoDecoderConfig` - Track dimensions, codec, and color/HDR metadata.
34 ///
35 /// # Returns
36 ///
37 /// - `Result<(), String>` - `Ok(())` on successful initialization or descriptive error.
38 fn configure(&mut self, config: &VideoDecoderConfig) -> Result<(), String>;
39
40 /// Decodes a single demuxed packet into an optional decoded video frame backed by GPU surface or pooled CPU memory.
41 ///
42 /// # Arguments
43 ///
44 /// - `&Self` - Mutable decoder backend.
45 /// - `&EncodedVideoPacket` - Demuxed compressed or structured frame packet with DTS/PTS and generation tag.
46 /// - `&VideoFramePool` - Bounded CPU pixel buffer pool for software fallback frames.
47 ///
48 /// # Returns
49 ///
50 /// - `Result<Option<DecodedVideoFrame>, String>` - Decoded frame ready for the PTS queue, `None` when buffered internally, or error.
51 fn decode_packet(
52 &mut self,
53 packet: &EncodedVideoPacket,
54 pool: &VideoFramePool,
55 ) -> Result<Option<DecodedVideoFrame>, String>;
56
57 /// Flushes internal reference frames and reorder buffers (invoked on seek or generation reset).
58 ///
59 /// # Arguments
60 ///
61 /// - `&Self` - Mutable decoder backend.
62 fn flush(&mut self);
63}
64
65/// Pluggable hardware or software video decoder backend interface for single-threaded WebAssembly hosts.
66#[cfg(target_arch = "wasm32")]
67pub trait VideoDecoderBackend {
68 /// Returns the backend identifier (`WebCodecs` or `SoftwareFallback`).
69 ///
70 /// # Arguments
71 ///
72 /// - `&Self` - Decoder backend reference.
73 ///
74 /// # Returns
75 ///
76 /// - `HardwareDecoderKind` - Active backend kind.
77 fn backend_kind(&self) -> HardwareDecoderKind;
78
79 /// Reports codec, resolution, HDR, and zero-copy capabilities supported by this backend.
80 ///
81 /// # Arguments
82 ///
83 /// - `&Self` - Decoder backend reference.
84 ///
85 /// # Returns
86 ///
87 /// - `HardwareDecoderCapabilities` - Backend capability descriptor.
88 fn capabilities(&self) -> HardwareDecoderCapabilities;
89
90 /// Configures or reconfigures the decoder for a video track descriptor.
91 ///
92 /// # Arguments
93 ///
94 /// - `&Self` - Mutable decoder backend.
95 /// - `&VideoDecoderConfig` - Track dimensions, codec, and color/HDR metadata.
96 ///
97 /// # Returns
98 ///
99 /// - `Result<(), String>` - `Ok(())` on successful initialization or descriptive error.
100 fn configure(&mut self, config: &VideoDecoderConfig) -> Result<(), String>;
101
102 /// Decodes a single demuxed packet into an optional decoded video frame backed by GPU surface or pooled CPU memory.
103 ///
104 /// # Arguments
105 ///
106 /// - `&Self` - Mutable decoder backend.
107 /// - `&EncodedVideoPacket` - Demuxed compressed or structured frame packet with DTS/PTS and generation tag.
108 /// - `&VideoFramePool` - Bounded CPU pixel buffer pool for software fallback frames.
109 ///
110 /// # Returns
111 ///
112 /// - `Result<Option<DecodedVideoFrame>, String>` - Decoded frame ready for the PTS queue, `None` when buffered internally, or error.
113 fn decode_packet(
114 &mut self,
115 packet: &EncodedVideoPacket,
116 pool: &VideoFramePool,
117 ) -> Result<Option<DecodedVideoFrame>, String>;
118
119 /// Flushes internal reference frames and reorder buffers (invoked on seek or generation reset).
120 ///
121 /// # Arguments
122 ///
123 /// - `&Self` - Mutable decoder backend.
124 fn flush(&mut self);
125}