forge
Explore
Log in

Don't you dare go Hollow

Re-take the byte pins under the default pyramid

Browse files at this commit

ef22613d3ddf2f1b59f93eb5ff5fcb0b3aba19ceAhmet Kaan GümüşParent: 534fad0
  • test
    • re-take the byte pins under the default pyramid
    • zip the rate census in coding order
Show full message
test(av1): re-take the byte pins under the default pyramid; zip the rate census in coding order

EncodedSequence now carries coding_order, the map from coding order (what a
per-coded-frame census counts) to the display-order frames.
crates/ec-av1/src/encode.rsmodified+41 -5
@@ -9000,8 +9000,15 @@ pub struct EncodedSequence {
90009000 /// `stream` (a temporal delimiter and that frame's OBU alone; it reuses
90019001 /// the sequence header the key frame carried).
90029002 pub stream: Vec<u8>,
9003- /// One entry per picture, in coding order.
9003+ /// One entry per picture, in DISPLAY order — the order a decoder outputs
9004+ /// them and the order `pictures` came in. Without a pyramid that is also
9005+ /// the coding order; with one the two differ, and `coding_order` is the
9006+ /// map between them.
90049007 pub frames: Vec<Encoded>,
9008+ /// The index into `frames` of each coded frame, in CODING order — what a
9009+ /// per-coded-frame census (`take_predicted_bits`) must be zipped against.
9010+ /// `0..frames.len()` on the flat path.
9011+ pub coding_order: Vec<usize>,
90059012 }
90069013
90079014 /// Encodes a sequence of pictures as a key frame followed by one inter frame
@@ -9130,7 +9137,11 @@ pub(crate) fn encode_sequence_with_ctx(
91309137 ));
91319138 frames.push(crop_encoded(&inter, render.0, render.1));
91329139 }
9133- Ok(EncodedSequence { stream, frames })
9140+ Ok(EncodedSequence {
9141+ stream,
9142+ coding_order: (0..frames.len()).collect(),
9143+ frames,
9144+ })
91349145 }
91359146
91369147 #[cfg(test)]
@@ -11407,11 +11418,24 @@ mod tests {
1140711418 // on that side, so the two directions no longer share a bound.
1140811419 let mut worst_over: f64 = 0.0;
1140911420 let mut worst_under: f64 = 0.0;
11410- for (i, (frame, &bits)) in encoded.frames.iter().zip(&predicted).enumerate() {
11421+ // The census is per CODED frame, so it is zipped in coding order --
11422+ // which is not display order under a pyramid.
11423+ let coded: Vec<&Encoded> =
11424+ encoded.coding_order.iter().map(|&i| &encoded.frames[i]).collect();
11425+ for (i, (frame, &bits)) in coded.into_iter().zip(&predicted).enumerate() {
1141111426 let written = frame.tile.len() as f64 * 8.0;
1141211427 let drift = (written - bits) / written;
1141311428 worst_over = worst_over.max(-drift);
11414- worst_under = worst_under.max(drift);
11429+ // lane-av1pyrdef: a pyramid LEAF codes almost no coefficients at
11430+ // all (150-250 bits of tile, nearly all of it partition/mode/mv
11431+ // syntax the coefficient sum never counts), so its ratio measures
11432+ // that floor rather than any drift. Frames under 512 written bits
11433+ // are left out of the under-price bound for that reason; the
11434+ // over-price bound -- the defect direction, where the search pays
11435+ // MORE than the writer -- still covers every frame.
11436+ if written >= 512.0 {
11437+ worst_under = worst_under.max(drift);
11438+ }
1141511439 eprintln!("{i:5} {bits:14.0} {written:12.0} {:+6.2}%", drift * 100.0);
1141611440 }
1141711441 // Measured 2026-09-06 on this sequence: -13.5% at the key frame,
@@ -11447,6 +11471,11 @@ mod tests {
1144711471 // decisions, so this bound and the byte pins above FAIL BY DESIGN
1144811472 // under it; the default path (no motion_mode syntax at all) is the
1144911473 // one they are measured on.
11474+ // lane-av1pyrdef: `encode_sequence` codes this fixture under the
11475+ // coding pyramid now, so the five frames are a key frame, a hidden
11476+ // ALTREF at q-16 and three leaves at q+8: +2.6% / +6.9% (the two
11477+ // frames over the 512-bit floor) and +44.7 / +74.4 / +74.4 on the
11478+ // near-empty leaves below it. Both bounds stand where they were.
1145011479 // lane-av1rejudge: local warp is ON by default now, so every eligible
1145111480 // single-reference block carries that same `motion_mode` symbol (a
1145211481 // 3-value alphabet where a warp sample exists) on the DEFAULT path --
@@ -12524,8 +12553,15 @@ mod tests {
1252412553 (h ^ u64::from(v)).wrapping_mul(0x0000_0100_0000_01b3)
1252512554 })
1252612555 };
12556+ // Re-taken on lane-av1pyrdef: `encode_sequence` codes this (non-screen)
12557+ // clip under the coding pyramid now -- one hidden ALTREF per mini-GOP
12558+ // of 4, its leaves at q+8 and a `show_existing_frame` header per
12559+ // group. 7299 -> 8194 bytes at q=150 and 26804 -> 28285 at q=60 over
12560+ // four frames; four pictures is one short mini-GOP, which is the
12561+ // shape that pays least (the ARF's own quality has no later group to
12562+ // carry it), so this is not the BD gate's number.
1252712563 let pins: [(u8, usize, u64); 2] =
12528- [(150, 7299, 0xaa98_12b4_860a_28cc), (60, 26804, 0xedea_182d_e11b_3c3f)];
12564+ [(150, 8194, 0x08ba_a7a8_26f6_f414), (60, 28285, 0x64af_fc52_eef6_2967)];
1252912565 for (q, bytes, hash) in pins {
1253012566 let encoded = encode_sequence(&source, q, 0.5).unwrap();
1253112567 assert_eq!(
crates/ec-av1/src/encoder.rsmodified+10 -4
@@ -1016,11 +1016,17 @@ impl Av1Encoder {
10161016 stream.extend_from_slice(&packet.data);
10171017 }
10181018 let mut collected = encoder.collected.take().expect("collecting");
1019+ // Every source picture is coded exactly once, so a frame's display
1020+ // order IS its index once the list is sorted by it.
1021+ let coding_order: Vec<usize> =
1022+ collected.iter().map(|(order, _)| *order as usize).collect();
10191023 collected.sort_by_key(|(order, _)| *order);
1020- Ok(crate::encode::EncodedSequence {
1021- stream,
1022- frames: collected.into_iter().map(|(_, encoded)| encoded).collect(),
1023- })
1024+ let frames: Vec<Encoded> = collected.into_iter().map(|(_, encoded)| encoded).collect();
1025+ assert!(
1026+ coding_order.iter().all(|&i| i < frames.len()),
1027+ "a coded frame's display position is outside the sequence"
1028+ );
1029+ Ok(crate::encode::EncodedSequence { stream, frames, coding_order })
10241030 }
10251031
10261032 /// Stamps a packet with its display and coding positions and advances the