vp9_onyxc_int.h 11.1 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_COMMON_VP9_ONYXC_INT_H_
#define VP9_COMMON_VP9_ONYXC_INT_H_
John Koleszar's avatar
John Koleszar committed
13

14 15
#include "vpx_config.h"
#include "vpx/internal/vpx_codec_internal.h"
16
#include "vp9_rtcd.h"
17 18 19 20
#include "vp9/common/vp9_loopfilter.h"
#include "vp9/common/vp9_entropymv.h"
#include "vp9/common/vp9_entropy.h"
#include "vp9/common/vp9_entropymode.h"
21
#include "vp9/common/vp9_quant_common.h"
22

23
#if CONFIG_POSTPROC
24
#include "vp9/common/vp9_postproc.h"
25
#endif
John Koleszar's avatar
John Koleszar committed
26

27
/*#ifdef PACKET_TESTING*/
28
#include "vp9/common/vp9_header.h"
29
/*#endif*/
John Koleszar's avatar
John Koleszar committed
30 31 32

/* Create/destroy static data structures. */

33
void vp9_initialize_common(void);
John Koleszar's avatar
John Koleszar committed
34

35 36 37 38
#if CONFIG_MULTIPLE_ARF
#define NUM_REF_FRAMES 8
#define NUM_REF_FRAMES_LG2 3
#else
39
#define NUM_REF_FRAMES 3
40
#define NUM_REF_FRAMES_LG2 2
41
#endif
42

43 44
#define ALLOWED_REFS_PER_FRAME 3

45 46 47 48
// 1 scratch frame for the new frame, 3 for scaled references on the encoder
// TODO(jkoleszar): These 3 extra references could probably come from the
// normal reference pool.
#define NUM_YV12_BUFFERS (NUM_REF_FRAMES + 4)
John Koleszar's avatar
John Koleszar committed
49

50 51 52
#define NUM_FRAME_CONTEXTS_LG2 2
#define NUM_FRAME_CONTEXTS (1 << NUM_FRAME_CONTEXTS_LG2)

53
#define COMP_PRED_CONTEXTS   2
Paul Wilkins's avatar
Paul Wilkins committed
54

55 56
#define MAX_LAG_BUFFERS 25

John Koleszar's avatar
John Koleszar committed
57
typedef struct frame_contexts {
58 59
  vp9_prob bmode_prob[VP9_NKF_BINTRAMODES - 1];
  vp9_prob ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
60
  vp9_prob sb_ymode_prob[VP9_I32X32_MODES - 1];
61
  vp9_prob uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1];
62
#if !CONFIG_SB8X8
63
  vp9_prob i8x8_mode_prob[VP9_I8X8_MODES - 1];
64
#endif
65
  vp9_prob sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
66
#if !CONFIG_SB8X8
67
  vp9_prob mbsplit_prob[VP9_NUMMBSPLITS - 1];
68
#endif
69
  vp9_prob partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1];
70

71 72 73
  vp9_coeff_probs coef_probs_4x4[BLOCK_TYPES];
  vp9_coeff_probs coef_probs_8x8[BLOCK_TYPES];
  vp9_coeff_probs coef_probs_16x16[BLOCK_TYPES];
74
  vp9_coeff_probs coef_probs_32x32[BLOCK_TYPES];
75 76 77 78 79 80
#if CONFIG_CODE_ZEROGROUP
  vp9_zpc_probs zpc_probs_4x4;
  vp9_zpc_probs zpc_probs_8x8;
  vp9_zpc_probs zpc_probs_16x16;
  vp9_zpc_probs zpc_probs_32x32;
#endif
81

82 83
  nmv_context nmvc;
  nmv_context pre_nmvc;
84 85
  vp9_prob pre_bmode_prob[VP9_NKF_BINTRAMODES - 1];
  vp9_prob pre_ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */
86
  vp9_prob pre_sb_ymode_prob[VP9_I32X32_MODES - 1];
87
  vp9_prob pre_uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1];
88
#if !CONFIG_SB8X8
89
  vp9_prob pre_i8x8_mode_prob[VP9_I8X8_MODES - 1];
90
#endif
91
  vp9_prob pre_sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1];
