vp9_block.h 4.93 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
87
typedef struct macroblock MACROBLOCK;
struct macroblock {
88
89
  DECLARE_ALIGNED(16, int16_t, src_diff[64*64+32*32*2]);
  DECLARE_ALIGNED(16, int16_t, coeff[64*64+32*32*2]);
John Koleszar's avatar
John Koleszar committed
90
  // 16 Y blocks, 4 U blocks, 4 V blocks,
91
  BLOCK block[24];
John Koleszar's avatar
John Koleszar committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

  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;

113
114
  int mv_best_ref_index[MAX_REF_FRAMES];

115
116
117
118
119
  int nmvjointcost[MV_JOINTS];
  int nmvcosts[2][MV_VALS];
  int *nmvcost[2];
  int nmvcosts_hp[2][MV_VALS];
  int *nmvcost_hp[2];
120
  int **mvcost;
121
122
123
124
125
126

  int nmvjointsadcost[MV_JOINTS];
  int nmvsadcosts[2][MV_VALS];
  int *nmvsadcost[2];
  int nmvsadcosts_hp[2][MV_VALS];
  int *nmvsadcost_hp[2];
127
  int **mvsadcost;
128

John Koleszar's avatar
John Koleszar committed
129
130
  int mbmode_cost[2][MB_MODE_COUNT];
  int intra_uv_mode_cost[2][MB_MODE_COUNT];
131
  int bmode_costs[VP9_KF_BINTRAMODES][VP9_KF_BINTRAMODES][VP9_KF_BINTRAMODES];
John Koleszar's avatar
John Koleszar committed
132
133
  int i8x8_mode_costs[MB_MODE_COUNT];
  int inter_bmode_costs[B_MODE_COUNT];
134
135
  int switchable_interp_costs[VP9_SWITCHABLE_FILTERS + 1]
                             [VP9_SWITCHABLE_FILTERS];
John Koleszar's avatar
John Koleszar committed
136

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

John Koleszar's avatar
John Koleszar committed
144
  int skip;
John Koleszar's avatar
John Koleszar committed
145

John Koleszar's avatar
John Koleszar committed
146
  int encode_breakout;
John Koleszar's avatar
John Koleszar committed
147

John Koleszar's avatar
John Koleszar committed
148
149
  // char * gf_active_ptr;
  signed char *gf_active_ptr;
150

John Koleszar's avatar
John Koleszar committed
151
  unsigned char *active_ptr;
John Koleszar's avatar
John Koleszar committed
152

153
  vp9_coeff_count token_costs[TX_SIZE_MAX_SB][BLOCK_TYPES];
154
155
156
157
158
159
#if CONFIG_CODE_NONZEROCOUNT
  unsigned int nzc_costs_4x4[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][17];
  unsigned int nzc_costs_8x8[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][65];
  unsigned int nzc_costs_16x16[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][257];
  unsigned int nzc_costs_32x32[MAX_NZC_CONTEXTS][REF_TYPES][BLOCK_TYPES][1025];
#endif
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)(MACROBLOCK *x, int b_idx);
  void (*quantize_b_4x4_pair)(MACROBLOCK *x, int b_idx1, int b_idx2);
176
177
  void (*quantize_b_16x16)(MACROBLOCK *x, int b_idx, TX_TYPE tx_type);
  void (*quantize_b_8x8)(MACROBLOCK *x, int b_idx, TX_TYPE tx_type);
178
};
John Koleszar's avatar
John Koleszar committed
179

180
#endif  // VP9_ENCODER_VP9_BLOCK_H_