forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBca4790fTahinli3 months ago1157 commits

lib.rs60 lines, 3.0 KiBHistoryRawDownload
1//! VP9 bitstream syntax: the superframe index and the uncompressed frame header.
2//!
3//! This crate parses exactly the part of VP9 a *stateless* hardware decoder needs
4//! handed to it — everything up to, and not including, the compressed header.
5//! The compressed header is bool-coded probability update state; a VA-API driver
6//! consumes it itself out of the slice data buffer, so re-coding it here would be
7//! work nobody reads. What the driver cannot do is tell you where the frames are:
8//! [`superframe::split`] unpacks the multi-frame chunks libvpx emits for hidden
9//! ALTREFs, and [`Vp9Parser::parse_frame`] turns one such frame into a
10//! [`FrameHeader`] whose fields map one-to-one onto
11//! `VADecPictureParameterBufferVP9` and `VASegmentParameterVP9`.
12//!
13//! The parser is stateful because the *format* is: `frame_size_with_refs` takes
14//! the frame dimensions from a reference slot, and segmentation data and loop
15//! filter deltas persist from frame to frame until a keyframe, an intra-only
16//! frame or an error-resilient frame resets them (spec 6.2, "setup past
17//! independence"). [`Vp9Parser`] carries that state and applies the reference
18//! refresh, so feeding it every frame of a stream in order is all a caller does.
19//!
20//! Derivations the picture parameter buffer wants but the bitstream does not
21//! carry directly are provided next to the fields they come from:
22//! [`FrameHeader::segment_qindex`] and [`FrameHeader::segment_dequant`]
23//! (spec 8.6.1) and [`FrameHeader::loop_filter_levels`] (spec 8.8.1). Nothing in
24//! `VADecPictureParameterBufferVP9` or `VASegmentParameterVP9` is left for the
25//! caller to work out except the surface ids, which are a property of its frame
26//! pool rather than of the bitstream.
27//!
28//! Malformed input is an [`Error`], never a panic: truncation is
29//! [`Error::NeedMore`], a rule violation is [`Error::Corrupt`].
30
31#![forbid(unsafe_code)]
32#![warn(missing_docs)]
33
34mod header;
35pub mod quant;
36pub mod superframe;
37
38pub use header::{
39 ColorSpace, FrameHeader, FrameType, InterpolationFilter, LoopFilterParams, QuantizationParams,
40 ReferenceSlot, SegmentDequant, SegmentationParams, TileInfo, Vp9Parser,
41};
42pub use quant::{ac_q, dc_q};
43pub use superframe::split;
44
45/// Reference frame slots in the VP9 decoded picture buffer (spec 6.2).
46pub const NUM_REF_FRAMES: usize = 8;
47/// Reference frames a single inter frame may name: LAST, GOLDEN, ALTREF.
48pub const REFS_PER_FRAME: usize = 3;
49/// Number of segments a frame can define (spec 6.2, `segmentation_params`).
50pub const MAX_SEGMENTS: usize = 8;
51/// Segment feature: alternate quantizer index, signed, 8 bits (spec 6.2).
52pub const SEG_LVL_ALT_Q: usize = 0;
53/// Segment feature: alternate loop filter level, signed, 6 bits (spec 6.2).
54pub const SEG_LVL_ALT_L: usize = 1;
55/// Segment feature: reference frame override, unsigned, 2 bits (spec 6.2).
56pub const SEG_LVL_REF_FRAME: usize = 2;
57/// Segment feature: skip, a flag with no payload bits (spec 6.2).
58pub const SEG_LVL_SKIP: usize = 3;
59/// Number of per-segment features (spec 6.2).
60pub const SEG_LVL_MAX: usize = 4;