92
#if !CONFIG_SB8X8
93
  vp9_prob pre_mbsplit_prob[VP9_NUMMBSPLITS - 1];
94
#endif
95
  vp9_prob pre_partition_prob[NUM_PARTITION_CONTEXTS][PARTITION_TYPES - 1];
96 97
  unsigned int bmode_counts[VP9_NKF_BINTRAMODES];
  unsigned int ymode_counts[VP9_YMODES];   /* interframe intra mode probs */
98
  unsigned int sb_ymode_counts[VP9_I32X32_MODES];
99
  unsigned int uv_mode_counts[VP9_YMODES][VP9_UV_MODES];
100
#if !CONFIG_SB8X8
101
  unsigned int i8x8_mode_counts[VP9_I8X8_MODES];   /* interframe intra probs */
102
#endif
103
  unsigned int sub_mv_ref_counts[SUBMVREF_COUNT][VP9_SUBMVREFS];
104
#if !CONFIG_SB8X8
105
  unsigned int mbsplit_counts[VP9_NUMMBSPLITS];
106
#endif
107
  unsigned int partition_counts[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
108

109 110 111
  vp9_coeff_probs pre_coef_probs_4x4[BLOCK_TYPES];
  vp9_coeff_probs pre_coef_probs_8x8[BLOCK_TYPES];
  vp9_coeff_probs pre_coef_probs_16x16[BLOCK_TYPES];
112
  vp9_coeff_probs pre_coef_probs_32x32[BLOCK_TYPES];
113 114 115 116 117 118
#if CONFIG_CODE_ZEROGROUP
  vp9_zpc_probs pre_zpc_probs_4x4;
  vp9_zpc_probs pre_zpc_probs_8x8;
  vp9_zpc_probs pre_zpc_probs_16x16;
  vp9_zpc_probs pre_zpc_probs_32x32;
#endif
119

120 121 122
  vp9_coeff_count coef_counts_4x4[BLOCK_TYPES];
  vp9_coeff_count coef_counts_8x8[BLOCK_TYPES];
  vp9_coeff_count coef_counts_16x16[BLOCK_TYPES];
123
  vp9_coeff_count coef_counts_32x32[BLOCK_TYPES];
124 125 126
  unsigned int eob_branch_counts[TX_SIZE_MAX_SB][BLOCK_TYPES][REF_TYPES]
                                [COEF_BANDS][PREV_COEF_CONTEXTS];

127 128 129 130 131 132
#if CONFIG_CODE_ZEROGROUP
  vp9_zpc_count zpc_counts_4x4;
  vp9_zpc_count zpc_counts_8x8;
  vp9_zpc_count zpc_counts_16x16;
  vp9_zpc_count zpc_counts_32x32;
#endif
133

134
  nmv_context_counts NMVcount;
135 136
  vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1]
                                 [VP9_SWITCHABLE_FILTERS - 1];
137 138 139 140 141
#if CONFIG_COMP_INTERINTRA_PRED
  unsigned int interintra_counts[2];
  vp9_prob interintra_prob;
  vp9_prob pre_interintra_prob;
#endif
142

Paul Wilkins's avatar
Paul Wilkins committed
143
  int vp9_mode_contexts[INTER_MODE_CONTEXTS][4];
Jim Bankoski's avatar
Jim Bankoski committed
144
  unsigned int mv_ref_ct[INTER_MODE_CONTEXTS][4][2];
John Koleszar's avatar
John Koleszar committed
145 146
} FRAME_CONTEXT;

John Koleszar's avatar
John Koleszar committed
147 148 149
typedef enum {
  RECON_CLAMP_REQUIRED        = 0,
  RECON_CLAMP_NOTREQUIRED     = 1
John Koleszar's avatar
John Koleszar committed
150 151
} CLAMP_TYPE;

John Koleszar's avatar
John Koleszar committed
152 153 154 155 156
typedef enum {
  SINGLE_PREDICTION_ONLY = 0,
  COMP_PREDICTION_ONLY   = 1,
  HYBRID_PREDICTION      = 2,
  NB_PREDICTION_TYPES    = 3,
157
} COMPPREDMODE_TYPE;
158

