vp9_block.h revision b08e2e23eec181e9951df33cd704ac294c5407b6
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 VP9_ENCODER_VP9_BLOCK_H_ 12#define VP9_ENCODER_VP9_BLOCK_H_ 13 14#include "vp9/common/vp9_entropymv.h" 15#include "vp9/common/vp9_entropy.h" 16#include "vpx_ports/mem.h" 17#include "vp9/common/vp9_onyxc_int.h" 18 19#ifdef __cplusplus 20extern "C" { 21#endif 22 23// motion search site 24typedef struct { 25 MV mv; 26 int offset; 27} search_site; 28 29// Structure to hold snapshot of coding context during the mode picking process 30typedef struct { 31 MODE_INFO mic; 32 uint8_t *zcoeff_blk; 33 int16_t *coeff[MAX_MB_PLANE][3]; 34 int16_t *qcoeff[MAX_MB_PLANE][3]; 35 int16_t *dqcoeff[MAX_MB_PLANE][3]; 36 uint16_t *eobs[MAX_MB_PLANE][3]; 37 38 // dual buffer pointers, 0: in use, 1: best in store 39 int16_t *coeff_pbuf[MAX_MB_PLANE][3]; 40 int16_t *qcoeff_pbuf[MAX_MB_PLANE][3]; 41 int16_t *dqcoeff_pbuf[MAX_MB_PLANE][3]; 42 uint16_t *eobs_pbuf[MAX_MB_PLANE][3]; 43 44 int is_coded; 45 int num_4x4_blk; 46 int skip; 47 int_mv best_ref_mv[2]; 48 int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; 49 int rate; 50 int distortion; 51 int best_mode_index; 52 int rddiv; 53 int rdmult; 54 int hybrid_pred_diff; 55 int comp_pred_diff; 56 int single_pred_diff; 57 int64_t tx_rd_diff[TX_MODES]; 58 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; 59 60 // motion vector cache for adaptive motion search control in partition 61 // search loop 62 int_mv pred_mv[MAX_REF_FRAMES]; 63 INTERP_FILTER pred_interp_filter; 64} PICK_MODE_CONTEXT; 65 66struct macroblock_plane { 67 DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); 68 int16_t *qcoeff; 69 int16_t *coeff; 70 uint16_t *eobs; 71 struct buf_2d src; 72 73 // Quantizer setings 74 int16_t *quant; 75 int16_t *quant_shift; 76 int16_t *zbin; 77 int16_t *round; 78 79 // Zbin Over Quant value 80 int16_t zbin_extra; 81}; 82 83/* The [2] dimension is for whether we skip the EOB node (i.e. if previous 84 * coefficient in this block was zero) or not. */ 85typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2] 86 [COEFF_CONTEXTS][ENTROPY_TOKENS]; 87 88typedef struct macroblock MACROBLOCK; 89struct macroblock { 90 struct macroblock_plane plane[MAX_MB_PLANE]; 91 92 MACROBLOCKD e_mbd; 93 int skip_block; 94 int select_txfm_size; 95 int skip_recode; 96 int skip_optimize; 97 int q_index; 98 99 search_site *ss; 100 int ss_count; 101 int searches_per_step; 102 103 int errorperbit; 104 int sadperbit16; 105 int sadperbit4; 106 int rddiv; 107 int rdmult; 108 unsigned int mb_energy; 109 unsigned int *mb_activity_ptr; 110 int *mb_norm_activity_ptr; 111 signed int act_zbin_adj; 112 113 int mv_best_ref_index[MAX_REF_FRAMES]; 114 unsigned int max_mv_context[MAX_REF_FRAMES]; 115 unsigned int source_variance; 116 unsigned int pred_sse[MAX_REF_FRAMES]; 117 int pred_mv_sad[MAX_REF_FRAMES]; 118 int mode_sad[MAX_REF_FRAMES][INTER_MODES + 1]; 119 120 int nmvjointcost[MV_JOINTS]; 121 int nmvcosts[2][MV_VALS]; 122 int *nmvcost[2]; 123 int nmvcosts_hp[2][MV_VALS]; 124 int *nmvcost_hp[2]; 125 int **mvcost; 126 127 int nmvjointsadcost[MV_JOINTS]; 128 int nmvsadcosts[2][MV_VALS]; 129 int *nmvsadcost[2]; 130 int nmvsadcosts_hp[2][MV_VALS]; 131 int *nmvsadcost_hp[2]; 132 int **mvsadcost; 133 134 int mbmode_cost[INTRA_MODES]; 135 unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; 136 int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES]; 137 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; 138 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; 139 140 unsigned char sb_index; // index of 32x32 block inside the 64x64 block 141 unsigned char mb_index; // index of 16x16 block inside the 32x32 block 142 unsigned char b_index; // index of 8x8 block inside the 16x16 block 143 unsigned char ab_index; // index of 4x4 block inside the 8x8 block 144 145 // These define limits to motion vector components to prevent them 146 // from extending outside the UMV borders 147 int mv_col_min; 148 int mv_col_max; 149 int mv_row_min; 150 int mv_row_max; 151 152 uint8_t zcoeff_blk[TX_SIZES][256]; 153 int skip; 154 155 int encode_breakout; 156 157 unsigned char *active_ptr; 158 159 // note that token_costs is the cost when eob node is skipped 160 vp9_coeff_cost token_costs[TX_SIZES]; 161 DECLARE_ALIGNED(16, uint8_t, token_cache[1024]); 162 163 int optimize; 164 165 // indicate if it is in the rd search loop or encoding process 166 int use_lp32x32fdct; 167 int skip_encode; 168 169 // Used to store sub partition's choices. 170 int_mv pred_mv[MAX_REF_FRAMES]; 171 172 // TODO(jingning): Need to refactor the structure arrays that buffers the 173 // coding mode decisions of each partition type. 174 PICK_MODE_CONTEXT ab4x4_context[4][4][4]; 175 PICK_MODE_CONTEXT sb8x4_context[4][4][4]; 176 PICK_MODE_CONTEXT sb4x8_context[4][4][4]; 177 PICK_MODE_CONTEXT sb8x8_context[4][4][4]; 178 PICK_MODE_CONTEXT sb8x16_context[4][4][2]; 179 PICK_MODE_CONTEXT sb16x8_context[4][4][2]; 180 PICK_MODE_CONTEXT mb_context[4][4]; 181 PICK_MODE_CONTEXT sb32x16_context[4][2]; 182 PICK_MODE_CONTEXT sb16x32_context[4][2]; 183 // when 4 MBs share coding parameters: 184 PICK_MODE_CONTEXT sb32_context[4]; 185 PICK_MODE_CONTEXT sb32x64_context[2]; 186 PICK_MODE_CONTEXT sb64x32_context[2]; 187 PICK_MODE_CONTEXT sb64_context; 188 int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES]; 189 190 BLOCK_SIZE b_partitioning[4][4][4]; 191 BLOCK_SIZE mb_partitioning[4][4]; 192 BLOCK_SIZE sb_partitioning[4]; 193 BLOCK_SIZE sb64_partitioning; 194 195 void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride); 196}; 197 198// TODO(jingning): the variables used here are little complicated. need further 199// refactoring on organizing the temporary buffers, when recursive 200// partition down to 4x4 block size is enabled. 201static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { 202 switch (bsize) { 203 case BLOCK_64X64: 204 return &x->sb64_context; 205 case BLOCK_64X32: 206 return &x->sb64x32_context[x->sb_index]; 207 case BLOCK_32X64: 208 return &x->sb32x64_context[x->sb_index]; 209 case BLOCK_32X32: 210 return &x->sb32_context[x->sb_index]; 211 case BLOCK_32X16: 212 return &x->sb32x16_context[x->sb_index][x->mb_index]; 213 case BLOCK_16X32: 214 return &x->sb16x32_context[x->sb_index][x->mb_index]; 215 case BLOCK_16X16: 216 return &x->mb_context[x->sb_index][x->mb_index]; 217 case BLOCK_16X8: 218 return &x->sb16x8_context[x->sb_index][x->mb_index][x->b_index]; 219 case BLOCK_8X16: 220 return &x->sb8x16_context[x->sb_index][x->mb_index][x->b_index]; 221 case BLOCK_8X8: 222 return &x->sb8x8_context[x->sb_index][x->mb_index][x->b_index]; 223 case BLOCK_8X4: 224 return &x->sb8x4_context[x->sb_index][x->mb_index][x->b_index]; 225 case BLOCK_4X8: 226 return &x->sb4x8_context[x->sb_index][x->mb_index][x->b_index]; 227 case BLOCK_4X4: 228 return &x->ab4x4_context[x->sb_index][x->mb_index][x->b_index]; 229 default: 230 assert(0); 231 return NULL; 232 } 233} 234 235#ifdef __cplusplus 236} // extern "C" 237#endif 238 239#endif // VP9_ENCODER_VP9_BLOCK_H_ 240