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