forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-t900' (c3a3efaa): four more refusals proven (motion_mode row enumeration, tile-group parser invariant, two negative gates); 21 of 40 proven

Browse files at this commit

d68cdb0f9224ba9d7701c9b13937aaf5c66cd329Ahmet Kaan GümüşParent: 3f6ede52eab33d
crates/ec-av1/src/decode.rsmodified+107 -24
@@ -7734,6 +7734,110 @@ fn every_intra_in_inter_shape_the_census_lists_has_a_size_group_row() {
7734 );7734 );
7735 }7735 }
7736 7736
7737+/// The `motion_mode` / `obmc` CDF row for a block footprint: libaom's
7738+/// `motion_mode_cdf[mbmi->bsize]`, in this crate's packed row order (which
7739+/// `cdf::MOTION_MODE` documents -- the 128-px rows come last, so they are
7740+/// matched before the square arm's `log2` shortcut).
7741+///
7742+/// `None` is the refusal "a motion_mode symbol for a block shape with no CDF
7743+/// row here"; the enumeration below is what proves no conformant block can
7744+/// reach it.
7745+pub(crate) fn motion_mode_cdf_row(write_w: usize, write_h: usize) -> Option<usize> {
7746+ Some(match (write_w, write_h) {
7747+ // lane-sb128c r5: the 128 root's own rows come FIRST -- the square arm
7748+ // below maps 128 to row 4 (BLOCK_16X32).
7749+ (64, 128) => 14,
7750+ (128, 64) => 15,
7751+ (128, 128) => 16,
7752+ (w, h) if w == h => (w.trailing_zeros() - 3) as usize,
7753+ (16, 32) => 4,
7754+ (32, 16) => 5,
7755+ (32, 64) => 6,
7756+ (64, 32) => 7,
7757+ (8, 32) => 8,
7758+ (32, 8) => 9,
7759+ (16, 64) => 10,
7760+ (64, 16) => 11,
7761+ // lane-inter4 r3: the 16x16-level rect inter leaves.
7762+ (8, 16) => 12,
7763+ (16, 8) => 13,
7764+ _ => return None,
7765+ })
7766+}
7767+
7768+/// Every `BLOCK_SIZES_ALL` footprint, as `(width, height)` in pixels: the six
7769+/// squares, the ten 2:1 shapes and the six 1:4 ones (libaom `common_data.h`,
7770+/// `block_size_wide`/`block_size_high`).
7771+#[cfg(test)]
7772+const BLOCK_SIZES_ALL_WH: [(usize, usize); 22] = [
7773+ (4, 4),
7774+ (4, 8),
7775+ (8, 4),
7776+ (8, 8),
7777+ (8, 16),
7778+ (16, 8),
7779+ (16, 16),
7780+ (16, 32),
7781+ (32, 16),
7782+ (32, 32),
7783+ (32, 64),
7784+ (64, 32),
7785+ (64, 64),
7786+ (64, 128),
7787+ (128, 64),
7788+ (128, 128),
7789+ (4, 16),
7790+ (16, 4),
7791+ (8, 32),
7792+ (32, 8),
7793+ (16, 64),
7794+ (64, 16),
7795+];
7796+
7797+/// lane-t900 r25, enumeration: the refusal "a motion_mode symbol for a block
7798+/// shape with no CDF row here" names a shape no conformant stream can present.
7799+///
7800+/// A `motion_mode`/`obmc` symbol is read only under `motion_mode_eligible`,
7801+/// whose `write_w.min(write_h) >= 8` clause is libaom's
7802+/// `is_motion_variation_allowed_bsize` (`blockd.h:1455`). So the reachable
7803+/// domain of [`motion_mode_cdf_row`] is exactly the `BLOCK_SIZES_ALL`
7804+/// footprints with `min(bw, bh) >= 8` -- 17 of the 22 -- and each of those
7805+/// must map to a distinct row of the 17-row `Cdfs::motion_mode` table. The
7806+/// five it excludes (4x4, 4x8, 8x4, 4x16, 16x4) are the ones the eligibility
7807+/// clause rejects before the lookup.
7808+#[test]
7809+fn every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row() {
7810+ let mut rows = std::collections::BTreeSet::new();
7811+ let mut excluded = 0;
7812+ for (w, h) in BLOCK_SIZES_ALL_WH {
7813+ if w.min(h) < 8 {
7814+ excluded += 1;
7815+ assert!(
7816+ w == 4 || h == 4,
7817+ "{w}x{h} is not one of the sub-8 shapes is_motion_variation_allowed_bsize rejects"
7818+ );
7819+ continue;
7820+ }
7821+ let row = motion_mode_cdf_row(w, h).unwrap_or_else(|| {
7822+ panic!(
7823+ "a {w}x{h} block passes is_motion_variation_allowed_bsize and reads a motion_mode \
7824+ symbol, but has no CDF row -- the refusal is a real gap, not a dead arm"
7825+ )
7826+ });
7827+ assert!(
7828+ row < 17,
7829+ "{w}x{h} maps to motion_mode row {row}, outside the 17-row table"
7830+ );
7831+ assert!(rows.insert(row), "{w}x{h} shares motion_mode row {row}");
7832+ }
7833+ assert_eq!(excluded, 5, "the sub-8 footprint set changed");
7834+ assert_eq!(
7835+ rows.len(),
7836+ 17,
7837+ "17 eligible footprints must fill all 17 rows of the motion_mode table"
7838+ );
7839+}
7840+
7737 fn decode_intra_rect_in_inter(7841 fn decode_intra_rect_in_inter(
7738 dec: &mut SymbolDecoder,7842 dec: &mut SymbolDecoder,
7739 cdfs: &mut Cdfs,7843 cdfs: &mut Cdfs,
@@ -22342,30 +22446,9 @@ fn decode_inter_block(
22342 // documented on `cdf::MOTION_MODE`); a wrong row is a wrong22446 // documented on `cdf::MOTION_MODE`); a wrong row is a wrong
22343 // interval narrowing, not a wrong value (class22447 // interval narrowing, not a wrong value (class
22344 // wrong-alphabet-same-value).22448 // wrong-alphabet-same-value).
22345- let bsize_idx = match (write_w, write_h) {22449+ let bsize_idx = motion_mode_cdf_row(write_w, write_h).ok_or_else(|| {
22346- // lane-sb128c r5: the 128 root's own rows come FIRST --22450+ unsupported("a motion_mode symbol for a block shape with no CDF row here")
22347- // the square arm below maps 128 to row 4 (BLOCK_16X32).22451+ })?;
22348- (64, 128) => 14,
22349- (128, 64) => 15,
22350- (128, 128) => 16,
22351- (w, h) if w == h => (w.trailing_zeros() - 3) as usize,
22352- (16, 32) => 4,
22353- (32, 16) => 5,
22354- (32, 64) => 6,
22355- (64, 32) => 7,
22356- (8, 32) => 8,
22357- (32, 8) => 9,
22358- (16, 64) => 10,
22359- (64, 16) => 11,
22360- // lane-inter4 r3: the 16x16-level rect inter leaves.
22361- (8, 16) => 12,
22362- (16, 8) => 13,
22363- _ => {
22364- return Err(unsupported(
22365- "a motion_mode symbol for a block shape with no CDF row here",
22366- ));
22367- }
22368- };
22369 // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf`22452 // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf`
22370 // instead of the 2-symbol `obmc_cdf` exactly when22453 // instead of the 2-symbol `obmc_cdf` exactly when
22371 // `num_proj_ref >= 1` under `allow_warped_motion`.22454 // `num_proj_ref >= 1` under `allow_warped_motion`.
crates/ec-av1/src/refusal_inventory.rsmodified+27 -0
@@ -262,6 +262,33 @@ const PROVEN: &[(&str, &str)] = &[
262 "a Golomb tail longer than this decoder reads",262 "a Golomb tail longer than this decoder reads",
263 "read_golomb_reads_every_value_a_conformant_stream_can_carry",263 "read_golomb_reads_every_value_a_conformant_stream_can_carry",
264 ),264 ),
265+ // lane-t900 r25, enumeration: `parse_tile_group` is the only producer of
266+ // the `tiles` vector `decode_stream` tests, and its success path always
267+ // pushes at least one `Tile` -- swept over a real frame OBU's tile payload
268+ // truncated from empty upwards.
269+ (
270+ "a frame OBU with no tile group",
271+ "a_frame_obu_that_parses_always_carries_at_least_one_tile",
272+ ),
273+ // lane-t900 r25, negative gates: hand-built streams that reach each
274+ // refusal by name and output no picture (a `show_existing_frame` header
275+ // over all 8 empty slots; a stream that opens on an inter frame).
276+ (
277+ "a show_existing_frame header naming an empty reference slot",
278+ "a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name",
279+ ),
280+ (
281+ "an inter frame with no key frame before it",
282+ "an_inter_frame_opening_a_stream_is_refused_by_name",
283+ ),
284+ // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under
285+ // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17
286+ // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of
287+ // the 17-row table.
288+ (
289+ "a motion_mode symbol for a block shape with no CDF row here",
290+ "every_shape_that_allows_motion_variation_has_a_motion_mode_cdf_row",
291+ ),
265 (292 (
266 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",293 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
267 "a_twelve_bit_sequence_header_is_refused_by_name",294 "a_twelve_bit_sequence_header_is_refused_by_name",
crates/ec-av1/src/stream.rsmodified+156 -0
@@ -1168,6 +1168,162 @@ mod tests {
1168 );1168 );
1169 }1169 }
1170 1170
1171+ /// lane-t900 r25: the refusal "a frame OBU with no tile group" names a
1172+ /// shape the parser cannot hand [`decode_stream`].
1173+ ///
1174+ /// `tiles` reaches that check from exactly two places -- `ObuKind::Frame`'s
1175+ /// own vector and the `ObuKind::TileGroup` accumulation -- and both are
1176+ /// filled by `ec_av1_syntax`'s `parse_tile_group`, whose only success path
1177+ /// pushes one `Tile` per `tile_num` of the INCLUSIVE range
1178+ /// `tg_start..=tg_end`. That range is never empty: the single-tile-group
1179+ /// case takes `(0, num_tiles - 1)` saturating at 0, and the multi-group
1180+ /// case rejects `end < start` as corrupt. So an `OBU_FRAME` either fails to
1181+ /// parse or carries at least one tile, however short its payload is --
1182+ /// including the empty payload the charter for this round asked to build,
1183+ /// which parses into ONE zero-byte tile rather than none.
1184+ ///
1185+ /// Sweeping a real frame OBU's tile payload from empty upwards asserts both
1186+ /// halves: every `Frame` OBU that parses has a tile, and `decode_stream`
1187+ /// never reports this refusal for any of them.
1188+ #[test]
1189+ fn a_frame_obu_that_parses_always_carries_at_least_one_tile() {
1190+ const REFUSAL: &str = "a frame OBU with no tile group";
1191+ let picture = test_card(64, 64);
1192+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
1193+ let (seq, header) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1194+ let mut frame_obus_parsed = 0;
1195+ for len in 0..=encoded.tile.len().min(24) {
1196+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
1197+ stream.extend_from_slice(
1198+ &crate::frame::frame_obu(&seq, &header, &encoded.tile[..len]).unwrap(),
1199+ );
1200+ let mut parser = Av1Parser::new();
1201+ let mut pos = 0usize;
1202+ while pos < stream.len() {
1203+ let Ok(obu) = parser.parse_obu(&stream[pos..]) else {
1204+ break;
1205+ };
1206+ pos += obu.total_size;
1207+ if let ObuKind::Frame(_, tiles) = &obu.kind {
1208+ frame_obus_parsed += 1;
1209+ assert!(
1210+ !tiles.is_empty(),
1211+ "a {len}-byte tile payload parsed into a frame OBU with no tile group -- \
1212+ the refusal {REFUSAL:?} is reachable after all"
1213+ );
1214+ }
1215+ }
1216+ if let Err(e) = decode_stream(&stream) {
1217+ let e = e.to_string();
1218+ assert!(
1219+ !e.contains(REFUSAL),
1220+ "a {len}-byte tile payload reached {REFUSAL:?}: {e}"
1221+ );
1222+ }
1223+ }
1224+ assert!(
1225+ frame_obus_parsed >= 2,
1226+ "the sweep parsed {frame_obus_parsed} frame OBUs -- it proves nothing about the \
1227+ refusal's reachability"
1228+ );
1229+ }
1230+
1231+ /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a
1232+ /// slot no frame has refreshed is refused BY NAME, and outputs no picture.
1233+ ///
1234+ /// The OBU is hand-built because [`crate::frame::write_frame_header`]
1235+ /// refuses to write one (it writes shown key and inter frames only): spec
1236+ /// 5.9.2's whole header for this case is `show_existing_frame` (1) plus
1237+ /// `frame_to_show_map_idx` (3), the sequence carrying neither a decoder
1238+ /// model nor frame ids.
1239+ ///
1240+ /// Deviation from the round's charter, which asked for a key frame first
1241+ /// with the named slot's `refresh_frame_flags` bit clear: a SHOWN key frame
1242+ /// refreshes every slot (spec 5.9.2 forces `refresh_frame_flags` to
1243+ /// `all_frames` and does not code it, which is also what
1244+ /// `write_frame_header` does), so the only reachable empty-slot stream is
1245+ /// one where no frame has refreshed that slot yet. The stream below is a
1246+ /// valid sequence header followed by the header OBU, and every one of the
1247+ /// eight slots is tried.
1248+ #[test]
1249+ fn a_show_existing_frame_header_naming_an_empty_slot_is_refused_by_name() {
1250+ const REFUSAL: &str = "a show_existing_frame header naming an empty reference slot";
1251+ let (seq, _) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1252+ for slot in 0..NUM_REF_FRAMES as u32 {
1253+ let mut w = ec_core::BitWriter::new();
1254+ w.write_bit(true); // show_existing_frame
1255+ w.write_bits(slot, 3); // frame_to_show_map_idx
1256+ crate::bits::write_byte_alignment(&mut w);
1257+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
1258+ stream.extend_from_slice(&crate::obu::wrap_obu(
1259+ &ec_av1_syntax::obu::ObuHeader {
1260+ obu_type: ec_av1_syntax::obu::ObuType::FrameHeader,
1261+ extension_flag: false,
1262+ has_size_field: true,
1263+ temporal_id: 0,
1264+ spatial_id: 0,
1265+ },
1266+ &w.into_bytes(),
1267+ ));
1268+
1269+ let mut shown = 0;
1270+ let err = decode_stream_with(&stream, |_, _, _| {
1271+ shown += 1;
1272+ Ok(())
1273+ })
1274+ .unwrap_err()
1275+ .to_string();
1276+ assert!(
1277+ err.contains(REFUSAL),
1278+ "slot {slot}: expected {REFUSAL:?}, got: {err}"
1279+ );
1280+ assert_eq!(shown, 0, "slot {slot}: an empty slot was output as a picture");
1281+ }
1282+ }
1283+
1284+ /// lane-t900 r25, negative gate: an inter frame whose `ref_frame_idx[0]`
1285+ /// slot holds no picture -- a stream that opens on an inter frame -- is
1286+ /// refused BY NAME rather than predicting from nothing.
1287+ ///
1288+ /// Deviation from the round's charter, which asked for a real aomenc
1289+ /// two-frame stream with the key frame's OBUs stripped: this crate's own
1290+ /// `write_frame_header` writes a shown INTER frame (short reference
1291+ /// signalling and non-identity global motion are the parts it refuses), so
1292+ /// the fixture is built from the writers, needs neither ffmpeg nor aomenc,
1293+ /// and is byte-identical on every run. The tile payload is a real key
1294+ /// frame's; the refusal fires on the header's reference lookup, before any
1295+ /// tile is decoded.
1296+ #[test]
1297+ fn an_inter_frame_opening_a_stream_is_refused_by_name() {
1298+ const REFUSAL: &str = "an inter frame with no key frame before it";
1299+ let picture = test_card(64, 64);
1300+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
1301+ let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
1302+ let inter = FrameHeader {
1303+ frame_type: FrameType::Inter,
1304+ frame_is_intra: false,
1305+ // Keeps `primary_ref_frame`, `frame_size_with_refs` and
1306+ // `use_ref_frame_mvs` out of the written header (spec 5.9.2).
1307+ error_resilient_mode: true,
1308+ primary_ref_frame: PRIMARY_REF_NONE,
1309+ refresh_frame_flags: 0x02,
1310+ order_hint: 1,
1311+ ..key
1312+ };
1313+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
1314+ stream.extend_from_slice(&crate::frame::frame_obu(&seq, &inter, &encoded.tile).unwrap());
1315+
1316+ let mut shown = 0;
1317+ let err = decode_stream_with(&stream, |_, _, _| {
1318+ shown += 1;
1319+ Ok(())
1320+ })
1321+ .unwrap_err()
1322+ .to_string();
1323+ assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}");
1324+ assert_eq!(shown, 0, "an inter frame with no reference produced a picture");
1325+ }
1326+
1171 /// lane-interedge r1: one attempt of the inter frame-edge half-strip gate --1327 /// lane-interedge r1: one attempt of the inter frame-edge half-strip gate --
1172 /// encode `width x height` with real aomenc (rect partitions ON, every other1328 /// encode `width x height` with real aomenc (rect partitions ON, every other
1173 /// lane's open tool pinned off), decode it, and return1329 /// lane's open tool pinned off), decode it, and return