Merge branch 'lane-av1txsel': TxMode::Select intra decode, proven firing
Browse files at this commit5 changed files +887 -72
- crates/ec-av1/src/cdf.rs +175 -0
- crates/ec-av1/src/cdf_state.rs +80 -35
- crates/ec-av1/src/decode.rs +421 -23
- crates/ec-av1/src/stream.rs +184 -14
- crates/ec-av1/src/transform.rs +27 -0
crates/ec-av1/src/cdf.rsmodified+175 -0
| @@ -326,6 +326,31 @@ pub const FILTER_INTRA: [[u16; 3]; 4] = [ | |||
| 326 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. | 326 | /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks. |
| 327 | pub const FILTER_INTRA_MODE: [u16; 6] = [8949, 12776, 17211, 29558, 32768, 0]; | 327 | pub const FILTER_INTRA_MODE: [u16; 6] = [8949, 12776, 17211, 29558, 32768, 0]; |
| 328 | 328 | ||
| 329 | +/// `default_tx_size_cdf[0]` (entropymode.c): an 8x8 block's `tx_depth` flag | ||
| 330 | +/// (`TX8` vs `TX4`), indexed by `tx_size_context` (0..=2). | ||
| 331 | +pub const TX_SIZE_CAT0: [[u16; 3]; 3] = [[19968, 32768, 0], [19968, 32768, 0], [24320, 32768, 0]]; | ||
| 332 | +/// `default_tx_size_cdf[1]` (entropymode.c): a 16x16 block's `tx_depth` | ||
| 333 | +/// (`TX16`/`TX8`/`TX4`), indexed by `tx_size_context`. | ||
| 334 | +pub const TX_SIZE_CAT1: [[u16; 4]; 3] = [ | ||
| 335 | + [12272, 30172, 32768, 0], | ||
| 336 | + [12272, 30172, 32768, 0], | ||
| 337 | + [18677, 30848, 32768, 0], | ||
| 338 | +]; | ||
| 339 | +/// `default_tx_size_cdf[2]` (entropymode.c): a 32x32 block's `tx_depth` | ||
| 340 | +/// (`TX32`/`TX16`/`TX8`), indexed by `tx_size_context`. | ||
| 341 | +pub const TX_SIZE_CAT2: [[u16; 4]; 3] = [ | ||
| 342 | + [12986, 15180, 32768, 0], | ||
| 343 | + [12986, 15180, 32768, 0], | ||
| 344 | + [24302, 25602, 32768, 0], | ||
| 345 | +]; | ||
| 346 | +/// `default_tx_size_cdf[3]` (entropymode.c): a 64x64 block's `tx_depth` | ||
| 347 | +/// (`TX64`/`TX32`/`TX16`), indexed by `tx_size_context`. | ||
| 348 | +pub const TX_SIZE_CAT3: [[u16; 4]; 3] = [ | ||
| 349 | + [5782, 11475, 32768, 0], | ||
| 350 | + [5782, 11475, 32768, 0], | ||
| 351 | + [16803, 22759, 32768, 0], | ||
| 352 | +]; | ||
| 353 | + | ||
| 329 | /// `Default_Cfl_Alpha_Cdf` (spec 9.4): a `UV_CFL_PRED` block's per-plane | 354 | /// `Default_Cfl_Alpha_Cdf` (spec 9.4): a `UV_CFL_PRED` block's per-plane |
| 330 | /// alpha magnitude (spec 5.11.45's `cfl_alpha_u`/`cfl_alpha_v`), indexed by | 355 | /// alpha magnitude (spec 5.11.45's `cfl_alpha_u`/`cfl_alpha_v`), indexed by |
| 331 | /// the joint sign's context (`CFL_CONTEXT_U`/`CFL_CONTEXT_V`, | 356 | /// the joint sign's context (`CFL_CONTEXT_U`/`CFL_CONTEXT_V`, |
| @@ -3733,3 +3758,153 @@ pub const INTRA_TX_TYPE_SET1_8: [[u16; 8]; 13] = [ | |||
| 3733 | /// at the flat 5-way default (unlike its trained `TX_16X16` neighbour, | 3758 | /// at the flat 5-way default (unlike its trained `TX_16X16` neighbour, |
| 3734 | /// [`INTRA_TX_TYPE_SET2_16`]) -- every mode reads the same uniform CDF. | 3759 | /// [`INTRA_TX_TYPE_SET2_16`]) -- every mode reads the same uniform CDF. |
| 3735 | pub const INTRA_TX_TYPE_SET2_8: [[u16; 6]; 13] = [[6554, 13107, 19661, 26214, 32768, 0]; 13]; | 3760 | pub const INTRA_TX_TYPE_SET2_8: [[u16; 6]; 13] = [[6554, 13107, 19661, 26214, 32768, 0]; 13]; |
| 3761 | +/// The full luma sub-range of spec `TXB_SKIP_CONTEXTS` (contexts 0..6, the | ||
| 3762 | +/// `plane_bsize != tx_size` `skip_contexts[top][left]` table plus its own | ||
| 3763 | +/// single `plane_bsize == tx_size` context 0), for a `TxMode::Select` block | ||
| 3764 | +/// whose luma transform is split into several transform units smaller than | ||
| 3765 | +/// the block itself -- the single-context `TXB_SKIP_LUMA_*` constants above | ||
| 3766 | +/// stay for every other caller, which only ever reads context 0. | ||
| 3767 | +pub const TXB_SKIP_LUMA_8_Q0_CTX: [[u16; 3]; 7] = [ | ||
| 3768 | + [31548, 32768, 0], | ||
| 3769 | + [1549, 32768, 0], | ||
| 3770 | + [10130, 32768, 0], | ||
| 3771 | + [16656, 32768, 0], | ||
| 3772 | + [18591, 32768, 0], | ||
| 3773 | + [26308, 32768, 0], | ||
| 3774 | + [32537, 32768, 0], | ||
| 3775 | +]; | ||
| 3776 | +pub const TXB_SKIP_LUMA_8_Q1_CTX: [[u16; 3]; 7] = [ | ||
| 3777 | + [31782, 32768, 0], | ||
| 3778 | + [1836, 32768, 0], | ||
| 3779 | + [10689, 32768, 0], | ||
| 3780 | + [17604, 32768, 0], | ||
| 3781 | + [21622, 32768, 0], | ||
| 3782 | + [27518, 32768, 0], | ||
| 3783 | + [32399, 32768, 0], | ||
| 3784 | +]; | ||
| 3785 | +pub const TXB_SKIP_LUMA_8_CTX: [[u16; 3]; 7] = [ | ||
| 3786 | + [31957, 32768, 0], | ||
| 3787 | + [3230, 32768, 0], | ||
| 3788 | + [11153, 32768, 0], | ||
| 3789 | + [18123, 32768, 0], | ||
| 3790 | + [20143, 32768, 0], | ||
| 3791 | + [26536, 32768, 0], | ||
| 3792 | + [31986, 32768, 0], | ||
| 3793 | +]; | ||
| 3794 | +pub const TXB_SKIP_LUMA_8_Q3_CTX: [[u16; 3]; 7] = [ | ||
| 3795 | + [31903, 32768, 0], | ||
| 3796 | + [2044, 32768, 0], | ||
| 3797 | + [7528, 32768, 0], | ||
| 3798 | + [14618, 32768, 0], | ||
| 3799 | + [16182, 32768, 0], | ||
| 3800 | + [24168, 32768, 0], | ||
| 3801 | + [31037, 32768, 0], | ||
| 3802 | +]; | ||
| 3803 | +pub const TXB_SKIP_LUMA_16_Q0_CTX: [[u16; 3]; 7] = [ | ||
| 3804 | + [29957, 32768, 0], | ||
| 3805 | + [5391, 32768, 0], | ||
| 3806 | + [18039, 32768, 0], | ||
| 3807 | + [23566, 32768, 0], | ||
| 3808 | + [22431, 32768, 0], | ||
| 3809 | + [25822, 32768, 0], | ||
| 3810 | + [32197, 32768, 0], | ||
| 3811 | +]; | ||
| 3812 | +pub const TXB_SKIP_LUMA_16_Q1_CTX: [[u16; 3]; 7] = [ | ||
| 3813 | + [31901, 32768, 0], | ||
| 3814 | + [10311, 32768, 0], | ||
| 3815 | + [18047, 32768, 0], | ||
| 3816 | + [24806, 32768, 0], | ||
| 3817 | + [23288, 32768, 0], | ||
| 3818 | + [27914, 32768, 0], | ||
| 3819 | + [32296, 32768, 0], | ||
| 3820 | +]; | ||
| 3821 | +pub const TXB_SKIP_LUMA_16_CTX: [[u16; 3]; 7] = [ | ||
| 3822 | + [32363, 32768, 0], | ||
| 3823 | + [10692, 32768, 0], | ||
| 3824 | + [19090, 32768, 0], | ||
| 3825 | + [24357, 32768, 0], | ||
| 3826 | + [24442, 32768, 0], | ||
| 3827 | + [28312, 32768, 0], | ||
| 3828 | + [32169, 32768, 0], | ||
| 3829 | +]; | ||
| 3830 | +pub const TXB_SKIP_LUMA_16_Q3_CTX: [[u16; 3]; 7] = [ | ||
| 3831 | + [32510, 32768, 0], | ||
| 3832 | + [8430, 32768, 0], | ||
| 3833 | + [17318, 32768, 0], | ||
| 3834 | + [24154, 32768, 0], | ||
| 3835 | + [23674, 32768, 0], | ||
| 3836 | + [28789, 32768, 0], | ||
| 3837 | + [32139, 32768, 0], | ||
| 3838 | +]; | ||
| 3839 | +pub const TXB_SKIP_LUMA_32_Q0_CTX: [[u16; 3]; 7] = [ | ||
| 3840 | + [17920, 32768, 0], | ||
| 3841 | + [1818, 32768, 0], | ||
| 3842 | + [7282, 32768, 0], | ||
| 3843 | + [25273, 32768, 0], | ||
| 3844 | + [10923, 32768, 0], | ||
| 3845 | + [31554, 32768, 0], | ||
| 3846 | + [32624, 32768, 0], | ||
| 3847 | +]; | ||
| 3848 | +pub const TXB_SKIP_LUMA_32_Q1_CTX: [[u16; 3]; 7] = [ | ||
| 3849 | + [26726, 32768, 0], | ||
| 3850 | + [1045, 32768, 0], | ||
| 3851 | + [11703, 32768, 0], | ||
| 3852 | + [20590, 32768, 0], | ||
| 3853 | + [18554, 32768, 0], | ||
| 3854 | + [25970, 32768, 0], | ||
| 3855 | + [31938, 32768, 0], | ||
| 3856 | +]; | ||
| 3857 | +pub const TXB_SKIP_LUMA_32_CTX: [[u16; 3]; 7] = [ | ||
| 3858 | + [30669, 32768, 0], | ||
| 3859 | + [3832, 32768, 0], | ||
| 3860 | + [11663, 32768, 0], | ||
| 3861 | + [18889, 32768, 0], | ||
| 3862 | + [19782, 32768, 0], | ||
| 3863 | + [23313, 32768, 0], | ||
| 3864 | + [31330, 32768, 0], | ||
| 3865 | +]; | ||
| 3866 | +pub const TXB_SKIP_LUMA_32_Q3_CTX: [[u16; 3]; 7] = [ | ||
| 3867 | + [31671, 32768, 0], | ||
| 3868 | + [2056, 32768, 0], | ||
| 3869 | + [11746, 32768, 0], | ||
| 3870 | + [16852, 32768, 0], | ||
| 3871 | + [18635, 32768, 0], | ||
| 3872 | + [24715, 32768, 0], | ||
| 3873 | + [31484, 32768, 0], | ||
| 3874 | +]; | ||
| 3875 | +pub const TXB_SKIP_LUMA_64_Q0_CTX: [[u16; 3]; 7] = [ | ||
| 3876 | + [6308, 32768, 0], | ||
| 3877 | + [117, 32768, 0], | ||
| 3878 | + [1638, 32768, 0], | ||
| 3879 | + [2161, 32768, 0], | ||
| 3880 | + [16384, 32768, 0], | ||
| 3881 | + [10923, 32768, 0], | ||
| 3882 | + [30247, 32768, 0], | ||
| 3883 | +]; | ||
| 3884 | +pub const TXB_SKIP_LUMA_64_Q1_CTX: [[u16; 3]; 7] = [ | ||
| 3885 | + [26584, 32768, 0], | ||
| 3886 | + [188, 32768, 0], | ||
| 3887 | + [8847, 32768, 0], | ||
| 3888 | + [24519, 32768, 0], | ||
| 3889 | + [22938, 32768, 0], | ||
| 3890 | + [30583, 32768, 0], | ||
| 3891 | + [32608, 32768, 0], | ||
| 3892 | +]; | ||
| 3893 | +pub const TXB_SKIP_LUMA_64_CTX: [[u16; 3]; 7] = [ | ||
| 3894 | + [28573, 32768, 0], | ||
| 3895 | + [3183, 32768, 0], | ||
| 3896 | + [17802, 32768, 0], | ||
| 3897 | + [25977, 32768, 0], | ||
| 3898 | + [26677, 32768, 0], | ||
| 3899 | + [27832, 32768, 0], | ||
| 3900 | + [32387, 32768, 0], | ||
| 3901 | +]; | ||
| 3902 | +pub const TXB_SKIP_LUMA_64_Q3_CTX: [[u16; 3]; 7] = [ | ||
| 3903 | + [31539, 32768, 0], | ||
| 3904 | + [8433, 32768, 0], | ||
| 3905 | + [20576, 32768, 0], | ||
| 3906 | + [27904, 32768, 0], | ||
| 3907 | + [27852, 32768, 0], | ||
| 3908 | + [30026, 32768, 0], | ||
| 3909 | + [32441, 32768, 0], | ||
| 3910 | +]; | ||
crates/ec-av1/src/cdf_state.rsmodified+80 -35
| @@ -41,6 +41,10 @@ pub(crate) enum TxbSet { | |||
| 41 | /// block (lane-av1-rect). An `is_inter` leaf reads | 41 | /// block (lane-av1-rect). An `is_inter` leaf reads |
| 42 | /// [`Luma8Inter`](TxbSet::Luma8Inter) instead. | 42 | /// [`Luma8Inter`](TxbSet::Luma8Inter) instead. |
| 43 | Luma8, | 43 | Luma8, |
| 44 | + /// [`Luma8`](TxbSet::Luma8)'s `reduced_tx_set: false` counterpart (round | ||
| 45 | + /// 8): the same coefficient tables, but the seven-symbol `TX_SET_INTRA_1` | ||
| 46 | + /// `tx_type` table rather than `Luma8`'s five-symbol reduced one. | ||
| 47 | + Luma8Set1, | ||
| 44 | /// The 8x8 luma transform of an `is_inter` 8x8 leaf under a straddling | 48 | /// The 8x8 luma transform of an `is_inter` 8x8 leaf under a straddling |
| 45 | /// 16x16 block (lane-av1inter8): the same coefficient tables | 49 | /// 16x16 block (lane-av1inter8): the same coefficient tables |
| 46 | /// [`Luma8`](TxbSet::Luma8) reads, but `get_tx_set` (spec 5.11.48) | 50 | /// [`Luma8`](TxbSet::Luma8) reads, but `get_tx_set` (spec 5.11.48) |
| @@ -116,10 +120,14 @@ pub(crate) struct Cdfs { | |||
| 116 | pub cfl_alpha: [[u16; 17]; 6], | 120 | pub cfl_alpha: [[u16; 17]; 6], |
| 117 | /// The angle a directional mode is nudged by. | 121 | /// The angle a directional mode is nudged by. |
| 118 | pub angle_delta: [[u16; 8]; 8], | 122 | pub angle_delta: [[u16; 8]; 8], |
| 119 | - /// The one-context all-zero flag of a 16x16 luma transform. | 123 | + /// The all-zero flag of a 16x16 luma transform, 7 contexts (index 0 for |
| 120 | - pub txb_skip_luma_16: [[u16; 3]; 1], | 124 | + /// a lone TU whose own bsize equals the block's; 1..6 the |
| 121 | - /// The one-context all-zero flag of an 8x8 luma transform. | 125 | + /// `skip_contexts[top][left]` table when `TxMode::Select` splits the |
| 122 | - pub txb_skip_luma_8: [[u16; 3]; 1], | 126 | + /// block's luma into several smaller transform units, spec |
| 127 | + /// `get_txb_ctx_general`). | ||
| 128 | + pub txb_skip_luma_16: [[u16; 3]; 7], | ||
| 129 | + /// The same, for an 8x8 luma transform. | ||
| 130 | + pub txb_skip_luma_8: [[u16; 3]; 7], | ||
| 123 | /// The all-zero flag of an 8x8 chroma transform. | 131 | /// The all-zero flag of an 8x8 chroma transform. |
| 124 | pub txb_skip_chroma_8: [[u16; 3]; 3], | 132 | pub txb_skip_chroma_8: [[u16; 3]; 3], |
| 125 | /// The all-zero flag of a 4x4 chroma transform. | 133 | /// The all-zero flag of a 4x4 chroma transform. |
| @@ -170,10 +178,10 @@ pub(crate) struct Cdfs { | |||
| 170 | /// `PARTITION_NONE` is ever coded against it, but the alphabet still | 178 | /// `PARTITION_NONE` is ever coded against it, but the alphabet still |
| 171 | /// adapts on every read, same as every other partition table. | 179 | /// adapts on every read, same as every other partition table. |
| 172 | pub partition_w8: [[u16; 5]; 4], | 180 | pub partition_w8: [[u16; 5]; 4], |
| 173 | - /// The one-context all-zero flag of a 32x32 luma transform. | 181 | + /// The same as `txb_skip_luma_16`'s 7 contexts, for a 32x32 luma transform. |
| 174 | - pub txb_skip_luma_32: [[u16; 3]; 1], | 182 | + pub txb_skip_luma_32: [[u16; 3]; 7], |
| 175 | /// The same, for a 64x64 luma transform. | 183 | /// The same, for a 64x64 luma transform. |
| 176 | - pub txb_skip_luma_64: [[u16; 3]; 1], | 184 | + pub txb_skip_luma_64: [[u16; 3]; 7], |
| 177 | /// The all-zero flag of a 16x16 chroma transform. | 185 | /// The all-zero flag of a 16x16 chroma transform. |
| 178 | pub txb_skip_chroma_16: [[u16; 3]; 3], | 186 | pub txb_skip_chroma_16: [[u16; 3]; 3], |
| 179 | /// The all-zero flag of a 32x32 chroma transform. | 187 | /// The all-zero flag of a 32x32 chroma transform. |
| @@ -221,6 +229,13 @@ pub(crate) struct Cdfs { | |||
| 221 | pub intra_tx_type_16: [[u16; 6]; 13], | 229 | pub intra_tx_type_16: [[u16; 6]; 13], |
| 222 | /// The transform type of an 8x8 intra luma transform, by luma mode. | 230 | /// The transform type of an 8x8 intra luma transform, by luma mode. |
| 223 | pub intra_tx_type_8: [[u16; 6]; 13], | 231 | pub intra_tx_type_8: [[u16; 6]; 13], |
| 232 | + /// The transform type of an 8x8 intra luma transform, by luma mode, when | ||
| 233 | + /// `reduced_tx_set` is false (spec `TX_SET_INTRA_1`, seven types) -- | ||
| 234 | + /// [`Self::intra_tx_type_8`]'s five-type table is only the | ||
| 235 | + /// `reduced_tx_set` row (round 8: a real `aomenc` stream with | ||
| 236 | + /// `reduced_tx_set` off desyncs an 8x8 TU read against this row's | ||
| 237 | + /// wrong-length CDF). | ||
| 238 | + pub intra_tx_type_8_set1: [[u16; 8]; 13], | ||
| 224 | /// The transform type of an `is_inter` 32x32 luma transform (spec | 239 | /// The transform type of an `is_inter` 32x32 luma transform (spec |
| 225 | /// `TX_SET_INTER_3`, `TX_32X32` row) -- unlike the intra 16x16 table, it | 240 | /// `TX_SET_INTER_3`, `TX_32X32` row) -- unlike the intra 16x16 table, it |
| 226 | /// is not indexed by mode. | 241 | /// is not indexed by mode. |
| @@ -260,6 +275,15 @@ pub(crate) struct Cdfs { | |||
| 260 | pub filter_intra: [[u16; 3]; 4], | 275 | pub filter_intra: [[u16; 3]; 4], |
| 261 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. | 276 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. |
| 262 | pub filter_intra_mode: [u16; 6], | 277 | pub filter_intra_mode: [u16; 6], |
| 278 | + /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` | ||
| 279 | + /// (0..=2) -- see [`cdf::TX_SIZE_CAT0`]. | ||
| 280 | + pub tx_size_cat0: [[u16; 3]; 3], | ||
| 281 | + /// `tx_depth` at a 16x16 block -- see [`cdf::TX_SIZE_CAT1`]. | ||
| 282 | + pub tx_size_cat1: [[u16; 4]; 3], | ||
| 283 | + /// `tx_depth` at a 32x32 block -- see [`cdf::TX_SIZE_CAT2`]. | ||
| 284 | + pub tx_size_cat2: [[u16; 4]; 3], | ||
| 285 | + /// `tx_depth` at a 64x64 block -- see [`cdf::TX_SIZE_CAT3`]. | ||
| 286 | + pub tx_size_cat3: [[u16; 4]; 3], | ||
| 263 | } | 287 | } |
| 264 | 288 | ||
| 265 | /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`, | 289 | /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`, |
| @@ -417,6 +441,7 @@ impl Cdfs { | |||
| 417 | reset2(&mut self.dc_sign_luma); | 441 | reset2(&mut self.dc_sign_luma); |
| 418 | reset2(&mut self.intra_tx_type_16); | 442 | reset2(&mut self.intra_tx_type_16); |
| 419 | reset2(&mut self.intra_tx_type_8); | 443 | reset2(&mut self.intra_tx_type_8); |
| 444 | + reset2(&mut self.intra_tx_type_8_set1); | ||
| 420 | reset1(&mut self.inter_tx_type_32); | 445 | reset1(&mut self.inter_tx_type_32); |
| 421 | reset1(&mut self.inter_tx_type_16); | 446 | reset1(&mut self.inter_tx_type_16); |
| 422 | reset1(&mut self.inter_tx_type_8); | 447 | reset1(&mut self.inter_tx_type_8); |
| @@ -434,6 +459,10 @@ impl Cdfs { | |||
| 434 | .for_each(MvComponentCdfs::reset_counts); | 459 | .for_each(MvComponentCdfs::reset_counts); |
| 435 | reset2(&mut self.filter_intra); | 460 | reset2(&mut self.filter_intra); |
| 436 | reset1(&mut self.filter_intra_mode); | 461 | reset1(&mut self.filter_intra_mode); |
| 462 | + reset2(&mut self.tx_size_cat0); | ||
| 463 | + reset2(&mut self.tx_size_cat1); | ||
| 464 | + reset2(&mut self.tx_size_cat2); | ||
| 465 | + reset2(&mut self.tx_size_cat3); | ||
| 437 | } | 466 | } |
| 438 | 467 | ||
| 439 | /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and | 468 | /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and |
| @@ -451,20 +480,20 @@ impl Cdfs { | |||
| 451 | cfl_sign: cdf::CFL_SIGN, | 480 | cfl_sign: cdf::CFL_SIGN, |
| 452 | cfl_alpha: cdf::CFL_ALPHA, | 481 | cfl_alpha: cdf::CFL_ALPHA, |
| 453 | angle_delta: cdf::ANGLE_DELTA, | 482 | angle_delta: cdf::ANGLE_DELTA, |
| 454 | - txb_skip_luma_16: [pick( | 483 | + txb_skip_luma_16: pick( |
| 455 | - q_ctx, | 484 | + q_ctx, |
| 456 | - cdf::TXB_SKIP_LUMA_16_Q0, | 485 | + cdf::TXB_SKIP_LUMA_16_Q0_CTX, |
| 457 | - cdf::TXB_SKIP_LUMA_16_Q1, | 486 | + cdf::TXB_SKIP_LUMA_16_Q1_CTX, |
| 458 | - cdf::TXB_SKIP_LUMA_16, | 487 | + cdf::TXB_SKIP_LUMA_16_CTX, |
| 459 | - cdf::TXB_SKIP_LUMA_16_Q3, | 488 | + cdf::TXB_SKIP_LUMA_16_Q3_CTX, |
| 460 | - )], | 489 | + ), |
| 461 | - txb_skip_luma_8: [pick( | 490 | + txb_skip_luma_8: pick( |
| 462 | - q_ctx, | 491 | + q_ctx, |
| 463 | - cdf::TXB_SKIP_LUMA_8_Q0, | 492 | + cdf::TXB_SKIP_LUMA_8_Q0_CTX, |
| 464 | - cdf::TXB_SKIP_LUMA_8_Q1, | 493 | + cdf::TXB_SKIP_LUMA_8_Q1_CTX, |
| 465 | - cdf::TXB_SKIP_LUMA_8, | 494 | + cdf::TXB_SKIP_LUMA_8_CTX, |
| 466 | - cdf::TXB_SKIP_LUMA_8_Q3, | 495 | + cdf::TXB_SKIP_LUMA_8_Q3_CTX, |
| 467 | - )], | 496 | + ), |
| 468 | txb_skip_chroma_8: pick( | 497 | txb_skip_chroma_8: pick( |
| 469 | q_ctx, | 498 | q_ctx, |
| 470 | cdf::TXB_SKIP_CHROMA_8_Q0, | 499 | cdf::TXB_SKIP_CHROMA_8_Q0, |
| @@ -621,20 +650,20 @@ impl Cdfs { | |||
| 621 | ), | 650 | ), |
| 622 | partition_w16: cdf::PARTITION_W16, | 651 | partition_w16: cdf::PARTITION_W16, |
| 623 | partition_w8: cdf::PARTITION_W8, | 652 | partition_w8: cdf::PARTITION_W8, |
| 624 | - txb_skip_luma_32: [pick( | 653 | + txb_skip_luma_32: pick( |
| 625 | - q_ctx, | 654 | + q_ctx, |
| 626 | - cdf::TXB_SKIP_LUMA_32_Q0, | 655 | + cdf::TXB_SKIP_LUMA_32_Q0_CTX, |
| 627 | - cdf::TXB_SKIP_LUMA_32_Q1, | 656 | + cdf::TXB_SKIP_LUMA_32_Q1_CTX, |
| 628 | - cdf::TXB_SKIP_LUMA_32, | 657 | + cdf::TXB_SKIP_LUMA_32_CTX, |
| 629 | - cdf::TXB_SKIP_LUMA_32_Q3, | 658 | + cdf::TXB_SKIP_LUMA_32_Q3_CTX, |
| 630 | - )], | 659 | + ), |
| 631 | - txb_skip_luma_64: [pick( | 660 | + txb_skip_luma_64: pick( |
| 632 | - q_ctx, | 661 | + q_ctx, |
| 633 | - cdf::TXB_SKIP_LUMA_64_Q0, | 662 | + cdf::TXB_SKIP_LUMA_64_Q0_CTX, |
| 634 | - cdf::TXB_SKIP_LUMA_64_Q1, | 663 | + cdf::TXB_SKIP_LUMA_64_Q1_CTX, |
| 635 | - cdf::TXB_SKIP_LUMA_64, | 664 | + cdf::TXB_SKIP_LUMA_64_CTX, |
| 636 | - cdf::TXB_SKIP_LUMA_64_Q3, | 665 | + cdf::TXB_SKIP_LUMA_64_Q3_CTX, |
| 637 | - )], | 666 | + ), |
| 638 | txb_skip_chroma_16: pick( | 667 | txb_skip_chroma_16: pick( |
| 639 | q_ctx, | 668 | q_ctx, |
| 640 | cdf::TXB_SKIP_CHROMA_16_Q0, | 669 | cdf::TXB_SKIP_CHROMA_16_Q0, |
| @@ -778,6 +807,7 @@ impl Cdfs { | |||
| 778 | dc_sign_luma: cdf::DC_SIGN_LUMA, | 807 | dc_sign_luma: cdf::DC_SIGN_LUMA, |
| 779 | intra_tx_type_16: cdf::INTRA_TX_TYPE_SET2_16, | 808 | intra_tx_type_16: cdf::INTRA_TX_TYPE_SET2_16, |
| 780 | intra_tx_type_8: cdf::INTRA_TX_TYPE_SET2_8, | 809 | intra_tx_type_8: cdf::INTRA_TX_TYPE_SET2_8, |
| 810 | + intra_tx_type_8_set1: cdf::INTRA_TX_TYPE_SET1_8, | ||
| 781 | inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32, | 811 | inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32, |
| 782 | inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16, | 812 | inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16, |
| 783 | inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8, | 813 | inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8, |
| @@ -793,6 +823,10 @@ impl Cdfs { | |||
| 793 | mv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], | 823 | mv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], |
| 794 | filter_intra: cdf::FILTER_INTRA, | 824 | filter_intra: cdf::FILTER_INTRA, |
| 795 | filter_intra_mode: cdf::FILTER_INTRA_MODE, | 825 | filter_intra_mode: cdf::FILTER_INTRA_MODE, |
| 826 | + tx_size_cat0: cdf::TX_SIZE_CAT0, | ||
| 827 | + tx_size_cat1: cdf::TX_SIZE_CAT1, | ||
| 828 | + tx_size_cat2: cdf::TX_SIZE_CAT2, | ||
| 829 | + tx_size_cat3: cdf::TX_SIZE_CAT3, | ||
| 796 | } | 830 | } |
| 797 | } | 831 | } |
| 798 | 832 | ||
| @@ -865,6 +899,17 @@ impl Cdfs { | |||
| 865 | dc_sign: &mut self.dc_sign_luma, | 899 | dc_sign: &mut self.dc_sign_luma, |
| 866 | tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), | 900 | tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), |
| 867 | }, | 901 | }, |
| 902 | + TxbSet::Luma8Set1 => TxbTables { | ||
| 903 | + side: 8, | ||
| 904 | + txb_skip: &mut self.txb_skip_luma_8, | ||
| 905 | + eob_pt: &mut self.eob_pt_64_luma, | ||
| 906 | + eob_extra: &mut self.eob_extra_luma_8, | ||
| 907 | + base: &mut self.base_luma_8, | ||
| 908 | + base_eob: &mut self.base_eob_luma_8, | ||
| 909 | + br: &mut self.br_luma_8, | ||
| 910 | + dc_sign: &mut self.dc_sign_luma, | ||
| 911 | + tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), | ||
| 912 | + }, | ||
| 868 | TxbSet::Luma8Inter => TxbTables { | 913 | TxbSet::Luma8Inter => TxbTables { |
| 869 | side: 8, | 914 | side: 8, |
| 870 | txb_skip: &mut self.txb_skip_luma_8, | 915 | txb_skip: &mut self.txb_skip_luma_8, |
crates/ec-av1/src/decode.rsmodified+421 -23
| @@ -61,6 +61,19 @@ static DEBLOCK_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicU | |||
| 61 | pub(crate) fn deblock_hits() -> usize { | 61 | pub(crate) fn deblock_hits() -> usize { |
| 62 | DEBLOCK_HITS.load(std::sync::atomic::Ordering::Relaxed) | 62 | DEBLOCK_HITS.load(std::sync::atomic::Ordering::Relaxed) |
| 63 | } | 63 | } |
| 64 | + | ||
| 65 | +/// How many [`read_tx_size`] reads resolved a `tx_depth` strictly less than | ||
| 66 | +/// the block's own side, across every call in the process -- the same | ||
| 67 | +/// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream | ||
| 68 | +/// actually exercised a *split* transform under `TxMode::Select` rather than | ||
| 69 | +/// every block coincidentally resolving `depth=0` (indistinguishable from | ||
| 70 | +/// `TxMode::Largest` pixel-wise). | ||
| 71 | +static TX_DEPTH_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 72 | + | ||
| 73 | +/// Current value of [`TX_DEPTH_HITS`]. | ||
| 74 | +pub(crate) fn tx_depth_hits() -> usize { | ||
| 75 | + TX_DEPTH_HITS.load(std::sync::atomic::Ordering::Relaxed) | ||
| 76 | +} | ||
| 64 | const SUB_MI: u32 = 4; | 77 | const SUB_MI: u32 = 4; |
| 65 | const MI: usize = 4; | 78 | const MI: usize = 4; |
| 66 | const SB: usize = 64; | 79 | const SB: usize = 64; |
| @@ -275,13 +288,20 @@ fn read_coeffs( | |||
| 275 | } | 288 | } |
| 276 | let mut tx_type = TxType::DctDct; | 289 | let mut tx_type = TxType::DctDct; |
| 277 | if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { | 290 | if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { |
| 291 | + // The CDF row's own width names its set: 7 symbols (8 slots) is | ||
| 292 | + // `TX_SET_INTRA_1`, 5 (6 slots) the reduced `TX_SET_INTRA_2` (the | ||
| 293 | + // inter sets we read share set 2's symbol order). | ||
| 294 | + let set1 = tx_type_cdf.len() == 8; | ||
| 278 | let t = dec.symbol(tx_type_cdf); | 295 | let t = dec.symbol(tx_type_cdf); |
| 279 | if trace { | 296 | if trace { |
| 280 | - eprintln!("TRACE tx_type value={t}"); | 297 | + eprintln!("TRACE tx_type value={t} set1={set1}"); |
| 298 | + } | ||
| 299 | + tx_type = if set1 { | ||
| 300 | + TxType::from_symbol_set1(t) | ||
| 301 | + } else { | ||
| 302 | + TxType::from_symbol(t) | ||
| 281 | } | 303 | } |
| 282 | - tx_type = TxType::from_symbol(t).ok_or_else(|| { | 304 | + .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?; |
| 283 | - unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")) | ||
| 284 | - })?; | ||
| 285 | } | 305 | } |
| 286 | 306 | ||
| 287 | let eob = read_eob(dec, coding); | 307 | let eob = read_eob(dec, coding); |
| @@ -368,17 +388,37 @@ fn read_coeffs( | |||
| 368 | /// [`crate::tile`]'s own private `Neighbour`. | 388 | /// [`crate::tile`]'s own private `Neighbour`. |
| 369 | #[derive(Clone, Copy, Default)] | 389 | #[derive(Clone, Copy, Default)] |
| 370 | struct Neighbour { | 390 | struct Neighbour { |
| 371 | - coded: bool, | 391 | + /// The transform unit's cumulative coefficient level (spec `cul_level`, |
| 392 | + /// `decodetxb.c`'s `read_coeffs_txb`): the sum of every coded level's | ||
| 393 | + /// magnitude, clamped to `COEFF_CONTEXT_MASK` (7). A plain "coded or not" | ||
| 394 | + /// boolean (`level != 0`) is enough for every context this decoder read | ||
| 395 | + /// until now, but the *luma* `txb_skip_ctx` of a transform unit smaller | ||
| 396 | + /// than its own block (`TxMode::Select`, spec `get_txb_ctx_general`) | ||
| 397 | + /// needs the actual magnitude tier of its above/left neighbours, not | ||
| 398 | + /// just whether they coded anything. | ||
| 399 | + level: u8, | ||
| 372 | dc: Option<bool>, | 400 | dc: Option<bool>, |
| 373 | } | 401 | } |
| 374 | 402 | ||
| 375 | fn neighbour_state(grid: &[i32]) -> Neighbour { | 403 | fn neighbour_state(grid: &[i32]) -> Neighbour { |
| 404 | + let cul: u32 = grid.iter().map(|&l| l.unsigned_abs()).sum(); | ||
| 376 | Neighbour { | 405 | Neighbour { |
| 377 | - coded: grid.iter().any(|&l| l != 0), | 406 | + level: cul.min(7) as u8, |
| 378 | dc: (grid[0] != 0).then_some(grid[0] < 0), | 407 | dc: (grid[0] != 0).then_some(grid[0] < 0), |
| 379 | } | 408 | } |
| 380 | } | 409 | } |
| 381 | 410 | ||
| 411 | +/// spec `get_txb_ctx_general`'s `skip_contexts[top][left]` table (plane 0, | ||
| 412 | +/// transform unit smaller than the block it sits in): `top`/`left` are the | ||
| 413 | +/// above/left neighbours' magnitude tiers, each already clamped to 4. | ||
| 414 | +const SKIP_CONTEXTS: [[usize; 5]; 5] = [ | ||
| 415 | + [1, 2, 2, 2, 3], | ||
| 416 | + [2, 4, 4, 4, 5], | ||
| 417 | + [2, 4, 4, 4, 5], | ||
| 418 | + [2, 4, 4, 4, 5], | ||
| 419 | + [3, 5, 5, 5, 6], | ||
| 420 | +]; | ||
| 421 | + | ||
| 382 | /// The neighbour state a block's contexts are read from — a duplicate of | 422 | /// The neighbour state a block's contexts are read from — a duplicate of |
| 383 | /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's | 423 | /// [`crate::tile`]'s own private `Neighbours` (that module is another lane's |
| 384 | /// territory this round), kept at the same two granularities the real writer | 424 | /// territory this round), kept at the same two granularities the real writer |
| @@ -588,14 +628,37 @@ impl Neighbours { | |||
| 588 | for cell in 0..side_mi { | 628 | for cell in 0..side_mi { |
| 589 | let above = &self.above[mi_c + cell][plane]; | 629 | let above = &self.above[mi_c + cell][plane]; |
| 590 | let left = &self.left[mi_r + cell][plane]; | 630 | let left = &self.left[mi_r + cell][plane]; |
| 591 | - above_coded |= above.coded; | 631 | + above_coded |= above.level != 0; |
| 592 | - left_coded |= left.coded; | 632 | + left_coded |= left.level != 0; |
| 593 | vote += dc_vote(above.dc) + dc_vote(left.dc); | 633 | vote += dc_vote(above.dc) + dc_vote(left.dc); |
| 594 | } | 634 | } |
| 595 | (above_coded, left_coded, vote) | 635 | (above_coded, left_coded, vote) |
| 596 | }) | 636 | }) |
| 597 | } | 637 | } |
| 598 | 638 | ||
| 639 | + /// The luma `txb_skip_ctx` of a transform unit smaller than its own block | ||
| 640 | + /// (spec `get_txb_ctx_general`, plane 0, `plane_bsize != tx_size`): the | ||
| 641 | + /// above/left neighbours' magnitude tiers, OR-reduced over the unit's own | ||
| 642 | + /// span and each clamped to 4, indexed into [`SKIP_CONTEXTS`]. Unlike | ||
| 643 | + /// [`Self::around_mi`]'s plain coded/uncoded bit, this needs the real | ||
| 644 | + /// cumulative level -- a lone-TU block never calls this (its `txb_skip_ctx` | ||
| 645 | + /// is always 0, spec's `plane_bsize == tx_size` branch). | ||
| 646 | + fn luma_skip_ctx(&self, (mi_r, mi_c): (usize, usize), side_mi: usize) -> usize { | ||
| 647 | + let mut top = 0u8; | ||
| 648 | + let mut left = 0u8; | ||
| 649 | + for cell in 0..side_mi { | ||
| 650 | + top |= self.above[mi_c + cell][0].level; | ||
| 651 | + left |= self.left[mi_r + cell][0].level; | ||
| 652 | + } | ||
| 653 | + let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)]; | ||
| 654 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | ||
| 655 | + eprintln!( | ||
| 656 | + "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx}" | ||
| 657 | + ); | ||
| 658 | + } | ||
| 659 | + ctx | ||
| 660 | + } | ||
| 661 | + | ||
| 599 | /// Writes one coded block into every cell it covers, on both grids: the | 662 | /// Writes one coded block into every cell it covers, on both grids: the |
| 600 | /// mode/side arrays up to `side`'s own width, and the coefficient-context | 663 | /// mode/side arrays up to `side`'s own width, and the coefficient-context |
| 601 | /// arrays up to the true frame edge — the units past it are left at their | 664 | /// arrays up to the true frame edge — the units past it are left at their |
| @@ -658,6 +721,69 @@ impl Neighbours { | |||
| 658 | }); | 721 | }); |
| 659 | } | 722 | } |
| 660 | } | 723 | } |
| 724 | + | ||
| 725 | + /// [`Self::record_mi`]'s plane-0 half only, for one luma transform unit | ||
| 726 | + /// inside a coded block whose luma transform is smaller than its own | ||
| 727 | + /// side (`TxMode::Select`): the real per-transform-unit coefficient | ||
| 728 | + /// context (spec `AboveLevelContext`/`LeftLevelContext`), unlike the | ||
| 729 | + /// coarse per-block `tx_grid`/`fill_lf_grid` state | ||
| 730 | + /// [`Self::record_split_luma`] still writes once for the whole block. | ||
| 731 | + /// Leaves `above_side_mi`/`left_side_mi` and the chroma planes alone -- | ||
| 732 | + /// the caller's own [`Self::record_split_luma`] call sets those once, | ||
| 733 | + /// at the block's own true side, not this TU's. | ||
| 734 | + fn record_mi_luma(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, grid: &[i32]) { | ||
| 735 | + let state = neighbour_state(grid); | ||
| 736 | + let side_mi = tx_px / MI; | ||
| 737 | + for cell in 0..side_mi { | ||
| 738 | + if mi_r + cell < self.mi_rows { | ||
| 739 | + self.left[mi_r + cell][0] = state; | ||
| 740 | + } | ||
| 741 | + if mi_c + cell < self.mi_cols { | ||
| 742 | + self.above[mi_c + cell][0] = state; | ||
| 743 | + } | ||
| 744 | + } | ||
| 745 | + } | ||
| 746 | + | ||
| 747 | + /// [`Self::record`]'s mode/side and chroma-context bookkeeping, for a | ||
| 748 | + /// block whose luma was decoded as several transform units through | ||
| 749 | + /// [`Self::record_mi_luma`] rather than [`Self::record`]'s own single | ||
| 750 | + /// whole-block luma write -- everything [`Self::record`] does except | ||
| 751 | + /// plane 0, which is already correct per-TU by the time this runs. | ||
| 752 | + fn record_split_luma( | ||
| 753 | + &mut self, | ||
| 754 | + at: (usize, usize), | ||
| 755 | + side: usize, | ||
| 756 | + mode: usize, | ||
| 757 | + chroma_grids: [&[i32]; 2], | ||
| 758 | + ) { | ||
| 759 | + let (r, c) = at; | ||
| 760 | + for cell in 0..side / SUB { | ||
| 761 | + self.above_mode[c + cell] = mode; | ||
| 762 | + self.left_mode[r + cell] = mode; | ||
| 763 | + self.above_side[c + cell] = side; | ||
| 764 | + self.left_side[r + cell] = side; | ||
| 765 | + } | ||
| 766 | + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 767 | + let side_mi = side / MI; | ||
| 768 | + for cell in 0..side_mi { | ||
| 769 | + self.left_side_mi[mi_r + cell] = side; | ||
| 770 | + self.above_side_mi[mi_c + cell] = side; | ||
| 771 | + } | ||
| 772 | + let round_up_even = |n: usize| n.div_ceil(2) * 2; | ||
| 773 | + let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols)); | ||
| 774 | + for (plane_idx, grid) in chroma_grids.into_iter().enumerate() { | ||
| 775 | + let plane = plane_idx + 1; | ||
| 776 | + let state = neighbour_state(grid); | ||
| 777 | + for cell in 0..side_mi { | ||
| 778 | + if cell < side_mi.min(bound_h.saturating_sub(mi_r)) { | ||
| 779 | + self.left[mi_r + cell][plane] = state; | ||
| 780 | + } | ||
| 781 | + if cell < side_mi.min(bound_w.saturating_sub(mi_c)) { | ||
| 782 | + self.above[mi_c + cell][plane] = state; | ||
| 783 | + } | ||
| 784 | + } | ||
| 785 | + } | ||
| 786 | + } | ||
| 661 | } | 787 | } |
| 662 | 788 | ||
| 663 | /// Reads one coded block's skip flag, luma mode, angle delta (if the mode | 789 | /// Reads one coded block's skip flag, luma mode, angle delta (if the mode |
| @@ -956,9 +1082,16 @@ fn read_plane( | |||
| 956 | base_q_idx: u8, | 1082 | base_q_idx: u8, |
| 957 | cfl: Option<(i32, &[i32])>, | 1083 | cfl: Option<(i32, &[i32])>, |
| 958 | filter_intra: Option<usize>, | 1084 | filter_intra: Option<usize>, |
| 1085 | + // Only meaningful for `plane_idx == 0`: `Some` when this transform unit is | ||
| 1086 | + // smaller than its own block (spec `get_txb_ctx_general`'s | ||
| 1087 | + // `plane_bsize != tx_size` branch), carrying the already-looked-up | ||
| 1088 | + // `SKIP_CONTEXTS` value; `None` everywhere else (a lone luma TU, or any | ||
| 1089 | + // chroma plane), where `txb_skip_ctx` is 0 or the usual OR-of-neighbours | ||
| 1090 | + // formula below. | ||
| 1091 | + luma_skip_ctx: Option<usize>, | ||
| 959 | ) -> Result<Vec<i32>> { | 1092 | ) -> Result<Vec<i32>> { |
| 960 | let skip_ctx = if plane_idx == 0 { | 1093 | let skip_ctx = if plane_idx == 0 { |
| 961 | - 0 | 1094 | + luma_skip_ctx.unwrap_or(0) |
| 962 | } else { | 1095 | } else { |
| 963 | usize::from(around.0) + usize::from(around.1) | 1096 | usize::from(around.0) + usize::from(around.1) |
| 964 | }; | 1097 | }; |
| @@ -1035,6 +1168,11 @@ fn decode_block( | |||
| 1035 | v: &mut PlaneBuf, | 1168 | v: &mut PlaneBuf, |
| 1036 | base_q_idx: u8, | 1169 | base_q_idx: u8, |
| 1037 | enable_filter_intra: bool, | 1170 | enable_filter_intra: bool, |
| 1171 | + scan32: &[u16], | ||
| 1172 | + scan16: &[u16], | ||
| 1173 | + scan8: &[u16], | ||
| 1174 | + tx_select: bool, | ||
| 1175 | + reduced_tx_set: bool, | ||
| 1038 | ) -> Result<()> { | 1176 | ) -> Result<()> { |
| 1039 | let (r, c) = at; | 1177 | let (r, c) = at; |
| 1040 | let (px, py) = (c * SUB, r * SUB); | 1178 | let (px, py) = (c * SUB, r * SUB); |
| @@ -1047,8 +1185,31 @@ fn decode_block( | |||
| 1047 | side, | 1185 | side, |
| 1048 | enable_filter_intra, | 1186 | enable_filter_intra, |
| 1049 | )?; | 1187 | )?; |
| 1188 | + let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | ||
| 1189 | + // `TxMode::Select`'s `tx_depth` (spec 5.11.16): read for every intra | ||
| 1190 | + // block, skipped or not. `logical_tx` is what the loop filter's edge | ||
| 1191 | + // lookup and the next block's own `tx_size_context` want (the *nominal* | ||
| 1192 | + // transform size -- 64 even for the 64x64 corner-scanned case, spec | ||
| 1193 | + // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side, | ||
| 1194 | + // which only differs from it at that one corner case. | ||
| 1195 | + let (logical_tx, coeff_tx_side) = if tx_select { | ||
| 1196 | + let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side); | ||
| 1197 | + if resolved == 4 { | ||
| 1198 | + return Err(unsupported( | ||
| 1199 | + "a resolved 4x4 luma transform (TxMode::Select depth exhausted; this decoder has no 4x4 luma coefficient tables)", | ||
| 1200 | + )); | ||
| 1201 | + } | ||
| 1202 | + (resolved, if resolved == 64 { 32 } else { resolved }) | ||
| 1203 | + } else { | ||
| 1204 | + (side, luma_tx) | ||
| 1205 | + }; | ||
| 1206 | + let luma_set = if tx_select { | ||
| 1207 | + txbset_for(logical_tx, reduced_tx_set) | ||
| 1208 | + } else { | ||
| 1209 | + luma_set | ||
| 1210 | + }; | ||
| 1211 | + let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8); | ||
| 1050 | let reach = Reach::of(side, px, py, y.width, y.height); | 1212 | let reach = Reach::of(side, px, py, y.width, y.height); |
| 1051 | - let (luma_grid, u_grid, v_grid); | ||
| 1052 | let (cpx, cpy) = (px / 2, py / 2); | 1213 | let (cpx, cpy) = (px / 2, py / 2); |
| 1053 | let chroma_side = side / 2; | 1214 | let chroma_side = side / 2; |
| 1054 | if skip { | 1215 | if skip { |
| @@ -1085,16 +1246,20 @@ fn decode_block( | |||
| 1085 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 1246 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 1086 | None, | 1247 | None, |
| 1087 | ); | 1248 | ); |
| 1088 | - luma_grid = vec![0i32; side * side]; | 1249 | + let luma_grid = vec![0i32; side * side]; |
| 1089 | - u_grid = vec![0i32; chroma_side * chroma_side]; | 1250 | + let u_grid = vec![0i32; chroma_side * chroma_side]; |
| 1090 | - v_grid = vec![0i32; chroma_side * chroma_side]; | 1251 | + let v_grid = vec![0i32; chroma_side * chroma_side]; |
| 1091 | - } else { | 1252 | + neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]); |
| 1253 | + } else if !tx_select || logical_tx == side { | ||
| 1254 | + // A single luma transform unit -- the old path, unchanged (including | ||
| 1255 | + // the 64x64 corner case, `logical_tx == side == 64` with | ||
| 1256 | + // `coeff_tx_side == 32`). | ||
| 1092 | let around = neighbours.around(at, side); | 1257 | let around = neighbours.around(at, side); |
| 1093 | - luma_grid = read_plane( | 1258 | + let luma_grid = read_plane( |
| 1094 | dec, | 1259 | dec, |
| 1095 | cdfs, | 1260 | cdfs, |
| 1096 | luma_set, | 1261 | luma_set, |
| 1097 | - scans.0, | 1262 | + luma_scan, |
| 1098 | 0, | 1263 | 0, |
| 1099 | around[0], | 1264 | around[0], |
| 1100 | mode, | 1265 | mode, |
| @@ -1104,13 +1269,14 @@ fn decode_block( | |||
| 1104 | px, | 1269 | px, |
| 1105 | py, | 1270 | py, |
| 1106 | side, | 1271 | side, |
| 1107 | - luma_tx, | 1272 | + coeff_tx_side, |
| 1108 | base_q_idx, | 1273 | base_q_idx, |
| 1109 | None, | 1274 | None, |
| 1110 | filter_intra, | 1275 | filter_intra, |
| 1276 | + None, | ||
| 1111 | )?; | 1277 | )?; |
| 1112 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 1278 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 1113 | - u_grid = read_plane( | 1279 | + let u_grid = read_plane( |
| 1114 | dec, | 1280 | dec, |
| 1115 | cdfs, | 1281 | cdfs, |
| 1116 | chroma_set, | 1282 | chroma_set, |
| @@ -1128,8 +1294,9 @@ fn decode_block( | |||
| 1128 | base_q_idx, | 1294 | base_q_idx, |
| 1129 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 1295 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 1130 | None, | 1296 | None, |
| 1297 | + None, | ||
| 1131 | )?; | 1298 | )?; |
| 1132 | - v_grid = read_plane( | 1299 | + let v_grid = read_plane( |
| 1133 | dec, | 1300 | dec, |
| 1134 | cdfs, | 1301 | cdfs, |
| 1135 | chroma_set, | 1302 | chroma_set, |
| @@ -1147,14 +1314,104 @@ fn decode_block( | |||
| 1147 | base_q_idx, | 1314 | base_q_idx, |
| 1148 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 1315 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 1149 | None, | 1316 | None, |
| 1317 | + None, | ||
| 1150 | )?; | 1318 | )?; |
| 1319 | + neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]); | ||
| 1320 | + } else { | ||
| 1321 | + // Several luma transform units, raster order (spec | ||
| 1322 | + // `transform_block`'s loop): the block's resolved transform is | ||
| 1323 | + // genuinely smaller than its own side, so each tile of it predicts | ||
| 1324 | + // and codes independently, its own context read fresh off whatever | ||
| 1325 | + // the earlier tiles in this same block already wrote -- the same | ||
| 1326 | + // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. | ||
| 1327 | + let n_axis = side / logical_tx; | ||
| 1328 | + for tu_row in 0..n_axis { | ||
| 1329 | + for tu_col in 0..n_axis { | ||
| 1330 | + let tu_mi = ( | ||
| 1331 | + mi_r + tu_row * (logical_tx / MI), | ||
| 1332 | + mi_c + tu_col * (logical_tx / MI), | ||
| 1333 | + ); | ||
| 1334 | + let tu_px = px + tu_col * logical_tx; | ||
| 1335 | + let tu_py = py + tu_row * logical_tx; | ||
| 1336 | + let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0]; | ||
| 1337 | + let tu_reach = Reach::of(logical_tx, tu_px, tu_py, y.width, y.height); | ||
| 1338 | + // This transform unit's own bsize (`logical_tx`) is smaller | ||
| 1339 | + // than the block it sits in (`side`), so `txb_skip_ctx` is | ||
| 1340 | + // the neighbour-magnitude table, not the lone-TU 0 (spec | ||
| 1341 | + // `get_txb_ctx_general`'s `plane_bsize != tx_size` branch). | ||
| 1342 | + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, logical_tx / MI); | ||
| 1343 | + let tu_grid = read_plane( | ||
| 1344 | + dec, | ||
| 1345 | + cdfs, | ||
| 1346 | + luma_set, | ||
| 1347 | + luma_scan, | ||
| 1348 | + 0, | ||
| 1349 | + tu_around, | ||
| 1350 | + mode, | ||
| 1351 | + mode, | ||
| 1352 | + tu_reach, | ||
| 1353 | + y, | ||
| 1354 | + tu_px, | ||
| 1355 | + tu_py, | ||
| 1356 | + logical_tx, | ||
| 1357 | + logical_tx, | ||
| 1358 | + base_q_idx, | ||
| 1359 | + None, | ||
| 1360 | + filter_intra, | ||
| 1361 | + Some(tu_skip_ctx), | ||
| 1362 | + )?; | ||
| 1363 | + neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid); | ||
| 1364 | + } | ||
| 1365 | + } | ||
| 1366 | + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | ||
| 1367 | + let chroma_around = neighbours.around(at, side); | ||
| 1368 | + let u_grid = read_plane( | ||
| 1369 | + dec, | ||
| 1370 | + cdfs, | ||
| 1371 | + chroma_set, | ||
| 1372 | + scans.1, | ||
| 1373 | + 1, | ||
| 1374 | + chroma_around[1], | ||
| 1375 | + mode, | ||
| 1376 | + DC_PRED, | ||
| 1377 | + Reach::none(), | ||
| 1378 | + u, | ||
| 1379 | + cpx, | ||
| 1380 | + cpy, | ||
| 1381 | + chroma_side, | ||
| 1382 | + chroma_tx, | ||
| 1383 | + base_q_idx, | ||
| 1384 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 1385 | + None, | ||
| 1386 | + None, | ||
| 1387 | + )?; | ||
| 1388 | + let v_grid = read_plane( | ||
| 1389 | + dec, | ||
| 1390 | + cdfs, | ||
| 1391 | + chroma_set, | ||
| 1392 | + scans.1, | ||
| 1393 | + 2, | ||
| 1394 | + chroma_around[2], | ||
| 1395 | + mode, | ||
| 1396 | + DC_PRED, | ||
| 1397 | + Reach::none(), | ||
| 1398 | + v, | ||
| 1399 | + cpx, | ||
| 1400 | + cpy, | ||
| 1401 | + chroma_side, | ||
| 1402 | + chroma_tx, | ||
| 1403 | + base_q_idx, | ||
| 1404 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 1405 | + None, | ||
| 1406 | + None, | ||
| 1407 | + )?; | ||
| 1408 | + neighbours.record_split_luma(at, side, mode, [&u_grid, &v_grid]); | ||
| 1151 | } | 1409 | } |
| 1152 | - neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]); | ||
| 1153 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); | 1410 | neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip); |
| 1154 | neighbours.fill_lf_grid( | 1411 | neighbours.fill_lf_grid( |
| 1155 | (r * (SUB / MI), c * (SUB / MI)), | 1412 | (r * (SUB / MI), c * (SUB / MI)), |
| 1156 | side / MI, | 1413 | side / MI, |
| 1157 | - side as u8, | 1414 | + logical_tx as u8, |
| 1158 | false, | 1415 | false, |
| 1159 | ); | 1416 | ); |
| 1160 | Ok(()) | 1417 | Ok(()) |
| @@ -1183,6 +1440,8 @@ fn decode_leaf8( | |||
| 1183 | v: &mut PlaneBuf, | 1440 | v: &mut PlaneBuf, |
| 1184 | base_q_idx: u8, | 1441 | base_q_idx: u8, |
| 1185 | enable_filter_intra: bool, | 1442 | enable_filter_intra: bool, |
| 1443 | + tx_select: bool, | ||
| 1444 | + reduced_tx_set: bool, | ||
| 1186 | ) -> Result<usize> { | 1445 | ) -> Result<usize> { |
| 1187 | let (r, c) = outer_at; | 1446 | let (r, c) = outer_at; |
| 1188 | let mut above_mode = neighbours.above_mode[c]; | 1447 | let mut above_mode = neighbours.above_mode[c]; |
| @@ -1206,6 +1465,19 @@ fn decode_leaf8( | |||
| 1206 | 8, | 1465 | 8, |
| 1207 | enable_filter_intra, | 1466 | enable_filter_intra, |
| 1208 | )?; | 1467 | )?; |
| 1468 | + // `TxMode::Select`'s `tx_depth` at an 8x8 leaf (spec 5.11.16): the only | ||
| 1469 | + // depths an 8x8 block offers are `TX8` (depth 0, this decoder's one | ||
| 1470 | + // supported case) and `TX4` (depth 1, which this crate has no 4x4 luma | ||
| 1471 | + // coefficient tables for) -- read to stay in sync, then refuse rather | ||
| 1472 | + // than silently miscode. | ||
| 1473 | + if tx_select { | ||
| 1474 | + let resolved = read_tx_size(dec, cdfs, neighbours, leaf_mi, 8); | ||
| 1475 | + if resolved == 4 { | ||
| 1476 | + return Err(unsupported( | ||
| 1477 | + "a resolved 4x4 luma transform (TxMode::Select depth exhausted; this decoder has no 4x4 luma coefficient tables)", | ||
| 1478 | + )); | ||
| 1479 | + } | ||
| 1480 | + } | ||
| 1209 | let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); | 1481 | let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); |
| 1210 | let reach = Reach::of(8, px, py, y.width, y.height); | 1482 | let reach = Reach::of(8, px, py, y.width, y.height); |
| 1211 | let (cpx, cpy) = (px / 2, py / 2); | 1483 | let (cpx, cpy) = (px / 2, py / 2); |
| @@ -1241,7 +1513,11 @@ fn decode_leaf8( | |||
| 1241 | luma_grid = read_plane( | 1513 | luma_grid = read_plane( |
| 1242 | dec, | 1514 | dec, |
| 1243 | cdfs, | 1515 | cdfs, |
| 1244 | - TxbSet::Luma8, | 1516 | + if reduced_tx_set { |
| 1517 | + TxbSet::Luma8 | ||
| 1518 | + } else { | ||
| 1519 | + TxbSet::Luma8Set1 | ||
| 1520 | + }, | ||
| 1245 | scans.0, | 1521 | scans.0, |
| 1246 | 0, | 1522 | 0, |
| 1247 | around[0], | 1523 | around[0], |
| @@ -1256,6 +1532,7 @@ fn decode_leaf8( | |||
| 1256 | base_q_idx, | 1532 | base_q_idx, |
| 1257 | None, | 1533 | None, |
| 1258 | filter_intra, | 1534 | filter_intra, |
| 1535 | + None, | ||
| 1259 | )?; | 1536 | )?; |
| 1260 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); | 1537 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8)); |
| 1261 | u_grid = read_plane( | 1538 | u_grid = read_plane( |
| @@ -1276,6 +1553,7 @@ fn decode_leaf8( | |||
| 1276 | base_q_idx, | 1553 | base_q_idx, |
| 1277 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 1554 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 1278 | None, | 1555 | None, |
| 1556 | + None, | ||
| 1279 | )?; | 1557 | )?; |
| 1280 | v_grid = read_plane( | 1558 | v_grid = read_plane( |
| 1281 | dec, | 1559 | dec, |
| @@ -1295,6 +1573,7 @@ fn decode_leaf8( | |||
| 1295 | base_q_idx, | 1573 | base_q_idx, |
| 1296 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 1574 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 1297 | None, | 1575 | None, |
| 1576 | + None, | ||
| 1298 | )?; | 1577 | )?; |
| 1299 | } | 1578 | } |
| 1300 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 1579 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| @@ -1537,6 +1816,76 @@ fn tx_px_at(n: &Neighbours, chroma: bool, mi_r: usize, mi_c: usize) -> u32 { | |||
| 1537 | if chroma { luma_tx / 2 } else { luma_tx } | 1816 | if chroma { luma_tx / 2 } else { luma_tx } |
| 1538 | } | 1817 | } |
| 1539 | 1818 | ||
| 1819 | +/// `get_tx_size_context` (spec 9.3's `TxDepthCtx`, libaom | ||
| 1820 | +/// `TXFM_CONTEXT`/`entropymode.c`): the sum of two boolean terms, each | ||
| 1821 | +/// present only when its neighbour exists inside the true frame -- whether | ||
| 1822 | +/// the block immediately above (at this block's own leftmost mi column) or | ||
| 1823 | +/// to the left (at its own topmost mi row) coded a transform at least as wide | ||
| 1824 | +/// as `own_side`. | ||
| 1825 | +fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { | ||
| 1826 | + let above = mi_r > 0 && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_side; | ||
| 1827 | + let left = mi_c > 0 && tx_px_at(n, false, mi_r, mi_c - 1) as usize >= own_side; | ||
| 1828 | + usize::from(above) + usize::from(left) | ||
| 1829 | +} | ||
| 1830 | + | ||
| 1831 | +/// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under | ||
| 1832 | +/// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to | ||
| 1833 | +/// the transform's own side in pixels (`side >> depth`) -- this decoder's | ||
| 1834 | +/// four square categories (8/16/32/64) each halve at most twice, matching | ||
| 1835 | +/// libaom's own per-size depth cap (`cdf::TX_SIZE_CAT0`..`TX_SIZE_CAT3`). | ||
| 1836 | +fn read_tx_size( | ||
| 1837 | + dec: &mut SymbolDecoder, | ||
| 1838 | + cdfs: &mut Cdfs, | ||
| 1839 | + n: &Neighbours, | ||
| 1840 | + at_mi: (usize, usize), | ||
| 1841 | + side: usize, | ||
| 1842 | +) -> usize { | ||
| 1843 | + let ctx = tx_size_context(n, at_mi, side); | ||
| 1844 | + let depth = match side { | ||
| 1845 | + 8 => dec.symbol(&mut cdfs.tx_size_cat0[ctx]), | ||
| 1846 | + 16 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), | ||
| 1847 | + 32 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), | ||
| 1848 | + 64 => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), | ||
| 1849 | + _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), | ||
| 1850 | + }; | ||
| 1851 | + if depth != 0 { | ||
| 1852 | + TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 1853 | + } | ||
| 1854 | + side >> depth | ||
| 1855 | +} | ||
| 1856 | + | ||
| 1857 | +/// The luma coefficient scan table for a resolved transform side -- 32/16/8, | ||
| 1858 | +/// the only three sizes a `TxMode::Select` block's coded coefficient grid | ||
| 1859 | +/// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be. | ||
| 1860 | +fn scan_for<'a>(tx_px: usize, scan32: &'a [u16], scan16: &'a [u16], scan8: &'a [u16]) -> &'a [u16] { | ||
| 1861 | + match tx_px { | ||
| 1862 | + 32 => scan32, | ||
| 1863 | + 16 => scan16, | ||
| 1864 | + 8 => scan8, | ||
| 1865 | + _ => unreachable!("read_tx_size never resolves the coefficient grid to anything else"), | ||
| 1866 | + } | ||
| 1867 | +} | ||
| 1868 | + | ||
| 1869 | +/// The [`TxbSet`] a resolved luma transform side reads its coefficient tables | ||
| 1870 | +/// from -- 64 is only ever the 64x64-block, depth-0, corner-scanned case | ||
| 1871 | +/// ([`TxbSet::Luma64`]); every other resolved side maps to its own matching | ||
| 1872 | +/// set. `get_tx_set` (spec 5.11.48) only splits on `reduced_tx_set` at | ||
| 1873 | +/// `TX_8X8`: an intra `TX_16X16` always reads `TX_SET_INTRA_2` regardless of | ||
| 1874 | +/// the flag (`av1_get_ext_tx_set_type`'s `tx_size_sqr == TX_16X16` branch | ||
| 1875 | +/// ignores `use_reduced_set` once it is past the `TX_32X32`/reduced-set | ||
| 1876 | +/// checks), so only the 8x8 case has a second table | ||
| 1877 | +/// ([`TxbSet::Luma8Set1`]). | ||
| 1878 | +fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { | ||
| 1879 | + match tx_px { | ||
| 1880 | + 64 => TxbSet::Luma64, | ||
| 1881 | + 32 => TxbSet::Luma32, | ||
| 1882 | + 16 => TxbSet::Luma16, | ||
| 1883 | + 8 if reduced_tx_set => TxbSet::Luma8, | ||
| 1884 | + 8 => TxbSet::Luma8Set1, | ||
| 1885 | + _ => unreachable!("read_tx_size never resolves a block's own side to anything else"), | ||
| 1886 | + } | ||
| 1887 | +} | ||
| 1888 | + | ||
| 1540 | /// `tx_size_wide_unit_log2`/`tx_size_high_unit_log2`: `log2(px / 4)`, the | 1889 | /// `tx_size_wide_unit_log2`/`tx_size_high_unit_log2`: `log2(px / 4)`, the |
| 1541 | /// index [`tx_dim_to_filter_length`] and the chroma 4-vs-6 choice key on. | 1890 | /// index [`tx_dim_to_filter_length`] and the chroma 4-vs-6 choice key on. |
| 1542 | fn unit_log2(px: u32) -> i32 { | 1891 | fn unit_log2(px: u32) -> i32 { |
| @@ -2077,6 +2426,8 @@ pub fn decode_key_frame_tile( | |||
| 2077 | enable_filter_intra: bool, | 2426 | enable_filter_intra: bool, |
| 2078 | cdef: &CdefParams, | 2427 | cdef: &CdefParams, |
| 2079 | loop_filter: &LoopFilterParams, | 2428 | loop_filter: &LoopFilterParams, |
| 2429 | + tx_select: bool, | ||
| 2430 | + reduced_tx_set: bool, | ||
| 2080 | ) -> Result<Picture> { | 2431 | ) -> Result<Picture> { |
| 2081 | decode_key_frame_tile_with_cdfs( | 2432 | decode_key_frame_tile_with_cdfs( |
| 2082 | data, | 2433 | data, |
| @@ -2089,6 +2440,8 @@ pub fn decode_key_frame_tile( | |||
| 2089 | cdef, | 2440 | cdef, |
| 2090 | loop_filter, | 2441 | loop_filter, |
| 2091 | None, | 2442 | None, |
| 2443 | + tx_select, | ||
| 2444 | + reduced_tx_set, | ||
| 2092 | ) | 2445 | ) |
| 2093 | .map(|(picture, _)| picture) | 2446 | .map(|(picture, _)| picture) |
| 2094 | } | 2447 | } |
| @@ -2112,6 +2465,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2112 | cdef: &CdefParams, | 2465 | cdef: &CdefParams, |
| 2113 | loop_filter: &LoopFilterParams, | 2466 | loop_filter: &LoopFilterParams, |
| 2114 | initial_cdfs: Option<Cdfs>, | 2467 | initial_cdfs: Option<Cdfs>, |
| 2468 | + tx_select: bool, | ||
| 2469 | + reduced_tx_set: bool, | ||
| 2115 | ) -> Result<(Picture, Cdfs)> { | 2470 | ) -> Result<(Picture, Cdfs)> { |
| 2116 | if mi_cols == 0 || mi_rows == 0 { | 2471 | if mi_cols == 0 || mi_rows == 0 { |
| 2117 | return Err(unsupported("a frame with no mode-info grid")); | 2472 | return Err(unsupported("a frame with no mode-info grid")); |
| @@ -2217,6 +2572,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2217 | &mut v, | 2572 | &mut v, |
| 2218 | base_q_idx, | 2573 | base_q_idx, |
| 2219 | enable_filter_intra, | 2574 | enable_filter_intra, |
| 2575 | + &scan32, | ||
| 2576 | + &scan16, | ||
| 2577 | + &scan8, | ||
| 2578 | + tx_select, | ||
| 2579 | + reduced_tx_set, | ||
| 2220 | )?; | 2580 | )?; |
| 2221 | } | 2581 | } |
| 2222 | PARTITION_SPLIT => { | 2582 | PARTITION_SPLIT => { |
| @@ -2274,6 +2634,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2274 | &mut v, | 2634 | &mut v, |
| 2275 | base_q_idx, | 2635 | base_q_idx, |
| 2276 | enable_filter_intra, | 2636 | enable_filter_intra, |
| 2637 | + &scan32, | ||
| 2638 | + &scan16, | ||
| 2639 | + &scan8, | ||
| 2640 | + tx_select, | ||
| 2641 | + reduced_tx_set, | ||
| 2277 | )?; | 2642 | )?; |
| 2278 | } | 2643 | } |
| 2279 | PARTITION_SPLIT => { | 2644 | PARTITION_SPLIT => { |
| @@ -2293,6 +2658,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2293 | let ctx16 = neighbours.partition_ctx(at16, SUB); | 2658 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| 2294 | if has_cols16 && has_rows16 { | 2659 | if has_cols16 && has_rows16 { |
| 2295 | let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); | 2660 | let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); |
| 2661 | + if std::env::var_os("EC_AV1_TRACE").is_some() { | ||
| 2662 | + eprintln!( | ||
| 2663 | + "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}", | ||
| 2664 | + at16.0, at16.1 | ||
| 2665 | + ); | ||
| 2666 | + } | ||
| 2296 | if part16 == PARTITION_NONE { | 2667 | if part16 == PARTITION_NONE { |
| 2297 | decode_block( | 2668 | decode_block( |
| 2298 | &mut dec, | 2669 | &mut dec, |
| @@ -2311,6 +2682,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2311 | &mut v, | 2682 | &mut v, |
| 2312 | base_q_idx, | 2683 | base_q_idx, |
| 2313 | enable_filter_intra, | 2684 | enable_filter_intra, |
| 2685 | + &scan32, | ||
| 2686 | + &scan16, | ||
| 2687 | + &scan8, | ||
| 2688 | + tx_select, | ||
| 2689 | + reduced_tx_set, | ||
| 2314 | )?; | 2690 | )?; |
| 2315 | continue; | 2691 | continue; |
| 2316 | } | 2692 | } |
| @@ -2354,6 +2730,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2354 | &mut v, | 2730 | &mut v, |
| 2355 | base_q_idx, | 2731 | base_q_idx, |
| 2356 | enable_filter_intra, | 2732 | enable_filter_intra, |
| 2733 | + tx_select, | ||
| 2734 | + reduced_tx_set, | ||
| 2357 | )?; | 2735 | )?; |
| 2358 | prev_leaf = Some((leaf_mi, leaf_mode)); | 2736 | prev_leaf = Some((leaf_mi, leaf_mode)); |
| 2359 | } | 2737 | } |
| @@ -2416,6 +2794,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 2416 | &mut v, | 2794 | &mut v, |
| 2417 | base_q_idx, | 2795 | base_q_idx, |
| 2418 | enable_filter_intra, | 2796 | enable_filter_intra, |
| 2797 | + tx_select, | ||
| 2798 | + reduced_tx_set, | ||
| 2419 | )?; | 2799 | )?; |
| 2420 | prev_leaf = Some((leaf_mi, leaf_mode)); | 2800 | prev_leaf = Some((leaf_mi, leaf_mode)); |
| 2421 | } | 2801 | } |
| @@ -2982,6 +3362,7 @@ fn decode_inter_block( | |||
| 2982 | base_q_idx, | 3362 | base_q_idx, |
| 2983 | None, | 3363 | None, |
| 2984 | None, | 3364 | None, |
| 3365 | + None, | ||
| 2985 | )?; | 3366 | )?; |
| 2986 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 3367 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 2987 | u_grid = read_plane( | 3368 | u_grid = read_plane( |
| @@ -3002,6 +3383,7 @@ fn decode_inter_block( | |||
| 3002 | base_q_idx, | 3383 | base_q_idx, |
| 3003 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 3384 | alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 3004 | None, | 3385 | None, |
| 3386 | + None, | ||
| 3005 | )?; | 3387 | )?; |
| 3006 | v_grid = read_plane( | 3388 | v_grid = read_plane( |
| 3007 | dec, | 3389 | dec, |
| @@ -3021,6 +3403,7 @@ fn decode_inter_block( | |||
| 3021 | base_q_idx, | 3403 | base_q_idx, |
| 3022 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 3404 | alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 3023 | None, | 3405 | None, |
| 3406 | + None, | ||
| 3024 | )?; | 3407 | )?; |
| 3025 | } | 3408 | } |
| 3026 | } | 3409 | } |
| @@ -3377,6 +3760,7 @@ fn decode_inter_block8( | |||
| 3377 | base_q_idx, | 3760 | base_q_idx, |
| 3378 | None, | 3761 | None, |
| 3379 | None, | 3762 | None, |
| 3763 | + None, | ||
| 3380 | )?; | 3764 | )?; |
| 3381 | u_grid = read_plane( | 3765 | u_grid = read_plane( |
| 3382 | dec, | 3766 | dec, |
| @@ -3396,6 +3780,7 @@ fn decode_inter_block8( | |||
| 3396 | base_q_idx, | 3780 | base_q_idx, |
| 3397 | None, | 3781 | None, |
| 3398 | None, | 3782 | None, |
| 3783 | + None, | ||
| 3399 | )?; | 3784 | )?; |
| 3400 | v_grid = read_plane( | 3785 | v_grid = read_plane( |
| 3401 | dec, | 3786 | dec, |
| @@ -3415,6 +3800,7 @@ fn decode_inter_block8( | |||
| 3415 | base_q_idx, | 3800 | base_q_idx, |
| 3416 | None, | 3801 | None, |
| 3417 | None, | 3802 | None, |
| 3803 | + None, | ||
| 3418 | )?; | 3804 | )?; |
| 3419 | } | 3805 | } |
| 3420 | } | 3806 | } |
| @@ -3808,7 +4194,9 @@ mod tests { | |||
| 3808 | 128, | 4194 | 128, |
| 3809 | false, | 4195 | false, |
| 3810 | &CdefParams::default(), | 4196 | &CdefParams::default(), |
| 3811 | - &LoopFilterParams::default() | 4197 | + &LoopFilterParams::default(), |
| 4198 | + false, | ||
| 4199 | + true, | ||
| 3812 | ) | 4200 | ) |
| 3813 | .is_err() | 4201 | .is_err() |
| 3814 | ); | 4202 | ); |
| @@ -3849,6 +4237,8 @@ mod tests { | |||
| 3849 | false, | 4237 | false, |
| 3850 | &CdefParams::default(), | 4238 | &CdefParams::default(), |
| 3851 | &LoopFilterParams::default(), | 4239 | &LoopFilterParams::default(), |
| 4240 | + false, | ||
| 4241 | + true, | ||
| 3852 | ) | 4242 | ) |
| 3853 | .unwrap(); | 4243 | .unwrap(); |
| 3854 | assert_eq!(decoded.width, w, "{w}x{h}: decoded width"); | 4244 | assert_eq!(decoded.width, w, "{w}x{h}: decoded width"); |
| @@ -3930,6 +4320,8 @@ mod tests { | |||
| 3930 | false, | 4320 | false, |
| 3931 | &CdefParams::default(), | 4321 | &CdefParams::default(), |
| 3932 | &LoopFilterParams::default(), | 4322 | &LoopFilterParams::default(), |
| 4323 | + false, | ||
| 4324 | + true, | ||
| 3933 | ) | 4325 | ) |
| 3934 | .unwrap(); | 4326 | .unwrap(); |
| 3935 | assert!( | 4327 | assert!( |
| @@ -4113,6 +4505,8 @@ mod tests { | |||
| 4113 | false, | 4505 | false, |
| 4114 | &CdefParams::default(), | 4506 | &CdefParams::default(), |
| 4115 | &LoopFilterParams::default(), | 4507 | &LoopFilterParams::default(), |
| 4508 | + false, | ||
| 4509 | + true, | ||
| 4116 | ) | 4510 | ) |
| 4117 | .unwrap(); | 4511 | .unwrap(); |
| 4118 | assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg"); | 4512 | assert_eq!(ours.y, ffmpeg_decoded.y, "{width}x{height}: luma vs ffmpeg"); |
| @@ -4183,6 +4577,8 @@ mod tests { | |||
| 4183 | false, | 4577 | false, |
| 4184 | &CdefParams::default(), | 4578 | &CdefParams::default(), |
| 4185 | &LoopFilterParams::default(), | 4579 | &LoopFilterParams::default(), |
| 4580 | + false, | ||
| 4581 | + true, | ||
| 4186 | ) | 4582 | ) |
| 4187 | .unwrap(); | 4583 | .unwrap(); |
| 4188 | assert_eq!( | 4584 | assert_eq!( |
| @@ -4456,6 +4852,8 @@ mod tests { | |||
| 4456 | false, | 4852 | false, |
| 4457 | &CdefParams::default(), | 4853 | &CdefParams::default(), |
| 4458 | &LoopFilterParams::default(), | 4854 | &LoopFilterParams::default(), |
| 4855 | + false, | ||
| 4856 | + true, | ||
| 4459 | ) | 4857 | ) |
| 4460 | .unwrap(); | 4858 | .unwrap(); |
| 4461 | assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg"); | 4859 | assert_eq!(reference.y, ffmpeg_frames[0].y, "frame 0 luma vs ffmpeg"); |
crates/ec-av1/src/stream.rsmodified+184 -14
| @@ -92,22 +92,22 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 92 | "a frame with cdef_bits > 0 (this decoder never reads the per-64x64 cdef_idx symbol)", | 92 | "a frame with cdef_bits > 0 (this decoder never reads the per-64x64 cdef_idx symbol)", |
| 93 | )); | 93 | )); |
| 94 | } | 94 | } |
| 95 | - // Every `decode_block` call below assumes the block's transform is | 95 | + // An intra frame's `decode_key_frame_tile*` now reads `tx_depth` |
| 96 | - // its own full size (`TxMode::Largest`, which is all this crate's own | 96 | + // under `TxMode::Select` (lane-av1txsel, spec 5.11.16): the key-frame |
| 97 | - // encoder ever writes, spec `read_tx_size` inferring the max depth | 97 | + // decode path threads `tx_select` through `decode_block`/ |
| 98 | - // with no bits) -- it never reads a `tx_depth` symbol at all. A real | 98 | + // `decode_leaf8`, and refuses on its own (a named `unsupported`, not |
| 99 | - // encoder's `TxMode::Select` (spec 5.9.2's `tx_mode` bit) codes one | 99 | + // a silent desync) the one case it still cannot code -- a resolved |
| 100 | - // per intra block, and skipping that read does not error -- the | 100 | + // 4x4 luma transform, which has no coefficient tables here. This |
| 101 | - // decoder just goes on consuming the next bits as if they were the | 101 | + // refusal is narrowed to what genuinely still has no reader at all: |
| 102 | - // uv_mode/coefficient symbols they are not, so the block "decodes" | 102 | + // `decode_inter_frame`'s inter path never threads `tx_select` |
| 103 | - // syntactically clean into low-energy garbage: lane-av1real r3's | 103 | + // through its own block loop, so an inter frame under |
| 104 | - // luma-near-flat-vs-ffmpeg-gradient bug. Refuse before that, the same | 104 | + // `TxMode::Select` still desyncs the same way the comment above used |
| 105 | - // way as the CDEF case above, rather than silently miscode every | 105 | + // to describe for every frame -- lane-av1real r3's |
| 106 | - // `TxMode::Select` stream. | 106 | + // luma-near-flat-vs-ffmpeg-gradient bug. |
| 107 | - if header.tx_mode == TxMode::Select { | 107 | + if header.tx_mode == TxMode::Select && header.frame_type != FrameType::Key { |
| 108 | return Err(Error::unsupported( | 108 | return Err(Error::unsupported( |
| 109 | "AV1 decode_stream", | 109 | "AV1 decode_stream", |
| 110 | - "a frame using TxMode::Select (this decoder never reads a tx_depth symbol, so it desyncs after the first intra block's mode)", | 110 | + "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", |
| 111 | )); | 111 | )); |
| 112 | } | 112 | } |
| 113 | // lane-av1real r11's blindness-audit sweep (`read_intra_frame_mode_info`, | 113 | // lane-av1real r11's blindness-audit sweep (`read_intra_frame_mode_info`, |
| @@ -214,6 +214,8 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 214 | &header.cdef, | 214 | &header.cdef, |
| 215 | &header.loop_filter, | 215 | &header.loop_filter, |
| 216 | initial_cdfs, | 216 | initial_cdfs, |
| 217 | + header.tx_mode == TxMode::Select, | ||
| 218 | + header.reduced_tx_set, | ||
| 217 | )? | 219 | )? |
| 218 | } else { | 220 | } else { |
| 219 | let last_slot = header.ref_frame_idx[0] as usize; | 221 | let last_slot = header.ref_frame_idx[0] as usize; |
| @@ -339,6 +341,9 @@ mod tests { | |||
| 339 | false, | 341 | false, |
| 340 | &ec_av1_syntax::CdefParams::default(), | 342 | &ec_av1_syntax::CdefParams::default(), |
| 341 | &ec_av1_syntax::LoopFilterParams::default(), | 343 | &ec_av1_syntax::LoopFilterParams::default(), |
| 344 | + false, | ||
| 345 | + // Our own encoder always writes `reduced_tx_set: true`. | ||
| 346 | + true, | ||
| 342 | ) | 347 | ) |
| 343 | .unwrap(); | 348 | .unwrap(); |
| 344 | let via_stream = decode_stream(&encoded.stream).unwrap(); | 349 | let via_stream = decode_stream(&encoded.stream).unwrap(); |
| @@ -996,6 +1001,171 @@ mod tests { | |||
| 996 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); | 1001 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); |
| 997 | } | 1002 | } |
| 998 | 1003 | ||
| 1004 | + /// As [`a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact`], | ||
| 1005 | + /// but WITHOUT `--enable-tx-size-search=0` -- the one flag every other | ||
| 1006 | + /// recipe in this file pins off specifically to keep the stream on | ||
| 1007 | + /// `TxMode::Largest`. Dropped, aomenc's RD is free to pick | ||
| 1008 | + /// `TxMode::Select` and split some blocks' luma transform below their own | ||
| 1009 | + /// side (spec 5.11.16), which is what this test's `tx_depth_hits()` | ||
| 1010 | + /// counter proves actually happened -- a stream that resolves every | ||
| 1011 | + /// `tx_depth` to 0 would pixel-match by construction (identical to | ||
| 1012 | + /// `TxMode::Largest`) without exercising the new split-TU decode path at | ||
| 1013 | + /// all. Same multi-seed retry shape as | ||
| 1014 | + /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`]: | ||
| 1015 | + /// aomenc's own RD is free (with tx-size search on) to also occasionally | ||
| 1016 | + /// pick `allow_screen_content_tools` on this content, a separate, | ||
| 1017 | + /// already-named refusal -- try several seeds, and the first stream that | ||
| 1018 | + /// both decodes AND actually split a transform must be pixel-exact. | ||
| 1019 | + #[test] | ||
| 1020 | + fn a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact() { | ||
| 1021 | + if !have_ffmpeg() { | ||
| 1022 | + eprintln!( | ||
| 1023 | + "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: no ffmpeg" | ||
| 1024 | + ); | ||
| 1025 | + return; | ||
| 1026 | + } | ||
| 1027 | + if !have_aomenc() { | ||
| 1028 | + eprintln!( | ||
| 1029 | + "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: no aomenc at {}", | ||
| 1030 | + aomenc_path().display() | ||
| 1031 | + ); | ||
| 1032 | + return; | ||
| 1033 | + } | ||
| 1034 | + let (width, height) = (64usize, 64usize); | ||
| 1035 | + let mut refusals = Vec::new(); | ||
| 1036 | + for attempt in 0..40u32 { | ||
| 1037 | + let seed = 42 + attempt; | ||
| 1038 | + // A flat gradient never has enough local detail for the RD | ||
| 1039 | + // search to prefer a split transform over the block's own full | ||
| 1040 | + // size -- `mandelbrot`'s fractal boundary gives every attempt | ||
| 1041 | + // (a different `start_scale`) sharp, varied-frequency edges. | ||
| 1042 | + // start_scale 5.0 is the proven first try (decodes pixel-exact | ||
| 1043 | + // AND reads the seven-symbol set-1 tx_type rows on TX8 TUs); | ||
| 1044 | + // later attempts walk down for variety when aomenc's RD flips | ||
| 1045 | + // elsewhere. | ||
| 1046 | + let source = format!( | ||
| 1047 | + "mandelbrot=size=64x64:start_scale={}:rate=25", | ||
| 1048 | + 5.0 - f64::from(attempt) * 0.06 | ||
| 1049 | + ); | ||
| 1050 | + let y4m = Command::new("ffmpeg") | ||
| 1051 | + .args([ | ||
| 1052 | + "-v", | ||
| 1053 | + "error", | ||
| 1054 | + "-f", | ||
| 1055 | + "lavfi", | ||
| 1056 | + "-i", | ||
| 1057 | + &source, | ||
| 1058 | + // Desaturated: chroma stays flat (constant 128) so | ||
| 1059 | + // `uv_mode` always resolves to `DC_PRED` and this | ||
| 1060 | + // decoder's still-unsupported directional-chroma round-2 | ||
| 1061 | + // gap never fires, leaving the luma detail alone to | ||
| 1062 | + // drive whether `TxMode::Select`'s RD splits a block. | ||
| 1063 | + "-vf", | ||
| 1064 | + "hue=s=0", | ||
| 1065 | + "-pix_fmt", | ||
| 1066 | + "yuv420p", | ||
| 1067 | + "-t", | ||
| 1068 | + "0.04", | ||
| 1069 | + "-f", | ||
| 1070 | + "yuv4mpegpipe", | ||
| 1071 | + "-", | ||
| 1072 | + ]) | ||
| 1073 | + .stdin(Stdio::null()) | ||
| 1074 | + .stdout(Stdio::piped()) | ||
| 1075 | + .stderr(Stdio::piped()) | ||
| 1076 | + .output() | ||
| 1077 | + .expect("ffmpeg failed to run"); | ||
| 1078 | + assert!( | ||
| 1079 | + y4m.status.success(), | ||
| 1080 | + "ffmpeg fixture: {}", | ||
| 1081 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 1082 | + ); | ||
| 1083 | + let mut child = Command::new(aomenc_path()) | ||
| 1084 | + .args([ | ||
| 1085 | + "--codec=av1", | ||
| 1086 | + "--passes=1", | ||
| 1087 | + "--end-usage=q", | ||
| 1088 | + "--cq-level=45", | ||
| 1089 | + "--cpu-used=0", | ||
| 1090 | + "--enable-rect-partitions=0", | ||
| 1091 | + "--enable-ab-partitions=0", | ||
| 1092 | + "--enable-1to4-partitions=0", | ||
| 1093 | + "--enable-filter-intra=0", | ||
| 1094 | + // Every non-DC intra tool off: directional chroma and | ||
| 1095 | + // angle deltas are separate round-2 gaps, and DC-only | ||
| 1096 | + // residual is exactly what gives the RD search a reason | ||
| 1097 | + // to split a transform. | ||
| 1098 | + "--enable-smooth-intra=0", | ||
| 1099 | + "--enable-paeth-intra=0", | ||
| 1100 | + "--enable-directional-intra=0", | ||
| 1101 | + "--enable-angle-delta=0", | ||
| 1102 | + "--enable-cdef=0", | ||
| 1103 | + // Loop restoration is a named refusal (aomenc's RD picks | ||
| 1104 | + // Sgrproj on this kind of content) -- off in every recipe | ||
| 1105 | + // whose test targets a different surface. | ||
| 1106 | + "--enable-restoration=0", | ||
| 1107 | + "--max-partition-size=32", | ||
| 1108 | + // 16x16 blocks are what split into the TX8 TUs whose | ||
| 1109 | + // set-1 tx_type rows this gate exists to prove; some | ||
| 1110 | + // scales resolve depth 2 (TX4, a named refusal) and the | ||
| 1111 | + // attempt loop just moves on. | ||
| 1112 | + "--min-partition-size=16", | ||
| 1113 | + "--enable-palette=0", | ||
| 1114 | + "--enable-intrabc=0", | ||
| 1115 | + "--enable-cfl-intra=0", | ||
| 1116 | + "--obu", | ||
| 1117 | + "-o", | ||
| 1118 | + "-", | ||
| 1119 | + "-", | ||
| 1120 | + ]) | ||
| 1121 | + .stdin(Stdio::piped()) | ||
| 1122 | + .stdout(Stdio::piped()) | ||
| 1123 | + .stderr(Stdio::piped()) | ||
| 1124 | + .spawn() | ||
| 1125 | + .expect("aomenc failed to start"); | ||
| 1126 | + child | ||
| 1127 | + .stdin | ||
| 1128 | + .take() | ||
| 1129 | + .expect("aomenc stdin") | ||
| 1130 | + .write_all(&y4m.stdout) | ||
| 1131 | + .expect("writing y4m to aomenc"); | ||
| 1132 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 1133 | + assert!( | ||
| 1134 | + out.status.success(), | ||
| 1135 | + "aomenc refused the fixture: {}", | ||
| 1136 | + String::from_utf8_lossy(&out.stderr) | ||
| 1137 | + ); | ||
| 1138 | + let stream = out.stdout; | ||
| 1139 | + let before = decode::tx_depth_hits(); | ||
| 1140 | + let frames = match decode_stream(&stream) { | ||
| 1141 | + Ok(frames) => frames, | ||
| 1142 | + Err(e) => { | ||
| 1143 | + refusals.push(format!("seed {seed}: {e}")); | ||
| 1144 | + continue; | ||
| 1145 | + } | ||
| 1146 | + }; | ||
| 1147 | + if decode::tx_depth_hits() == before { | ||
| 1148 | + refusals.push(format!( | ||
| 1149 | + "seed {seed}: decoded, but no block resolved a split tx_depth" | ||
| 1150 | + )); | ||
| 1151 | + continue; | ||
| 1152 | + } | ||
| 1153 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 1154 | + assert_eq!( | ||
| 1155 | + frames[0].y, ffmpeg_frames[0].y, | ||
| 1156 | + "luma vs ffmpeg (seed {seed})" | ||
| 1157 | + ); | ||
| 1158 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})"); | ||
| 1159 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})"); | ||
| 1160 | + return; | ||
| 1161 | + } | ||
| 1162 | + eprintln!( | ||
| 1163 | + "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: every attempt \ | ||
| 1164 | + hit a named refusal or never split a transform:\n{}", | ||
| 1165 | + refusals.join("\n") | ||
| 1166 | + ); | ||
| 1167 | + } | ||
| 1168 | + | ||
| 999 | /// As above, but a multi-frame inter sequence -- `--lag-in-frames=0 | 1169 | /// As above, but a multi-frame inter sequence -- `--lag-in-frames=0 |
| 1000 | /// --auto-alt-ref=0` keep every non-key frame a simple forward | 1170 | /// --auto-alt-ref=0` keep every non-key frame a simple forward |
| 1001 | /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this | 1171 | /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this |
crates/ec-av1/src/transform.rsmodified+27 -0
| @@ -314,6 +314,12 @@ pub enum TxType { | |||
| 314 | AdstDct, | 314 | AdstDct, |
| 315 | /// DCT down the column axis, ADST across the row axis. | 315 | /// DCT down the column axis, ADST across the row axis. |
| 316 | DctAdst, | 316 | DctAdst, |
| 317 | + /// DCT down the column axis, identity across the row axis | ||
| 318 | + /// (`V_DCT` -- `TX_SET_INTRA_1` only). | ||
| 319 | + VDct, | ||
| 320 | + /// Identity down the column axis, DCT across the row axis | ||
| 321 | + /// (`H_DCT` -- `TX_SET_INTRA_1` only). | ||
| 322 | + HDct, | ||
| 317 | } | 323 | } |
| 318 | 324 | ||
| 319 | impl TxType { | 325 | impl TxType { |
| @@ -329,6 +335,24 @@ impl TxType { | |||
| 329 | } | 335 | } |
| 330 | } | 336 | } |
| 331 | 337 | ||
| 338 | + /// The inverse of `Tx_Type_Intra_Inv_Set1`'s CDF symbol order | ||
| 339 | + /// (`av1_ext_tx_inv[EXT_TX_SET_DTT4_IDTX_1DDCT]`, entropymode.h: | ||
| 340 | + /// `{9, 0, 10, 11, 3, 1, 2}` = IDTX, DCT_DCT, V_DCT, H_DCT, ADST_ADST, | ||
| 341 | + /// ADST_DCT, DCT_ADST) -- the seven-type set a `reduced_tx_set == 0` | ||
| 342 | + /// frame's small intra transforms read from. | ||
| 343 | + pub fn from_symbol_set1(t: usize) -> Option<Self> { | ||
| 344 | + match t { | ||
| 345 | + 0 => Some(Self::Idtx), | ||
| 346 | + 1 => Some(Self::DctDct), | ||
| 347 | + 2 => Some(Self::VDct), | ||
| 348 | + 3 => Some(Self::HDct), | ||
| 349 | + 4 => Some(Self::AdstAdst), | ||
| 350 | + 5 => Some(Self::AdstDct), | ||
| 351 | + 6 => Some(Self::DctAdst), | ||
| 352 | + _ => None, | ||
| 353 | + } | ||
| 354 | + } | ||
| 355 | + | ||
| 332 | /// `(row, col)`: the transform `inverse_transform_2d_typed`'s row pass | 356 | /// `(row, col)`: the transform `inverse_transform_2d_typed`'s row pass |
| 333 | /// (`htx_tab`, spec/libaom "horizontal") and column pass (`vtx_tab`, | 357 | /// (`htx_tab`, spec/libaom "horizontal") and column pass (`vtx_tab`, |
| 334 | /// "vertical") each run. Read off libaom's `av1_inv_txfm2d.c` `vtx_tab`/ | 358 | /// "vertical") each run. Read off libaom's `av1_inv_txfm2d.c` `vtx_tab`/ |
| @@ -343,6 +367,9 @@ impl TxType { | |||
| 343 | Self::AdstAdst => (Adst, Adst), | 367 | Self::AdstAdst => (Adst, Adst), |
| 344 | Self::AdstDct => (Dct, Adst), | 368 | Self::AdstDct => (Dct, Adst), |
| 345 | Self::DctAdst => (Adst, Dct), | 369 | Self::DctAdst => (Adst, Dct), |
| 370 | + // `av1_inv_txfm2d.c`: V_DCT vtx=DCT htx=IDTX, H_DCT the mirror. | ||
| 371 | + Self::VDct => (Identity, Dct), | ||
| 372 | + Self::HDct => (Dct, Identity), | ||
| 346 | } | 373 | } |
| 347 | } | 374 | } |
| 348 | } | 375 | } |