From 818f85da227aec31eb5e64453ca299270590ffe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 08:37:02 +0300 Subject: [PATCH] feat(av1): thread allow_screen_content_tools/allow_intrabc through decode_key_frame_tile[_with_cdfs]; narrow whole-frame refusal to non-key frames decode_block/decode_leaf8/read_intra_mode already consumed palette/intrabc syntax on key frames (prior builder). This wires the two bools the rest of the way: through decode_key_frame_tile_with_cdfs and the public decode_key_frame_tile wrapper, stream.rs's real production call (header.allow_screen_content_tools/allow_intrabc), and the 7 test call sites (false, false -- none of those fixtures use screen content tools). Narrows stream.rs:169's whole-frame refusal to `frame_type != Key && allow_screen_content_tools`: decode_inter_block/ decode_inter_block8's intra-sub-block branches have no palette/intrabc wiring at all, so removing the refusal for inter frames would desync them silently. --- crates/ec-av1/src/decode.rs | 18 ++++++++++++++++++ crates/ec-av1/src/stream.rs | 13 +++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index abae5647..c4fe48b0 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -3539,6 +3539,8 @@ pub fn decode_key_frame_tile( loop_filter: &LoopFilterParams, tx_select: bool, reduced_tx_set: bool, + allow_screen_content_tools: bool, + allow_intrabc: bool, ) -> Result { decode_key_frame_tile_with_cdfs( data, @@ -3554,6 +3556,8 @@ pub fn decode_key_frame_tile( None, tx_select, reduced_tx_set, + allow_screen_content_tools, + allow_intrabc, ) .map(|(picture, _)| picture) } @@ -3580,6 +3584,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( initial_cdfs: Option, tx_select: bool, reduced_tx_set: bool, + allow_screen_content_tools: bool, + allow_intrabc: bool, ) -> Result<(Picture, Cdfs)> { if mi_cols == 0 || mi_rows == 0 { return Err(unsupported("a frame with no mode-info grid")); @@ -9388,6 +9394,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .is_err() ); @@ -9430,6 +9438,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!(decoded.width, w, "{w}x{h}: decoded width"); @@ -9513,6 +9523,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert!( @@ -9698,6 +9710,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg"); @@ -9770,6 +9784,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!( @@ -10073,6 +10089,8 @@ mod tests { &LoopFilterParams::default(), false, true, + false, + false, ) .unwrap(); assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg"); diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 5841fa16..7d3e6932 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -166,10 +166,15 @@ pub fn decode_stream(data: &[u8]) -> Result> { // (spec 5.11.10/5.11.11, one symbol group per superblock). Refuse // before desyncing rather than silently miscode, the same pattern as // the CDEF/TxMode::Select refusals above. - if header.allow_screen_content_tools { + // Key frames now consume (not reconstruct) palette/intrabc syntax + // via read_intra_mode, so the arithmetic decoder stays in sync; + // decode_inter_block/decode_inter_block8's intra-sub-block branches + // still have no such wiring, so a non-key frame with the bit set + // still desyncs and must refuse. + if header.frame_type != FrameType::Key && header.allow_screen_content_tools { return Err(Error::unsupported( "AV1 decode_stream", - "a frame with allow_screen_content_tools set (this decoder never reads intrabc/palette_mode_info)", + "a non-key frame with allow_screen_content_tools set (this decoder's inter path never reads intrabc/palette_mode_info)", )); } if header.delta.q_present || header.delta.lf_present { @@ -313,6 +318,8 @@ pub fn decode_stream(data: &[u8]) -> Result> { initial_cdfs, header.tx_mode == TxMode::Select, header.reduced_tx_set, + header.allow_screen_content_tools, + header.allow_intrabc, )?; // A key frame codes no inter blocks -- its own saved motion // field has no cells set, matching libaom's own "intra frame @@ -535,6 +542,8 @@ mod tests { false, // Our own encoder always writes `reduced_tx_set: true`. true, + false, + false, ) .unwrap(); let via_stream = decode_stream(&encoded.stream).unwrap();