edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiBcd61dc0Tahinli3 months ago728 commits
| 1 | //! AV1 bitstream syntax: OBU framing, the sequence header and the frame header. |
| 2 | //! |
| 3 | //! This crate parses what a *stateless* hardware decoder has to be told before |
| 4 | //! it can decode a frame — everything outside the entropy-coded tile data. That |
| 5 | //! is the whole of `sequence_header_obu` and `uncompressed_header` plus the tile |
| 6 | //! group headers, which is exactly the shape of |
| 7 | //! `VADecPictureParameterBufferAV1` and `VASliceParameterBufferAV1`; the tile |
| 8 | //! payloads themselves are handed to the driver as bytes, located by |
| 9 | //! [`Tile::offset`] and [`Tile::size`]. |
| 10 | //! |
| 11 | //! [`Av1Parser`] holds the state the format spreads across frames: the sequence |
| 12 | //! header (without which a frame header cannot even be parsed), the eight |
| 13 | //! reference slots with their sizes, order hints, saved segmentation, loop |
| 14 | //! filter deltas, global motion and film grain, and the reference update after |
| 15 | //! each frame (spec 7.20). Feed it every OBU of a stream in order and it answers |
| 16 | //! with headers whose fields are the spec's, under the spec's names. |
| 17 | //! |
| 18 | //! What is deliberately not here: the symbol decoder and everything behind it |
| 19 | //! (tile data, CDFs), Annex B length-delimited framing (containers hand over the |
| 20 | //! low-overhead format), the large scale tile mode, and metadata payloads — |
| 21 | //! [`metadata_type`] names the type and leaves the body to a caller that has a |
| 22 | //! use for HDR metadata, which is [`ec_core::color`]'s business rather than a |
| 23 | //! decode submission's. |
| 24 | //! |
| 25 | //! Malformed input is an [`Error`], never a panic: truncation is |
| 26 | //! [`Error::NeedMore`], a rule violation is [`Error::Corrupt`]. |
| 27 | //! |
| 28 | //! AV1 is covered by the AOMedia Patent License 1.0, which grants what an |
| 29 | //! independent implementation of the specification needs; this crate is such an |
| 30 | //! implementation, written from the specification alone. |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | use ; |
| 41 | |
| 42 | pub use |
| 43 | |
| 44 | |
| 45 | |
| 46 | ; |
| 47 | pub use ; |
| 48 | pub use |
| 49 | |
| 50 | |
| 51 | ; |
| 52 | |
| 53 | use ; |
| 54 | |
| 55 | /// Reference frame slots in the AV1 decoded frame buffer (spec 3). |
| 56 | pub const NUM_REF_FRAMES: usize = 8; |
| 57 | /// References a single inter frame may name: LAST through ALTREF (spec 3). |
| 58 | pub const REFS_PER_FRAME: usize = 7; |
| 59 | /// References including intra, which is what the loop filter deltas are indexed by. |
| 60 | pub const TOTAL_REFS_PER_FRAME: usize = 8; |
| 61 | /// `PRIMARY_REF_NONE` (spec 3): this frame inherits no probability or filter state. |
| 62 | pub const PRIMARY_REF_NONE: u8 = 7; |
| 63 | /// Number of segments a frame can define (spec 3). |
| 64 | pub const MAX_SEGMENTS: usize = 8; |
| 65 | /// Number of per-segment features (spec 3). |
| 66 | pub const SEG_LVL_MAX: usize = 8; |
| 67 | /// Segment feature: alternate quantizer index (spec 3). |
| 68 | pub const SEG_LVL_ALT_Q: usize = 0; |
| 69 | /// Segment feature: alternate loop filter level, luma vertical (spec 3). |
| 70 | pub const SEG_LVL_ALT_LF_Y_V: usize = 1; |
| 71 | /// Segment feature: reference frame override (spec 3). |
| 72 | pub const SEG_LVL_REF_FRAME: usize = 5; |
| 73 | /// Segment feature: skip (spec 3). |
| 74 | pub const SEG_LVL_SKIP: usize = 6; |
| 75 | /// Segment feature: global motion vector (spec 3). |
| 76 | pub const SEG_LVL_GLOBALMV: usize = 7; |
| 77 | /// `MAX_TILE_WIDTH` in samples (spec 3). |
| 78 | pub const MAX_TILE_WIDTH: u32 = 4096; |
| 79 | /// `MAX_TILE_AREA` in samples (spec 3). |
| 80 | pub const MAX_TILE_AREA: u32 = 4096 * 2304; |
| 81 | /// `MAX_TILE_COLS` (spec 3). |
| 82 | pub const MAX_TILE_COLS: u32 = 64; |
| 83 | /// `MAX_TILE_ROWS` (spec 3). |
| 84 | pub const MAX_TILE_ROWS: u32 = 64; |
| 85 | /// `RESTORATION_TILESIZE_MAX` (spec 3). |
| 86 | pub const RESTORATION_TILESIZE_MAX: u32 = 256; |
| 87 | |
| 88 | /// What an OBU turned out to hold. |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | /// One parsed OBU, and where it sat in the buffer. |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | /// An AV1 OBU parser carrying the state the format spreads across frames. |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 |