forge
Explore
Log in

Don't you dare go Hollow

FrameCtx stays crate-private -- public signatures back to what they were

Browse files at this commit

1c71b70ba5f3e4b7a8b25ba24f66db55673374a8Ahmet Kaan GümüşParent: 4c4f667
  • refactor
    • FrameCtx stays crate-private -- public signatures back to what they were
Show full message
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.rsmodified+14 -8
@@ -81,6 +81,12 @@ pub(crate) struct FrameCtx {
81 pub(crate) grain_bit_depth: std::cell::Cell<u32>,81 pub(crate) grain_bit_depth: std::cell::Cell<u32>,
82 }82 }
83 83
84+impl std::fmt::Debug for FrameCtx {
85+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86+ f.write_str("FrameCtx")
87+ }
88+}
89+
84 impl FrameCtx {90 impl FrameCtx {
85 /// A fresh context, every field at the default its thread-local91 /// A fresh context, every field at the default its thread-local
86 /// predecessor was born with.92 /// predecessor was born with.
@@ -17535,7 +17541,7 @@ fn apply_loop_restoration(
17535 /// 16x16, a directional mode's angle delta other than zero, chroma-from-luma),17541 /// 16x16, a directional mode's angle delta other than zero, chroma-from-luma),
17536 /// or when the tile payload runs out of the symbols this decode expects (a17542 /// or when the tile payload runs out of the symbols this decode expects (a
17537 /// genuinely foreign stream).17543 /// genuinely foreign stream).
17538-pub fn decode_key_frame_tile(17544+pub(crate) fn decode_key_frame_tile(
17539 data: &[u8],17545 data: &[u8],
17540 mi_cols: u32,17546 mi_cols: u32,
17541 mi_rows: u32,17547 mi_rows: u32,
@@ -32762,7 +32768,7 @@ mod tests {
32762 mi_rows,32768 mi_rows,
32763 base_q_idx,32769 base_q_idx,
32764 ..32770 ..
32765- }: Encoded = crate::encode::encode_key_frame_with_modes(&picture, 40, 0.0, modes, fctx).unwrap();32771+ }: Encoded = crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx).unwrap();
32766 let decoded = decode_key_frame_tile(32772 let decoded = decode_key_frame_tile(
32767 &tile,32773 &tile,
32768 mi_cols,32774 mi_cols,
@@ -33117,10 +33123,10 @@ mod tests {
33117 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg");33123 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_key_frame: no ffmpeg");
33118 return;33124 return;
33119 }33125 }
33120- use crate::encode::encode_key_frame;33126+ use crate::encode::encode_key_frame_with_ctx;
33121 for &(width, height) in &[(64usize, 64usize), (216, 96), (40, 32)] {33127 for &(width, height) in &[(64usize, 64usize), (216, 96), (40, 32)] {
33122 let picture = round_trip_test_card(width, height);33128 let picture = round_trip_test_card(width, height);
33123- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();33129+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
33124 let (coded_w, coded_h) = ffprobe_size(&encoded.stream);33130 let (coded_w, coded_h) = ffprobe_size(&encoded.stream);
33125 let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize);33131 let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize);
33126 let ours = decode_key_frame_tile(33132 let ours = decode_key_frame_tile(
@@ -33189,11 +33195,11 @@ mod tests {
33189 /// into the next as its reference -- exactly the single-slot DPB33195 /// into the next as its reference -- exactly the single-slot DPB
33190 /// [`crate::encode::encode_sequence`] itself threads.33196 /// [`crate::encode::encode_sequence`] itself threads.
33191 fn gop_round_trips(width: usize, height: usize, fctx: &crate::decode::FrameCtx) {33197 fn gop_round_trips(width: usize, height: usize, fctx: &crate::decode::FrameCtx) {
33192- use crate::encode::encode_sequence;33198+ use crate::encode::encode_sequence_with_ctx;
33193 let pictures: Vec<_> = (0..4)33199 let pictures: Vec<_> = (0..4)
33194 .map(|i| panned_test_card(width, height, i * 3))33200 .map(|i| panned_test_card(width, height, i * 3))
33195 .collect();33201 .collect();
33196- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();33202+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
33197 assert_eq!(encoded.frames.len(), 4);33203 assert_eq!(encoded.frames.len(), 4);
33198 33204
33199 let key = &encoded.frames[0];33205 let key = &encoded.frames[0];
@@ -33520,12 +33526,12 @@ mod tests {
33520 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg");33526 eprintln!("SKIP ffmpeg_and_this_decoder_agree_on_a_gop: no ffmpeg");
33521 return;33527 return;
33522 }33528 }
33523- use crate::encode::encode_sequence;33529+ use crate::encode::encode_sequence_with_ctx;
33524 let (width, height) = (128usize, 64usize);33530 let (width, height) = (128usize, 64usize);
33525 let pictures: Vec<_> = (0..3)33531 let pictures: Vec<_> = (0..3)
33526 .map(|i| panned_test_card(width, height, i * 3))33532 .map(|i| panned_test_card(width, height, i * 3))
33527 .collect();33533 .collect();
33528- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();33534+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
33529 let (coded_w, coded_h) = ffprobe_size(&encoded.stream);33535 let (coded_w, coded_h) = ffprobe_size(&encoded.stream);
33530 let ffmpeg_frames =33536 let ffmpeg_frames =
33531 ffmpeg_decode_sequence(&encoded.stream, coded_w as usize, coded_h as usize, 3);33537 ffmpeg_decode_sequence(&encoded.stream, coded_w as usize, coded_h as usize, 3);
crates/ec-av1/src/encode.rsmodified+90 -46
@@ -1995,8 +1995,52 @@ fn coeffs(levels: &[i32], side: usize) -> Vec<Coeff> {
1995 /// # Errors1995 /// # Errors
1996 /// Returns an error when the picture's width or height is zero or odd, or1996 /// Returns an error when the picture's width or height is zero or odd, or
1997 /// when its planes are not 4:2:0 of that size.1997 /// when its planes are not 4:2:0 of that size.
1998-pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx) -> Result<Encoded> {1998+/// Codes one picture as a whole key frame, at `base_q_idx`, and returns its
1999- encode_key_frame_with_modes(picture, base_q_idx, deadzone, &KEY_FRAME_MODES, fctx)1999+/// stream. The per-frame decode state this needs lives for exactly this call.
2000+///
2001+/// # Errors
2002+/// Returns an error under the same conditions
2003+/// [`encode_key_frame_with_modes`] does.
2004+pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64) -> Result<Encoded> {
2005+ encode_key_frame_with_ctx(picture, base_q_idx, deadzone, &crate::decode::FrameCtx::new())
2006+}
2007+
2008+/// [`encode_key_frame`] with the per-block intra modes given rather than
2009+/// searched.
2010+///
2011+/// # Errors
2012+/// Returns an error when `picture`'s dimensions are odd or zero, when `modes`
2013+/// is empty, or when a block's coefficients do not fit the coded frame.
2014+pub fn encode_key_frame_with_modes(
2015+ picture: &Picture,
2016+ base_q_idx: u8,
2017+ deadzone: f64,
2018+ modes: &[u8],
2019+) -> Result<Encoded> {
2020+ encode_key_frame_with_modes_with_ctx(
2021+ picture,
2022+ base_q_idx,
2023+ deadzone,
2024+ modes,
2025+ &crate::decode::FrameCtx::new(),
2026+ )
2027+}
2028+
2029+/// Codes `pictures` as one key frame followed by inter frames.
2030+///
2031+/// # Errors
2032+/// Returns an error under the same conditions [`encode_key_frame`] and the
2033+/// inter frame path do.
2034+pub fn encode_sequence(
2035+ pictures: &[Picture],
2036+ base_q_idx: u8,
2037+ deadzone: f64,
2038+) -> Result<EncodedSequence> {
2039+ encode_sequence_with_ctx(pictures, base_q_idx, deadzone, &crate::decode::FrameCtx::new())
2040+}
2041+
2042+pub(crate) fn encode_key_frame_with_ctx(picture: &Picture, base_q_idx: u8, deadzone: f64, fctx: &crate::decode::FrameCtx) -> Result<Encoded> {
2043+ encode_key_frame_with_modes_with_ctx(picture, base_q_idx, deadzone, &KEY_FRAME_MODES, fctx)
2000 }2044 }
2001 2045
2002 /// Encodes one picture as a key frame, choosing each block's luma mode from2046 /// 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:
2010 /// # Errors2054 /// # Errors
2011 /// The same as [`encode_key_frame`], and additionally when `modes` is empty or2055 /// The same as [`encode_key_frame`], and additionally when `modes` is empty or
2012 /// names a mode [`crate::intra::predict`] does not predict.2056 /// names a mode [`crate::intra::predict`] does not predict.
2013-pub fn encode_key_frame_with_modes(2057+pub(crate) fn encode_key_frame_with_modes_with_ctx(
2014 picture: &Picture,2058 picture: &Picture,
2015 base_q_idx: u8,2059 base_q_idx: u8,
2016 deadzone: f64,2060 deadzone: f64,
@@ -3314,7 +3358,7 @@ pub struct EncodedSequence {
3314 /// Returns an error when `pictures` is empty, when any picture besides the3358 /// Returns an error when `pictures` is empty, when any picture besides the
3315 /// first is not the same size as the first, or under the same conditions3359 /// first is not the same size as the first, or under the same conditions
3316 /// [`encode_key_frame`] and the inter frame path do.3360 /// [`encode_key_frame`] and the inter frame path do.
3317-pub fn encode_sequence(3361+pub(crate) fn encode_sequence_with_ctx(
3318 pictures: &[Picture],3362 pictures: &[Picture],
3319 base_q_idx: u8,3363 base_q_idx: u8,
3320 deadzone: f64, fctx: &crate::decode::FrameCtx,3364 deadzone: f64, fctx: &crate::decode::FrameCtx,
@@ -3659,7 +3703,7 @@ mod tests {
3659 }3703 }
3660 for &(width, height) in &[(64usize, 64usize), (96, 64), (160, 96), (32, 48)] {3704 for &(width, height) in &[(64usize, 64usize), (96, 64), (160, 96), (32, 48)] {
3661 let picture = test_card(width, height);3705 let picture = test_card(width, height);
3662- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();3706+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
3663 let decoded = ffmpeg_decode(&encoded.stream, width, height);3707 let decoded = ffmpeg_decode(&encoded.stream, width, height);
3664 assert_eq!(3708 assert_eq!(
3665 decoded.y, encoded.reconstruction.y,3709 decoded.y, encoded.reconstruction.y,
@@ -3673,7 +3717,7 @@ mod tests {
3673 let (width, height) = (64usize, 64usize);3717 let (width, height) = (64usize, 64usize);
3674 let picture = test_card(width, height);3718 let picture = test_card(width, height);
3675 for &q in &[15u8, 45, 100, 200] {3719 for &q in &[15u8, 45, 100, 200] {
3676- let encoded = encode_key_frame(&picture, q, 0.5, fctx).unwrap();3720+ let encoded = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap();
3677 let decoded = ffmpeg_decode(&encoded.stream, width, height);3721 let decoded = ffmpeg_decode(&encoded.stream, width, height);
3678 assert_eq!(decoded.y, encoded.reconstruction.y, "q={q}: luma");3722 assert_eq!(decoded.y, encoded.reconstruction.y, "q={q}: luma");
3679 assert_eq!(decoded.u, encoded.reconstruction.u, "q={q}: U");3723 assert_eq!(decoded.u, encoded.reconstruction.u, "q={q}: U");
@@ -3700,7 +3744,7 @@ mod tests {
3700 }3744 }
3701 let (width, height) = (64usize, 64usize);3745 let (width, height) = (64usize, 64usize);
3702 let picture = Picture::grey(width, height);3746 let picture = Picture::grey(width, height);
3703- let key = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();3747+ let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
3704 3748
3705 let (seq, _) = key_frame_headers(width, height, 100).unwrap();3749 let (seq, _) = key_frame_headers(width, height, 100).unwrap();
3706 let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap();3750 let (_, inter_header) = inter_frame_headers(width, height, 100, 1, 0).unwrap();
@@ -3829,7 +3873,7 @@ mod tests {
3829 (192, 120),3873 (192, 120),
3830 ] {3874 ] {
3831 let picture = test_card(width, height);3875 let picture = test_card(width, height);
3832- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();3876+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
3833 assert_eq!(3877 assert_eq!(
3834 (encoded.reconstruction.width, encoded.reconstruction.height),3878 (encoded.reconstruction.width, encoded.reconstruction.height),
3835 (width, height),3879 (width, height),
@@ -3883,7 +3927,7 @@ mod tests {
3883 }3927 }
3884 let (width, height) = (854usize, 480usize);3928 let (width, height) = (854usize, 480usize);
3885 let picture = test_card(width, height);3929 let picture = test_card(width, height);
3886- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();3930+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
3887 let decoded = ffmpeg_decode(&encoded.stream, width, height);3931 let decoded = ffmpeg_decode(&encoded.stream, width, height);
3888 assert_eq!(decoded.y, encoded.reconstruction.y, "854x480: luma");3932 assert_eq!(decoded.y, encoded.reconstruction.y, "854x480: luma");
3889 assert_eq!(decoded.u, encoded.reconstruction.u, "854x480: U");3933 assert_eq!(decoded.u, encoded.reconstruction.u, "854x480: U");
@@ -4125,7 +4169,7 @@ mod tests {
4125 let fctx = &crate::decode::FrameCtx::new();4169 let fctx = &crate::decode::FrameCtx::new();
4126 for &(width, height) in &[(1921usize, 1080usize), (1920, 1081), (63, 63)] {4170 for &(width, height) in &[(1921usize, 1080usize), (1920, 1081), (63, 63)] {
4127 let picture = Picture::grey(width, height);4171 let picture = Picture::grey(width, height);
4128- let err = encode_key_frame(&picture, 100, 0.5, fctx)4172+ let err = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx)
4129 .expect_err(&format!("{width}x{height} is odd and must be refused"));4173 .expect_err(&format!("{width}x{height} is odd and must be refused"));
4130 assert!(4174 assert!(
4131 err.to_string().contains("even"),4175 err.to_string().contains("even"),
@@ -4149,7 +4193,7 @@ mod tests {
4149 let pictures: Vec<Picture> = (0..3)4193 let pictures: Vec<Picture> = (0..3)
4150 .map(|i| panned_test_card(width, height, i * 3))4194 .map(|i| panned_test_card(width, height, i * 3))
4151 .collect();4195 .collect();
4152- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();4196+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
4153 assert_eq!(encoded.frames.len(), 3);4197 assert_eq!(encoded.frames.len(), 3);
4154 for (i, frame) in encoded.frames.iter().enumerate() {4198 for (i, frame) in encoded.frames.iter().enumerate() {
4155 assert_eq!(4199 assert_eq!(
@@ -4192,7 +4236,7 @@ mod tests {
4192 let pictures: Vec<Picture> = (0..3)4236 let pictures: Vec<Picture> = (0..3)
4193 .map(|i| panned_test_card(width, height, i * 3))4237 .map(|i| panned_test_card(width, height, i * 3))
4194 .collect();4238 .collect();
4195- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();4239+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
4196 assert_eq!(encoded.frames.len(), 3);4240 assert_eq!(encoded.frames.len(), 3);
4197 for (i, frame) in encoded.frames.iter().enumerate() {4241 for (i, frame) in encoded.frames.iter().enumerate() {
4198 assert_eq!(4242 assert_eq!(
@@ -4231,12 +4275,12 @@ mod tests {
4231 let fctx = &crate::decode::FrameCtx::new();4275 let fctx = &crate::decode::FrameCtx::new();
4232 let (width, height) = (640usize, 360usize);4276 let (width, height) = (640usize, 360usize);
4233 let picture = Picture::grey(width, height);4277 let picture = Picture::grey(width, height);
4234- encode_key_frame(&picture, 100, 0.5, fctx).expect("key frame now codes the mod-32==8 straddle");4278+ encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).expect("key frame now codes the mod-32==8 straddle");
4235 4279
4236 // `encode_sequence`'s second frame is the inter path: same size, now4280 // `encode_sequence`'s second frame is the inter path: same size, now
4237 // wired the same way.4281 // wired the same way.
4238 let pictures = vec![picture.clone(), picture];4282 let pictures = vec![picture.clone(), picture];
4239- encode_sequence(&pictures, 100, 0.5, fctx)4283+ encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
4240 .expect("inter frame now codes the mod-32==8 straddle too");4284 .expect("inter frame now codes the mod-32==8 straddle too");
4241 }4285 }
4242 4286
@@ -4258,7 +4302,7 @@ mod tests {
4258 let (width, height) = (640usize, 360usize);4302 let (width, height) = (640usize, 360usize);
4259 for shift in [0i64, 7, 19] {4303 for shift in [0i64, 7, 19] {
4260 let picture = panned_test_card(width, height, shift);4304 let picture = panned_test_card(width, height, shift);
4261- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();4305+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
4262 let decoded = ffmpeg_decode(&encoded.stream, width, height);4306 let decoded = ffmpeg_decode(&encoded.stream, width, height);
4263 assert_eq!(decoded.y, encoded.reconstruction.y, "shift {shift}: luma");4307 assert_eq!(decoded.y, encoded.reconstruction.y, "shift {shift}: luma");
4264 assert_eq!(decoded.u, encoded.reconstruction.u, "shift {shift}: U");4308 assert_eq!(decoded.u, encoded.reconstruction.u, "shift {shift}: U");
@@ -4283,7 +4327,7 @@ mod tests {
4283 let pictures: Vec<Picture> = (0..4)4327 let pictures: Vec<Picture> = (0..4)
4284 .map(|i| panned_test_card(width, height, i * 3))4328 .map(|i| panned_test_card(width, height, i * 3))
4285 .collect();4329 .collect();
4286- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();4330+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
4287 assert_eq!(encoded.frames.len(), 4);4331 assert_eq!(encoded.frames.len(), 4);
4288 if let Ok(path) = std::env::var("EC_AV1_DUMP") {4332 if let Ok(path) = std::env::var("EC_AV1_DUMP") {
4289 std::fs::write(&path, &encoded.stream).expect("dump the raw stream");4333 std::fs::write(&path, &encoded.stream).expect("dump the raw stream");
@@ -4472,7 +4516,7 @@ mod tests {
4472 for (width, height) in [(128, 96), (160, 96)] {4516 for (width, height) in [(128, 96), (160, 96)] {
4473 let picture = test_card(width, height);4517 let picture = test_card(width, height);
4474 for mode in KEY_FRAME_MODES {4518 for mode in KEY_FRAME_MODES {
4475- let encoded = encode_key_frame_with_modes(&picture, 100, 0.5, &[mode], fctx).unwrap();4519+ let encoded = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[mode], fctx).unwrap();
4476 let decoded = ffmpeg_decode(&encoded.stream, width, height);4520 let decoded = ffmpeg_decode(&encoded.stream, width, height);
4477 for (plane, ours, theirs, stride) in [4521 for (plane, ours, theirs, stride) in [
4478 ("luma", &encoded.reconstruction.y, &decoded.y, width),4522 ("luma", &encoded.reconstruction.y, &decoded.y, width),
@@ -4508,7 +4552,7 @@ mod tests {
4508 // tie then goes to whichever is cheaper to name, which is not what4552 // tie then goes to whichever is cheaper to name, which is not what
4509 // this gate is about.4553 // this gate is about.
4510 let encoded =4554 let encoded =
4511- encode_key_frame_with_modes(&picture, 100, 0.5, &[V_PRED, H_PRED], fctx).unwrap();4555+ encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[V_PRED, H_PRED], fctx).unwrap();
4512 // The first block of the picture has neither neighbour, so it4556 // The first block of the picture has neither neighbour, so it
4513 // cannot tell the modes apart; every other one can.4557 // cannot tell the modes apart; every other one can.
4514 let picked = encoded.modes[1..].iter().filter(|&&m| m == want).count();4558 let picked = encoded.modes[1..].iter().filter(|&&m| m == want).count();
@@ -4557,7 +4601,7 @@ mod tests {
4557 let mut points: Vec<(f64, f64)> = [110u8, 90, 70]4601 let mut points: Vec<(f64, f64)> = [110u8, 90, 70]
4558 .iter()4602 .iter()
4559 .map(|&q| {4603 .map(|&q| {
4560- let encoded = encode_key_frame_with_modes(picture, q, 0.5, modes, fctx).unwrap();4604+ let encoded = encode_key_frame_with_modes_with_ctx(picture, q, 0.5, modes, fctx).unwrap();
4561 (4605 (
4562 psnr(&encoded.reconstruction.y, picture.y.as_slice()),4606 psnr(&encoded.reconstruction.y, picture.y.as_slice()),
4563 (encoded.stream.len() as f64).log10(),4607 (encoded.stream.len() as f64).log10(),
@@ -4621,7 +4665,7 @@ mod tests {
4621 let dc = ladder(&picture, &[DC_PRED], fctx);4665 let dc = ladder(&picture, &[DC_PRED], fctx);
4622 let flat = ladder(&picture, &NON_DIRECTIONAL, fctx);4666 let flat = ladder(&picture, &NON_DIRECTIONAL, fctx);
4623 let all = ladder(&picture, &KEY_FRAME_MODES, fctx);4667 let all = ladder(&picture, &KEY_FRAME_MODES, fctx);
4624- let encoded = encode_key_frame(&picture, 90, 0.5, fctx).unwrap();4668+ let encoded = encode_key_frame_with_ctx(&picture, 90, 0.5, fctx).unwrap();
4625 let directional = encoded4669 let directional = encoded
4626 .modes4670 .modes
4627 .iter()4671 .iter()
@@ -4666,7 +4710,7 @@ mod tests {
4666 /// The mode picked by the most blocks of a picture, ignoring the first4710 /// The mode picked by the most blocks of a picture, ignoring the first
4667 /// block, which has no neighbours to tell the modes apart with.4711 /// block, which has no neighbours to tell the modes apart with.
4668 fn favourite_mode(picture: &Picture, fctx: &crate::decode::FrameCtx) -> (u8, usize, usize) {4712 fn favourite_mode(picture: &Picture, fctx: &crate::decode::FrameCtx) -> (u8, usize, usize) {
4669- let encoded = encode_key_frame(picture, 100, 0.5, fctx).unwrap();4713+ let encoded = encode_key_frame_with_ctx(picture, 100, 0.5, fctx).unwrap();
4670 let blocks = &encoded.modes[1..];4714 let blocks = &encoded.modes[1..];
4671 let mut counts = [0usize; 13];4715 let mut counts = [0usize; 13];
4672 for &mode in blocks {4716 for &mode in blocks {
@@ -4730,14 +4774,14 @@ mod tests {
4730 fn a_mode_the_encoder_cannot_predict_is_refused() {4774 fn a_mode_the_encoder_cannot_predict_is_refused() {
4731 let fctx = &crate::decode::FrameCtx::new();4775 let fctx = &crate::decode::FrameCtx::new();
4732 let picture = test_card(64, 64);4776 let picture = test_card(64, 64);
4733- let message = encode_key_frame_with_modes(&picture, 100, 0.5, &[13], fctx)4777+ let message = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[13], fctx)
4734 .unwrap_err()4778 .unwrap_err()
4735 .to_string();4779 .to_string();
4736 assert!(4780 assert!(
4737 message.contains("intra mode 13"),4781 message.contains("intra mode 13"),
4738 "the refusal must name the mode, got {message}"4782 "the refusal must name the mode, got {message}"
4739 );4783 );
4740- assert!(encode_key_frame_with_modes(&picture, 100, 0.5, &[], fctx).is_err());4784+ assert!(encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[], fctx).is_err());
4741 }4785 }
4742 4786
4743 /// The picture that comes back is the picture that went in, to within the4787 /// The picture that comes back is the picture that went in, to within the
@@ -4749,7 +4793,7 @@ mod tests {
4749 fn the_encoded_picture_is_the_one_that_went_in() {4793 fn the_encoded_picture_is_the_one_that_went_in() {
4750 let fctx = &crate::decode::FrameCtx::new();4794 let fctx = &crate::decode::FrameCtx::new();
4751 let picture = test_card(160, 96);4795 let picture = test_card(160, 96);
4752- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();4796+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
4753 let luma = psnr(&encoded.reconstruction.y, &picture.y);4797 let luma = psnr(&encoded.reconstruction.y, &picture.y);
4754 assert!(luma > 36.0, "luma PSNR {luma} at q 100");4798 assert!(luma > 36.0, "luma PSNR {luma} at q 100");
4755 for (plane, (got, want)) in [4799 for (plane, (got, want)) in [
@@ -4773,7 +4817,7 @@ mod tests {
4773 let picture = test_card(128, 128);4817 let picture = test_card(128, 128);
4774 let mut previous: Option<(usize, f64)> = None;4818 let mut previous: Option<(usize, f64)> = None;
4775 for &q in &[70u8, 90, 110] {4819 for &q in &[70u8, 90, 110] {
4776- let encoded = encode_key_frame(&picture, q, 0.5, fctx).unwrap();4820+ let encoded = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap();
4777 let quality = psnr(&encoded.reconstruction.y, &picture.y);4821 let quality = psnr(&encoded.reconstruction.y, &picture.y);
4778 if let Some((bytes, better)) = previous {4822 if let Some((bytes, better)) = previous {
4779 assert!(4823 assert!(
@@ -4788,7 +4832,7 @@ mod tests {
4788 4832
4789 let mut previous = None;4833 let mut previous = None;
4790 for &deadzone in &[0.5f64, 0.3, 0.15] {4834 for &deadzone in &[0.5f64, 0.3, 0.15] {
4791- let encoded = encode_key_frame(&picture, 100, deadzone, fctx).unwrap();4835+ let encoded = encode_key_frame_with_ctx(&picture, 100, deadzone, fctx).unwrap();
4792 let quality = psnr(&encoded.reconstruction.y, &picture.y);4836 let quality = psnr(&encoded.reconstruction.y, &picture.y);
4793 if let Some((bytes, better)) = previous {4837 if let Some((bytes, better)) = previous {
4794 assert!(4838 assert!(
@@ -4806,8 +4850,8 @@ mod tests {
4806 // even though a coarser quantizer always codes no more than a finer4850 // even though a coarser quantizer always codes no more than a finer
4807 // one on the same picture.4851 // one on the same picture.
4808 for &(lo, hi) in &[(20u8, 21u8), (60, 61), (120, 121)] {4852 for &(lo, hi) in &[(20u8, 21u8), (60, 61), (120, 121)] {
4809- let lo_bytes = encode_key_frame(&picture, lo, 0.5, fctx).unwrap().stream.len();4853+ let lo_bytes = encode_key_frame_with_ctx(&picture, lo, 0.5, fctx).unwrap().stream.len();
4810- let hi_bytes = encode_key_frame(&picture, hi, 0.5, fctx).unwrap().stream.len();4854+ let hi_bytes = encode_key_frame_with_ctx(&picture, hi, 0.5, fctx).unwrap().stream.len();
4811 assert!(4855 assert!(
4812 hi_bytes <= lo_bytes,4856 hi_bytes <= lo_bytes,
4813 "q {lo}->{hi} crosses a context boundary: {lo_bytes} -> {hi_bytes} bytes"4857 "q {lo}->{hi} crosses a context boundary: {lo_bytes} -> {hi_bytes} bytes"
@@ -4822,7 +4866,7 @@ mod tests {
4822 let fctx = &crate::decode::FrameCtx::new();4866 let fctx = &crate::decode::FrameCtx::new();
4823 let mut picture = Picture::grey(128, 128);4867 let mut picture = Picture::grey(128, 128);
4824 picture.y.fill(97);4868 picture.y.fill(97);
4825- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();4869+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
4826 // The first block has no neighbour and predicts 128, so it carries a4870 // The first block has no neighbour and predicts 128, so it carries a
4827 // DC; every block after it predicts 97 and carries nothing.4871 // DC; every block after it predicts 97 and carries nothing.
4828 assert!(4872 assert!(
@@ -4850,14 +4894,14 @@ mod tests {
4850 #[test]4894 #[test]
4851 fn a_picture_off_the_block_grid_is_refused() {4895 fn a_picture_off_the_block_grid_is_refused() {
4852 let fctx = &crate::decode::FrameCtx::new();4896 let fctx = &crate::decode::FrameCtx::new();
4853- let msg = encode_key_frame(&Picture::grey(40, 40), 100, 0.5, fctx)4897+ let msg = encode_key_frame_with_ctx(&Picture::grey(40, 40), 100, 0.5, fctx)
4854 .expect_err("40x40 straddles both axes of a 16x16 leaf, needs a rectangular transform")4898 .expect_err("40x40 straddles both axes of a 16x16 leaf, needs a rectangular transform")
4855 .to_string();4899 .to_string();
4856 assert!(msg.contains("rectangular"), "refusal: {msg}");4900 assert!(msg.contains("rectangular"), "refusal: {msg}");
4857 4901
4858 let mut short = Picture::grey(64, 64);4902 let mut short = Picture::grey(64, 64);
4859 short.u.truncate(10);4903 short.u.truncate(10);
4860- assert!(encode_key_frame(&short, 100, 0.5, fctx).is_err());4904+ assert!(encode_key_frame_with_ctx(&short, 100, 0.5, fctx).is_err());
4861 }4905 }
4862 4906
4863 /// 40x32: cols mod 32 == 8, so the true edge cuts a 16x16 leaf's own4907 /// 40x32: cols mod 32 == 8, so the true edge cuts a 16x16 leaf's own
@@ -4939,7 +4983,7 @@ mod tests {
4939 }4983 }
4940 let (width, height) = (40usize, 32usize);4984 let (width, height) = (40usize, 32usize);
4941 let picture = test_card(width, height);4985 let picture = test_card(width, height);
4942- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();4986+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
4943 assert_eq!(4987 assert_eq!(
4944 (encoded.reconstruction.width, encoded.reconstruction.height),4988 (encoded.reconstruction.width, encoded.reconstruction.height),
4945 (width, height)4989 (width, height)
@@ -4981,7 +5025,7 @@ mod tests {
4981 let (width, height) = (640usize, 352usize);5025 let (width, height) = (640usize, 352usize);
4982 let picture = clip_frame(&clip, &skip, width, height);5026 let picture = clip_frame(&clip, &skip, width, height);
4983 5027
4984- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();5028+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
4985 let decoded = ffmpeg_decode(&encoded.stream, width, height);5029 let decoded = ffmpeg_decode(&encoded.stream, width, height);
4986 assert_eq!(decoded.y, encoded.reconstruction.y, "luma");5030 assert_eq!(decoded.y, encoded.reconstruction.y, "luma");
4987 assert_eq!(decoded.u, encoded.reconstruction.u, "U");5031 assert_eq!(decoded.u, encoded.reconstruction.u, "U");
@@ -5103,7 +5147,7 @@ mod tests {
5103 let pictures: Vec<Picture> = (0..5)5147 let pictures: Vec<Picture> = (0..5)
5104 .map(|i| panned_test_card(width, height, i * 3))5148 .map(|i| panned_test_card(width, height, i * 3))
5105 .collect();5149 .collect();
5106- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();5150+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
5107 assert_eq!(encoded.frames.len(), 5);5151 assert_eq!(encoded.frames.len(), 5);
5108 5152
5109 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 5);5153 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, 5);
@@ -5138,7 +5182,7 @@ mod tests {
5138 let pictures: Vec<Picture> = (0..5)5182 let pictures: Vec<Picture> = (0..5)
5139 .map(|i| panned_test_card(width, height, i * 2))5183 .map(|i| panned_test_card(width, height, i * 2))
5140 .collect();5184 .collect();
5141- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();5185+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
5142 5186
5143 let key_bytes = encoded.frames[0].stream.len();5187 let key_bytes = encoded.frames[0].stream.len();
5144 eprintln!("frame bytes inter share");5188 eprintln!("frame bytes inter share");
@@ -5177,16 +5221,16 @@ mod tests {
5177 let picture = test_card(width, height);5221 let picture = test_card(width, height);
5178 5222
5179 let t = Instant::now();5223 let t = Instant::now();
5180- let dc_only = encode_key_frame_with_modes(&picture, 100, 0.5, &[DC_PRED], fctx).unwrap();5224+ let dc_only = encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &[DC_PRED], fctx).unwrap();
5181 let dc_only_t = t.elapsed();5225 let dc_only_t = t.elapsed();
5182 5226
5183 let t = Instant::now();5227 let t = Instant::now();
5184 let non_directional =5228 let non_directional =
5185- encode_key_frame_with_modes(&picture, 100, 0.5, &NON_DIRECTIONAL, fctx).unwrap();5229+ encode_key_frame_with_modes_with_ctx(&picture, 100, 0.5, &NON_DIRECTIONAL, fctx).unwrap();
5186 let non_directional_t = t.elapsed();5230 let non_directional_t = t.elapsed();
5187 5231
5188 let t = Instant::now();5232 let t = Instant::now();
5189- let all_modes = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();5233+ let all_modes = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
5190 let all_modes_t = t.elapsed();5234 let all_modes_t = t.elapsed();
5191 5235
5192 eprintln!(5236 eprintln!(
@@ -5297,7 +5341,7 @@ mod tests {
5297 5341
5298 let (width, height) = (1280usize, 720);5342 let (width, height) = (1280usize, 720);
5299 let picture = test_card(width, height);5343 let picture = test_card(width, height);
5300- let key = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();5344+ let key = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
5301 let padded_ref = key.reconstruction.padded_to(SUPERBLOCK);5345 let padded_ref = key.reconstruction.padded_to(SUPERBLOCK);
5302 let padded_pic = picture.padded_to(SUPERBLOCK);5346 let padded_pic = picture.padded_to(SUPERBLOCK);
5303 5347
@@ -5376,7 +5420,7 @@ mod tests {
5376 // a single-threaded #[ignore] probe, run by hand, never5420 // a single-threaded #[ignore] probe, run by hand, never
5377 // alongside other tests that read Search::top_k.5421 // alongside other tests that read Search::top_k.
5378 set_test_top_k_override(None);5422 set_test_top_k_override(None);
5379- let baseline = encode_key_frame(&picture, q, 0.5, fctx).unwrap();5423+ let baseline = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap();
5380 let baseline_psnr = psnr(&baseline.reconstruction.y, &picture.y);5424 let baseline_psnr = psnr(&baseline.reconstruction.y, &picture.y);
5381 eprint!(5425 eprint!(
5382 "{label:9} q={q:3} baseline {:6} bytes {:6.2} dB",5426 "{label:9} q={q:3} baseline {:6} bytes {:6.2} dB",
@@ -5385,7 +5429,7 @@ mod tests {
5385 );5429 );
5386 for &k in &[3usize, 4, 6] {5430 for &k in &[3usize, 4, 6] {
5387 set_test_top_k_override(Some(k));5431 set_test_top_k_override(Some(k));
5388- let pruned = encode_key_frame(&picture, q, 0.5, fctx).unwrap();5432+ let pruned = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap();
5389 let pruned_psnr = psnr(&pruned.reconstruction.y, &picture.y);5433 let pruned_psnr = psnr(&pruned.reconstruction.y, &picture.y);
5390 eprint!(5434 eprint!(
5391 " K={k} {:6} bytes {:6.2} dB ({:+.3} dB)",5435 " K={k} {:6} bytes {:6.2} dB ({:+.3} dB)",
@@ -5474,7 +5518,7 @@ mod tests {
5474 // single-threaded #[ignore] probe, run by hand, never5518 // single-threaded #[ignore] probe, run by hand, never
5475 // alongside other tests that read Search::top_k.5519 // alongside other tests that read Search::top_k.
5476 set_test_top_k_override_inter(None);5520 set_test_top_k_override_inter(None);
5477- let key = encode_key_frame(&key_source, q, 0.5, fctx).unwrap();5521+ let key = encode_key_frame_with_ctx(&key_source, q, 0.5, fctx).unwrap();
5478 let baseline = encode_inter_frame(5522 let baseline = encode_inter_frame(
5479 &inter_source,5523 &inter_source,
5480 &key.reconstruction,5524 &key.reconstruction,
@@ -5594,7 +5638,7 @@ mod tests {
5594 }5638 }
5595 let (width, height, frame_count) = (640usize, 384usize, 12usize);5639 let (width, height, frame_count) = (640usize, 384usize, 12usize);
5596 let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count);5640 let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count);
5597- let encoded = encode_sequence(&source, 100, 0.5, fctx).unwrap();5641+ let encoded = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap();
5598 assert_eq!(encoded.frames.len(), frame_count);5642 assert_eq!(encoded.frames.len(), frame_count);
5599 5643
5600 // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole5644 // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole
@@ -5659,7 +5703,7 @@ mod tests {
5659 }5703 }
5660 let (width, height, frame_count) = (704usize, 400usize, 8usize);5704 let (width, height, frame_count) = (704usize, 400usize, 8usize);
5661 let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count);5705 let source = clip_frames(clip.to_str().unwrap(), "0", width, height, frame_count);
5662- let encoded = encode_sequence(&source, 100, 0.5, fctx).unwrap();5706+ let encoded = encode_sequence_with_ctx(&source, 100, 0.5, fctx).unwrap();
5663 assert_eq!(encoded.frames.len(), frame_count);5707 assert_eq!(encoded.frames.len(), frame_count);
5664 5708
5665 // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole5709 // Gate 1: a real AV1 decoder (dav1d, via ffmpeg) accepts the whole
@@ -5703,7 +5747,7 @@ mod tests {
5703 .map(|i| panned_test_card(width, height, i * 3))5747 .map(|i| panned_test_card(width, height, i * 3))
5704 .collect();5748 .collect();
5705 let t = Instant::now();5749 let t = Instant::now();
5706- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();5750+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
5707 let elapsed = t.elapsed();5751 let elapsed = t.elapsed();
5708 let total_bytes: usize = encoded.frames.iter().map(|f| f.stream.len()).sum();5752 let total_bytes: usize = encoded.frames.iter().map(|f| f.stream.len()).sum();
5709 eprintln!(5753 eprintln!(
@@ -5739,7 +5783,7 @@ mod tests {
5739 let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames);5783 let source = clip_frames(path.to_str().unwrap(), "0", width, height, frames);
5740 eprintln!("--- {clip} ---");5784 eprintln!("--- {clip} ---");
5741 for q in [40u8, 70, 100, 130, 160, 190, 220, 240] {5785 for q in [40u8, 70, 100, 130, 160, 190, 220, 240] {
5742- let encoded = encode_sequence(&source, q, 0.5, fctx).unwrap();5786+ let encoded = encode_sequence_with_ctx(&source, q, 0.5, fctx).unwrap();
5743 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frames);5787 let decoded = ffmpeg_decode_sequence(&encoded.stream, width, height, frames);
5744 let mean_psnr: f64 = decoded5788 let mean_psnr: f64 = decoded
5745 .iter()5789 .iter()
crates/ec-av1/src/encoder.rsmodified+28 -21
@@ -221,8 +221,21 @@ pub struct Av1Encoder {
221 /// otherwise every picture is coded at `config.base_q_idx`, unchanged221 /// otherwise every picture is coded at `config.base_q_idx`, unchanged
222 /// from before this field existed.222 /// from before this field existed.
223 rate_loop: Option<RateLoop>,223 rate_loop: Option<RateLoop>,
224+ /// This stream's decode-side per-frame state, owned here so `encode`
225+ /// keeps the public signature it had before the state stopped being
226+ /// thread-local. One per encoder, never per frame: several of its fields
227+ /// (the inter-frame inheritance guards) carry state ACROSS frames.
228+ fctx: crate::decode::FrameCtx,
224 }229 }
225 230
231+/// The encoder stays `Send` now that it owns a `FrameCtx` (whose cells are
232+/// `Send` but `!Sync`): it can move to another thread, it just cannot be
233+/// shared by reference across threads.
234+const _: fn() = || {
235+ fn assert_send<T: Send>() {}
236+ assert_send::<Av1Encoder>();
237+};
238+
226 impl Av1Encoder {239 impl Av1Encoder {
227 /// # Errors240 /// # Errors
228 /// Returns an error when `config.width`/`config.height` are zero, odd,241 /// Returns an error when `config.width`/`config.height` are zero, odd,
@@ -243,6 +256,7 @@ impl Av1Encoder {
243 reference: None,256 reference: None,
244 next_index: 0,257 next_index: 0,
245 rate_loop: None,258 rate_loop: None,
259+ fctx: crate::decode::FrameCtx::new(),
246 })260 })
247 }261 }
248 262
@@ -297,7 +311,7 @@ impl Av1Encoder {
297 /// [`EncoderConfig::width`]/[`EncoderConfig::height`], or under the same311 /// [`EncoderConfig::width`]/[`EncoderConfig::height`], or under the same
298 /// conditions [`crate::encode::encode_key_frame`]/312 /// conditions [`crate::encode::encode_key_frame`]/
299 /// [`crate::encode::encode_sequence`] do.313 /// [`crate::encode::encode_sequence`] do.
300- pub fn encode(&mut self, picture: &Picture, fctx: &crate::decode::FrameCtx) -> Result<Packet> {314+ pub fn encode(&mut self, picture: &Picture) -> Result<Packet> {
301 if (picture.width, picture.height) != (self.config.width, self.config.height) {315 if (picture.width, picture.height) != (self.config.width, self.config.height) {
302 return Err(Error::unsupported(316 return Err(Error::unsupported(
303 "AV1 encode",317 "AV1 encode",
@@ -324,7 +338,8 @@ impl Av1Encoder {
324 &KEY_FRAME_MODES,338 &KEY_FRAME_MODES,
325 split_blocks(),339 split_blocks(),
326 render,340 render,
327- self.color_config, fctx,341+ self.color_config,
342+ &self.fctx,
328 )?343 )?
329 } else {344 } else {
330 let reference = self.reference.as_ref().ok_or_else(|| {345 let reference = self.reference.as_ref().ok_or_else(|| {
@@ -339,7 +354,8 @@ impl Av1Encoder {
339 base_q_idx,354 base_q_idx,
340 DEADZONE,355 DEADZONE,
341 order as u32,356 order as u32,
342- render, fctx,357+ render,
358+ &self.fctx,
343 )?359 )?
344 };360 };
345 361
@@ -414,7 +430,6 @@ mod tests {
414 /// ffmpeg since it is a property of the return type, not the bytes.430 /// ffmpeg since it is a property of the return type, not the bytes.
415 #[test]431 #[test]
416 fn one_in_one_out() {432 fn one_in_one_out() {
417- let fctx = &crate::decode::FrameCtx::new();
418 let config = EncoderConfig {433 let config = EncoderConfig {
419 width: 64,434 width: 64,
420 height: 64,435 height: 64,
@@ -424,7 +439,7 @@ mod tests {
424 };439 };
425 let mut enc = Av1Encoder::new(config).unwrap();440 let mut enc = Av1Encoder::new(config).unwrap();
426 for t in 0..5u64 {441 for t in 0..5u64 {
427- let packet = enc.encode(&test_card(64, 64, t as usize), fctx).unwrap();442+ let packet = enc.encode(&test_card(64, 64, t as usize)).unwrap();
428 assert!(!packet.data.is_empty(), "picture {t}: empty packet");443 assert!(!packet.data.is_empty(), "picture {t}: empty packet");
429 assert_eq!(packet.order, t, "picture {t}: order");444 assert_eq!(packet.order, t, "picture {t}: order");
430 }445 }
@@ -435,7 +450,6 @@ mod tests {
435 /// reads back out of the coded bytes.450 /// reads back out of the coded bytes.
436 #[test]451 #[test]
437 fn gop_cadence_is_honored() {452 fn gop_cadence_is_honored() {
438- let fctx = &crate::decode::FrameCtx::new();
439 let config = EncoderConfig {453 let config = EncoderConfig {
440 width: 64,454 width: 64,
441 height: 64,455 height: 64,
@@ -445,7 +459,7 @@ mod tests {
445 };459 };
446 let mut enc = Av1Encoder::new(config).unwrap();460 let mut enc = Av1Encoder::new(config).unwrap();
447 let keys: Vec<bool> = (0..7)461 let keys: Vec<bool> = (0..7)
448- .map(|t| enc.encode(&test_card(64, 64, t), fctx).unwrap().key)462+ .map(|t| enc.encode(&test_card(64, 64, t)).unwrap().key)
449 .collect();463 .collect();
450 assert_eq!(keys, vec![true, false, false, true, false, false, true]);464 assert_eq!(keys, vec![true, false, false, true, false, false, true]);
451 }465 }
@@ -529,7 +543,6 @@ mod tests {
529 /// coded size confirm what the facade already reported.543 /// coded size confirm what the facade already reported.
530 #[test]544 #[test]
531 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {545 fn thirty_pictures_at_gop_fifteen_decode_to_two_key_frames() {
532- let fctx = &crate::decode::FrameCtx::new();
533 if !have_ffmpeg() {546 if !have_ffmpeg() {
534 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");547 eprintln!("SKIP thirty_pictures_at_gop_fifteen_decode_to_two_key_frames: no ffmpeg");
535 return;548 return;
@@ -554,7 +567,7 @@ mod tests {
554 );567 );
555 568
556 let packets: Vec<Packet> = (0..30)569 let packets: Vec<Packet> = (0..30)
557- .map(|t| enc.encode(&test_card(width, height, t), fctx).unwrap())570+ .map(|t| enc.encode(&test_card(width, height, t)).unwrap())
558 .collect();571 .collect();
559 let expect_key: Vec<bool> = (0..30).map(|t| t % 15 == 0).collect();572 let expect_key: Vec<bool> = (0..30).map(|t| t % 15 == 0).collect();
560 assert_eq!(573 assert_eq!(
@@ -584,7 +597,6 @@ mod tests {
584 /// which is a visibly different string).597 /// which is a visibly different string).
585 #[test]598 #[test]
586 fn bt709_limited_colour_is_reported_by_ffprobe() {599 fn bt709_limited_colour_is_reported_by_ffprobe() {
587- let fctx = &crate::decode::FrameCtx::new();
588 if !have_ffmpeg() {600 if !have_ffmpeg() {
589 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");601 eprintln!("SKIP bt709_limited_colour_is_reported_by_ffprobe: no ffmpeg");
590 return;602 return;
@@ -597,7 +609,7 @@ mod tests {
597 colour: Colour::Bt709Limited,609 colour: Colour::Bt709Limited,
598 };610 };
599 let mut enc = Av1Encoder::new(config).unwrap();611 let mut enc = Av1Encoder::new(config).unwrap();
600- let packet = enc.encode(&test_card(64, 64, 0), fctx).unwrap();612+ let packet = enc.encode(&test_card(64, 64, 0)).unwrap();
601 let colour = ffprobe_colour(&packet.data);613 let colour = ffprobe_colour(&packet.data);
602 assert_eq!(colour, "tv,bt709,bt709,bt709", "ffprobe colour fields");614 assert_eq!(colour, "tv,bt709,bt709,bt709", "ffprobe colour fields");
603 }615 }
@@ -607,7 +619,6 @@ mod tests {
607 /// as BT.709 for every input.619 /// as BT.709 for every input.
608 #[test]620 #[test]
609 fn bt601_limited_colour_is_reported_by_ffprobe() {621 fn bt601_limited_colour_is_reported_by_ffprobe() {
610- let fctx = &crate::decode::FrameCtx::new();
611 if !have_ffmpeg() {622 if !have_ffmpeg() {
612 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");623 eprintln!("SKIP bt601_limited_colour_is_reported_by_ffprobe: no ffmpeg");
613 return;624 return;
@@ -620,7 +631,7 @@ mod tests {
620 colour: Colour::Bt601Limited,631 colour: Colour::Bt601Limited,
621 };632 };
622 let mut enc = Av1Encoder::new(config).unwrap();633 let mut enc = Av1Encoder::new(config).unwrap();
623- let packet = enc.encode(&test_card(64, 64, 0), fctx).unwrap();634+ let packet = enc.encode(&test_card(64, 64, 0)).unwrap();
624 let colour = ffprobe_colour(&packet.data);635 let colour = ffprobe_colour(&packet.data);
625 assert_eq!(636 assert_eq!(
626 colour, "tv,smpte170m,smpte170m,smpte170m",637 colour, "tv,smpte170m,smpte170m,smpte170m",
@@ -632,7 +643,6 @@ mod tests {
632 /// is refused by name.643 /// is refused by name.
633 #[test]644 #[test]
634 fn geometry_mismatch_is_refused() {645 fn geometry_mismatch_is_refused() {
635- let fctx = &crate::decode::FrameCtx::new();
636 let config = EncoderConfig {646 let config = EncoderConfig {
637 width: 64,647 width: 64,
638 height: 64,648 height: 64,
@@ -641,7 +651,7 @@ mod tests {
641 colour: Colour::Bt709Limited,651 colour: Colour::Bt709Limited,
642 };652 };
643 let mut enc = Av1Encoder::new(config).unwrap();653 let mut enc = Av1Encoder::new(config).unwrap();
644- let err = enc.encode(&Picture::grey(32, 32), fctx).unwrap_err();654+ let err = enc.encode(&Picture::grey(32, 32)).unwrap_err();
645 assert!(err.to_string().contains("64x64"), "{err}");655 assert!(err.to_string().contains("64x64"), "{err}");
646 }656 }
647 657
@@ -714,7 +724,6 @@ mod tests {
714 /// state and the controller's first couple of steps).724 /// state and the controller's first couple of steps).
715 #[test]725 #[test]
716 fn bytes_per_frame_target_settles_within_20_percent() {726 fn bytes_per_frame_target_settles_within_20_percent() {
717- let fctx = &crate::decode::FrameCtx::new();
718 let Some(pictures) = h264_clip_frames(640, 384, 24) else {727 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
719 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");728 eprintln!("SKIP bytes_per_frame_target_settles_within_20_percent: no ffmpeg/fixture");
720 return;729 return;
@@ -731,7 +740,7 @@ mod tests {
731 Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(target_bytes)).unwrap();740 Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(target_bytes)).unwrap();
732 let sizes: Vec<usize> = pictures741 let sizes: Vec<usize> = pictures
733 .iter()742 .iter()
734- .map(|p| enc.encode(p, fctx).unwrap().data.len())743+ .map(|p| enc.encode(p).unwrap().data.len())
735 .collect();744 .collect();
736 // Discard the key frame (always far larger than an inter target) and745 // Discard the key frame (always far larger than an inter target) and
737 // the next 4 inter frames the loop needs to step toward it.746 // the next 4 inter frames the loop needs to step toward it.
@@ -751,7 +760,6 @@ mod tests {
751 /// that breaks the bound).760 /// that breaks the bound).
752 #[test]761 #[test]
753 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {762 fn bytes_per_frame_controller_never_oscillates_past_its_clamp() {
754- let fctx = &crate::decode::FrameCtx::new();
755 let Some(pictures) = h264_clip_frames(640, 384, 24) else {763 let Some(pictures) = h264_clip_frames(640, 384, 24) else {
756 eprintln!(764 eprintln!(
757 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"765 "SKIP bytes_per_frame_controller_never_oscillates_past_its_clamp: no ffmpeg/fixture"
@@ -769,7 +777,7 @@ mod tests {
769 Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(4_000)).unwrap();777 Av1Encoder::with_rate_target(config, RateTarget::BytesPerFrame(4_000)).unwrap();
770 let mut prev_q = enc.rate_loop.as_ref().unwrap().q_idx();778 let mut prev_q = enc.rate_loop.as_ref().unwrap().q_idx();
771 for picture in &pictures {779 for picture in &pictures {
772- enc.encode(picture, fctx).unwrap();780+ enc.encode(picture).unwrap();
773 let q = enc.rate_loop.as_ref().unwrap().q_idx();781 let q = enc.rate_loop.as_ref().unwrap().q_idx();
774 let step = (i32::from(q) - i32::from(prev_q)).abs();782 let step = (i32::from(q) - i32::from(prev_q)).abs();
775 assert!(783 assert!(
@@ -832,7 +840,6 @@ mod tests {
832 /// the same real clip.840 /// the same real clip.
833 #[test]841 #[test]
834 fn quality_target_is_monotone_in_bytes_and_psnr() {842 fn quality_target_is_monotone_in_bytes_and_psnr() {
835- let fctx = &crate::decode::FrameCtx::new();
836 if !have_ffmpeg() {843 if !have_ffmpeg() {
837 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");844 eprintln!("SKIP quality_target_is_monotone_in_bytes_and_psnr: no ffmpeg");
838 return;845 return;
@@ -857,7 +864,7 @@ mod tests {
857 let mut stream = Vec::new();864 let mut stream = Vec::new();
858 let mut total_bytes = 0usize;865 let mut total_bytes = 0usize;
859 for picture in &pictures {866 for picture in &pictures {
860- let packet = enc.encode(picture, fctx).unwrap();867+ let packet = enc.encode(picture).unwrap();
861 total_bytes += packet.data.len();868 total_bytes += packet.data.len();
862 stream.extend_from_slice(&packet.data);869 stream.extend_from_slice(&packet.data);
863 }870 }
crates/ec-av1/src/intra.rsmodified+2 -2
@@ -262,7 +262,7 @@ pub(crate) fn intra_edge_filter_hits() -> usize {
262 }262 }
263 263
264 #[allow(clippy::too_many_arguments)]264 #[allow(clippy::too_many_arguments)]
265-pub fn predict(265+pub(crate) fn predict(
266 mode: u8,266 mode: u8,
267 angle_delta: i32,267 angle_delta: i32,
268 above: Option<&[u16]>,268 above: Option<&[u16]>,
@@ -772,7 +772,7 @@ const FILTER_INTRA_SCALE_BITS: u32 = 4;
772 /// Panics when `dst` is not `bw * bh` long, or `bw` is not a multiple of 4772 /// Panics when `dst` is not `bw * bh` long, or `bw` is not a multiple of 4
773 /// or `bh` not a multiple of 2 (spec `av1_filter_intra_allowed_bsize` never773 /// or `bh` not a multiple of 2 (spec `av1_filter_intra_allowed_bsize` never
774 /// offers this mode past 32x32).774 /// offers this mode past 32x32).
775-pub fn predict_filter_intra(775+pub(crate) fn predict_filter_intra(
776 mode: usize,776 mode: usize,
777 above: Option<&[u16]>,777 above: Option<&[u16]>,
778 left: Option<&[u16]>,778 left: Option<&[u16]>,
crates/ec-av1/src/mc.rsmodified+10 -10
@@ -663,7 +663,7 @@ fn with_scratch<R>(rows: usize, block_w: usize, f: impl FnOnce(&mut [i32], &mut
663 /// Panics when `dst` is not `block_w * block_h` long, or the reference is663 /// Panics when `dst` is not `block_w * block_h` long, or the reference is
664 /// empty.664 /// empty.
665 #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape665 #[allow(clippy::too_many_arguments)] // one reference plane, one position, one block shape
666-pub fn predict(666+pub(crate) fn predict(
667 reference: &[u16],667 reference: &[u16],
668 stride: usize,668 stride: usize,
669 true_width: usize,669 true_width: usize,
@@ -692,7 +692,7 @@ pub fn predict(
692 /// 6.8.9's `interpolation_filter`) instead of always `Regular` -- the same692 /// 6.8.9's `interpolation_filter`) instead of always `Regular` -- the same
693 /// kernel both directions.693 /// kernel both directions.
694 #[allow(clippy::too_many_arguments)]694 #[allow(clippy::too_many_arguments)]
695-pub fn predict_with_filter(695+pub(crate) fn predict_with_filter(
696 reference: &[u16],696 reference: &[u16],
697 stride: usize,697 stride: usize,
698 true_width: usize,698 true_width: usize,
@@ -724,7 +724,7 @@ pub fn predict_with_filter(
724 /// 5.11.20's per-block `SWITCHABLE` read is per-direction (`enable_dual_filter`),724 /// 5.11.20's per-block `SWITCHABLE` read is per-direction (`enable_dual_filter`),
725 /// so the two passes can genuinely differ.725 /// so the two passes can genuinely differ.
726 #[allow(clippy::too_many_arguments)]726 #[allow(clippy::too_many_arguments)]
727-pub fn predict_with_filters(727+pub(crate) fn predict_with_filters(
728 reference: &[u16],728 reference: &[u16],
729 stride: usize,729 stride: usize,
730 true_width: usize,730 true_width: usize,
@@ -752,7 +752,7 @@ pub fn predict_with_filters(
752 /// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask752 /// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask
753 /// for the 4-tap kernel on that axis -- lane-rectchroma2 r1.753 /// for the 4-tap kernel on that axis -- lane-rectchroma2 r1.
754 #[allow(clippy::too_many_arguments)]754 #[allow(clippy::too_many_arguments)]
755-pub fn predict_with_filters_kern(755+pub(crate) fn predict_with_filters_kern(
756 reference: &[u16],756 reference: &[u16],
757 stride: usize,757 stride: usize,
758 true_width: usize,758 true_width: usize,
@@ -1070,7 +1070,7 @@ fn horizontal_pass(
1070 /// Panics when `dst` is not `block_w * block_h` long, or the reference is1070 /// Panics when `dst` is not `block_w * block_h` long, or the reference is
1071 /// empty.1071 /// empty.
1072 #[allow(clippy::too_many_arguments)]1072 #[allow(clippy::too_many_arguments)]
1073-pub fn predict_scaled(1073+pub(crate) fn predict_scaled(
1074 reference: &[u16],1074 reference: &[u16],
1075 stride: usize,1075 stride: usize,
1076 true_width: usize,1076 true_width: usize,
@@ -1093,7 +1093,7 @@ pub fn predict_scaled(
1093 /// [`predict_scaled`] with the 4-tap decision from the block's true dims1093 /// [`predict_scaled`] with the 4-tap decision from the block's true dims
1094 /// (see [`predict_with_filters_kern`]).1094 /// (see [`predict_with_filters_kern`]).
1095 #[allow(clippy::too_many_arguments)]1095 #[allow(clippy::too_many_arguments)]
1096-pub fn predict_scaled_kern(1096+pub(crate) fn predict_scaled_kern(
1097 reference: &[u16],1097 reference: &[u16],
1098 stride: usize,1098 stride: usize,
1099 true_width: usize,1099 true_width: usize,
@@ -1156,7 +1156,7 @@ pub fn predict_scaled_kern(
1156 /// scaled (superres). `REF_NO_SCALE` takes the ordinary stride-1 path, which1156 /// scaled (superres). `REF_NO_SCALE` takes the ordinary stride-1 path, which
1157 /// keeps [`predict_scaled_hits`] a true count of scaled predictions.1157 /// keeps [`predict_scaled_hits`] a true count of scaled predictions.
1158 #[allow(clippy::too_many_arguments)]1158 #[allow(clippy::too_many_arguments)]
1159-pub fn predict_maybe_scaled(1159+pub(crate) fn predict_maybe_scaled(
1160 reference: &[u16],1160 reference: &[u16],
1161 stride: usize,1161 stride: usize,
1162 true_width: usize,1162 true_width: usize,
@@ -1305,7 +1305,7 @@ pub fn predict_compound_intermediate_kern(
1305 /// output; both always sum to `1 << DIST_PRECISION_BITS`). Masked compound1305 /// output; both always sum to `1 << DIST_PRECISION_BITS`). Masked compound
1306 /// (`comp_group_idx == 1`, wedge/diffwtd) is a different combine this1306 /// (`comp_group_idx == 1`, wedge/diffwtd) is a different combine this
1307 /// function does not cover -- decode.rs still refuses those by name.1307 /// function does not cover -- decode.rs still refuses those by name.
1308-pub fn combine_compound(1308+pub(crate) fn combine_compound(
1309 pred0: &[i32],1309 pred0: &[i32],
1310 pred1: &[i32],1310 pred1: &[i32],
1311 fwd_weight: i32,1311 fwd_weight: i32,
@@ -1338,7 +1338,7 @@ pub fn combine_compound(
1338 /// produces give the identical `diff` libaom computes. `round` is1338 /// produces give the identical `diff` libaom computes. `round` is
1339 /// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for1339 /// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for
1340 /// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`).1340 /// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`).
1341-pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8], fctx: &crate::decode::FrameCtx) {1341+pub(crate) fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8], fctx: &crate::decode::FrameCtx) {
1342 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");1342 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
1343 assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel");1343 assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel");
1344 // libaom `diffwtd_mask_d16` (`reconinter.c:307`): `round = 2*FILTER_BITS1344 // 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
1365 /// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 /1365 /// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 /
1366 /// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read.1366 /// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read.
1367 #[allow(clippy::too_many_arguments)]1367 #[allow(clippy::too_many_arguments)]
1368-pub fn blend_masked_compound(1368+pub(crate) fn blend_masked_compound(
1369 pred0: &[i32],1369 pred0: &[i32],
1370 pred1: &[i32],1370 pred1: &[i32],
1371 mask: &[u8],1371 mask: &[u8],
crates/ec-av1/src/motion.rsmodified+1 -1
@@ -189,7 +189,7 @@ pub struct MotionSearch {
189 /// Panics when `source` is not `block_w * block_h` long, or `reference` is189 /// Panics when `source` is not `block_w * block_h` long, or `reference` is
190 /// empty (the same contracts [`predict`] has).190 /// empty (the same contracts [`predict`] has).
191 #[allow(clippy::too_many_arguments)] // one reference plane, one block, one predictor191 #[allow(clippy::too_many_arguments)] // one reference plane, one block, one predictor
192-pub fn search(192+pub(crate) fn search(
193 reference: &[u8],193 reference: &[u8],
194 stride: usize,194 stride: usize,
195 ref_width: usize,195 ref_width: usize,
crates/ec-av1/src/stream.rsmodified+12 -12
@@ -1070,7 +1070,7 @@ pub fn intra_rect4_in_inter_counters() -> (usize, usize, usize, usize) {
1070 #[cfg(test)]1070 #[cfg(test)]
1071 mod tests {1071 mod tests {
1072 use super::*;1072 use super::*;
1073- use crate::encode::{Picture as Pic, encode_key_frame, encode_sequence};1073+ use crate::encode::{Picture as Pic, encode_key_frame_with_ctx, encode_sequence_with_ctx};
1074 1074
1075 fn test_card(width: usize, height: usize) -> Pic {1075 fn test_card(width: usize, height: usize) -> Pic {
1076 let mut picture = Pic::grey(width, height);1076 let mut picture = Pic::grey(width, height);
@@ -1119,7 +1119,7 @@ mod tests {
1119 fn a_twelve_bit_sequence_header_is_refused_by_name() {1119 fn a_twelve_bit_sequence_header_is_refused_by_name() {
1120 let fctx = &crate::decode::FrameCtx::new();1120 let fctx = &crate::decode::FrameCtx::new();
1121 let picture = test_card(64, 64);1121 let picture = test_card(64, 64);
1122- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();1122+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1123 let mut color = ec_av1_syntax::ColorConfig {1123 let mut color = ec_av1_syntax::ColorConfig {
1124 bit_depth: 12,1124 bit_depth: 12,
1125 ..Default::default()1125 ..Default::default()
@@ -1164,7 +1164,7 @@ mod tests {
1164 let fctx = &crate::decode::FrameCtx::new();1164 let fctx = &crate::decode::FrameCtx::new();
1165 const REFUSAL: &str = "a frame OBU with no tile group";1165 const REFUSAL: &str = "a frame OBU with no tile group";
1166 let picture = test_card(64, 64);1166 let picture = test_card(64, 64);
1167- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();1167+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1168 let (seq, header) = crate::encode::key_frame_headers(64, 64, 100).unwrap();1168 let (seq, header) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1169 let mut frame_obus_parsed = 0;1169 let mut frame_obus_parsed = 0;
1170 for len in 0..=encoded.tile.len().min(24) {1170 for len in 0..=encoded.tile.len().min(24) {
@@ -1221,7 +1221,7 @@ mod tests {
1221 const REFUSAL: &str =1221 const REFUSAL: &str =
1222 "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV";1222 "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV";
1223 let picture = test_card(64, 64);1223 let picture = test_card(64, 64);
1224- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();1224+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1225 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();1225 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1226 for feature in [SEG_LVL_REF_FRAME, SEG_LVL_SKIP, SEG_LVL_GLOBALMV] {1226 for feature in [SEG_LVL_REF_FRAME, SEG_LVL_SKIP, SEG_LVL_GLOBALMV] {
1227 for segment in [0usize, 3, 7] {1227 for segment in [0usize, 3, 7] {
@@ -1612,7 +1612,7 @@ mod tests {
1612 let fctx = &crate::decode::FrameCtx::new();1612 let fctx = &crate::decode::FrameCtx::new();
1613 const REFUSAL: &str = "an inter frame with no key frame before it";1613 const REFUSAL: &str = "an inter frame with no key frame before it";
1614 let picture = test_card(64, 64);1614 let picture = test_card(64, 64);
1615- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();1615+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1616 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();1616 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1617 let inter = FrameHeader {1617 let inter = FrameHeader {
1618 frame_type: FrameType::Inter,1618 frame_type: FrameType::Inter,
@@ -1659,7 +1659,7 @@ mod tests {
1659 const REFUSAL: &str =1659 const REFUSAL: &str =
1660 "a reference picture whose height does not match this frame's own true size";1660 "a reference picture whose height does not match this frame's own true size";
1661 let picture = test_card(64, 64);1661 let picture = test_card(64, 64);
1662- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();1662+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1663 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();1663 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1664 let inter = FrameHeader {1664 let inter = FrameHeader {
1665 frame_type: FrameType::Inter,1665 frame_type: FrameType::Inter,
@@ -1736,7 +1736,7 @@ mod tests {
1736 }1736 }
1737 1737
1738 let picture = test_card(64, 64);1738 let picture = test_card(64, 64);
1739- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();1739+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
1740 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();1740 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1741 for slot in 0..NUM_REF_FRAMES as u8 {1741 for slot in 0..NUM_REF_FRAMES as u8 {
1742 let inter = FrameHeader {1742 let inter = FrameHeader {
@@ -2142,7 +2142,7 @@ mod tests {
2142 let fctx = &crate::decode::FrameCtx::new();2142 let fctx = &crate::decode::FrameCtx::new();
2143 for &(width, height) in &[(64usize, 64usize), (216, 96)] {2143 for &(width, height) in &[(64usize, 64usize), (216, 96)] {
2144 let picture = test_card(width, height);2144 let picture = test_card(width, height);
2145- let encoded = encode_key_frame(&picture, 100, 0.5, fctx).unwrap();2145+ let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
2146 let via_tile = decode_key_frame_tile(2146 let via_tile = decode_key_frame_tile(
2147 &encoded.tile,2147 &encoded.tile,
2148 encoded.mi_cols,2148 encoded.mi_cols,
@@ -2179,7 +2179,7 @@ mod tests {
2179 let pictures: Vec<_> = (0..4)2179 let pictures: Vec<_> = (0..4)
2180 .map(|i| panned_test_card(width, height, i * 3))2180 .map(|i| panned_test_card(width, height, i * 3))
2181 .collect();2181 .collect();
2182- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();2182+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
2183 let decoded = decode_stream(&encoded.stream).unwrap();2183 let decoded = decode_stream(&encoded.stream).unwrap();
2184 assert_eq!(decoded.len(), encoded.frames.len());2184 assert_eq!(decoded.len(), encoded.frames.len());
2185 for (i, (got, frame)) in decoded.iter().zip(&encoded.frames).enumerate() {2185 for (i, (got, frame)) in decoded.iter().zip(&encoded.frames).enumerate() {
@@ -2222,7 +2222,7 @@ mod tests {
2222 fn streaming_decode_matches_the_collecting_one() {2222 fn streaming_decode_matches_the_collecting_one() {
2223 let fctx = &crate::decode::FrameCtx::new();2223 let fctx = &crate::decode::FrameCtx::new();
2224 let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect();2224 let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect();
2225- let stream = encode_sequence(&pictures, 100, 0.5, fctx).unwrap().stream;2225+ let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap().stream;
2226 let collected = decode_stream(&stream).unwrap();2226 let collected = decode_stream(&stream).unwrap();
2227 2227
2228 let mut shown = Vec::new();2228 let mut shown = Vec::new();
@@ -2466,7 +2466,7 @@ mod tests {
2466 let pictures: Vec<_> = (0..3)2466 let pictures: Vec<_> = (0..3)
2467 .map(|i| panned_test_card(width, height, i * 3))2467 .map(|i| panned_test_card(width, height, i * 3))
2468 .collect();2468 .collect();
2469- let encoded = encode_sequence(&pictures, 100, 0.5, fctx).unwrap();2469+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
2470 let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, 3);2470 let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, 3);
2471 let decoded = decode_stream(&encoded.stream).unwrap();2471 let decoded = decode_stream(&encoded.stream).unwrap();
2472 assert_eq!(decoded.len(), 3);2472 assert_eq!(decoded.len(), 3);
@@ -2541,7 +2541,7 @@ mod tests {
2541 2541
2542 for run in 0..4 {2542 for run in 0..4 {
2543 let picture = test_card(width, height);2543 let picture = test_card(width, height);
2544- let key = encode_key_frame(&picture, base_q_idx, 0.5, fctx).unwrap();2544+ let key = encode_key_frame_with_ctx(&picture, base_q_idx, 0.5, fctx).unwrap();
2545 let (seq, _) = key_frame_headers(width, height, base_q_idx).unwrap();2545 let (seq, _) = key_frame_headers(width, height, base_q_idx).unwrap();
2546 2546
2547 // Frame 1: hand-coded, intra-only, refreshes slot 0 with a flat2547 // Frame 1: hand-coded, intra-only, refreshes slot 0 with a flat
crates/ec-av1/src/warp.rsmodified+2 -2
@@ -429,7 +429,7 @@ fn clip_pixel(v: i32, fctx: &crate::decode::FrameCtx) -> u16 {
429 /// the stream (`crate::decode::bit_depth`), the same thread-local429 /// the stream (`crate::decode::bit_depth`), the same thread-local
430 /// [`clip_pixel`] already clamps against -- libaom's `bd` parameter.430 /// [`clip_pixel`] already clamps against -- libaom's `bd` parameter.
431 #[allow(clippy::too_many_arguments)]431 #[allow(clippy::too_many_arguments)]
432-pub fn warp_affine(432+pub(crate) fn warp_affine(
433 params: &WarpParams,433 params: &WarpParams,
434 reference: &[u16],434 reference: &[u16],
435 width: i32,435 width: i32,
@@ -477,7 +477,7 @@ pub fn warp_affine(
477 /// [`mc::predict_compound_intermediate`]'s for477 /// [`mc::predict_compound_intermediate`]'s for
478 /// [`mc::combine_compound`]/[`mc::blend_masked_compound`].478 /// [`mc::combine_compound`]/[`mc::blend_masked_compound`].
479 #[allow(clippy::too_many_arguments)]479 #[allow(clippy::too_many_arguments)]
480-pub fn warp_affine_compound(480+pub(crate) fn warp_affine_compound(
481 params: &WarpParams,481 params: &WarpParams,
482 reference: &[u16],482 reference: &[u16],
483 width: i32,483 width: i32,