Skip to main content

vp8_decoder/
lib.rs

1//! A VP8 video decoder in pure Rust (RFC 6386).
2//!
3//! It decodes every VP8 bitstream version (0 to 3): keyframes and
4//! interframes, all intra and inter prediction modes including split motion
5//! vectors, segmentation, the normal and simple loop filters, token
6//! partitions, probability updates and persistence, and the last, golden and
7//! alt-ref reference frames with their sign bias and buffer copies. Its
8//! output matches the WebM project's VP8 test vectors bit for bit.
9//!
10//! Input is one raw VP8 frame at a time, starting at the frame tag (no IVF,
11//! WebM or RTP framing). Output is a borrowed I420 [`Picture`].
12//!
13//! ```no_run
14//! let frames: Vec<Vec<u8>> = Vec::new(); // raw VP8 frames, in order
15//! let mut decoder = vp8_decoder::Decoder::new();
16//! for frame in &frames {
17//!     match decoder.decode(frame) {
18//!         Ok(Some(picture)) => { let _i420 = picture.to_i420(); }
19//!         Ok(None) => {} // a frame that only updates references
20//!         Err(vp8_decoder::DecodeError::NeedKeyframe) => {} // wait for a keyframe
21//!         Err(_) => {} // corrupt: ask the sender for a keyframe
22//!     }
23//! }
24//! ```
25//!
26//! See PROVENANCE.md for how this crate was written.
27
28// The only `unsafe` code is in the SIMD modules (NEON on aarch64, SSE2 on
29// x86_64), which allow it for themselves; see the comments at their tops.
30#![deny(unsafe_code)]
31
32mod bool_decoder;
33mod decoder;
34mod frame;
35pub mod ivf;
36#[cfg(all(target_arch = "aarch64", target_feature = "neon", not(vp8_portable)))]
37#[allow(unsafe_code)]
38mod neon;
39#[cfg(all(target_arch = "aarch64", target_feature = "neon", not(vp8_portable)))]
40use neon as simd;
41#[cfg(all(target_arch = "x86_64", target_feature = "sse2", not(vp8_portable)))]
42#[allow(unsafe_code)]
43mod sse2;
44#[cfg(all(target_arch = "x86_64", target_feature = "sse2", not(vp8_portable)))]
45use sse2 as simd;
46#[cfg(test)]
47mod reference;
48
49// Shared with the vp8-encoder crate. Not a stable API: it may change in any
50// release, and vp8-encoder pins this crate's exact version. Lockstep rule:
51// any vp8-decoder release that touches these modules ships with a matching
52// vp8-encoder release that bumps its `=` pin.
53#[doc(hidden)]
54pub mod bool_encoder;
55#[doc(hidden)]
56pub mod idct;
57#[doc(hidden)]
58pub mod loop_filter;
59#[doc(hidden)]
60pub mod modes;
61#[doc(hidden)]
62pub mod predict;
63#[doc(hidden)]
64pub mod tables;
65
66pub use decoder::{frame_info, DecodeError, Decoder, Dimensions, FrameInfo, DEFAULT_MAX_PIXELS};
67pub use frame::Picture;
68
69#[cfg(vp8_stage_timers)]
70#[doc(hidden)]
71pub use decoder::StageTimes;
72
73// The README's examples are compiled as doc tests.
74#[cfg(doctest)]
75#[doc = include_str!("../README.md")]
76struct ReadmeDoctests;