forge
Explore
Log in

Don't you dare go Hollow

Lossless INTER frames decode -- the chroma plane is 4x4 units, plane-major

Browse files at this commit

5136c0f114622e14055c3dc9883b76f7487f7b9aAhmet Kaan GümüşParent: f60365c
  • feat
    • lossless INTER frames decode -- the chroma plane is 4x4 units, plane-major
Show full message
feat(av1): lossless INTER frames decode -- the chroma plane is 4x4 units, plane-major

A lossless frame codes TX_4X4 on every plane (libaom read_tx_size returns
TX_4X4 before it ever consults max_txsize_rect_lookup), and
decode_token_recon_block walks a 64x64 mu chunk PLANE-MAJOR
(for (plane..) for (blk_row..) for (blk_col..)). The inter readers still
read chroma as one transform per block, so a lossless inter frame was
refused by name; they now walk the 4x4 units, and the refusal is gone.

Three defects the previous lane's gate could not see (its source had a FLAT
chroma plane, so every chroma unit coded one txb_skip symbol against
all-zero contexts -- class gate-blind-to-feature):

- decode_block read its chroma units interleaved U,V per unit instead of
  plane-major. Identical order at one unit per plane per chunk (every
  non-lossless case), wrong for a lossless block's 4x4 raster.
- decode_rect_split's lossless chroma branch stamped each unit's neighbour
  context and then let record_split_luma_rect_mi overwrite all of them with
  the LAST unit's state, so the next block read dc_sign_ctx 1 where libaom
  reads 0 (class override-slot-on-one-arm).
- decode_inter_sub8_rect2 kept one 8x4/4x8 luma transform on a lossless
  frame, which fed a rect grid to the 4x4 Walsh-Hadamard.

