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

11 12
#ifndef VP9_ENCODER_VP9_BLOCK_H_
#define VP9_ENCODER_VP9_BLOCK_H_
John Koleszar's avatar
John Koleszar committed
13

14 15
#include "vpx_util/vpx_thread.h"

16 17
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_entropy.h"
John Koleszar's avatar
John Koleszar committed
18

19 20 21 22
#ifdef __cplusplus
extern "C" {
#endif

23 24 25 26 27 28
typedef struct {
  unsigned int sse;
  int sum;
  unsigned int var;
} diff;

29
struct macroblock_plane {
30
  DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
31 32
  tran_low_t *qcoeff;
  tran_low_t *coeff;
33
  uint16_t *eobs;
John Koleszar's avatar
John Koleszar committed
34
  struct buf_2d src;
35 36

  // Quantizer setings
37
  int16_t *quant_fp;
Jingning Han's avatar
Jingning Han committed
38
  int16_t *round_fp;
39
  int16_t *quant;
40
  int16_t *quant_shift;
41 42 43
  int16_t *zbin;
  int16_t *round;

44
  int64_t quant_thred[2];
45 46
};

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

52 53 54 55 56
typedef struct {
  int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
  uint8_t mode_context[MAX_REF_FRAMES];
} MB_MODE_INFO_EXT;

Alex Converse's avatar
Alex Converse committed
57 58 59 60 61 62 63
typedef struct {
  int col_min;
  int col_max;
  int row_min;
  int row_max;
} MvLimits;

64 65
typedef struct macroblock MACROBLOCK;
struct macroblock {
66 67 68 69 70
// cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054
#if defined(_MSC_VER) && _MSC_VER < 1900
  int64_t bsse[MAX_MB_PLANE << 2];
#endif

71
  struct macroblock_plane plane[MAX_MB_PLANE];
John Koleszar's avatar
John Koleszar committed
72 73

  MACROBLOCKD e_mbd;
74 75
  MB_MODE_INFO_EXT *mbmi_ext;
  MB_MODE_INFO_EXT *mbmi_ext_base;
John Koleszar's avatar
John Koleszar committed
76
  int skip_block;
77
  int select_tx_size;
78
  int skip_recode;
79
  int skip_optimize;
80
  int q_index;
81 82
  int block_qcoeff_opt;
  int block_tx_domain;
John Koleszar's avatar
John Koleszar committed
83

84 85
  // The equivalent error at the current rdmult of one whole bit (not one
  // bitcost unit).
John Koleszar's avatar
John Koleszar committed
86
  int errorperbit;
87 88
  // The equivalend SAD error of one (whole) bit at the current quantizer
  // for large blocks.
John Koleszar's avatar
John Koleszar committed
89
  int sadperbit16;
90 91
  // The equivalend SAD error of one (whole) bit at the current quantizer
  // for sub-8x8 blocks.
John Koleszar's avatar
John Koleszar committed
92 93 94
  int sadperbit4;
  int rddiv;
  int rdmult;
95
  int mb_energy;
John Koleszar's avatar
John Koleszar committed
96

97 98 99 100 101
  // 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;

102
  int mv_best_ref_index[MAX_REF_FRAMES];
103
  unsigned int max_mv_context[MAX_REF_FRAMES];
104
  unsigned int source_variance;
105 106
  unsigned int pred_sse[MAX_REF_FRAMES];
  int pred_mv_sad[MAX_REF_FRAMES];
107

108 109 110
  int nmvjointcost[MV_JOINTS];
  int *nmvcost[2];
  int *nmvcost_hp[2];
111
  int **mvcost;
112 113 114 115

  int nmvjointsadcost[MV_JOINTS];
  int *nmvsadcost[2];
  int *nmvsadcost_hp[2];
116
  int **mvsadcost;
117

118 119
  // These define limits to motion vector components to prevent them
  // from extending outside the UMV borders
Alex Converse's avatar
Alex Converse committed
120
  MvLimits mv_limits;
John Koleszar's avatar
John Koleszar committed
121

Alex Converse's avatar
Alex Converse committed
122 123
  // Notes transform blocks where no coefficents are coded.
  // Set during mode selection. Read during block encoding.
124
  uint8_t zcoeff_blk[TX_SIZES][256];
Alex Converse's avatar
Alex Converse committed
125

126 127 128
  // Accumulate the tx block eobs in a partition block.
  int32_t sum_y_eobs[TX_SIZES];

John Koleszar's avatar
John Koleszar committed
129
  int skip;
John Koleszar's avatar
John Koleszar committed
130

John Koleszar's avatar
John Koleszar committed
131
  int encode_breakout;
John Koleszar's avatar
John Koleszar committed
132

133
  // note that token_costs is the cost when eob node is skipped
134
  vp9_coeff_cost token_costs[TX_SIZES];
135

John Koleszar's avatar
John Koleszar committed
136
  int optimize;
John Koleszar's avatar
John Koleszar committed
137

138
  // indicate if it is in the rd search loop or encoding process
139
  int use_lp32x32fdct;
140
  int skip_encode;
141

142 143 144 145
  // In first pass, intra prediction is done based on source pixels
  // at tile boundaries
  int fp_src_pred;

Jingning Han's avatar
Jingning Han committed
146 147 148
  // use fast quantization process
  int quant_fp;

149
  // skip forward transform and quantization
150
  uint8_t skip_txfm[MAX_MB_PLANE << 2];
clang-format's avatar
clang-format committed
151 152 153
#define SKIP_TXFM_NONE 0
#define SKIP_TXFM_AC_DC 1
#define SKIP_TXFM_AC_ONLY 2
154

155 156
// cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054
#if !defined(_MSC_VER) || _MSC_VER >= 1900
157
  int64_t bsse[MAX_MB_PLANE << 2];
158
#endif
159

160
  // Used to store sub partition's choices.
Dmitry Kovalev's avatar
Dmitry Kovalev committed
161
  MV pred_mv[MAX_REF_FRAMES];
162

163 164 165 166
  // 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];

167 168
  uint8_t sb_is_skin;

169 170
  uint8_t skip_low_source_sad;

171 172
  uint8_t lowvar_highsumdiff;

173 174
  uint8_t last_sb_high_content;

175 176 177 178 179 180
  int sb_use_mv_part;

  int sb_mvcol_part;

  int sb_mvrow_part;

181 182
  int sb_pickmode_part;

183 184 185 186
  // For each superblock: saves the content value (e.g., low/high sad/sumdiff)
  // based on source sad, prior to encoding the frame.
  uint8_t content_state_sb;

187
  // Used to save the status of whether a block has a low variance in
188 189 190
  // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for
  // 32x32, 9~24 for 16x16.
  uint8_t variance_low[25];
191

192
  void (*fwd_txfm4x4)(const int16_t *input, tran_low_t *output, int stride);
193 194
  void (*inv_txfm_add)(const tran_low_t *input, uint8_t *dest, int stride,
                       int eob);
195
#if CONFIG_VP9_HIGHBITDEPTH
196 197
  void (*highbd_inv_txfm_add)(const tran_low_t *input, uint16_t *dest,
                              int stride, int eob, int bd);
198
#endif
199
};
John Koleszar's avatar
John Koleszar committed
200

201 202 203 204
#ifdef __cplusplus
}  // extern "C"
#endif

205
#endif  // VP9_ENCODER_VP9_BLOCK_H_