From 1c71b70ba5f3e4b7a8b25ba24f66db55673374a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 4 Sep 2026 23:52:02 +0300 Subject: [PATCH] refactor(av1): FrameCtx stays crate-private -- public signatures back to what they were The FrameCtx refactor threaded `&crate::decode::FrameCtx` through 21 `pub fn` signatures, which put a `pub(crate)` type in the crate's public API: external callers of `Av1Encoder::encode` stopped compiling (tools/ec-bench). `Av1Encoder` now owns its `FrameCtx` -- one per stream, not per frame, since the inter-frame inheritance guards carry state across frames -- so `encode` takes `(&mut self, picture)` again. `encode_key_frame`, `encode_key_frame_with_modes` and `encode_sequence` keep their old public signatures as wrappers over `pub(crate) *_with_ctx` inners that make the context. The other 14 helpers that gained the parameter (intra/mc/warp/motion predictors, `decode_key_frame_tile`) have no caller outside the crate and become `pub(crate)`. `Av1Encoder` is still `Send` (compile-time assert), but owning cells makes it `!Sync`; nothing in the workspace shares one by reference. --- crates/ec-av1/src/decode.rs | 22 +++--- crates/ec-av1/src/encode.rs | 136 +++++++++++++++++++++++------------ crates/ec-av1/src/encoder.rs | 49 +++++++------ crates/ec-av1/src/intra.rs | 4 +- crates/ec-av1/src/mc.rs | 20 +++--- crates/ec-av1/src/motion.rs | 2 +- crates/ec-av1/src/stream.rs | 24 +++---- crates/ec-av1/src/warp.rs | 4 +- 8 files changed, 159 insertions(+), 102 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index cc45e921..b0a14eea 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -81,6 +81,12 @@ pub(crate) struct FrameCtx { pub(crate) grain_bit_depth: std::cell::Cell, } +impl std::fmt::Debug for FrameCtx { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("FrameCtx") + } +} + impl FrameCtx { /// A fresh context, every field at the default its thread-local /// predecessor was born with. @@ -17535,7 +17541,7 @@ fn apply_loop_restoration( /// 16x16, a directional mode's angle delta other than zero, chroma-from-luma), /// or when the tile payload runs out of the symbols this decode expects (a /// genuinely foreign stream). -pub fn decode_key_frame_tile( +pub(crate) fn decode_key_frame_tile( data: &[u8], mi_cols: u32, mi_rows: u32, @@ -32762,7 +32768,7 @@ mod tests { mi_rows, base_q_idx, .. - }: Encoded = crate::encode::encode_key_frame_with_modes(&picture, 40, 0.0, modes, fctx).unwrap(); + }: Encoded = crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx).unwrap(); let decoded = decode_key_frame_tile( &tile, mi_cols, @@ -33117,10 +33123,10 @@ mod tests { eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg"); return; } - use crate::encode::encode_key_frame; + use crate::encode::encode_key_frame_with_ctx; for &(width, height) in &[(64usize, 64usize), (216, 96), (40, 32)] { let picture = round_trip_test_card(width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (coded_w, coded_h) = ffprobe_size(&encoded.stream); let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize); let ours = decode_key_frame_tile( @@ -33189,11 +33195,11 @@ mod tests { /// into the next as its reference -- exactly the single-slot DPB /// [`crate::encode::encode_sequence`] itself threads. fn gop_round_trips(width: usize, height: usize, fctx: &crate::decode::FrameCtx) { - use crate::encode::encode_sequence; + use crate::encode::encode_sequence_with_ctx; let pictures: Vec<_> = (0..4) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), 4); let key = &encoded.frames[0]; @@ -33520,12 +33526,12 @@ mod tests { eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg"); return; } - use crate::encode::encode_sequence; + use crate::encode::encode_sequence_with_ctx; let (width, height) = (128usize, 64usize); let pictures: Vec<_> = (0..3) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); let (coded_w, coded_h) = ffprobe_size(&encoded.stream); let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, coded_w as usize, coded_h as usize, 3); diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 3acf13ef..d30ab733 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1995,8 +1995,52 @@ fn coeffs(levels: &[i32], side: usize) -> Vec { /// # Errors /// Returns an error when the picture's width or height is zero or odd, or /// when its planes are not 4:2:0 of that size. -pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx) -> Result { - encode_key_frame_with_modes(picture, base_q_idx, deadzone, &KEY_FRAME_MODES, fctx) +/// Codes one picture as a whole key frame, at `base_q_idx`, and returns its +/// stream. The per-frame decode state this needs lives for exactly this call. +/// +/// # Errors +/// Returns an error under the same conditions +/// [`encode_key_frame_with_modes`] does. +pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64) -> Result { + encode_key_frame_with_ctx(picture, base_q_idx, deadzone, &crate::decode::FrameCtx::new()) +} + +/// [`encode_key_frame`] with the per-block intra modes given rather than +/// searched. +/// +/// # Errors +/// Returns an error when `picture`'s dimensions are odd or zero, when `modes` +/// is empty, or when a block's coefficients do not fit the coded frame. +pub fn encode_key_frame_with_modes( + picture: &Picture, + base_q_idx: u8, + deadzone: f64, + modes: &[u8], +) -> Result { + encode_key_frame_with_modes_with_ctx( + picture, + base_q_idx, + deadzone, + modes, + &crate::decode::FrameCtx::new(), + ) +} + +/// Codes `pictures` as one key frame followed by inter frames. +/// +/// # Errors +/// Returns an error under the same conditions [`encode_key_frame`] and the +/// inter frame path do. +pub fn encode_sequence( + pictures: &[Picture], + base_q_idx: u8, + deadzone: f64, +) -> Result { + encode_sequence_with_ctx(pictures, base_q_idx, deadzone, &crate::decode::FrameCtx::new()) +} + +pub(crate) fn encode_key_frame_with_ctx(picture: &Picture, base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx) -> Result { + encode_key_frame_with_modes_with_ctx(picture, base_q_idx, deadzone, &KEY_FRAME_MODES, fctx) } /// Encodes one picture as a key frame, choosing each block's luma mode from @@ -2010,7 +2054,7 @@ pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64, fctx: /// # Errors /// The same as [`encode_key_frame`], and additionally when `modes` is empty or /// names a mode [`crate::intra::predict`] does not predict. -pub fn encode_key_frame_with_modes( +pub(crate) fn encode_key_frame_with_modes_with_ctx( picture: &Picture, base_q_idx: u8, deadzone: f64, @@ -3314,7 +3358,7 @@ pub struct EncodedSequence { /// Returns an error when `pictures` is empty, when any picture besides the /// first is not the same size as the first, or under the same conditions /// [`encode_key_frame`] and the inter frame path do. -pub fn encode_sequence( +pub(crate) fn encode_sequence_with_ctx( pictures: &[Picture], base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx, @@ -3659,7 +3703,7 @@ mod tests { } for &(width, height) in &[(64usize, 64usize), (96, 64), (160, 96), (32, 48)] { let picture = test_card(width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let decoded = ffmpeg_decode(&encoded.stream, width, height); assert_eq!( decoded.y, encoded.reconstruction.y, @@ -3673,7 +3717,7 @@ mod tests { let (width, height) = (64usize, 64usize); let picture = test_card(width, height); for &q in &[15u8, 45, 100, 200] { - let encoded = encode_key_frame(&picture, q, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); let decoded = ffmpeg_decode(&encoded.stream, width, height); assert_eq!(decoded.y, encoded.reconstruction.y, "q={q}: luma"); assert_eq!(decoded.u, encoded.reconstruction.u, "q={q}: U"); @@ -3700,7 +3744,7 @@ mod tests { } let (width, height) = (64usize, 64usize); let picture = Picture::grey(width, height); - let key = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, _) = key_frame_headers(width, height, 100).unwrap(); let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap(); @@ -3829,7 +3873,7 @@ mod tests { (192, 120), ] { let picture = test_card(width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); assert_eq!( (encoded.reconstruction.width, encoded.reconstruction.height), (width, height), @@ -3883,7 +3927,7 @@ mod tests { } let (width, height) = (854usize, 480usize); let picture = test_card(width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let decoded = ffmpeg_decode(&encoded.stream, width, height); assert_eq!(decoded.y, encoded.reconstruction.y, "854x480: luma"); assert_eq!(decoded.u, encoded.reconstruction.u, "854x480: U"); @@ -4125,7 +4169,7 @@ mod tests { let fctx = &crate::decode::FrameCtx::new(); for &(width, height) in &[(1921usize, 1080usize), (1920, 1081), (63, 63)] { let picture = Picture::grey(width, height); - let err = encode_key_frame(&picture, 100, 0.5, fctx) + let err = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx) .expect_err(&format!("{width}x{height} is odd and must be refused")); assert!( err.to_string().contains("even"), @@ -4149,7 +4193,7 @@ mod tests { let pictures: Vec = (0..3) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), 3); for (i, frame) in encoded.frames.iter().enumerate() { assert_eq!( @@ -4192,7 +4236,7 @@ mod tests { let pictures: Vec = (0..3) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), 3); for (i, frame) in encoded.frames.iter().enumerate() { assert_eq!( @@ -4231,12 +4275,12 @@ mod tests { let fctx = &crate::decode::FrameCtx::new(); let (width, height) = (640usize, 360usize); let picture = Picture::grey(width, height); - encode_key_frame(&picture, 100, 0.5, fctx).expect("key frame now codes the mod-32==8 straddle"); + encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).expect("key frame now codes the mod-32==8 straddle"); // `encode_sequence`'s second frame is the inter path: same size, now // wired the same way. let pictures = vec![picture.clone(), picture]; - encode_sequence(&pictures, 100, 0.5, fctx) + encode_sequence_with_ctx(&pictures, 100, 0.5, fctx) .expect("inter frame now codes the mod-32==8 straddle too"); } @@ -4258,7 +4302,7 @@ mod tests { let (width, height) = (640usize, 360usize); for shift in [0i64, 7, 19] { let picture = panned_test_card(width, height, shift); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let decoded = ffmpeg_decode(&encoded.stream, width, height); assert_eq!(decoded.y, encoded.reconstruction.y, "shift {shift}: luma"); assert_eq!(decoded.u, encoded.reconstruction.u, "shift {shift}: U"); @@ -4283,7 +4327,7 @@ mod tests { let pictures: Vec = (0..4) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), 4); if let Ok(path) = std::env::var("EC_AV1_DUMP") { std::fs::write(&path, &encoded.stream).expect("dump the raw stream"); @@ -4472,7 +4516,7 @@ mod tests { for (width, height) in [(128, 96), (160, 96)] { let picture = test_card(width, height); for mode in KEY_FRAME_MODES { - let encoded = encode_key_frame_with_modes(&picture, 100, 0.5, &[mode], fctx).unwrap(); + let encoded = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[mode], fctx).unwrap(); let decoded = ffmpeg_decode(&encoded.stream, width, height); for (plane, ours, theirs, stride) in [ ("luma", &encoded.reconstruction.y, &decoded.y, width), @@ -4508,7 +4552,7 @@ mod tests { // tie then goes to whichever is cheaper to name, which is not what // this gate is about. let encoded = - encode_key_frame_with_modes(&picture, 100, 0.5, &[V_PRED, H_PRED], fctx).unwrap(); + encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[V_PRED, H_PRED], fctx).unwrap(); // The first block of the picture has neither neighbour, so it // cannot tell the modes apart; every other one can. let picked = encoded.modes[1..].iter().filter(|&&m| m == want).count(); @@ -4557,7 +4601,7 @@ mod tests { let mut points: Vec<(f64, f64)> = [110u8, 90, 70] .iter() .map(|&q| { - let encoded = encode_key_frame_with_modes(picture, q, 0.5, modes, fctx).unwrap(); + let encoded = encode_key_frame_with_modes_with_ctx(picture, q, 0.5, modes, fctx).unwrap(); ( psnr(&encoded.reconstruction.y, picture.y.as_slice()), (encoded.stream.len() as f64).log10(), @@ -4621,7 +4665,7 @@ mod tests { let dc = ladder(&picture, &[DC_PRED], fctx); let flat = ladder(&picture, &NON_DIRECTIONAL, fctx); let all = ladder(&picture, &KEY_FRAME_MODES, fctx); - let encoded = encode_key_frame(&picture, 90, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 90, 0.5, fctx).unwrap(); let directional = encoded .modes .iter() @@ -4666,7 +4710,7 @@ mod tests { /// The mode picked by the most blocks of a picture, ignoring the first /// block, which has no neighbours to tell the modes apart with. fn favourite_mode(picture: &Picture, fctx: &crate::decode::FrameCtx) -> (u8, usize, usize) { - let encoded = encode_key_frame(picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(picture, 100, 0.5, fctx).unwrap(); let blocks = &encoded.modes[1..]; let mut counts = [0usize; 13]; for &mode in blocks { @@ -4730,14 +4774,14 @@ mod tests { fn a_mode_the_encoder_cannot_predict_is_refused() { let fctx = &crate::decode::FrameCtx::new(); let picture = test_card(64, 64); - let message = encode_key_frame_with_modes(&picture, 100, 0.5, &[13], fctx) + let message = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[13], fctx) .unwrap_err() .to_string(); assert!( message.contains("intra mode 13"), "the refusal must name the mode, got {message}" ); - assert!(encode_key_frame_with_modes(&picture, 100, 0.5, &[], fctx).is_err()); + assert!(encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[], fctx).is_err()); } /// The picture that comes back is the picture that went in, to within the @@ -4749,7 +4793,7 @@ mod tests { fn the_encoded_picture_is_the_one_that_went_in() { let fctx = &crate::decode::FrameCtx::new(); let picture = test_card(160, 96); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let luma = psnr(&encoded.reconstruction.y, &picture.y); assert!(luma > 36.0, "luma PSNR {luma} at q 100"); for (plane, (got, want)) in [ @@ -4773,7 +4817,7 @@ mod tests { let picture = test_card(128, 128); let mut previous: Option<(usize, f64)> = None; for &q in &[70u8, 90, 110] { - let encoded = encode_key_frame(&picture, q, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); let quality = psnr(&encoded.reconstruction.y, &picture.y); if let Some((bytes, better)) = previous { assert!( @@ -4788,7 +4832,7 @@ mod tests { let mut previous = None; for &deadzone in &[0.5f64, 0.3, 0.15] { - let encoded = encode_key_frame(&picture, 100, deadzone, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, deadzone, fctx).unwrap(); let quality = psnr(&encoded.reconstruction.y, &picture.y); if let Some((bytes, better)) = previous { assert!( @@ -4806,8 +4850,8 @@ mod tests { // even though a coarser quantizer always codes no more than a finer // one on the same picture. for &(lo, hi) in &[(20u8, 21u8), (60, 61), (120, 121)] { - let lo_bytes = encode_key_frame(&picture, lo, 0.5, fctx).unwrap().stream.len(); - let hi_bytes = encode_key_frame(&picture, hi, 0.5, fctx).unwrap().stream.len(); + let lo_bytes = encode_key_frame_with_ctx(&picture, lo, 0.5, fctx).unwrap().stream.len(); + let hi_bytes = encode_key_frame_with_ctx(&picture, hi, 0.5, fctx).unwrap().stream.len(); assert!( hi_bytes <= lo_bytes, "q {lo}->{hi} crosses a context boundary: {lo_bytes} -> {hi_bytes} bytes" @@ -4822,7 +4866,7 @@ mod tests { let fctx = &crate::decode::FrameCtx::new(); let mut picture = Picture::grey(128, 128); picture.y.fill(97); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); // The first block has no neighbour and predicts 128, so it carries a // DC; every block after it predicts 97 and carries nothing. assert!( @@ -4850,14 +4894,14 @@ mod tests { #[test] fn a_picture_off_the_block_grid_is_refused() { let fctx = &crate::decode::FrameCtx::new(); - let msg = encode_key_frame(&Picture::grey(40, 40), 100, 0.5, fctx) + let msg = encode_key_frame_with_ctx(&Picture::grey(40, 40), 100, 0.5, fctx) .expect_err("40x40 straddles both axes of a 16x16 leaf, needs a rectangular transform") .to_string(); assert!(msg.contains("rectangular"), "refusal: {msg}"); let mut short = Picture::grey(64, 64); short.u.truncate(10); - assert!(encode_key_frame(&short, 100, 0.5, fctx).is_err()); + assert!(encode_key_frame_with_ctx(&short, 100, 0.5, fctx).is_err()); } /// 40x32: cols mod 32 == 8, so the true edge cuts a 16x16 leaf's own @@ -4939,7 +4983,7 @@ mod tests { } let (width, height) = (40usize, 32usize); let picture = test_card(width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); assert_eq!( (encoded.reconstruction.width, encoded.reconstruction.height), (width, height) @@ -4981,7 +5025,7 @@ mod tests { let (width, height) = (640usize, 352usize); let picture = clip_frame(&clip, &skip, width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let decoded = ffmpeg_decode(&encoded.stream, width, height); assert_eq!(decoded.y, encoded.reconstruction.y, "luma"); assert_eq!(decoded.u, encoded.reconstruction.u, "U"); @@ -5103,7 +5147,7 @@ mod tests { let pictures: Vec = (0..5) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), 5); let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 5); @@ -5138,7 +5182,7 @@ mod tests { let pictures: Vec = (0..5) .map(|i| panned_test_card(width, height, i * 2)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); let key_bytes = encoded.frames[0].stream.len(); eprintln!("frame bytes inter share"); @@ -5177,16 +5221,16 @@ mod tests { let picture = test_card(width, height); let t = Instant::now(); - let dc_only = encode_key_frame_with_modes(&picture, 100, 0.5, &[DC_PRED], fctx).unwrap(); + let dc_only = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[DC_PRED], fctx).unwrap(); let dc_only_t = t.elapsed(); let t = Instant::now(); let non_directional = - encode_key_frame_with_modes(&picture, 100, 0.5, &NON_DIRECTIONAL, fctx).unwrap(); + encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &NON_DIRECTIONAL, fctx).unwrap(); let non_directional_t = t.elapsed(); let t = Instant::now(); - let all_modes = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let all_modes = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let all_modes_t = t.elapsed(); eprintln!( @@ -5297,7 +5341,7 @@ mod tests { let (width, height) = (1280usize, 720); let picture = test_card(width, height); - let key = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let padded_ref = key.reconstruction.padded_to(SUPERBLOCK); let padded_pic = picture.padded_to(SUPERBLOCK); @@ -5376,7 +5420,7 @@ mod tests { // a single-threaded #[ignore] probe, run by hand, never // alongside other tests that read Search::top_k. set_test_top_k_override(None); - let baseline = encode_key_frame(&picture, q, 0.5, fctx).unwrap(); + let baseline = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); let baseline_psnr = psnr(&baseline.reconstruction.y, &picture.y); eprint!( "{label:9} q={q:3} baseline {:6} bytes {:6.2} dB", @@ -5385,7 +5429,7 @@ mod tests { ); for &k in &[3usize, 4, 6] { set_test_top_k_override(Some(k)); - let pruned = encode_key_frame(&picture, q, 0.5, fctx).unwrap(); + let pruned = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); let pruned_psnr = psnr(&pruned.reconstruction.y, &picture.y); eprint!( " K={k} {:6} bytes {:6.2} dB ({:+.3} dB)", @@ -5474,7 +5518,7 @@ mod tests { // single-threaded #[ignore] probe, run by hand, never // alongside other tests that read Search::top_k. set_test_top_k_override_inter(None); - let key = encode_key_frame(&key_source, q, 0.5, fctx).unwrap(); + let key = encode_key_frame_with_ctx(&key_source, q, 0.5, fctx).unwrap(); let baseline = encode_inter_frame( &inter_source, &key.reconstruction, @@ -5594,7 +5638,7 @@ mod tests { } let (width, height, frame_count) = (640usize, 384usize, 12usize); let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count); - let encoded = encode_sequence(&source, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), frame_count); // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole @@ -5659,7 +5703,7 @@ mod tests { } let (width, height, frame_count) = (704usize, 400usize, 8usize); let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count); - let encoded = encode_sequence(&source, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap(); assert_eq!(encoded.frames.len(), frame_count); // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole @@ -5703,7 +5747,7 @@ mod tests { .map(|i| panned_test_card(width, height, i * 3)) .collect(); let t = Instant::now(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); let elapsed = t.elapsed(); let total_bytes: usize = encoded.frames.iter().map(|f| f.stream.len()).sum(); eprintln!( @@ -5739,7 +5783,7 @@ mod tests { let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames); eprintln!("--- {clip} ---"); for q in [40u8, 70, 100, 130, 160, 190, 220, 240] { - let encoded = encode_sequence(&source, q, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&source, q, 0.5, fctx).unwrap(); let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frames); let mean_psnr: f64 = decoded .iter() diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index a852215b..bd8943d6 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -221,8 +221,21 @@ pub struct Av1Encoder { /// otherwise every picture is coded at `config.base_q_idx`, unchanged /// from before this field existed. rate_loop: Option, + /// This stream's decode-side per-frame state, owned here so `encode` + /// keeps the public signature it had before the state stopped being + /// thread-local. One per encoder, never per frame: several of its fields + /// (the inter-frame inheritance guards) carry state ACROSS frames. + fctx: crate::decode::FrameCtx, } +/// The encoder stays `Send` now that it owns a `FrameCtx` (whose cells are +/// `Send` but `!Sync`): it can move to another thread, it just cannot be +/// shared by reference across threads. +const _: fn() = || { + fn assert_send() {} + assert_send::(); +}; + impl Av1Encoder { /// # Errors /// Returns an error when `config.width`/`config.height` are zero, odd, @@ -243,6 +256,7 @@ impl Av1Encoder { reference: None, next_index: 0, rate_loop: None, + fctx: crate::decode::FrameCtx::new(), }) } @@ -297,7 +311,7 @@ impl Av1Encoder { /// [`EncoderConfig::width`]/[`EncoderConfig::height`], or under the same /// conditions [`crate::encode::encode_key_frame`]/ /// [`crate::encode::encode_sequence`] do. - pub fn encode(&mut self, picture: &Picture, fctx: &crate::decode::FrameCtx) -> Result { + pub fn encode(&mut self, picture: &Picture) -> Result { if (picture.width, picture.height) != (self.config.width, self.config.height) { return Err(Error::unsupported( "AV1 encode", @@ -324,7 +338,8 @@ impl Av1Encoder { &KEY_FRAME_MODES, split_blocks(), render, - self.color_config, fctx, + self.color_config, + &self.fctx, )? } else { let reference = self.reference.as_ref().ok_or_else(|| { @@ -339,7 +354,8 @@ impl Av1Encoder { base_q_idx, DEADZONE, order as u32, - render, fctx, + render, + &self.fctx, )? }; @@ -414,7 +430,6 @@ mod tests { /// ffmpeg since it is a property of the return type, not the bytes. #[test] fn one_in_one_out() { - let fctx = &crate::decode::FrameCtx::new(); let config = EncoderConfig { width: 64, height: 64, @@ -424,7 +439,7 @@ mod tests { }; let mut enc = Av1Encoder::new(config).unwrap(); for t in 0..5u64 { - let packet = enc.encode(&test_card(64, 64, t as usize), fctx).unwrap(); + let packet = enc.encode(&test_card(64, 64, t as usize)).unwrap(); assert!(!packet.data.is_empty(), "picture {t}: empty packet"); assert_eq!(packet.order, t, "picture {t}: order"); } @@ -435,7 +450,6 @@ mod tests { /// reads back out of the coded bytes. #[test] fn gop_cadence_is_honored() { - let fctx = &crate::decode::FrameCtx::new(); let config = EncoderConfig { width: 64, height: 64, @@ -445,7 +459,7 @@ mod tests { }; let mut enc = Av1Encoder::new(config).unwrap(); let keys: Vec = (0..7) - .map(|t| enc.encode(&test_card(64, 64, t), fctx).unwrap().key) + .map(|t| enc.encode(&test_card(64, 64, t)).unwrap().key) .collect(); assert_eq!(keys, vec![true, false, false, true, false, false, true]); } @@ -529,7 +543,6 @@ mod tests { /// coded size confirm what the facade already reported. #[test] fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() { - let fctx = &crate::decode::FrameCtx::new(); if !have_ffmpeg() { eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg"); return; @@ -554,7 +567,7 @@ mod tests { ); let packets: Vec = (0..30) - .map(|t| enc.encode(&test_card(width, height, t), fctx).unwrap()) + .map(|t| enc.encode(&test_card(width, height, t)).unwrap()) .collect(); let expect_key: Vec = (0..30).map(|t| t % 15 == 0).collect(); assert_eq!( @@ -584,7 +597,6 @@ mod tests { /// which is a visibly different string). #[test] fn bt709_limited_colour_is_reported_by_ffprobe() { - let fctx = &crate::decode::FrameCtx::new(); if !have_ffmpeg() { eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg"); return; @@ -597,7 +609,7 @@ mod tests { colour: Colour::Bt709Limited, }; let mut enc = Av1Encoder::new(config).unwrap(); - let packet = enc.encode(&test_card(64, 64, 0), fctx).unwrap(); + let packet = enc.encode(&test_card(64, 64, 0)).unwrap(); let colour = ffprobe_colour(&packet.data); assert_eq!(colour, "tv,bt709,bt709,bt709", "ffprobe colour fields"); } @@ -607,7 +619,6 @@ mod tests { /// as BT.709 for every input. #[test] fn bt601_limited_colour_is_reported_by_ffprobe() { - let fctx = &crate::decode::FrameCtx::new(); if !have_ffmpeg() { eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg"); return; @@ -620,7 +631,7 @@ mod tests { colour: Colour::Bt601Limited, }; let mut enc = Av1Encoder::new(config).unwrap(); - let packet = enc.encode(&test_card(64, 64, 0), fctx).unwrap(); + let packet = enc.encode(&test_card(64, 64, 0)).unwrap(); let colour = ffprobe_colour(&packet.data); assert_eq!( colour, "tv,smpte170m,smpte170m,smpte170m", @@ -632,7 +643,6 @@ mod tests { /// is refused by name. #[test] fn geometry_mismatch_is_refused() { - let fctx = &crate::decode::FrameCtx::new(); let config = EncoderConfig { width: 64, height: 64, @@ -641,7 +651,7 @@ mod tests { colour: Colour::Bt709Limited, }; let mut enc = Av1Encoder::new(config).unwrap(); - let err = enc.encode(&Picture::grey(32, 32), fctx).unwrap_err(); + let err = enc.encode(&Picture::grey(32, 32)).unwrap_err(); assert!(err.to_string().contains("64x64"), "{err}"); } @@ -714,7 +724,6 @@ mod tests { /// state and the controller's first couple of steps). #[test] fn bytes_per_frame_target_settles_within_20_percent() { - let fctx = &crate::decode::FrameCtx::new(); let Some(pictures) = h264_clip_frames(640, 384, 24) else { eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture"); return; @@ -731,7 +740,7 @@ mod tests { Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(target_bytes)).unwrap(); let sizes: Vec = pictures .iter() - .map(|p| enc.encode(p, fctx).unwrap().data.len()) + .map(|p| enc.encode(p).unwrap().data.len()) .collect(); // Discard the key frame (always far larger than an inter target) and // the next 4 inter frames the loop needs to step toward it. @@ -751,7 +760,6 @@ mod tests { /// that breaks the bound). #[test] fn bytes_per_frame_controller_never_oscillates_past_its_clamp() { - let fctx = &crate::decode::FrameCtx::new(); let Some(pictures) = h264_clip_frames(640, 384, 24) else { eprintln!( "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture" @@ -769,7 +777,7 @@ mod tests { Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(4_000)).unwrap(); let mut prev_q = enc.rate_loop.as_ref().unwrap().q_idx(); for picture in &pictures { - enc.encode(picture, fctx).unwrap(); + enc.encode(picture).unwrap(); let q = enc.rate_loop.as_ref().unwrap().q_idx(); let step = (i32::from(q) - i32::from(prev_q)).abs(); assert!( @@ -832,7 +840,6 @@ mod tests { /// the same real clip. #[test] fn quality_target_is_monotone_in_bytes_and_psnr() { - let fctx = &crate::decode::FrameCtx::new(); if !have_ffmpeg() { eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg"); return; @@ -857,7 +864,7 @@ mod tests { let mut stream = Vec::new(); let mut total_bytes = 0usize; for picture in &pictures { - let packet = enc.encode(picture, fctx).unwrap(); + let packet = enc.encode(picture).unwrap(); total_bytes += packet.data.len(); stream.extend_from_slice(&packet.data); } diff --git a/crates/ec-av1/src/intra.rs b/crates/ec-av1/src/intra.rs index f202758d..c759208c 100644 --- a/crates/ec-av1/src/intra.rs +++ b/crates/ec-av1/src/intra.rs @@ -262,7 +262,7 @@ pub(crate) fn intra_edge_filter_hits() -> usize { } #[allow(clippy::too_many_arguments)] -pub fn predict( +pub(crate) fn predict( mode: u8, angle_delta: i32, above: Option<&[u16]>, @@ -772,7 +772,7 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4; /// Panics when `dst` is not `bw * bh` long, or `bw` is not a multiple of 4 /// or `bh` not a multiple of 2 (spec `av1_filter_intra_allowed_bsize` never /// offers this mode past 32x32). -pub fn predict_filter_intra( +pub(crate) fn predict_filter_intra( mode: usize, above: Option<&[u16]>, left: Option<&[u16]>, diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index 5b4f7b8a..b9168834 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -663,7 +663,7 @@ fn with_scratch(rows: usize, block_w: usize, f: impl FnOnce(&mut [i32], &mut /// Panics when `dst` is not `block_w * block_h` long, or the reference is /// empty. #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape -pub fn predict( +pub(crate) fn predict( reference: &[u16], stride: usize, true_width: usize, @@ -692,7 +692,7 @@ pub fn predict( /// 6.8.9's `interpolation_filter`) instead of always `Regular` -- the same /// kernel both directions. #[allow(clippy::too_many_arguments)] -pub fn predict_with_filter( +pub(crate) fn predict_with_filter( reference: &[u16], stride: usize, true_width: usize, @@ -724,7 +724,7 @@ pub fn predict_with_filter( /// 5.11.20's per-block `SWITCHABLE` read is per-direction (`enable_dual_filter`), /// so the two passes can genuinely differ. #[allow(clippy::too_many_arguments)] -pub fn predict_with_filters( +pub(crate) fn predict_with_filters( reference: &[u16], stride: usize, true_width: usize, @@ -752,7 +752,7 @@ pub fn predict_with_filters( /// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask /// for the 4-tap kernel on that axis -- lane-rectchroma2 r1. #[allow(clippy::too_many_arguments)] -pub fn predict_with_filters_kern( +pub(crate) fn predict_with_filters_kern( reference: &[u16], stride: usize, true_width: usize, @@ -1070,7 +1070,7 @@ fn horizontal_pass( /// Panics when `dst` is not `block_w * block_h` long, or the reference is /// empty. #[allow(clippy::too_many_arguments)] -pub fn predict_scaled( +pub(crate) fn predict_scaled( reference: &[u16], stride: usize, true_width: usize, @@ -1093,7 +1093,7 @@ pub fn predict_scaled( /// [`predict_scaled`] with the 4-tap decision from the block's true dims /// (see [`predict_with_filters_kern`]). #[allow(clippy::too_many_arguments)] -pub fn predict_scaled_kern( +pub(crate) fn predict_scaled_kern( reference: &[u16], stride: usize, true_width: usize, @@ -1156,7 +1156,7 @@ pub fn predict_scaled_kern( /// scaled (superres). `REF_NO_SCALE` takes the ordinary stride-1 path, which /// keeps [`predict_scaled_hits`] a true count of scaled predictions. #[allow(clippy::too_many_arguments)] -pub fn predict_maybe_scaled( +pub(crate) fn predict_maybe_scaled( reference: &[u16], stride: usize, true_width: usize, @@ -1305,7 +1305,7 @@ pub fn predict_compound_intermediate_kern( /// output; both always sum to `1 << DIST_PRECISION_BITS`). Masked compound /// (`comp_group_idx == 1`, wedge/diffwtd) is a different combine this /// function does not cover -- decode.rs still refuses those by name. -pub fn combine_compound( +pub(crate) fn combine_compound( pred0: &[i32], pred1: &[i32], fwd_weight: i32, @@ -1338,7 +1338,7 @@ pub fn combine_compound( /// produces give the identical `diff` libaom computes. `round` is /// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for /// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`). -pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8], fctx: &crate::decode::FrameCtx) { +pub(crate) fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8], fctx: &crate::decode::FrameCtx) { assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block"); assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel"); // libaom `diffwtd_mask_d16` (`reconinter.c:307`): `round = 2*FILTER_BITS @@ -1365,7 +1365,7 @@ pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8], fc /// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 / /// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read. #[allow(clippy::too_many_arguments)] -pub fn blend_masked_compound( +pub(crate) fn blend_masked_compound( pred0: &[i32], pred1: &[i32], mask: &[u8], diff --git a/crates/ec-av1/src/motion.rs b/crates/ec-av1/src/motion.rs index f5695f72..5f2b586f 100644 --- a/crates/ec-av1/src/motion.rs +++ b/crates/ec-av1/src/motion.rs @@ -189,7 +189,7 @@ pub struct MotionSearch { /// Panics when `source` is not `block_w * block_h` long, or `reference` is /// empty (the same contracts [`predict`] has). #[allow(clippy::too_many_arguments)] // one reference plane, one block, one predictor -pub fn search( +pub(crate) fn search( reference: &[u8], stride: usize, ref_width: usize, diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 38d2f3b0..b2e39d43 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -1070,7 +1070,7 @@ pub fn intra_rect4_in_inter_counters() -> (usize, usize, usize, usize) { #[cfg(test)] mod tests { use super::*; - use crate::encode::{Picture as Pic, encode_key_frame, encode_sequence}; + use crate::encode::{Picture as Pic, encode_key_frame_with_ctx, encode_sequence_with_ctx}; fn test_card(width: usize, height: usize) -> Pic { let mut picture = Pic::grey(width, height); @@ -1119,7 +1119,7 @@ mod tests { fn a_twelve_bit_sequence_header_is_refused_by_name() { let fctx = &crate::decode::FrameCtx::new(); let picture = test_card(64, 64); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let mut color = ec_av1_syntax::ColorConfig { bit_depth: 12, ..Default::default() @@ -1164,7 +1164,7 @@ mod tests { let fctx = &crate::decode::FrameCtx::new(); const REFUSAL: &str = "a frame OBU with no tile group"; let picture = test_card(64, 64); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, header) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); let mut frame_obus_parsed = 0; for len in 0..=encoded.tile.len().min(24) { @@ -1221,7 +1221,7 @@ mod tests { const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV"; let picture = test_card(64, 64); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); for feature in [SEG_LVL_REF_FRAME, SEG_LVL_SKIP, SEG_LVL_GLOBALMV] { for segment in [0usize, 3, 7] { @@ -1612,7 +1612,7 @@ mod tests { let fctx = &crate::decode::FrameCtx::new(); const REFUSAL: &str = "an inter frame with no key frame before it"; let picture = test_card(64, 64); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); let inter = FrameHeader { frame_type: FrameType::Inter, @@ -1659,7 +1659,7 @@ mod tests { const REFUSAL: &str = "a reference picture whose height does not match this frame's own true size"; let picture = test_card(64, 64); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); let inter = FrameHeader { frame_type: FrameType::Inter, @@ -1736,7 +1736,7 @@ mod tests { } let picture = test_card(64, 64); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap(); for slot in 0..NUM_REF_FRAMES as u8 { let inter = FrameHeader { @@ -2142,7 +2142,7 @@ mod tests { let fctx = &crate::decode::FrameCtx::new(); for &(width, height) in &[(64usize, 64usize), (216, 96)] { let picture = test_card(width, height); - let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap(); + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); let via_tile = decode_key_frame_tile( &encoded.tile, encoded.mi_cols, @@ -2179,7 +2179,7 @@ mod tests { let pictures: Vec<_> = (0..4) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); let decoded = decode_stream(&encoded.stream).unwrap(); assert_eq!(decoded.len(), encoded.frames.len()); for (i, (got, frame)) in decoded.iter().zip(&encoded.frames).enumerate() { @@ -2222,7 +2222,7 @@ mod tests { fn streaming_decode_matches_the_collecting_one() { let fctx = &crate::decode::FrameCtx::new(); let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect(); - let stream = encode_sequence(&pictures, 100, 0.5, fctx).unwrap().stream; + let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap().stream; let collected = decode_stream(&stream).unwrap(); let mut shown = Vec::new(); @@ -2466,7 +2466,7 @@ mod tests { let pictures: Vec<_> = (0..3) .map(|i| panned_test_card(width, height, i * 3)) .collect(); - let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, 3); let decoded = decode_stream(&encoded.stream).unwrap(); assert_eq!(decoded.len(), 3); @@ -2541,7 +2541,7 @@ mod tests { for run in 0..4 { let picture = test_card(width, height); - let key = encode_key_frame(&picture, base_q_idx, 0.5, fctx).unwrap(); + let key = encode_key_frame_with_ctx(&picture, base_q_idx, 0.5, fctx).unwrap(); let (seq, _) = key_frame_headers(width, height, base_q_idx).unwrap(); // Frame 1: hand-coded, intra-only, refreshes slot 0 with a flat diff --git a/crates/ec-av1/src/warp.rs b/crates/ec-av1/src/warp.rs index f6a96edd..b93dc8fe 100644 --- a/crates/ec-av1/src/warp.rs +++ b/crates/ec-av1/src/warp.rs @@ -429,7 +429,7 @@ fn clip_pixel(v: i32, fctx: &crate::decode::FrameCtx) -> u16 { /// the stream (`crate::decode::bit_depth`), the same thread-local /// [`clip_pixel`] already clamps against -- libaom's `bd` parameter. #[allow(clippy::too_many_arguments)] -pub fn warp_affine( +pub(crate) fn warp_affine( params: &WarpParams, reference: &[u16], width: i32, @@ -477,7 +477,7 @@ pub fn warp_affine( /// [`mc::predict_compound_intermediate`]'s for /// [`mc::combine_compound`]/[`mc::blend_masked_compound`]. #[allow(clippy::too_many_arguments)] -pub fn warp_affine_compound( +pub(crate) fn warp_affine_compound( params: &WarpParams, reference: &[u16], width: i32,