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