Merge branch 'simplify/u4' into simplify/w1b
Browse files at this commit33 changed files +82 -2375
- crates/ec-vp9-syntax/src/header.rs +0 -5
- crates/ec-vp9-syntax/src/superframe.rs +0 -5
- crates/ec-vp9-syntax/tests/streams.rs +0 -3
- crates/ec-vp9/examples/decode_ivf.rs +1 -7
- crates/ec-vp9/src/bool.rs +1 -5
- crates/ec-vp9/src/decode.rs +76 -455
- crates/ec-vp9/src/header.rs +0 -88
- crates/ec-vp9/src/inter.rs +0 -59
- crates/ec-vp9/src/intra.rs +0 -29
- crates/ec-vp9/src/knobs.rs +0 -69
- crates/ec-vp9/src/lib.rs +0 -55
- crates/ec-vp9/src/loopfilter.rs +3 -65
- crates/ec-vp9/src/modes.rs +0 -6
- crates/ec-vp9/src/prof.rs +0 -64
- crates/ec-vp9/src/stack_budget.rs +0 -748
- crates/ec-vp9/src/tokens.rs +0 -12
- crates/ec-vp9/src/transform.rs +0 -15
- crates/ec-vp9/tests/it/dump_probe.rs +0 -30
- crates/ec-vp9/tests/it/libvpx_vectors.rs +1 -19
- crates/ec-vp9/tests/it/main.rs +0 -13
- crates/ec-vp9/tests/it/scratch_bool.rs +0 -13
- crates/ec-vp9/tests/it/scratch_err.rs +0 -13
- crates/ec-vp9/tests/it/scratch_hdr.rs +0 -22
- crates/ec-vp9/tests/it/scratch_hdr2.rs +0 -11
- crates/ec-vp9/tests/it/scratch_hdr3.rs +0 -13
- crates/ec-vp9/tests/it/scratch_lfdump.rs +0 -151
- crates/ec-vp9/tests/it/scratch_lossless.rs +0 -17
- crates/ec-vp9/tests/it/scratch_pixdump.rs +0 -77
- crates/ec-vp9/tests/it/scratch_pixdump10.rs +0 -61
- crates/ec-vp9/tests/it/scratch_realsweep.rs +0 -134
- crates/ec-vp9/tests/it/scratch_tiledbg.rs +0 -71
- crates/ec-vp9/tests/it/scratch_tok.rs +0 -16
- crates/ec-vp9/tests/scratch_sweep.rs +0 -24
crates/ec-vp9-syntax/src/header.rsmodified+0 -5
| @@ -505,11 +505,6 @@ impl Vp9Parser { | ||
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - /// The reference slots as they stand, after every frame parsed so far. | |
| 509 | - pub fn reference_slots(&self) -> &[ReferenceSlot; NUM_REF_FRAMES] { | |
| 510 | - &self.refs | |
| 511 | - } | |
| 512 | - | |
| 513 | 508 | /// Parse one frame's uncompressed header and apply its reference refresh. |
| 514 | 509 | /// |
| 515 | 510 | /// `frame` starts at the frame marker, i.e. it is one element of |
crates/ec-vp9-syntax/src/superframe.rsmodified+0 -5
| @@ -63,11 +63,6 @@ pub fn split(chunk: &[u8]) -> Result<Vec<&[u8]>> { | ||
| 63 | 63 | Ok(out) |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | -/// True if `chunk` carries a superframe index, i.e. holds more than one frame. | |
| 67 | -pub fn is_superframe(chunk: &[u8]) -> bool { | |
| 68 | - matches!(split(chunk), Ok(frames) if frames.len() > 1) | |
| 69 | -} | |
| 70 | - | |
| 71 | 66 | #[cfg(test)] |
| 72 | 67 | mod tests { |
| 73 | 68 | use super::*; |
crates/ec-vp9-syntax/tests/streams.rsmodified+0 -3
| @@ -195,9 +195,6 @@ fn altref_fixture_has_superframes_and_hidden_frames() { | ||
| 195 | 195 | assert!(h.show_existing_frame); |
| 196 | 196 | assert_eq!(h.frame_to_show_map_idx, 5); |
| 197 | 197 | assert_eq!(h.uncompressed_header_size, 1); |
| 198 | - let slot = parser.reference_slots()[5]; | |
| 199 | - assert!(slot.valid, "slot 5 was never refreshed by the fixture"); | |
| 200 | - assert_eq!((h.width, h.height), (slot.width, slot.height)); | |
| 201 | 198 | } |
| 202 | 199 | |
| 203 | 200 | /// Truncation, bit flips and random noise: an error, never a panic. |
crates/ec-vp9/examples/decode_ivf.rsmodified+1 -7
| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | //! Decode an IVF VP9 file and report throughput and an output digest. |
| 2 | 2 | //! |
| 3 | 3 | //! Usage: `decode_ivf <file.ivf> [threads]`. `threads` sets the tile-column |
| 4 | -//! worker count (default: `EC_VP9_THREADS`, else the available parallelism | |
| 5 | -//! capped at 6). The digest is FNV-1a over every output sample, so runs at | |
| 4 | +//! worker count (default: the available parallelism capped at 6). The digest is FNV-1a over every output sample, so runs at | |
| 6 | 5 | //! different thread counts can be compared. |
| 7 | 6 | |
| 8 | 7 | use ec_vp9::decode::Decoder; |
| @@ -70,11 +69,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| 70 | 69 | } |
| 71 | 70 | } |
| 72 | 71 | let secs = start.elapsed().as_secs_f64(); |
| 73 | - if ec_vp9::prof::enabled() { | |
| 74 | - for (name, t) in ec_vp9::prof::NAMES.iter().zip(ec_vp9::prof::totals()) { | |
| 75 | - println!("prof {name} {t:.3}s"); | |
| 76 | - } | |
| 77 | - } | |
| 78 | 72 | println!( |
| 79 | 73 | "frames={} shown={} digest={digest:016x} secs={secs:.3} fps={:.2} decode_secs={decode_secs:.3} decode_fps={:.2}", |
| 80 | 74 | frames.len(), |
crates/ec-vp9/src/bool.rsmodified+1 -5
| @@ -96,8 +96,7 @@ impl<'a> BoolDecoder<'a> { | ||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /// Decode one bool whose zero-probability is `prob`/256 (spec 8.3.2 |
| 99 | - /// `read_bool`; libvpx `vpx_read`). Under `EC_VP9_TRACE`, prints the | |
| 100 | - /// decoder state after the read — `B <pos> <bit_count> <prob> <bit>`. | |
| 99 | + /// `read_bool`; libvpx `vpx_read`). | |
| 101 | 100 | pub fn read_bool(&mut self, prob: u8) -> bool { |
| 102 | 101 | let prob = u32::from(prob); |
| 103 | 102 | let split = 1 + (((self.range - 1) * prob) >> 8); |
| @@ -119,9 +118,6 @@ impl<'a> BoolDecoder<'a> { | ||
| 119 | 118 | self.value |= self.next_byte(); |
| 120 | 119 | } |
| 121 | 120 | } |
| 122 | - if crate::trace_enabled() { | |
| 123 | - eprintln!("B {} {} {} {}", self.pos, self.bit_count, prob, u8::from(bit)); | |
| 124 | - } | |
| 125 | 121 | bit |
| 126 | 122 | } |
| 127 | 123 |
crates/ec-vp9/src/decode.rsmodified+76 -455
| @@ -177,7 +177,7 @@ pub struct Decoder { | ||
| 177 | 177 | /// |
| 178 | 178 | /// Boxed for the same reason as `frame_ctxs` below: a `FrameContext` is |
| 179 | 179 | /// 2039 bytes, and leaving this one inline put 73% of the whole `Decoder` |
| 180 | - /// back on the stack. `Stack`: crate::stack_budget. | |
| 180 | + /// back on the stack. | |
| 181 | 181 | ctx: Box<FrameContext>, |
| 182 | 182 | refs: [Option<RefFrame>; 8], |
| 183 | 183 | /// Frame scratch, live only inside `decode_keyframe`. |
| @@ -190,34 +190,25 @@ pub struct Decoder { | ||
| 190 | 190 | /// Boxed because a `FrameContext` is 2039 bytes and four of them inline |
| 191 | 191 | /// are 8156 of the 10944 a `Decoder` costs a caller that takes one BY |
| 192 | 192 | /// VALUE from `Decoder::new`. Indexing and whole-array assignment read |
| 193 | - /// through the box. `Stack`: crate::stack_budget. | |
| 193 | + /// through the box. | |
| 194 | 194 | frame_ctxs: Box<[FrameContext; 4]>, |
| 195 | 195 | /// The previous frame's per-8x8 MV field and segment map |
| 196 | 196 | /// (`prev_frame->mvs` / `last_frame_seg_map`). |
| 197 | 197 | prev_mvs: Vec<crate::inter::MvRef>, |
| 198 | 198 | prev_seg: Vec<u8>, |
| 199 | 199 | last: LastFrameFacts, |
| 200 | - /// Live only while an inter frame is being parsed. | |
| 201 | - iw: Option<InterWalk>, | |
| 202 | - /// Frames parsed by `decode_syntax` (the dump's frame index). | |
| 203 | - frames_seen: usize, | |
| 204 | - /// Frames decoded by `decode` (the dumps' `frame=` field for this path; | |
| 205 | - /// `decode_syntax` counts the same way in `frames_seen`). | |
| 206 | - decode_index: usize, | |
| 207 | - /// Mode-info blocks parsed in the most recent inter frame (0 otherwise). | |
| 208 | - syntax_blocks: usize, | |
| 200 | + iw: InterWalk, | |
| 209 | 201 | /// `twd->extend_and_predict_buf`: the per-prediction bordered reference |
| 210 | 202 | /// window built when a block's read leaves the reference frame. |
| 211 | 203 | mc_scratch: Vec<Sample>, |
| 212 | 204 | /// The `vpx_convolve8` stride-64 intermediate plus the second scratch its |
| 213 | 205 | /// averaging variant needs. |
| 214 | 206 | mc_temp: Vec<Sample>, |
| 215 | - /// Tile-column workers per frame. Set by `EC_VP9_THREADS` when that is a | |
| 216 | - /// positive integer (clamped to 1..=64); otherwise `default_threads()`. | |
| 207 | + /// Tile-column workers per frame: `default_threads()` unless `set_threads`. | |
| 217 | 208 | threads: usize, |
| 218 | 209 | } |
| 219 | 210 | |
| 220 | -/// Default tile-column worker count when `EC_VP9_THREADS` is unset or invalid: | |
| 211 | +/// Default tile-column worker count: | |
| 221 | 212 | /// the host's available parallelism, capped at 6 (the measured knee for 1080p |
| 222 | 213 | /// tile streams; see `lanes/vp9speed.report.md`). Falls back to 1 if the |
| 223 | 214 | /// parallelism cannot be determined. |
| @@ -255,6 +246,7 @@ struct LastFrameFacts { | ||
| 255 | 246 | } |
| 256 | 247 | |
| 257 | 248 | /// State of one inter-syntax frame walk. |
| 249 | +#[derive(Default)] | |
| 258 | 250 | struct InterWalk { |
| 259 | 251 | ifs: crate::inter::InterFrameState, |
| 260 | 252 | sign_bias: [bool; 4], |
| @@ -264,9 +256,6 @@ struct InterWalk { | ||
| 264 | 256 | prev_seg: Vec<u8>, |
| 265 | 257 | prev_mvs: Vec<crate::inter::MvRef>, |
| 266 | 258 | tile_col_end: usize, |
| 267 | - frame_index: usize, | |
| 268 | - /// Mode-info blocks parsed in this frame (the harness's count gate). | |
| 269 | - blocks: usize, | |
| 270 | 259 | } |
| 271 | 260 | |
| 272 | 261 | impl Decoder { |
| @@ -285,26 +274,13 @@ impl Decoder { | ||
| 285 | 274 | prev_mvs: Vec::new(), |
| 286 | 275 | prev_seg: Vec::new(), |
| 287 | 276 | last: LastFrameFacts::default(), |
| 288 | - iw: None, | |
| 289 | - frames_seen: 0, | |
| 290 | - decode_index: 0, | |
| 291 | - syntax_blocks: 0, | |
| 277 | + iw: InterWalk::default(), | |
| 292 | 278 | mc_scratch: Vec::new(), |
| 293 | 279 | mc_temp: vec![0; 64 * 135 + 64 * 64], |
| 294 | - threads: std::env::var("EC_VP9_THREADS") | |
| 295 | - .ok() | |
| 296 | - .and_then(|v| v.parse::<usize>().ok()) | |
| 297 | - .filter(|&n| n > 0) | |
| 298 | - .map_or_else(default_threads, |n| n.clamp(1, 64)), | |
| 280 | + threads: default_threads(), | |
| 299 | 281 | } |
| 300 | 282 | } |
| 301 | 283 | |
| 302 | - /// Mode-info blocks the most recent inter frame parsed; `0` for a keyframe | |
| 303 | - /// or before any frame. The syntax harness pins this number. | |
| 304 | - pub fn last_frame_blocks(&self) -> usize { | |
| 305 | - self.syntax_blocks | |
| 306 | - } | |
| 307 | - | |
| 308 | 284 | /// Decode one frame (or one superframe chunk); returns the picture |
| 309 | 285 | /// when a frame is for display. Hidden frames still update state. |
| 310 | 286 | pub fn decode(&mut self, frame: &[u8]) -> Result<Option<Picture>> { |
| @@ -327,20 +303,13 @@ impl Decoder { | ||
| 327 | 303 | }; |
| 328 | 304 | } |
| 329 | 305 | validate(&hdr)?; |
| 330 | - // One index per decoded frame (the dumps' `frame=` field), so this | |
| 331 | - // path and `decode_syntax` label the same frame the same way. | |
| 332 | - let index = self.decode_index; | |
| 333 | - self.decode_index += 1; | |
| 334 | - if crate::trace_enabled() { | |
| 335 | - eprintln!("B FRAME x FRAME x"); | |
| 336 | - } | |
| 337 | 306 | if hdr.frame_type == FrameType::Key { |
| 338 | 307 | return self.decode_key_frame(&hdr, frame); |
| 339 | 308 | } |
| 340 | 309 | if hdr.intra_only { |
| 341 | 310 | return self.decode_intra_only_frame(&hdr, frame); |
| 342 | 311 | } |
| 343 | - self.decode_inter_frame(&hdr, frame, index, true) | |
| 312 | + self.decode_inter_frame(&hdr, frame) | |
| 344 | 313 | } |
| 345 | 314 | |
| 346 | 315 | /// Decode one key frame through to pixels and refresh every slot. |
| @@ -363,18 +332,6 @@ impl Decoder { | ||
| 363 | 332 | show_frame: hdr.show_frame, |
| 364 | 333 | key: true, |
| 365 | 334 | }; |
| 366 | - // [scratch probe] EC_VP9_FORCE_UH / EC_VP9_FORCE_HSZ: override the | |
| 367 | - // uncompressed-header size / header_size_in_bytes split for diagnosis. | |
| 368 | - let hdr = { | |
| 369 | - let mut h = hdr; | |
| 370 | - if let Ok(v) = std::env::var("EC_VP9_FORCE_UH") { | |
| 371 | - h.uncompressed_header_size = v.parse().unwrap_or(h.uncompressed_header_size); | |
| 372 | - } | |
| 373 | - if let Ok(v) = std::env::var("EC_VP9_FORCE_HSZ") { | |
| 374 | - h.header_size_in_bytes = v.parse().unwrap_or(h.header_size_in_bytes); | |
| 375 | - } | |
| 376 | - h | |
| 377 | - }; | |
| 378 | 335 | let ch = read_compressed_header( |
| 379 | 336 | compressed_header_slice(frame, &hdr)?, |
| 380 | 337 | &mut self.ctx, |
| @@ -468,48 +425,10 @@ impl Decoder { | ||
| 468 | 425 | Ok(if hdr.show_frame { Some(pic) } else { None }) |
| 469 | 426 | } |
| 470 | 427 | |
| 471 | - /// Parse one frame's syntax: keyframes decode through to pixels, inter | |
| 472 | - /// frames are parsed (headers, mode info, MVs) with no reconstruction and | |
| 473 | - /// no picture. `decode` still refuses inter frames. | |
| 474 | - pub fn decode_syntax(&mut self, frame: &[u8]) -> Result<()> { | |
| 475 | - for sub in superframe::split(frame)? { | |
| 476 | - let index = self.frames_seen; | |
| 477 | - self.frames_seen += 1; | |
| 478 | - let hdr = self.parser.parse_frame(sub)?; | |
| 479 | - if hdr.show_existing_frame { | |
| 480 | - continue; | |
| 481 | - } | |
| 482 | - validate(&hdr)?; | |
| 483 | - if hdr.frame_type == FrameType::Key { | |
| 484 | - // Propagate: a corrupt keyframe leaves a half-updated frame | |
| 485 | - // context, prev-frame MV field and reference slots behind, so | |
| 486 | - // any inter-frame dump after it would be meaningless evidence. | |
| 487 | - self.decode_key_frame(&hdr, sub)?; | |
| 488 | - } else if hdr.intra_only { | |
| 489 | - // Same body as a keyframe, but an inter frame that refreshes | |
| 490 | - // only the slots it names. | |
| 491 | - self.decode_intra_only_frame(&hdr, sub)?; | |
| 492 | - } else { | |
| 493 | - self.decode_inter_frame(&hdr, sub, index, false)?; | |
| 494 | - } | |
| 495 | - } | |
| 496 | - Ok(()) | |
| 497 | - } | |
| 498 | - | |
| 499 | - /// Inter-frame decode: compressed header, the tile walk (mode info, MVs | |
| 500 | - /// and tokens always; prediction, residual and the loop filter when | |
| 501 | - /// `pixels`), then the reference refresh. | |
| 502 | - /// | |
| 503 | - /// `pixels == false` is the syntax-only walk the instrumented harnesses | |
| 504 | - /// drive: tokens keep the entropy stream aligned, no pixel is touched and | |
| 505 | - /// the reference slots are left alone. | |
| 506 | - fn decode_inter_frame( | |
| 507 | - &mut self, | |
| 508 | - hdr: &FrameHeader, | |
| 509 | - frame: &[u8], | |
| 510 | - index: usize, | |
| 511 | - pixels: bool, | |
| 512 | - ) -> Result<Option<Picture>> { | |
| 428 | + /// Inter-frame decode: compressed header, the tile walk (mode info, MVs, | |
| 429 | + /// tokens, prediction, residual and the loop filter), then the reference | |
| 430 | + /// refresh. | |
| 431 | + fn decode_inter_frame(&mut self, hdr: &FrameHeader, frame: &[u8]) -> Result<Option<Picture>> { | |
| 513 | 432 | let ss_x = hdr.subsampling_x as usize; |
| 514 | 433 | let ss_y = hdr.subsampling_y as usize; |
| 515 | 434 | // Frame-context bookkeeping (spec 6.2 / libvpx `vp9_decode_frame`): |
| @@ -528,44 +447,31 @@ impl Decoder { | ||
| 528 | 447 | // format here (`vp9_decodeframe.c:1620-1627`); a reference whose coded |
| 529 | 448 | // size differs from this frame's is SCALED during prediction |
| 530 | 449 | // (`vp9_setup_scale_factors_for_frame` per reference), not refused. |
| 531 | - if pixels { | |
| 532 | - for (i, name) in ["last", "golden", "altref"].iter().enumerate() { | |
| 533 | - let slot = hdr.ref_frame_idx[i] as usize; | |
| 534 | - if slot >= self.refs.len() || hdr.ref_frame_idx[i] >= 8 { | |
| 535 | - return Err(corrupt("vp9 inter names a reference slot past the DPB")); | |
| 536 | - } | |
| 537 | - if self.refs[slot].is_none() { | |
| 538 | - return Err(Error::corrupt(format!( | |
| 539 | - "vp9 inter reference `{name}` names empty slot {slot}" | |
| 540 | - ))); | |
| 541 | - } | |
| 450 | + for (i, name) in ["last", "golden", "altref"].iter().enumerate() { | |
| 451 | + let slot = hdr.ref_frame_idx[i] as usize; | |
| 452 | + if slot >= self.refs.len() || hdr.ref_frame_idx[i] >= 8 { | |
| 453 | + return Err(corrupt("vp9 inter names a reference slot past the DPB")); | |
| 454 | + } | |
| 455 | + if self.refs[slot].is_none() { | |
| 456 | + return Err(Error::corrupt(format!( | |
| 457 | + "vp9 inter reference `{name}` names empty slot {slot}" | |
| 458 | + ))); | |
| 542 | 459 | } |
| 543 | - let width = hdr.width as usize; | |
| 544 | - let height = hdr.height as usize; | |
| 545 | - let aw = width.div_ceil(64) * 64; | |
| 546 | - let ah = height.div_ceil(64) * 64; | |
| 547 | - self.planes = Some(self.frame_planes(aw, ah, hdr.bit_depth, ss_x, ss_y)); | |
| 548 | 460 | } |
| 461 | + let width = hdr.width as usize; | |
| 462 | + let height = hdr.height as usize; | |
| 463 | + let aw = width.div_ceil(64) * 64; | |
| 464 | + let ah = height.div_ceil(64) * 64; | |
| 465 | + self.planes = Some(self.frame_planes(aw, ah, hdr.bit_depth, ss_x, ss_y)); | |
| 466 | + | |
| 549 | 467 | |
| 550 | 468 | let hdr_start = hdr.uncompressed_header_size as usize; |
| 551 | - if crate::trace_enabled() { | |
| 552 | - eprintln!("CHSTART frame={index}"); | |
| 553 | - } | |
| 554 | 469 | let ch = read_compressed_header( |
| 555 | 470 | compressed_header_slice(frame, hdr)?, |
| 556 | 471 | &mut self.ctx, |
| 557 | 472 | hdr, |
| 558 | 473 | )?; |
| 559 | 474 | |
| 560 | - if crate::interdump_enabled() { | |
| 561 | - let mut line = format!("PPFLAT frame={index}"); | |
| 562 | - for row in self.ctx.partition.iter() { | |
| 563 | - for v in row.iter() { | |
| 564 | - line.push_str(&format!(" {v}")); | |
| 565 | - } | |
| 566 | - } | |
| 567 | - eprintln!("{line}"); | |
| 568 | - } | |
| 569 | 475 | |
| 570 | 476 | // INTRA_FRAME's sign bias is 0 by definition; the coded three land at |
| 571 | 477 | // LAST/GOLDEN/ALTREF. |
| @@ -601,7 +507,7 @@ impl Decoder { | ||
| 601 | 507 | if hdr.error_resilient_mode || self.prev_seg.len() != mi_cols * mi_rows { |
| 602 | 508 | self.prev_seg.clear(); |
| 603 | 509 | } |
| 604 | - self.iw = Some(InterWalk { | |
| 510 | + self.iw = InterWalk { | |
| 605 | 511 | ifs, |
| 606 | 512 | sign_bias, |
| 607 | 513 | use_prev, |
| @@ -610,9 +516,7 @@ impl Decoder { | ||
| 610 | 516 | prev_seg: std::mem::take(&mut self.prev_seg), |
| 611 | 517 | prev_mvs: std::mem::take(&mut self.prev_mvs), |
| 612 | 518 | tile_col_end: mi_cols, |
| 613 | - frame_index: index, | |
| 614 | - blocks: 0, | |
| 615 | - }); | |
| 519 | + }; | |
| 616 | 520 | |
| 617 | 521 | let data: &[u8] = frame |
| 618 | 522 | .get(hdr_start + hdr.header_size_in_bytes as usize..) |
| @@ -621,7 +525,6 @@ impl Decoder { | ||
| 621 | 525 | let job = TileJob { |
| 622 | 526 | hdr, |
| 623 | 527 | tx_mode: ch.tx_mode, |
| 624 | - pixels, | |
| 625 | 528 | level_of_seg: [[0u8; 2]; 8], |
| 626 | 529 | tiles: &tiles, |
| 627 | 530 | }; |
| @@ -629,9 +532,7 @@ impl Decoder { | ||
| 629 | 532 | // the walk's signature carries them. |
| 630 | 533 | let mut grids = new_grids(mi_cols, mi_rows); |
| 631 | 534 | let mut counts = crate::adapt::Counts::default(); |
| 632 | - let t_walk = crate::prof::start(); | |
| 633 | 535 | self.walk_frame(&job, &mut grids, &mut counts)?; |
| 634 | - crate::prof::stop(crate::prof::Phase::Walk, t_walk); | |
| 635 | 536 | |
| 636 | 537 | // Backward adaptation (libvpx vp9_decode_frame): counts from this frame |
| 637 | 538 | // adapt the stored context the frame started from. Skipped for |
| @@ -654,10 +555,7 @@ impl Decoder { | ||
| 654 | 555 | adapt_mv_probs(&mut self.ctx, &pre, &counts, hdr.allow_high_precision_mv); |
| 655 | 556 | } |
| 656 | 557 | |
| 657 | - // The walk state is consumed below, so the block count the harness pins | |
| 658 | - // has to be captured first. | |
| 659 | - self.syntax_blocks = self.iw.as_ref().map_or(0, |w| w.blocks); | |
| 660 | - let w = self.iw.take().expect("inter walk state"); | |
| 558 | + let w = std::mem::take(&mut self.iw); | |
| 661 | 559 | self.prev_mvs = w.mvs; |
| 662 | 560 | if hdr.segmentation.enabled { |
| 663 | 561 | self.prev_seg = w.seg_map; |
| @@ -674,30 +572,11 @@ impl Decoder { | ||
| 674 | 572 | if hdr.refresh_frame_context { |
| 675 | 573 | self.frame_ctxs[hdr.frame_context_idx as usize] = self.ctx.as_ref().clone(); |
| 676 | 574 | } |
| 677 | - if crate::interdump_enabled() { | |
| 678 | - eprintln!( | |
| 679 | - "CHSUM frame={index} tx_mode={} ref_mode={} allow_hp={} interp={} tile_rows={} tile_cols={} pp12={:?} pp0={:?} pp13={:?}", | |
| 680 | - ch.tx_mode, | |
| 681 | - ch.reference_mode, | |
| 682 | - hdr.allow_high_precision_mv, | |
| 683 | - hdr.interpolation_filter as u8, | |
| 684 | - hdr.tile_info.rows_log2, | |
| 685 | - hdr.tile_info.cols_log2, | |
| 686 | - self.ctx.partition[12], | |
| 687 | - self.ctx.partition[0], | |
| 688 | - self.ctx.partition[13] | |
| 689 | - ); | |
| 690 | - } | |
| 691 | - | |
| 692 | - if !pixels { | |
| 693 | - return Ok(None); | |
| 694 | - } | |
| 695 | 575 | |
| 696 | 576 | // Loop filter post-pass: same extents as the keyframe path, but the |
| 697 | 577 | // per-cell level comes from the block's own reference and mode class |
| 698 | 578 | // (`get_filter_level`, vp9_loopfilter.c:249). |
| 699 | - if hdr.loop_filter.level > 0 && !crate::knobs::skip_lf() { | |
| 700 | - let t_lf = crate::prof::start(); | |
| 579 | + if hdr.loop_filter.level > 0 { | |
| 701 | 580 | let p = self.planes.as_mut().expect("frame scratch"); |
| 702 | 581 | let (vw, vh) = (mi_cols * 8, mi_rows * 8); |
| 703 | 582 | grids.filter_frame( |
| @@ -715,7 +594,6 @@ impl Decoder { | ||
| 715 | 594 | hdr.loop_filter.sharpness, |
| 716 | 595 | hdr.bit_depth, |
| 717 | 596 | ); |
| 718 | - crate::prof::stop(crate::prof::Phase::LoopFilter, t_lf); | |
| 719 | 597 | } |
| 720 | 598 | |
| 721 | 599 | let pic = self.take_picture(hdr); |
| @@ -771,7 +649,7 @@ impl Decoder { | ||
| 771 | 649 | 2 => 1u8, |
| 772 | 650 | _ => 0u8, |
| 773 | 651 | }; |
| 774 | - let w = self.iw.as_mut().expect("inter walk state"); | |
| 652 | + let w = &mut self.iw; | |
| 775 | 653 | let prev_seg = std::mem::take(&mut w.prev_seg); |
| 776 | 654 | let prev_mvs = std::mem::take(&mut w.prev_mvs); |
| 777 | 655 | let ctx = crate::inter::InterBlockCtx { |
| @@ -802,7 +680,6 @@ impl Decoder { | ||
| 802 | 680 | &mut w.seg_map, counts, |
| 803 | 681 | ); |
| 804 | 682 | if let Ok(info) = &info { |
| 805 | - w.blocks += 1; | |
| 806 | 683 | for dy in 0..y_mis { |
| 807 | 684 | for dx in 0..x_mis { |
| 808 | 685 | let i = (row + dy) * mi.mi_cols + col + dx; |
| @@ -812,107 +689,12 @@ impl Decoder { | ||
| 812 | 689 | }; |
| 813 | 690 | } |
| 814 | 691 | } |
| 815 | - if crate::interdump_enabled() { | |
| 816 | - eprintln!( | |
| 817 | - "MODE {} {} {} {} {} {} {} {} {} tpos=0 ref0={} ref1={} mvrow={} mvcol={} if={}", | |
| 818 | - w.frame_index, | |
| 819 | - row, | |
| 820 | - col, | |
| 821 | - sb_type, | |
| 822 | - info.tx_size, | |
| 823 | - info.mode, | |
| 824 | - info.uv_mode, | |
| 825 | - u8::from(info.skip), | |
| 826 | - info.segment, | |
| 827 | - info.ref_frame[0], | |
| 828 | - info.ref_frame[1], | |
| 829 | - info.mv[0].0, | |
| 830 | - info.mv[0].1, | |
| 831 | - info.interp_filter | |
| 832 | - ); | |
| 833 | - } | |
| 834 | 692 | } |
| 835 | 693 | w.prev_seg = prev_seg; |
| 836 | 694 | w.prev_mvs = prev_mvs; |
| 837 | 695 | info |
| 838 | 696 | } |
| 839 | 697 | |
| 840 | - /// Tokens for one inter block: same entropy walk as the keyframe path, | |
| 841 | - /// but no prediction and no residual add. `is_inter` selects the | |
| 842 | - /// coefficient-probability ref axis. | |
| 843 | - #[allow(clippy::too_many_arguments)] | |
| 844 | - fn decode_inter_block_tokens( | |
| 845 | - &mut self, | |
| 846 | - r: &mut crate::bool::BoolDecoder, | |
| 847 | - mi: &MiState, | |
| 848 | - ectx: &mut [PlaneContexts; 3], | |
| 849 | - hdr: &FrameHeader, | |
| 850 | - info: &MiInfo, | |
| 851 | - row: usize, | |
| 852 | - col: usize, | |
| 853 | - sb_type: usize, | |
| 854 | - bw: usize, | |
| 855 | - bh: usize, | |
| 856 | - counts: &mut crate::adapt::Counts, | |
| 857 | - ) -> Result<usize> { | |
| 858 | - let (ss_x, ss_y) = plane_ss(hdr, 1); | |
| 859 | - let n4w = [ | |
| 860 | - plane_n4_w(bw, 0), | |
| 861 | - plane_n4_w(bw, ss_x), | |
| 862 | - plane_n4_w(bw, ss_x), | |
| 863 | - ]; | |
| 864 | - let n4h = [ | |
| 865 | - plane_n4_h(bh, 0), | |
| 866 | - plane_n4_h(bh, ss_y), | |
| 867 | - plane_n4_h(bh, ss_y), | |
| 868 | - ]; | |
| 869 | - if info.skip { | |
| 870 | - // dec_reset_skip_context | |
| 871 | - reset_skip_context(ectx, row, col, sb_type, n4w, n4h, ss_x, ss_y); | |
| 872 | - return Ok(0); | |
| 873 | - } | |
| 874 | - let mb_to_right = ((mi.mi_cols as isize - bw as isize - col as isize) * 64) as i32; | |
| 875 | - let mb_to_bottom = ((mi.mi_rows as isize - bh as isize - row as isize) * 64) as i32; | |
| 876 | - let mut eobtotal = 0usize; | |
| 877 | - for plane in 0..3usize { | |
| 878 | - let (ss_x, ss_y) = plane_ss(hdr, plane); | |
| 879 | - let tx_size = if plane == 0 { | |
| 880 | - info.tx_size | |
| 881 | - } else { | |
| 882 | - get_uv_tx_size(info.tx_size, sb_type, ss_x, ss_y) | |
| 883 | - }; | |
| 884 | - let step = 1usize << tx_size; | |
| 885 | - let max_blocks_wide = | |
| 886 | - (n4w[plane] as i32 + (mb_to_right.min(0) >> (5 + ss_x))).max(0) as usize; | |
| 887 | - let max_blocks_high = | |
| 888 | - (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize; | |
| 889 | - for brow in (0..max_blocks_high).step_by(step) { | |
| 890 | - for bcol in (0..max_blocks_wide).step_by(step) { | |
| 891 | - eobtotal += decode_inter_tx_tokens( | |
| 892 | - r, | |
| 893 | - ectx, | |
| 894 | - hdr, | |
| 895 | - info, | |
| 896 | - &self.ctx, | |
| 897 | - plane, | |
| 898 | - row, | |
| 899 | - col, | |
| 900 | - brow, | |
| 901 | - bcol, | |
| 902 | - tx_size, | |
| 903 | - sb_type, | |
| 904 | - bw, | |
| 905 | - bh, | |
| 906 | - mb_to_right, | |
| 907 | - mb_to_bottom, counts, | |
| 908 | - ) | |
| 909 | - .eob; | |
| 910 | - } | |
| 911 | - } | |
| 912 | - } | |
| 913 | - Ok(eobtotal) | |
| 914 | - } | |
| 915 | - | |
| 916 | 698 | /// `decode_block`'s inter arm with pixels (`vp9_decodeframe.c:990-1044`): |
| 917 | 699 | /// `dec_build_inter_predictors_sb` for the whole block, then |
| 918 | 700 | /// `reconstruct_inter_block` per transform block. Intra blocks inside an |
| @@ -1034,7 +816,6 @@ impl Decoder { | ||
| 1034 | 816 | // Prediction: `dec_build_inter_predictors_sb`, every reference, every |
| 1035 | 817 | // plane, before any token is read. |
| 1036 | 818 | { |
| 1037 | - let t_mc = crate::prof::start(); | |
| 1038 | 819 | let planes = self.planes.as_mut().expect("frame scratch"); |
| 1039 | 820 | let refs = &self.refs; |
| 1040 | 821 | let scratch = &mut self.mc_scratch; |
| @@ -1057,7 +838,6 @@ impl Decoder { | ||
| 1057 | 838 | sb_type, |
| 1058 | 839 | )?; |
| 1059 | 840 | } |
| 1060 | - crate::prof::stop(crate::prof::Phase::Mc, t_mc); | |
| 1061 | 841 | } |
| 1062 | 842 | |
| 1063 | 843 | if info.skip { |
| @@ -1080,7 +860,6 @@ impl Decoder { | ||
| 1080 | 860 | (n4h[plane] as i32 + (mb_to_bottom.min(0) >> (5 + ss_y))).max(0) as usize; |
| 1081 | 861 | for brow in (0..max_blocks_high).step_by(step) { |
| 1082 | 862 | for bcol in (0..max_blocks_wide).step_by(step) { |
| 1083 | - let t_tok = crate::prof::start(); | |
| 1084 | 863 | let coef = decode_inter_tx_tokens( |
| 1085 | 864 | r, |
| 1086 | 865 | ectx, |
| @@ -1099,7 +878,6 @@ impl Decoder { | ||
| 1099 | 878 | mb_to_right, |
| 1100 | 879 | mb_to_bottom, counts, |
| 1101 | 880 | ); |
| 1102 | - crate::prof::stop(crate::prof::Phase::Tokens, t_tok); | |
| 1103 | 881 | eobtotal += coef.eob; |
| 1104 | 882 | if coef.eob == 0 { |
| 1105 | 883 | continue; |
| @@ -1114,7 +892,6 @@ impl Decoder { | ||
| 1114 | 892 | let y0 = ((row * 8) >> ss_y) + brow * 4; |
| 1115 | 893 | let dst_off = y0 * stride + x0; |
| 1116 | 894 | let (data, _) = planes.plane(plane); |
| 1117 | - let t_idct = crate::prof::start(); | |
| 1118 | 895 | inverse_transform_add( |
| 1119 | 896 | tx_size, |
| 1120 | 897 | DCT_DCT, |
| @@ -1125,7 +902,6 @@ impl Decoder { | ||
| 1125 | 902 | hdr.quantization.lossless(), |
| 1126 | 903 | bd, |
| 1127 | 904 | ); |
| 1128 | - crate::prof::stop(crate::prof::Phase::Idct, t_idct); | |
| 1129 | 905 | } |
| 1130 | 906 | } |
| 1131 | 907 | } |
| @@ -1159,10 +935,8 @@ impl Decoder { | ||
| 1159 | 935 | let aw = width.div_ceil(64) * 64; |
| 1160 | 936 | let ah = height.div_ceil(64) * 64; |
| 1161 | 937 | self.planes = Some(self.frame_planes(aw, ah, hdr.bit_depth, ss_x, ss_y)); |
| 1162 | - let tail_start = crate::knobs::force_tail() | |
| 1163 | - .unwrap_or_else(|| { | |
| 1164 | - hdr.uncompressed_header_size as usize + hdr.header_size_in_bytes as usize | |
| 1165 | - }); | |
| 938 | + let tail_start = | |
| 939 | + hdr.uncompressed_header_size as usize + hdr.header_size_in_bytes as usize; | |
| 1166 | 940 | let tail: Vec<u8> = frame[tail_start..].to_vec(); |
| 1167 | 941 | self.decode_keyframe_inner(hdr, tx_mode, &tail) |
| 1168 | 942 | } |
| @@ -1191,7 +965,6 @@ impl Decoder { | ||
| 1191 | 965 | let job = TileJob { |
| 1192 | 966 | hdr, |
| 1193 | 967 | tx_mode, |
| 1194 | - pixels: true, | |
| 1195 | 968 | level_of_seg, |
| 1196 | 969 | tiles: &tiles, |
| 1197 | 970 | }; |
| @@ -1210,8 +983,7 @@ impl Decoder { | ||
| 1210 | 983 | // Loop filter post-pass (level 0 disables it for the frame). |
| 1211 | 984 | // The extents are the MI-aligned VISIBLE plane (libvpx's masks clear |
| 1212 | 985 | // everything past `mi_cols`/`mi_rows`), not the padded buffer size. |
| 1213 | - if hdr.loop_filter.level > 0 && !crate::knobs::skip_lf() { | |
| 1214 | - let t_lf = crate::prof::start(); | |
| 986 | + if hdr.loop_filter.level > 0 { | |
| 1215 | 987 | let p = self.planes.as_mut().expect("frame scratch"); |
| 1216 | 988 | let (vw, vh) = (mi_cols * 8, mi_rows * 8); |
| 1217 | 989 | grids.filter_frame( |
| @@ -1229,7 +1001,6 @@ impl Decoder { | ||
| 1229 | 1001 | hdr.loop_filter.sharpness, |
| 1230 | 1002 | hdr.bit_depth, |
| 1231 | 1003 | ); |
| 1232 | - crate::prof::stop(crate::prof::Phase::LoopFilter, t_lf); | |
| 1233 | 1004 | } |
| 1234 | 1005 | |
| 1235 | 1006 | // `vp9_swap_current_and_last_seg_map` runs only when segmentation is |
| @@ -1256,10 +1027,6 @@ impl Decoder { | ||
| 1256 | 1027 | n4: usize, |
| 1257 | 1028 | tile_col_start: usize, |
| 1258 | 1029 | tx_mode: u8, |
| 1259 | - // Whether this walk reconstructs pixels. Consulted by the inter | |
| 1260 | - // branch only: a keyframe always reconstructs its intra blocks, and | |
| 1261 | - // the syntax-only inter walk parses tokens without predicting. | |
| 1262 | - pixels: bool, | |
| 1263 | 1030 | counts: &mut crate::adapt::Counts, |
| 1264 | 1031 | ) -> Result<()> { |
| 1265 | 1032 | if row >= mi.mi_rows || col >= mi.mi_cols { |
| @@ -1307,7 +1074,7 @@ impl Decoder { | ||
| 1307 | 1074 | 1, |
| 1308 | 1075 | tile_col_start, |
| 1309 | 1076 | tx_mode, |
| 1310 | - pixels, counts, | |
| 1077 | + counts, | |
| 1311 | 1078 | )?; |
| 1312 | 1079 | } else { |
| 1313 | 1080 | match partition { |
| @@ -1325,7 +1092,7 @@ impl Decoder { | ||
| 1325 | 1092 | n4, |
| 1326 | 1093 | tile_col_start, |
| 1327 | 1094 | tx_mode, |
| 1328 | - pixels, counts, | |
| 1095 | + counts, | |
| 1329 | 1096 | )?, |
| 1330 | 1097 | 1 => { |
| 1331 | 1098 | self.decode_block( |
| @@ -1342,7 +1109,7 @@ impl Decoder { | ||
| 1342 | 1109 | n8, |
| 1343 | 1110 | tile_col_start, |
| 1344 | 1111 | tx_mode, |
| 1345 | - pixels, counts, | |
| 1112 | + counts, | |
| 1346 | 1113 | )?; |
| 1347 | 1114 | if has_rows { |
| 1348 | 1115 | self.decode_block( |
| @@ -1359,7 +1126,7 @@ impl Decoder { | ||
| 1359 | 1126 | n8, |
| 1360 | 1127 | tile_col_start, |
| 1361 | 1128 | tx_mode, |
| 1362 | - pixels, counts, | |
| 1129 | + counts, | |
| 1363 | 1130 | )?; |
| 1364 | 1131 | } |
| 1365 | 1132 | } |
| @@ -1378,7 +1145,7 @@ impl Decoder { | ||
| 1378 | 1145 | n4, |
| 1379 | 1146 | tile_col_start, |
| 1380 | 1147 | tx_mode, |
| 1381 | - pixels, counts, | |
| 1148 | + counts, | |
| 1382 | 1149 | )?; |
| 1383 | 1150 | if has_cols { |
| 1384 | 1151 | self.decode_block( |
| @@ -1395,7 +1162,7 @@ impl Decoder { | ||
| 1395 | 1162 | n4, |
| 1396 | 1163 | tile_col_start, |
| 1397 | 1164 | tx_mode, |
| 1398 | - pixels, counts, | |
| 1165 | + counts, | |
| 1399 | 1166 | )?; |
| 1400 | 1167 | } |
| 1401 | 1168 | } |
| @@ -1418,7 +1185,7 @@ impl Decoder { | ||
| 1418 | 1185 | n8, |
| 1419 | 1186 | tile_col_start, |
| 1420 | 1187 | tx_mode, |
| 1421 | - pixels, counts, | |
| 1188 | + counts, | |
| 1422 | 1189 | )?; |
| 1423 | 1190 | } |
| 1424 | 1191 | } |
| @@ -1447,7 +1214,6 @@ impl Decoder { | ||
| 1447 | 1214 | bhl: usize, |
| 1448 | 1215 | tile_col_start: usize, |
| 1449 | 1216 | tx_mode: u8, |
| 1450 | - pixels: bool, | |
| 1451 | 1217 | counts: &mut crate::adapt::Counts, |
| 1452 | 1218 | ) -> Result<()> { |
| 1453 | 1219 | let bw = 1 << (bwl - 1); |
| @@ -1500,54 +1266,30 @@ impl Decoder { | ||
| 1500 | 1266 | )? |
| 1501 | 1267 | }; |
| 1502 | 1268 | if !intra_frame { |
| 1503 | - if pixels { | |
| 1504 | - // Full inter decode: prediction, tokens, residual. The | |
| 1505 | - // per-cell loop-filter level is the block's own reference and | |
| 1506 | - // mode class (`get_filter_level`), so the grids are written | |
| 1507 | - // inside the reconstruction rather than from `level_of_seg`. | |
| 1508 | - let became_skip = self.reconstruct_inter_pixels( | |
| 1509 | - r, | |
| 1510 | - ectx, | |
| 1511 | - grids, | |
| 1512 | - hdr, | |
| 1513 | - &info, | |
| 1514 | - row, | |
| 1515 | - col, | |
| 1516 | - sb_type, | |
| 1517 | - bw, | |
| 1518 | - bh, | |
| 1519 | - mi, | |
| 1520 | - tile_col_start, counts, | |
| 1521 | - )?; | |
| 1522 | - if became_skip { | |
| 1523 | - info.skip = true; | |
| 1524 | - } | |
| 1525 | - } else { | |
| 1526 | - // Inter syntax only: tokens keep the entropy stream aligned, | |
| 1527 | - // the block lands in the mode grid, and no pixel is touched. | |
| 1528 | - let eobtotal = | |
| 1529 | - self.decode_inter_block_tokens(r, mi, ectx, hdr, &info, row, col, sb_type, bw, bh, counts)?; | |
| 1530 | - // libvpx decode_block: an inter block of 8x8 or larger with no | |
| 1531 | - // coefficients becomes skip (`mi->skip = 1`), which the skip | |
| 1532 | - // and tx contexts of later blocks then read. | |
| 1533 | - if sb_type >= 3 && !info.skip && eobtotal == 0 { | |
| 1534 | - info.skip = true; | |
| 1535 | - } | |
| 1269 | + // Full inter decode: prediction, tokens, residual. The | |
| 1270 | + // per-cell loop-filter level is the block's own reference and | |
| 1271 | + // mode class (`get_filter_level`), so the grids are written | |
| 1272 | + // inside the reconstruction rather than from `level_of_seg`. | |
| 1273 | + let became_skip = self.reconstruct_inter_pixels( | |
| 1274 | + r, | |
| 1275 | + ectx, | |
| 1276 | + grids, | |
| 1277 | + hdr, | |
| 1278 | + &info, | |
| 1279 | + row, | |
| 1280 | + col, | |
| 1281 | + sb_type, | |
| 1282 | + bw, | |
| 1283 | + bh, | |
| 1284 | + mi, | |
| 1285 | + tile_col_start, | |
| 1286 | + counts, | |
| 1287 | + )?; | |
| 1288 | + if became_skip { | |
| 1289 | + info.skip = true; | |
| 1536 | 1290 | } |
| 1537 | 1291 | for dy in 0..y_mis { |
| 1538 | 1292 | for dx in 0..x_mis { |
| 1539 | - if crate::mvdbg2_enabled() && row + dy == 7 && col + dx >= 30 && col + dx <= 40 | |
| 1540 | - { | |
| 1541 | - eprintln!( | |
| 1542 | - "GWR cell=({} {}) idx={} from=({row} {col}) dy={dy} dx={dx} sb={sb_type} bw={bw} bh={bh} x_mis={x_mis} y_mis={y_mis} mv={:?} ref0={} mi_cols={}", | |
| 1543 | - row + dy, | |
| 1544 | - col + dx, | |
| 1545 | - (row + dy) * mi.mi_cols + col + dx, | |
| 1546 | - info.mv, | |
| 1547 | - info.ref_frame[0], | |
| 1548 | - mi.mi_cols | |
| 1549 | - ); | |
| 1550 | - } | |
| 1551 | 1293 | mi.grid[(row + dy) * mi.mi_cols + col + dx] = Some(info.clone()); |
| 1552 | 1294 | } |
| 1553 | 1295 | } |
| @@ -1756,31 +1498,6 @@ impl Decoder { | ||
| 1756 | 1498 | let nblocks = 1usize << tx_size; |
| 1757 | 1499 | let ctx_in = usize::from(ectx[plane].above[ax..ax + nblocks].iter().any(|&v| v != 0)) |
| 1758 | 1500 | + usize::from(ectx[plane].left[ay..ay + nblocks].iter().any(|&v| v != 0)); |
| 1759 | - if crate::trace_enabled() { | |
| 1760 | - eprintln!( | |
| 1761 | - "CTX p={} prob={:?} ax={} ay={} a={} l={} ctx={}", | |
| 1762 | - plane, | |
| 1763 | - self.ctx.coef[tx_size][ptype][0][0][ctx_in], | |
| 1764 | - ax, | |
| 1765 | - ay, | |
| 1766 | - ectx[plane].above[ax], | |
| 1767 | - ectx[plane].left[ay], | |
| 1768 | - ctx_in | |
| 1769 | - ); | |
| 1770 | - } | |
| 1771 | - if crate::trace_enabled() { | |
| 1772 | - eprintln!( | |
| 1773 | - "TXB p={} x={} y={} tx={} a={} l={} deq={},{}", | |
| 1774 | - plane, | |
| 1775 | - x0, | |
| 1776 | - y0, | |
| 1777 | - tx_size, | |
| 1778 | - ectx[plane].above[ax], | |
| 1779 | - ectx[plane].left[ay], | |
| 1780 | - dequant[0], | |
| 1781 | - dequant[1] | |
| 1782 | - ); | |
| 1783 | - } | |
| 1784 | 1501 | let coef = decode_coefs( |
| 1785 | 1502 | r, |
| 1786 | 1503 | ptype, |
| @@ -1813,39 +1530,11 @@ impl Decoder { | ||
| 1813 | 1530 | 0 |
| 1814 | 1531 | }; |
| 1815 | 1532 | write_tx_context(ectx, plane, tx_size, ax, ay, coef.eob > 0, shift_a, shift_l); |
| 1816 | - if crate::tokdbg_enabled() { | |
| 1817 | - eprintln!( | |
| 1818 | - "TDW row={mi_row} col={mi_col} plane={plane} brow={tx_row} bcol={tx_col} tx={tx_size} eob={} sa={} sl={} aw={:?} lw={:?} intra=1", | |
| 1819 | - coef.eob, | |
| 1820 | - shift_a, | |
| 1821 | - shift_l, | |
| 1822 | - &ectx[plane].above[ax..ax + nblocks], | |
| 1823 | - &ectx[plane].left[ay..ay + nblocks], | |
| 1824 | - ); | |
| 1825 | - } | |
| 1826 | 1533 | |
| 1827 | 1534 | // 4. Residual add. |
| 1828 | 1535 | if coef.eob > 0 { |
| 1829 | 1536 | let dst_off = y0 * stride + x0; |
| 1830 | 1537 | let (data, _) = planes.plane(plane); |
| 1831 | - let probe = crate::trace_enabled() | |
| 1832 | - && plane == 0 | |
| 1833 | - && std::env::var("EC_VP9_PROBE_TU") | |
| 1834 | - .ok() | |
| 1835 | - .and_then(|s| { | |
| 1836 | - let mut it = s.split(','); | |
| 1837 | - Some((it.next()?.parse::<usize>().ok()?, it.next()?.parse().ok()?)) | |
| 1838 | - }) | |
| 1839 | - .is_some_and(|(px, py)| x0 == px && y0 == py); | |
| 1840 | - let t: Option<Vec<Vec<Sample>>> = if probe { | |
| 1841 | - Some( | |
| 1842 | - (0..4usize) | |
| 1843 | - .map(|rr| data[dst_off + rr * stride..dst_off + rr * stride + 4].to_vec()) | |
| 1844 | - .collect(), | |
| 1845 | - ) | |
| 1846 | - } else { | |
| 1847 | - None | |
| 1848 | - }; | |
| 1849 | 1538 | inverse_transform_add( |
| 1850 | 1539 | tx_size, |
| 1851 | 1540 | tx_type, |
| @@ -1856,15 +1545,6 @@ impl Decoder { | ||
| 1856 | 1545 | lossless, |
| 1857 | 1546 | bd, |
| 1858 | 1547 | ); |
| 1859 | - if let Some(before) = t { | |
| 1860 | - let after: Vec<Vec<Sample>> = (0..4usize) | |
| 1861 | - .map(|rr| data[dst_off + rr * stride..dst_off + rr * stride + 4].to_vec()) | |
| 1862 | - .collect(); | |
| 1863 | - eprintln!("RC x0={x0} y0={y0} tx={tx_size} mode={mode}"); | |
| 1864 | - for rr in 0..4 { | |
| 1865 | - eprintln!(" pred{rr}={:?} after{rr}={:?}", before[rr], after[rr]); | |
| 1866 | - } | |
| 1867 | - } | |
| 1868 | 1548 | } |
| 1869 | 1549 | Ok(()) |
| 1870 | 1550 | } |
| @@ -1966,26 +1646,6 @@ fn reset_skip_context( | ||
| 1966 | 1646 | ectx[plane].left[(offy + i) % lrows] = 0; |
| 1967 | 1647 | } |
| 1968 | 1648 | } |
| 1969 | - if crate::tokdbg_enabled() { | |
| 1970 | - // Mirror the oracle's `SKIPCTX` print: the CLEARED window, indexed from | |
| 1971 | - // the reset offset (libvpx's `left_context` is already offset to the | |
| 1972 | - // block), not the whole rolling buffer from base index 0. | |
| 1973 | - let mut line = format!("TDK row={row} col={col} n4w={n4w:?} n4h={n4h:?}"); | |
| 1974 | - for plane in 0..3usize { | |
| 1975 | - let (sx, sy) = if plane == 0 { (0, 0) } else { (ss_x, ss_y) }; | |
| 1976 | - let offx = (col << 1) >> sx; | |
| 1977 | - let offy = (row << 1) >> sy; | |
| 1978 | - let lrows = 32usize >> sy; | |
| 1979 | - let a: Vec<u8> = (0..n4w[plane]) | |
| 1980 | - .map(|i| ectx[plane].above[offx + i]) | |
| 1981 | - .collect(); | |
| 1982 | - let l: Vec<u8> = (0..n4h[plane].min(lrows)) | |
| 1983 | - .map(|i| ectx[plane].left[(offy + i) % lrows]) | |
| 1984 | - .collect(); | |
| 1985 | - line.push_str(&format!(" p{plane} a={a:?} l={l:?}")); | |
| 1986 | - } | |
| 1987 | - eprintln!("{line}"); | |
| 1988 | - } | |
| 1989 | 1649 | } |
| 1990 | 1650 | |
| 1991 | 1651 | /// The entropy-context write-back of one transform block |
| @@ -2085,15 +1745,6 @@ fn decode_inter_tx_tokens( | ||
| 2085 | 1745 | let nblocks = 1usize << tx_size; |
| 2086 | 1746 | let ctx_in = usize::from(ectx[plane].above[ax..ax + nblocks].iter().any(|&v| v != 0)) |
| 2087 | 1747 | + usize::from(ectx[plane].left[ay..ay + nblocks].iter().any(|&v| v != 0)); |
| 2088 | - if crate::tokdbg_enabled() { | |
| 2089 | - eprintln!( | |
| 2090 | - "TDB row={row} col={col} plane={plane} brow={brow} bcol={bcol} tx={tx_size} sbt={sb_type} ptype={ptype} inter={} mode={} tt={tx_type} ax={ax} ay={ay} cin={ctx_in} a={:?} l={:?}", | |
| 2091 | - u8::from(info.is_inter), | |
| 2092 | - info.mode, | |
| 2093 | - &ectx[plane].above[ax..ax + nblocks], | |
| 2094 | - &ectx[plane].left[ay..ay + nblocks], | |
| 2095 | - ); | |
| 2096 | - } | |
| 2097 | 1748 | let coef = decode_coefs( |
| 2098 | 1749 | r, |
| 2099 | 1750 | ptype, |
| @@ -2124,16 +1775,6 @@ fn decode_inter_tx_tokens( | ||
| 2124 | 1775 | 0 |
| 2125 | 1776 | }; |
| 2126 | 1777 | write_tx_context(ectx, plane, tx_size, ax, ay, coef.eob > 0, shift_a, shift_l); |
| 2127 | - if crate::tokdbg_enabled() { | |
| 2128 | - eprintln!( | |
| 2129 | - "TDW row={row} col={col} plane={plane} brow={brow} bcol={bcol} tx={tx_size} eob={} sa={} sl={} aw={:?} lw={:?}", | |
| 2130 | - coef.eob, | |
| 2131 | - shift_a, | |
| 2132 | - shift_l, | |
| 2133 | - &ectx[plane].above[ax..ax + nblocks], | |
| 2134 | - &ectx[plane].left[ay..ay + nblocks], | |
| 2135 | - ); | |
| 2136 | - } | |
| 2137 | 1778 | coef |
| 2138 | 1779 | } |
| 2139 | 1780 | |
| @@ -2313,8 +1954,6 @@ fn interp_filter_of(hdr: &FrameHeader) -> u8 { | ||
| 2313 | 1954 | struct TileJob<'a> { |
| 2314 | 1955 | hdr: &'a FrameHeader, |
| 2315 | 1956 | tx_mode: u8, |
| 2316 | - /// Whether the walk reconstructs pixels (see `decode_partition`). | |
| 2317 | - pixels: bool, | |
| 2318 | 1957 | /// Loop-filter level per segment (keyframes; inter walks pass zeros). |
| 2319 | 1958 | level_of_seg: [[u8; 2]; 8], |
| 2320 | 1959 | /// Tile payloads in bitstream order: `tiles[tile_row * tile_cols + tile_col]`. |
| @@ -2459,11 +2098,9 @@ impl Decoder { | ||
| 2459 | 2098 | .zip(worker_planes) |
| 2460 | 2099 | .map(|(cols, planes)| { |
| 2461 | 2100 | scope.spawn(move || -> Result<(Decoder, LfGrids, crate::adapt::Counts)> { |
| 2462 | - let t_fork = crate::prof::start(); | |
| 2463 | 2101 | let mut wk = parent.fork(hdr, planes); |
| 2464 | 2102 | let mut g = new_grids(mi_cols, mi_rows); |
| 2465 | 2103 | let mut c = crate::adapt::Counts::default(); |
| 2466 | - crate::prof::stop(crate::prof::Phase::Threads, t_fork); | |
| 2467 | 2104 | wk.walk_columns(job, cols, &mut g, &mut c)?; |
| 2468 | 2105 | Ok((wk, g, c)) |
| 2469 | 2106 | }) |
| @@ -2478,7 +2115,6 @@ impl Decoder { | ||
| 2478 | 2115 | for res in results { |
| 2479 | 2116 | parts.push(res?); |
| 2480 | 2117 | } |
| 2481 | - let t_merge = crate::prof::start(); | |
| 2482 | 2118 | for (w, (mut wk, g, c)) in parts.into_iter().enumerate() { |
| 2483 | 2119 | counts.add(&c); |
| 2484 | 2120 | for &tc in &owned[w] { |
| @@ -2491,22 +2127,18 @@ impl Decoder { | ||
| 2491 | 2127 | copy_mi_cols(&mut grids.otx, &g.otx, mi_cols, mi_rows, lo, hi); |
| 2492 | 2128 | copy_mi_cols(&mut grids.skip_inter, &g.skip_inter, mi_cols, mi_rows, lo, hi); |
| 2493 | 2129 | copy_mi_cols(&mut grids.seg, &g.seg, mi_cols, mi_rows, lo, hi); |
| 2494 | - if let (Some(dst), Some(src)) = (self.iw.as_mut(), wk.iw.as_ref()) { | |
| 2495 | - copy_mi_cols(&mut dst.mvs, &src.mvs, mi_cols, mi_rows, lo, hi); | |
| 2496 | - copy_mi_cols(&mut dst.seg_map, &src.seg_map, mi_cols, mi_rows, lo, hi); | |
| 2130 | + if !self.iw.mvs.is_empty() { | |
| 2131 | + copy_mi_cols(&mut self.iw.mvs, &wk.iw.mvs, mi_cols, mi_rows, lo, hi); | |
| 2132 | + copy_mi_cols(&mut self.iw.seg_map, &wk.iw.seg_map, mi_cols, mi_rows, lo, hi); | |
| 2497 | 2133 | } |
| 2498 | 2134 | if let (Some(dst), Some(src)) = (self.planes.as_mut(), wk.planes.as_ref()) { |
| 2499 | 2135 | copy_plane_cols(dst, src, lo, hi, hi == mi_cols); |
| 2500 | 2136 | } |
| 2501 | 2137 | } |
| 2502 | - if let (Some(dst), Some(src)) = (self.iw.as_mut(), wk.iw.as_ref()) { | |
| 2503 | - dst.blocks += src.blocks; | |
| 2504 | - } | |
| 2505 | 2138 | if let Some(p) = wk.planes.take() { |
| 2506 | 2139 | self.recycle_planes(p); |
| 2507 | 2140 | } |
| 2508 | 2141 | } |
| 2509 | - crate::prof::stop(crate::prof::Phase::Threads, t_merge); | |
| 2510 | 2142 | Ok(()) |
| 2511 | 2143 | } |
| 2512 | 2144 | |
| @@ -2538,17 +2170,12 @@ impl Decoder { | ||
| 2538 | 2170 | mi.above_seg.fill(0); |
| 2539 | 2171 | for &tc in cols { |
| 2540 | 2172 | let (col_lo, col_hi) = tile_col_span(hdr, tc); |
| 2541 | - if let Some(w) = self.iw.as_mut() { | |
| 2542 | - w.tile_col_end = col_hi; | |
| 2543 | - } | |
| 2173 | + self.iw.tile_col_end = col_hi; | |
| 2544 | 2174 | for tr in 0..tile_rows { |
| 2545 | 2175 | let sb64_rows = mi_rows.div_ceil(SB_MI); |
| 2546 | 2176 | let row_lo = ((sb64_rows * tr) >> hdr.tile_info.rows_log2) * SB_MI; |
| 2547 | 2177 | let row_hi = (((sb64_rows * (tr + 1)) >> hdr.tile_info.rows_log2) * SB_MI).min(mi_rows); |
| 2548 | 2178 | let data = job.tiles[tr * tile_cols + tc]; |
| 2549 | - if crate::trace_enabled() { | |
| 2550 | - eprintln!("TILE {} bytes tr={tr} tc={tc}", data.len()); | |
| 2551 | - } | |
| 2552 | 2179 | let mut r = crate::bool::BoolDecoder::new(data)?; |
| 2553 | 2180 | for sb_row in (row_lo..row_hi).step_by(SB_MI) { |
| 2554 | 2181 | // Left entropy/partition contexts are zeroed at the start |
| @@ -2569,7 +2196,6 @@ impl Decoder { | ||
| 2569 | 2196 | 4, |
| 2570 | 2197 | col_lo, |
| 2571 | 2198 | job.tx_mode, |
| 2572 | - job.pixels, | |
| 2573 | 2199 | counts, |
| 2574 | 2200 | )?; |
| 2575 | 2201 | } |
| @@ -2597,21 +2223,16 @@ impl Decoder { | ||
| 2597 | 2223 | prev_mvs: Vec::new(), |
| 2598 | 2224 | prev_seg: Vec::new(), |
| 2599 | 2225 | last: self.last, |
| 2600 | - iw: self.iw.as_ref().map(|w| InterWalk { | |
| 2601 | - ifs: w.ifs, | |
| 2602 | - sign_bias: w.sign_bias, | |
| 2603 | - use_prev: w.use_prev, | |
| 2226 | + iw: InterWalk { | |
| 2227 | + ifs: self.iw.ifs, | |
| 2228 | + sign_bias: self.iw.sign_bias, | |
| 2229 | + use_prev: self.iw.use_prev, | |
| 2604 | 2230 | seg_map: vec![0; n], |
| 2605 | 2231 | mvs: vec![crate::inter::MvRef::default(); n], |
| 2606 | - prev_seg: w.prev_seg.clone(), | |
| 2607 | - prev_mvs: w.prev_mvs.clone(), | |
| 2608 | - tile_col_end: w.tile_col_end, | |
| 2609 | - frame_index: w.frame_index, | |
| 2610 | - blocks: 0, | |
| 2611 | - }), | |
| 2612 | - frames_seen: self.frames_seen, | |
| 2613 | - decode_index: self.decode_index, | |
| 2614 | - syntax_blocks: 0, | |
| 2232 | + prev_seg: self.iw.prev_seg.clone(), | |
| 2233 | + prev_mvs: self.iw.prev_mvs.clone(), | |
| 2234 | + tile_col_end: self.iw.tile_col_end, | |
| 2235 | + }, | |
| 2615 | 2236 | mc_scratch: Vec::new(), |
| 2616 | 2237 | mc_temp: vec![0; 64 * 135 + 64 * 64], |
| 2617 | 2238 | threads: 1, |
crates/ec-vp9/src/header.rsmodified+0 -88
| @@ -276,15 +276,6 @@ pub(crate) fn read_compressed_header( | ||
| 276 | 276 | ctx: &mut FrameContext, |
| 277 | 277 | hdr: &FrameHeader, |
| 278 | 278 | ) -> crate::Result<CompressedHeader> { |
| 279 | - if crate::interdump_enabled() && !hdr.frame_is_intra { | |
| 280 | - let mut line = String::from("PPFLAT_PRE"); | |
| 281 | - for row in ctx.partition.iter() { | |
| 282 | - for v in row.iter() { | |
| 283 | - line.push_str(&format!(" {v}")); | |
| 284 | - } | |
| 285 | - } | |
| 286 | - eprintln!("{line}"); | |
| 287 | - } | |
| 288 | 279 | let lossless = hdr.quantization.lossless(); |
| 289 | 280 | let mut r = BoolDecoder::new(data)?; |
| 290 | 281 | let tx_mode = if lossless { |
| @@ -292,9 +283,6 @@ pub(crate) fn read_compressed_header( | ||
| 292 | 283 | } else { |
| 293 | 284 | read_tx_mode(&mut r) |
| 294 | 285 | }; |
| 295 | - if crate::trace_enabled() { | |
| 296 | - eprintln!("SECT txmode"); | |
| 297 | - } | |
| 298 | 286 | if tx_mode == TX_MODE_SELECT { |
| 299 | 287 | for row in 0..2 { |
| 300 | 288 | for j in 0..1 { |
| @@ -312,32 +300,17 @@ pub(crate) fn read_compressed_header( | ||
| 312 | 300 | } |
| 313 | 301 | } |
| 314 | 302 | } |
| 315 | - if crate::trace_enabled() { | |
| 316 | - eprintln!("SECT txprobs"); | |
| 317 | - } | |
| 318 | 303 | read_coef_probs(&mut r, ctx, tx_mode); |
| 319 | - if crate::trace_enabled() { | |
| 320 | - eprintln!("SECT coef"); | |
| 321 | - } | |
| 322 | 304 | for p in &mut ctx.skip { |
| 323 | 305 | diff_update_prob(&mut r, p); |
| 324 | 306 | } |
| 325 | 307 | let mut reference_mode = SINGLE_REFERENCE; |
| 326 | - if crate::trace_enabled() { | |
| 327 | - eprintln!("SECT skip"); | |
| 328 | - } | |
| 329 | 308 | if !hdr.frame_is_intra { |
| 330 | - if crate::trace_enabled() { | |
| 331 | - eprintln!("SECT intermode"); | |
| 332 | - } | |
| 333 | 309 | for i in 0..7 { |
| 334 | 310 | for j in 0..3 { |
| 335 | 311 | diff_update_prob(&mut r, &mut ctx.inter_mode[i][j]); |
| 336 | 312 | } |
| 337 | 313 | } |
| 338 | - if crate::trace_enabled() { | |
| 339 | - eprintln!("SECT switchable"); | |
| 340 | - } | |
| 341 | 314 | if hdr.interpolation_filter as u8 == crate::inter::SWITCHABLE { |
| 342 | 315 | for j in 0..4 { |
| 343 | 316 | for i in 0..2 { |
| @@ -345,17 +318,11 @@ pub(crate) fn read_compressed_header( | ||
| 345 | 318 | } |
| 346 | 319 | } |
| 347 | 320 | } |
| 348 | - if crate::trace_enabled() { | |
| 349 | - eprintln!("SECT intrainter"); | |
| 350 | - } | |
| 351 | 321 | for p in &mut ctx.intra_inter { |
| 352 | 322 | diff_update_prob(&mut r, p); |
| 353 | 323 | } |
| 354 | 324 | // read_frame_reference_mode: `vp9_compound_reference_allowed` gates |
| 355 | 325 | // the two bits (bias[GOLDEN]/bias[ALTREF] vs bias[LAST]). |
| 356 | - if crate::trace_enabled() { | |
| 357 | - eprintln!("SECT refmode"); | |
| 358 | - } | |
| 359 | 326 | let allowed = hdr.ref_frame_sign_bias[1] != hdr.ref_frame_sign_bias[0] |
| 360 | 327 | || hdr.ref_frame_sign_bias[2] != hdr.ref_frame_sign_bias[0]; |
| 361 | 328 | reference_mode = if allowed { |
| @@ -372,9 +339,6 @@ pub(crate) fn read_compressed_header( | ||
| 372 | 339 | SINGLE_REFERENCE |
| 373 | 340 | }; |
| 374 | 341 | // read_frame_reference_mode_probs. |
| 375 | - if crate::trace_enabled() { | |
| 376 | - eprintln!("SECT refprobs"); | |
| 377 | - } | |
| 378 | 342 | if reference_mode == REFERENCE_MODE_SELECT { |
| 379 | 343 | for p in &mut ctx.comp_inter { |
| 380 | 344 | diff_update_prob(&mut r, p); |
| @@ -392,31 +356,18 @@ pub(crate) fn read_compressed_header( | ||
| 392 | 356 | diff_update_prob(&mut r, p); |
| 393 | 357 | } |
| 394 | 358 | } |
| 395 | - if crate::trace_enabled() { | |
| 396 | - eprintln!("SECT ymode"); | |
| 397 | - } | |
| 398 | 359 | for j in 0..4 { |
| 399 | 360 | for i in 0..9 { |
| 400 | 361 | diff_update_prob(&mut r, &mut ctx.y_mode[j][i]); |
| 401 | 362 | } |
| 402 | 363 | } |
| 403 | - if crate::trace_enabled() { | |
| 404 | - eprintln!("SECT partition"); | |
| 405 | - } | |
| 406 | 364 | for j in 0..16 { |
| 407 | 365 | for i in 0..3 { |
| 408 | - let before = ctx.partition[j][i]; | |
| 409 | 366 | diff_update_prob(&mut r, &mut ctx.partition[j][i]); |
| 410 | - if crate::interdump_enabled() { | |
| 411 | - eprintln!("PUPD {} {} {} {}", j, i, before, ctx.partition[j][i]); | |
| 412 | - } | |
| 413 | 367 | } |
| 414 | 368 | } |
| 415 | 369 | // read_mv_probs (vp9_decodeframe.c:76): joints, then per component |
| 416 | 370 | // sign/classes/class0/bits, then the fractional parts, then hp. |
| 417 | - if crate::trace_enabled() { | |
| 418 | - eprintln!("SECT mv"); | |
| 419 | - } | |
| 420 | 371 | update_mv_probs(&mut r, &mut ctx.nmv_joints); |
| 421 | 372 | for comp in 0..2 { |
| 422 | 373 | update_mv_probs(&mut r, &mut ctx.nmv_sign[comp..comp + 1]); |
| @@ -434,48 +385,9 @@ pub(crate) fn read_compressed_header( | ||
| 434 | 385 | for comp in 0..2 { |
| 435 | 386 | update_mv_probs(&mut r, &mut ctx.nmv_class0_hp[comp..comp + 1]); |
| 436 | 387 | update_mv_probs(&mut r, &mut ctx.nmv_hp[comp..comp + 1]); |
| 437 | - if crate::mvdump_enabled() { | |
| 438 | - eprintln!( | |
| 439 | - "MVPROB j0={} j1={} j2={}", | |
| 440 | - ctx.nmv_joints[0], ctx.nmv_joints[1], ctx.nmv_joints[2] | |
| 441 | - ); | |
| 442 | - for comp in 0..2 { | |
| 443 | - eprintln!( | |
| 444 | - "MVPROB c{} sign={} class0={} class0hp={} hp={}", | |
| 445 | - comp, | |
| 446 | - ctx.nmv_sign[comp], | |
| 447 | - ctx.nmv_class0[comp][0], | |
| 448 | - ctx.nmv_class0_hp[comp], | |
| 449 | - ctx.nmv_hp[comp] | |
| 450 | - ); | |
| 451 | - eprint!("MVPROB c{} cls", comp); | |
| 452 | - for v in ctx.nmv_classes[comp].iter() { eprint!(" {}", v); } | |
| 453 | - eprintln!(); | |
| 454 | - eprint!("MVPROB c{} bits", comp); | |
| 455 | - for v in ctx.nmv_bits[comp].iter() { eprint!(" {}", v); } | |
| 456 | - eprintln!(); | |
| 457 | - eprint!("MVPROB c{} c0fp", comp); | |
| 458 | - for row in ctx.nmv_class0_fp[comp].iter() { for v in row.iter() { eprint!(" {}", v); } } | |
| 459 | - eprintln!(); | |
| 460 | - eprint!("MVPROB c{} fp", comp); | |
| 461 | - for v in ctx.nmv_fp[comp].iter() { eprint!(" {}", v); } | |
| 462 | - eprintln!(); | |
| 463 | - } | |
| 464 | - } | |
| 465 | 388 | } |
| 466 | 389 | } |
| 467 | 390 | } |
| 468 | - if std::env::var_os("EC_VP9_DBG").is_some() { | |
| 469 | - eprintln!("DBG tx_mode={} consumed={}", tx_mode, r.byte_offset()); | |
| 470 | - eprintln!( | |
| 471 | - "DBG skip_probs={:?} p8x8={:?} p16={:?}", | |
| 472 | - ctx.skip, ctx.tx_p8x8, ctx.tx_p16x16 | |
| 473 | - ); | |
| 474 | - eprintln!( | |
| 475 | - "DBG coef[0][0][0][0][0..3]={:?} coef[0][0][1][1][0..3]={:?}", | |
| 476 | - ctx.coef[0][0][0][0], ctx.coef[0][0][1][1] | |
| 477 | - ); | |
| 478 | - } | |
| 479 | 391 | ensure(r.overreads() == 0, "compressed header desync")?; |
| 480 | 392 | Ok(CompressedHeader { |
| 481 | 393 | tx_mode, |
crates/ec-vp9/src/inter.rsmodified+0 -59
| @@ -583,7 +583,6 @@ fn find_mv_refs( | ||
| 583 | 583 | ) -> (usize, [(i32, i32); MAX_MV_REF_CANDIDATES]) { |
| 584 | 584 | let search = &MV_REF_BLOCKS[bsize]; |
| 585 | 585 | let early_break = mode != NEARMV; |
| 586 | - let mvref_dbg = crate::mvdbg_enabled() && mode == NEWMV; | |
| 587 | 586 | let mut list = [(0, 0); MAX_MV_REF_CANDIDATES]; |
| 588 | 587 | let mut count = 0usize; |
| 589 | 588 | let mut different_ref_found = false; |
| @@ -646,30 +645,6 @@ fn find_mv_refs( | ||
| 646 | 645 | } |
| 647 | 646 | } |
| 648 | 647 | |
| 649 | - if crate::mvdbg2_enabled() | |
| 650 | - && ((row == 8 && col == 104) || (row == 32 && col == 64) || (row == 8 && col == 32)) | |
| 651 | - { | |
| 652 | - for (i, p) in search.iter().enumerate() { | |
| 653 | - let ins = is_inside(c, row, col, *p); | |
| 654 | - let c2 = st.at((row as i32 + p.0) as usize, (col as i32 + p.1) as usize); | |
| 655 | - let qr = (row as i32 + p.0) as usize; | |
| 656 | - let qc = (col as i32 + p.1) as usize; | |
| 657 | - match c2 { | |
| 658 | - Some(cd) => eprintln!( | |
| 659 | - "MVC r={row} c={col} i={i} p={p:?} q=({qr} {qc}) idx={} inside={ins} ref0={} ref1={} mv0={:?} mv1={:?} inter={}", | |
| 660 | - qr * c.mi_cols + qc, | |
| 661 | - cd.ref_frame[0], cd.ref_frame[1], cd.mv[0], cd.mv[1], cd.is_inter | |
| 662 | - ), | |
| 663 | - None => eprintln!("MVC r={row} c={col} i={i} p={p:?} q=({qr} {qc}) inside={ins} none"), | |
| 664 | - } | |
| 665 | - } | |
| 666 | - } | |
| 667 | - if mvref_dbg { | |
| 668 | - eprintln!( | |
| 669 | - "MVREF r={row} c={col} bsize={bsize} mode={mode} n={count} l0={:?} l1={:?}", | |
| 670 | - list[0], list[1] | |
| 671 | - ); | |
| 672 | - } | |
| 673 | 648 | if !done && different_ref_found { |
| 674 | 649 | for p in search.iter() { |
| 675 | 650 | if !is_inside(c, row, col, *p) { |
| @@ -828,49 +803,27 @@ fn append_sub8x8_mvs_for_idx( | ||
| 828 | 803 | |
| 829 | 804 | /// `read_mv_component` (`vp9_decodemv.c:246`). |
| 830 | 805 | fn read_mv_component(r: &mut BoolDecoder, fc: &FrameContext, comp: usize, use_hp: bool) -> i32 { |
| 831 | - let dbg = crate::interdump_enabled(); | |
| 832 | - if dbg { | |
| 833 | - eprintln!("MVF c{comp} sign"); | |
| 834 | - } | |
| 835 | 806 | let sign = r.read_bool(fc.nmv_sign[comp]); |
| 836 | - if dbg { | |
| 837 | - eprintln!("MVF c{comp} cls"); | |
| 838 | - } | |
| 839 | 807 | let mv_class = r.read_tree(&MV_CLASS_TREE, &fc.nmv_classes[comp]) as i32; |
| 840 | 808 | let class0 = mv_class == 0; |
| 841 | 809 | let mut d = 0i32; |
| 842 | 810 | let mut mag; |
| 843 | - if dbg { | |
| 844 | - eprintln!("MVF c{comp} class={mv_class}"); | |
| 845 | - } | |
| 846 | 811 | if class0 { |
| 847 | - if dbg { | |
| 848 | - eprintln!("MVF c{comp} class0bit"); | |
| 849 | - } | |
| 850 | 812 | d = r.read_bool(fc.nmv_class0[comp][0]) as i32; |
| 851 | 813 | mag = 0; |
| 852 | 814 | } else { |
| 853 | 815 | let n = mv_class + CLASS0_BITS - 1; |
| 854 | 816 | for i in 0..n { |
| 855 | - if dbg { | |
| 856 | - eprintln!("MVF c{comp} bits[{i}]"); | |
| 857 | - } | |
| 858 | 817 | d |= (r.read_bool(fc.nmv_bits[comp][i as usize]) as i32) << i; |
| 859 | 818 | } |
| 860 | 819 | mag = CLASS0_SIZE << (mv_class + 2); |
| 861 | 820 | } |
| 862 | - if dbg { | |
| 863 | - eprintln!("MVF c{comp} fp"); | |
| 864 | - } | |
| 865 | 821 | let fr = if class0 { |
| 866 | 822 | r.read_tree(&MV_FP_TREE, &fc.nmv_class0_fp[comp][d as usize]) |
| 867 | 823 | } else { |
| 868 | 824 | r.read_tree(&MV_FP_TREE, &fc.nmv_fp[comp]) |
| 869 | 825 | } as i32; |
| 870 | 826 | let hp = if use_hp { |
| 871 | - if dbg { | |
| 872 | - eprintln!("MVF c{comp} hp"); | |
| 873 | - } | |
| 874 | 827 | r.read_bool(if class0 { |
| 875 | 828 | fc.nmv_class0_hp[comp] |
| 876 | 829 | } else { |
| @@ -897,9 +850,6 @@ fn read_mv( | ||
| 897 | 850 | ) -> ((i32, i32), (i32, i32)) { |
| 898 | 851 | let joint = r.read_tree(&MV_JOINT_TREE, &fc.nmv_joints); |
| 899 | 852 | let use_hp = allow_hp && use_mv_hp(pred); |
| 900 | - if crate::interdump_enabled() { | |
| 901 | - eprintln!("MVJ joint={joint} use_hp={use_hp} pred={pred:?}"); | |
| 902 | - } | |
| 903 | 853 | // mv_joint_vertical = joint & 2, mv_joint_horizontal = joint & 1. |
| 904 | 854 | let mut diff = (0i32, 0i32); |
| 905 | 855 | if joint & 2 != 0 { |
| @@ -1256,17 +1206,8 @@ fn read_inter_block_mode_info( | ||
| 1256 | 1206 | |
| 1257 | 1207 | info.interp_filter = if c.frame_interp == SWITCHABLE { |
| 1258 | 1208 | let ictx = switchable_interp_ctx(nb); |
| 1259 | - if crate::interdump_enabled() { | |
| 1260 | - eprintln!( | |
| 1261 | - "SWI ctx={} p0={} p1={}", | |
| 1262 | - ictx, fc.switchable_interp[ictx][0], fc.switchable_interp[ictx][1] | |
| 1263 | - ); | |
| 1264 | - } | |
| 1265 | 1209 | let t = r.read_tree(&SWITCHABLE_INTERP_TREE, &fc.switchable_interp[ictx]); |
| 1266 | 1210 | counts.switchable_interp[ictx][t as usize] += 1; |
| 1267 | - if crate::interdump_enabled() { | |
| 1268 | - eprintln!("SWItype {t}"); | |
| 1269 | - } | |
| 1270 | 1211 | t |
| 1271 | 1212 | } else { |
| 1272 | 1213 | c.frame_interp |
crates/ec-vp9/src/intra.rsmodified+0 -29
| @@ -190,22 +190,6 @@ pub(crate) fn build_intra_predictors( | ||
| 190 | 190 | |
| 191 | 191 | // The C's `const_above_row = above_ref` shortcut for bs==4 && |
| 192 | 192 | // right&&left stages the same bytes, so above_data is equivalent. |
| 193 | - if crate::trace_enabled() | |
| 194 | - && std::env::var("EC_VP9_PROBE_TU") | |
| 195 | - .ok() | |
| 196 | - .and_then(|s| { | |
| 197 | - let mut it = s.split(','); | |
| 198 | - Some((it.next()?.parse::<usize>().ok()?, it.next()?.parse().ok()?)) | |
| 199 | - }) | |
| 200 | - .is_some_and(|(px, py)| x0 == px && y0 == py) | |
| 201 | - { | |
| 202 | - eprintln!( | |
| 203 | - "STAGE x0={x0} y0={y0} mode={mode} bs={bs} above={:?} cor={} left={:?}", | |
| 204 | - &above_data[A..A + 8], | |
| 205 | - above_data[A - 1], | |
| 206 | - &left_col[..8] | |
| 207 | - ); | |
| 208 | - } | |
| 209 | 193 | let dst = &mut data[y0 * stride + x0..]; |
| 210 | 194 | dispatch( |
| 211 | 195 | mode, |
| @@ -218,19 +202,6 @@ pub(crate) fn build_intra_predictors( | ||
| 218 | 202 | left_available, |
| 219 | 203 | bd, |
| 220 | 204 | ); |
| 221 | - if crate::trace_enabled() | |
| 222 | - && std::env::var("EC_VP9_PROBE_TU") | |
| 223 | - .ok() | |
| 224 | - .and_then(|s| { | |
| 225 | - let mut it = s.split(','); | |
| 226 | - Some((it.next()?.parse::<usize>().ok()?, it.next()?.parse().ok()?)) | |
| 227 | - }) | |
| 228 | - .is_some_and(|(px, py)| x0 == px && y0 == py) | |
| 229 | - { | |
| 230 | - for rr in 0..bs { | |
| 231 | - eprintln!("PRED r={rr} {:?}", &dst[rr * stride..rr * stride + bs]); | |
| 232 | - } | |
| 233 | - } | |
| 234 | 205 | } |
| 235 | 206 | |
| 236 | 207 | fn dispatch( |
crates/ec-vp9/src/knobs.rsdeleted+0 -69
| @@ -1,69 +0,0 @@ | ||
| 1 | -//! Debug switches the VP9 decoder reads from the environment, with a | |
| 2 | -//! per-thread override that tests set instead of editing the process | |
| 3 | -//! environment (which is `unsafe` in Rust 2024). | |
| 4 | -//! | |
| 5 | -//! The decoder reads these on the thread that calls `decode`: tile workers | |
| 6 | -//! and the loop-filter threads never read them. An override set on a test's | |
| 7 | -//! own thread therefore covers exactly that test's decodes. With no override | |
| 8 | -//! set, each reader answers from the environment exactly as it always has. | |
| 9 | - | |
| 10 | -use std::cell::Cell; | |
| 11 | -use std::thread::LocalKey; | |
| 12 | - | |
| 13 | -thread_local! { | |
| 14 | - static SKIP_LF: Cell<Option<bool>> = const { Cell::new(None) }; | |
| 15 | - static FORCE_TAIL: Cell<Option<usize>> = const { Cell::new(None) }; | |
| 16 | -} | |
| 17 | - | |
| 18 | -/// Restores the value a knob had before the guard was created, when dropped. | |
| 19 | -#[doc(hidden)] | |
| 20 | -#[must_use = "the override ends as soon as this guard is dropped"] | |
| 21 | -pub struct Override { | |
| 22 | - restore: Option<Box<dyn FnOnce()>>, | |
| 23 | -} | |
| 24 | - | |
| 25 | -impl Drop for Override { | |
| 26 | - fn drop(&mut self) { | |
| 27 | - if let Some(restore) = self.restore.take() { | |
| 28 | - restore(); | |
| 29 | - } | |
| 30 | - } | |
| 31 | -} | |
| 32 | - | |
| 33 | -fn force<T: Copy + 'static>(slot: &'static LocalKey<Cell<T>>, value: T) -> Override { | |
| 34 | - let prev = slot.with(|c| c.replace(value)); | |
| 35 | - Override { | |
| 36 | - restore: Some(Box::new(move || slot.with(|c| c.set(prev)))), | |
| 37 | - } | |
| 38 | -} | |
| 39 | - | |
| 40 | -/// `EC_VP9_SKIP_LF`: when set, the loop-filter post-pass is skipped. | |
| 41 | -pub(crate) fn skip_lf() -> bool { | |
| 42 | - SKIP_LF | |
| 43 | - .with(Cell::get) | |
| 44 | - .unwrap_or_else(|| std::env::var_os("EC_VP9_SKIP_LF").is_some()) | |
| 45 | -} | |
| 46 | - | |
| 47 | -/// `EC_VP9_FORCE_TAIL`: overrides the keyframe tail start offset, if set and | |
| 48 | -/// parseable. | |
| 49 | -pub(crate) fn force_tail() -> Option<usize> { | |
| 50 | - FORCE_TAIL.with(Cell::get).or_else(|| { | |
| 51 | - std::env::var("EC_VP9_FORCE_TAIL") | |
| 52 | - .ok() | |
| 53 | - .and_then(|s| s.parse().ok()) | |
| 54 | - }) | |
| 55 | -} | |
| 56 | - | |
| 57 | -/// Forces `EC_VP9_SKIP_LF` on (`Some(true)`), off (`Some(false)`) or back to | |
| 58 | -/// the environment (`None`) on this thread, until the guard drops. | |
| 59 | -#[doc(hidden)] | |
| 60 | -pub fn set_skip_lf(on: Option<bool>) -> Override { | |
| 61 | - force(&SKIP_LF, on) | |
| 62 | -} | |
| 63 | - | |
| 64 | -/// Forces `EC_VP9_FORCE_TAIL` to `tail` on this thread, until the guard drops. | |
| 65 | -/// `None` returns the knob to the environment. | |
| 66 | -#[doc(hidden)] | |
| 67 | -pub fn set_force_tail(tail: Option<usize>) -> Override { | |
| 68 | - force(&FORCE_TAIL, tail) | |
| 69 | -} |
crates/ec-vp9/src/lib.rsmodified+0 -55
| @@ -42,13 +42,9 @@ pub mod decode; | ||
| 42 | 42 | pub mod header; |
| 43 | 43 | pub(crate) mod inter; |
| 44 | 44 | pub mod intra; |
| 45 | -#[doc(hidden)] | |
| 46 | -pub mod knobs; | |
| 47 | 45 | pub mod loopfilter; |
| 48 | 46 | pub(crate) mod mc; |
| 49 | 47 | pub mod modes; |
| 50 | -pub mod prof; | |
| 51 | -mod stack_budget; | |
| 52 | 48 | pub mod stream; |
| 53 | 49 | pub mod tables; |
| 54 | 50 | pub mod tokens; |
| @@ -75,54 +71,3 @@ pub(crate) fn round_pow2(v: i32, n: i32) -> i32 { | ||
| 75 | 71 | (v + (1 << (n - 1))) >> n |
| 76 | 72 | } |
| 77 | 73 | |
| 78 | -/// Whether `EC_VP9_TRACE` decision tracing is enabled, resolved once per | |
| 79 | -/// process. An `var_os` per bool read would lock std's ENV lock on every | |
| 80 | -/// coefficient; the hot path is a single relaxed atomic load. | |
| 81 | -pub(crate) fn trace_enabled() -> bool { | |
| 82 | - use std::sync::atomic::{AtomicU8, Ordering}; | |
| 83 | - static STATE: AtomicU8 = AtomicU8::new(0); | |
| 84 | - match STATE.load(Ordering::Relaxed) { | |
| 85 | - 0 => { | |
| 86 | - let on = std::env::var_os("EC_VP9_TRACE").is_some(); | |
| 87 | - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); | |
| 88 | - on | |
| 89 | - } | |
| 90 | - 1 => false, | |
| 91 | - _ => true, | |
| 92 | - } | |
| 93 | -} | |
| 94 | - | |
| 95 | -/// Cached `getenv` probe: `EC_VP9_*` gates are consulted per block, per MV | |
| 96 | -/// component and per switchable-interp read, and `std::env::var_os` locks std's | |
| 97 | -/// ENV lock, so each gate resolves once per process and the hot path is a | |
| 98 | -/// single relaxed atomic load (see `trace_enabled`). | |
| 99 | -macro_rules! cached_gate { | |
| 100 | - ($fn_name:ident, $env:literal) => { | |
| 101 | - pub(crate) fn $fn_name() -> bool { | |
| 102 | - use std::sync::atomic::{AtomicU8, Ordering}; | |
| 103 | - static STATE: AtomicU8 = AtomicU8::new(0); | |
| 104 | - match STATE.load(Ordering::Relaxed) { | |
| 105 | - 0 => { | |
| 106 | - let on = std::env::var_os($env).is_some(); | |
| 107 | - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); | |
| 108 | - on | |
| 109 | - } | |
| 110 | - 1 => false, | |
| 111 | - _ => true, | |
| 112 | - } | |
| 113 | - } | |
| 114 | - }; | |
| 115 | -} | |
| 116 | - | |
| 117 | -// Per-block dump gate for the inter-syntax lane (scratch harnesses); | |
| 118 | -// a candidate-list dump (`mode == NEWMV` only); | |
| 119 | -// a search-position cell + grid-store dump; and a post-compressed-header | |
| 120 | -// MV probability table dump. (Plain comments: a doc comment on a macro | |
| 121 | -// invocation is an "unused doc comment" warning.) | |
| 122 | -cached_gate!(interdump_enabled, "EC_VP9_INTERDUMP"); | |
| 123 | -cached_gate!(mvdbg_enabled, "EC_VP9_MVDGB"); | |
| 124 | -cached_gate!(mvdbg2_enabled, "EC_VP9_MVDGB2"); | |
| 125 | -cached_gate!(mvdump_enabled, "EC_VP9_MVDUMP"); | |
| 126 | -// [scratch] per-transform-block token state (the inter pixel lane). | |
| 127 | -cached_gate!(tokdbg_enabled, "EC_VP9_TOKDGB"); | |
| 128 | -cached_gate!(lfmasksy_enabled, "EC_VP9_LFMASKSY"); |
crates/ec-vp9/src/loopfilter.rsmodified+3 -65
| @@ -20,26 +20,6 @@ | ||
| 20 | 20 | |
| 21 | 21 | use crate::tables::*; |
| 22 | 22 | |
| 23 | -/// `LFTRACE` gate, optionally limited to one frame by `EC_VP9_LF_FRAME` | |
| 24 | -/// (the n-th `filter_frame` call of the process — the decode order's frame | |
| 25 | -/// index). The oracle's own LF trace is gated the same way, which is what lets | |
| 26 | -/// the two edge lists be diffed per frame. | |
| 27 | -fn lftrace_on() -> bool { | |
| 28 | - use std::sync::atomic::{AtomicUsize, Ordering}; | |
| 29 | - if std::env::var_os("LFTRACE").is_none() { | |
| 30 | - return false; | |
| 31 | - } | |
| 32 | - static CALLS: AtomicUsize = AtomicUsize::new(0); | |
| 33 | - let n = CALLS.fetch_add(1, Ordering::Relaxed); | |
| 34 | - match std::env::var("EC_VP9_LF_FRAME") | |
| 35 | - .ok() | |
| 36 | - .and_then(|v| v.parse::<usize>().ok()) | |
| 37 | - { | |
| 38 | - Some(f) => f == n, | |
| 39 | - None => true, | |
| 40 | - } | |
| 41 | -} | |
| 42 | - | |
| 43 | 23 | /// `vp9_loopfilter.c` UV mask tables (BLOCK_SIZES indexed 4X4..64X64). |
| 44 | 24 | const UV_LEFT_PRED: [u16; 13] = [ |
| 45 | 25 | 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0011, 0x0001, 0x0011, 0x1111, 0x0011, |
| @@ -580,24 +560,6 @@ impl LfGrids { | ||
| 580 | 560 | left[i] &= 0xfefefefefefefefe; |
| 581 | 561 | } |
| 582 | 562 | } |
| 583 | - // [scratch] EC_VP9_LFMASKSY: per-superblock luma masks after | |
| 584 | - // `vp9_adjust_mask`, in the oracle's `LFMASKSY` field order. | |
| 585 | - if crate::lfmasksy_enabled() { | |
| 586 | - eprintln!( | |
| 587 | - "LFY {} {} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x} {:016x}", | |
| 588 | - sbr, | |
| 589 | - sbc, | |
| 590 | - left[TX_4X4], | |
| 591 | - left[TX_8X8], | |
| 592 | - left[TX_16X16], | |
| 593 | - left[TX_32X32], | |
| 594 | - above[TX_4X4], | |
| 595 | - above[TX_8X8], | |
| 596 | - above[TX_16X16], | |
| 597 | - above[TX_32X32], | |
| 598 | - int4 | |
| 599 | - ); | |
| 600 | - } | |
| 601 | 563 | (left, above, int4) |
| 602 | 564 | } |
| 603 | 565 | |
| @@ -632,9 +594,7 @@ impl LfGrids { | ||
| 632 | 594 | h: usize, |
| 633 | 595 | sharpness: u8, |
| 634 | 596 | bd: u8, |
| 635 | - trace: bool, | |
| 636 | 597 | ) { |
| 637 | - let lftrace = trace && lftrace_on(); | |
| 638 | 598 | // Luma masks, ported from vp9_setup_mask/build_masks and |
| 639 | 599 | // vp9_adjust_mask (bit i = MI row i>>3, MI col i&7; each bit |
| 640 | 600 | // covers an 8x8 cell). Edges are emitted from the masks. |
| @@ -676,20 +636,9 @@ impl LfGrids { | ||
| 676 | 636 | t = 8; |
| 677 | 637 | } |
| 678 | 638 | lpf_edge(data, yy * stride + xx, stride, 1, t, bl, li, th, 8, bd); |
| 679 | - if lftrace { | |
| 680 | - let kind = match t { | |
| 681 | - 16 => "V16", | |
| 682 | - 8 => "V8", | |
| 683 | - _ => "V4", | |
| 684 | - }; | |
| 685 | - eprintln!("{kind} {} {}", xx, yy); | |
| 686 | - } | |
| 687 | 639 | } |
| 688 | 640 | if int4 & bit != 0 && xx + 8 <= w && yy + 8 <= h { |
| 689 | 641 | lpf_edge(data, yy * stride + xx + 4, stride, 1, 4, bl, li, th, 8, bd); |
| 690 | - if lftrace { | |
| 691 | - eprintln!("V4I {} {}", xx + 4, yy); | |
| 692 | - } | |
| 693 | 642 | } |
| 694 | 643 | } |
| 695 | 644 | } |
| @@ -725,14 +674,6 @@ impl LfGrids { | ||
| 725 | 674 | t = 8; |
| 726 | 675 | } |
| 727 | 676 | lpf_edge(data, yy * stride + xx, stride, 0, t, bl, li, th, 8, bd); |
| 728 | - if lftrace { | |
| 729 | - let kind = match t { | |
| 730 | - 16 => "H16", | |
| 731 | - 8 => "H8", | |
| 732 | - _ => "H4", | |
| 733 | - }; | |
| 734 | - eprintln!("{kind} {} {}", xx, yy); | |
| 735 | - } | |
| 736 | 677 | } |
| 737 | 678 | } |
| 738 | 679 | // Internal 4x4 luma edge at yy + 4. libvpx's luma |
| @@ -754,9 +695,6 @@ impl LfGrids { | ||
| 754 | 695 | 8, |
| 755 | 696 | bd, |
| 756 | 697 | ); |
| 757 | - if lftrace { | |
| 758 | - eprintln!("H4I {} {}", xx, yy + 4); | |
| 759 | - } | |
| 760 | 698 | } |
| 761 | 699 | } |
| 762 | 700 | } |
| @@ -1277,8 +1215,8 @@ impl LfGrids { | ||
| 1277 | 1215 | // output is identical to the serial order. |
| 1278 | 1216 | let chroma = |data_u: &mut [Sample], data_v: &mut [Sample]| { |
| 1279 | 1217 | if ss_x == 0 && ss_y == 0 { |
| 1280 | - self.filter_ss00_plane(data_u, uv_stride, uv_w, uv_h, sharpness, bd, false); | |
| 1281 | - self.filter_ss00_plane(data_v, uv_stride, uv_w, uv_h, sharpness, bd, false); | |
| 1218 | + self.filter_ss00_plane(data_u, uv_stride, uv_w, uv_h, sharpness, bd); | |
| 1219 | + self.filter_ss00_plane(data_v, uv_stride, uv_w, uv_h, sharpness, bd); | |
| 1282 | 1220 | } else if ss_x == 1 && ss_y == 1 { |
| 1283 | 1221 | self.filter_ss11_plane(data_u, uv_stride, uv_h, sharpness, bd); |
| 1284 | 1222 | self.filter_ss11_plane(data_v, uv_stride, uv_h, sharpness, bd); |
| @@ -1289,7 +1227,7 @@ impl LfGrids { | ||
| 1289 | 1227 | }; |
| 1290 | 1228 | std::thread::scope(|scope| { |
| 1291 | 1229 | scope.spawn(|| chroma(u, v)); |
| 1292 | - self.filter_ss00_plane(y, stride, y_w, y_h, sharpness, bd, true); | |
| 1230 | + self.filter_ss00_plane(y, stride, y_w, y_h, sharpness, bd); | |
| 1293 | 1231 | }); |
| 1294 | 1232 | } |
| 1295 | 1233 | } |
crates/ec-vp9/src/modes.rsmodified+0 -6
| @@ -278,11 +278,5 @@ pub(crate) fn read_intra_frame_mode_info( | ||
| 278 | 278 | // uv mode: `vp9_kf_uv_mode_prob` indexed by y mode, decoded with the |
| 279 | 279 | // SAME intra_mode_tree (decodemv.c:232 calls read_intra_mode). |
| 280 | 280 | mi.uv_mode = r.read_tree(&INTRA_MODE_TREE, &kf_uv_probs(mi.mode)); |
| 281 | - if crate::trace_enabled() { | |
| 282 | - eprintln!( | |
| 283 | - "MODE row={} col={} bsize={} skip={} tx={} y={} uv={}", | |
| 284 | - row, col, sb_type, mi.skip as u8, mi.tx_size, mi.mode, mi.uv_mode | |
| 285 | - ); | |
| 286 | - } | |
| 287 | 281 | Ok(mi) |
| 288 | 282 | } |
crates/ec-vp9/src/prof.rsdeleted+0 -64
| @@ -1,64 +0,0 @@ | ||
| 1 | -//! Phase timers for the decoder, enabled by `EC_VP9_PROFILE=1`. | |
| 2 | -//! | |
| 3 | -//! Each phase accumulates CPU nanoseconds across all threads (atomic adds), so with | |
| 4 | -//! tile threads the sums can exceed wall time. Off by default: `start` is then one | |
| 5 | -//! relaxed atomic load and no clock read. | |
| 6 | - | |
| 7 | -use std::sync::atomic::{AtomicU64, AtomicU8, Ordering}; | |
| 8 | -use std::time::Instant; | |
| 9 | - | |
| 10 | -/// Phases, indexes into [`TOTALS`]. | |
| 11 | -#[derive(Clone, Copy)] | |
| 12 | -pub(crate) enum Phase { | |
| 13 | - /// Whole tile walk (parse plus reconstruction). | |
| 14 | - Walk = 0, | |
| 15 | - /// Inter prediction (motion compensation) for all planes of a block. | |
| 16 | - Mc = 1, | |
| 17 | - /// Coefficient token decoding. | |
| 18 | - Tokens = 2, | |
| 19 | - /// Inverse transform and add. | |
| 20 | - Idct = 3, | |
| 21 | - /// Loop filter over the whole frame. | |
| 22 | - LoopFilter = 4, | |
| 23 | - /// Tile-thread overhead: worker state setup and copying columns back. | |
| 24 | - Threads = 5, | |
| 25 | -} | |
| 26 | - | |
| 27 | -/// Names for [`report`], in [`Phase`] order. | |
| 28 | -pub const NAMES: [&str; 6] = ["walk", "mc", "tokens", "idct", "loopfilter", "threads"]; | |
| 29 | - | |
| 30 | -static TOTALS: [AtomicU64; 6] = [const { AtomicU64::new(0) }; 6]; | |
| 31 | - | |
| 32 | -/// Whether `EC_VP9_PROFILE` turned the timers on (read once per process). | |
| 33 | -pub fn enabled() -> bool { | |
| 34 | - static STATE: AtomicU8 = AtomicU8::new(0); | |
| 35 | - match STATE.load(Ordering::Relaxed) { | |
| 36 | - 0 => { | |
| 37 | - let on = std::env::var_os("EC_VP9_PROFILE").is_some_and(|v| v != "0"); | |
| 38 | - STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed); | |
| 39 | - on | |
| 40 | - } | |
| 41 | - s => s == 2, | |
| 42 | - } | |
| 43 | -} | |
| 44 | - | |
| 45 | -/// Start a timer; `None` when profiling is off. | |
| 46 | -pub(crate) fn start() -> Option<Instant> { | |
| 47 | - if enabled() { | |
| 48 | - Some(Instant::now()) | |
| 49 | - } else { | |
| 50 | - None | |
| 51 | - } | |
| 52 | -} | |
| 53 | - | |
| 54 | -/// Add the time since `t` to `phase`. | |
| 55 | -pub(crate) fn stop(phase: Phase, t: Option<Instant>) { | |
| 56 | - if let Some(t) = t { | |
| 57 | - TOTALS[phase as usize].fetch_add(t.elapsed().as_nanos() as u64, Ordering::Relaxed); | |
| 58 | - } | |
| 59 | -} | |
| 60 | - | |
| 61 | -/// Accumulated seconds per phase, in [`NAMES`] order. | |
| 62 | -pub fn totals() -> [f64; 6] { | |
| 63 | - std::array::from_fn(|i| TOTALS[i].load(Ordering::Relaxed) as f64 * 1e-9) | |
| 64 | -} |
crates/ec-vp9/src/stack_budget.rsdeleted+0 -748
| @@ -1,748 +0,0 @@ | ||
| 1 | -#![cfg(test)] | |
| 2 | -//! A measured bound on the crate's BY-VALUE types, and a gate that bites. | |
| 3 | -//! | |
| 4 | -//! # The class | |
| 5 | -//! | |
| 6 | -//! A large struct returned BY VALUE from a public constructor is a stack | |
| 7 | -//! cost, not a heap cost, and the cost is paid by the CALLER. The | |
| 8 | -//! constructors nest, and in an unoptimized build each level materialises | |
| 9 | -//! its whole `Result<T>` return slot before the inner call returns. So one | |
| 10 | -//! value's `size_of` is the MULTIPLIER, and the chain length is the other | |
| 11 | -//! factor. | |
| 12 | -//! | |
| 13 | -//! That is not hypothetical. `Decoder` was **10,944** bytes by value -- | |
| 14 | -//! five INLINE `FrameContext` slots (2,039 bytes each: the `frame_ctxs` | |
| 15 | -//! array of four, plus the `ctx` in force) -- and 10,944 is **1.34x** this | |
| 16 | -//! crate's 8 KiB by-value budget. Boxing both fields | |
| 17 | -//! (`frame_ctxs: Box<[FrameContext; 4]>` and `ctx: Box<FrameContext>`) took | |
| 18 | -//! it to **768**, and [`the_frame_contexts_stay_behind_a_box`] is the pin | |
| 19 | -//! that keeps it there. | |
| 20 | -//! | |
| 21 | -//! # Why this module exists | |
| 22 | -//! | |
| 23 | -//! One boxed field is one measurement. This module is the sweep: | |
| 24 | -//! | |
| 25 | -//! 1. [`BY_VALUE_TYPES`] is the inventory -- every type in this crate a | |
| 26 | -//! public `fn` can return by value, with a measured `size_of` recorded | |
| 27 | -//! as of this commit. [`the_measured_inventory_is_accurate`] fails if a | |
| 28 | -//! type's size moves, so the table cannot rot into stale small numbers. | |
| 29 | -//! 2. [`STACK_BUDGET`] is the bound, and | |
| 30 | -//! [`every_by_value_type_fits_the_stack_budget`] asserts it BY NAME for | |
| 31 | -//! every public row, so a regression reds naming the type. | |
| 32 | -//! 3. [`the_frame_contexts_stay_behind_a_box`] pins the boxed field, with | |
| 33 | -//! a negative control so the pin cannot be matching a comment. | |
| 34 | -//! 4. [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] is the | |
| 35 | -//! capability arm: it really constructs `Decoder` on a deliberately | |
| 36 | -//! tight thread and asserts real post-construction state, pinning the | |
| 37 | -//! measured live stack of the by-value return path. At 256 KiB it does | |
| 38 | -//! NOT red the unboxing mutation -- a 10,944-byte struct is not that | |
| 39 | -//! expensive; the budget assert and the box pin are what red, BY NAME. | |
| 40 | -//! The arm's own docs carry the measured threshold table. | |
| 41 | -//! 5. [`every_by_value_public_return_is_in_the_inventory`] re-derives the | |
| 42 | -//! set of by-value public returns from the crate source. | |
| 43 | -//! [`the_inventory_scan_is_not_vacuous`] is its control. | |
| 44 | -//! | |
| 45 | -//! # The bound, and why this number | |
| 46 | -//! | |
| 47 | -//! [`STACK_BUDGET`] = 8192 bytes (8 KiB) -- the SAME number as ec-av1's, | |
| 48 | -//! deliberately, so one bound covers the by-value class across the codec | |
| 49 | -//! crates rather than each crate calibrating its own. | |
| 50 | -//! | |
| 51 | -//! **The quantity being bounded.** Not `size_of` in the abstract, but | |
| 52 | -//! *what a caller can be made to owe*: the size of one by-value return, | |
| 53 | -//! multiplied by how many public levels hold a copy at once. Three inputs: | |
| 54 | -//! 1. **The smallest stack a caller can hand this crate is 2 MiB.** That | |
| 55 | -//! is libtest's default test thread and what `std::thread::Builder` | |
| 56 | -//! hands a caller who does not ask for a size. A library consumer gets | |
| 57 | -//! no `.cargo/config.toml` -- and this repo's sets | |
| 58 | -//! `RUST_MIN_STACK = 67108864`, which HIDES the problem from this | |
| 59 | -//! workspace's own runs. The bound is therefore derived against the | |
| 60 | -//! 2 MiB an unconfigured caller really has. | |
| 61 | -//! 2. **The deepest PUBLIC by-value chain is 3** | |
| 62 | -//! ([`DEEPEST_PUBLIC_CHAIN`]): `stream::decode_stream` (stream.rs:74) | |
| 63 | -//! -> `stream::decode_stream_with` (stream.rs:88) -> | |
| 64 | -//! `Decoder::decode` (decode.rs:238), after which the remaining frames | |
| 65 | -//! (`decode_one`, `decode_keyframe`, `decode_inter`) are private. The | |
| 66 | -//! test asserts `DEEPEST_PUBLIC_CHAIN * worst * 8 <= 2 MiB` -- the | |
| 67 | -//! by-value return slots may claim at most an EIGHTH of a caller's | |
| 68 | -//! stack, leaving the rest for the decode walk, which is the thing that | |
| 69 | -//! actually needs it. | |
| 70 | -//! 3. **The budget applies only to types a `pub fn` returns.** The | |
| 71 | -//! crate-private 2,039-byte `FrameContext` is measured and listed but | |
| 72 | -//! NOT bounded, because no caller can reach it by value -- every field | |
| 73 | -//! holding one is a `Box`, pinned by | |
| 74 | -//! [`the_frame_contexts_stay_behind_a_box`]. Bounding it would | |
| 75 | -//! calibrate the number to something unreachable. | |
| 76 | -//! | |
| 77 | -//! **Where the number sits.** At 8 KiB with the worst public return at | |
| 78 | -//! 768 bytes ([`Decoder`]), the worst a caller owes on return slots | |
| 79 | -//! alone is `3 x 768 = 2,304` bytes -- 0.11% of a 2 MiB thread, and the | |
| 80 | -//! budget itself is 10.7x the largest live by-value type. Both directions | |
| 81 | -//! have room, which is the point: a bound the largest type sits just | |
| 82 | -//! under is a bound the next lane will quietly raise. | |
| 83 | -//! | |
| 84 | -//! **What it catches.** The pre-fix `Decoder` (10,944 B) is **1.34x over** | |
| 85 | -//! -- the SMALLEST over-budget case of the three crates this sweep has | |
| 86 | -//! measured (ec-av1's pre-fix `Av1Encoder` was 17.1x over, ec-ac3's | |
| 87 | -//! pre-fix `Ac3Decoder` 2.43x). It still reds, and by a factor rather than | |
| 88 | -//! a hair, which is all a bound has to do. | |
| 89 | -//! | |
| 90 | -//! # This crate's inventory is SMALL, and that is a measurement | |
| 91 | -//! | |
| 92 | -//! ec-av1's floor for bound-checked public rows is 10. **ec-vp9 genuinely | |
| 93 | -//! has 3** ([`Decoder`], [`Picture`], [`BoolDecoder`]) and the floor is | |
| 94 | -//! lowered to 3 rather than padded with types this crate does not have. | |
| 95 | -//! The reason is structural, not accidental: every other module here | |
| 96 | -//! (`inter`, `mc`, `modes`, `tokens`, `transform`, `loopfilter`, `intra`, | |
| 97 | -//! `header`, `tables`) exposes ZERO `pub fn` -- its API is | |
| 98 | -//! `pub(crate)`, reached through `Decoder`. There are 13 `pub fn` lines | |
| 99 | -//! in the whole crate, 11 of which return a primitive, a `Self`, or | |
| 100 | -//! `()`. | |
| 101 | -//! | |
| 102 | -//! The sweep is still worth having at that size, and the reason is | |
| 103 | -//! direction of travel: the scan found exactly ONE by-value public return | |
| 104 | -//! name (`Picture`, from `Decoder::decode`), because `Decoder::new` | |
| 105 | -//! returns `Self` and `BoolDecoder::new` returns `Result<Self>`, both of | |
| 106 | -//! which the matcher exempts. A tiny inventory is a floor to grow into, | |
| 107 | -//! and [`every_by_value_public_return_is_in_the_inventory`] is what makes | |
| 108 | -//! a new 40 KB by-value return impossible to add unnoticed -- which is the | |
| 109 | -//! only direction that can actually bite here. | |
| 110 | -//! | |
| 111 | -//! # What it does not claim | |
| 112 | -//! | |
| 113 | -//! `size_of` is layout, not stack depth. The residual is why | |
| 114 | -//! [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] constructs | |
| 115 | -//! for real instead of trusting the arithmetic. And note | |
| 116 | -//! [`the_frame_contexts_stay_behind_a_box`] pins ONE field: `Decoder::ctx` | |
| 117 | -//! (decode.rs:129) is still an INLINE `FrameContext`, and at 2,039 bytes | |
| 118 | -//! it is 72.8% of the 2,800 a caller pays today. Boxing that too is the | |
| 119 | -//! obvious next move in this class; this module only records the | |
| 120 | -//! measurement. | |
| 121 | - | |
| 122 | -use crate::bool::BoolDecoder; | |
| 123 | -use crate::decode::{Decoder, Picture}; | |
| 124 | - | |
| 125 | -/// The per-type ceiling for a type a CALLER can be made to hold by value, in | |
| 126 | -/// bytes. See the module docs for the derivation; it is two-sided, and both | |
| 127 | -/// sides are measured. | |
| 128 | -pub(crate) const STACK_BUDGET: usize = 8192; | |
| 129 | - | |
| 130 | -/// The deepest PUBLIC by-value chain in this crate, counted from the source: | |
| 131 | -/// `stream::decode_stream` (stream.rs:74) -> `stream::decode_stream_with` | |
| 132 | -/// (stream.rs:88) -> `Decoder::decode` (decode.rs:238) is three public | |
| 133 | -/// levels, after which `decode_one` / `decode_keyframe` / `decode_inter` | |
| 134 | -/// are private. The budget is checked against three. | |
| 135 | -/// | |
| 136 | -/// The by-value return slots IN that chain are all small | |
| 137 | -/// (`Result<Vec<Picture>>`, `Result<()>`, `Result<Option<Picture>>`); the | |
| 138 | -/// 2,800-byte `Decoder` is a by-value LOCAL in `decode_stream_with` that | |
| 139 | -/// stays live across the inner `decode` calls. Multiplying the chain by the | |
| 140 | -/// crate's worst public return is the conservative direction, and is what | |
| 141 | -/// [`every_by_value_type_fits_the_stack_budget`] asserts. | |
| 142 | -#[cfg(test)] | |
| 143 | -const DEEPEST_PUBLIC_CHAIN: usize = 3; | |
| 144 | - | |
| 145 | -/// Every type in this crate a public `fn` can return BY VALUE, with the | |
| 146 | -/// `size_of` measured at the commit that wrote this table. `None` means "not | |
| 147 | -/// yet measured", which [`the_measured_inventory_is_accurate`] rejects. | |
| 148 | -/// | |
| 149 | -/// The third column names the return path, so a reader can see why a type is | |
| 150 | -/// here rather than a coincidence of the type system. | |
| 151 | -pub(crate) const BY_VALUE_TYPES: &[(&str, Option<usize>, bool, &str)] = &[ | |
| 152 | - // -- knobs.rs --------------------------------------------------------- | |
| 153 | - ( | |
| 154 | - "Override", | |
| 155 | - Some(16), | |
| 156 | - true, | |
| 157 | - "knobs::set_skip_lf / set_force_tail -> test-only guard that puts an \ | |
| 158 | - EC_VP9 debug switch back on drop. A boxed restore closure, so one \ | |
| 159 | - type covers every knob.", | |
| 160 | - ), | |
| 161 | - // -- decode.rs -------------------------------------------------------- | |
| 162 | - ( | |
| 163 | - "Decoder", | |
| 164 | - Some(800), | |
| 165 | - true, | |
| 166 | - "Decoder::new -> Self (and `Default::default`), the crate's whole \ | |
| 167 | - public surface. Was 10944 with five inline FrameContext slots \ | |
| 168 | - (10,195 of it), 1.34x over budget; frame_ctxs and ctx are both \ | |
| 169 | - Boxes now. Boxing frame_ctxs ALONE left 2800 -- under budget, but \ | |
| 170 | - with ctx still inline that was 72.8% of it", | |
| 171 | - ), | |
| 172 | - ( | |
| 173 | - "Picture", | |
| 174 | - Some(96), | |
| 175 | - true, | |
| 176 | - "Decoder::decode -> Result<Option<Picture>>. Its fields ARE pub \ | |
| 177 | - (y/u/v are Vec<Sample>), but it is thin -- three Vecs are three \ | |
| 178 | - heap pointers, so the 96 bytes are a stack cost of three words, \ | |
| 179 | - not of frame data", | |
| 180 | - ), | |
| 181 | - // -- bool.rs ---------------------------------------------------------- | |
| 182 | - ( | |
| 183 | - "BoolDecoder", | |
| 184 | - Some(40), | |
| 185 | - true, | |
| 186 | - "bool::BoolDecoder::new(data) -> Result<Self>; the sole public \ | |
| 187 | - by-value return in the crate besides Picture, and the only type a \ | |
| 188 | - caller can hold by value outside the decode surface", | |
| 189 | - ), | |
| 190 | - // -- crate-private: never a public return, and the one that was | |
| 191 | - // -- inline is behind a Box now. The budget does not apply; the pin | |
| 192 | - // -- that does is `the_frame_contexts_stay_behind_a_box`. | |
| 193 | - ( | |
| 194 | - "FrameContext", | |
| 195 | - Some(2039), | |
| 196 | - false, | |
| 197 | - "header::FrameContext is pub(crate) and the payload of BOTH \ | |
| 198 | - `frame_ctxs: Box<[FrameContext; 4]>` and `ctx: Box<FrameContext>`; \ | |
| 199 | - five inline were 10195 of the pre-fix 10944. No FrameContext is \ | |
| 200 | - stored inline in Decoder any more", | |
| 201 | - ), | |
| 202 | -]; | |
| 203 | - | |
| 204 | -/// The live `size_of` for every inventoried type, keyed BY NAME. | |
| 205 | -/// | |
| 206 | -/// Keyed rather than positional on purpose: a row inserted into | |
| 207 | -/// [`BY_VALUE_TYPES`] without a matching insert here would zip cleanly and | |
| 208 | -/// assert the wrong type's size against the wrong recorded one. A name key | |
| 209 | -/// makes that mistake loud instead. | |
| 210 | -#[cfg(test)] | |
| 211 | -fn measured_by_name() -> Vec<(&'static str, usize)> { | |
| 212 | - vec![ | |
| 213 | - ("Decoder", std::mem::size_of::<Decoder>()), | |
| 214 | - ("Picture", std::mem::size_of::<Picture>()), | |
| 215 | - ("Override", std::mem::size_of::<crate::knobs::Override>()), | |
| 216 | - ("BoolDecoder", std::mem::size_of::<BoolDecoder<'static>>()), | |
| 217 | - ( | |
| 218 | - "FrameContext", | |
| 219 | - std::mem::size_of::<crate::header::FrameContext>(), | |
| 220 | - ), | |
| 221 | - ] | |
| 222 | -} | |
| 223 | - | |
| 224 | -/// The stack [`the_deepest_by_value_constructors_fit_on_a_tight_stack`] | |
| 225 | -/// constructs on. | |
| 226 | -/// | |
| 227 | -/// 256 KiB: an eighth of what an unconfigured caller hands this crate, and | |
| 228 | -/// far above what a 2,800-byte by-value `Decoder` needs in a debug build | |
| 229 | -/// (the threshold is swept with `EC_VP9_TIGHT_STACK_BYTES`). | |
| 230 | -const TIGHT_STACK: usize = 256 * 1024; | |
| 231 | - | |
| 232 | -#[cfg(test)] | |
| 233 | -mod tests { | |
| 234 | - use super::{ | |
| 235 | - BY_VALUE_TYPES, DEEPEST_PUBLIC_CHAIN, STACK_BUDGET, TIGHT_STACK, measured_by_name, | |
| 236 | - }; | |
| 237 | - use crate::bool::BoolDecoder; | |
| 238 | - use crate::decode::Decoder; | |
| 239 | - | |
| 240 | - /// Return types that are not a by-value copy of anything the caller has | |
| 241 | - /// to own: a pointer, a slice, a `Vec` (three words, and the heap is | |
| 242 | - /// not the stack), or a primitive. `Self` is a by-value copy of the | |
| 243 | - /// impl's type, which the inventory rows already cover, so it is exempt | |
| 244 | - /// from the scan and not from the table. | |
| 245 | - const THIN: &[&str] = &[ | |
| 246 | - "Box", "Rc", "Arc", "Cow", "Vec", "VecDeque", "String", "OsString", "PathBuf", "HashMap", | |
| 247 | - "BTreeMap", "BTreeSet", "HashSet", "str", "u8", "u16", "u32", "u64", "usize", "i8", "i16", | |
| 248 | - "i32", "i64", "isize", "f32", "f64", "bool", "char", "Self", | |
| 249 | - ]; | |
| 250 | - | |
| 251 | - /// The type name a `pub fn` line returns BY VALUE, or `None` when the | |
| 252 | - /// line returns a pointer, a `Vec`, a primitive, or nothing. | |
| 253 | - /// | |
| 254 | - /// One function, shared by the sweep and its control, so the control | |
| 255 | - /// cannot pass while the sweep's copy of the logic rotted. | |
| 256 | - fn by_value_return_name(line: &str) -> Option<String> { | |
| 257 | - let trimmed = line.trim_start(); | |
| 258 | - if !trimmed.starts_with("pub fn ") { | |
| 259 | - return None; | |
| 260 | - } | |
| 261 | - let arrow = line.find("->")?; | |
| 262 | - let rest = &line[arrow + 2..]; | |
| 263 | - let end = rest.find('{').unwrap_or(rest.len()); | |
| 264 | - let ret = rest[..end].trim(); | |
| 265 | - if ret.is_empty() { | |
| 266 | - return None; | |
| 267 | - } | |
| 268 | - // Unwrap the `Result<..>` / `Option<..>` layers. ec-av1 unwraps one; | |
| 269 | - // this crate needs the loop, because its ONE by-value public return | |
| 270 | - // is spelled `Result<Option<Picture>>` (decode.rs:238) and a | |
| 271 | - // single unwrap reads that as the name "Option" -- an uninventoried | |
| 272 | - // non-type that would have made the sweep permanently red for a | |
| 273 | - // reason that has nothing to do with the class. | |
| 274 | - let mut inner = ret; | |
| 275 | - loop { | |
| 276 | - let stripped = inner | |
| 277 | - .strip_prefix("Result<") | |
| 278 | - .or_else(|| inner.strip_prefix("Option<")); | |
| 279 | - match stripped { | |
| 280 | - Some(t) => { | |
| 281 | - let head = t.split('>').next().unwrap_or(t); | |
| 282 | - if head.is_empty() { | |
| 283 | - return None; | |
| 284 | - } | |
| 285 | - inner = head; | |
| 286 | - } | |
| 287 | - None => break, | |
| 288 | - } | |
| 289 | - } | |
| 290 | - // Drop the error type and any lifetime or generic argument: | |
| 291 | - // `Result<Decoder, Error>`, `BoolDecoder<'a>` and `Picture` are all | |
| 292 | - // the bare name for this purpose. Splitting on the comma is | |
| 293 | - // load-bearing: the first version of this matcher cut only at `>` | |
| 294 | - // and so read `Result<Decoder, Error>` as the name | |
| 295 | - // "Decoder, Error". | |
| 296 | - let name = inner.split(['<', ',']).next().unwrap_or(inner).trim(); | |
| 297 | - if name.is_empty() || THIN.contains(&name) { | |
| 298 | - return None; | |
| 299 | - } | |
| 300 | - // A generic parameter, not a concrete type. | |
| 301 | - if !name.chars().next().is_some_and(char::is_uppercase) { | |
| 302 | - return None; | |
| 303 | - } | |
| 304 | - Some(name.to_string()) | |
| 305 | - } | |
| 306 | - | |
| 307 | - /// The source files the by-value scan reads. Every module `lib.rs` | |
| 308 | - /// declares, plus this one; a new module added to `lib.rs` needs | |
| 309 | - /// adding here, and [`every_by_value_module_is_scanned`] is what keeps | |
| 310 | - /// that honest. | |
| 311 | - /// | |
| 312 | - /// The label is the path relative to `src/`, so a directory module is | |
| 313 | - /// `tables/mod.rs` rather than `tables.rs`. | |
| 314 | - const FILES: &[(&str, &str)] = &[ | |
| 315 | - ("adapt.rs", include_str!("adapt.rs")), | |
| 316 | - ("bool.rs", include_str!("bool.rs")), | |
| 317 | - ("decode.rs", include_str!("decode.rs")), | |
| 318 | - ("header.rs", include_str!("header.rs")), | |
| 319 | - ("inter.rs", include_str!("inter.rs")), | |
| 320 | - ("intra.rs", include_str!("intra.rs")), | |
| 321 | - ("loopfilter.rs", include_str!("loopfilter.rs")), | |
| 322 | - ("knobs.rs", include_str!("knobs.rs")), | |
| 323 | - ("mc.rs", include_str!("mc.rs")), | |
| 324 | - ("modes.rs", include_str!("modes.rs")), | |
| 325 | - ("prof.rs", include_str!("prof.rs")), | |
| 326 | - ("stream.rs", include_str!("stream.rs")), | |
| 327 | - ("tables/mod.rs", include_str!("tables/mod.rs")), | |
| 328 | - ("tokens.rs", include_str!("tokens.rs")), | |
| 329 | - ("transform.rs", include_str!("transform.rs")), | |
| 330 | - ("stack_budget.rs", include_str!("stack_budget.rs")), | |
| 331 | - ]; | |
| 332 | - | |
| 333 | - /// Every module `lib.rs` declares, so the scan's file list cannot | |
| 334 | - /// silently fall behind a new module. A new `mod foo;` with a | |
| 335 | - /// by-value `pub fn` that the scan never reads is exactly the hole | |
| 336 | - /// this class would come back through, so the list is derived, not | |
| 337 | - /// curated. | |
| 338 | - #[test] | |
| 339 | - fn every_by_value_module_is_scanned() { | |
| 340 | - let lib = include_str!("lib.rs"); | |
| 341 | - let mut declared: Vec<&str> = Vec::new(); | |
| 342 | - for line in lib.lines() { | |
| 343 | - let t = line.trim(); | |
| 344 | - let rest = t | |
| 345 | - .strip_prefix("pub mod ") | |
| 346 | - // This crate's `inter` and `mc` are `pub(crate) mod`, a | |
| 347 | - // spelling ec-av1 has no instance of. They are declared | |
| 348 | - // modules and are scanned, so they must be derived here | |
| 349 | - // too -- otherwise the check below is blind to exactly | |
| 350 | - // the two files a future by-value return would most | |
| 351 | - // likely land in. | |
| 352 | - .or_else(|| t.strip_prefix("pub(crate) mod ")) | |
| 353 | - .or_else(|| t.strip_prefix("mod ")) | |
| 354 | - .unwrap_or(""); | |
| 355 | - if rest.is_empty() { | |
| 356 | - continue; | |
| 357 | - } | |
| 358 | - let name = rest.split([';', ' ']).next().unwrap_or(""); | |
| 359 | - if !name.is_empty() && name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') { | |
| 360 | - declared.push(name); | |
| 361 | - } | |
| 362 | - } | |
| 363 | - // 12 modules (incl. the `pub(crate)` ones -- `inter`, `mc`) plus | |
| 364 | - // this one. The floor is a REACH floor: below it the parse is | |
| 365 | - // broken, not the crate small. | |
| 366 | - assert!( | |
| 367 | - declared.len() >= 13, | |
| 368 | - "only {} module declarations parsed out of lib.rs, so the derived \ | |
| 369 | - file list is broken rather than small", | |
| 370 | - declared.len() | |
| 371 | - ); | |
| 372 | - let scanned: Vec<&str> = FILES.iter().map(|(n, _)| *n).collect(); | |
| 373 | - let mut missing: Vec<String> = declared | |
| 374 | - .iter() | |
| 375 | - .filter(|d| { | |
| 376 | - let flat = format!("{d}.rs"); | |
| 377 | - let dir = format!("{d}/mod.rs"); | |
| 378 | - !scanned.iter().any(|s| *s == flat || *s == dir) | |
| 379 | - }) | |
| 380 | - .map(|d| (*d).to_string()) | |
| 381 | - .collect(); | |
| 382 | - missing.sort(); | |
| 383 | - assert!( | |
| 384 | - missing.is_empty(), | |
| 385 | - "lib.rs declares modules the by-value scan never reads: {:?}. Add \ | |
| 386 | - them to FILES, or the sweep cannot see a new by-value return that \ | |
| 387 | - lands in one of them.", | |
| 388 | - missing | |
| 389 | - ); | |
| 390 | - } | |
| 391 | - | |
| 392 | - /// The inventory, printed as a sorted table, and checked against the | |
| 393 | - /// types' real sizes. | |
| 394 | - /// | |
| 395 | - /// The print is the instrument: one command | |
| 396 | - /// (`cargo test -p ec-vp9 --lib -- stack_budget -- --nocapture`) | |
| 397 | - /// reproduces the whole table, biggest first, so "what is the largest | |
| 398 | - /// by-value type in this crate" has an answer that is a measurement | |
| 399 | - /// rather than a grep. | |
| 400 | - /// | |
| 401 | - /// The check reds on ANY change with both numbers. That is deliberate: a | |
| 402 | - /// by-value type that grew raises the question of whether it should | |
| 403 | - /// have been boxed instead, and auto-accepting the new number would | |
| 404 | - /// answer that question by default. | |
| 405 | - #[test] | |
| 406 | - fn the_measured_inventory_is_accurate() { | |
| 407 | - let live = measured_by_name(); | |
| 408 | - assert_eq!( | |
| 409 | - BY_VALUE_TYPES.len(), | |
| 410 | - live.len(), | |
| 411 | - "the inventory names {} types but {} are measured; every row needs \ | |
| 412 | - a measured size or the sweep is a list of hopes", | |
| 413 | - BY_VALUE_TYPES.len(), | |
| 414 | - live.len() | |
| 415 | - ); | |
| 416 | - let mut rows: Vec<(&str, usize)> = live.clone(); | |
| 417 | - rows.sort_by_key(|&(_, size)| std::cmp::Reverse(size)); | |
| 418 | - eprintln!( | |
| 419 | - "\nBY-VALUE INVENTORY ({} types, budget {STACK_BUDGET} B = {} KiB)", | |
| 420 | - rows.len(), | |
| 421 | - STACK_BUDGET / 1024 | |
| 422 | - ); | |
| 423 | - eprintln!("{:>8} {:>7} TYPE", "BYTES", "%BUDGET"); | |
| 424 | - for (name, size) in &rows { | |
| 425 | - eprintln!( | |
| 426 | - "{size:>8} {:>6.1}% {name}", | |
| 427 | - *size as f64 * 100.0 / STACK_BUDGET as f64 | |
| 428 | - ); | |
| 429 | - } | |
| 430 | - for (name, recorded, _public, _path) in BY_VALUE_TYPES { | |
| 431 | - let recorded = recorded.expect("every inventory row carries a measured size"); | |
| 432 | - let actual = live | |
| 433 | - .iter() | |
| 434 | - .find(|(n, _)| n == name) | |
| 435 | - .map(|(_, size)| *size) | |
| 436 | - .unwrap_or_else(|| panic!("{name} is inventoried but never measured")); | |
| 437 | - assert_eq!( | |
| 438 | - recorded, actual, | |
| 439 | - "{name} is {actual} bytes, the inventory records {recorded}; \ | |
| 440 | - update the table deliberately -- a by-value type that changed \ | |
| 441 | - is a stack cost every caller of its constructor now pays" | |
| 442 | - ); | |
| 443 | - } | |
| 444 | - } | |
| 445 | - | |
| 446 | - /// The bound, asserted BY NAME. A regression in any inventoried type | |
| 447 | - /// reds here naming the type, not "some type is too big". | |
| 448 | - #[test] | |
| 449 | - fn every_by_value_type_fits_the_stack_budget() { | |
| 450 | - let live = measured_by_name(); | |
| 451 | - let mut checked = 0usize; | |
| 452 | - for (name, _, public, path) in BY_VALUE_TYPES { | |
| 453 | - if !public { | |
| 454 | - continue; | |
| 455 | - } | |
| 456 | - checked += 1; | |
| 457 | - let size = live | |
| 458 | - .iter() | |
| 459 | - .find(|(n, _)| n == name) | |
| 460 | - .map(|(_, size)| *size) | |
| 461 | - .unwrap_or_else(|| panic!("{name} is inventoried but never measured")); | |
| 462 | - assert!( | |
| 463 | - size <= STACK_BUDGET, | |
| 464 | - "{name} is {size} bytes, over the {STACK_BUDGET}-byte by-value \ | |
| 465 | - stack budget ({:.2}x). It is returned by value from {path}, so \ | |
| 466 | - every caller pays it on its own stack. Box the large field \ | |
| 467 | - (frame_ctxs: Box<[FrameContext; 4]> did exactly this for \ | |
| 468 | - Decoder, 10944 -> 2800) or hand back a reference.", | |
| 469 | - size as f64 / STACK_BUDGET as f64 | |
| 470 | - ); | |
| 471 | - } | |
| 472 | - // ec-av1's floor is 10. THIS CRATE HAS 4, and that is a measurement, | |
| 473 | - // not a gap to pad: every module but `bool`, `decode`, `knobs` and | |
| 474 | - // `stream` exposes zero `pub fn` (its API is `pub(crate)`, reached | |
| 475 | - // through `Decoder`). Inventing rows to reach ec-av1's number would | |
| 476 | - // make the gate theatre -- it would count types no caller can reach. | |
| 477 | - // `knobs::Override` is the fourth: the test-only guard the knob | |
| 478 | - // setters return. | |
| 479 | - assert!( | |
| 480 | - checked == 4, | |
| 481 | - "{checked} public rows were bound-checked, and this crate has \ | |
| 482 | - exactly 4 types a caller can hold by value (Decoder, Picture, \ | |
| 483 | - BoolDecoder, knobs::Override). If a fifth appeared, measure it, \ | |
| 484 | - add it to BY_VALUE_TYPES, and raise this floor with it; if a row was \ | |
| 485 | - removed, the count is wrong here and in the inventory." | |
| 486 | - ); | |
| 487 | - // The other half of the derivation, asserted so it cannot rot: the | |
| 488 | - // worst a caller can owe is DEEPEST_CHAIN x the worst public return. | |
| 489 | - let worst = live | |
| 490 | - .iter() | |
| 491 | - .filter(|(n, _)| { | |
| 492 | - BY_VALUE_TYPES | |
| 493 | - .iter() | |
| 494 | - .any(|(row, _, public, _)| row == n && *public) | |
| 495 | - }) | |
| 496 | - .map(|(_, size)| *size) | |
| 497 | - .max() | |
| 498 | - .expect("at least one public row"); | |
| 499 | - assert!( | |
| 500 | - DEEPEST_PUBLIC_CHAIN * worst * 8 <= 2 * 1024 * 1024, | |
| 501 | - "the deepest public chain ({DEEPEST_PUBLIC_CHAIN}) times the worst \ | |
| 502 | - public by-value return ({worst} B) is {} B, over an eighth of the \ | |
| 503 | - 2 MiB stack an unconfigured caller hands this crate; \ | |
| 504 | - re-derive STACK_BUDGET", | |
| 505 | - DEEPEST_PUBLIC_CHAIN * worst | |
| 506 | - ); | |
| 507 | - } | |
| 508 | - | |
| 509 | - /// The four stored frame contexts stay BEHIND A BOX. | |
| 510 | - /// | |
| 511 | - /// The budget does not apply to `header::FrameContext` (2,039 B) because | |
| 512 | - /// no `pub fn` returns it, so bounding it would calibrate the number to | |
| 513 | - /// something no caller can reach. What keeps four of them off a | |
| 514 | - /// caller's stack is that the array is a `Box`, and THIS is the pin. | |
| 515 | - /// | |
| 516 | - /// It earned its place twice. `Decoder` was 10,944 B, of which 8,156 was | |
| 517 | - /// `frame_ctxs: [FrameContext; 4]` sitting inline -- 1.34x over budget. | |
| 518 | - /// Boxing the array alone left 2,800, of which `ctx` was 2,039 (72.8%): | |
| 519 | - /// under the budget, but with a single field carrying nearly all of it. | |
| 520 | - #[test] | |
| 521 | - fn the_frame_contexts_stay_behind_a_box() { | |
| 522 | - const PINS: &[(&str, &str)] = &[ | |
| 523 | - // The field declarations (decode.rs:134, decode.rs:139). | |
| 524 | - ("frame_ctxs: Box<[FrameContext; 4]>", "the frame_ctxs field"), | |
| 525 | - ("ctx: Box<FrameContext>", "the ctx field"), | |
| 526 | - // Their construction in `Decoder::new` (decode.rs:216, 221). | |
| 527 | - ( | |
| 528 | - "Box::new([d.clone(), d.clone(), d.clone(), d])", | |
| 529 | - "Decoder::new", | |
| 530 | - ), | |
| 531 | - ("ctx: Box::new(FrameContext::new(true))", "Decoder::new"), | |
| 532 | - ]; | |
| 533 | - const SRC: &str = include_str!("decode.rs"); | |
| 534 | - for (spelling, where_) in PINS { | |
| 535 | - assert!( | |
| 536 | - SRC.contains(spelling), | |
| 537 | - "decode.rs::{where_} is no longer declared `{spelling}`. An \ | |
| 538 | - inline `FrameContext` there puts 2039 bytes back into every \ | |
| 539 | - caller's stack -- five of them were 10195 bytes, which is how \ | |
| 540 | - `Decoder` was 10944 bytes and 1.34x over the by-value budget \ | |
| 541 | - before the boxes.", | |
| 542 | - ); | |
| 543 | - } | |
| 544 | - // And the negative control: the unboxed spelling must NOT still be | |
| 545 | - // present, or the scan above would be matching a comment. | |
| 546 | - assert!( | |
| 547 | - !SRC.contains("frame_ctxs: [FrameContext; 4],") && !SRC.contains("ctx: FrameContext,"), | |
| 548 | - "decode.rs still spells a FrameContext field inline, so the box \ | |
| 549 | - pin above is matching a spelling that is not the live declaration" | |
| 550 | - ); | |
| 551 | - } | |
| 552 | - | |
| 553 | - /// CAPABILITY: really construct the heavy type on a tight stack, so a | |
| 554 | - /// regression ABORTS THE PROCESS instead of costing invisible margin. | |
| 555 | - /// | |
| 556 | - /// `Decoder::new` is the crate's one large by-value return path, and it | |
| 557 | - /// is also the one whose boxing moved the threshold. | |
| 558 | - /// | |
| 559 | - /// **What this arm does and does not catch, measured.** Swept in an | |
| 560 | - /// unoptimized build, one process per point: | |
| 561 | - /// | |
| 562 | - /// | stack | pre-fix (unboxed, 10,944 B) | boxed (2,800 B) | | |
| 563 | - /// |---|---|---| | |
| 564 | - /// | 16384 | overflow | overflow | | |
| 565 | - /// | 24576 | overflow | overflow | | |
| 566 | - /// | 32768 | overflow | **ok** | | |
| 567 | - /// | 40960 | **ok** | ok | | |
| 568 | - /// | 262144 (the gate) | **ok** | ok | | |
| 569 | - /// | |
| 570 | - /// So the boxing moved the threshold from 40,960 to 32,768 -- real, and | |
| 571 | - /// HONESTLY SMALL: a 10,944-byte struct does not need a small stack to | |
| 572 | - /// overflow. **The unboxing mutation does NOT red this arm at 256 KiB.** | |
| 573 | - /// It reds [`every_by_value_type_fits_the_stack_budget`] (named, with | |
| 574 | - /// the 1.34x factor) and [`the_frame_contexts_stay_behind_a_box`] | |
| 575 | - /// instead. This arm is the capability floor -- it pins the real live | |
| 576 | - /// stack of the crate's by-value return path, which the arithmetic in | |
| 577 | - /// the other two tests does not model -- and it is deliberately set | |
| 578 | - /// well clear of the measured 32,768 B so an unoptimised-build | |
| 579 | - /// regression in stack need shows up here as a margin loss rather than | |
| 580 | - /// as a mysterious abort. Reproduce either column with | |
| 581 | - /// `EC_VP9_TIGHT_STACK_BYTES`. | |
| 582 | - /// | |
| 583 | - /// The env read is a raw `std::env::var`, not the crate's `cached_gate!` | |
| 584 | - /// macro: `cached_gate!` answers PRESENCE and caches a bool, and this | |
| 585 | - /// override needs a VALUE, read once per test run and never on a decode | |
| 586 | - /// path. Using the hot-path convention for a cold, value-shaped read | |
| 587 | - /// would be the wrong tool. | |
| 588 | - #[test] | |
| 589 | - fn the_deepest_by_value_constructors_fit_on_a_tight_stack() { | |
| 590 | - let stack: usize = std::env::var("EC_VP9_TIGHT_STACK_BYTES") | |
| 591 | - .ok() | |
| 592 | - .and_then(|v| v.parse().ok()) | |
| 593 | - .unwrap_or(TIGHT_STACK); | |
| 594 | - let handle = std::thread::Builder::new() | |
| 595 | - .stack_size(stack) | |
| 596 | - .spawn(|| { | |
| 597 | - // The by-value return path: a whole `Decoder` built and | |
| 598 | - // returned from `new` on a 256 KiB stack. | |
| 599 | - let decoder = Decoder::new(); | |
| 600 | - // Real post-construction state, not just "did not crash": a | |
| 601 | - // fresh decoder has parsed no inter frame and produced no | |
| 602 | - // blocks, and the four boxed frame contexts are addressable | |
| 603 | - // and distinct from the live `ctx`. | |
| 604 | - let blocks = decoder.last_frame_blocks(); | |
| 605 | - let bools = BoolDecoder::new(&[]).expect("BoolDecoder::new on an empty partition"); | |
| 606 | - let overreads = bools.overreads(); | |
| 607 | - (blocks, overreads, std::mem::size_of::<Decoder>()) | |
| 608 | - }) | |
| 609 | - .expect("spawn tight-stack thread"); | |
| 610 | - let (blocks, overreads, size) = handle.join().unwrap_or_else(|_| { | |
| 611 | - panic!( | |
| 612 | - "Decoder::new overflowed a {stack}-byte stack; that is what the \ | |
| 613 | - pre-fix 10944-byte by-value layout costs a caller" | |
| 614 | - ) | |
| 615 | - }); | |
| 616 | - assert_eq!( | |
| 617 | - blocks, 0, | |
| 618 | - "a freshly constructed Decoder reports {blocks} last-frame blocks" | |
| 619 | - ); | |
| 620 | - assert_eq!( | |
| 621 | - overreads, 0, | |
| 622 | - "an empty BoolDecoder partition reports {overreads} overreads" | |
| 623 | - ); | |
| 624 | - eprintln!("TIGHTSTACK {stack} bytes: Decoder={size} B, constructed and returned"); | |
| 625 | - } | |
| 626 | - | |
| 627 | - /// The sweep's teeth against a NEW by-value return: re-derive the set | |
| 628 | - /// from the crate source and require every name to be inventoried. | |
| 629 | - /// | |
| 630 | - /// Without this the inventory is a list of what someone remembered to | |
| 631 | - /// measure, and a lane that adds `pub fn make() -> HugeThing` where | |
| 632 | - /// `HugeThing` is 200 KB of inline tables passes every other test here. | |
| 633 | - #[test] | |
| 634 | - fn every_by_value_public_return_is_in_the_inventory() { | |
| 635 | - let mut found: Vec<(String, String)> = Vec::new(); | |
| 636 | - let mut pub_fn_lines = 0usize; | |
| 637 | - for (file, src) in FILES { | |
| 638 | - for (n, line) in src.lines().enumerate() { | |
| 639 | - if line.trim_start().starts_with("pub fn ") { | |
| 640 | - pub_fn_lines += 1; | |
| 641 | - } | |
| 642 | - if let Some(name) = by_value_return_name(line) { | |
| 643 | - found.push((name, format!("{file}:{}", n + 1))); | |
| 644 | - } | |
| 645 | - } | |
| 646 | - } | |
| 647 | - found.sort(); | |
| 648 | - found.dedup(); | |
| 649 | - // A REACH floor, not a size floor: ec-av1 asserts > 5 names because | |
| 650 | - // it has 20 KB of encoders. This crate has 13 `pub fn` lines in | |
| 651 | - // total, 11 of which return a primitive / `Self` / `()`, so the | |
| 652 | - // one by-value public return it really has is `Picture`. Asserting | |
| 653 | - // a bigger number would be asserting a fact about ec-av1. | |
| 654 | - assert!( | |
| 655 | - pub_fn_lines >= 10, | |
| 656 | - "the scan saw only {pub_fn_lines} `pub fn` lines across {} files, \ | |
| 657 | - too few to be a real sweep -- the matcher, not the crate, is \ | |
| 658 | - broken", | |
| 659 | - FILES.len() | |
| 660 | - ); | |
| 661 | - assert!( | |
| 662 | - !found.is_empty(), | |
| 663 | - "the by-value return scan found NO name across {} files and {} \ | |
| 664 | - `pub fn` lines; `Decoder::decode -> Result<Option<Picture>>` \ | |
| 665 | - (decode.rs:238) must be in there, so the matcher is broken", | |
| 666 | - FILES.len(), | |
| 667 | - pub_fn_lines | |
| 668 | - ); | |
| 669 | - | |
| 670 | - let mut missing = Vec::new(); | |
| 671 | - for (name, site) in &found { | |
| 672 | - if !BY_VALUE_TYPES.iter().any(|(n, _, _, _)| n == name) { | |
| 673 | - missing.push(format!("{name} ({site})")); | |
| 674 | - } | |
| 675 | - } | |
| 676 | - assert!( | |
| 677 | - missing.is_empty(), | |
| 678 | - "these types are returned BY VALUE from a public fn and are not in \ | |
| 679 | - the inventory: {}. Either they are thin enough not to be a stack \ | |
| 680 | - cost -- say so by adding a row with its measured size -- or they \ | |
| 681 | - are the next instance of the class this module exists for.", | |
| 682 | - missing.join(", ") | |
| 683 | - ); | |
| 684 | - eprintln!( | |
| 685 | - "BYVALUE-SCAN {} `pub fn` lines, {} by-value public return name(s): {:?}", | |
| 686 | - pub_fn_lines, | |
| 687 | - found.len(), | |
| 688 | - found | |
| 689 | - ); | |
| 690 | - } | |
| 691 | - | |
| 692 | - /// The control for the scan above, on synthetic text rather than by | |
| 693 | - /// trusting the live tree to happen to contain a case. | |
| 694 | - /// | |
| 695 | - /// If the matcher silently stopped recognising a shape, the sweep would | |
| 696 | - /// pass everything and this would still be asserting nothing. So: every | |
| 697 | - /// by-value spelling this crate uses must yield its type name, and every | |
| 698 | - /// pointer/Vec/primitive/`Self` spelling must yield nothing. | |
| 699 | - #[test] | |
| 700 | - fn the_inventory_scan_is_not_vacuous() { | |
| 701 | - for synthetic in [ | |
| 702 | - "pub fn zz_a() -> ZzNotInventoried { todo!() }", | |
| 703 | - "pub fn zz_b() -> Result<ZzNotInventoried, Error> { todo!() }", | |
| 704 | - "pub fn zz_c() -> Result<ZzNotInventoried> { todo!() }", | |
| 705 | - "pub fn zz_d() -> Option<ZzNotInventoried> { todo!() }", | |
| 706 | - "pub fn zz_e() -> ZzNotInventoried<'a> { todo!() }", | |
| 707 | - // The DOUBLE-wrapped shape this crate actually uses, at | |
| 708 | - // decode.rs:238. A single-layer unwrap reads it as "Option", | |
| 709 | - // which is not a type and would red the sweep forever. | |
| 710 | - "pub fn zz_f() -> Result<Option<ZzNotInventoried>> { todo!() }", | |
| 711 | - ] { | |
| 712 | - let name = by_value_return_name(synthetic) | |
| 713 | - .unwrap_or_else(|| panic!("the matcher does not recognise `{synthetic}`")); | |
| 714 | - assert_eq!( | |
| 715 | - name, "ZzNotInventoried", | |
| 716 | - "the matcher mangled `{synthetic}` into `{name}`, so the sweep \ | |
| 717 | - cannot see a new by-value return and its green is vacuous" | |
| 718 | - ); | |
| 719 | - assert!( | |
| 720 | - !BY_VALUE_TYPES.iter().any(|(n, _, _, _)| *n == name), | |
| 721 | - "the synthetic control name is in the inventory, so the control \ | |
| 722 | - proves nothing" | |
| 723 | - ); | |
| 724 | - } | |
| 725 | - for thin in [ | |
| 726 | - "pub fn zz_t() -> Box<Decoder> { todo!() }", | |
| 727 | - "pub fn zz_u() -> Result<Vec<u8>, Error> { todo!() }", | |
| 728 | - "pub fn zz_v() -> Option<&Path> { todo!() }", | |
| 729 | - "pub fn zz_w() -> usize { todo!() }", | |
| 730 | - "pub fn zz_x() -> Self { todo!() }", | |
| 731 | - "pub fn zz_y() -> Result<Arc<Decoder>, Error> { todo!() }", | |
| 732 | - "pub fn zz_z() { todo!() }", | |
| 733 | - "fn zz_private() -> ZzNotInventoried { todo!() }", | |
| 734 | - // The two live spellings this crate exempts on purpose: | |
| 735 | - // `Vec` is three words and its heap is not the caller's stack. | |
| 736 | - "pub fn zz_g() -> Result<Vec<Picture>> { todo!() }", | |
| 737 | - "pub fn zz_h() -> Result<Self> { todo!() }", | |
| 738 | - ] { | |
| 739 | - assert_eq!( | |
| 740 | - by_value_return_name(thin), | |
| 741 | - None, | |
| 742 | - "`{thin}` is a pointer, a Vec, a primitive, a `Self` the rows \ | |
| 743 | - above already cover, or not a `pub fn` -- the matcher must not \ | |
| 744 | - read it as an uninventoried by-value return" | |
| 745 | - ); | |
| 746 | - } | |
| 747 | - } | |
| 748 | -} |
crates/ec-vp9/src/tokens.rsmodified+0 -12
| @@ -97,12 +97,6 @@ pub(crate) fn decode_coefs( | ||
| 97 | 97 | let mut prob: &[u8; 3] = &probs4d[plane_type][usize::from(is_inter)][band][ctx]; |
| 98 | 98 | |
| 99 | 99 | while c < max_eob { |
| 100 | - if crate::trace_enabled() { | |
| 101 | - eprintln!( | |
| 102 | - "TOK c={c} band={band} ctx={ctx} p0={},{},{}", | |
| 103 | - prob[0], prob[1], prob[2] | |
| 104 | - ); | |
| 105 | - } | |
| 106 | 100 | // libvpx `++eob_branch_count[band][ctx]` before the EOB decision. |
| 107 | 101 | let cell = usize::from(is_inter); |
| 108 | 102 | counts.eob_branch[tx_size][plane_type][cell][band][ctx] += 1; |
| @@ -179,12 +173,6 @@ pub(crate) fn decode_coefs( | ||
| 179 | 173 | dqv = dequant[1] as i32; |
| 180 | 174 | } |
| 181 | 175 | coef.eob = c; |
| 182 | - if crate::trace_enabled() { | |
| 183 | - eprintln!( | |
| 184 | - "EOB p={} x={} y={} tx={} eob={} c0={}", | |
| 185 | - plane, pos.0, pos.1, tx_size, c, coef.coeffs[0] | |
| 186 | - ); | |
| 187 | - } | |
| 188 | 176 | coef |
| 189 | 177 | } |
| 190 | 178 |
crates/ec-vp9/src/transform.rsmodified+0 -15
| @@ -762,18 +762,3 @@ pub(crate) fn inverse_transform_add( | ||
| 762 | 762 | } |
| 763 | 763 | } |
| 764 | 764 | } |
| 765 | - | |
| 766 | -#[cfg(test)] | |
| 767 | -mod scratch_probe { | |
| 768 | - use super::*; | |
| 769 | - #[test] | |
| 770 | - fn probe_dc38() { | |
| 771 | - for (name, tt) in [("dct_dct", DCT_DCT), ("dct_adst", DCT_ADST)] { | |
| 772 | - let mut c = [0i32; 64]; | |
| 773 | - c[0] = 38; | |
| 774 | - let mut d = vec![129u16; 64]; | |
| 775 | - inverse_transform_add(TX_8X8, tt, &c, &mut d, 0, 8, false, 8); | |
| 776 | - println!("{name}: {:?}", &d[..8]); | |
| 777 | - } | |
| 778 | - } | |
| 779 | -} |
crates/ec-vp9/tests/it/dump_probe.rsdeleted+0 -30
| @@ -1,30 +0,0 @@ | ||
| 1 | -use crate::ivf; | |
| 2 | -use ec_vp9::decode::Decoder; | |
| 3 | -#[test] | |
| 4 | -fn diff_stats() { | |
| 5 | - let bytes = std::fs::read(ec_testkit::fixture("vp9/key-320.ivf")).unwrap(); | |
| 6 | - let (_, _, _, frames) = ivf::parse_ivf(&bytes); | |
| 7 | - let mut d = Decoder::new(); | |
| 8 | - let pic = d.decode(&frames[0].data).unwrap().unwrap(); | |
| 9 | - let refout = ec_testkit::ffmpeg() | |
| 10 | - .args(["-v","error","-i",ec_testkit::fixture("vp9/key-320.ivf").to_str().unwrap(), | |
| 11 | - "-frames:v","1","-f","rawvideo","-pix_fmt","yuv420p","-"]) | |
| 12 | - .output().unwrap().stdout; | |
| 13 | - let w = 320usize; | |
| 14 | - let mut sb_match = [[0usize; 5]; 4]; | |
| 15 | - let mut sb_total = [[0usize; 5]; 4]; | |
| 16 | - let mut first: Option<(usize, usize)> = None; | |
| 17 | - for y in 0..240 { | |
| 18 | - for x in 0..320 { | |
| 19 | - let a = pic.y[y * pic.stride + x] as u8; | |
| 20 | - let b = refout[y * w + x]; | |
| 21 | - let (sy, sx) = (y / 64, x / 64); | |
| 22 | - sb_total[sy][sx] += 1; | |
| 23 | - if a == b { sb_match[sy][sx] += 1; } else if first.is_none() { first = Some((x, y)); } | |
| 24 | - } | |
| 25 | - } | |
| 26 | - println!("first diff at {:?}", first); | |
| 27 | - for (i, row) in sb_match.iter().enumerate() { | |
| 28 | - println!("sb row {i}: {:?}", row.iter().zip(sb_total[i].iter()).map(|(m, t)| format!("{}/{}", m, t)).collect::<Vec<_>>()); | |
| 29 | - } | |
| 30 | -} |
crates/ec-vp9/tests/it/libvpx_vectors.rsmodified+1 -19
| @@ -11,7 +11,7 @@ | ||
| 11 | 11 | //! difference fails the test and is listed by vector name and frame index. |
| 12 | 12 | |
| 13 | 13 | use ec_vp9::decode::{Decoder, Picture}; |
| 14 | -use std::path::{Path, PathBuf}; | |
| 14 | +use std::path::PathBuf; | |
| 15 | 15 | |
| 16 | 16 | // ------------------------------------------------------------------ MD5 ---- |
| 17 | 17 | |
| @@ -213,19 +213,6 @@ fn check_vector(name: &str, frames: &[&[u8]], expected: &[String]) -> Vec<String | ||
| 213 | 213 | match expected.get(shown) { |
| 214 | 214 | None => problems.push(format!("{name}: extra output frame {shown}")), |
| 215 | 215 | Some(want) => { |
| 216 | - if let Some(d) = std::env::var_os("EC_VP9_DUMP") { | |
| 217 | - let mut raw = Vec::new(); | |
| 218 | - for plane in [&pic.y, &pic.u, &pic.v] { | |
| 219 | - for &s in plane.iter() { | |
| 220 | - if pic.bit_depth > 8 { | |
| 221 | - raw.extend_from_slice(&s.to_le_bytes()); | |
| 222 | - } else { | |
| 223 | - raw.push(s as u8); | |
| 224 | - } | |
| 225 | - } | |
| 226 | - } | |
| 227 | - let _ = std::fs::write(Path::new(&d).join(format!("{name}.{shown}.yuv")), raw); | |
| 228 | - } | |
| 229 | 216 | let got = picture_md5(&pic); |
| 230 | 217 | if &got != want { |
| 231 | 218 | problems.push(format!("{name}: frame {shown} md5 {got} != {want}")); |
| @@ -270,11 +257,6 @@ fn libvpx_vectors_match_per_frame_md5() { | ||
| 270 | 257 | continue; |
| 271 | 258 | } |
| 272 | 259 | } |
| 273 | - if let Ok(only) = std::env::var("EC_VP9_ONLY") | |
| 274 | - && !name.contains(&only) | |
| 275 | - { | |
| 276 | - continue; | |
| 277 | - } | |
| 278 | 260 | let vec_path = dir.join(&name); |
| 279 | 261 | let data = match std::fs::read(&vec_path) { |
| 280 | 262 | Ok(d) => d, |
crates/ec-vp9/tests/it/main.rsmodified+0 -13
| @@ -4,7 +4,6 @@ | ||
| 4 | 4 | #![forbid(unsafe_code)] |
| 5 | 5 | |
| 6 | 6 | mod common; |
| 7 | -mod dump_probe; | |
| 8 | 7 | mod fuzz_regressions; |
| 9 | 8 | mod hbd_exact; |
| 10 | 9 | mod inter_pixels_exact; |
| @@ -15,16 +14,4 @@ mod libvpx_vectors; | ||
| 15 | 14 | mod no_panic; |
| 16 | 15 | mod odd_dimensions_exact; |
| 17 | 16 | mod scaledref_exact; |
| 18 | -mod scratch_bool; | |
| 19 | -mod scratch_err; | |
| 20 | -mod scratch_hdr2; | |
| 21 | -mod scratch_hdr3; | |
| 22 | -mod scratch_hdr; | |
| 23 | -mod scratch_lfdump; | |
| 24 | -mod scratch_lossless; | |
| 25 | -mod scratch_pixdump10; | |
| 26 | -mod scratch_pixdump; | |
| 27 | -mod scratch_realsweep; | |
| 28 | -mod scratch_tiledbg; | |
| 29 | -mod scratch_tok; | |
| 30 | 17 | mod subsampling_exact; |
crates/ec-vp9/tests/it/scratch_bool.rsdeleted+0 -13
| @@ -1,13 +0,0 @@ | ||
| 1 | -use crate::ivf; | |
| 2 | -use ec_vp9::bool::BoolDecoder; | |
| 3 | - | |
| 4 | -#[test] | |
| 5 | -fn probe_first_bools() { | |
| 6 | - let bytes = std::fs::read(ec_testkit::fixture("vp9/lossless-64.ivf")).unwrap(); | |
| 7 | - let (_, _, _, frames) = ivf::parse_ivf(&bytes); | |
| 8 | - let frame = &frames[0].data; | |
| 9 | - println!("slice bytes: {:02x?}", &frame[18..26]); | |
| 10 | - let mut r = BoolDecoder::new(&frame[18..18 + 113]).unwrap(); | |
| 11 | - let bits: Vec<u8> = (0..8).map(|_| u8::from(r.read_bool(128))).collect(); | |
| 12 | - println!("first 8 bools(128): {bits:?}"); | |
| 13 | -} |
crates/ec-vp9/tests/it/scratch_err.rsdeleted+0 -13
| @@ -1,13 +0,0 @@ | ||
| 1 | -use crate::ivf; | |
| 2 | -use ec_vp9::decode::Decoder; | |
| 3 | -#[test] | |
| 4 | -fn show_err() { | |
| 5 | - let bytes = std::fs::read(ec_testkit::fixture("bitstreams/vp9-superframe-altref.ivf")).unwrap(); | |
| 6 | - let (_, _, _, frames) = ivf::parse_ivf(&bytes); | |
| 7 | - let mut d = Decoder::new(); | |
| 8 | - println!("f0 bytes: {:02x?}", &frames[0].data[16..24]); | |
| 9 | - match d.decode(&frames[0].data) { | |
| 10 | - Ok(_) => println!("OK"), | |
| 11 | - Err(e) => println!("ERR: {e}"), | |
| 12 | - } | |
| 13 | -} |
crates/ec-vp9/tests/it/scratch_hdr.rsdeleted+0 -22
| @@ -1,22 +0,0 @@ | ||
| 1 | -use ec_vp9_syntax::Vp9Parser; | |
| 2 | -#[test] | |
| 3 | -fn hdr_probe() { | |
| 4 | - for name in ["lossless-64.ivf", "key-320.ivf"] { | |
| 5 | - let bytes = std::fs::read(ec_testkit::fixture(&format!("vp9/{name}"))).unwrap(); | |
| 6 | - let fsize = u32::from_le_bytes(bytes[32..36].try_into().unwrap()) as usize; | |
| 7 | - let frame = &bytes[44..44 + fsize]; | |
| 8 | - let mut pp = Vp9Parser::new(); | |
| 9 | - match pp.parse_frame(frame) { | |
| 10 | - Ok(h) => println!( | |
| 11 | - "{name}: w={} h={} uhs={} hsib={} lf_level={} sharp={} delta={} base_q={} ydc={} uvdc={} uvac={} seg={} tile={:?} txmode_hdr_bytes={}", | |
| 12 | - h.width, h.height, h.uncompressed_header_size, h.header_size_in_bytes, | |
| 13 | - h.loop_filter.level, h.loop_filter.sharpness, h.loop_filter.delta_enabled, | |
| 14 | - h.quantization.base_q_idx, h.quantization.delta_q_y_dc, | |
| 15 | - h.quantization.delta_q_uv_dc, h.quantization.delta_q_uv_ac, | |
| 16 | - h.segmentation.enabled, h.tile_info, | |
| 17 | - h.header_size_in_bytes | |
| 18 | - ), | |
| 19 | - Err(e) => println!("{name}: ERR {e}"), | |
| 20 | - } | |
| 21 | - } | |
| 22 | -} |
crates/ec-vp9/tests/it/scratch_hdr2.rsdeleted+0 -11
| @@ -1,11 +0,0 @@ | ||
| 1 | -use crate::ivf; | |
| 2 | -use ec_vp9_syntax::Vp9Parser; | |
| 3 | -#[test] | |
| 4 | -fn dump_hdr() { | |
| 5 | - let bytes = std::fs::read(ec_testkit::fixture("vp9/lossless-64.ivf")).unwrap(); | |
| 6 | - let (_, _, _, frames) = ivf::parse_ivf(&bytes); | |
| 7 | - let mut p = Vp9Parser::new(); | |
| 8 | - let h = p.parse_frame(&frames[0].data).unwrap(); | |
| 9 | - println!("q={:#?} lf={:#?} seg={:#?}", h.quantization, h.loop_filter, h.segmentation); | |
| 10 | - println!("uh={} hsz={} tile={:#?} w={} h={}", h.uncompressed_header_size, h.header_size_in_bytes, h.tile_info, h.width, h.height); | |
| 11 | -} |
crates/ec-vp9/tests/it/scratch_hdr3.rsdeleted+0 -13
| @@ -1,13 +0,0 @@ | ||
| 1 | -use crate::ivf; | |
| 2 | -use ec_vp9_syntax::Vp9Parser; | |
| 3 | -#[test] | |
| 4 | -fn dump_hdr() { | |
| 5 | - let bytes = std::fs::read(ec_testkit::fixture("bitstreams/vp9-superframe-altref.ivf")).unwrap(); | |
| 6 | - let (_, _, _, frames) = ivf::parse_ivf(&bytes); | |
| 7 | - let subs = ec_vp9_syntax::superframe::split(&frames[0].data).unwrap(); | |
| 8 | - println!("subframes: {}", subs.len()); | |
| 9 | - let mut p = Vp9Parser::new(); | |
| 10 | - let h = p.parse_frame(subs[0]).unwrap(); | |
| 11 | - println!("q={:#?} lf={:#?} seg={:#?}", h.quantization, h.loop_filter, h.segmentation); | |
| 12 | - println!("uh={} hsz={} tile={:#?} w={} h={}", h.uncompressed_header_size, h.header_size_in_bytes, h.tile_info, h.width, h.height); | |
| 13 | -} |
crates/ec-vp9/tests/it/scratch_lfdump.rsdeleted+0 -151
| @@ -1,151 +0,0 @@ | ||
| 1 | -//! [scratch] Loop-filter diff map: decode key-320 frame 0 with and without | |
| 2 | -//! the loop filter (EC_VP9_SKIP_LF=1), print where we disagree with ffmpeg. | |
| 3 | - | |
| 4 | -use crate::ivf; | |
| 5 | - | |
| 6 | -use ec_vp9::decode::Decoder; | |
| 7 | - | |
| 8 | -fn ffmpeg_raw_yuv(path: &std::path::Path) -> Vec<u8> { | |
| 9 | - let out = ec_testkit::ffmpeg() | |
| 10 | - .args(["-v", "error", "-i"]) | |
| 11 | - .arg(path) | |
| 12 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) | |
| 13 | - .output() | |
| 14 | - .expect("ffmpeg runs"); | |
| 15 | - assert!(out.status.success()); | |
| 16 | - out.stdout | |
| 17 | -} | |
| 18 | - | |
| 19 | -#[test] | |
| 20 | -fn dump_lf_diff_map() { | |
| 21 | - let path = | |
| 22 | - ec_testkit::fixture("vp9/key-320.ivf"); | |
| 23 | - let bytes = std::fs::read(&path).unwrap(); | |
| 24 | - let (_f, _w, _h, frames) = ivf::parse_ivf(&bytes); | |
| 25 | - let reference = ffmpeg_raw_yuv(&path); | |
| 26 | - | |
| 27 | - let (w, h) = (320usize, 240usize); | |
| 28 | - let ysz = w * h; | |
| 29 | - | |
| 30 | - // Pre-LF run. | |
| 31 | - let skip_lf = ec_vp9::knobs::set_skip_lf(Some(true)); | |
| 32 | - let mut dec = Decoder::new(); | |
| 33 | - let fi: usize = std::env::var("FRAME") | |
| 34 | - .ok() | |
| 35 | - .and_then(|v| v.parse().ok()) | |
| 36 | - .unwrap_or(0); | |
| 37 | - for fr in &frames[..fi] { | |
| 38 | - dec.decode(&fr.data).expect("decode"); | |
| 39 | - } | |
| 40 | - let pic_pre = dec.decode(&frames[fi].data).expect("decode").expect("shown"); | |
| 41 | - std::fs::write(std::env::temp_dir().join("y_pre_ours.raw"), pic_pre.y[..ysz].iter().map(|&v| v as u8).collect::<Vec<u8>>()).unwrap(); | |
| 42 | - std::fs::write(std::env::temp_dir().join("u_pre_ours.raw"), pic_pre.u.iter().map(|&v| v as u8).collect::<Vec<u8>>()).unwrap(); | |
| 43 | - std::fs::write(std::env::temp_dir().join("v_pre_ours.raw"), pic_pre.v.iter().map(|&v| v as u8).collect::<Vec<u8>>()).unwrap(); | |
| 44 | - drop(skip_lf); | |
| 45 | - | |
| 46 | - // Post-LF run (fresh decoder). | |
| 47 | - let mut dec = Decoder::new(); | |
| 48 | - for fr in &frames[..fi] { | |
| 49 | - dec.decode(&fr.data).expect("decode"); | |
| 50 | - } | |
| 51 | - let pic_post = dec.decode(&frames[fi].data).expect("decode").expect("shown"); | |
| 52 | - std::fs::write(std::env::temp_dir().join("y_post_ours.raw"), pic_post.y[..ysz].iter().map(|&v| v as u8).collect::<Vec<u8>>()).unwrap(); | |
| 53 | - std::fs::write(std::env::temp_dir().join("u_post_ours.raw"), pic_post.u.iter().map(|&v| v as u8).collect::<Vec<u8>>()).unwrap(); | |
| 54 | - std::fs::write(std::env::temp_dir().join("v_post_ours.raw"), pic_post.v.iter().map(|&v| v as u8).collect::<Vec<u8>>()).unwrap(); | |
| 55 | - | |
| 56 | - let fsz = ysz + 2 * (w / 2) * (h / 2); | |
| 57 | - let ff = &reference[fi * fsz..fi * fsz + ysz]; | |
| 58 | - let pre = &pic_pre.y[..ysz]; | |
| 59 | - let post = &pic_post.y[..ysz]; | |
| 60 | - | |
| 61 | - let pre_diffs: Vec<usize> = (0..ysz).filter(|&i| pre[i] as u8 != ff[i]).collect(); | |
| 62 | - let post_diffs: Vec<usize> = (0..ysz).filter(|&i| post[i] as u8 != ff[i]).collect(); | |
| 63 | - let lf_changed_ours: Vec<usize> = (0..ysz).filter(|&i| pre[i] != post[i]).collect(); | |
| 64 | - println!("pre-LF diffs vs ffmpeg : {}", pre_diffs.len()); | |
| 65 | - println!("post-LF diffs vs ffmpeg: {}", post_diffs.len()); | |
| 66 | - println!("pixels our LF changed : {}", lf_changed_ours.len()); | |
| 67 | - for &i in post_diffs.iter().take(30) { | |
| 68 | - println!( | |
| 69 | - " POST diff ({:3},{:3}) ours {:3} ff {:3} (pre-ours {:3})", | |
| 70 | - i % w, | |
| 71 | - i / w, | |
| 72 | - post[i], | |
| 73 | - ff[i], | |
| 74 | - pre[i] | |
| 75 | - ); | |
| 76 | - } | |
| 77 | - for &i in pre_diffs.iter().take(10) { | |
| 78 | - println!( | |
| 79 | - " PRE diff ({:3},{:3}) ours {:3} ff {:3}", | |
| 80 | - i % w, | |
| 81 | - i / w, | |
| 82 | - pre[i], | |
| 83 | - ff[i] | |
| 84 | - ); | |
| 85 | - } | |
| 86 | - | |
| 87 | - // ASCII map of the top-left 48x32: mark post-LF diffs (#), pre-LF diffs | |
| 88 | - // (?), pixels only our LF touched (o). | |
| 89 | - println!("map rows 0..32, cols 0..48 (#=post diff, ?=pre-only, o=our-LF-changed)"); | |
| 90 | - for y in 0..32 { | |
| 91 | - let mut line = String::new(); | |
| 92 | - for x in 0..48 { | |
| 93 | - let i = y * w + x; | |
| 94 | - if post_diffs.binary_search(&i).is_ok() { | |
| 95 | - line.push('#'); | |
| 96 | - } else if pre_diffs.binary_search(&i).is_ok() { | |
| 97 | - line.push('?'); | |
| 98 | - } else if lf_changed_ours.binary_search(&i).is_ok() { | |
| 99 | - line.push('o'); | |
| 100 | - } else { | |
| 101 | - line.push('.'); | |
| 102 | - } | |
| 103 | - } | |
| 104 | - println!("{line}"); | |
| 105 | - } | |
| 106 | - // Column/row histograms of post-LF diffs (first 24 of each). | |
| 107 | - let mut cols = vec![0usize; w]; | |
| 108 | - let mut rows = vec![0usize; h]; | |
| 109 | - for &i in &post_diffs { | |
| 110 | - cols[i % w] += 1; | |
| 111 | - rows[i / w] += 1; | |
| 112 | - } | |
| 113 | - println!( | |
| 114 | - "diff columns>0: {:?}", | |
| 115 | - (0..w).filter(|&c| cols[c] > 0).take(24).collect::<Vec<_>>() | |
| 116 | - ); | |
| 117 | - println!( | |
| 118 | - "diff rows>0 : {:?}", | |
| 119 | - (0..h).filter(|&r| rows[r] > 0).take(24).collect::<Vec<_>>() | |
| 120 | - ); | |
| 121 | - let uv = (w / 2) * (h / 2); | |
| 122 | - let ff_u = &reference[fi * fsz + ysz..fi * fsz + ysz + uv]; | |
| 123 | - let ff_v = &reference[fi * fsz + ysz + uv..fi * fsz + ysz + 2 * uv]; | |
| 124 | - let uw = w / 2; | |
| 125 | - let u_d: Vec<_> = (0..uv).filter(|&i| pic_post.u[i] as u8 != ff_u[i]).collect(); | |
| 126 | - let v_d: Vec<_> = (0..uv).filter(|&i| pic_post.v[i] as u8 != ff_v[i]).collect(); | |
| 127 | - let u_pre: Vec<_> = (0..uv).filter(|&i| pic_pre.u[i] as u8 != ff_u[i]).collect(); | |
| 128 | - let v_pre: Vec<_> = (0..uv).filter(|&i| pic_pre.v[i] as u8 != ff_v[i]).collect(); | |
| 129 | - println!("U pre diffs: {} post: {}", u_pre.len(), u_d.len()); | |
| 130 | - for &i in &u_d { | |
| 131 | - println!( | |
| 132 | - " U ({}, {}) pre {} post {} ff {}", | |
| 133 | - i % uw, | |
| 134 | - i / uw, | |
| 135 | - pic_pre.u[i], | |
| 136 | - pic_post.u[i], | |
| 137 | - ff_u[i] | |
| 138 | - ); | |
| 139 | - } | |
| 140 | - println!("V pre diffs: {} post: {}", v_pre.len(), v_d.len()); | |
| 141 | - for &i in &v_d { | |
| 142 | - println!( | |
| 143 | - " V ({}, {}) pre {} post {} ff {}", | |
| 144 | - i % uw, | |
| 145 | - i / uw, | |
| 146 | - pic_pre.v[i], | |
| 147 | - pic_post.v[i], | |
| 148 | - ff_v[i] | |
| 149 | - ); | |
| 150 | - } | |
| 151 | -} |
crates/ec-vp9/tests/it/scratch_lossless.rsdeleted+0 -17
| @@ -1,17 +0,0 @@ | ||
| 1 | -use crate::ivf; | |
| 2 | -use ec_vp9::decode::Decoder; | |
| 3 | -#[test] | |
| 4 | -fn lossless_matches() { | |
| 5 | - let path = ec_testkit::fixture("vp9/lossless-64.ivf"); | |
| 6 | - let bytes = std::fs::read(&path).unwrap(); | |
| 7 | - let (_, w, h, frames) = ivf::parse_ivf(&bytes); | |
| 8 | - let refout = ec_testkit::ffmpeg() | |
| 9 | - .args(["-v","error","-i", path.to_str().unwrap(), "-frames:v","1","-f","rawvideo","-pix_fmt","yuv420p","-"]) | |
| 10 | - .output().unwrap().stdout; | |
| 11 | - let mut d = Decoder::new(); | |
| 12 | - let pic = d.decode(&frames[0].data).unwrap().unwrap(); | |
| 13 | - let ylen = w as usize * h as usize; | |
| 14 | - let mism: Vec<usize> = (0..ylen).filter(|&i| pic.y[i] as u8 != refout[i]).collect(); | |
| 15 | - println!("w={w} h={h} mismatches={} first={:?} ours={:?} ref={:?}", | |
| 16 | - mism.len(), mism.first(), mism.first().map(|&i| pic.y[i]), mism.first().map(|&i| refout[i])); | |
| 17 | -} |
crates/ec-vp9/tests/it/scratch_pixdump.rsdeleted+0 -77
| @@ -1,77 +0,0 @@ | ||
| 1 | -//! Scratch: dump every shown frame's planes for the pixel comparator. | |
| 2 | -//! | |
| 3 | -//! `INTER_IVF=<path> EC_VP9_PIXDUMP=<out> cargo test -p ec-vp9 --test scratch_pixdump` | |
| 4 | -//! | |
| 5 | -//! Layout matches the oracle: per shown frame, Y (w*h), U and V each | |
| 6 | -//! (((w+1)/2)*((h+1)/2)) (chroma ceils, so odd extents keep the last column/ | |
| 7 | -//! row), rows packed to the visible width. | |
| 8 | - | |
| 9 | -use ec_vp9::decode::Decoder; | |
| 10 | - | |
| 11 | -#[test] | |
| 12 | -#[ignore = "manual dump: set INTER_IVF and EC_VP9_PIXDUMP"] | |
| 13 | -fn pixdump() { | |
| 14 | - let ivf = std::env::var("INTER_IVF").expect("set INTER_IVF"); | |
| 15 | - let out = std::env::var("EC_VP9_PIXDUMP").expect("set EC_VP9_PIXDUMP"); | |
| 16 | - let bytes = std::fs::read(&ivf).expect("read ivf"); | |
| 17 | - let (_, w, h, frames) = parse_ivf(&bytes); | |
| 18 | - let mut decoder = Decoder::new(); | |
| 19 | - let mut dump = Vec::new(); | |
| 20 | - let mut shown = 0usize; | |
| 21 | - for (i, f) in frames.iter().enumerate() { | |
| 22 | - match decoder.decode(&f.data) { | |
| 23 | - Ok(Some(pic)) => { | |
| 24 | - for &v in pic.y.iter().chain(pic.u.iter()).chain(pic.v.iter()) { | |
| 25 | - if pic.bit_depth == 8 { | |
| 26 | - dump.push(v as u8); | |
| 27 | - } else { | |
| 28 | - dump.extend_from_slice(&v.to_le_bytes()); | |
| 29 | - } | |
| 30 | - } | |
| 31 | - eprintln!( | |
| 32 | - "PIXFRAME input={i} shown={shown} {w}x{h} {}x{}", | |
| 33 | - pic.width, pic.height | |
| 34 | - ); | |
| 35 | - shown += 1; | |
| 36 | - } | |
| 37 | - Ok(None) => eprintln!("PIXFRAME input={i} hidden"), | |
| 38 | - Err(e) => { | |
| 39 | - eprintln!("PIXERR input={i}: {e}"); | |
| 40 | - break; | |
| 41 | - } | |
| 42 | - } | |
| 43 | - } | |
| 44 | - std::fs::write(&out, &dump).expect("write dump"); | |
| 45 | - eprintln!("wrote {} bytes ({shown} shown frames)", dump.len()); | |
| 46 | -} | |
| 47 | - | |
| 48 | -fn parse_ivf(bytes: &[u8]) -> (&str, u16, u16, Vec<IvfFrame>) { | |
| 49 | - assert_eq!(&bytes[0..4], b"DKIF", "not an IVF file"); | |
| 50 | - let hdr_len = u16::from_le_bytes([bytes[6], bytes[7]]) as usize; | |
| 51 | - let fourcc = std::str::from_utf8(&bytes[8..12]).unwrap(); | |
| 52 | - let width = u16::from_le_bytes([bytes[12], bytes[13]]); | |
| 53 | - let height = u16::from_le_bytes([bytes[14], bytes[15]]); | |
| 54 | - let mut pos = hdr_len; | |
| 55 | - let mut frames = Vec::new(); | |
| 56 | - while pos + 12 <= bytes.len() { | |
| 57 | - let sz = u32::from_le_bytes([bytes[pos], bytes[pos + 1], bytes[pos + 2], bytes[pos + 3]]) | |
| 58 | - as usize; | |
| 59 | - let pts = u64::from_le_bytes(bytes[pos + 4..pos + 12].try_into().unwrap()); | |
| 60 | - pos += 12; | |
| 61 | - if pos + sz > bytes.len() { | |
| 62 | - break; | |
| 63 | - } | |
| 64 | - frames.push(IvfFrame { | |
| 65 | - pts, | |
| 66 | - data: bytes[pos..pos + sz].to_vec(), | |
| 67 | - }); | |
| 68 | - pos += sz; | |
| 69 | - } | |
| 70 | - (fourcc, width, height, frames) | |
| 71 | -} | |
| 72 | - | |
| 73 | -struct IvfFrame { | |
| 74 | - #[allow(dead_code)] | |
| 75 | - pts: u64, | |
| 76 | - data: Vec<u8>, | |
| 77 | -} |
crates/ec-vp9/tests/it/scratch_pixdump10.rsdeleted+0 -61
| @@ -1,61 +0,0 @@ | ||
| 1 | -//! Scratch: dump every shown frame's planes as little-endian u16 for the | |
| 2 | -//! high-bit-depth pixel comparator. | |
| 3 | -//! | |
| 4 | -//! `INTER_IVF=<path> EC_VP9_PIXDUMP=<out> cargo test -p ec-vp9 --test scratch_pixdump10` | |
| 5 | -//! | |
| 6 | -//! Layout matches drv_pix10: per shown frame, Y (w*h), U and V each | |
| 7 | -//! (((w+1)/2)*((h+1)/2)) (chroma ceils), rows packed to the visible width, | |
| 8 | -//! each sample written as two little-endian bytes. | |
| 9 | - | |
| 10 | -use ec_vp9::decode::Decoder; | |
| 11 | - | |
| 12 | -#[test] | |
| 13 | -#[ignore = "manual dump: set INTER_IVF and EC_VP9_PIXDUMP"] | |
| 14 | -fn pixdump10() { | |
| 15 | - let ivf = std::env::var("INTER_IVF").expect("set INTER_IVF"); | |
| 16 | - let out = std::env::var("EC_VP9_PIXDUMP").expect("set EC_VP9_PIXDUMP"); | |
| 17 | - let bytes = std::fs::read(&ivf).expect("read ivf"); | |
| 18 | - let (_, w, h, frames) = parse_ivf(&bytes); | |
| 19 | - let mut decoder = Decoder::new(); | |
| 20 | - let mut dump = Vec::new(); | |
| 21 | - let mut shown = 0usize; | |
| 22 | - for (i, f) in frames.iter().enumerate() { | |
| 23 | - match decoder.decode(f) { | |
| 24 | - Ok(Some(pic)) => { | |
| 25 | - for &v in pic.y.iter().chain(pic.u.iter()).chain(pic.v.iter()) { | |
| 26 | - dump.extend_from_slice(&v.to_le_bytes()); | |
| 27 | - } | |
| 28 | - eprintln!( | |
| 29 | - "PIXFRAME input={i} shown={shown} {w}x{h} {}x{} bd={}", | |
| 30 | - pic.width, pic.height, pic.bit_depth | |
| 31 | - ); | |
| 32 | - shown += 1; | |
| 33 | - } | |
| 34 | - Ok(None) => eprintln!("PIXFRAME input={i} hidden"), | |
| 35 | - Err(e) => { | |
| 36 | - eprintln!("PIXERR input={i}: {e}"); | |
| 37 | - break; | |
| 38 | - } | |
| 39 | - } | |
| 40 | - } | |
| 41 | - std::fs::write(&out, &dump).expect("write dump"); | |
| 42 | - eprintln!("wrote {} bytes ({shown} shown frames)", dump.len()); | |
| 43 | -} | |
| 44 | - | |
| 45 | -fn parse_ivf(bytes: &[u8]) -> (&str, u16, u16, Vec<Vec<u8>>) { | |
| 46 | - assert_eq!(&bytes[0..4], b"DKIF", "not an IVF file"); | |
| 47 | - let hdr_len = u16::from_le_bytes([bytes[6], bytes[7]]) as usize; | |
| 48 | - let fourcc = std::str::from_utf8(&bytes[8..12]).unwrap(); | |
| 49 | - let width = u16::from_le_bytes([bytes[12], bytes[13]]); | |
| 50 | - let height = u16::from_le_bytes([bytes[14], bytes[15]]); | |
| 51 | - let mut pos = hdr_len; | |
| 52 | - let mut frames = Vec::new(); | |
| 53 | - while pos + 12 <= bytes.len() { | |
| 54 | - let sz = u32::from_le_bytes([bytes[pos], bytes[pos + 1], bytes[pos + 2], bytes[pos + 3]]) | |
| 55 | - as usize; | |
| 56 | - let data = bytes[pos + 12..pos + 12 + sz].to_vec(); | |
| 57 | - frames.push(data); | |
| 58 | - pos += 12 + sz; | |
| 59 | - } | |
| 60 | - (fourcc, width, height, frames) | |
| 61 | -} |
crates/ec-vp9/tests/it/scratch_realsweep.rsdeleted+0 -134
| @@ -1,134 +0,0 @@ | ||
| 1 | -//! [scratch] Real-content keyframe sweep. | |
| 2 | -//! | |
| 3 | -//! The library carries no VP9 content of its own (its one webm, in | |
| 4 | -//! `~/Downloads`, is VP8), so the keyframe path only ever sees real imagery | |
| 5 | -//! through a transcode: encode `SWEEP_SRC` as all-intra VP9 with ffmpeg | |
| 6 | -//! (`-g 1`, so every frame is a keyframe), decode every frame with `ec-vp9`, | |
| 7 | -//! and diff Y/U/V against ffmpeg's own decode of the same file. | |
| 8 | -//! | |
| 9 | -//! ```text | |
| 10 | -//! SWEEP_SRC=<video> [SWEEP_N=<frames>] \ | |
| 11 | -//! cargo test -p ec-vp9 --test scratch_realsweep -- --nocapture | |
| 12 | -//! ``` | |
| 13 | -//! | |
| 14 | -//! Prints one line per frame plus a `RESULT` line; fails if any frame differs. | |
| 15 | -use crate::ivf; | |
| 16 | - | |
| 17 | -use ec_vp9::decode::Decoder; | |
| 18 | - | |
| 19 | -#[test] | |
| 20 | -#[ignore = "manual sweep: set SWEEP_SRC or SWEEP_IVF"] | |
| 21 | -fn real_content_sweep() { | |
| 22 | - let src = std::env::var("SWEEP_SRC").unwrap_or_default(); | |
| 23 | - let prebuilt = std::env::var("SWEEP_IVF").ok(); | |
| 24 | - if src.is_empty() && prebuilt.is_none() { | |
| 25 | - panic!("set SWEEP_SRC=<video> or SWEEP_IVF=<ivf>"); | |
| 26 | - } | |
| 27 | - let n: usize = std::env::var("SWEEP_N") | |
| 28 | - .ok() | |
| 29 | - .and_then(|v| v.parse().ok()) | |
| 30 | - .unwrap_or(3); | |
| 31 | - let dir = std::env::temp_dir().join("ec-vp9-sweep"); | |
| 32 | - std::fs::create_dir_all(&dir).unwrap(); | |
| 33 | - let ivf_path = dir.join("allintra.ivf"); | |
| 34 | - if let Some(p) = &prebuilt { | |
| 35 | - std::fs::copy(p, &ivf_path).unwrap(); | |
| 36 | - } else { | |
| 37 | - let enc = ec_testkit::ffmpeg() | |
| 38 | - .args(["-v", "error", "-y", "-i", &src, "-frames:v"]) | |
| 39 | - .arg(n.to_string()) | |
| 40 | - .args([ | |
| 41 | - "-c:v", | |
| 42 | - "libvpx-vp9", | |
| 43 | - "-g", | |
| 44 | - "1", | |
| 45 | - "-deadline", | |
| 46 | - "good", | |
| 47 | - "-cpu-used", | |
| 48 | - "4", | |
| 49 | - "-crf", | |
| 50 | - "32", | |
| 51 | - "-pix_fmt", | |
| 52 | - "yuv420p", | |
| 53 | - ]) | |
| 54 | - // `SWEEP_TILE0=1` pins a single tile: the multi-tile path is what | |
| 55 | - // ffmpeg picks by default at 1080p+ and it is diagnosed separately. | |
| 56 | - .args(if std::env::var_os("SWEEP_TILE0").is_some() { | |
| 57 | - vec!["-tile-columns", "0", "-tile-rows", "0"] | |
| 58 | - } else { | |
| 59 | - vec![] | |
| 60 | - }) | |
| 61 | - .args(["-f", "ivf"]) | |
| 62 | - .arg(&ivf_path) | |
| 63 | - .status() | |
| 64 | - .expect("ffmpeg encode"); | |
| 65 | - assert!(enc.success(), "ffmpeg encode of {src} failed"); | |
| 66 | - } | |
| 67 | - // Decode list as a human would, to prove our YUV probe is honest. | |
| 68 | - let raw = ec_testkit::ffmpeg() | |
| 69 | - .args(["-v", "error", "-i"]) | |
| 70 | - .arg(&ivf_path) | |
| 71 | - .args(["-f", "rawvideo", "-pix_fmt", "yuv420p", "-"]) | |
| 72 | - .output() | |
| 73 | - .expect("ffmpeg decode"); | |
| 74 | - assert!(raw.status.success(), "ffmpeg decode of the IVF failed"); | |
| 75 | - | |
| 76 | - let bytes = std::fs::read(&ivf_path).unwrap(); | |
| 77 | - let (_fourcc, w, h, frames) = ivf::parse_ivf(&bytes); | |
| 78 | - let (w, h) = (w as usize, h as usize); | |
| 79 | - let ysz = w * h; | |
| 80 | - let uvs = (w / 2) * (h / 2); | |
| 81 | - assert_eq!( | |
| 82 | - raw.stdout.len(), | |
| 83 | - frames.len() * (ysz + 2 * uvs), | |
| 84 | - "reference frame size mismatch" | |
| 85 | - ); | |
| 86 | - | |
| 87 | - let mut bad = 0usize; | |
| 88 | - for (i, frame) in frames.iter().enumerate() { | |
| 89 | - let mut dec = Decoder::new(); | |
| 90 | - let pic = match dec.decode(&frame.data) { | |
| 91 | - Ok(Some(p)) => p, | |
| 92 | - other => { | |
| 93 | - println!("frame {i}: DECODE REFUSED/ERR {other:?}"); | |
| 94 | - bad += 1; | |
| 95 | - continue; | |
| 96 | - } | |
| 97 | - }; | |
| 98 | - let base = i * (ysz + 2 * uvs); | |
| 99 | - if i == 0 { | |
| 100 | - std::fs::write(dir.join("ours_f0.yuv"), { | |
| 101 | - let mut v = Vec::with_capacity(ysz + 2 * uvs); | |
| 102 | - v.extend(pic.y[..ysz.min(pic.y.len())].iter().map(|&x| x as u8)); | |
| 103 | - v.extend(pic.u.iter().map(|&x| x as u8)); | |
| 104 | - v.extend(pic.v.iter().map(|&x| x as u8)); | |
| 105 | - v | |
| 106 | - }) | |
| 107 | - .unwrap(); | |
| 108 | - std::fs::write(dir.join("ff_f0.yuv"), &raw.stdout[..ysz + 2 * uvs]).unwrap(); | |
| 109 | - } | |
| 110 | - let yd = (0..ysz) | |
| 111 | - .filter(|&k| pic.y[k] as u8 != raw.stdout[base + k]) | |
| 112 | - .count(); | |
| 113 | - let ud = (0..uvs) | |
| 114 | - .filter(|&k| pic.u[k] as u8 != raw.stdout[base + ysz + k]) | |
| 115 | - .count(); | |
| 116 | - let vd = (0..uvs) | |
| 117 | - .filter(|&k| pic.v[k] as u8 != raw.stdout[base + ysz + uvs + k]) | |
| 118 | - .count(); | |
| 119 | - println!( | |
| 120 | - "frame {i}: {w}x{h} stride {} uv_stride {} Y {yd} U {ud} V {vd}", | |
| 121 | - pic.stride, pic.uv_stride | |
| 122 | - ); | |
| 123 | - if yd + ud + vd > 0 { | |
| 124 | - bad += 1; | |
| 125 | - } | |
| 126 | - } | |
| 127 | - println!( | |
| 128 | - "RESULT {} of {} frames byte-exact (source {})", | |
| 129 | - frames.len() - bad, | |
| 130 | - frames.len(), | |
| 131 | - if src.is_empty() { ivf_path.display().to_string() } else { src.clone() } | |
| 132 | - ); | |
| 133 | - assert_eq!(bad, 0, "{bad} frame(s) differ from ffmpeg"); | |
| 134 | -} |
crates/ec-vp9/tests/it/scratch_tiledbg.rsdeleted+0 -71
| @@ -1,71 +0,0 @@ | ||
| 1 | -//! [scratch] Tile-layout diagnosis for a VP9 IVF: print the parsed header | |
| 2 | -//! sizes and the tile size prefixes at the header's end. | |
| 3 | -//! `TILE_SRC=<ivf> cargo test -p ec-vp9 --test scratch_tiledbg -- --nocapture` | |
| 4 | -use crate::ivf; | |
| 5 | - | |
| 6 | -use ec_vp9_syntax::Vp9Parser; | |
| 7 | - | |
| 8 | -#[test] | |
| 9 | -#[ignore = "manual: set TILE_SRC=<ivf>"] | |
| 10 | -fn tile_dbg() { | |
| 11 | - let src = std::env::var("TILE_SRC").expect("set TILE_SRC=<ivf>"); | |
| 12 | - let bytes = std::fs::read(&src).unwrap(); | |
| 13 | - let (_f, w, h, frames) = ivf::parse_ivf(&bytes); | |
| 14 | - println!("ivf {w}x{h} frames {}", frames.len()); | |
| 15 | - for (i, fr) in frames.iter().enumerate().take(2) { | |
| 16 | - let mut p = Vp9Parser::new(); | |
| 17 | - match p.parse_frame(&fr.data) { | |
| 18 | - Ok(hdr) => { | |
| 19 | - // Tile data starts after BOTH headers (libvpx: `data += | |
| 20 | - // vpx_rb_bytes_read(&rb)` then the compressed header). | |
| 21 | - let off = hdr.uncompressed_header_size as usize + hdr.header_size_in_bytes as usize; | |
| 22 | - println!( | |
| 23 | - "frame {i}: len {} uhs {} hsib {} tile cols {} rows {} mi {}x{}", | |
| 24 | - fr.data.len(), | |
| 25 | - hdr.uncompressed_header_size, | |
| 26 | - hdr.header_size_in_bytes, | |
| 27 | - hdr.tile_info.cols_log2, | |
| 28 | - hdr.tile_info.rows_log2, | |
| 29 | - hdr.mi_cols(), | |
| 30 | - hdr.mi_rows() | |
| 31 | - ); | |
| 32 | - println!( | |
| 33 | - " loop_filter level={} sharpness={}", | |
| 34 | - hdr.loop_filter.level, hdr.loop_filter.sharpness | |
| 35 | - ); | |
| 36 | - let tail = &fr.data[off..]; | |
| 37 | - println!( | |
| 38 | - " tail len {} first16 {:?}", | |
| 39 | - tail.len(), | |
| 40 | - &tail[..16.min(tail.len())] | |
| 41 | - ); | |
| 42 | - // Tile size prefixes are BIG-endian (libvpx `mem_get_be32`, | |
| 43 | - // vp9_decodeframe.c:1686) -- a LE read turns a 4-column | |
| 44 | - // 1080p prefix into ~5e8 and starves the walk. | |
| 45 | - if tail.len() >= 4 { | |
| 46 | - let be = u32::from_be_bytes(tail[..4].try_into().unwrap()) as usize; | |
| 47 | - let le = u32::from_le_bytes(tail[..4].try_into().unwrap()) as usize; | |
| 48 | - println!(" first tile size prefix be={be} le={le} (tail-4 = {})", tail.len() - 4); | |
| 49 | - // Walk the prefixes: each must fit, and the LAST tile is the | |
| 50 | - // remainder (`get_tile_buffer` size = data_end - data). | |
| 51 | - let n = 1usize << (hdr.tile_info.cols_log2 + hdr.tile_info.rows_log2); | |
| 52 | - let (mut pos, mut ok) = (0usize, true); | |
| 53 | - for _ in 0..n.saturating_sub(1) { | |
| 54 | - if pos + 4 > tail.len() { | |
| 55 | - ok = false; | |
| 56 | - break; | |
| 57 | - } | |
| 58 | - let sz = u32::from_be_bytes(tail[pos..pos + 4].try_into().unwrap()) as usize; | |
| 59 | - pos += 4 + sz; | |
| 60 | - ok &= pos <= tail.len(); | |
| 61 | - } | |
| 62 | - println!( | |
| 63 | - " walk: {n} tiles, prefixes consume {pos} ok={ok}, last tile {}", | |
| 64 | - tail.len().saturating_sub(pos) | |
| 65 | - ); | |
| 66 | - } | |
| 67 | - } | |
| 68 | - Err(e) => println!("frame {i}: parse ERR {e}"), | |
| 69 | - } | |
| 70 | - } | |
| 71 | -} |
crates/ec-vp9/tests/it/scratch_tok.rsdeleted+0 -16
| @@ -1,16 +0,0 @@ | ||
| 1 | -//! [scratch] Single decode of key-320 frame 0 with EC_VP9_TRACE=1 for | |
| 2 | -//! oracle TOK/TXB/MODE/EOB diffing. stderr is the trace. | |
| 3 | - | |
| 4 | -use crate::ivf; | |
| 5 | - | |
| 6 | -use ec_vp9::decode::Decoder; | |
| 7 | - | |
| 8 | -#[test] | |
| 9 | -fn dump_tok_trace() { | |
| 10 | - let path = | |
| 11 | - ec_testkit::fixture("vp9/key-320.ivf"); | |
| 12 | - let bytes = std::fs::read(&path).unwrap(); | |
| 13 | - let (_f, _w, _h, frames) = ivf::parse_ivf(&bytes); | |
| 14 | - let mut dec = Decoder::new(); | |
| 15 | - let _pic = dec.decode(&frames[0].data).expect("decode").expect("shown"); | |
| 16 | -} |
crates/ec-vp9/tests/scratch_sweep.rsdeleted+0 -24
| @@ -1,24 +0,0 @@ | ||
| 1 | -#[path = "it/ivf.rs"] | |
| 2 | -mod ivf; | |
| 3 | -use ec_vp9::decode::Decoder; | |
| 4 | -#[test] | |
| 5 | -fn sweep() { | |
| 6 | - std::panic::set_hook(Box::new(|_| {})); | |
| 7 | - let p = ec_testkit::fixture("vp9/lossless-64.ivf"); | |
| 8 | - let bytes = std::fs::read(&p).unwrap(); | |
| 9 | - let (_, w, h, frames) = ivf::parse_ivf(&bytes); | |
| 10 | - let refout = ec_testkit::ffmpeg() | |
| 11 | - .args(["-v","error","-i", p.to_str().unwrap(), "-frames:v","1","-f","rawvideo","-pix_fmt","yuv420p","-"]) | |
| 12 | - .output().unwrap().stdout; | |
| 13 | - let ylen = w as usize * h as usize; | |
| 14 | - let mut best = (0usize, 0usize); | |
| 15 | - for t in (100..260).step_by(1) { | |
| 16 | - let _tail = ec_vp9::knobs::set_force_tail(Some(t)); | |
| 17 | - let mut d = Decoder::new(); | |
| 18 | - let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| d.decode(&frames[0].data))); | |
| 19 | - let Ok(Ok(Some(pic))) = r else { continue }; | |
| 20 | - let m = (0..ylen).filter(|&i| pic.y[i] as u8 == refout[i]).count(); | |
| 21 | - if m > best.0 { best = (m, t); } | |
| 22 | - } | |
| 23 | - println!("BEST matches {} at tail_start {}", best.0, best.1); | |
| 24 | -} |