1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/encoder/vp9_block.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,255 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#ifndef VP9_ENCODER_VP9_BLOCK_H_ 1.15 +#define VP9_ENCODER_VP9_BLOCK_H_ 1.16 + 1.17 +#include "vp9/common/vp9_onyx.h" 1.18 +#include "vp9/common/vp9_entropymv.h" 1.19 +#include "vp9/common/vp9_entropy.h" 1.20 +#include "vpx_ports/mem.h" 1.21 +#include "vp9/common/vp9_onyxc_int.h" 1.22 + 1.23 +// motion search site 1.24 +typedef struct { 1.25 + MV mv; 1.26 + int offset; 1.27 +} search_site; 1.28 + 1.29 +// Structure to hold snapshot of coding context during the mode picking process 1.30 +typedef struct { 1.31 + MODE_INFO mic; 1.32 + uint8_t *zcoeff_blk; 1.33 + int16_t *coeff[MAX_MB_PLANE][3]; 1.34 + int16_t *qcoeff[MAX_MB_PLANE][3]; 1.35 + int16_t *dqcoeff[MAX_MB_PLANE][3]; 1.36 + uint16_t *eobs[MAX_MB_PLANE][3]; 1.37 + 1.38 + // dual buffer pointers, 0: in use, 1: best in store 1.39 + int16_t *coeff_pbuf[MAX_MB_PLANE][3]; 1.40 + int16_t *qcoeff_pbuf[MAX_MB_PLANE][3]; 1.41 + int16_t *dqcoeff_pbuf[MAX_MB_PLANE][3]; 1.42 + uint16_t *eobs_pbuf[MAX_MB_PLANE][3]; 1.43 + 1.44 + int is_coded; 1.45 + int num_4x4_blk; 1.46 + int skip; 1.47 + int_mv best_ref_mv; 1.48 + int_mv second_best_ref_mv; 1.49 + int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; 1.50 + int rate; 1.51 + int distortion; 1.52 + int64_t intra_error; 1.53 + int best_mode_index; 1.54 + int rddiv; 1.55 + int rdmult; 1.56 + int hybrid_pred_diff; 1.57 + int comp_pred_diff; 1.58 + int single_pred_diff; 1.59 + int64_t tx_rd_diff[TX_MODES]; 1.60 + int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; 1.61 + 1.62 + // motion vector cache for adaptive motion search control in partition 1.63 + // search loop 1.64 + int_mv pred_mv[MAX_REF_FRAMES]; 1.65 + 1.66 + // Bit flag for each mode whether it has high error in comparison to others. 1.67 + unsigned int modes_with_high_error; 1.68 + 1.69 + // Bit flag for each ref frame whether it has high error compared to others. 1.70 + unsigned int frames_with_high_error; 1.71 +} PICK_MODE_CONTEXT; 1.72 + 1.73 +struct macroblock_plane { 1.74 + DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); 1.75 + int16_t *coeff; 1.76 + struct buf_2d src; 1.77 + 1.78 + // Quantizer setings 1.79 + int16_t *quant; 1.80 + int16_t *quant_shift; 1.81 + int16_t *zbin; 1.82 + int16_t *round; 1.83 + 1.84 + // Zbin Over Quant value 1.85 + int16_t zbin_extra; 1.86 +}; 1.87 + 1.88 +/* The [2] dimension is for whether we skip the EOB node (i.e. if previous 1.89 + * coefficient in this block was zero) or not. */ 1.90 +typedef unsigned int vp9_coeff_cost[BLOCK_TYPES][REF_TYPES][COEF_BANDS][2] 1.91 + [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; 1.92 + 1.93 +typedef struct macroblock MACROBLOCK; 1.94 +struct macroblock { 1.95 + struct macroblock_plane plane[MAX_MB_PLANE]; 1.96 + 1.97 + MACROBLOCKD e_mbd; 1.98 + int skip_block; 1.99 + int select_txfm_size; 1.100 + int skip_recode; 1.101 + int skip_optimize; 1.102 + int q_index; 1.103 + 1.104 + search_site *ss; 1.105 + int ss_count; 1.106 + int searches_per_step; 1.107 + 1.108 + int errorperbit; 1.109 + int sadperbit16; 1.110 + int sadperbit4; 1.111 + int rddiv; 1.112 + int rdmult; 1.113 + unsigned int mb_energy; 1.114 + unsigned int *mb_activity_ptr; 1.115 + int *mb_norm_activity_ptr; 1.116 + signed int act_zbin_adj; 1.117 + 1.118 + int mv_best_ref_index[MAX_REF_FRAMES]; 1.119 + unsigned int max_mv_context[MAX_REF_FRAMES]; 1.120 + unsigned int source_variance; 1.121 + 1.122 + int nmvjointcost[MV_JOINTS]; 1.123 + int nmvcosts[2][MV_VALS]; 1.124 + int *nmvcost[2]; 1.125 + int nmvcosts_hp[2][MV_VALS]; 1.126 + int *nmvcost_hp[2]; 1.127 + int **mvcost; 1.128 + 1.129 + int nmvjointsadcost[MV_JOINTS]; 1.130 + int nmvsadcosts[2][MV_VALS]; 1.131 + int *nmvsadcost[2]; 1.132 + int nmvsadcosts_hp[2][MV_VALS]; 1.133 + int *nmvsadcost_hp[2]; 1.134 + int **mvsadcost; 1.135 + 1.136 + int mbmode_cost[MB_MODE_COUNT]; 1.137 + unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; 1.138 + int intra_uv_mode_cost[2][MB_MODE_COUNT]; 1.139 + int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; 1.140 + int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; 1.141 + 1.142 + unsigned char sb_index; // index of 32x32 block inside the 64x64 block 1.143 + unsigned char mb_index; // index of 16x16 block inside the 32x32 block 1.144 + unsigned char b_index; // index of 8x8 block inside the 16x16 block 1.145 + unsigned char ab_index; // index of 4x4 block inside the 8x8 block 1.146 + 1.147 + // These define limits to motion vector components to prevent them 1.148 + // from extending outside the UMV borders 1.149 + int mv_col_min; 1.150 + int mv_col_max; 1.151 + int mv_row_min; 1.152 + int mv_row_max; 1.153 + 1.154 + uint8_t zcoeff_blk[TX_SIZES][256]; 1.155 + int skip; 1.156 + 1.157 + int encode_breakout; 1.158 + 1.159 + unsigned char *active_ptr; 1.160 + 1.161 + // note that token_costs is the cost when eob node is skipped 1.162 + vp9_coeff_cost token_costs[TX_SIZES]; 1.163 + DECLARE_ALIGNED(16, uint8_t, token_cache[1024]); 1.164 + 1.165 + int optimize; 1.166 + 1.167 + // indicate if it is in the rd search loop or encoding process 1.168 + int use_lp32x32fdct; 1.169 + int skip_encode; 1.170 + 1.171 + // Used to store sub partition's choices. 1.172 + int fast_ms; 1.173 + int_mv pred_mv[MAX_REF_FRAMES]; 1.174 + int subblock_ref; 1.175 + 1.176 + // TODO(jingning): Need to refactor the structure arrays that buffers the 1.177 + // coding mode decisions of each partition type. 1.178 + PICK_MODE_CONTEXT ab4x4_context[4][4][4]; 1.179 + PICK_MODE_CONTEXT sb8x4_context[4][4][4]; 1.180 + PICK_MODE_CONTEXT sb4x8_context[4][4][4]; 1.181 + PICK_MODE_CONTEXT sb8x8_context[4][4][4]; 1.182 + PICK_MODE_CONTEXT sb8x16_context[4][4][2]; 1.183 + PICK_MODE_CONTEXT sb16x8_context[4][4][2]; 1.184 + PICK_MODE_CONTEXT mb_context[4][4]; 1.185 + PICK_MODE_CONTEXT sb32x16_context[4][2]; 1.186 + PICK_MODE_CONTEXT sb16x32_context[4][2]; 1.187 + // when 4 MBs share coding parameters: 1.188 + PICK_MODE_CONTEXT sb32_context[4]; 1.189 + PICK_MODE_CONTEXT sb32x64_context[2]; 1.190 + PICK_MODE_CONTEXT sb64x32_context[2]; 1.191 + PICK_MODE_CONTEXT sb64_context; 1.192 + int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES]; 1.193 + 1.194 + BLOCK_SIZE b_partitioning[4][4][4]; 1.195 + BLOCK_SIZE mb_partitioning[4][4]; 1.196 + BLOCK_SIZE sb_partitioning[4]; 1.197 + BLOCK_SIZE sb64_partitioning; 1.198 + 1.199 + void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride); 1.200 +}; 1.201 + 1.202 +// TODO(jingning): the variables used here are little complicated. need further 1.203 +// refactoring on organizing the temporary buffers, when recursive 1.204 +// partition down to 4x4 block size is enabled. 1.205 +static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { 1.206 + switch (bsize) { 1.207 + case BLOCK_64X64: 1.208 + return &x->sb64_context; 1.209 + case BLOCK_64X32: 1.210 + return &x->sb64x32_context[x->sb_index]; 1.211 + case BLOCK_32X64: 1.212 + return &x->sb32x64_context[x->sb_index]; 1.213 + case BLOCK_32X32: 1.214 + return &x->sb32_context[x->sb_index]; 1.215 + case BLOCK_32X16: 1.216 + return &x->sb32x16_context[x->sb_index][x->mb_index]; 1.217 + case BLOCK_16X32: 1.218 + return &x->sb16x32_context[x->sb_index][x->mb_index]; 1.219 + case BLOCK_16X16: 1.220 + return &x->mb_context[x->sb_index][x->mb_index]; 1.221 + case BLOCK_16X8: 1.222 + return &x->sb16x8_context[x->sb_index][x->mb_index][x->b_index]; 1.223 + case BLOCK_8X16: 1.224 + return &x->sb8x16_context[x->sb_index][x->mb_index][x->b_index]; 1.225 + case BLOCK_8X8: 1.226 + return &x->sb8x8_context[x->sb_index][x->mb_index][x->b_index]; 1.227 + case BLOCK_8X4: 1.228 + return &x->sb8x4_context[x->sb_index][x->mb_index][x->b_index]; 1.229 + case BLOCK_4X8: 1.230 + return &x->sb4x8_context[x->sb_index][x->mb_index][x->b_index]; 1.231 + case BLOCK_4X4: 1.232 + return &x->ab4x4_context[x->sb_index][x->mb_index][x->b_index]; 1.233 + default: 1.234 + assert(0); 1.235 + return NULL; 1.236 + } 1.237 +} 1.238 + 1.239 +struct rdcost_block_args { 1.240 + MACROBLOCK *x; 1.241 + ENTROPY_CONTEXT t_above[16]; 1.242 + ENTROPY_CONTEXT t_left[16]; 1.243 + TX_SIZE tx_size; 1.244 + int bw; 1.245 + int bh; 1.246 + int rate; 1.247 + int64_t dist; 1.248 + int64_t sse; 1.249 + int this_rate; 1.250 + int64_t this_dist; 1.251 + int64_t this_sse; 1.252 + int64_t this_rd; 1.253 + int64_t best_rd; 1.254 + int skip; 1.255 + const int16_t *scan, *nb; 1.256 +}; 1.257 + 1.258 +#endif // VP9_ENCODER_VP9_BLOCK_H_