edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits
| 1 | //! A key-frame picture encoder: a planar 4:2:0 picture in, an AV1 stream out. |
| 2 | //! |
| 3 | //! This is the layer that turns the pieces below it — the intra predictors of |
| 4 | //! [`crate::intra`], the forward transform and quantizer of |
| 5 | //! [`crate::transform`], and the tile writer of [`crate::tile`] — into |
| 6 | //! something that takes a picture. Every block is 32x32 (its chroma 16x16), |
| 7 | //! which is the subset the tile writer codes, and each one picks its luma mode |
| 8 | //! from the seven non-directional ones by rate-distortion; chroma searches |
| 9 | //! its own `uv_mode` over the seven that read no further than the row above |
| 10 | //! and the column to the left, its transform type derived from that mode the |
| 11 | //! way the decoder derives it. Block sizes are what a loop above this would |
| 12 | //! choose between. |
| 13 | //! |
| 14 | //! The encoder carries its own reconstruction, because prediction reads it: a |
| 15 | //! block predicts from the reconstructed samples above and to its left, exactly |
| 16 | //! as the decoder will. That makes the reconstruction a claim about what a |
| 17 | //! decoder produces, and it is gated as one — sample for sample against ffmpeg. |
| 18 | |
| 19 | use crateWithRef; |
| 20 | use ; |
| 21 | use |
| 22 | |
| 23 | |
| 24 | ; |
| 25 | use ; |
| 26 | |
| 27 | use cratecdf; |
| 28 | use crateTxbSet; |
| 29 | use crateframe_obu; |
| 30 | use crate |
| 31 | |
| 32 | |
| 33 | ; |
| 34 | use cratemc; |
| 35 | use cratemotion; |
| 36 | use crate; |
| 37 | use cratetemporal_delimiter; |
| 38 | use crateac_q; |
| 39 | use cratesequence_header_obu; |
| 40 | use crate |
| 41 | |
| 42 | ; |
| 43 | |
| 44 | use crateforward_and_quantize; |
| 45 | use crate |
| 46 | |
| 47 | |
| 48 | ; |
| 49 | |
| 50 | /// The side of the larger of the two luma blocks this encoder codes, in |
| 51 | /// samples. |
| 52 | const BLOCK: usize = 32; |
| 53 | |
| 54 | /// The side of the smaller one, which a 32x32 block may be split into four of. |
| 55 | const SUB: usize = 16; |
| 56 | |
| 57 | /// The side of a superblock, which is what the partition tree starts from. |
| 58 | pub const SUPERBLOCK: usize = 64; |
| 59 | |
| 60 | // lane-sb128 r1: the superblock size in samples the intra-reach rules |
| 61 | // (`has_top_right`/`has_bottom_left`) are answered against. libaom masks the |
| 62 | // block's mi position with `mi_size_wide[cm->seq_params->sb_size] - 1` and |
| 63 | // tests the "top row"/"rightmost column" of THAT superblock, so a 128x128 |
| 64 | // superblock changes every answer inside it (the tables themselves are |
| 65 | // already laid out 128-relative -- see `Reach::table_stride`). [`SUPERBLOCK`] |
| 66 | // stays the encoder's own fixed 64. |
| 67 | |
| 68 | /// Sets the superblock size [`Reach`] answers against (64 or 128). |
| 69 | pub |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | /// [`reach_sb_px`] in 4x4 mode-info units -- libaom's `sb_mi_size` in |
| 78 | /// `has_top_right`/`has_bottom_left` (`mi_size_high[sb_size]`), which is what |
| 79 | /// [`Reach::of_tu_chroma`] masks the block's mi position with. |
| 80 | pub |
| 81 | |
| 82 | |
| 83 | |
| 84 | /// `scale_chroma_bsize(bsize, ss_x, ss_y)` (libaom `reconintra.c:1649`, |
| 85 | /// called from `av1_predict_intra_block` at `:1823`) in 4x4 mode-info units: |
| 86 | /// the block shape a CHROMA plane's reach is answered against. Only the |
| 87 | /// BLOCK_4X4 / BLOCK_4X8 / BLOCK_8X4 / BLOCK_4X16 / BLOCK_16X4 family is |
| 88 | /// remapped -- every other block size passes through, so at `ss (0,0)` and |
| 89 | /// for any block of 8 or more this is the block's own `(bw/4, bh/4)`. |
| 90 | pub |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | /// How heavily the mode search weighs rate against squared error, in units of |
| 113 | /// the quantizer's reconstruction step squared per bit. |
| 114 | /// |
| 115 | /// Swept three times over his clips and three synthetic pictures |
| 116 | /// (`probe_lambda`, `probe_directional` and `probe_ladder`, and the tables in |
| 117 | /// the three lane reports). The first sweep, before the mode symbol was |
| 118 | /// costed, put the best point at 0.05; costing it moved the point to 0.1. The |
| 119 | /// third sweep, after the levels were costed through the writer's own CDFs |
| 120 | /// too, left it there: against 0.2 the ladders are worth -1.19% against -0.98% |
| 121 | /// on film and -0.20% against -0.14% on screen capture. |
| 122 | /// |
| 123 | /// The fourth sweep (lane-av1lambda) ran the BD gates themselves rather than |
| 124 | /// those ladders, and 0.1 was far off the point: the rate term was carrying |
| 125 | /// roughly twice the weight it is worth. 640x384 gate, BD-rate vs libaom / |
| 126 | /// vs rav1e for 1080p film, 2160p film, screen capture: |
| 127 | /// |
| 128 | /// | lambda | 1080p | 2160p | screen | |
| 129 | /// |--------|-------|-------|--------| |
| 130 | /// | 0.0125 | +78.0 / +31.3 | +90.8 / +46.5 | +57.2 / -0.3 | |
| 131 | /// | 0.025 | +71.5 / +28.4 | +87.0 / +46.5 | +50.4 / -3.8 | |
| 132 | /// | 0.0375 | +71.2 / +28.5 | +84.3 / +45.4 | +48.7 / -4.4 | |
| 133 | /// | 0.05 | +71.9 / +29.6 | +87.1 / +49.3 | +48.7 / -4.0 | |
| 134 | /// | 0.075 | +74.8 / +32.7 | +91.3 / +52.8 | +51.4 / -1.3 | |
| 135 | /// | 0.1 | +79.2 / +36.9 | +97.7 / +58.8 | +53.1 / -0.4 | |
| 136 | /// | 0.125 | +84.0 / +41.1 | +100.7 / +61.5 | +56.8 / +2.3 | |
| 137 | /// | 0.15 | +86.0 / +42.9 | +104.4 / +65.2 | +59.5 / +4.2 | |
| 138 | /// | 0.2 | +89.6 / +45.5 | +109.9 / +69.8 | +62.3 / +7.3 | |
| 139 | /// |
| 140 | /// and on the native 1920x1024 crops, which is the table that decides: |
| 141 | /// |
| 142 | /// | lambda | film 1080p | film 2160p | screen | |
| 143 | /// |--------|------------|------------|--------| |
| 144 | /// | 0.025 | +17.1 / -0.5 | +49.0 / +21.1 | +51.5 / -15.1 | |
| 145 | /// | 0.0375 | +16.3 / -1.0 | +47.5 / +19.7 | +50.7 / -15.1 | |
| 146 | /// | 0.05 | +17.0 / -0.3 | +47.0 / +19.2 | +51.6 / -14.2 | |
| 147 | /// | 0.1 | +18.1 / +0.9 | +47.1 / +19.0 | +58.3 / -9.8 | |
| 148 | /// |
| 149 | /// 0.0375 was the best point on two clips of three there and cost the "2160p |
| 150 | /// film" row +0.4/+0.7, outside the +-0.3 band every other lever here is kept |
| 151 | /// inside, so 0.05 shipped. BOTH of those tables' "film" rows are the |
| 152 | /// `testsrc2` COLOUR BARS fixtures (see [`bd_rate_screen_native`]), ~90% of |
| 153 | /// whose cells have no intra cost -- no real film supported the point. |
| 154 | /// |
| 155 | /// FIFTH SWEEP (lane-av1resweep, 2026-09-07), on the native gate's two REAL |
| 156 | /// film crops (film A 1080p, film B 2160p HDR) plus the capture, BD-rate vs |
| 157 | /// libaom / vs rav1e, everything else at the shipped defaults: |
| 158 | /// |
| 159 | /// | lambda | bars 1080p | bars 2160p | film A | film B | screen | |
| 160 | /// |--------|------------|------------|--------|--------|--------| |
| 161 | /// | 0.02 | +17.5 / -0.2 | +49.7 / +21.7 | +65.8 / +35.0 | +91.2 / +55.4 | +53.4 / -14.1 | |
| 162 | /// | 0.0275 | +16.6 / -0.9 | +48.3 / +20.5 | +65.5 / +34.7 | +91.6 / +55.1 | +51.3 / -15.0 | |
| 163 | /// | 0.035 | +16.1 / -1.3 | +47.5 / +19.7 | +66.4 / +35.2 | +94.2 / +56.9 | +50.8 / -15.1 | |
| 164 | /// | 0.05 | +15.6 / -1.7 | +46.5 / +18.8 | +69.0 / +37.5 | +100.0 / +61.5 | +51.0 / -14.5 | |
| 165 | /// | 0.07 | +16.6 / -0.5 | +46.8 / +18.8 | +72.3 / +40.4 | +108.5 / +68.8 | +54.4 / -12.4 | |
| 166 | /// | 0.1 | +16.5 / -0.7 | +46.6 / +18.7 | +76.9 / +44.4 | +118.2 / +77.1 | +57.3 / -10.1 | |
| 167 | /// |
| 168 | /// Real film wants roughly HALF the rate weight the bars asked for: the bowl |
| 169 | /// on both film rows bottoms between 0.02 and 0.0275 and is 5-11 points deep |
| 170 | /// against the shipped 0.05, while the bars rows walk the other way (they are |
| 171 | /// recorded, not decided on). 0.02 breaks the capture (+2.4 vs libaom), so |
| 172 | /// 0.0275 ships -- both films 3.5/8.4 points down vs libaom, the capture |
| 173 | /// +0.3/-0.5 (at the +-0.3 band, and better than baseline once the var-tx |
| 174 | /// defaults below are on: +50.1 / -15.4). It spends ~5% more encode wall. |
| 175 | const LAMBDA_SCALE: f64 = 0.0275; |
| 176 | |
| 177 | /// The rate weight a HIDDEN frame (a pyramid ARF, coded but not shown) codes |
| 178 | /// under, as a multiple of [`LAMBDA_SCALE`] (lane-arfcen). |
| 179 | /// |
| 180 | /// The ARF-vs-ARF census says our top ARF codes residual over HALF its area |
| 181 | /// (rav1e's, at the same display position, over 26-30%) and comes out 1.4-2.5x |
| 182 | /// its bytes at the same PSNR, while every leaf that predicts from it is |
| 183 | /// still 0.4 dB behind rav1e's -- i.e. the ARF's extra fidelity is bought at |
| 184 | /// a rate weight fitted on shown frames and does not propagate. This is the |
| 185 | /// one knob that prices a hidden frame's rate differently from its q, which |
| 186 | /// the pyramid's q offsets cannot do (they move lambda and step together). |
| 187 | const HIDDEN_LAMBDA_FACTOR: f64 = 1.0; |
| 188 | |
| 189 | /// [`HIDDEN_LAMBDA_FACTOR`], swept by `EC_AV1_LAMBDA_HIDDEN` in any build. |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | /// [`LAMBDA_SCALE`], or whatever `EC_AV1_LAMBDA` names when the sweep that |
| 201 | /// picks it is the thing running. A release build has no such knob. |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | /// How a key frame's lambda differs from an inter frame's: libaom weighs the |
| 213 | /// two apart (`rd_frame_type_factor`, key 128 against an inter frame's 144 out |
| 214 | /// of 128), because every later frame predicts from the key frame, so an error |
| 215 | /// left in it is paid for over the whole group. This encoder has no temporal |
| 216 | /// propagation model at all, and this factor is the cheapest stand-in for one. |
| 217 | /// Swept by `EC_AV1_LAMBDA_KEY` in a test build, like [`lambda_scale`]. |
| 218 | /// |
| 219 | /// MEASURED and NOT KEPT. 640x384 gate at [`LAMBDA_SCALE`] 0.05, BD vs |
| 220 | /// libaom / vs rav1e: |
| 221 | /// |
| 222 | /// | k_key | 1080p | 2160p | screen | |
| 223 | /// |---|---|---|---| |
| 224 | /// | 1.0 | +71.9 / +29.6 | +87.1 / +49.3 | +48.7 / -4.0 | |
| 225 | /// | 0.85 | +71.5 / +29.4 | +87.0 / +48.3 | +49.7 / -3.9 | |
| 226 | /// | 0.7 | +71.3 / +28.9 | +87.2 / +48.6 | +49.4 / -4.1 | |
| 227 | /// | 0.5 | +71.4 / +28.9 | +88.7 / +49.6 | +50.1 / -3.4 | |
| 228 | /// |
| 229 | /// The two films want the key frame coded finer and the screen capture wants |
| 230 | /// the opposite, by about the same amount, and at native the whole lever is |
| 231 | /// inside the +-0.3 band that decides nothing: k_key 0.7 reads +16.9 / -0.3, |
| 232 | /// +47.2 / +19.2, +51.4 / -14.7 against 1.0's +17.0 / -0.3, +47.0 / +19.2, |
| 233 | /// +51.6 / -14.2. A gate whose GOP is one key frame in twelve cannot see a |
| 234 | /// per-frame-type weight; the real lever here is temporal propagation |
| 235 | /// (libaom's `tpl`), which weighs each BLOCK by how much of it later frames |
| 236 | /// predict from, not each frame. |
| 237 | const KEY_LAMBDA_FACTOR: f64 = 1.0; |
| 238 | |
| 239 | /// [`KEY_LAMBDA_FACTOR`], or what `EC_AV1_LAMBDA_KEY` names in a test build. |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | // Every frame's predicted coefficient bits since the last |
| 251 | // `take_predicted_bits`, in coding order -- the encoder half of |
| 252 | // `predicted_coeff_bits_track_the_tile_the_writer_wrote`'s drift measurement. |
| 253 | |
| 254 | thread_local! |
| 255 | |
| 256 | |
| 257 | |
| 258 | /// Records one frame's predicted coefficient bits. |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | /// Takes (and clears) what the frames encoded on this thread were predicted to |
| 265 | /// spend on coefficients. |
| 266 | |
| 267 | pub |
| 268 | |
| 269 | |
| 270 | |
| 271 | /// Whether a 16x16 inter leaf may split into four 8x8 ones of its own. |
| 272 | pub const SPLIT_INTER_8: bool = true; |
| 273 | |
| 274 | /// [`SPLIT_INTER_8`], or what `EC_AV1_SPLIT_INTER8` names in a test build. |
| 275 | /// Whether a key frame codes `tx_mode == TxMode::Select` and searches each |
| 276 | /// block's transform depth (lane-av1tx). On by default; `EC_AV1_TX_SELECT=0` |
| 277 | /// turns it off for an A/B on one build. |
| 278 | /// Whether an INTER frame also carries `TxMode::Select`: an inter block's |
| 279 | /// residual as one transform over the whole block or as the four transforms |
| 280 | /// of half the side ([`commit_inter_luma`]), a searched `tx_depth` on every |
| 281 | /// intra block inside the inter frame. ON since lane-av1tx2, which found why |
| 282 | /// the streams desynced -- the writer counted the [`crate::decode:: |
| 283 | /// TXFM_CTX_INIT`] band value of a neighbour outside the tile, where the |
| 284 | /// reader drops the term -- and measured the split search: BD-rate vs libaom |
| 285 | /// 233.5 -> 226.1 and 170.9 -> 167.4 on two clips, 212.8 -> 213.2 on the |
| 286 | /// third, for 13% encode wall. `EC_AV1_TX_SELECT_INTER=0` turns it off for an |
| 287 | /// A/B on one build. |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | /// SCREEN CONTENT ONLY, measured (12-frame `bd_rate_screen_native`, control |
| 298 | /// vs arm): the capture row goes +27.8/-26.0 -> +20.8/-30.1 -- seven points |
| 299 | /// against libaom -- while BOTH film rows LOSE (film A +21.7/-4.4 -> |
| 300 | /// +22.1/-4.0, film B +26.9/-0.6 -> +28.1/+0.7) and 2160p bars lose 0.8/1.1. |
| 301 | /// The keep rule wants both films down, so this takes the same content gate |
| 302 | /// palette, intrabc and the angle-delta refinement already stand behind: a |
| 303 | /// non-screen frame is byte-identical to the encoder before the lane. |
| 304 | /// |
| 305 | /// The transform types an intra luma transform unit of `set` may be coded |
| 306 | /// with -- exactly the alphabet the writer's `tx_type` symbol names for that |
| 307 | /// set, so a searched type is always one the tile can express (lane-txset). |
| 308 | /// `DCT_DCT` first: it is the incumbent every other candidate has to beat. |
| 309 | /// |
| 310 | /// Under this encoder's `reduced_tx_set` header bit every intra set at 16x16 |
| 311 | /// and below is `TX_SET_INTRA_2` (spec `get_tx_set`), the five types |
| 312 | /// [`TxType::from_symbol`] names; 32x32 and 64x64 luma code no symbol at all, |
| 313 | /// and inter luma reads the two-type `TX_SET_INTER_3`, left at `DCT_DCT` |
| 314 | /// here. |
| 315 | pub |
| 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 | /// The transform types an INTER luma transform unit of `set` may be coded |
| 346 | /// with (lane-txset2). Under this encoder's `reduced_tx_set` header bit every |
| 347 | /// inter luma set at 16x16 and below is the two-type `TX_SET_INTER_3` |
| 348 | /// (`IDTX`, `DCT_DCT`) and 32x32 is `EXT_TX_SET_DCT_IDTX` -- the same two |
| 349 | /// types, a symbol the writer already codes and never varied. 64x64 codes no |
| 350 | /// `tx_type` symbol at all, so it is not offered one. |
| 351 | /// SCREEN CONTENT ONLY, measured (12-frame `bd_rate_screen_native`): the |
| 352 | /// capture row goes +20.8/-30.1 -> +20.1/-30.4 while the two synthetic bars |
| 353 | /// rows lose TWENTY points (-1.0/-16.8 -> +23.1/+3.3 and +9.4/-12.7 -> |
| 354 | /// +31.2/+3.7) and film B 0.3 -- the `local-rd-on-references` class at its |
| 355 | /// loudest, and restricting the offer to 16x16 and below does not soften it |
| 356 | /// (`le16`: +22.9/+3.1, +31.6/+4.0). So this takes the same content gate the |
| 357 | /// intra search, palette and intrabc stand behind: a non-screen frame is |
| 358 | /// byte-identical to the encoder before the lane. |
| 359 | /// |
| 360 | /// `EC_AV1_TXSET_INTER`: `0`/`off`, `screen` (screen frames only), `le16` |
| 361 | /// (16x16 and below, the sizes libaom's own census picks a non-`DCT_DCT` |
| 362 | /// inter type on -- it never takes `IDTX` at 32x32 on film B), anything else |
| 363 | /// on for every frame at every size. |
| 364 | pub |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | /// lane-txi: does THIS frame code `reduced_tx_set = 0` (spec 5.9.2), i.e. |
| 400 | /// the wider `tx_type` alphabets at intra 8x8/4x4 and inter 16x16 and below? |
| 401 | /// `EC_AV1_TXSET_WIDE`: `0`/`off`, `screen` (screen frames only), anything |
| 402 | /// else every frame; unset takes [`crate::speed::WIDE_TX_SET`], screen-gated |
| 403 | /// like both halves of the type search itself. |
| 404 | pub |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | /// A PROCESS-GLOBAL [`wide_tx_set`] override that wins over both the |
| 431 | /// environment and the preset (`u8::MAX` = unset), the shape |
| 432 | /// [`set_inter_tx_search`] has: the lever is OFF at every preset, so the |
| 433 | /// witness that has to see the wider alphabets turns it on through this while |
| 434 | /// holding [`crate::speed::knob_write`]. |
| 435 | static WIDE_TX_OVERRIDE: AtomicU8 = new; |
| 436 | |
| 437 | /// Sets [`WIDE_TX_OVERRIDE`]; `None` clears it. |
| 438 | // set only from the `#[cfg(test)]` gates |
| 439 | pub |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | |
| 446 | /// The luma [`TxbSet`] the SEARCH and its pricer name for a frame that codes |
| 447 | /// `reduced_tx_set = 0`: the writer reads the bit once, off the frame's own |
| 448 | /// [`crate::cdf_state::Cdfs`], but the trial that prices a type has to read |
| 449 | /// the same alphabet or the two disagree on what a `tx_type` symbol costs. |
| 450 | pub |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | pub |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | /// A PROCESS-GLOBAL [`inter_tx_type_search`] override that wins over both the |
| 464 | /// environment and the preset (`u8::MAX` = unset), the shape |
| 465 | /// [`set_deltaq_res`] has: the lever is OFF at every preset, so the witness |
| 466 | /// that has to see a non-`DCT_DCT` inter unit turns it on through this while |
| 467 | /// holding [`crate::speed::knob_write`]. |
| 468 | static INTER_TX_OVERRIDE: AtomicU8 = new; |
| 469 | |
| 470 | /// Sets [`INTER_TX_OVERRIDE`]; `None` clears it. |
| 471 | // set only from the `#[cfg(test)]` gates |
| 472 | pub |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | /// The inter luma [`TxbSet`] a `tx`-sided transform unit reads, `None` for the |
| 505 | /// 64-point one (it codes no `tx_type` symbol). |
| 506 | /// lane-txw history, resolved by lane-intertx: the INTER half of the |
| 507 | /// widening was blocked by `refusal-from-own-desync` twice over. Half of it |
| 508 | /// was this writer coding a `V_DCT`/`H_DCT` unit as `TX_CLASS_2D` |
| 509 | /// (`tile::write_coeffs`, fixed by lane-txw, which unblocked the intra |
| 510 | /// half). The other half was the CHROMA inheritance: an inter block's |
| 511 | /// chroma transform type is the luma type reduced to the chroma size's set |
| 512 | /// (`decode::reduce_inherited_chroma_tx_type`), and (a) the encoder never |
| 513 | /// set `FrameCtx::reduced_tx_set_inter`, so [`recode_inter_chroma`] reduced |
| 514 | /// against a STALE allowance, and (b) `tile::write_block_planes` coded |
| 515 | /// every chroma plane as `DCT_DCT`, so an inherited 1-D type desynced the |
| 516 | /// chroma exactly as luma did. lane-intertx fixed both -- the frame sets |
| 517 | /// its own bit on the context (`encode_inter_frame`), the writer derives |
| 518 | /// the chroma type from this frame's own header bit |
| 519 | /// (`reduce_inherited_chroma_tx_type_flagged`) -- and the widened SEARCH |
| 520 | /// names these sets through [`luma_set_for`] at its call sites, so the |
| 521 | /// wider candidates are reachable and honestly priced. The intra half |
| 522 | /// never needed either (an intra block's chroma type comes off its own UV |
| 523 | /// mode, never off luma). |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | /// Whether an intra luma unit of this frame searches its own type at all: |
| 544 | /// the preset lever ([`tx_type_search`]) under the screen content gate, which |
| 545 | /// `EC_AV1_TXSET=all` ([`intra_tx_all_frames`]) lifts and the process-global |
| 546 | /// [`set_intra_tx_search`] override wins over (the witness needs the search |
| 547 | /// on a frame the detector called non-screen). |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | /// A PROCESS-GLOBAL [`intra_tx_search_on`] override (`u8::MAX` = unset), the |
| 558 | /// shape [`set_inter_tx_search`] has. |
| 559 | static INTRA_TX_OVERRIDE: AtomicU8 = new; |
| 560 | |
| 561 | /// Sets [`INTRA_TX_OVERRIDE`]; `None` clears it. |
| 562 | // set only from the `#[cfg(test)]` gates |
| 563 | pub |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | /// lane-txi: `EC_AV1_TXSET=all` offers the five-type intra set on EVERY |
| 571 | /// frame -- the unconditional arm the gate measures -- instead of the screen |
| 572 | /// content gate [`tx_type_candidates`] ships behind. Any other value keeps |
| 573 | /// the gate (`0`/`off` still switches the search off entirely). |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | |
| 596 | /// Whether a 16x16 (or 8x8) leaf runs a motion search of its own beside the |
| 597 | /// NEARESTMV candidate it always had. |
| 598 | pub const LEAF_NEW_MV: bool = true; |
| 599 | |
| 600 | /// Whether GOLDEN/ALTREF get a `NEWMV` search of their own. Measured on the |
| 601 | /// BD gate: with the early-out below at its swept margin, -1.7/-2.5/-0.0 |
| 602 | /// points vs libaom and -1.6/-2.3/-0.0 vs rav1e for 4%/4%/0.3% more motion |
| 603 | /// searches (the census `bd_rate_vs_libaom_and_rav1e` prints). |
| 604 | pub const EXTRA_REF_NEW_MV: bool = true; |
| 605 | |
| 606 | /// How much cheaper an extra reference's `NEARESTMV` has to be than LAST's |
| 607 | /// own best vector before that reference's `NEWMV` search is skipped: a |
| 608 | /// factor on the search cost scale, `1.0` meaning "as good or better". |
| 609 | /// Swept on the BD gate over 0.15/0.25/0.35/0.5/0.8/1.0/1.5 and off (`0.0`, |
| 610 | /// never skip): the whole BD gain survives down to 0.35 (+124.8/+150.4/+80.9 |
| 611 | /// vs libaom, against +124.9/+150.3/+81.0 with no early-out at all) while the |
| 612 | /// extra searches drop from +27% to +4% of the base count -- and on screen |
| 613 | /// capture, where an extra reference's NEWMV wins nothing, it skips 99.7% of |
| 614 | /// them. Below 0.35 the gain starts eroding (0.15: +125.3/+151.7). |
| 615 | /// RE-SWEPT on lane-av1rejudge at [`LAMBDA_SCALE`] 0.05 with warp on: 0.25 |
| 616 | /// reads +16.6/-0.6, +47.0/+19.1, +51.3/-14.3 and 0.5 reads +16.6/-0.7, |
| 617 | /// +47.0/+19.1, +51.3/-14.3 against the base's +16.7/-0.5, +47.0/+19.1, |
| 618 | /// +51.3/-14.3 -- one row 0.1-0.2 down, two flat, inside the measurement's |
| 619 | /// own noise. 0.35 stays; the lever that did move at the new rate weight is |
| 620 | /// [`LEAF_SECOND_NEW_MARGIN`], not this one. |
| 621 | const EXTRA_NEW_SKIP_MARGIN: f64 = 0.35; |
| 622 | |
| 623 | /// [`EXTRA_NEW_SKIP_MARGIN`], swept by `EC_AV1_MV_SKIP_MARGIN`. |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | /// The margin on a LEAF's SECOND-reference motion search, the same early-out |
| 632 | /// shape [`EXTRA_NEW_SKIP_MARGIN`] gives a whole block's extra-reference |
| 633 | /// `NEWMV`: the search is skipped when that reference's own |
| 634 | /// `NEAREST_NEARESTMV` vector already prices this many times better than the |
| 635 | /// leaf's `LAST` search found. `0.0` never skips. |
| 636 | /// |
| 637 | /// Swept on the BD gate over 0.15/0.35/0.6/0.8/1.2 and 0.0, reading BD vs |
| 638 | /// libaom (1080p/2160p/screen) against the extra `motion::search` calls at |
| 639 | /// 2160p (38195 with no second-reference search at all): |
| 640 | /// 0.15 +81.7/+97.4/+54.5 at 41286, 0.35 +81.4/+96.7 at 43093, |
| 641 | /// 0.6 +80.6/+95.5 at 44843, 0.8 +79.9/+94.6 at 47008, 1.2 +80.2/+94.2 at |
| 642 | /// 77882, never-skip +79.7/+94.1 at 81801. 0.8 takes the whole gain the |
| 643 | /// unskipped search buys (-3.1/-5.3 off the +83.0/+99.9 base) for a quarter |
| 644 | /// of its extra searches; past it the calls double for another -0.3/-0.5. |
| 645 | /// Screen capture is BYTE-IDENTICAL at every margin -- its leaf compound is |
| 646 | /// all `NEAREST_NEARESTMV` and no searched second vector ever wins there -- |
| 647 | /// so the margin is pure wall on that content (+10% searches at 0.8). |
| 648 | /// |
| 649 | /// RE-SWEPT on lane-av1rejudge after [`LAMBDA_SCALE`] moved 0.1 -> 0.05, on |
| 650 | /// the native gate with local warp on, BD vs libaom / vs rav1e: |
| 651 | /// |
| 652 | /// | margin | film 1080p | film 2160p | screen | |
| 653 | /// |---|---|---|---| |
| 654 | /// | 0.6 | +16.9 / -0.4 | +47.0 / +19.1 | +51.2 / -14.4 | |
| 655 | /// | 0.8 (was) | +16.7 / -0.5 | +47.0 / +19.1 | +51.3 / -14.3 | |
| 656 | /// | 1.2 | +16.2 / -1.1 | +46.6 / +18.8 | +51.3 / -14.4 | |
| 657 | /// | 1.6 | +16.4 / -0.8 | +46.6 / +18.8 | +51.3 / -14.4 | |
| 658 | /// | 0.0 (never skip) | +16.4 / -0.8 | +46.6 / +18.8 | +51.3 / -14.4 | |
| 659 | /// |
| 660 | /// 1.2 is the floor of that bowl -- two rows 0.3-0.6 down on BOTH columns |
| 661 | /// with screen flat -- and it beats never-skipping, i.e. the early-out is |
| 662 | /// still worth having, just at a looser margin than the old rate weight |
| 663 | /// wanted. It costs about 10% encoder wall on the two film clips (36.6s vs |
| 664 | /// 32.6s at 2160p), which is the price of the extra second-reference |
| 665 | /// searches. |
| 666 | const LEAF_SECOND_NEW_MARGIN: f64 = 1.2; |
| 667 | |
| 668 | /// [`LEAF_SECOND_NEW_MARGIN`], swept by `EC_AV1_LEAF_SECOND_MARGIN`; the |
| 669 | /// search itself is switched off by `EC_AV1_LEAF_SECOND_NEWMV=0`. |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | /// Whether a leaf searches its SECOND reference at all (lane-av1comp4). |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | /// Whether a 16x16 or 8x8 inter LEAF is offered the compound candidates the |
| 686 | /// whole 32x32 block is (lane-av1comp3). The writer already codes a compound |
| 687 | /// block at any leaf size (`tile::write_inter_frame_leaf`/`..._leaf8` both |
| 688 | /// route through `write_compound_block`, which is sized by `bw4`/`bh4`); what |
| 689 | /// was missing was the encoder ever forming one below 32x32. |
| 690 | pub const LEAF_COMPOUND: bool = true; |
| 691 | |
| 692 | /// [`LEAF_COMPOUND`], or what `EC_AV1_LEAF_COMPOUND` names in any build. |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | /// [`LEAF_NEW_MV`], or what `EC_AV1_LEAF_NEWMV` names in a test build. |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | /// Whether an INTER frame's 32x32 block may be split into four 16x16 ones |
| 709 | /// when the trial says four cost less. Before lane-av1rd2 only a quadrant |
| 710 | /// the true frame edge cut through was ever split there; inside the frame |
| 711 | /// every block was coded whole, which left the partition decision the key |
| 712 | /// frame already makes unmade for eleven frames out of twelve. |
| 713 | pub const SPLIT_INTER_BLOCKS: bool = true; |
| 714 | |
| 715 | /// [`SPLIT_INTER_BLOCKS`], or what `EC_AV1_SPLIT_INTER` names when the |
| 716 | /// measurement that keeps it is running (test builds only, like |
| 717 | /// [`lambda_scale`]). |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | /// Whether the inter search offers the whole superblock as ONE 64x64 block |
| 726 | /// (`PARTITION_NONE` at `BLOCK_64X64`), coded SKIP, against the four 32x32 |
| 727 | /// quadrants it would otherwise always split into. |
| 728 | /// |
| 729 | /// The census (`lanes/census-filmB.md`) is what points here: rav1e speed 6 |
| 730 | /// codes 45.2% of its blocks at 64x64 -- 73.8% of its LEAF blocks, 99.2% of |
| 731 | /// them skip at 328 bytes a frame -- while every block this encoder wrote was |
| 732 | /// 32x32 or smaller, which put our mode+mv+partition+tx_size spend at 162,669 |
| 733 | /// bits against rav1e's 61,988, about 46% of the film B gap. |
| 734 | /// |
| 735 | /// lane-tx64: no longer skip-only. The root also prices a REAL residual -- |
| 736 | /// one TX_64X64 luma transform (`transform.rs`'s forward network has always |
| 737 | /// reached 64 points; what was missing was the block coder and the writer |
| 738 | /// around it) and one TX_32X32 per chroma plane -- see [`b64_residual`], |
| 739 | /// which carries that arm's own gate table. Still refused at the 64 root: |
| 740 | /// compound references, a depth-1 4x32x32 var-tx tree, intra, and a |
| 741 | /// superblock the true frame edge cuts through. |
| 742 | /// |
| 743 | /// Switched off by `EC_AV1_B64=0` in any build; `EC_AV1_B64RES=0` keeps the |
| 744 | /// root and restores the skip-only shape lane-b64 shipped. |
| 745 | pub const B64_ROOT: bool = true; |
| 746 | |
| 747 | /// How many superblocks took the 64x64 root since the last |
| 748 | /// [`take_b64_root_hits`], so a gate reports how often it fires rather than |
| 749 | /// assuming it does (class `gate-blind-to-feature`). |
| 750 | static B64_HITS: AtomicUsize = new; |
| 751 | |
| 752 | /// The 64x64-root count since the last call, and zero it. |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | /// Whether the 128 superblock root offers its `PARTITION_NONE` candidate at |
| 758 | /// all ([`search_root_128`]). On by default; `EC_AV1_B128=0` turns it off, |
| 759 | /// which is the attribution arm for a 128-superblock stream: it separates |
| 760 | /// what the SIZE costs from what the 128x128 BLOCK buys. |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | /// lane-b128r: whether the 128 root prices a REAL residual as well as the |
| 771 | /// skip arm -- four TX_64X64 luma units interleaved with a TX_32X32 chroma |
| 772 | /// pair per 64x64 mu chunk, var-tx depth 0 (the shape |
| 773 | /// [`crate::tile::write_inter_block_128`] codes and `decode_inter_block` |
| 774 | /// reads). Written, witnessed and byte-exact through both decoders, and |
| 775 | /// **off by default** (`EC_AV1_B128RES=1` turns it on) because it is INERT |
| 776 | /// on content: the RD takes it 0.7-1.9 times per frame against thousands of |
| 777 | /// whole 128 roots (lane-b128res census, native 12-frame gate, every clip), |
| 778 | /// and the BD effect is inside the noise on both gates -- long-GOP films |
| 779 | /// -0.1/+0.1 and all five 12-frame rows within 0.1 of the off default. |
| 780 | /// |
| 781 | /// The historical reason for the parking is CLOSED: the bars 2160p q=90 |
| 782 | /// frame 11 disagreement with ffmpeg (8 luma samples at the rows above a |
| 783 | /// 128-superblock horizontal edge) was the CDEF search pricing a preset per |
| 784 | /// 64x64 unit under a root that codes ONE literal for all four -- lane- |
| 785 | /// edge128's `crate::tile::cdef_unit_owner` collapses the four to the one |
| 786 | /// the decoder derives, and on this HEAD the same row re-measures three-way |
| 787 | /// EXACT (encoder reconstruction == ffmpeg == `decode_stream`, every frame, |
| 788 | /// every plane, both gates). The knob stays as the arm's gate, not as a |
| 789 | /// defect flag. |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | /// lane-rectres: whether the 128 root's RECTANGULAR pieces -- the two |
| 800 | /// HORZ/VERT halves and the four AB shapes' three pieces (two 64x64 squares |
| 801 | /// plus one half) -- price a REAL residual in the RD as well as the skip arm |
| 802 | /// ([`search_root_128_rect`] / [`search_root_128_ab`], written through |
| 803 | /// [`crate::tile::write_inter_block_128_rect`]). **Off by default** |
| 804 | /// (`EC_AV1_RECTRES=1` turns it on): OFF is today's behavior bit for bit -- |
| 805 | /// no rect/AB piece can come out non-skip, so the writer's refusal is never |
| 806 | /// reached. The residual shape is the whole 128 block's, halved or quartered |
| 807 | /// per piece: one TX_64X64 luma unit plus a TX_32X32 chroma pair per 64x64 |
| 808 | /// mu chunk, var-tx depth 0 (exactly what the decoder's mu-chunk loop reads |
| 809 | /// for any inter partition shape). |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | |
| 819 | /// Test-only: take the rect/AB pieces' residual arm whatever it costs, so a |
| 820 | /// witness clip codes the shape rather than waiting for content on which the |
| 821 | /// RD picks it (the same role [`FORCE_B128_RESIDUAL`] plays at the NONE |
| 822 | /// root). Never read outside `#[cfg(test)]` builds. |
| 823 | static FORCE_B128_RECTRES: AtomicBool = |
| 824 | new; |
| 825 | |
| 826 | /// Arms [`FORCE_B128_RECTRES`] for the rest of the process. |
| 827 | |
| 828 | pub |
| 829 | |
| 830 | |
| 831 | |
| 832 | /// How many rect/AB pieces the search left WITH a residual rather than |
| 833 | /// skipped, since the last [`take_b128_rectres_hits`] (class |
| 834 | /// `gate-blind-to-feature`). |
| 835 | static B128_RECTRES_HITS: AtomicUsize = new; |
| 836 | |
| 837 | /// The rect/AB-piece-residual count since the last call, and zero it. |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | /// lane-b128r: whether the 128 root offers the COMPOUND candidates the 64 |
| 843 | /// root already does (`NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV`, |
| 844 | /// `NEW_NEARESTMV` over the LAST+GOLDEN / LAST+ALTREF pairs), at the block's |
| 845 | /// own 32x32-mi window. `EC_AV1_B128COMP=0` turns it off, which is this |
| 846 | /// arm's attribution control; the writer has always had the path |
| 847 | /// (`write_inter_block_128` calls `write_compound_block` for a block that |
| 848 | /// names a second reference). |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | /// How many 128 roots came out COMPOUND since the last |
| 859 | /// [`take_b128_compound_hits`] (class `gate-blind-to-feature`). |
| 860 | static B128_COMPOUND_HITS: AtomicUsize = new; |
| 861 | |
| 862 | /// The compound-128 count since the last call, and zero it. |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | /// lane-b128hv: whether the 128 superblock root offers its `PARTITION_HORZ` |
| 868 | /// and `PARTITION_VERT` candidates -- two 128x64 / 64x128 inter blocks, the |
| 869 | /// same skip-only single-reference/compound machinery the NONE arm ships, |
| 870 | /// halved ([`search_root_128_rect`], `crate::tile::write_inter_block_128_rect`). |
| 871 | /// `EC_AV1_B128HV=0` is this arm's attribution control. |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | |
| 878 | /// lane-rectdq: whether the delta_q symbol group is priced on the root |
| 879 | /// candidates that really code it. `EC_AV1_RECTDQ=0` is this fix's |
| 880 | /// attribution control (the pre-lane pricing, where a 128 rect root and the |
| 881 | /// four-superblock arm were both priced as if the group were free). |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | |
| 887 | |
| 888 | /// lane-rectdq: what `crate::tile::write_delta_q` spends to move |
| 889 | /// `CurrentQIndex` from `cur` to `target` at `1 << delta_q_res` steps of |
| 890 | /// `res` -- the same three pieces that writer codes, in its order: the |
| 891 | /// `delta_q_abs` symbol of `min(abs, 3)` against the DEFAULT table (the |
| 892 | /// writer's own `cdfs.delta_q`, which every tile arms fresh, adapts from |
| 893 | /// exactly this row), the escape literal pair when `abs >= 3`, and the sign |
| 894 | /// bit when `abs != 0`. Zero when the plan is disarmed (`res <= 0`). |
| 895 | pub |
| 896 | |
| 897 | |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | /// [`delta_q_bits`] for the 128 superblock root at `(root_r, root_c)` (in 64 |
| 923 | /// superblock units): the group every root shape but a SKIPPED |
| 924 | /// `PARTITION_NONE` root codes, since decode.rs' `whole_sb` asks for |
| 925 | /// `side == write_w == write_h == sb_px` and neither a rect half nor a 64 |
| 926 | /// superblock under a 128 grid is that. |
| 927 | /// |
| 928 | /// The target is the root's own cell of the `sb_q` grid, exactly the entry |
| 929 | /// `write_delta_q` indexes. `CurrentQIndex` is NOT knowable in the search -- |
| 930 | /// the writer's `plan.cur` only advances at the roots that really code a |
| 931 | /// group, and which those are is decided by this very comparison -- so the |
| 932 | /// PREVIOUS 128 root's target in raster order stands in for it (the frame's |
| 933 | /// `base_q_idx` at the first root of the frame, which is also the writer's |
| 934 | /// own per-tile reset). Wrong only where a neighbouring root came out a |
| 935 | /// skipped NONE block, and then only by the difference of two adjacent tpl |
| 936 | /// cells. |
| 937 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 942 | |
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | /// How many 128 roots the search left as two 128x64 (HORZ) / 64x128 (VERT) |
| 965 | /// halves since the last take (class `gate-blind-to-feature`). |
| 966 | static B128_HORZ_HITS: AtomicUsize = new; |
| 967 | /// The VERT twin of [`B128_HORZ_HITS`]. |
| 968 | static B128_VERT_HITS: AtomicUsize = new; |
| 969 | |
| 970 | /// The HORZ-128-root count since the last call, and zero it. |
| 971 | |
| 972 | |
| 973 | |
| 974 | |
| 975 | /// The VERT-128-root count since the last call, and zero it. |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | /// Test-only: force the 128 root's rect partition whatever it costs -- 0 off, |
| 981 | /// 1 `PARTITION_HORZ`, 2 `PARTITION_VERT`. The witness needs it because |
| 982 | /// synthetic content is where the shape is cheapest to decode-check and the |
| 983 | /// RD there prefers one whole block; the gate census is the unforced count. |
| 984 | static FORCE_B128_RECT: AtomicU8 = new; |
| 985 | |
| 986 | /// Arms [`FORCE_B128_RECT`] for the rest of the process (0 / 1 HORZ / 2 VERT). |
| 987 | |
| 988 | pub |
| 989 | |
| 990 | |
| 991 | |
| 992 | /// lane-ab128: whether the 128 superblock root offers its four AB shapes -- |
| 993 | /// `PARTITION_HORZ_A` (two 64x64 on top, one 128x64 below), `_HORZ_B` (one |
| 994 | /// 128x64 on top, two 64x64 below), `_VERT_A` (two 64x64 left, one 64x128 |
| 995 | /// right) and `_VERT_B` (one 64x128 left, two 64x64 right). Every piece is |
| 996 | /// the same skip-only single-reference/compound block the NONE and HORZ/VERT |
| 997 | /// arms ship, at its own footprint ([`search_root_128_ab`], |
| 998 | /// `crate::tile::write_inter_block_128_rect`). `EC_AV1_B128AB=0` is this |
| 999 | /// arm's attribution control. |
| 1000 | /// |
| 1001 | /// **Off by default** (`EC_AV1_B128AB=1` turns it on): measured on both gates |
| 1002 | /// and it does not pay. The shapes fire 0-2 roots a frame against ~1000 coded |
| 1003 | /// blocks (`EC_AV1_B128_CENSUS`), and every row is flat or 0.1 worse -- |
| 1004 | /// long-GOP film A +22.0/-8.5 against a +21.9/-8.6 control, film B +75.8/+0.8 |
| 1005 | /// against the same, 12-frame film A +18.1/-6.2 against +18.0/-6.3, film B |
| 1006 | /// +23.1/-3.3 against +23.0/-3.5, screen byte-identical (lane-ab128). The |
| 1007 | /// machinery is written, witnessed sample-exact through both decoders on all |
| 1008 | /// four shapes, and kept for the arm that makes it pay: a non-skip piece (the |
| 1009 | /// 64x64 pieces could carry the 64 root's residual, which is where libaom's |
| 1010 | /// AB shapes earn their keep) or a cheaper partition price. |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | /// How many 128 roots the search left as each AB shape since the last take, |
| 1018 | /// in `PARTITION_HORZ_A`, `_HORZ_B`, `_VERT_A`, `_VERT_B` order (class |
| 1019 | /// `gate-blind-to-feature`). |
| 1020 | static B128_AB_HITS: = |
| 1021 | ; |
| 1022 | |
| 1023 | /// The four per-shape AB-root counts since the last call, and zero them. |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | /// Test-only: force the 128 root's AB shape whatever it costs -- 0 off, then |
| 1029 | /// 4..=7, the partition symbol itself ([`force_b128_rect`]'s twin; synthetic |
| 1030 | /// content is where the shapes are cheapest to decode-check and the RD there |
| 1031 | /// prefers one whole block). |
| 1032 | static FORCE_B128_AB: AtomicU8 = new; |
| 1033 | |
| 1034 | /// Arms [`FORCE_B128_AB`] for the rest of the process (0 off, else 4..=7). |
| 1035 | |
| 1036 | pub |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | /// lane-ab128: the three pieces of an AB shape at a 128 root, in the order |
| 1041 | /// libaom's `decode_partition` codes them and decode.rs' `sb128_ab` arm |
| 1042 | /// reads them (decode.rs ~35269) -- HORZ_A = TL, TR, bottom half; HORZ_B = |
| 1043 | /// top half, BL, BR; VERT_A = TL, BL, right half; VERT_B = left half, TR, BR. |
| 1044 | /// Each entry is the piece's own top-left in mode-info units and its |
| 1045 | /// footprint in samples. |
| 1046 | pub |
| 1047 | |
| 1048 | |
| 1049 | |
| 1050 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | /// Test-only: take the 128 root's residual arm whatever it costs, so a |
| 1066 | /// witness clip codes the shape rather than waiting for content on which the |
| 1067 | /// RD picks it (the same role [`force_sb128`] plays for the superblock size). |
| 1068 | /// Never read outside `#[cfg(test)]` builds. |
| 1069 | static FORCE_B128_RESIDUAL: AtomicBool = |
| 1070 | new; |
| 1071 | |
| 1072 | /// Test-only twin of [`FORCE_B128_RESIDUAL`] for the PARTITION decision: take |
| 1073 | /// the 128 root whenever it produced a candidate at all, whatever its four |
| 1074 | /// cells cost, so a witness codes the block it is about rather than waiting |
| 1075 | /// for content on which the root also wins its own comparison. |
| 1076 | static FORCE_B128_ROOT: AtomicBool = new; |
| 1077 | |
| 1078 | /// Arms [`FORCE_B128_RESIDUAL`] -- and with it [`FORCE_B128_ROOT`], since a |
| 1079 | /// forced residual block only reaches the writer if its root is taken. |
| 1080 | |
| 1081 | pub |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | /// Arms [`FORCE_B128_ROOT`] for the rest of the process. |
| 1087 | |
| 1088 | pub |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | /// How many 128 roots came out cheaper WITH a residual than skipped, since |
| 1093 | /// the last [`take_b128_residual_hits`] (class `gate-blind-to-feature`). |
| 1094 | static B128_RESIDUAL_HITS: AtomicUsize = new; |
| 1095 | |
| 1096 | /// The 128-residual count since the last call, and zero it. |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | /// How many 128x128 `PARTITION_NONE` roots the search took since the last |
| 1102 | /// [`take_b128_none_hits`] (class `gate-blind-to-feature`): a flat BD result |
| 1103 | /// is only attributable once the fire count is known. |
| 1104 | static B128_NONE_HITS: AtomicUsize = new; |
| 1105 | |
| 1106 | /// The 128x128-root count since the last call, and zero it. |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | /// Rate-distortion optimised quantisation ([`crate::tile::rdoq`], lane-rdoq). |
| 1112 | /// Preset-gated: it re-prices the block once per candidate level, so it buys |
| 1113 | /// bits with wall (see `crate::speed::RDOQ` for the per-preset table). |
| 1114 | /// |
| 1115 | /// `EC_AV1_RDOQ=0` in any build restores the plain deadzone quantiser -- |
| 1116 | /// which is what the byte pins are taken under when they name it. |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | /// The rate weight [`crate::tile::rdoq`] trades bits for squared error at, in |
| 1124 | /// units of one squared AC quantiser step -- the search's own |
| 1125 | /// [`LAMBDA_SCALE`], so the quantiser and the mode search speak one currency. |
| 1126 | /// |
| 1127 | /// The per-frame factors the search multiplies onto it ([`key_lambda_factor`], |
| 1128 | /// [`hidden_lambda_factor`], both 1.0 as shipped) and the per-superblock |
| 1129 | /// temporal map ([`tpl_lambda_factors`]) are NOT threaded down here: |
| 1130 | /// corner-cut, ceiling = a superblock the temporal map weighs away from the |
| 1131 | /// frame average has its coefficients optimised at the frame's weight. The |
| 1132 | /// upgrade is one `lambda` field on the trial call sites, which is the whole |
| 1133 | /// mode-search argument list. |
| 1134 | /// |
| 1135 | /// SWEPT (lane-rdoq, 12-frame `bd_rate_screen_native`, BD vs libaom |
| 1136 | /// `cpu-used 6` on the three real rows). The bowl is a factor of TWO above |
| 1137 | /// the mode search's own weight, and it is the same multiplier on all three |
| 1138 | /// rows: |
| 1139 | /// |
| 1140 | /// | `EC_AV1_RDOQ_LAMBDA` | film A | film B | screen | |
| 1141 | /// |---|---|---|---| |
| 1142 | /// | 0.7 | +27.6 | +39.5 | +29.6 | |
| 1143 | /// | 1.0 | +26.3 | +37.5 | +29.1 | |
| 1144 | /// | 1.3 | +25.6 | +37.0 | +28.8 | |
| 1145 | /// | 1.6 | +24.6 | +35.9 | +28.7 | |
| 1146 | /// | 2.2 (shipped) | +24.4 | +35.5 | +28.1 | |
| 1147 | /// | 3.2 | +24.7 | +36.1 | +29.4 | |
| 1148 | /// |
| 1149 | /// A coefficient's rate is worth twice here what the mode search prices it |
| 1150 | /// at, and the likeliest reason is that the price is taken against tables |
| 1151 | /// that have not adapted yet ([`crate::tile::coeff_bits`]): a block coded |
| 1152 | /// late in a frame whose `txb_skip`/`base` tables have narrowed really costs |
| 1153 | /// less than the pricer says, and this pass is the one decision taken per |
| 1154 | /// COEFFICIENT, so it feels that error most. The honest fix is an adapted |
| 1155 | /// price, not a fitted multiplier; this is the fitted multiplier, and its |
| 1156 | /// bowl is measured rather than assumed. |
| 1157 | const RDOQ_LAMBDA_MULT: f64 = 2.2; |
| 1158 | |
| 1159 | /// [`RDOQ_LAMBDA_MULT`], or what `EC_AV1_RDOQ_LAMBDA` names (the rate-term |
| 1160 | /// calibration sweep). |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | /// [`B64_ROOT`], or what `EC_AV1_B64` names. |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | /// The KEY frame's own 64x64 root (lane-i64): the whole superblock searched |
| 1179 | /// as ONE intra block -- every mode the 32x32 search offers, one TX_64X64 |
| 1180 | /// luma transform (`TxbSet::Luma64`, whose coded quarter is the 32x32 corner) |
| 1181 | /// and one TX_32X32 per chroma plane -- and compared against the four 32x32 |
| 1182 | /// quadrants at the same lambda, exactly the shape the inter root |
| 1183 | /// ([`B64_ROOT`]) takes on an inter frame. The writer has always been able to |
| 1184 | /// code one (`crate::tile::sb_coeff_key_frame_tile`'s `Superblock::Whole`); |
| 1185 | /// nothing produced one, so the key frame -- 21.6% of a real film stream -- |
| 1186 | /// coded every superblock split while libaom and rav1e leave 45-54% of theirs |
| 1187 | /// whole. |
| 1188 | /// |
| 1189 | /// No CfL (spec `is_cfl_allowed` stops at 32x32, and `search_chroma` gates on |
| 1190 | /// it), no filter intra (`filter_intra_size_class` has no 64 row) and no |
| 1191 | /// transform-depth split (the writer's `Superblock::Whole` arm takes a 32x32 |
| 1192 | /// level grid, so only depth 0 is representable) -- the root is refused |
| 1193 | /// outright on an `allow_intrabc` frame, whose quadrant searches carry DV |
| 1194 | /// state a discarded trial would desync. |
| 1195 | /// |
| 1196 | /// Switched off by `EC_AV1_I64=0` in any build. |
| 1197 | pub const I64_ROOT: bool = true; |
| 1198 | |
| 1199 | /// How many key-frame superblocks were coded as one 64x64 intra block since |
| 1200 | /// the last [`take_i64_root_hits`], so a gate reports the fire rate rather |
| 1201 | /// than assuming it (class `gate-blind-to-feature`). |
| 1202 | /// Index 1 is how many were OFFERED the trial at all, so a gate reads a |
| 1203 | /// SHARE and not a bare count, and index 2 how many of the whole ones sat on |
| 1204 | /// a superblock the true frame edge CUTS THROUGH (lane-corner) -- the |
| 1205 | /// `gate-blind-to-feature` guard for the edge path, which no |
| 1206 | /// superblock-aligned clip fires at all. |
| 1207 | static I64_HITS: = |
| 1208 | ; |
| 1209 | |
| 1210 | /// The key-frame `(whole, offered, edge)` 64x64-intra-root counts since the |
| 1211 | /// last call, and zero them. |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | /// [`I64_ROOT`], or what `EC_AV1_I64` names. |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | /// Whether the 64x64 root also prices a NON-skip candidate (lane-tx64): the |
| 1224 | /// winner's prediction through one TX_64X64 luma transform and two TX_32X32 |
| 1225 | /// chroma ones. Off by `EC_AV1_B64RES=0`, which restores the skip-only root |
| 1226 | /// lane-b64 shipped, so the two can be measured against each other on the |
| 1227 | /// same build. |
| 1228 | /// |
| 1229 | /// MEASURED on the native gate (two arms of one build, baseline reproduced to |
| 1230 | /// the tenth): both film rows improve on both columns -- film A |
| 1231 | /// +43.0/+15.0 -> +42.9/+14.8, film B +64.7/+34.0 -> +63.3/+31.5 -- and |
| 1232 | /// SCREEN CAPTURE loses +33.4/-23.8 -> +34.3/-23.4, outside the keep rule's |
| 1233 | /// +-0.3 screen clause. So the caller gates this off on a screen frame |
| 1234 | /// (`allow_screen_content_tools`), the same content gate the coding pyramid |
| 1235 | /// takes: a desktop capture's 64x64 superblocks are flat runs whose skip arm |
| 1236 | /// already codes them for nothing, and a residual there only spends bits the |
| 1237 | /// intra/palette tools would have spent better. |
| 1238 | /// |
| 1239 | /// CENSUS on film B (12 frames, q120, `EC_AV1_BITCENSUS=1` + |
| 1240 | /// `examples/syntax_census.rs`, both streams read by OUR decoder), off vs on: |
| 1241 | /// |
| 1242 | /// | | skip-only | + residual | |
| 1243 | /// |---|---|---| |
| 1244 | /// | 64x64 share, all frames | 36.4% | 38.3% | |
| 1245 | /// | 64x64 share, leaf frames | 53.3% | 56.0% | |
| 1246 | /// | skip area, all frames | 80.4% | 78.8% | |
| 1247 | /// | skip area, leaf frames | 90.2% | 88.5% | |
| 1248 | /// | stream bytes | 34,366 | 34,295 | |
| 1249 | /// | encoder wall | 13.4s | 9.6s | |
| 1250 | /// |
| 1251 | /// `base_luma_64` enters the leaf frames' top tables at 5.7%, i.e. the |
| 1252 | /// TX_64X64 coefficients are really being coded. The root wins MORE often |
| 1253 | /// with a residual to offer (rav1e speed 6's own 64x64 share on this clip is |
| 1254 | /// 45.2%), which is also why the arm is 28% FASTER despite costing three more |
| 1255 | /// transforms per superblock: a root that wins is four quadrant searches that |
| 1256 | /// never run. |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | /// How many 64x64 roots came out cheaper with a residual than skipped, since |
| 1264 | /// the last [`take_b64_residual_hits`] -- so a gate reports the fire rate |
| 1265 | /// rather than assuming one (class `gate-blind-to-feature`). |
| 1266 | static B64_RESIDUAL_HITS: AtomicUsize = new; |
| 1267 | |
| 1268 | /// The non-skip 64x64-root count since the last call, and zero it. |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | /// Whether the 64x64 root also prices COMPOUND candidates (lane-b64b): the |
| 1274 | /// `LAST` + extra-reference pairs the 32x32 level already offers, at the |
| 1275 | /// three modes a root can form without a second 64x64 motion search -- |
| 1276 | /// `NEAREST_NEARESTMV`, `GLOBAL_GLOBALMV` and `NEW_NEARESTMV` (whose NEW half |
| 1277 | /// is the vector `search_skip_64`'s own single-reference search already |
| 1278 | /// found). `NEAREST_NEWMV`/`NEW_NEWMV` need the SECOND reference's own |
| 1279 | /// `NEWMV` vector, which only a second search per superblock produces -- the |
| 1280 | /// wall this root exists to save -- so they are not offered here. |
| 1281 | /// |
| 1282 | /// Off by `EC_AV1_B64COMP=0`, so both arms measure on one build. |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | /// How many 64x64 roots took a COMPOUND candidate since the last |
| 1293 | /// [`take_b64_compound_hits`] (class `gate-blind-to-feature`). |
| 1294 | static B64_COMPOUND_HITS: AtomicUsize = new; |
| 1295 | |
| 1296 | /// The compound 64x64-root count since the last call, and zero it. |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | /// Whether a 64x64 root that codes a residual may SPLIT its luma transform |
| 1302 | /// (lane-b64b): four TX_32X32 units instead of the one TX_64X64, decided by |
| 1303 | /// [`commit_inter_luma`] like every other inter block's var-tx, and coded by |
| 1304 | /// the writer's `Whole64` arm as `txfm_split = 1`. It exists because |
| 1305 | /// TX_64X64 zeroes everything outside its 32x32 corner, so a root whose |
| 1306 | /// residual has detail in the other three quadrants cannot code it at all. |
| 1307 | /// |
| 1308 | /// Off by `EC_AV1_B64VARTX=0`. |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | /// How many 64x64 roots split their luma transform since the last |
| 1319 | /// [`take_b64_var_tx_hits`]. |
| 1320 | static B64_VAR_TX_HITS: AtomicUsize = new; |
| 1321 | |
| 1322 | /// The split-luma 64x64-root count since the last call, and zero it. |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | /// Whether a superblock the true frame edge CUTS THROUGH may be left whole |
| 1328 | /// (lane-b64b). AV1 asks only that the block's own half is inside |
| 1329 | /// (`has_cols`/`has_rows`, spec `decode_partition`), and the writer already |
| 1330 | /// codes that case; what was missing was a trial whose SSE is scored over the |
| 1331 | /// INSIDE part alone ([`Plane::block_sse`], which clips since lane-sse) |
| 1332 | /// instead of over the padding the encoder |
| 1333 | /// invented past the edge. Both gate films are superblock-aligned, so this |
| 1334 | /// only reaches the user's own arbitrary export sizes. |
| 1335 | /// |
| 1336 | /// Off by `EC_AV1_B64EDGE=0`. |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | /// What `EC_AV1_B64EDGE` names on its own, without the inter root's own |
| 1342 | /// preset switch -- the key frame's root ([`I64_ROOT`]) reads the same flag |
| 1343 | /// but is gated by [`i64_root`]. |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | /// How many 64x64 roots the frame edge cut through since the last |
| 1354 | /// [`take_b64_edge_hits`] (class `gate-blind-to-feature`: both gate films are |
| 1355 | /// superblock-aligned, so nothing but a synthetic size fires this). |
| 1356 | static B64_EDGE_HITS: AtomicUsize = new; |
| 1357 | |
| 1358 | /// The edge 64x64-root count since the last call, and zero it. |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | /// Whether the encoder searches loop restoration at all (spec 7.17): one |
| 1364 | /// Wiener filter per 64x64 luma restoration unit, picked from |
| 1365 | /// [`crate::filter_search::WIENER_CANDIDATES`]. Swept by `EC_AV1_LR` in a |
| 1366 | /// test build, like [`lambda_scale`]. |
| 1367 | pub const RESTORATION: bool = true; |
| 1368 | |
| 1369 | /// [`RESTORATION`], or what `EC_AV1_LR` names in a test build. |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | /// libaom's `partition_search_breakout` shape: how many non-zero luma |
| 1378 | /// coefficients per 256 luma samples a block may code and still be judged |
| 1379 | /// well enough predicted that the split below it is not worth trying. `0` |
| 1380 | /// disables the breakout (only the existing all-skip prune applies), which |
| 1381 | /// is the default until the sweep below justifies otherwise. |
| 1382 | /// |
| 1383 | /// Swept on the BD gate (`EC_AV1_SPLIT_BREAKOUT`, test builds only), which |
| 1384 | /// is where this lane's wall would have gone: 1 cuts the three clips' |
| 1385 | /// encode wall 6.3/6.0/6.2 s -> 3.6/3.2/4.4 s but costs +18.4/+24.0/+7.9 |
| 1386 | /// BD-rate points against libaom; 2 costs +23.4/+29.4/+18.8 and 4 costs |
| 1387 | /// +31.7/+40.6/+27.8, for barely more speed. The split trial is where this |
| 1388 | /// encoder's inter quality lives, so `0` ships and the knob stays for a |
| 1389 | /// future explicit speed preset. |
| 1390 | pub const SPLIT_BREAKOUT_COEFFS: usize = 0; |
| 1391 | |
| 1392 | /// libaom's `partition_search_breakout_rate_thr` shape, in this encoder's own |
| 1393 | /// currency: a 32x32 inter block whose whole-block RD cost per pixel comes |
| 1394 | /// out under `threshold * lambda` is not offered the split at all, and a |
| 1395 | /// 16x16 leaf under it is not offered the 8x8 split. `0.0` offers both |
| 1396 | /// always, as before this lever. |
| 1397 | /// |
| 1398 | /// The census is what points here: the split trial runs on nearly every |
| 1399 | /// non-skip block (15132 leaf searches per ladder point on the 1080p clip) |
| 1400 | /// and wins 7.6% of the time on film, 3.0% on screen -- yet the coefficient |
| 1401 | /// -count breakout ([`SPLIT_BREAKOUT_COEFFS`]) that prunes it costs 18-31 BD |
| 1402 | /// points, so the gate has to read the block's own RD cost, not its levels. |
| 1403 | /// |
| 1404 | /// Swept on the BD gate over 0.125/0.25/0.5/1.0 (vs libaom, against a base of |
| 1405 | /// +121.1/+146.1/+79.3): 0.125 is +121.2/+146.4/+79.1 (+0.1/+0.3/-0.2) for |
| 1406 | /// -10.0%/-5.7% instructions (1080p/screen, `perf stat` ABAB x2) and |
| 1407 | /// -7.7/-8.6/-4.5% wall; 0.25 already costs +0.7/+0.6/+0.6, 0.5 costs |
| 1408 | /// +3.5/+4.7/+1.8 for -15% wall, and 1.0 costs +19/+27/+6. So 0.125 ships -- |
| 1409 | /// the largest threshold whose BD stays inside the +0.3 keep rule on every |
| 1410 | /// clip. |
| 1411 | /// RE-SWEPT on lane-av1rejudge at [`LAMBDA_SCALE`] 0.05 with warp on (base |
| 1412 | /// +16.7/-0.5, +47.0/+19.1, +51.3/-14.3): 0.0625 is +16.9/-0.4, +47.0/+19.1, |
| 1413 | /// +51.3/-14.2 (the 1080p film 0.2 worse for a finer search) and 0.25 is |
| 1414 | /// +16.6/-0.6, +46.9/+19.1, +51.6/-14.5 (screen 0.3 worse vs libaom, 3s off |
| 1415 | /// the screen wall). Neither clears the keep rule; 0.125 stays. |
| 1416 | pub const SPLIT_RD_THRESHOLD: f64 = 0.125; |
| 1417 | |
| 1418 | /// [`SPLIT_RD_THRESHOLD`], swept by `EC_AV1_SPLIT_RD` in any build. |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | |
| 1428 | /// Whether `cost` over a `side` x `side` block is cheap enough per pixel that |
| 1429 | /// [`split_rd_threshold`] withholds the split trial. |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | |
| 1434 | /// [`split_rd_breakout`] at an explicit threshold -- what the 64x64 root's own |
| 1435 | /// early-out reads. |
| 1436 | |
| 1437 | |
| 1438 | |
| 1439 | |
| 1440 | /// The threshold the 64x64 root's early-out uses: [`split_rd_threshold`] |
| 1441 | /// CLAMPED at the shipped [`SPLIT_RD_THRESHOLD`] (lane-tx64). |
| 1442 | /// |
| 1443 | /// The 32x32 level is allowed to loosen its breakout with the speed preset |
| 1444 | /// (`crate::speed::SPLIT_RD` steps to 0.5 at preset 6), but lane-b64 measured |
| 1445 | /// what that does one size up: at 0.5 a whole superblock is taken at 64x64 |
| 1446 | /// without its four quadrants ever being searched, and film B goes |
| 1447 | /// +91.5/+53.4 -> +114.6/+71.5. A 64x64 block is four times the area, so the |
| 1448 | /// same per-pixel threshold withholds four times as much search -- the |
| 1449 | /// preset's step is priced for the 32 level and does not carry up here. |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | /// [`SPLIT_BREAKOUT_COEFFS`], swept by `EC_AV1_SPLIT_BREAKOUT` in a test |
| 1455 | /// build. |
| 1456 | |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | /// How often each partition decision was taken since the last |
| 1464 | /// [`take_partition_hits`], so a gate can report how often a new partition |
| 1465 | /// fires rather than assume it does (gate-blind-to-feature). Index 0 is an |
| 1466 | /// inter 32x32 block left whole, 1 one split into four 16x16 leaves; 2 is |
| 1467 | /// such a leaf left whole, 3 one split into four 8x8 leaves of its own. |
| 1468 | static PARTITION_HITS: = |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | ; |
| 1474 | |
| 1475 | /// Records one such decision. |
| 1476 | |
| 1477 | |
| 1478 | |
| 1479 | |
| 1480 | /// Takes (and clears) the counts. |
| 1481 | |
| 1482 | pub |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | /// Whether the trial-set census (`EC_AV1_CENSUS=1`) is on: how many full |
| 1487 | /// rate-distortion trials the block search actually runs, by kind, and where |
| 1488 | /// the winner sat in the cheap SAD ranking the pruning levers rank by. Off by |
| 1489 | /// default, and a measurement build rather than a speed one -- the census |
| 1490 | /// runs the SAD pre-pass the unpruned search otherwise skips. |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | /// What each [`CENSUS`] counter counts. |
| 1497 | pub const CENSUS_KINDS: = |
| 1498 | |
| 1499 | |
| 1500 | |
| 1501 | |
| 1502 | |
| 1503 | |
| 1504 | |
| 1505 | |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | ; |
| 1510 | |
| 1511 | /// The census counters themselves, indexed by [`CENSUS_KINDS`]. |
| 1512 | static CENSUS: = |
| 1513 | ; |
| 1514 | |
| 1515 | /// Where the RD winner sat in the SAD ranking, for the luma intra search and |
| 1516 | /// the chroma mode search -- what says whether a top-N prune would have kept |
| 1517 | /// the block the search actually chose. |
| 1518 | static LUMA_RANK: = |
| 1519 | ; |
| 1520 | static CHROMA_RANK: = |
| 1521 | ; |
| 1522 | |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | /// Reads (and clears) the census, so a driver can attribute it to its own encode. |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | /// The rank of `winner` in `scored` ordered by its cheap score, cheapest |
| 1540 | /// first -- the census's one shared rule, so the luma and chroma histograms |
| 1541 | /// mean the same thing. |
| 1542 | |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | |
| 1551 | |
| 1552 | |
| 1553 | |
| 1554 | |
| 1555 | |
| 1556 | /// Whether a 32x32 block may be split into four 16x16 ones when the trial says |
| 1557 | /// four cost less. Set from the measurement in the lane report. |
| 1558 | const SPLIT_BLOCKS: bool = true; |
| 1559 | |
| 1560 | /// What [`encode_key_frame_with_modes`] codes with, which the sweep overrides |
| 1561 | /// by calling [`encode_key_frame_inner`] both ways. |
| 1562 | pub |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | /// One planar 4:2:0 picture. `y`/`u`/`v` hold one sample per position as |
| 1567 | /// `u16` regardless of bit depth (`crate::decode`'s own `PlaneBuf` has used |
| 1568 | /// `u16` throughout since the round-hbd-r1/r2 widen; this is the last |
| 1569 | /// narrowing boundary that stayed `u8` -- widened lane-hbd r3 so a 10-bit |
| 1570 | /// stream's decode output actually carries 10-bit precision instead of |
| 1571 | /// silently losing its low 2 bits). The encoder only ever produces values in |
| 1572 | /// `0..=255` (it is still 8-bit-only by design, see `encode.rs`'s r2 |
| 1573 | /// decision); `Plane::source` narrows right back to `u8` at its two |
| 1574 | /// construction sites, a lossless round trip for that range. |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | |
| 1614 | |
| 1615 | |
| 1616 | |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | |
| 1628 | |
| 1629 | |
| 1630 | |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | |
| 1668 | |
| 1669 | |
| 1670 | |
| 1671 | |
| 1672 | |
| 1673 | |
| 1674 | |
| 1675 | |
| 1676 | |
| 1677 | |
| 1678 | |
| 1679 | |
| 1680 | |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | |
| 1687 | |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | |
| 1692 | /// lane-hbd r2: the encoder's own reconstruction/source buffers stay `u8` |
| 1693 | /// (8-bit only, unchanged this round -- widening the encoder is out of this |
| 1694 | /// round's scope, see `lanes/hbd-r2.report.md`); this is the local box that |
| 1695 | /// lets it keep calling [`crate::intra::predict`] now that shape is `u16` |
| 1696 | /// in and out. A block-sized round-trip through `u16` is exact for 8-bit |
| 1697 | /// content (every value fits both ways), so this changes no encoder output. |
| 1698 | |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | |
| 1708 | |
| 1709 | |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | |
| 1716 | |
| 1717 | |
| 1718 | |
| 1719 | |
| 1720 | |
| 1721 | |
| 1722 | |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | |
| 1732 | |
| 1733 | |
| 1734 | |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | |
| 1739 | |
| 1740 | |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | |
| 1750 | |
| 1751 | |
| 1752 | |
| 1753 | |
| 1754 | |
| 1755 | |
| 1756 | |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | |
| 1766 | |
| 1767 | |
| 1768 | /// [`intra_predict_u8`] for recursive filter intra (spec 7.11.2.3): the same |
| 1769 | /// `u8` box around [`crate::intra::predict_filter_intra`], whose `mode` is one |
| 1770 | /// of the five `FILTER_INTRA_MODES` rather than an ordinary intra mode. |
| 1771 | |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | |
| 1787 | |
| 1788 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | |
| 1809 | |
| 1810 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last |
| 1811 | /// row and column, so the block coder always sees a whole number of blocks. |
| 1812 | /// [`crop_plane`] undoes this on the way back out. |
| 1813 | |
| 1814 | |
| 1815 | |
| 1816 | |
| 1817 | |
| 1818 | |
| 1819 | |
| 1820 | |
| 1821 | |
| 1822 | |
| 1823 | |
| 1824 | |
| 1825 | |
| 1826 | |
| 1827 | |
| 1828 | |
| 1829 | |
| 1830 | /// The top-left `width` x `height` region of a plane that is `padded_width` |
| 1831 | /// wide, which is the render-size crop [`Picture::padded`]'s replication |
| 1832 | /// exists to let a decoder undo. |
| 1833 | |
| 1834 | |
| 1835 | |
| 1836 | |
| 1837 | |
| 1838 | |
| 1839 | |
| 1840 | |
| 1841 | /// [`Encoded::reconstruction`] cropped to `(width, height)`: the render-size |
| 1842 | /// region a decoder produces, which is the public contract for what a caller |
| 1843 | /// sees back — the padded planes the encoder coded against never leave this |
| 1844 | /// module. Identity when the reconstruction is already that size. |
| 1845 | /// |
| 1846 | /// The chroma extent is `ROUND_POWER_OF_TWO(size, 1)` -- `(size + 1) / 2`, |
| 1847 | /// libaom's `av1_common_plane_width` (`av1/common/av1_common_int.h`) -- so an |
| 1848 | /// ODD declared luma size keeps the chroma column a decoder keeps (a 65-wide |
| 1849 | /// 4:2:0 frame has 33, not 32). Every even size is unaffected: `(2k+1)/2 == |
| 1850 | /// k`, so this is a no-op for every caller `encode_key_frame`'s even-size |
| 1851 | /// check lets through. |
| 1852 | pub |
| 1853 | |
| 1854 | |
| 1855 | |
| 1856 | |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | |
| 1875 | |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | |
| 1882 | |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | |
| 1887 | |
| 1888 | |
| 1889 | /// A `Cdfs` inside a `Debug` type: the tables are tens of kilobytes of |
| 1890 | /// numbers nobody wants printed, and [`Encoded`] derives `Debug`. |
| 1891 | |
| 1892 | pub crateCdfs); |
| 1893 | |
| 1894 | |
| 1895 | |
| 1896 | |
| 1897 | |
| 1898 | |
| 1899 | |
| 1900 | /// What one call to [`encode_key_frame`] produced. |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | |
| 1937 | |
| 1938 | |
| 1939 | |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | |
| 1944 | |
| 1945 | |
| 1946 | |
| 1947 | |
| 1948 | |
| 1949 | |
| 1950 | |
| 1951 | |
| 1952 | |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | |
| 1958 | |
| 1959 | |
| 1960 | |
| 1961 | |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | |
| 1970 | |
| 1971 | |
| 1972 | |
| 1973 | |
| 1974 | |
| 1975 | |
| 1976 | |
| 1977 | |
| 1978 | |
| 1979 | |
| 1980 | |
| 1981 | |
| 1982 | |
| 1983 | |
| 1984 | |
| 1985 | |
| 1986 | |
| 1987 | |
| 1988 | |
| 1989 | |
| 1990 | |
| 1991 | |
| 1992 | |
| 1993 | |
| 1994 | |
| 1995 | |
| 1996 | |
| 1997 | |
| 1998 | |
| 1999 | |
| 2000 | thread_local! |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | |
| 2006 | |
| 2007 | /// [`IBC_SHARE`] for the last key frame encoded on this thread. |
| 2008 | // read only from the `#[cfg(test)]` gates |
| 2009 | pub |
| 2010 | |
| 2011 | |
| 2012 | |
| 2013 | thread_local! |
| 2014 | |
| 2015 | |
| 2016 | |
| 2017 | |
| 2018 | |
| 2019 | |
| 2020 | |
| 2021 | |
| 2022 | |
| 2023 | |
| 2024 | |
| 2025 | |
| 2026 | |
| 2027 | thread_local! |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | thread_local! |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | |
| 2043 | |
| 2044 | |
| 2045 | |
| 2046 | |
| 2047 | |
| 2048 | /// The pyramid the last sequence coded on this thread was EFFECTIVELY under. |
| 2049 | // read only from the `#[cfg(test)]` gates |
| 2050 | pub |
| 2051 | |
| 2052 | |
| 2053 | |
| 2054 | |
| 2055 | pub |
| 2056 | |
| 2057 | |
| 2058 | |
| 2059 | // lane-fintra: [`force_screen`] for the filter-intra candidate, so a MODE |
| 2060 | // ablation can measure the mode search alone. Setting it also clears the |
| 2061 | // sequence header's own `enable_filter_intra` bit, so the stream the arm |
| 2062 | // writes is exactly the one this encoder wrote before the lane. |
| 2063 | |
| 2064 | thread_local! |
| 2065 | |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | pub |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | pub |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | |
| 2078 | |
| 2079 | |
| 2080 | |
| 2081 | /// How many distinct colours a 16x16 luma block may hold and still count as |
| 2082 | /// screen content ([`screen_content`]), `EC_AV1_SCREEN_COLORS`. libaom's own |
| 2083 | /// `av1_set_screen_content_options` bound is 4, which separates nothing on |
| 2084 | /// lossily coded (so noisy) material: `probe_screen_detect` sweeps N against |
| 2085 | /// the variance floor below on the five gate clips at BOTH the native crop |
| 2086 | /// and the 640x384 gate's scale, and 16 colours / var > 16 / an eighth of |
| 2087 | /// the frame is the widest-margin split of those ten rows -- every |
| 2088 | /// non-screen row at most 9.6% of blocks (bars 3.6/2.3 native, 9.6/9.5 |
| 2089 | /// scaled; film A 0.6/0.3, film B 0.5/0.9) against the OBS capture's 23.6% |
| 2090 | /// native and 17.9% scaled. |
| 2091 | |
| 2092 | |
| 2093 | |
| 2094 | |
| 2095 | |
| 2096 | |
| 2097 | |
| 2098 | |
| 2099 | |
| 2100 | |
| 2101 | /// The reciprocal of the frame area those blocks must cover, in tenths -- |
| 2102 | /// libaom's own `counts * blk_h * blk_w * 10 > width * height` is a tenth; |
| 2103 | /// 8 (an eighth) is the midpoint of the two populations |
| 2104 | /// `probe_screen_detect` measures at the colour bound and variance floor |
| 2105 | /// around it. `EC_AV1_SCREEN_PCT`. |
| 2106 | |
| 2107 | |
| 2108 | |
| 2109 | |
| 2110 | |
| 2111 | |
| 2112 | |
| 2113 | |
| 2114 | |
| 2115 | |
| 2116 | /// The per-pixel variance a few-colour block must clear before it counts as |
| 2117 | /// screen content, `EC_AV1_SCREEN_VAR`. libaom keeps the same term (its |
| 2118 | /// `counts_2`/`var_thresh` in `av1_set_screen_content_options`); without it |
| 2119 | /// a smooth dark film frame is all few-colour blocks and reads as a desktop |
| 2120 | /// capture -- which is exactly what this detector did until 2026-09-07, when |
| 2121 | /// it called BOTH real films screen content on 48/48 frames, priced every |
| 2122 | /// coefficient against the default CDFs and ran the palette search over |
| 2123 | /// film. `probe_screen_detect`: at 16 colours the floor takes both films |
| 2124 | /// from 46.2/52.5% of blocks to 0.6/0.5% and the capture only from 29.9% to |
| 2125 | /// 23.6%. |
| 2126 | |
| 2127 | |
| 2128 | |
| 2129 | |
| 2130 | |
| 2131 | |
| 2132 | |
| 2133 | |
| 2134 | |
| 2135 | |
| 2136 | /// How many frames [`screen_content`] said yes/no to, so a gate can print |
| 2137 | /// whether the detector fired at all (class `gate-blind-to-feature`). |
| 2138 | pub static SCREEN_FRAMES: = |
| 2139 | ; |
| 2140 | |
| 2141 | /// `av1_set_screen_content_options` (av1/encoder/encoder.c), luma only: count |
| 2142 | /// the distinct colours of every 16x16 block and turn the screen-content |
| 2143 | /// tools on when the blocks holding between 2 and [`screen_colors`] of them |
| 2144 | /// AND clearing [`screen_var`] cover more than a [`screen_pct`]th of the |
| 2145 | /// frame. `width` is the plane's |
| 2146 | /// stride, `true_*` the frame's real (decodable) extent. |
| 2147 | |
| 2148 | |
| 2149 | |
| 2150 | |
| 2151 | |
| 2152 | |
| 2153 | |
| 2154 | |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | |
| 2159 | |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | |
| 2164 | |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | |
| 2188 | /// Whether this SOURCE picture reads as screen content, for a caller that has |
| 2189 | /// to decide something BEFORE the frame is coded: [`crate::encoder::Av1Encoder`] |
| 2190 | /// gates its coding pyramid on this (a desktop capture keeps the flat |
| 2191 | /// one-in-one-out structure the BD gate measured it on, camera material takes |
| 2192 | /// the mini-GOP). The key frame runs the same detector again when it builds |
| 2193 | /// its header -- that is the run the [`SCREEN_FRAMES`] histogram is meant to |
| 2194 | /// count, so this probe undoes its own tick and leaves the gate prints |
| 2195 | /// reading one detection per coded frame. |
| 2196 | pub |
| 2197 | |
| 2198 | |
| 2199 | |
| 2200 | |
| 2201 | |
| 2202 | |
| 2203 | /// The sequence and frame headers a picture of this size is coded under: one |
| 2204 | /// tile, one transform size per block, no in-loop filter parameters yet |
| 2205 | /// (`crate::encode::pick_and_apply_filters` fills the deblocking levels and |
| 2206 | /// CDEF strengths in once the tile is coded), no CDF adaptation |
| 2207 | /// and no tool the tile writer does not code. |
| 2208 | /// |
| 2209 | /// # Errors |
| 2210 | /// Returns an error when the picture is larger than the 16-bit frame size the |
| 2211 | /// sequence header carries. |
| 2212 | |
| 2213 | |
| 2214 | |
| 2215 | |
| 2216 | |
| 2217 | |
| 2218 | |
| 2219 | |
| 2220 | /// [`ColorConfig`] with every CICP field "unspecified" (H.273 value 2) and |
| 2221 | /// studio (limited) range: what this crate's sequence header carried before |
| 2222 | /// [`crate::encoder`]'s facade could configure it, and what |
| 2223 | /// [`key_frame_headers`] still asks for. |
| 2224 | |
| 2225 | |
| 2226 | |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | |
| 2233 | |
| 2234 | |
| 2235 | |
| 2236 | |
| 2237 | |
| 2238 | |
| 2239 | |
| 2240 | /// [`key_frame_headers`] with the sequence header's colour config named |
| 2241 | /// instead of hardcoded to "unspecified" -- spec 5.5.2's `color_primaries`, |
| 2242 | /// `transfer_characteristics`, `matrix_coefficients` and `color_range`, |
| 2243 | /// which is all a player picks a colour transform from and which |
| 2244 | /// [`crate::encoder::Colour`] is the facade's own name for. |
| 2245 | /// |
| 2246 | /// `color_config` also carries the chroma shape, and that is what a coverage |
| 2247 | /// witness needs: nothing in this crate's ENCODER codes a shape other than |
| 2248 | /// 4:2:0, but a sequence header can still be written at any |
| 2249 | /// `subsampling_x`/`subsampling_y` the spec allows, which is how the 4:4:0 |
| 2250 | /// header witness is built. It builds HEADERS only -- pair the pair it |
| 2251 | /// returns with a tile from [`encode_key_frame`] (4:2:0) or |
| 2252 | /// [`encode_key_frame_at_size`]. |
| 2253 | /// |
| 2254 | /// # Errors |
| 2255 | /// The same as [`key_frame_headers`]. |
| 2256 | |
| 2257 | |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | |
| 2264 | |
| 2265 | |
| 2266 | |
| 2267 | |
| 2268 | |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | |
| 2280 | |
| 2281 | |
| 2282 | |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | |
| 2294 | |
| 2295 | |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | |
| 2327 | |
| 2328 | |
| 2329 | |
| 2330 | |
| 2331 | |
| 2332 | |
| 2333 | |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | |
| 2338 | |
| 2339 | |
| 2340 | |
| 2341 | |
| 2342 | |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 | |
| 2348 | |
| 2349 | |
| 2350 | |
| 2351 | |
| 2352 | |
| 2353 | |
| 2354 | |
| 2355 | |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | |
| 2360 | |
| 2361 | |
| 2362 | |
| 2363 | |
| 2364 | |
| 2365 | |
| 2366 | |
| 2367 | |
| 2368 | |
| 2369 | |
| 2370 | |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | |
| 2375 | |
| 2376 | |
| 2377 | |
| 2378 | |
| 2379 | |
| 2380 | |
| 2381 | |
| 2382 | |
| 2383 | |
| 2384 | |
| 2385 | |
| 2386 | |
| 2387 | |
| 2388 | |
| 2389 | |
| 2390 | /// The DPB slot `GOLDEN_FRAME` names in every frame this encoder writes: the |
| 2391 | /// key frame refreshes all eight slots, each inter frame only slot 0, so slot |
| 2392 | /// 1 still holds the key frame however long the GOP runs. |
| 2393 | pub const GOLDEN_SLOT: u8 = 1; |
| 2394 | |
| 2395 | /// lane-refs: the frame-level `interpolation_filter` (spec 6.8.9) every inter |
| 2396 | /// frame this encoder writes carries. `EC_AV1_INTERP=smooth|sharp` codes the |
| 2397 | /// EIGHTTAP_SMOOTH / EIGHTTAP_SHARP kernel instead of the default REGULAR -- |
| 2398 | /// one filter for the whole frame, which is what libaom does on this content |
| 2399 | /// too (`lanes/obmc3.report.md` read `switchable_interp 0/0` out of its own |
| 2400 | /// stream, so a per-BLOCK filter search has no bits to win). The kernel |
| 2401 | /// reaches the search, the trials and the recon through |
| 2402 | /// `FrameCtx::interp_filter`, so the stream a decoder reads and the |
| 2403 | /// prediction the search priced are the same one. |
| 2404 | /// A PROCESS-GLOBAL [`frame_interp_filter`] override that wins over the |
| 2405 | /// environment (`u8::MAX` = unset), the shape [`set_inter_tx_search`] has: |
| 2406 | /// the witness that has to see a non-REGULAR kernel coded and decoded turns |
| 2407 | /// it on through this while holding [`crate::speed::knob_write`]. |
| 2408 | static INTERP_OVERRIDE: AtomicU8 = new; |
| 2409 | |
| 2410 | /// Sets [`INTERP_OVERRIDE`]; `None` clears it. |
| 2411 | // set only from the `#[cfg(test)]` gates |
| 2412 | pub |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | |
| 2417 | |
| 2418 | |
| 2419 | |
| 2420 | |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | |
| 2425 | |
| 2426 | |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | |
| 2431 | |
| 2432 | |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | |
| 2437 | |
| 2438 | |
| 2439 | /// The frame header for a shown inter frame that predicts from the single |
| 2440 | /// slot `last_slot` (every `ref_frame_idx` entry names it) and refreshes that |
| 2441 | /// same slot with itself once coded. The sequence header is [`key_frame_headers`]'s, |
| 2442 | /// reused verbatim: an inter frame never changes the sequence. |
| 2443 | /// |
| 2444 | /// # Errors |
| 2445 | /// Returns an error under the same conditions as [`key_frame_headers`]. |
| 2446 | |
| 2447 | |
| 2448 | |
| 2449 | |
| 2450 | |
| 2451 | |
| 2452 | |
| 2453 | |
| 2454 | |
| 2455 | |
| 2456 | |
| 2457 | |
| 2458 | /// [`inter_frame_headers`] with the three slots named apart: the one read as |
| 2459 | /// `LAST_FRAME`, the one this frame refreshes, and the one read as |
| 2460 | /// `ALTREF_FRAME`. The encoder alternates the refreshed slot between 0 and 2 |
| 2461 | /// so that the frame two back is still intact in the slot this one is about |
| 2462 | /// to overwrite -- read before write, spec 7.20's decode order. |
| 2463 | /// |
| 2464 | /// # Errors |
| 2465 | /// As [`inter_frame_headers`]. |
| 2466 | |
| 2467 | |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | |
| 2472 | |
| 2473 | |
| 2474 | |
| 2475 | |
| 2476 | |
| 2477 | |
| 2478 | |
| 2479 | |
| 2480 | |
| 2481 | |
| 2482 | |
| 2483 | |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | |
| 2488 | |
| 2489 | |
| 2490 | |
| 2491 | |
| 2492 | |
| 2493 | |
| 2494 | |
| 2495 | |
| 2496 | |
| 2497 | |
| 2498 | |
| 2499 | |
| 2500 | |
| 2501 | |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | |
| 2506 | |
| 2507 | |
| 2508 | |
| 2509 | |
| 2510 | |
| 2511 | |
| 2512 | |
| 2513 | |
| 2514 | |
| 2515 | |
| 2516 | |
| 2517 | |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | |
| 2527 | |
| 2528 | |
| 2529 | |
| 2530 | |
| 2531 | |
| 2532 | |
| 2533 | |
| 2534 | |
| 2535 | |
| 2536 | |
| 2537 | |
| 2538 | |
| 2539 | |
| 2540 | |
| 2541 | |
| 2542 | |
| 2543 | |
| 2544 | |
| 2545 | |
| 2546 | |
| 2547 | |
| 2548 | |
| 2549 | |
| 2550 | |
| 2551 | |
| 2552 | |
| 2553 | |
| 2554 | |
| 2555 | |
| 2556 | |
| 2557 | pub use *; |
| 2558 | |
| 2559 | |
| 2560 | pub use *; |
| 2561 | |
| 2562 | |
| 2563 | pub use *; |
| 2564 | |
| 2565 | |
| 2566 | pub use *; |
| 2567 | |
| 2568 | |
| 2569 | |
| 2570 | |
| 2571 | |
| 2572 |