edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBabd41b6Tahinli3 months ago75 commits
| 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 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | pub use |
| 39 | |
| 40 | |
| 41 | ; |
| 42 | pub use ; |
| 43 | pub use split; |
| 44 | |
| 45 | /// Reference frame slots in the VP9 decoded picture buffer (spec 6.2). |
| 46 | pub const NUM_REF_FRAMES: usize = 8; |
| 47 | /// Reference frames a single inter frame may name: LAST, GOLDEN, ALTREF. |
| 48 | pub const REFS_PER_FRAME: usize = 3; |
| 49 | /// Number of segments a frame can define (spec 6.2, `segmentation_params`). |
| 50 | pub const MAX_SEGMENTS: usize = 8; |
| 51 | /// Segment feature: alternate quantizer index, signed, 8 bits (spec 6.2). |
| 52 | pub const SEG_LVL_ALT_Q: usize = 0; |
| 53 | /// Segment feature: alternate loop filter level, signed, 6 bits (spec 6.2). |
| 54 | pub const SEG_LVL_ALT_L: usize = 1; |
| 55 | /// Segment feature: reference frame override, unsigned, 2 bits (spec 6.2). |
| 56 | pub const SEG_LVL_REF_FRAME: usize = 2; |
| 57 | /// Segment feature: skip, a flag with no payload bits (spec 6.2). |
| 58 | pub const SEG_LVL_SKIP: usize = 3; |
| 59 | /// Number of per-segment features (spec 6.2). |
| 60 | pub const SEG_LVL_MAX: usize = 4; |