John Koleszar's avatar
John Koleszar committed
159 160
typedef enum {
  ONLY_4X4            = 0,
161 162
  ALLOW_8X8           = 1,
  ALLOW_16X16         = 2,
163
  ALLOW_32X32         = 3,
Ronald S. Bultje's avatar
Ronald S. Bultje committed
164 165
  TX_MODE_SELECT      = 4,
  NB_TXFM_MODES       = 5,
166 167
} TXFM_MODE;

168
typedef struct VP9Common {
John Koleszar's avatar
John Koleszar committed
169
  struct vpx_internal_error_info  error;
John Koleszar's avatar
John Koleszar committed
170

Dmitry Kovalev's avatar
Dmitry Kovalev committed
171 172
  DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][16]);
  DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][16]);
John Koleszar's avatar
John Koleszar committed
173

174 175
  int width;
  int height;
176 177
  int display_width;
  int display_height;
178 179
  int last_width;
  int last_height;
John Koleszar's avatar
John Koleszar committed
180

John Koleszar's avatar
John Koleszar committed
181 182
  YUV_TYPE clr_type;
  CLAMP_TYPE  clamp_type;
John Koleszar's avatar
John Koleszar committed
183

John Koleszar's avatar
John Koleszar committed
184
  YV12_BUFFER_CONFIG *frame_to_show;
185

John Koleszar's avatar
John Koleszar committed
186
  YV12_BUFFER_CONFIG yv12_fb[NUM_YV12_BUFFERS];
187
  int fb_idx_ref_cnt[NUM_YV12_BUFFERS]; /* reference counts */
188 189
  int ref_frame_map[NUM_REF_FRAMES]; /* maps fb_idx to reference slot */

190 191 192 193 194 195
  // TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and
  // roll new_fb_idx into it.

  // Each frame can reference ALLOWED_REFS_PER_FRAME buffers
  int active_ref_idx[ALLOWED_REFS_PER_FRAME];
  struct scale_factors active_ref_scale[ALLOWED_REFS_PER_FRAME];
196
  int new_fb_idx;
197

198

John Koleszar's avatar
John Koleszar committed
199 200
  YV12_BUFFER_CONFIG post_proc_buffer;
  YV12_BUFFER_CONFIG temp_scale_frame;
John Koleszar's avatar
John Koleszar committed
201

Attila Nagy's avatar
Attila Nagy committed
202

John Koleszar's avatar
John Koleszar committed
203 204
  FRAME_TYPE last_frame_type;  /* Save last frame's frame type for motion search. */
  FRAME_TYPE frame_type;
John Koleszar's avatar
John Koleszar committed
205

John Koleszar's avatar
John Koleszar committed
206
  int show_frame;
207
  int last_show_frame;
John Koleszar's avatar
John Koleszar committed
208

John Koleszar's avatar
John Koleszar committed
209
  int frame_flags;
210 211 212
  // MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in
  // MODE_INFO units (depending on CONFIG_SB8X8, that is either
  // 16-pixel or 8-pixel)
John Koleszar's avatar
John Koleszar committed
213
  int MBs;
214 215
  int mb_rows, mi_rows;
  int mb_cols, mi_cols;
John Koleszar's avatar
John Koleszar committed
216
  int mode_info_stride;
John Koleszar's avatar
John Koleszar committed
217

John Koleszar's avatar
John Koleszar committed
218 219 220 221 222 223
  /* profile settings */
  int experimental;
  TXFM_MODE txfm_mode;
  COMPPREDMODE_TYPE comp_pred_mode;
  int no_lpf;
  int use_bilinear_mc_filter;
John Koleszar's avatar
John Koleszar committed
224

John Koleszar's avatar
John Koleszar committed
225 226
  int base_qindex;
  int last_kf_gf_q;  /* Q used on the last GF or KF */
John Koleszar's avatar
John Koleszar committed
227

228 229 230
  int y_dc_delta_q;
  int uv_dc_delta_q;
  int uv_ac_delta_q;
John Koleszar's avatar
John Koleszar committed
231

