vp9_block.h 4.74 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
38
39
40
41
42
43
  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;
  int16_t *zbin_32x32;
  int16_t *zrun_zbin_boost;
  int16_t *zrun_zbin_boost_8x8;
  int16_t *zrun_zbin_boost_16x16;
  int16_t *zrun_zbin_boost_32x32;
  int16_t *round;
John Koleszar's avatar
John Koleszar committed
44
45
46
47

  // Zbin Over Quant value
  short zbin_extra;

48
49
  uint8_t **base_src;
  uint8_t **base_second_src;
John Koleszar's avatar
John Koleszar committed
50
51
52
  int src;
  int src_stride;

Paul Wilkins's avatar
Paul Wilkins committed
53
  int skip_block;
John Koleszar's avatar
John Koleszar committed
54
55
} BLOCK;

John Koleszar's avatar
John Koleszar committed
56
57
58
59
60
61
62
typedef struct {
  int count;
  struct {
    B_PREDICTION_MODE mode;
    int_mv mv;
    int_mv second_mv;
  } bmi[16];
63
64
} PARTITION_INFO;

Adrian Grange's avatar
Adrian Grange committed
65
66
// 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
67
68
69
typedef struct {
  MODE_INFO mic;
  PARTITION_INFO partition_info;
70
  int skip;
John Koleszar's avatar
John Koleszar committed
71
72
  int_mv best_ref_mv;
  int_mv second_best_ref_mv;
Paul Wilkins's avatar
Paul Wilkins committed
73
  int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
John Koleszar's avatar
John Koleszar committed
74
75
  int rate;
  int distortion;
76
  int64_t intra_error;
John Koleszar's avatar
John Koleszar committed
77
78
79
  int best_mode_index;
  int rddiv;
  int rdmult;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
80
81
82
  int hybrid_pred_diff;
  int comp_pred_diff;
  int single_pred_diff;
83
  int64_t txfm_rd_diff[NB_TXFM_MODES];
Adrian Grange's avatar
Adrian Grange committed
84
85
} PICK_MODE_CONTEXT;

86
typedef struct superblock {
87
88
  DECLARE_ALIGNED(16, int16_t, src_diff[32*32+16*16*2]);
  DECLARE_ALIGNED(16, int16_t, coeff[32*32+16*16*2]);
89
90
} SUPERBLOCK;

Jim Bankoski's avatar
Jim Bankoski committed
91
typedef struct macroblock {
92
93
  DECLARE_ALIGNED(16, int16_t, src_diff[384]);  // 16x16 Y 8x8 U 8x8 V
  DECLARE_ALIGNED(16, int16_t, coeff[384]);     // 16x16 Y 8x8 U 8x8 V
John Koleszar's avatar
John Koleszar committed
94
  // 16 Y blocks, 4 U blocks, 4 V blocks,
95
  BLOCK block[24];
John Koleszar's avatar
John Koleszar committed
96

97
98
  SUPERBLOCK sb_coeff_data;

John Koleszar's avatar
John Koleszar committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  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;

119
120
  int mv_best_ref_index[MAX_REF_FRAMES];

121
122
123
124
125
  int nmvjointcost[MV_JOINTS];
  int nmvcosts[2][MV_VALS];
  int *nmvcost[2];
  int nmvcosts_hp[2][MV_VALS];
  int *nmvcost_hp[2];
126
  int **mvcost;
127
128
129
130
131
132

  int nmvjointsadcost[MV_JOINTS];
  int nmvsadcosts[2][MV_VALS];
  int *nmvsadcost[2];
  int nmvsadcosts_hp[2][MV_VALS];
  int *nmvsadcost_hp[2];
133
  int **mvsadcost;
134

John Koleszar's avatar
John Koleszar committed
135
136
  int mbmode_cost[2][MB_MODE_COUNT];
  int intra_uv_mode_cost[2][MB_MODE_COUNT];
137
  int bmode_costs[VP9_KF_BINTRAMODES][VP9_KF_BINTRAMODES][VP9_KF_BINTRAMODES];
John Koleszar's avatar
John Koleszar committed
138
139
  int i8x8_mode_costs[MB_MODE_COUNT];
  int inter_bmode_costs[B_MODE_COUNT];
140
141
  int switchable_interp_costs[VP9_SWITCHABLE_FILTERS + 1]
                             [VP9_SWITCHABLE_FILTERS];
John Koleszar's avatar
John Koleszar committed
142

143
144
  // These define limits to motion vector components to prevent them
  // from extending outside the UMV borders
John Koleszar's avatar
John Koleszar committed
145
146
147
148
  int mv_col_min;
  int mv_col_max;
  int mv_row_min;
  int mv_row_max;
John Koleszar's avatar
John Koleszar committed
149

John Koleszar's avatar
John Koleszar committed
150
  int skip;
John Koleszar's avatar
John Koleszar committed
151

John Koleszar's avatar
John Koleszar committed
152
  int encode_breakout;
John Koleszar's avatar
John Koleszar committed
153

John Koleszar's avatar
John Koleszar committed
154
155
  // char * gf_active_ptr;
  signed char *gf_active_ptr;
156

John Koleszar's avatar
John Koleszar committed
157
  unsigned char *active_ptr;
John Koleszar's avatar
John Koleszar committed
158

159
  vp9_coeff_count token_costs[TX_SIZE_MAX_SB][BLOCK_TYPES];
160

John Koleszar's avatar
John Koleszar committed
161
  int optimize;
John Koleszar's avatar
John Koleszar committed
162

John Koleszar's avatar
John Koleszar committed
163
164
  // 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
165
  PICK_MODE_CONTEXT mb_context[4][4];
John Koleszar's avatar
John Koleszar committed
166
  // when 4 MBs share coding parameters:
Ronald S. Bultje's avatar
Ronald S. Bultje committed
167
168
  PICK_MODE_CONTEXT sb32_context[4];
  PICK_MODE_CONTEXT sb64_context;
Adrian Grange's avatar
Adrian Grange committed
169

Yaowu Xu's avatar
Yaowu Xu committed
170
171
172
173
  void (*fwd_txm4x4)(int16_t *input, int16_t *output, int pitch);
  void (*fwd_txm8x4)(int16_t *input, int16_t *output, int pitch);
  void (*fwd_txm8x8)(int16_t *input, int16_t *output, int pitch);
  void (*fwd_txm16x16)(int16_t *input, int16_t *output, int pitch);
174
175
  void (*quantize_b_4x4)(BLOCK *b, BLOCKD *d);
  void (*quantize_b_4x4_pair)(BLOCK *b1, BLOCK *b2, BLOCKD *d0, BLOCKD *d1);
Daniel Kang's avatar
Daniel Kang committed
176
  void (*quantize_b_16x16)(BLOCK *b, BLOCKD *d);
John Koleszar's avatar
John Koleszar committed
177
  void (*quantize_b_8x8)(BLOCK *b, BLOCKD *d);
John Koleszar's avatar
John Koleszar committed
178
179
} MACROBLOCK;

180
#endif  // VP9_ENCODER_VP9_BLOCK_H_