Gates: the key gate's source is now textured chroma, and
a_lossless_libaom_inter_frame_decodes_sample_exact replaces the retired
refusal gate with four libaom -crf 0 fixtures (256x128 8-bit, 192x96
10-bit, 320x192, 256x256 --sb-size=128), each sample-exact vs ffmpeg.
crates/ec-av1/src/decode.rsmodified+354 -26
@@ -6172,7 +6172,7 @@ fn read_coeffs(
6172 if coeff_trace_on() {6172 if coeff_trace_on() {
6173 let (rng, _) = dec.debug_state();6173 let (rng, _) = dec.debug_state();
6174 eprintln!(6174 eprintln!(
6175- "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng}",6175+ "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} dcctx={sign_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng}",
6176 coding.side,6176 coding.side,
6177 all_zero as i326177 all_zero as i32
6178 );6178 );
@@ -9546,6 +9546,13 @@ fn decode_rect_split(
9546 }9546 }
9547 }9547 }
9548 // CHROMA: one un-split rect transform for the whole strip.9548 // CHROMA: one un-split rect transform for the whole strip.
9549+ // lane-lossless2: except on a lossless frame, where it is a raster of 4x4
9550+ // units -- each stamps its own neighbour context as it is read, and the
9551+ // whole-block `record_split_luma_rect_mi` below would overwrite all of
9552+ // them with the LAST unit's state (class `override-slot-on-one-arm`: the
9553+ // next block then read `dc_sign_ctx` 1 where libaom reads 0). They are
9554+ // collected here and replayed after that record.
9555+ let mut ll_chroma_units: Vec<((usize, usize), usize, Grid)> = Vec::new();
9549 let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));9556 let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));
9550 let reach = block_reach;9557 let reach = block_reach;
9551 let (u_grid, v_grid) = if m.skip {9558 let (u_grid, v_grid) = if m.skip {
@@ -9611,6 +9618,7 @@ fn decode_rect_split(
9611 None, offset, m.smooth_neighbor_uv, fctx,9618 None, offset, m.smooth_neighbor_uv, fctx,
9612 )?;9619 )?;
9613 neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_idx, &grid);9620 neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_idx, &grid);
9621+ ll_chroma_units.push((cu_mi, plane_idx, grid.clone()));
9614 last[plane_idx - 1] = grid;9622 last[plane_idx - 1] = grid;
9615 }9623 }
9616 }9624 }
@@ -9695,6 +9703,9 @@ fn decode_rect_split(
9695 m.uv_predict_mode,9703 m.uv_predict_mode,
9696 [&u_grid, &v_grid],9704 [&u_grid, &v_grid],
9697 );9705 );
9706+ for (cu_mi, plane, unit) in &ll_chroma_units {
9707+ neighbours.record_mi_chroma(*cu_mi, 8, 8, *plane, unit);
9708+ }
9698 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);9709 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);
9699 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx);9710 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx);
9700 if crate::envflags::env_flag!("EC_AV1_TRACE") {9711 if crate::envflags::env_flag!("EC_AV1_TRACE") {
@@ -14455,6 +14466,16 @@ fn decode_block(
14455 // identical at every size up to 64x64, but a 128x128 block's 64x64 uv14466 // identical at every size up to 64x64, but a 128x128 block's 64x64 uv
14456 // plane block adjusts TX_64X64 down to TX_32X32, so each plane is14467 // plane block adjusts TX_64X64 down to TX_32X32, so each plane is
14457 // FOUR units (lane-sb128b r2) -- one per mu chunk.14468 // FOUR units (lane-sb128b r2) -- one per mu chunk.
14469+ // libaom `decode_token_recon_block` codes a mu chunk PLANE-MAJOR
14470+ // (`for (plane..) for (blk_row..) for (blk_col..)`): every U unit of
14471+ // the chunk, then every V unit. At one unit per plane per chunk --
14472+ // every non-lossless case this decoder reaches -- that is the same
14473+ // symbol order as the interleaved pair this loop used to read; a
14474+ // lossless frame's 4x4 chroma units are the case where it differs
14475+ // (lane-lossless2).
14476+ let mut u_pass: Vec<Grid> = Vec::new();
14477+ for plane_pass in 1..=2usize {
14478+ let mut pass_idx = 0usize;
14458 for cu_row in ch_row * cpc..(ch_row + 1) * cpc {14479 for cu_row in ch_row * cpc..(ch_row + 1) * cpc {
14459 for cu_col in ch_col * cpc..(ch_col + 1) * cpc {14480 for cu_col in ch_col * cpc..(ch_col + 1) * cpc {
14460 // The chroma context arrays are indexed in LUMA mi, so this14481 // The chroma context arrays are indexed in LUMA mi, so this
@@ -14476,24 +14497,21 @@ fn decode_block(
14476 )14497 )
14477 };14498 };
14478 let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx);14499 let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx);
14479- if let Some((ub, _)) = &palette_uv_bufs {14500+ if let Some((ub, vb)) = &palette_uv_bufs {
14480- set_palette_pred(ub.clone(), fctx);14501+ set_palette_pred(
14481- }14502+ if plane_pass == 1 { ub.clone() } else { vb.clone() },
14482- let u_grid = read_plane(14503+ fctx,
14483- dec, cdfs, chroma_set, scans.1, 1, cu_around[1], mode,14504+ );
14484- uv_predict_mode, angle_delta_uv, cu_reach, u, cu_x, cu_y,
14485- chroma_tx, chroma_tx, base_q_idx,
14486- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
14487- None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
14488- )?;
14489- if let Some((_, vb)) = &palette_uv_bufs {
14490- set_palette_pred(vb.clone(), fctx);
14491 }14505 }
14492- let v_grid = read_plane(14506+ let buf: &mut PlaneBuf<'static> =
14493- dec, cdfs, chroma_set, scans.1, 2, cu_around[2], mode,14507+ if plane_pass == 1 { &mut *u } else { &mut *v };
14494- uv_predict_mode, angle_delta_uv, cu_reach, v, cu_x, cu_y,14508+ let cu_grid = read_plane(
14509+ dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode,
14510+ uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y,
14495 chroma_tx, chroma_tx, base_q_idx,14511 chroma_tx, chroma_tx, base_q_idx,
14496- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),14512+ alpha.zip(ac).map(|((au, av), ac)| {
14513+ (if plane_pass == 1 { au } else { av }, ac)
14514+ }),
14497 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,14515 None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
14498 )?;14516 )?;
14499 if cn > 1 {14517 if cn > 1 {
@@ -14504,15 +14522,23 @@ fn decode_block(
14504 // 1 from this left neighbour -- measured against aomdec).14522 // 1 from this left neighbour -- measured against aomdec).
14505 // The same writes are replayed after `record_split_luma`14523 // The same writes are replayed after `record_split_luma`
14506 // below, which would otherwise clobber them whole-block.14524 // below, which would otherwise clobber them whole-block.
14507- neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 1, &u_grid);14525+ neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &cu_grid);
14508- neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 2, &v_grid);
14509- units.push((cu_mi, luma_span, u_grid.clone(), v_grid.clone()));
14510 }14526 }
14511- last_grids = [u_grid, v_grid];14527+ if plane_pass == 1 {
14528+ u_pass.push(cu_grid);
14529+ } else {
14530+ let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0));
14531+ if cn > 1 {
14532+ units.push((cu_mi, luma_span, u_grid.clone(), cu_grid.clone()));
14533+ }
14534+ last_grids = [u_grid, cu_grid];
14535+ }
14536+ pass_idx += 1;
14512 }14537 }
14513 }14538 }
14514 }14539 }
14515 }14540 }
14541+ }
14516 // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma14542 // Mode/side bookkeeping plus, at `cn == 1`, the whole-plane chroma
14517 // context write; at `cn > 1` the per-unit writes above are what the14543 // context write; at `cn > 1` the per-unit writes above are what the
14518 // next block reads, so they run after this (last writer wins).14544 // next block reads, so they run after this (last writer wins).
@@ -24427,6 +24453,190 @@ fn read_inter_plane(
24427 Ok((grid, tx_type))24453 Ok((grid, tx_type))
24428 }24454 }
24429 24455
24456+/// The intra twin of [`read_inter_chroma_lossless`]: an INTRA block inside a
24457+/// lossless frame codes its chroma plane as 4x4 transform units, plane-major
24458+/// inside each 64x64 mu chunk (libaom `decode_token_recon_block`'s
24459+/// `for (plane..) for (blk_row..) for (blk_col..)` with `av1_get_tx_size`
24460+/// returning TX_4X4 under `xd->lossless[..]`). CfL never rides here:
24461+/// `is_cfl_allowed` (`blockd.h`) needs a BLOCK_4X4 chroma plane block, i.e. a
24462+/// luma block of 8x8 or less, which the sub-8x8 readers own.
24463+#[allow(clippy::too_many_arguments)]
24464+fn read_intra_chroma_lossless(
24465+ dec: &mut SymbolDecoder,
24466+ cdfs: &mut Cdfs,
24467+ neighbours: &mut Neighbours,
24468+ u: &mut PlaneBuf<'static>,
24469+ v: &mut PlaneBuf<'static>,
24470+ at_mi: (usize, usize),
24471+ (px, py): (usize, usize),
24472+ (cpx, cpy): (usize, usize),
24473+ side: usize,
24474+ (blk_w, blk_h): (usize, usize),
24475+ (org_x, org_y): (usize, usize),
24476+ (reg_w, reg_h): (usize, usize),
24477+ stride: usize,
24478+ reach: Reach,
24479+ (frame_w, frame_h): (usize, usize),
24480+ mode: usize,
24481+ uv_predict_mode: usize,
24482+ angle_delta_uv: i32,
24483+ palette_uv_bufs: Option<(&[u16], &[u16])>,
24484+ smooth_neighbor_uv: bool,
24485+ base_q_idx: u8,
24486+ u_out: &mut Vec<i32>,
24487+ v_out: &mut Vec<i32>,
24488+ fctx: &crate::decode::FrameCtx,
24489+) -> Result<()> {
24490+ let scan4 = default_scan(4);
24491+ let offset = (blk_w > 4 || blk_h > 4).then_some(3);
24492+ for plane_idx in 1..3 {
24493+ for rr in 0..reg_h / 4 {
24494+ for cc in 0..reg_w / 4 {
24495+ let (ox, oy) = (org_x + cc * 4, org_y + rr * 4);
24496+ let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2);
24497+ let cu_around = neighbours.around_mi(cu_mi, 8);
24498+ let cu_reach = tu_reach(
24499+ side, side, ox * 2, oy * 2, 8, reach, px, py, frame_w, frame_h, fctx,
24500+ );
24501+ if let Some((ub, vb)) = palette_uv_bufs {
24502+ set_palette_pred(
24503+ if plane_idx == 1 { ub.to_vec() } else { vb.to_vec() },
24504+ fctx,
24505+ );
24506+ }
24507+ let buf: &mut PlaneBuf<'static> =
24508+ if plane_idx == 1 { &mut *u } else { &mut *v };
24509+ let cu_grid = read_plane(
24510+ dec,
24511+ cdfs,
24512+ TxbSet::Chroma4,
24513+ &scan4,
24514+ plane_idx,
24515+ cu_around[plane_idx],
24516+ mode,
24517+ uv_predict_mode,
24518+ angle_delta_uv,
24519+ cu_reach,
24520+ buf,
24521+ cpx + ox,
24522+ cpy + oy,
24523+ 4,
24524+ 4,
24525+ base_q_idx,
24526+ None,
24527+ None,
24528+ offset,
24529+ smooth_neighbor_uv,
24530+ fctx,
24531+ )?;
24532+ neighbours.record_mi_chroma(cu_mi, 8, 8, plane_idx, &cu_grid);
24533+ hit!(CHROMA_SPLIT_TX_HITS);
24534+ let dst = mu_units(
24535+ if plane_idx == 1 { &mut *u_out } else { &mut *v_out },
24536+ stride * stride,
24537+ );
24538+ for row in 0..4 {
24539+ let start = (oy + row) * stride + ox;
24540+ dst[start..start + 4].copy_from_slice(&cu_grid[row * 4..][..4]);
24541+ }
24542+ }
24543+ }
24544+ }
24545+ Ok(())
24546+}
24547+
24548+/// lane-lossless2: the chroma half of a lossless INTER block. libaom's
24549+/// `read_tx_size` (`av1/decoder/decodeframe.c`) returns TX_4X4 for EVERY
24550+/// plane of a lossless block, so the chroma plane block is a raster of 4x4
24551+/// transform units instead of one whole-block transform, and
24552+/// `decode_token_recon_block` walks them PLANE-MAJOR inside each 64x64 "mu"
24553+/// chunk (`for (plane..) for (blk_row..) for (blk_col..)`): every U unit of
24554+/// the chunk, then every V unit. Reads one chunk-sized region
24555+/// (`org`/`reg`, chroma pixels relative to the block) and copies its units
24556+/// into the block-sized `u_out`/`v_out` grids.
24557+#[allow(clippy::too_many_arguments)]
24558+fn read_inter_chroma_lossless(
24559+ dec: &mut SymbolDecoder,
24560+ cdfs: &mut Cdfs,
24561+ neighbours: &mut Neighbours,
24562+ u: &mut PlaneBuf<'static>,
24563+ v: &mut PlaneBuf<'static>,
24564+ su: Pred<'_>,
24565+ sv: Pred<'_>,
24566+ at_mi: (usize, usize),
24567+ (cpx, cpy): (usize, usize),
24568+ (org_x, org_y): (usize, usize),
24569+ (reg_w, reg_h): (usize, usize),
24570+ // the whole block's chroma plane block -- what `get_txb_ctx`'s offset is
24571+ // decided on.
24572+ (blk_w, blk_h): (usize, usize),
24573+ // the stride the predictors and the block-sized `u_out`/`v_out` are read
24574+ // at (the block's square chroma side, even for a 2:1 strip, which embeds
24575+ // its narrower plane block in the same square grid).
24576+ stride: usize,
24577+ mode_for_tx: usize,
24578+ base_q_idx: u8,
24579+ u_out: &mut Vec<i32>,
24580+ v_out: &mut Vec<i32>,
24581+ fctx: &crate::decode::FrameCtx,
24582+) -> Result<()> {
24583+ let scan4 = default_scan(4);
24584+ // `get_txb_ctx` (`av1/common/txb_common.h`): `ctx_offset` is 10 when the
24585+ // plane block is bigger than the transform and 7 when it is the
24586+ // transform -- our chroma tables carry the offset-10 rows at +3.
24587+ let offset = (blk_w > 4 || blk_h > 4).then_some(3);
24588+ for plane_idx in 1..3 {
24589+ for rr in 0..reg_h / 4 {
24590+ for cc in 0..reg_w / 4 {
24591+ let (ox, oy) = (org_x + cc * 4, org_y + rr * 4);
24592+ // The chroma neighbour bands are indexed in LUMA mi: 4 chroma
24593+ // pixels span 8 luma ones, i.e. 2 mi.
24594+ let cu_mi = (at_mi.0 + oy / 2, at_mi.1 + ox / 2);
24595+ let cu_around = neighbours.around_mi(cu_mi, 8);
24596+ let (src, buf) = if plane_idx == 1 {
24597+ (su, &mut *u)
24598+ } else {
24599+ (sv, &mut *v)
24600+ };
24601+ let cu_grid = read_inter_plane(
24602+ dec,
24603+ cdfs,
24604+ TxbSet::Chroma4,
24605+ &scan4,
24606+ plane_idx,
24607+ cu_around[plane_idx],
24608+ mode_for_tx,
24609+ buf,
24610+ cpx + ox,
24611+ cpy + oy,
24612+ 4,
24613+ base_q_idx,
24614+ src.offset(oy * stride + ox),
24615+ // A lossless block codes DCT_DCT on every plane
24616+ // (`av1_get_tx_type`, `blockd.h`), so nothing is
24617+ // inherited from the luma unit.
24618+ None,
24619+ offset,
24620+ fctx,
24621+ )?
24622+ .0;
24623+ // Immediately, so the NEXT unit reads this one's context.
24624+ neighbours.record_mi_chroma(cu_mi, 8, 8, plane_idx, &cu_grid);
24625+ hit!(CHROMA_SPLIT_TX_HITS);
24626+ let dst = mu_units(
24627+ if plane_idx == 1 { &mut *u_out } else { &mut *v_out },
24628+ stride * stride,
24629+ );
24630+ for row in 0..4 {
24631+ let start = (oy + row) * stride + ox;
24632+ dst[start..start + 4].copy_from_slice(&cu_grid[row * 4..][..4]);
24633+ }
24634+ }
24635+ }
24636+ }
24637+ Ok(())
24638+}
24639+
24430 /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode`24640 /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode`
24431 /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with24641 /// is known `SINGLE_REFERENCE` -- `decode_stream` refuses any frame with
24432 /// `reference_select` set before this is ever called, so that read is never24642 /// `reference_select` set before this is ever called, so that read is never
@@ -27403,6 +27613,21 @@ fn decode_inter_block(
27403 let cu_around = neighbours.around_mi(cu_mi, luma_span);27613 let cu_around = neighbours.around_mi(cu_mi, luma_span);
27404 let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx);27614 let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx);
27405 let cu_scan = default_scan(cu_tx);27615 let cu_scan = default_scan(cu_tx);
27616+ if lossless(fctx) {
27617+ // lane-lossless2: this chunk's chroma is
27618+ // 8x8 TX_4X4 units per plane, not one
27619+ // TX_32X32 unit.
27620+ read_inter_chroma_lossless(
27621+ dec, cdfs, neighbours, u, v, su, sv,
27622+ at_mi, (cpx, cpy),
27623+ (cc * cu_tx, cr * cu_tx), (cu_tx, cu_tx),
27624+ (write_chroma_w, write_chroma_h),
27625+ chroma_side, mode_for_tx, base_q_idx,
27626+ &mut u_units, &mut v_units, fctx,
27627+ )?;
27628+ mu_chroma = true;
27629+ continue;
27630+ }
27406 for plane_idx in 1..3 {27631 for plane_idx in 1..3 {
27407 let (src, buf) = if plane_idx == 1 {27632 let (src, buf) = if plane_idx == 1 {
27408 (su, &mut *u)27633 (su, &mut *u)
@@ -27513,6 +27738,23 @@ fn decode_inter_block(
27513 } else {27738 } else {
27514 Grid::Own(std::mem::take(&mut v_units))27739 Grid::Own(std::mem::take(&mut v_units))
27515 };27740 };
27741+ } else if lossless(fctx) {
27742+ // lane-lossless2: TX_4X4 chroma units, plane-major
27743+ // (libaom `read_tx_size` + `decode_token_recon_block`).
27744+ let (mut uo, mut vo) = (Vec::new(), Vec::new());
27745+ read_inter_chroma_lossless(
27746+ dec, cdfs, neighbours, u, v, su, sv, at_mi, (cpx, cpy),
27747+ (0, 0), (write_chroma_w, write_chroma_h),
27748+ (write_chroma_w, write_chroma_h), chroma_side,
27749+ mode_for_tx, base_q_idx, &mut uo, &mut vo, fctx,
27750+ )?;
27751+ let zero = chroma_side * chroma_side;
27752+ u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) };
27753+ v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) };
27754+ // Every unit stamped its own neighbour context above; the
27755+ // whole-block record must not overwrite them with the
27756+ // assembled grid (class `override-slot-on-one-arm`).
27757+ mu_chroma = true;
27516 } else if rect_tu {27758 } else if rect_tu {
27517 // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a27759 // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a
27518 // 2:1 strip is the strip's own rect chroma size (16x8 /27760 // 2:1 strip is the strip's own rect chroma size (16x8 /
@@ -28700,6 +28942,21 @@ fn decode_inter_block(
28700 let cu_around = neighbours.around_mi(cu_mi, luma_span);28942 let cu_around = neighbours.around_mi(cu_mi, luma_span);
28701 let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx);28943 let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx);
28702 let cu_scan = default_scan(cu_tx);28944 let cu_scan = default_scan(cu_tx);
28945+ if lossless(fctx) {
28946+ // lane-lossless2: this chunk's chroma is
28947+ // 8x8 TX_4X4 units per plane, not one
28948+ // TX_32X32 unit.
28949+ read_inter_chroma_lossless(
28950+ dec, cdfs, neighbours, u, v, su, sv,
28951+ at_mi, (cpx, cpy),
28952+ (cc * cu_tx, cr * cu_tx), (cu_tx, cu_tx),
28953+ (write_chroma_w, write_chroma_h),
28954+ chroma_side, mode_for_tx, base_q_idx,
28955+ &mut u_units, &mut v_units, fctx,
28956+ )?;
28957+ mu_chroma = true;
28958+ continue;
28959+ }
28703 for plane_idx in 1..3 {28960 for plane_idx in 1..3 {
28704 let (src, buf) = if plane_idx == 1 {28961 let (src, buf) = if plane_idx == 1 {
28705 (su, &mut *u)28962 (su, &mut *u)
@@ -28819,6 +29076,23 @@ fn decode_inter_block(
28819 } else {29076 } else {
28820 Grid::Own(std::mem::take(&mut v_units))29077 Grid::Own(std::mem::take(&mut v_units))
28821 };29078 };
29079+ } else if lossless(fctx) {
29080+ // lane-lossless2: TX_4X4 chroma units, plane-major
29081+ // (libaom `read_tx_size` + `decode_token_recon_block`).
29082+ let (mut uo, mut vo) = (Vec::new(), Vec::new());
29083+ read_inter_chroma_lossless(
29084+ dec, cdfs, neighbours, u, v, su, sv, at_mi, (cpx, cpy),
29085+ (0, 0), (write_chroma_w, write_chroma_h),
29086+ (write_chroma_w, write_chroma_h), chroma_side,
29087+ mode_for_tx, base_q_idx, &mut uo, &mut vo, fctx,
29088+ )?;
29089+ let zero = chroma_side * chroma_side;
29090+ u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) };
29091+ v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) };
29092+ // Every unit stamped its own neighbour context above; the
29093+ // whole-block record must not overwrite them with the
29094+ // assembled grid (class `override-slot-on-one-arm`).
29095+ mu_chroma = true;
28822 } else if rect_tu {29096 } else if rect_tu {
28823 // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a29097 // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a
28824 // 2:1 strip is the strip's own rect chroma size (16x8 /29098 // 2:1 strip is the strip's own rect chroma size (16x8 /
@@ -29380,6 +29654,22 @@ fn decode_inter_block(
29380 reach, px, py, y.width, y.height, fctx,29654 reach, px, py, y.width, y.height, fctx,
29381 );29655 );
29382 let cu_scan = default_scan(cu_tx);29656 let cu_scan = default_scan(cu_tx);
29657+ if lossless(fctx) {
29658+ // lane-lossless2: 8x8 TX_4X4 units per plane in this
29659+ // chunk, not one TX_32X32 unit.
29660+ read_intra_chroma_lossless(
29661+ dec, cdfs, neighbours, u, v, at_mi, (px, py),
29662+ (cpx, cpy), side, (chroma_side, chroma_side),
29663+ (cc * cu_tx, cr * cu_tx), (cu_tx, cu_tx),
29664+ chroma_side, reach, (y.width, y.height), mode,
29665+ uv_predict_mode, angle_delta_uv,
29666+ palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
29667+ smooth_neighbor_uv, base_q_idx,
29668+ &mut u_units, &mut v_units, fctx,
29669+ )?;
29670+ mu_chroma = true;
29671+ continue;
29672+ }
29383 for plane_idx in 1..3 {29673 for plane_idx in 1..3 {
29384 let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v };29674 let buf: &mut PlaneBuf<'static> = if plane_idx == 1 { &mut *u } else { &mut *v };
29385 let cu_grid = if skip {29675 let cu_grid = if skip {
@@ -29552,6 +29842,23 @@ fn decode_inter_block(
29552 )?;29842 )?;
29553 }29843 }
29554 let ac = alpha.map(|_| cfl_src(px, py, side));29844 let ac = alpha.map(|_| cfl_src(px, py, side));
29845+ if lossless(fctx) {
29846+ // lane-lossless2: the block's chroma plane is a raster of 4x4
29847+ // units, plane-major (`read_intra_chroma_lossless`).
29848+ let (mut uo, mut vo) = (Vec::new(), Vec::new());
29849+ read_intra_chroma_lossless(
29850+ dec, cdfs, neighbours, u, v, at_mi, (px, py), (cpx, cpy),
29851+ side, (chroma_side, chroma_side), (0, 0),
29852+ (chroma_side, chroma_side), chroma_side, reach,
29853+ (y.width, y.height), mode, uv_predict_mode, angle_delta_uv,
29854+ palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
29855+ smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx,
29856+ )?;
29857+ let zero = chroma_side * chroma_side;
29858+ u_grid = if uo.is_empty() { Grid::Zero(zero) } else { Grid::Own(uo) };
29859+ v_grid = if vo.is_empty() { Grid::Zero(zero) } else { Grid::Own(vo) };
29860+ mu_chroma = true;
29861+ } else {
29555 if let Some((ub, _)) = &palette_uv_bufs {29862 if let Some((ub, _)) = &palette_uv_bufs {
29556 set_palette_pred(ub.clone(), fctx);29863 set_palette_pred(ub.clone(), fctx);
29557 }29864 }
@@ -29602,6 +29909,7 @@ fn decode_inter_block(
29602 None,29909 None,
29603 smooth_neighbor_uv, fctx,29910 smooth_neighbor_uv, fctx,
29604 )?;29911 )?;
29912+ }
29605 }29913 }
29606 }29914 }
29607 // lane-comppin r9: end-of-block checkpoint -- everything between29915 // lane-comppin r9: end-of-block checkpoint -- everything between
@@ -29634,11 +29942,20 @@ fn decode_inter_block(
29634 // units are collected here and re-stamped after that record, in mu-chunk29942 // units are collected here and re-stamped after that record, in mu-chunk
29635 // order so a later unit still wins over an earlier one.29943 // order so a later unit still wins over an earlier one.
29636 let mu_chroma_units: Vec<((usize, usize), usize, Grid)> = if mu_chroma {29944 let mu_chroma_units: Vec<((usize, usize), usize, Grid)> = if mu_chroma {
29637- let cu = 32usize;29945+ // lane-lossless2: the unit is TX_32X32 (one per 64x64 mu chunk)
29946+ // normally and TX_4X4 on a lossless frame, where the whole chroma
29947+ // plane block is a raster of them.
29948+ let cu = if lossless(fctx) { 4usize } else { 32usize };
29949+ let span = cu * 2;
29950+ let (rows, cols) = if lossless(fctx) {
29951+ ((write_h / 2).div_ceil(cu), (write_w / 2).div_ceil(cu))
29952+ } else {
29953+ ((write_h / 64).max(1), (write_w / 64).max(1))
29954+ };
29638 let mut units = Vec::new();29955 let mut units = Vec::new();
29639- for cr in 0..(write_h / 64).max(1) {29956+ for cr in 0..rows {
29640- for cc in 0..(write_w / 64).max(1) {29957+ for cc in 0..cols {
29641- let cu_mi = (at.0 + cr * 16, at.1 + cc * 16);29958+ let cu_mi = (at.0 + cr * (span / MI), at.1 + cc * (span / MI));
29642 for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {29959 for (plane, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
29643 let mut unit = Vec::with_capacity(cu * cu);29960 let mut unit = Vec::with_capacity(cu * cu);
29644 for rr in 0..cu {29961 for rr in 0..cu {
@@ -29782,8 +30099,9 @@ fn decode_inter_block(
29782 neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode);30099 neighbours.record_uv_mode_mi(s.pair_mi.0, s.pair_mi.1, pw / MI, ph / MI, uv_predict_mode);
29783 hit!(INTER16_CHROMA_PAIR_HITS);30100 hit!(INTER16_CHROMA_PAIR_HITS);
29784 }30101 }
30102+ let mu_span = if lossless(fctx) { 8 } else { 64 };
29785 for (cu_mi, plane, unit) in &mu_chroma_units {30103 for (cu_mi, plane, unit) in &mu_chroma_units {
29786- neighbours.record_mi_chroma(*cu_mi, 64, 64, *plane, unit);30104+ neighbours.record_mi_chroma(*cu_mi, mu_span, mu_span, *plane, unit);
29787 }30105 }
29788 neighbours.record_inter_rect_mi(30106 neighbours.record_inter_rect_mi(
29789 at,30107 at,
@@ -31201,6 +31519,16 @@ fn decode_inter_sub8_rect2(
31201 0,31519 0,
31202 &mut leaves,31520 &mut leaves,
31203 );31521 );
31522+ } else if lossless(fctx) && !skip {
31523+ // lane-lossless2: `read_block_tx_size` returns TX_4X4 before it
31524+ // ever looks at `max_txsize_rect_lookup`, so an 8x4/4x8 leaf is
31525+ // TWO 4x4 units, not one rect one.
31526+ for row in 0..bh / MI {
31527+ for col in 0..bw / MI {
31528+ leaves.push((row, col, MI, MI));
31529+ }
31530+ }
31531+ set_txfm_ctxs(neighbours, lmi, MI, w_mi, h_mi, skip);
31204 } else {31532 } else {
31205 leaves.push((0, 0, bw, bh));31533 leaves.push((0, 0, bw, bh));
31206 set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);31534 set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
crates/ec-av1/src/refusal_inventory.rsmodified+7 -12
@@ -57,15 +57,14 @@ const REFUSALS: &[&str] = &[
57 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",57 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
58 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",58 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
59 "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)",59 "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)",
60- // lane-lossless: the KEY/intra-only half of a lossless frame (base_q_idx60+ // lane-lossless/lane-lossless2: a lossless frame (base_q_idx 0) decodes
61- // 0) now decodes sample-exact -- TX_4X4 with the Walsh-Hadamard transform61+ // sample-exact, KEY and INTER -- TX_4X4 with the Walsh-Hadamard transform
62 // on every plane, no `tx_type` symbol, `is_cfl_allowed` narrowed to a62 // on every plane, no `tx_type` symbol, `is_cfl_allowed` narrowed to a
63- // BLOCK_4X4 chroma plane block. What is left is the INTER chroma walk: an63+ // BLOCK_4X4 chroma plane block, and the chroma plane walked as 4x4 units
64- // inter block's chroma plane is still read as ONE transform per block64+ // plane-major inside each mu chunk (gates
65- // here, so a lossless inter frame is refused by name (gate65+ // `a_lossless_libaom_key_frame_decodes_sample_exact` /
66- // `a_lossless_inter_frame_is_refused_by_name`). A frame whose segments66+ // `a_lossless_libaom_inter_frame_decodes_sample_exact`). A frame whose
67- // disagree is refused separately: every lossless rule is per segment.67+ // segments disagree is still refused: every lossless rule is per segment.
68- "a lossless INTER frame (its chroma plane is still coded as one transform per block here)",
69 "a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)",68 "a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)",
70 "a frame OBU with no tile group",69 "a frame OBU with no tile group",
71 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",70 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
@@ -285,10 +284,6 @@ const PROVEN: &[(&str, &str)] = &[
285 "an inter frame with no key frame before it",284 "an inter frame with no key frame before it",
286 "an_inter_frame_opening_a_stream_is_refused_by_name",285 "an_inter_frame_opening_a_stream_is_refused_by_name",
287 ),286 ),
288- (
289- "a lossless INTER frame (its chroma plane is still coded as one transform per block here)",
290- "a_lossless_inter_frame_is_refused_by_name",
291- ),
292 // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under287 // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under
293 // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17288 // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17
294 // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of289 // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of
crates/ec-av1/src/stream.rsmodified+130 -52
@@ -1617,19 +1617,10 @@ fn decode_frame(
1617 "a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)",1617 "a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)",
1618 ));1618 ));
1619 }1619 }
1620- // lane-lossless r1 ships the KEY/intra-only half: an inter block's chroma1620+ // lane-lossless2: an INTER frame's chroma plane is now walked as 4x4
1621- // plane is still read as ONE transform per block here, where a lossless1621+ // transform units too (`decode::read_inter_chroma_lossless`), so the
1622- // frame codes it as 4x4 units like everything else (libaom1622+ // named refusal that stood here is gone -- the gate that replaced it is
1623- // `read_block_tx_size` returns TX_4X4 for every plane). The luma side of1623+ // `a_lossless_libaom_inter_frame_decodes_sample_exact`.
1624- // the inter path is already converted (`read_block_tx_size`'s synthesized
1625- // leaves); the chroma walk and its mu-chunk order are the remaining work,
1626- // so refuse by name rather than return silently wrong pixels.
1627- if coded_lossless && header.frame_type == FrameType::Inter {
1628- return Err(Error::unsupported(
1629- "AV1 decode_stream",
1630- "a lossless INTER frame (its chroma plane is still coded as one transform per block here)",
1631- ));
1632- }
1633 crate::decode::set_lossless(coded_lossless, fctx);1624 crate::decode::set_lossless(coded_lossless, fctx);
1634 crate::decode::set_bit_depth(bit_depth, fctx);1625 crate::decode::set_bit_depth(bit_depth, fctx);
1635 // spec 7.16: this frame's superres state, for the filter chain --1626 // spec 7.16: this frame's superres state, for the filter chain --
@@ -4033,7 +4024,20 @@ pub(crate) mod tests {
4033 raw.push(((col * 7 + row * 13 + f * 31) % 251) as u8);4024 raw.push(((col * 7 + row * 13 + f * 31) % 251) as u8);
4034 }4025 }
4035 }4026 }
4036- raw.extend(std::iter::repeat_n(128u8, w * h / 2));4027+ // lane-lossless2: TEXTURED chroma. A flat chroma plane codes one
4028+ // `txb_skip` symbol per 4x4 unit with every context at 0, which
4029+ // is blind to both the unit ORDER and the per-unit contexts
4030+ // (class `gate-blind-to-feature`).
4031+ for row in 0..h / 2 {
4032+ for col in 0..w / 2 {
4033+ raw.push((((col + f) * 11 + row * 5) % 251) as u8);
4034+ }
4035+ }
4036+ for row in 0..h / 2 {
4037+ for col in 0..w / 2 {
4038+ raw.push(((col * 3 + (row + f) * 17) % 251) as u8);
4039+ }
4040+ }
4037 }4041 }
4038 // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.4042 // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.
4039 let src = std::env::temp_dir().join(format!("ec-av1-lossless-{}.yuv", std::process::id()));4043 let src = std::env::temp_dir().join(format!("ec-av1-lossless-{}.yuv", std::process::id()));
@@ -4092,51 +4096,125 @@ pub(crate) mod tests {
4092 }4096 }
4093 }4097 }
4094 4098
4095- /// The other half of lane-lossless r1: a lossless INTER frame is refused BY4099+ /// lane-lossless2: the refusal `a_lossless_inter_frame_is_refused_by_name`
4096- /// NAME (its chroma plane is still one transform per block here), never4100+ /// pinned became an implementation, so its gate became a DECODE-EXACT one
4097- /// decoded into silently wrong pixels -- the refusal this gate pins is the4101+ /// (class `refusal-lifted-without-a-gate`). A lossless INTER frame codes
4098- /// one `refusal_inventory` carries.4102+ /// its chroma plane as 4x4 transform units, plane-major inside each 64x64
4103+ /// mu chunk (libaom `read_tx_size` returns TX_4X4 for every plane under
4104+ /// `xd->lossless[..]`, and `decode_token_recon_block` walks
4105+ /// `for (plane..) for (blk_row..) for (blk_col..)`), which is what
4106+ /// `decode::read_inter_chroma_lossless` reads. The source carries TEXTURED
4107+ /// CHROMA and real motion on purpose: a flat-chroma source codes one
4108+ /// `txb_skip` symbol per unit and is blind to both the unit order and the
4109+ /// per-unit contexts (class `gate-blind-to-feature`).
4099 #[test]4110 #[test]
4100- fn a_lossless_inter_frame_is_refused_by_name() {4111+ fn a_lossless_libaom_inter_frame_decodes_sample_exact() {
4101- const NAME: &str = "a_lossless_inter_frame_is_refused_by_name";4112+ const NAME: &str = "a_lossless_libaom_inter_frame_decodes_sample_exact";
4102 if !have_ffmpeg() {4113 if !have_ffmpeg() {
4103 eprintln!("SKIP {NAME}: no ffmpeg");4114 eprintln!("SKIP {NAME}: no ffmpeg");
4104 return;4115 return;
4105 }4116 }
4106- let (w, h, frames) = (128usize, 64usize, 4usize);4117+ // (w, h, frames, gop, bit depth, 128-superblock)
4107- let mut raw = Vec::with_capacity(frames * w * h * 3 / 2);4118+ let cases: [(usize, usize, usize, &str, u32, bool); 4] = [
4108- for f in 0..frames {4119+ (256, 128, 8, "4", 8, false),
4109- for row in 0..h {4120+ (192, 96, 6, "3", 10, false),
4110- for col in 0..w {4121+ (320, 192, 6, "3", 8, false),
4111- raw.push(((col * 7 + row * 13 + f * 31) % 251) as u8);4122+ (256, 256, 4, "2", 8, true),
4123+ ];
4124+ for &(w, h, frames, gop, depth, sb128) in &cases {
4125+ let tag = format!("{w}x{h} {depth}-bit gop {gop}{}", if sb128 { " sb128" } else { "" });
4126+ let mut raw: Vec<u8> = Vec::new();
4127+ let put = |v: u32, raw: &mut Vec<u8>| {
4128+ if depth == 10 {
4129+ raw.extend_from_slice(&((v * 4) as u16).to_le_bytes());
4130+ } else {
4131+ raw.push(v as u8);
4132+ }
4133+ };
4134+ for f in 0..frames {
4135+ for row in 0..h {
4136+ for col in 0..w {
4137+ put((((col + 2 * f) * 7 + row * 13) % 251) as u32, &mut raw);
4138+ }
4139+ }
4140+ for row in 0..h / 2 {
4141+ for col in 0..w / 2 {
4142+ put((((col + f) * 11 + row * 5) % 251) as u32, &mut raw);
4143+ }
4144+ }
4145+ for row in 0..h / 2 {
4146+ for col in 0..w / 2 {
4147+ put(((col * 3 + (row + f) * 17) % 251) as u32, &mut raw);
4148+ }
4149+ }
4150+ }
4151+ let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
4152+ // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.
4153+ let src = std::env::temp_dir()
4154+ .join(format!("ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", std::process::id()));
4155+ std::fs::write(&src, &raw).expect("raw source");
4156+ let mut cmd = Command::new("ffmpeg");
4157+ cmd.args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", pix])
4158+ .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
4159+ .arg(&src)
4160+ .args(["-an", "-threads", "1", "-g", gop, "-c:v", "libaom-av1"])
4161+ .args(["-pix_fmt", pix, "-cpu-used", "6", "-b:v", "0", "-crf", "0"]);
4162+ if sb128 {
4163+ cmd.args(["-aom-params", "sb-size=128"]);
4164+ }
4165+ let out = cmd
4166+ .args(["-f", "obu", "-"])
4167+ .stdin(Stdio::null())
4168+ .stdout(Stdio::piped())
4169+ .stderr(Stdio::piped())
4170+ .output()
4171+ .expect("ffmpeg failed to run");
4172+ let _ = std::fs::remove_file(&src);
4173+ if !out.status.success() {
4174+ eprintln!(
4175+ "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})",
4176+ String::from_utf8_lossy(&out.stderr)
4177+ );
4178+ return;
4179+ }
4180+ let stream = out.stdout;
4181+ // The stream must really be lossless AND really carry inter frames
4182+ // (class `gate-blind-to-feature`).
4183+ let mut parser = Av1Parser::new();
4184+ let (mut pos, mut lossless, mut inters) = (0usize, 0usize, 0usize);
4185+ while pos < stream.len() {
4186+ let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses");
4187+ pos += obu.total_size.max(1);
4188+ let header = match &obu.kind {
4189+ ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h,
4190+ _ => continue,
4191+ };
4192+ if header.lossless.iter().all(|&l| l) {
4193+ lossless += 1;
4194+ }
4195+ if header.frame_type == FrameType::Inter {
4196+ inters += 1;
4197+ }
4198+ }
4199+ assert!(lossless >= frames, "{NAME} [{tag}] went blind: {lossless} lossless frames");
4200+ assert!(inters > 0, "{NAME} [{tag}] went blind: no inter frame at gop {gop}");
4201+ let ours = decode_stream(&stream)
4202+ .unwrap_or_else(|e| panic!("{NAME} [{tag}]: a lossless inter stream decodes: {e}"));
4203+ let refs = if depth == 10 {
4204+ ffmpeg_decode_sequence_10bit(&stream, w, h, frames)
4205+ } else {
4206+ ffmpeg_decode_sequence(&stream, w, h, frames)
4207+ };
4208+ assert_eq!(ours.len(), frames, "{NAME} [{tag}]: frame count");
4209+ for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() {
4210+ for (plane, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
4211+ .iter()
4212+ .enumerate()
4213+ {
4214+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
4215+ assert_eq!(bad, 0, "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ");
4112 }4216 }
4113 }4217 }
4114- raw.extend(std::iter::repeat_n(128u8, w * h / 2));
4115- }
4116- let src = std::env::temp_dir().join(format!("ec-av1-lossless-i-{}.yuv", std::process::id()));
4117- std::fs::write(&src, &raw).expect("raw source");
4118- let out = Command::new("ffmpeg")
4119- .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
4120- .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
4121- .arg(&src)
4122- .args(["-an", "-threads", "1", "-g", "4", "-c:v", "libaom-av1"])
4123- .args(["-cpu-used", "6", "-b:v", "0", "-crf", "0", "-f", "obu", "-"])
4124- .stdin(Stdio::null())
4125- .stdout(Stdio::piped())
4126- .stderr(Stdio::piped())
4127- .output()
4128- .expect("ffmpeg failed to run");
4129- let _ = std::fs::remove_file(&src);
4130- if !out.status.success() {
4131- eprintln!("SKIP {NAME}: ffmpeg has no libaom-av1 encoder");
4132- return;
4133- }
4134- match decode_stream(&out.stdout) {
4135- Ok(_) => panic!("{NAME}: a lossless inter stream decoded instead of being refused"),
4136- Err(e) => assert!(
4137- format!("{e}").contains("a lossless INTER frame"),
4138- "{NAME}: refused for the wrong reason: {e}"
4139- ),
4140 }4218 }
4141 }4219 }
4142 4220