John Koleszar's avatar
John Koleszar committed
232 233
  unsigned int frames_since_golden;
  unsigned int frames_till_alt_ref_frame;
John Koleszar's avatar
John Koleszar committed
234

John Koleszar's avatar
John Koleszar committed
235 236
  /* We allocate a MODE_INFO struct for each macroblock, together with
     an extra row on top and column on the left to simplify prediction. */
John Koleszar's avatar
John Koleszar committed
237

John Koleszar's avatar
John Koleszar committed
238 239 240 241
  MODE_INFO *mip; /* Base of allocated array */
  MODE_INFO *mi;  /* Corresponds to upper left visible macroblock */
  MODE_INFO *prev_mip; /* MODE_INFO array 'mip' from last decoded frame */
  MODE_INFO *prev_mi;  /* 'mi' from last frame (points into prev_mip) */
John Koleszar's avatar
John Koleszar committed
242 243


John Koleszar's avatar
John Koleszar committed
244 245
  // Persistent mb segment id map used in prediction.
  unsigned char *last_frame_seg_map;
246

John Koleszar's avatar
John Koleszar committed
247
  INTERPOLATIONFILTERTYPE mcomp_filter_type;
248
  LOOPFILTER_TYPE filter_type;
Attila Nagy's avatar
Attila Nagy committed
249

John Koleszar's avatar
John Koleszar committed
250
  loop_filter_info_n lf_info;
Attila Nagy's avatar
Attila Nagy committed
251

John Koleszar's avatar
John Koleszar committed
252 253 254
  int filter_level;
  int last_sharpness_level;
  int sharpness_level;
255
  int dering_enabled;
John Koleszar's avatar
John Koleszar committed
256

257
  int refresh_frame_context;    /* Two state 0 = NO, 1 = YES */
John Koleszar's avatar
John Koleszar committed
258

John Koleszar's avatar
John Koleszar committed
259
  int ref_frame_sign_bias[MAX_REF_FRAMES];    /* Two state 0, 1 */
John Koleszar's avatar
John Koleszar committed
260

261
  /* Y,U,V */
262 263
  ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
  ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16];
John Koleszar's avatar
John Koleszar committed
264

265 266 267 268
  // partition contexts
  PARTITION_CONTEXT *above_seg_context;
  PARTITION_CONTEXT left_seg_context[4];

John Koleszar's avatar
John Koleszar committed
269
  /* keyframe block modes are predicted by their above, left neighbors */
John Koleszar's avatar
John Koleszar committed
270

271 272 273
  vp9_prob kf_bmode_prob[VP9_KF_BINTRAMODES]
                        [VP9_KF_BINTRAMODES]
                        [VP9_KF_BINTRAMODES - 1];
274 275
  vp9_prob kf_ymode_prob[8][VP9_YMODES - 1]; /* keyframe "" */
  vp9_prob sb_kf_ymode_prob[8][VP9_I32X32_MODES - 1];
John Koleszar's avatar
John Koleszar committed
276 277
  int kf_ymode_probs_index;
  int kf_ymode_probs_update;
278
  vp9_prob kf_uv_mode_prob[VP9_YMODES] [VP9_UV_MODES - 1];
279

280 281 282
  vp9_prob prob_intra_coded;
  vp9_prob prob_last_coded;
  vp9_prob prob_gf_coded;
283

John Koleszar's avatar
John Koleszar committed
284
  // Context probabilities when using predictive coding of segment id
285
  vp9_prob segment_pred_probs[PREDICTION_PROBS];
John Koleszar's avatar
John Koleszar committed
286
  unsigned char temporal_update;
287

John Koleszar's avatar
John Koleszar committed
288 289
  // Context probabilities for reference frame prediction
  unsigned char ref_scores[MAX_REF_FRAMES];
290 291
  vp9_prob ref_pred_probs[PREDICTION_PROBS];
  vp9_prob mod_refprobs[MAX_REF_FRAMES][PREDICTION_PROBS];
John Koleszar's avatar
John Koleszar committed
292

293
  vp9_prob prob_comppred[COMP_PRED_CONTEXTS];
Paul Wilkins's avatar
Paul Wilkins committed
294

295
  // FIXME contextualize
