Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 12 | #include "config/aom_config.h" |
| 13 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 14 | #include "aom/aom_integer.h" |
Thomas Davies | 87aeeb8 | 2017-02-17 00:19:40 +0000 | [diff] [blame] | 15 | #include "aom_mem/aom_mem.h" |
Wan-Teh Chang | f2d15ee | 2020-03-10 09:24:43 -0700 | [diff] [blame] | 16 | #include "av1/common/av1_common_int.h" |
Thomas Davies | 87aeeb8 | 2017-02-17 00:19:40 +0000 | [diff] [blame] | 17 | #include "av1/common/blockd.h" |
Angie Chiang | bb100e2 | 2017-03-21 11:42:32 -0700 | [diff] [blame] | 18 | #include "av1/common/entropy.h" |
Thomas Davies | 87aeeb8 | 2017-02-17 00:19:40 +0000 | [diff] [blame] | 19 | #include "av1/common/entropymode.h" |
Thomas Davies | 87aeeb8 | 2017-02-17 00:19:40 +0000 | [diff] [blame] | 20 | #include "av1/common/scan.h" |
hui su | ef125a0 | 2017-07-31 12:56:15 -0700 | [diff] [blame] | 21 | #include "av1/common/token_cdfs.h" |
Angie Chiang | bb100e2 | 2017-03-21 11:42:32 -0700 | [diff] [blame] | 22 | #include "av1/common/txb_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 23 | |
Hui Su | f094fe9 | 2018-02-01 18:30:13 -0800 | [diff] [blame] | 24 | static int get_q_ctx(int q) { |
| 25 | if (q <= 20) return 0; |
| 26 | if (q <= 60) return 1; |
| 27 | if (q <= 120) return 2; |
| 28 | return 3; |
| 29 | } |
Hui Su | f094fe9 | 2018-02-01 18:30:13 -0800 | [diff] [blame] | 30 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | void av1_default_coef_probs(AV1_COMMON *cm) { |
Urvang Joshi | 1781462 | 2020-03-27 17:26:17 -0700 | [diff] [blame] | 32 | const int index = get_q_ctx(cm->quant_params.base_qindex); |
Yue Chen | 198738d | 2018-03-08 17:26:01 -0800 | [diff] [blame] | 33 | #if CONFIG_ENTROPY_STATS |
| 34 | cm->coef_cdf_category = index; |
| 35 | #endif |
| 36 | |
Hui Su | f094fe9 | 2018-02-01 18:30:13 -0800 | [diff] [blame] | 37 | av1_copy(cm->fc->txb_skip_cdf, av1_default_txb_skip_cdfs[index]); |
| 38 | av1_copy(cm->fc->eob_extra_cdf, av1_default_eob_extra_cdfs[index]); |
| 39 | av1_copy(cm->fc->dc_sign_cdf, av1_default_dc_sign_cdfs[index]); |
| 40 | av1_copy(cm->fc->coeff_br_cdf, av1_default_coeff_lps_multi_cdfs[index]); |
| 41 | av1_copy(cm->fc->coeff_base_cdf, av1_default_coeff_base_multi_cdfs[index]); |
| 42 | av1_copy(cm->fc->coeff_base_eob_cdf, |
| 43 | av1_default_coeff_base_eob_multi_cdfs[index]); |
| 44 | av1_copy(cm->fc->eob_flag_cdf16, av1_default_eob_multi16_cdfs[index]); |
| 45 | av1_copy(cm->fc->eob_flag_cdf32, av1_default_eob_multi32_cdfs[index]); |
| 46 | av1_copy(cm->fc->eob_flag_cdf64, av1_default_eob_multi64_cdfs[index]); |
| 47 | av1_copy(cm->fc->eob_flag_cdf128, av1_default_eob_multi128_cdfs[index]); |
| 48 | av1_copy(cm->fc->eob_flag_cdf256, av1_default_eob_multi256_cdfs[index]); |
| 49 | av1_copy(cm->fc->eob_flag_cdf512, av1_default_eob_multi512_cdfs[index]); |
| 50 | av1_copy(cm->fc->eob_flag_cdf1024, av1_default_eob_multi1024_cdfs[index]); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 53 | static AOM_INLINE void reset_cdf_symbol_counter(aom_cdf_prob *cdf_ptr, |
| 54 | int num_cdfs, int cdf_stride, |
| 55 | int nsymbs) { |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 56 | for (int i = 0; i < num_cdfs; i++) { |
| 57 | cdf_ptr[i * cdf_stride + nsymbs] = 0; |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 61 | #define RESET_CDF_COUNTER(cname, nsymbs) \ |
| 62 | RESET_CDF_COUNTER_STRIDE(cname, nsymbs, CDF_SIZE(nsymbs)) |
| 63 | |
| 64 | #define RESET_CDF_COUNTER_STRIDE(cname, nsymbs, cdf_stride) \ |
| 65 | do { \ |
| 66 | aom_cdf_prob *cdf_ptr = (aom_cdf_prob *)cname; \ |
| 67 | int array_size = (int)sizeof(cname) / sizeof(aom_cdf_prob); \ |
| 68 | int num_cdfs = array_size / cdf_stride; \ |
| 69 | reset_cdf_symbol_counter(cdf_ptr, num_cdfs, cdf_stride, nsymbs); \ |
| 70 | } while (0) |
| 71 | |
Elliott Karpilovsky | 18fcd6a | 2019-09-16 15:15:06 -0700 | [diff] [blame] | 72 | static AOM_INLINE void reset_nmv_counter(nmv_context *nmv) { |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 73 | RESET_CDF_COUNTER(nmv->joints_cdf, 4); |
| 74 | for (int i = 0; i < 2; i++) { |
| 75 | RESET_CDF_COUNTER(nmv->comps[i].classes_cdf, MV_CLASSES); |
| 76 | RESET_CDF_COUNTER(nmv->comps[i].class0_fp_cdf, MV_FP_SIZE); |
| 77 | RESET_CDF_COUNTER(nmv->comps[i].fp_cdf, MV_FP_SIZE); |
| 78 | RESET_CDF_COUNTER(nmv->comps[i].sign_cdf, 2); |
| 79 | RESET_CDF_COUNTER(nmv->comps[i].class0_hp_cdf, 2); |
| 80 | RESET_CDF_COUNTER(nmv->comps[i].hp_cdf, 2); |
| 81 | RESET_CDF_COUNTER(nmv->comps[i].class0_cdf, CLASS0_SIZE); |
| 82 | RESET_CDF_COUNTER(nmv->comps[i].bits_cdf, 2); |
| 83 | } |
| 84 | } |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 85 | |
Hui Su | dc54be6 | 2018-03-14 19:14:28 -0700 | [diff] [blame] | 86 | void av1_reset_cdf_symbol_counters(FRAME_CONTEXT *fc) { |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 87 | RESET_CDF_COUNTER(fc->txb_skip_cdf, 2); |
| 88 | RESET_CDF_COUNTER(fc->eob_extra_cdf, 2); |
| 89 | RESET_CDF_COUNTER(fc->dc_sign_cdf, 2); |
| 90 | RESET_CDF_COUNTER(fc->eob_flag_cdf16, 5); |
| 91 | RESET_CDF_COUNTER(fc->eob_flag_cdf32, 6); |
| 92 | RESET_CDF_COUNTER(fc->eob_flag_cdf64, 7); |
| 93 | RESET_CDF_COUNTER(fc->eob_flag_cdf128, 8); |
| 94 | RESET_CDF_COUNTER(fc->eob_flag_cdf256, 9); |
| 95 | RESET_CDF_COUNTER(fc->eob_flag_cdf512, 10); |
| 96 | RESET_CDF_COUNTER(fc->eob_flag_cdf1024, 11); |
| 97 | RESET_CDF_COUNTER(fc->coeff_base_eob_cdf, 3); |
| 98 | RESET_CDF_COUNTER(fc->coeff_base_cdf, 4); |
| 99 | RESET_CDF_COUNTER(fc->coeff_br_cdf, BR_CDF_SIZE); |
| 100 | RESET_CDF_COUNTER(fc->newmv_cdf, 2); |
| 101 | RESET_CDF_COUNTER(fc->zeromv_cdf, 2); |
| 102 | RESET_CDF_COUNTER(fc->refmv_cdf, 2); |
| 103 | RESET_CDF_COUNTER(fc->drl_cdf, 2); |
| 104 | RESET_CDF_COUNTER(fc->inter_compound_mode_cdf, INTER_COMPOUND_MODES); |
Debargha Mukherjee | 54eabb5 | 2019-02-01 16:54:33 -0800 | [diff] [blame] | 105 | RESET_CDF_COUNTER(fc->compound_type_cdf, MASKED_COMPOUND_TYPES); |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 106 | RESET_CDF_COUNTER(fc->wedge_idx_cdf, 16); |
| 107 | RESET_CDF_COUNTER(fc->interintra_cdf, 2); |
| 108 | RESET_CDF_COUNTER(fc->wedge_interintra_cdf, 2); |
| 109 | RESET_CDF_COUNTER(fc->interintra_mode_cdf, INTERINTRA_MODES); |
| 110 | RESET_CDF_COUNTER(fc->motion_mode_cdf, MOTION_MODES); |
| 111 | RESET_CDF_COUNTER(fc->obmc_cdf, 2); |
| 112 | RESET_CDF_COUNTER(fc->palette_y_size_cdf, PALETTE_SIZES); |
| 113 | RESET_CDF_COUNTER(fc->palette_uv_size_cdf, PALETTE_SIZES); |
| 114 | for (int j = 0; j < PALETTE_SIZES; j++) { |
| 115 | int nsymbs = j + PALETTE_MIN_SIZE; |
| 116 | RESET_CDF_COUNTER_STRIDE(fc->palette_y_color_index_cdf[j], nsymbs, |
| 117 | CDF_SIZE(PALETTE_COLORS)); |
| 118 | RESET_CDF_COUNTER_STRIDE(fc->palette_uv_color_index_cdf[j], nsymbs, |
| 119 | CDF_SIZE(PALETTE_COLORS)); |
| 120 | } |
| 121 | RESET_CDF_COUNTER(fc->palette_y_mode_cdf, 2); |
| 122 | RESET_CDF_COUNTER(fc->palette_uv_mode_cdf, 2); |
| 123 | RESET_CDF_COUNTER(fc->comp_inter_cdf, 2); |
| 124 | RESET_CDF_COUNTER(fc->single_ref_cdf, 2); |
| 125 | RESET_CDF_COUNTER(fc->comp_ref_type_cdf, 2); |
| 126 | RESET_CDF_COUNTER(fc->uni_comp_ref_cdf, 2); |
| 127 | RESET_CDF_COUNTER(fc->comp_ref_cdf, 2); |
| 128 | RESET_CDF_COUNTER(fc->comp_bwdref_cdf, 2); |
| 129 | RESET_CDF_COUNTER(fc->txfm_partition_cdf, 2); |
| 130 | RESET_CDF_COUNTER(fc->compound_index_cdf, 2); |
| 131 | RESET_CDF_COUNTER(fc->comp_group_idx_cdf, 2); |
| 132 | RESET_CDF_COUNTER(fc->skip_mode_cdfs, 2); |
chiyotsai | 8c004e1 | 2020-04-17 15:52:08 -0700 | [diff] [blame] | 133 | RESET_CDF_COUNTER(fc->skip_txfm_cdfs, 2); |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 134 | RESET_CDF_COUNTER(fc->intra_inter_cdf, 2); |
| 135 | reset_nmv_counter(&fc->nmvc); |
| 136 | reset_nmv_counter(&fc->ndvc); |
| 137 | RESET_CDF_COUNTER(fc->intrabc_cdf, 2); |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 138 | RESET_CDF_COUNTER(fc->seg.pred_cdf, 2); |
| 139 | RESET_CDF_COUNTER(fc->seg.spatial_pred_seg_cdf, MAX_SEGMENTS); |
| 140 | RESET_CDF_COUNTER(fc->filter_intra_cdfs, 2); |
| 141 | RESET_CDF_COUNTER(fc->filter_intra_mode_cdf, FILTER_INTRA_MODES); |
| 142 | RESET_CDF_COUNTER(fc->switchable_restore_cdf, RESTORE_SWITCHABLE_TYPES); |
| 143 | RESET_CDF_COUNTER(fc->wiener_restore_cdf, 2); |
| 144 | RESET_CDF_COUNTER(fc->sgrproj_restore_cdf, 2); |
| 145 | RESET_CDF_COUNTER(fc->y_mode_cdf, INTRA_MODES); |
| 146 | RESET_CDF_COUNTER_STRIDE(fc->uv_mode_cdf[0], UV_INTRA_MODES - 1, |
| 147 | CDF_SIZE(UV_INTRA_MODES)); |
| 148 | RESET_CDF_COUNTER(fc->uv_mode_cdf[1], UV_INTRA_MODES); |
| 149 | for (int i = 0; i < PARTITION_CONTEXTS; i++) { |
| 150 | if (i < 4) { |
| 151 | RESET_CDF_COUNTER_STRIDE(fc->partition_cdf[i], 4, CDF_SIZE(10)); |
| 152 | } else if (i < 16) { |
David Barker | e648649 | 2018-04-17 15:44:08 +0100 | [diff] [blame] | 153 | RESET_CDF_COUNTER(fc->partition_cdf[i], 10); |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 154 | } else { |
| 155 | RESET_CDF_COUNTER_STRIDE(fc->partition_cdf[i], 8, CDF_SIZE(10)); |
| 156 | } |
| 157 | } |
| 158 | RESET_CDF_COUNTER(fc->switchable_interp_cdf, SWITCHABLE_FILTERS); |
| 159 | RESET_CDF_COUNTER(fc->kf_y_cdf, INTRA_MODES); |
| 160 | RESET_CDF_COUNTER(fc->angle_delta_cdf, 2 * MAX_ANGLE_DELTA + 1); |
| 161 | RESET_CDF_COUNTER_STRIDE(fc->tx_size_cdf[0], MAX_TX_DEPTH, |
| 162 | CDF_SIZE(MAX_TX_DEPTH + 1)); |
| 163 | RESET_CDF_COUNTER(fc->tx_size_cdf[1], MAX_TX_DEPTH + 1); |
| 164 | RESET_CDF_COUNTER(fc->tx_size_cdf[2], MAX_TX_DEPTH + 1); |
Peter de Rivaz | 9d3b3eb | 2018-05-07 13:50:41 +0100 | [diff] [blame] | 165 | RESET_CDF_COUNTER(fc->tx_size_cdf[3], MAX_TX_DEPTH + 1); |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 166 | RESET_CDF_COUNTER(fc->delta_q_cdf, DELTA_Q_PROBS + 1); |
Peter de Rivaz | 9d3b3eb | 2018-05-07 13:50:41 +0100 | [diff] [blame] | 167 | RESET_CDF_COUNTER(fc->delta_lf_cdf, DELTA_LF_PROBS + 1); |
| 168 | for (int i = 0; i < FRAME_LF_COUNT; i++) { |
| 169 | RESET_CDF_COUNTER(fc->delta_lf_multi_cdf[i], DELTA_LF_PROBS + 1); |
| 170 | } |
Thomas Daede | 421ab87 | 2018-04-10 15:44:52 -0700 | [diff] [blame] | 171 | RESET_CDF_COUNTER_STRIDE(fc->intra_ext_tx_cdf[1], 7, CDF_SIZE(TX_TYPES)); |
| 172 | RESET_CDF_COUNTER_STRIDE(fc->intra_ext_tx_cdf[2], 5, CDF_SIZE(TX_TYPES)); |
| 173 | RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[1], 16, CDF_SIZE(TX_TYPES)); |
| 174 | RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[2], 12, CDF_SIZE(TX_TYPES)); |
| 175 | RESET_CDF_COUNTER_STRIDE(fc->inter_ext_tx_cdf[3], 2, CDF_SIZE(TX_TYPES)); |
| 176 | RESET_CDF_COUNTER(fc->cfl_sign_cdf, CFL_JOINT_SIGNS); |
| 177 | RESET_CDF_COUNTER(fc->cfl_alpha_cdf, CFL_ALPHABET_SIZE); |
Thomas Davies | 028b57f | 2017-02-22 16:42:11 +0000 | [diff] [blame] | 178 | } |