vp9_block.h 5.3 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
16
#include "vp9/common/vp9_onyx.h"
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_entropy.h"
John Koleszar's avatar
John Koleszar committed
17
#include "vpx_ports/mem.h"
18
#include "vp9/common/vp9_onyxc_int.h"
John Koleszar's avatar
John Koleszar committed
19
20

// motion search site
John Koleszar's avatar
John Koleszar committed
21
22
23
typedef struct {
  MV mv;
  int offset;
John Koleszar's avatar
John Koleszar committed
24
25
} search_site;

Jim Bankoski's avatar
Jim Bankoski committed
26
typedef struct block {
John Koleszar's avatar
John Koleszar committed
27
  // 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries
28
29
  int16_t *src_diff;
  int16_t *coeff;
John Koleszar's avatar
John Koleszar committed
30
31

  // 16 Y blocks, 4 U blocks, 4 V blocks each with 16 entries
32
33
34
35
36
37
  int16_t *quant;
  int16_t *quant_fast;      // fast quant deprecated for now
  uint8_t *quant_shift;
  int16_t *zbin;
  int16_t *zbin_8x8;
  int16_t *zbin_16x16;
38
#if CONFIG_TX32X32
39
  int16_t *zbin_32x32;
40
#endif
41
42
43
  int16_t *zrun_zbin_boost;
  int16_t *zrun_zbin_boost_8x8;
  int16_t *zrun_zbin_boost_16x16;
44
#if CONFIG_TX32X32
45
  int16_t *zrun_zbin_boost_32x32;
46
#endif
47
  int16_t *round;
John Koleszar's avatar
John Koleszar committed
48
49
50
51

  // Zbin Over Quant value
  short zbin_extra;

52
53
  uint8_t **base_src;
  uint8_t **base_second_src;
John Koleszar's avatar
John Koleszar committed
54
55
56
57
58
  int src;
  int src_stride;

  int eob_max_offset;
  int eob_max_offset_8x8;
Daniel Kang's avatar
Daniel Kang committed
59
  int eob_max_offset_16x16;
60
#if CONFIG_TX32X32
61
62
  int eob_max_offset_32x32;
#endif
John Koleszar's avatar
John Koleszar committed
63
64
} BLOCK;

John Koleszar's avatar
John Koleszar committed
65
66
67
68
69
70
71
typedef struct {
  int count;
  struct {
    B_PREDICTION_MODE mode;
    int_mv mv;
    int_mv second_mv;
  } bmi[16];
72
73
} PARTITION_INFO;

Adrian Grange's avatar
Adrian Grange committed
74
75
// Structure to hold snapshot of coding context during the mode picking process
// TODO Do we need all of these?
John Koleszar's avatar
John Koleszar committed
76
77
78
typedef struct {
  MODE_INFO mic;
  PARTITION_INFO partition_info;
79
  int skip;
John Koleszar's avatar
John Koleszar committed
80
81
  int_mv best_ref_mv;
  int_mv second_best_ref_mv;
Paul Wilkins's avatar
Paul Wilkins committed
82
  int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
John Koleszar's avatar
John Koleszar committed
83
84
  int rate;
  int distortion;
85
  int64_t intra_error;
John Koleszar's avatar
John Koleszar committed
86
87
88
  int best_mode_index;
  int rddiv;
  int rdmult;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
89
90
91
  int hybrid_pred_diff;
  int comp_pred_diff;
  int single_pred_diff;
92
  int64_t txfm_rd_diff[NB_TXFM_MODES];
Adrian Grange's avatar
Adrian Grange committed
93
94
} PICK_MODE_CONTEXT;

95
#if CONFIG_TX32X32
96
typedef struct superblock {
97
98
  DECLARE_ALIGNED(16, int16_t, src_diff[32*32+16*16*2]);
  DECLARE_ALIGNED(16, int16_t, coeff[32*32+16*16*2]);
99
100
101
} SUPERBLOCK;
#endif