296
  vp9_prob prob_tx[TX_SIZE_MAX_SB - 1];
297

298
  vp9_prob mbskip_pred_probs[MBSKIP_CONTEXTS];
299

John Koleszar's avatar
John Koleszar committed
300
  FRAME_CONTEXT fc;  /* this frame entropy */
301 302
  FRAME_CONTEXT frame_contexts[NUM_FRAME_CONTEXTS];
  unsigned int  frame_context_idx; /* Context to use/update */
John Koleszar's avatar
John Koleszar committed
303

John Koleszar's avatar
John Koleszar committed
304 305 306
  unsigned int current_video_frame;
  int near_boffset[3];
  int version;
John Koleszar's avatar
John Koleszar committed
307 308

#ifdef PACKET_TESTING
309
  VP9_HEADER oh;
John Koleszar's avatar
John Koleszar committed
310
#endif
John Koleszar's avatar
John Koleszar committed
311 312
  double bitrate;
  double framerate;
John Koleszar's avatar
John Koleszar committed
313

314
#if CONFIG_POSTPROC
John Koleszar's avatar
John Koleszar committed
315
  struct postproc_state  postproc_state;
316
#endif
317

318 319 320
#if CONFIG_COMP_INTERINTRA_PRED
  int use_interintra;
#endif
321

322
  int error_resilient_mode;
323
  int frame_parallel_decoding_mode;
324

325
  int tile_columns, log2_tile_columns;
326
  int cur_tile_mi_col_start, cur_tile_mi_col_end, cur_tile_col_idx;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
327
  int tile_rows, log2_tile_rows;
328
  int cur_tile_mi_row_start, cur_tile_mi_row_end, cur_tile_row_idx;
329
} VP9_COMMON;
John Koleszar's avatar
John Koleszar committed
330

331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
static int get_free_fb(VP9_COMMON *cm) {
  int i;
  for (i = 0; i < NUM_YV12_BUFFERS; i++)
    if (cm->fb_idx_ref_cnt[i] == 0)
      break;

  assert(i < NUM_YV12_BUFFERS);
  cm->fb_idx_ref_cnt[i] = 1;
  return i;
}

static void ref_cnt_fb(int *buf, int *idx, int new_idx) {
  if (buf[*idx] > 0)
    buf[*idx]--;

  *idx = new_idx;

  buf[new_idx]++;
}

351 352 353 354
static int mb_cols_aligned_to_sb(VP9_COMMON *cm) {
  return (cm->mb_cols + 3) & ~3;
}

355 356 357 358 359 360 361
static void set_mi_row_col(VP9_COMMON *cm, MACROBLOCKD *xd,
                       int mi_row, int bh,
                       int mi_col, int bw) {
  xd->mb_to_top_edge    = -((mi_row * MI_SIZE) << 3);
  xd->mb_to_bottom_edge = ((cm->mi_rows - bh - mi_row) * MI_SIZE) << 3;
  xd->mb_to_left_edge   = -((mi_col * MI_SIZE) << 3);
  xd->mb_to_right_edge  = ((cm->mi_cols - bw - mi_col) * MI_SIZE) << 3;
362 363

  // Are edges available for intra prediction?
364 365 366
  xd->up_available    = (mi_row != 0);
  xd->left_available  = (mi_col > cm->cur_tile_mi_col_start);
  xd->right_available = (mi_col + bw < cm->cur_tile_mi_col_end);
367 368
}

369 370
static int get_mi_row(const MACROBLOCKD *xd) {
  return ((-xd->mb_to_top_edge) >> (3 + LOG2_MI_SIZE));
371 372
}

373 374
static int get_mi_col(const MACROBLOCKD *xd) {
  return ((-xd->mb_to_left_edge) >> (3 + LOG2_MI_SIZE));
375
}
376 377

static int get_token_alloc(int mb_rows, int mb_cols) {
378 379 380
#if CONFIG_CODE_ZEROGROUP
  return mb_rows * mb_cols * (24 * 16 * 2);
#else
381
  return mb_rows * mb_cols * (24 * 16 + 4);
382
#endif
383
}
384
#endif  // VP9_COMMON_VP9_ONYXC_INT_H_