1 /* 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VPX_VP9_ENCODER_VP9_BLOCK_H_ 12 #define VPX_VP9_ENCODER_VP9_BLOCK_H_ 13 14 #include "vpx_util/vpx_thread.h" 15 16 #include "vp9/common/vp9_blockd.h" 17 #include "vp9/common/vp9_entropymv.h" 18 #include "vp9/common/vp9_entropy.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 typedef struct { 25 unsigned int sse; 26 int sum; 27 unsigned int var; 28 } Diff; 29 30 struct macroblock_plane { 31 DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); 32 tran_low_t *qcoeff; 33 tran_low_t *coeff; 34 uint16_t *eobs; 35 struct buf_2d src; 36 37 // Quantizer settings 38 int16_t *round_fp; 39 int16_t *quant_fp; 40 int16_t *quant; 41 int16_t *quant_shift; 42 int16_t *zbin; 43 int16_t *round; 44 45 int64_t quant_thred[2]; 46 }; 47 48 /* The [2] dimension is for whether we skip the EOB node (i.e. if previous 49 * coefficient in this block was zero) or not. */ 50 typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2] 51 [COEFF_CONTEXTS][ENTROPY_TOKENS]; 52 53 typedef struct { 54 int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; 55 uint8_t mode_context[MAX_REF_FRAMES]; 56 } MB_MODE_INFO_EXT; 57 58 typedef struct { 59 int col_min; 60 int col_max; 61 int row_min; 62 int row_max; 63 } MvLimits; 64 65 typedef struct macroblock MACROBLOCK; 66 struct macroblock { 67 // cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054 68 #if defined(_MSC_VER) && _MSC_VER < 1900 69 int64_t bsse[MAX_MB_PLANE << 2]; 70 #endif 71 72 struct macroblock_plane plane[MAX_MB_PLANE]; 73 74 MACROBLOCKD e_mbd; 75 MB_MODE_INFO_EXT *mbmi_ext; 76 MB_MODE_INFO_EXT *mbmi_ext_base; 77 int skip_block; 78 int select_tx_size; 79 int skip_recode; 80 int skip_optimize; 81 int q_index; 82 double log_block_src_var; 83 int block_tx_domain; 84 85 // The equivalent error at the current rdmult of one whole bit (not one 86 // bitcost unit). 87 int errorperbit; 88 // The equivalent SAD error of one (whole) bit at the current quantizer 89 // for large blocks. 90 int sadperbit16; 91 // The equivalent SAD error of one (whole) bit at the current quantizer 92 // for sub-8x8 blocks. 93 int sadperbit4; 94 int rddiv; 95 int rdmult; 96 int cb_rdmult; 97 int segment_id; 98 int mb_energy; 99 100 // These are set to their default values at the beginning, and then adjusted 101 // further in the encoding process. 102 BLOCK_SIZE min_partition_size; 103 BLOCK_SIZE max_partition_size; 104 105 int mv_best_ref_index[MAX_REF_FRAMES]; 106 unsigned int max_mv_context[MAX_REF_FRAMES]; 107 unsigned int source_variance; 108 unsigned int pred_sse[MAX_REF_FRAMES]; 109 int pred_mv_sad[MAX_REF_FRAMES]; 110 111 int nmvjointcost[MV_JOINTS]; 112 int *nmvcost[2]; 113 int *nmvcost_hp[2]; 114 int **mvcost; 115 116 int nmvjointsadcost[MV_JOINTS]; 117 int *nmvsadcost[2]; 118 int *nmvsadcost_hp[2]; 119 int **mvsadcost; 120 121 // sharpness is used to disable skip mode and change rd_mult 122 int sharpness; 123 124 // aq mode is used to adjust rd based on segment. 125 int adjust_rdmult_by_segment; 126 127 // These define limits to motion vector components to prevent them 128 // from extending outside the UMV borders 129 MvLimits mv_limits; 130 131 // Notes transform blocks where no coefficients are coded. 132 // Set during mode selection. Read during block encoding. 133 uint8_t zcoeff_blk[TX_SIZES][256]; 134 135 // Accumulate the tx block eobs in a partition block. 136 int32_t sum_y_eobs[TX_SIZES]; 137 138 int skip; 139 140 int encode_breakout; 141 142 // note that token_costs is the cost when eob node is skipped 143 vp9_coeff_cost token_costs[TX_SIZES]; 144 145 int optimize; 146 147 // indicate if it is in the rd search loop or encoding process 148 int use_lp32x32fdct; 149 int skip_encode; 150 151 // In first pass, intra prediction is done based on source pixels 152 // at tile boundaries 153 int fp_src_pred; 154 155 // use fast quantization process 156 int quant_fp; 157 158 // skip forward transform and quantization 159 uint8_t skip_txfm[MAX_MB_PLANE << 2]; 160 #define SKIP_TXFM_NONE 0 161 // TODO(chengchen): consider remove SKIP_TXFM_AC_DC from vp9 completely 162 // since it increases risks of bad perceptual quality. 163 // https://crbug.com/webm/1729 164 #define SKIP_TXFM_AC_DC 1 165 #define SKIP_TXFM_AC_ONLY 2 166 167 // cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054 168 #if !defined(_MSC_VER) || _MSC_VER >= 1900 169 int64_t bsse[MAX_MB_PLANE << 2]; 170 #endif 171 172 // Used to store sub partition's choices. 173 MV pred_mv[MAX_REF_FRAMES]; 174 175 // Strong color activity detection. Used in RTC coding mode to enhance 176 // the visual quality at the boundary of moving color objects. 177 uint8_t color_sensitivity[2]; 178 179 uint8_t sb_is_skin; 180 181 uint8_t skip_low_source_sad; 182 183 uint8_t lowvar_highsumdiff; 184 185 uint8_t last_sb_high_content; 186 187 int sb_use_mv_part; 188 189 int sb_mvcol_part; 190 191 int sb_mvrow_part; 192 193 int sb_pickmode_part; 194 195 int zero_temp_sad_source; 196 197 // For each superblock: saves the content value (e.g., low/high sad/sumdiff) 198 // based on source sad, prior to encoding the frame. 199 uint8_t content_state_sb; 200 201 // Used to save the status of whether a block has a low variance in 202 // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for 203 // 32x32, 9~24 for 16x16. 204 uint8_t variance_low[25]; 205 206 uint8_t arf_frame_usage; 207 uint8_t lastgolden_frame_usage; 208 209 void (*fwd_txfm4x4)(const int16_t *input, tran_low_t *output, int stride); 210 void (*inv_txfm_add)(const tran_low_t *input, uint8_t *dest, int stride, 211 int eob); 212 #if CONFIG_VP9_HIGHBITDEPTH 213 void (*highbd_inv_txfm_add)(const tran_low_t *input, uint16_t *dest, 214 int stride, int eob, int bd); 215 #endif 216 DECLARE_ALIGNED(16, uint8_t, est_pred[64 * 64]); 217 218 struct scale_factors *me_sf; 219 }; 220 221 #ifdef __cplusplus 222 } // extern "C" 223 #endif 224 225 #endif // VPX_VP9_ENCODER_VP9_BLOCK_H_ 226