vp9_block.h revision f3bed9137f66ef693bd406e43b17e9a1114f1e14
1ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang/* 2ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 3ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * 4ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * Use of this source code is governed by a BSD-style license 5ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * that can be found in the LICENSE file in the root of the source 6ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * tree. An additional intellectual property rights grant can be found 7ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * in the file PATENTS. All contributing project authors may 8ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang * be found in the AUTHORS file in the root of the source tree. 9ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang */ 10ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 11ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#ifndef VP9_ENCODER_VP9_BLOCK_H_ 12ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#define VP9_ENCODER_VP9_BLOCK_H_ 13ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 14ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vp9/common/vp9_onyx.h" 15ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vp9/common/vp9_entropymv.h" 16ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vp9/common/vp9_entropy.h" 17ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vpx_ports/mem.h" 18ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#include "vp9/common/vp9_onyxc_int.h" 19ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 20ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// motion search site 21ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangtypedef struct { 22ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang MV mv; 23ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int offset; 24ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} search_site; 25ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 26ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangtypedef struct { 27ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang struct { 28ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang MB_PREDICTION_MODE mode; 29ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } bmi[4]; 30ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} PARTITION_INFO; 31ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 32ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// Structure to hold snapshot of coding context during the mode picking process 33ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// TODO Do we need all of these? 34ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangtypedef struct { 35ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang MODE_INFO mic; 36ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PARTITION_INFO partition_info; 37ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int skip; 38ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int_mv best_ref_mv; 39ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int_mv second_best_ref_mv; 40ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; 41ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int rate; 42ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int distortion; 43ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int64_t intra_error; 44ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int best_mode_index; 45ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int rddiv; 46ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int rdmult; 47ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int hybrid_pred_diff; 48ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int comp_pred_diff; 49ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int single_pred_diff; 50f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang int64_t tx_rd_diff[TX_MODES]; 5191037db265ecdd914a26e056cf69207b4f50924ehkuang int64_t best_filter_diff[VP9_SWITCHABLE_FILTERS + 1]; 52ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 53ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // Bit flag for each mode whether it has high error in comparison to others. 54ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang unsigned int modes_with_high_error; 55ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 56ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // Bit flag for each ref frame whether it has high error compared to others. 57ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang unsigned int frames_with_high_error; 58ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} PICK_MODE_CONTEXT; 59ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 60ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangstruct macroblock_plane { 61ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang DECLARE_ALIGNED(16, int16_t, src_diff[64*64]); 62ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang DECLARE_ALIGNED(16, int16_t, coeff[64*64]); 63ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang struct buf_2d src; 64ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 65ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // Quantizer setings 66ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int16_t *quant; 6791037db265ecdd914a26e056cf69207b4f50924ehkuang int16_t *quant_shift; 68ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int16_t *zbin; 69ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int16_t *round; 70ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 71ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // Zbin Over Quant value 72ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int16_t zbin_extra; 73ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}; 74ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 75f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang/* The [2] dimension is for whether we skip the EOB node (i.e. if previous 76f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang * coefficient in this block was zero) or not. */ 77f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuangtypedef unsigned int vp9_coeff_cost[BLOCK_TYPES][REF_TYPES][COEF_BANDS][2] 78f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; 79f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang 80ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangtypedef struct macroblock MACROBLOCK; 81ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangstruct macroblock { 82ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang struct macroblock_plane plane[MAX_MB_PLANE]; 83ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 84ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang MACROBLOCKD e_mbd; 85ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int skip_block; 86ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PARTITION_INFO *partition_info; /* work pointer */ 87ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PARTITION_INFO *pi; /* Corresponds to upper left visible macroblock */ 88ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PARTITION_INFO *pip; /* Base of allocated array */ 89ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 90ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang search_site *ss; 91ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int ss_count; 92ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int searches_per_step; 93ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 94ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int errorperbit; 95ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int sadperbit16; 96ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int sadperbit4; 97ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int rddiv; 98ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int rdmult; 99ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang unsigned int *mb_activity_ptr; 100ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int *mb_norm_activity_ptr; 101ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang signed int act_zbin_adj; 102ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 103ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int mv_best_ref_index[MAX_REF_FRAMES]; 10491037db265ecdd914a26e056cf69207b4f50924ehkuang unsigned int max_mv_context[MAX_REF_FRAMES]; 105f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang unsigned int source_variance; 106ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 107ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int nmvjointcost[MV_JOINTS]; 108ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int nmvcosts[2][MV_VALS]; 109ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int *nmvcost[2]; 110ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int nmvcosts_hp[2][MV_VALS]; 111ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int *nmvcost_hp[2]; 112ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int **mvcost; 113ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 114ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int nmvjointsadcost[MV_JOINTS]; 115ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int nmvsadcosts[2][MV_VALS]; 116ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int *nmvsadcost[2]; 117ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int nmvsadcosts_hp[2][MV_VALS]; 118ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int *nmvsadcost_hp[2]; 119ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int **mvsadcost; 120ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 121ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int mbmode_cost[MB_MODE_COUNT]; 12291037db265ecdd914a26e056cf69207b4f50924ehkuang unsigned inter_mode_cost[INTER_MODE_CONTEXTS][MB_MODE_COUNT - NEARESTMV]; 123ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int intra_uv_mode_cost[2][MB_MODE_COUNT]; 124ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int y_mode_costs[VP9_INTRA_MODES][VP9_INTRA_MODES][VP9_INTRA_MODES]; 125ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int switchable_interp_costs[VP9_SWITCHABLE_FILTERS + 1] 126ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang [VP9_SWITCHABLE_FILTERS]; 127ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 128ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // These define limits to motion vector components to prevent them 129ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // from extending outside the UMV borders 130ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int mv_col_min; 131ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int mv_col_max; 132ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int mv_row_min; 133ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int mv_row_max; 134ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 135ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int skip; 136ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 137ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int encode_breakout; 138ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 139ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang unsigned char *active_ptr; 140ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 141ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // note that token_costs is the cost when eob node is skipped 142f3bed9137f66ef693bd406e43b17e9a1114f1e14hkuang vp9_coeff_cost token_costs[TX_SIZES]; 143ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 144ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int optimize; 145ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 146ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // indicate if it is in the rd search loop or encoding process 147ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int rd_search; 14891037db265ecdd914a26e056cf69207b4f50924ehkuang int skip_encode; 14991037db265ecdd914a26e056cf69207b4f50924ehkuang 15091037db265ecdd914a26e056cf69207b4f50924ehkuang // Used to store sub partition's choices. 15191037db265ecdd914a26e056cf69207b4f50924ehkuang int fast_ms; 15291037db265ecdd914a26e056cf69207b4f50924ehkuang int_mv pred_mv; 15391037db265ecdd914a26e056cf69207b4f50924ehkuang int subblock_ref; 154ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 155ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // TODO(jingning): Need to refactor the structure arrays that buffers the 156ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // coding mode decisions of each partition type. 157ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT ab4x4_context[4][4][4]; 158ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb8x4_context[4][4][4]; 159ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb4x8_context[4][4][4]; 160ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb8x8_context[4][4][4]; 161ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb8x16_context[4][4][2]; 162ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb16x8_context[4][4][2]; 163ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT mb_context[4][4]; 164ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb32x16_context[4][2]; 165ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb16x32_context[4][2]; 166ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang // when 4 MBs share coding parameters: 167ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb32_context[4]; 168ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb32x64_context[2]; 169ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb64x32_context[2]; 170ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang PICK_MODE_CONTEXT sb64_context; 171ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int partition_cost[NUM_PARTITION_CONTEXTS][PARTITION_TYPES]; 172ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 173ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang BLOCK_SIZE_TYPE b_partitioning[4][4][4]; 174ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang BLOCK_SIZE_TYPE mb_partitioning[4][4]; 175ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang BLOCK_SIZE_TYPE sb_partitioning[4]; 176ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang BLOCK_SIZE_TYPE sb64_partitioning; 177ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 178ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang void (*fwd_txm4x4)(int16_t *input, int16_t *output, int pitch); 179ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang void (*fwd_txm8x4)(int16_t *input, int16_t *output, int pitch); 180ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang void (*fwd_txm8x8)(int16_t *input, int16_t *output, int pitch); 181ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang void (*fwd_txm16x16)(int16_t *input, int16_t *output, int pitch); 182ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang void (*quantize_b_4x4)(MACROBLOCK *x, int b_idx, TX_TYPE tx_type, 183ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int y_blocks); 184ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}; 185ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 186ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#endif // VP9_ENCODER_VP9_BLOCK_H_ 187