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