block.h 4.94 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1 2 3 4 5 6 7 8 9 10
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

11 12
#ifndef VP10_ENCODER_BLOCK_H_
#define VP10_ENCODER_BLOCK_H_
Jingning Han's avatar
Jingning Han committed
13

14 15
#include "vp10/common/entropymv.h"
#include "vp10/common/entropy.h"
16 17 18
#if CONFIG_REF_MV
#include "vp10/common/mvref_common.h"
#endif
Jingning Han's avatar
Jingning Han committed
19 20 21 22 23 24 25 26 27 28 29

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
  unsigned int sse;
  int sum;
  unsigned int var;
} diff;

Angie Chiang's avatar
Angie Chiang committed
30
typedef struct macroblock_plane {
31
  DECLARE_ALIGNED(16, int16_t, src_diff[MAX_SB_SQUARE]);
Jingning Han's avatar
Jingning Han committed
32 33 34 35 36 37
  tran_low_t *qcoeff;
  tran_low_t *coeff;
  uint16_t *eobs;
  struct buf_2d src;

  // Quantizer setings
38 39 40 41 42 43
  const int16_t *quant_fp;
  const int16_t *round_fp;
  const int16_t *quant;
  const int16_t *quant_shift;
  const int16_t *zbin;
  const int16_t *round;
44
#if CONFIG_NEW_QUANT
45
  cuml_bins_type_nuq *cuml_bins_nuq[QUANT_PROFILES];
46
#endif  // CONFIG_NEW_QUANT
Jingning Han's avatar
Jingning Han committed
47 48

  int64_t quant_thred[2];
Angie Chiang's avatar
Angie Chiang committed
49
} MACROBLOCK_PLANE;
Jingning Han's avatar
Jingning Han committed
50 51 52 53 54 55 56

/* The [2] dimension is for whether we skip the EOB node (i.e. if previous
 * coefficient in this block was zero) or not. */
typedef unsigned int vp10_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
                                   [COEFF_CONTEXTS][ENTROPY_TOKENS];