Jim Bankoski's avatar
Jim Bankoski committed
102
typedef struct macroblock {
103
104
  DECLARE_ALIGNED(16, int16_t, src_diff[400]);  // 16x16 Y 8x8 U 8x8 V 4x4 2nd Y
  DECLARE_ALIGNED(16, int16_t, coeff[400]);     // 16x16 Y 8x8 U 8x8 V 4x4 2nd Y
John Koleszar's avatar
John Koleszar committed
105
106
107
108
  // 16 Y blocks, 4 U blocks, 4 V blocks,
  // 1 DC 2nd order block each with 16 entries
  BLOCK block[25];

109
#if CONFIG_TX32X32
110
111
112
  SUPERBLOCK sb_coeff_data;
#endif

John Koleszar's avatar
John Koleszar committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  YV12_BUFFER_CONFIG src;

  MACROBLOCKD e_mbd;
  PARTITION_INFO *partition_info; /* work pointer */
  PARTITION_INFO *pi;   /* Corresponds to upper left visible macroblock */
  PARTITION_INFO *pip;  /* Base of allocated array */

  search_site *ss;
  int ss_count;
  int searches_per_step;

  int errorperbit;
  int sadperbit16;
  int sadperbit4;
  int rddiv;
  int rdmult;
  unsigned int *mb_activity_ptr;
  int *mb_norm_activity_ptr;
  signed int act_zbin_adj;

133
134
  int mv_best_ref_index[MAX_REF_FRAMES];

135
136
137
138
139
  int nmvjointcost[MV_JOINTS];
  int nmvcosts[2][MV_VALS];
  int *nmvcost[2];
  int nmvcosts_hp[2][MV_VALS];
  int *nmvcost_hp[2];
140
  int **mvcost;
141
142
143
144
145
146

  int nmvjointsadcost[MV_JOINTS];
  int nmvsadcosts[2][MV_VALS];
  int *nmvsadcost[2];
  int nmvsadcosts_hp[2][MV_VALS];
  int *nmvsadcost_hp[2];
147
  int **mvsadcost;
148

John Koleszar's avatar
John Koleszar committed
149
150
  int mbmode_cost[2][MB_MODE_COUNT];
  int intra_uv_mode_cost[2][MB_MODE_COUNT];
151
  int bmode_costs[VP9_KF_BINTRAMODES][VP9_KF_BINTRAMODES][VP9_KF_BINTRAMODES];
John Koleszar's avatar
John Koleszar committed
152
153
  int i8x8_mode_costs[MB_MODE_COUNT];
  int inter_bmode_costs[B_MODE_COUNT];
154
155
  int switchable_interp_costs[VP9_SWITCHABLE_FILTERS + 1]
                             [VP9_SWITCHABLE_FILTERS];
John Koleszar's avatar
John Koleszar committed
156

157
158
  // These define limits to motion vector components to prevent them
  // from extending outside the UMV borders
John Koleszar's avatar
John Koleszar committed
159
160
161
162
  int mv_col_min;
  int mv_col_max;
  int mv_row_min;
  int mv_row_max;
John Koleszar's avatar
John Koleszar committed
163

John Koleszar's avatar
John Koleszar committed
164
  int skip;
John Koleszar's avatar
John Koleszar committed
165

John Koleszar's avatar
John Koleszar committed
166
  int encode_breakout;
John Koleszar's avatar
John Koleszar committed
167

John Koleszar's avatar
John Koleszar committed
168
169
  // char * gf_active_ptr;
  signed char *gf_active_ptr;
170

John Koleszar's avatar
John Koleszar committed
171
  unsigned char *active_ptr;
John Koleszar's avatar
John Koleszar committed
172

173
174
  vp9_coeff_count token_costs[TX_SIZE_MAX_SB][BLOCK_TYPES_4X4];
  vp9_coeff_count hybrid_token_costs[TX_SIZE_MAX_SB][BLOCK_TYPES_4X4];
175

John Koleszar's avatar
John Koleszar committed
176
  int optimize;
John Koleszar's avatar
John Koleszar committed
177

John Koleszar's avatar
John Koleszar committed
178
179
  // Structure to hold context for each of the 4 MBs within a SB:
  // when encoded as 4 independent MBs:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
180
  PICK_MODE_CONTEXT mb_context[4][4];
John Koleszar's avatar
John Koleszar committed
181
  // when 4 MBs share coding parameters:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
182
183
  PICK_MODE_CONTEXT sb32_context[4];
  PICK_MODE_CONTEXT sb64_context;
Adrian Grange's avatar
Adrian Grange committed
184

185
186
187
  void (*vp9_short_fdct4x4)(int16_t *input, int16_t *output, int pitch);
  void (*vp9_short_fdct8x4)(int16_t *input, int16_t *output, int pitch);
  void (*short_walsh4x4)(int16_t *input, int16_t *output, int pitch);
188
189
  void (*quantize_b_4x4)(BLOCK *b, BLOCKD *d);
  void (*quantize_b_4x4_pair)(BLOCK *b1, BLOCK *b2, BLOCKD *d0, BLOCKD *d1);
190
191
192
  void (*vp9_short_fdct8x8)(int16_t *input, int16_t *output, int pitch);
  void (*vp9_short_fdct16x16)(int16_t *input, int16_t *output, int pitch);
  void (*short_fhaar2x2)(int16_t *input, int16_t *output, int pitch);
Daniel Kang's avatar
Daniel Kang committed
193
  void (*quantize_b_16x16)(BLOCK *b, BLOCKD *d);
John Koleszar's avatar
John Koleszar committed
194
195
  void (*quantize_b_8x8)(BLOCK *b, BLOCKD *d);
  void (*quantize_b_2x2)(BLOCK *b, BLOCKD *d);
John Koleszar's avatar
John Koleszar committed
196
197
} MACROBLOCK;

198
#endif  // VP9_ENCODER_VP9_BLOCK_H_