michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: #ifndef VP9_ENCODER_VP9_BLOCK_H_ michael@0: #define VP9_ENCODER_VP9_BLOCK_H_ michael@0: michael@0: #include "vp9/common/vp9_onyx.h" michael@0: #include "vp9/common/vp9_entropymv.h" michael@0: #include "vp9/common/vp9_entropy.h" michael@0: #include "vpx_ports/mem.h" michael@0: #include "vp9/common/vp9_onyxc_int.h" michael@0: michael@0: // motion search site michael@0: typedef struct { michael@0: MV mv; michael@0: int offset; michael@0: } search_site; michael@0: michael@0: // Structure to hold snapshot of coding context during the mode picking process michael@0: typedef struct { michael@0: MODE_INFO mic; michael@0: uint8_t *zcoeff_blk; michael@0: int16_t *coeff[MAX_MB_PLANE][3]; michael@0: int16_t *qcoeff[MAX_MB_PLANE][3]; michael@0: int16_t *dqcoeff[MAX_MB_PLANE][3]; michael@0: uint16_t *eobs[MAX_MB_PLANE][3]; michael@0: michael@0: // dual buffer pointers, 0: in use, 1: best in store michael@0: int16_t *coeff_pbuf[MAX_MB_PLANE][3]; michael@0: int16_t *qcoeff_pbuf[MAX_MB_PLANE][3]; michael@0: int16_t *dqcoeff_pbuf[MAX_MB_PLANE][3]; michael@0: uint16_t *eobs_pbuf[MAX_MB_PLANE][3]; michael@0: michael@0: int is_coded; michael@0: int num_4x4_blk; michael@0: int skip; michael@0: int_mv best_ref_mv; michael@0: int_mv second_best_ref_mv; michael@0: int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES]; michael@0: int rate; michael@0: int distortion; michael@0: int64_t intra_error; michael@0: int best_mode_index; michael@0: int rddiv; michael@0: int rdmult; michael@0: int hybrid_pred_diff; michael@0: int comp_pred_diff; michael@0: int single_pred_diff; michael@0: int64_t tx_rd_diff[TX_MODES]; michael@0: int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; michael@0: michael@0: // motion vector cache for adaptive motion search control in partition michael@0: // search loop michael@0: int_mv pred_mv[MAX_REF_FRAMES]; michael@0: michael@0: // Bit flag for each mode whether it has high error in comparison to others. michael@0: unsigned int modes_with_high_error; michael@0: michael@0: // Bit flag for each ref frame whether it has high error compared to others. michael@0: unsigned int frames_with_high_error; michael@0: } PICK_MODE_CONTEXT; michael@0: michael@0: struct macroblock_plane { michael@0: DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]); michael@0: int16_t *coeff; michael@0: struct buf_2d src; michael@0: michael@0: // Quantizer setings michael@0: int16_t *quant; michael@0: int16_t *quant_shift; michael@0: int16_t *zbin; michael@0: int16_t *round; michael@0: michael@0: // Zbin Over Quant value michael@0: int16_t zbin_extra; michael@0: }; michael@0: michael@0: /* The [2] dimension is for whether we skip the EOB node (i.e. if previous michael@0: * coefficient in this block was zero) or not. */ michael@0: typedef unsigned int vp9_coeff_cost[BLOCK_TYPES][REF_TYPES][COEF_BANDS][2] michael@0: [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; michael@0: michael@0: typedef struct macroblock MACROBLOCK; michael@0: struct macroblock { michael@0: struct macroblock_plane plane[MAX_MB_PLANE]; michael@0: michael@0: MACROBLOCKD e_mbd; michael@0: int skip_block; michael@0: int select_txfm_size; michael@0: int skip_recode; michael@0: int skip_optimize; michael@0: int q_index; michael@0: michael@0: search_site *ss; michael@0: int ss_count; michael@0: int searches_per_step; michael@0: michael@0: int errorperbit; michael@0: int sadperbit16; michael@0: int sadperbit4; michael@0: int rddiv; michael@0: int rdmult; michael@0: unsigned int mb_energy; michael@0: unsigned int *mb_activity_ptr; michael@0: int *mb_norm_activity_ptr; michael@0: signed int act_zbin_adj; michael@0: michael@0: int mv_best_ref_index[MAX_REF_FRAMES]; michael@0: unsigned int max_mv_context[MAX_REF_FRAMES]; michael@0: unsigned int source_variance; michael@0: michael@0: int nmvjointcost[MV_JOINTS]; michael@0: int nmvcosts[2][MV_VALS]; michael@0: int *nmvcost[2]; michael@0: int nmvcosts_hp[2][MV_VALS]; michael@0: int *nmvcost_hp[2]; michael@0: int **mvcost; michael@0: michael@0: int nmvjointsadcost[MV_JOINTS]; michael@0: int nmvsadcosts[2][MV_VALS]; michael@0: int *nmvsadcost[2]; michael@0: int nmvsadcosts_hp[2][MV_VALS]; michael@0: int *nmvsadcost_hp[2]; michael@0: int **mvsadcost; michael@0: michael@0: int mbmode_cost[MB_MODE_COUNT]; michael@0: unsigned inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; michael@0: int intra_uv_mode_cost[2][MB_MODE_COUNT]; michael@0: int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; michael@0: int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; michael@0: michael@0: unsigned char sb_index; // index of 32x32 block inside the 64x64 block michael@0: unsigned char mb_index; // index of 16x16 block inside the 32x32 block michael@0: unsigned char b_index; // index of 8x8 block inside the 16x16 block michael@0: unsigned char ab_index; // index of 4x4 block inside the 8x8 block michael@0: michael@0: // These define limits to motion vector components to prevent them michael@0: // from extending outside the UMV borders michael@0: int mv_col_min; michael@0: int mv_col_max; michael@0: int mv_row_min; michael@0: int mv_row_max; michael@0: michael@0: uint8_t zcoeff_blk[TX_SIZES][256]; michael@0: int skip; michael@0: michael@0: int encode_breakout; michael@0: michael@0: unsigned char *active_ptr; michael@0: michael@0: // note that token_costs is the cost when eob node is skipped michael@0: vp9_coeff_cost token_costs[TX_SIZES]; michael@0: DECLARE_ALIGNED(16, uint8_t, token_cache[1024]); michael@0: michael@0: int optimize; michael@0: michael@0: // indicate if it is in the rd search loop or encoding process michael@0: int use_lp32x32fdct; michael@0: int skip_encode; michael@0: michael@0: // Used to store sub partition's choices. michael@0: int fast_ms; michael@0: int_mv pred_mv[MAX_REF_FRAMES]; michael@0: int subblock_ref; michael@0: michael@0: // TODO(jingning): Need to refactor the structure arrays that buffers the michael@0: // coding mode decisions of each partition type. michael@0: PICK_MODE_CONTEXT ab4x4_context[4][4][4]; michael@0: PICK_MODE_CONTEXT sb8x4_context[4][4][4]; michael@0: PICK_MODE_CONTEXT sb4x8_context[4][4][4]; michael@0: PICK_MODE_CONTEXT sb8x8_context[4][4][4]; michael@0: PICK_MODE_CONTEXT sb8x16_context[4][4][2]; michael@0: PICK_MODE_CONTEXT sb16x8_context[4][4][2]; michael@0: PICK_MODE_CONTEXT mb_context[4][4]; michael@0: PICK_MODE_CONTEXT sb32x16_context[4][2]; michael@0: PICK_MODE_CONTEXT sb16x32_context[4][2]; michael@0: // when 4 MBs share coding parameters: michael@0: PICK_MODE_CONTEXT sb32_context[4]; michael@0: PICK_MODE_CONTEXT sb32x64_context[2]; michael@0: PICK_MODE_CONTEXT sb64x32_context[2]; michael@0: PICK_MODE_CONTEXT sb64_context; michael@0: int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES]; michael@0: michael@0: BLOCK_SIZE b_partitioning[4][4][4]; michael@0: BLOCK_SIZE mb_partitioning[4][4]; michael@0: BLOCK_SIZE sb_partitioning[4]; michael@0: BLOCK_SIZE sb64_partitioning; michael@0: michael@0: void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride); michael@0: }; michael@0: michael@0: // TODO(jingning): the variables used here are little complicated. need further michael@0: // refactoring on organizing the temporary buffers, when recursive michael@0: // partition down to 4x4 block size is enabled. michael@0: static PICK_MODE_CONTEXT *get_block_context(MACROBLOCK *x, BLOCK_SIZE bsize) { michael@0: switch (bsize) { michael@0: case BLOCK_64X64: michael@0: return &x->sb64_context; michael@0: case BLOCK_64X32: michael@0: return &x->sb64x32_context[x->sb_index]; michael@0: case BLOCK_32X64: michael@0: return &x->sb32x64_context[x->sb_index]; michael@0: case BLOCK_32X32: michael@0: return &x->sb32_context[x->sb_index]; michael@0: case BLOCK_32X16: michael@0: return &x->sb32x16_context[x->sb_index][x->mb_index]; michael@0: case BLOCK_16X32: michael@0: return &x->sb16x32_context[x->sb_index][x->mb_index]; michael@0: case BLOCK_16X16: michael@0: return &x->mb_context[x->sb_index][x->mb_index]; michael@0: case BLOCK_16X8: michael@0: return &x->sb16x8_context[x->sb_index][x->mb_index][x->b_index]; michael@0: case BLOCK_8X16: michael@0: return &x->sb8x16_context[x->sb_index][x->mb_index][x->b_index]; michael@0: case BLOCK_8X8: michael@0: return &x->sb8x8_context[x->sb_index][x->mb_index][x->b_index]; michael@0: case BLOCK_8X4: michael@0: return &x->sb8x4_context[x->sb_index][x->mb_index][x->b_index]; michael@0: case BLOCK_4X8: michael@0: return &x->sb4x8_context[x->sb_index][x->mb_index][x->b_index]; michael@0: case BLOCK_4X4: michael@0: return &x->ab4x4_context[x->sb_index][x->mb_index][x->b_index]; michael@0: default: michael@0: assert(0); michael@0: return NULL; michael@0: } michael@0: } michael@0: michael@0: struct rdcost_block_args { michael@0: MACROBLOCK *x; michael@0: ENTROPY_CONTEXT t_above[16]; michael@0: ENTROPY_CONTEXT t_left[16]; michael@0: TX_SIZE tx_size; michael@0: int bw; michael@0: int bh; michael@0: int rate; michael@0: int64_t dist; michael@0: int64_t sse; michael@0: int this_rate; michael@0: int64_t this_dist; michael@0: int64_t this_sse; michael@0: int64_t this_rd; michael@0: int64_t best_rd; michael@0: int skip; michael@0: const int16_t *scan, *nb; michael@0: }; michael@0: michael@0: #endif // VP9_ENCODER_VP9_BLOCK_H_