typedef struct {
57 58
  int_mv ref_mvs[MODE_CTX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
  int16_t mode_context[MODE_CTX_REF_FRAMES];
59
#if CONFIG_REF_MV
60 61
  uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
  CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
62 63 64
#if CONFIG_EXT_INTER
  int16_t compound_mode_context[MODE_CTX_REF_FRAMES];
#endif  // CONFIG_EXT_INTER
65
#endif
Jingning Han's avatar
Jingning Han committed
66 67
} MB_MODE_INFO_EXT;

hui su's avatar
hui su committed
68
typedef struct {
69
  uint8_t best_palette_color_map[MAX_SB_SQUARE];
70
  float kmeans_data_buf[2 * MAX_SB_SQUARE];
71 72
  uint8_t kmeans_indices_buf[MAX_SB_SQUARE];
  uint8_t kmeans_pre_indices_buf[MAX_SB_SQUARE];
hui su's avatar
hui su committed
73 74
} PALETTE_BUFFER;

Jingning Han's avatar
Jingning Han committed
75 76 77 78 79 80 81 82 83 84 85
typedef struct macroblock MACROBLOCK;
struct macroblock {
  struct macroblock_plane plane[MAX_MB_PLANE];

  MACROBLOCKD e_mbd;
  MB_MODE_INFO_EXT *mbmi_ext;
  int skip_block;
  int select_tx_size;
  int skip_optimize;
  int q_index;

86 87
  // The equivalent error at the current rdmult of one whole bit (not one
  // bitcost unit).
Jingning Han's avatar
Jingning Han committed
88
  int errorperbit;
89 90
  // The equivalend SAD error of one (whole) bit at the current quantizer
  // for large blocks.
Jingning Han's avatar
Jingning Han committed
91
  int sadperbit16;
92 93
  // The equivalend SAD error of one (whole) bit at the current quantizer
  // for sub-8x8 blocks.
Jingning Han's avatar
Jingning Han committed
94 95 96 97
  int sadperbit4;
  int rddiv;
  int rdmult;
  int mb_energy;
98 99
  int * m_search_count_ptr;
  int * ex_search_count_ptr;
Jingning Han's avatar
Jingning Han committed
100 101 102 103 104 105 106 107 108

  // These are set to their default values at the beginning, and then adjusted
  // further in the encoding process.
  BLOCK_SIZE min_partition_size;
  BLOCK_SIZE max_partition_size;

  int mv_best_ref_index[MAX_REF_FRAMES];
  unsigned int max_mv_context[MAX_REF_FRAMES];
  unsigned int source_variance;
109
  unsigned int recon_variance;
Jingning Han's avatar
Jingning Han committed
110 111 112
  unsigned int pred_sse[MAX_REF_FRAMES];
  int pred_mv_sad[MAX_REF_FRAMES];

113 114 115 116 117 118
#if CONFIG_REF_MV
  int *nmvjointcost;
  int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS];
  int *nmvcost[NMV_CONTEXTS][2];
  int *nmvcost_hp[NMV_CONTEXTS][2];
  int **mv_cost_stack[NMV_CONTEXTS];
Jingning Han's avatar
Jingning Han committed
119
  int *nmvjointsadcost;
120 121
  int zero_rmv_cost[NMV_CONTEXTS][2];
  int comp_rmv_cost[2];
122
#else
Jingning Han's avatar
Jingning Han committed
123 124 125
  int nmvjointcost[MV_JOINTS];
  int *nmvcost[2];
  int *nmvcost_hp[2];
Jingning Han's avatar
Jingning Han committed
126
  int nmvjointsadcost[MV_JOINTS];
127 128
#endif

Jingning Han's avatar
Jingning Han committed
129 130 131 132 133
  int **mvcost;
  int *nmvsadcost[2];
  int *nmvsadcost_hp[2];
  int **mvsadcost;

hui su's avatar
hui su committed
134 135
  PALETTE_BUFFER *palette_buffer;

Jingning Han's avatar
Jingning Han committed
136 137 138 139 140 141 142
  // These define limits to motion vector components to prevent them
  // from extending outside the UMV borders
  int mv_col_min;
  int mv_col_max;
  int mv_row_min;
  int mv_row_max;

143
#if CONFIG_VAR_TX
144
  uint8_t blk_skip[MAX_MB_PLANE][MAX_MIB_SIZE * MAX_MIB_SIZE * 4];
145
#if CONFIG_REF_MV
146
  uint8_t blk_skip_drl[MAX_MB_PLANE][MAX_MIB_SIZE * MAX_MIB_SIZE * 4];
147
#endif
148
#endif
Jingning Han's avatar
Jingning Han committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

  int skip;

  int encode_breakout;

  // note that token_costs is the cost when eob node is skipped
  vp10_coeff_cost token_costs[TX_SIZES];

  int optimize;

  // indicate if it is in the rd search loop or encoding process
  int use_lp32x32fdct;

  // Used to store sub partition's choices.
  MV pred_mv[MAX_REF_FRAMES];

hui su's avatar
hui su committed
165 166
  // Store the best motion vector during motion search
  int_mv best_mv;
167 168
  // Store the second best motion vector during full-pixel motion search
  int_mv second_best_mv;
hui su's avatar
hui su committed
169

Jingning Han's avatar
Jingning Han committed
170 171 172
  // Strong color activity detection. Used in RTC coding mode to enhance
  // the visual quality at the boundary of moving color objects.
  uint8_t color_sensitivity[2];
173 174 175

  // use default transform and skip transform type search for intra modes
  int use_default_intra_tx_type;
176 177
  // use default transform and skip transform type search for inter modes
  int use_default_inter_tx_type;
Jingning Han's avatar
Jingning Han committed
178 179 180 181 182 183
};

#ifdef __cplusplus
}  // extern "C"
#endif

184
#endif  // VP10_ENCODER_BLOCK_H_