forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiBff99ad6Tahinli6 days ago1055 commits

vpx.rs78 lines, 3.3 KiBHistoryRawDownload
1//! The software VP8 decoder: `ec-vp8`, this project's own implementation of
2//! RFC 6386 -- the reason a VP8 file decodes on a machine whose GPU has no
3//! VP8 profile, or whose GPU is absent altogether.
4//!
5//! The seat was `libvpx`, resolved at runtime behind a hand-written FFI; the
6//! native crate replaces it outright, and with it the whole dlopen layer
7//! goes: the plugin links the decoder as ordinary Rust, so there is no
8//! library to look for, no ABI to pin, and no machine where the codec is
9//! absent from a build that carries this plugin. What survives from the FFI
10//! days is the seat's shape -- the five verbs the session above lives on:
11//!
12//! - `init` -- a fresh [`Decoder`], infallible now that there is no ABI to
13//! negotiate;
14//! - `decode` -- one access unit in, the picture (if any) held for the next
15//! `get_frame`;
16//! - `get_frame` -- the picture the last `decode` produced, taken once;
17//! - `flush` -- a formality: VP8 reorders nothing and holds nothing back, so
18//! end of stream has nothing to release (libvpx wanted the empty
19//! `vpx_codec_decode`; the native decoder has no equivalent need, and the
20//! verb stays because the session's pump is written around it);
21//! - `destroy` -- now simply the drop of an owned value, which is why a
22//! seek is `self.decoder = Decoder::new()` where the FFI seat paid a
23//! destroy + re-init round trip.
24
25use ec_vp8::decode;
26
27/// The VP8 decoder: [`decode::Decoder`] plus the one-picture slot between
28/// `decode` and `get_frame`.
29pub(super) struct Decoder {
30 inner: decode::Decoder,
31 pending: Option<Picture>,
32}
33
34/// One decoded picture: the visible frame's planes, 8-bit 4:2:0, strided
35/// (`stride` may exceed `width`) and owned by whoever holds it -- what
36/// [`crate::VhFrame`] hands on is the packed copy the session makes.
37pub(super) use decode::Picture;
38
39impl Decoder {
40 /// `init`: a decoder holding no references yet; the first key frame
41 /// sets the size.
42 pub(super) fn new() -> Self {
43 Self {
44 inner: decode::Decoder::new(),
45 pending: None,
46 }
47 }
48
49 /// `decode`: one access unit in -- one complete VP8 frame payload,
50 /// exactly what a container demuxer hands over for `V_VP8`/`vp08`. A
51 /// hidden frame (an alternate reference, `show_frame == 0`) updates the
52 /// reference buffers and produces no picture: the same nothing libvpx
53 /// emitted for one, so the seat's picture accounting does not move.
54 pub(super) fn decode(&mut self, au: &[u8]) -> Result<(), String> {
55 if au.is_empty() {
56 return Ok(());
57 }
58 match self.inner.decode(au) {
59 Ok(picture) => self.pending = picture,
60 Err(e) => return Err(format!("vp8 decode failed: {e}")),
61 }
62 Ok(())
63 }
64
65 /// `get_frame`: the picture the last `decode` produced, if that frame
66 /// was shown. Taken, not peeked -- the slot is empty again afterwards,
67 /// which is what lets the pump loop feed the next unit.
68 pub(super) fn get_frame(&mut self) -> Option<Picture> {
69 self.pending.take()
70 }
71
72 /// `flush`: end of the track. VP8 queues nothing -- one unit in, at
73 /// most one picture out, feed order -- so there is nothing held back to
74 /// drain; the answer is always ok, immediately.
75 pub(super) fn flush(&mut self) -> Result<(), String> {
76 Ok(())
77 }
78}