media/libvpx/vp9/common/vp9_onyxc_int.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license
michael@0 5 * that can be found in the LICENSE file in the root of the source
michael@0 6 * tree. An additional intellectual property rights grant can be found
michael@0 7 * in the file PATENTS. All contributing project authors may
michael@0 8 * be found in the AUTHORS file in the root of the source tree.
michael@0 9 */
michael@0 10
michael@0 11 #ifndef VP9_COMMON_VP9_ONYXC_INT_H_
michael@0 12 #define VP9_COMMON_VP9_ONYXC_INT_H_
michael@0 13
michael@0 14 #include "./vpx_config.h"
michael@0 15 #include "vpx/internal/vpx_codec_internal.h"
michael@0 16 #include "./vp9_rtcd.h"
michael@0 17 #include "vp9/common/vp9_loopfilter.h"
michael@0 18 #include "vp9/common/vp9_entropymv.h"
michael@0 19 #include "vp9/common/vp9_entropy.h"
michael@0 20 #include "vp9/common/vp9_entropymode.h"
michael@0 21 #include "vp9/common/vp9_quant_common.h"
michael@0 22 #include "vp9/common/vp9_tile_common.h"
michael@0 23
michael@0 24 #if CONFIG_VP9_POSTPROC
michael@0 25 #include "vp9/common/vp9_postproc.h"
michael@0 26 #endif
michael@0 27
michael@0 28 #define ALLOWED_REFS_PER_FRAME 3
michael@0 29
michael@0 30 #define NUM_REF_FRAMES_LOG2 3
michael@0 31 #define NUM_REF_FRAMES (1 << NUM_REF_FRAMES_LOG2)
michael@0 32
michael@0 33 // 1 scratch frame for the new frame, 3 for scaled references on the encoder
michael@0 34 // TODO(jkoleszar): These 3 extra references could probably come from the
michael@0 35 // normal reference pool.
michael@0 36 #define NUM_YV12_BUFFERS (NUM_REF_FRAMES + 4)
michael@0 37
michael@0 38 #define NUM_FRAME_CONTEXTS_LOG2 2
michael@0 39 #define NUM_FRAME_CONTEXTS (1 << NUM_FRAME_CONTEXTS_LOG2)
michael@0 40
michael@0 41 typedef struct frame_contexts {
michael@0 42 vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1];
michael@0 43 vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1];
michael@0 44 vp9_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1];
michael@0 45 vp9_coeff_probs_model coef_probs[TX_SIZES][BLOCK_TYPES];
michael@0 46 vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS]
michael@0 47 [SWITCHABLE_FILTERS - 1];
michael@0 48 vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1];
michael@0 49 vp9_prob intra_inter_prob[INTRA_INTER_CONTEXTS];
michael@0 50 vp9_prob comp_inter_prob[COMP_INTER_CONTEXTS];
michael@0 51 vp9_prob single_ref_prob[REF_CONTEXTS][2];
michael@0 52 vp9_prob comp_ref_prob[REF_CONTEXTS];
michael@0 53 struct tx_probs tx_probs;
michael@0 54 vp9_prob mbskip_probs[MBSKIP_CONTEXTS];
michael@0 55 nmv_context nmvc;
michael@0 56 } FRAME_CONTEXT;
michael@0 57
michael@0 58 typedef struct {
michael@0 59 unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES];
michael@0 60 unsigned int uv_mode[INTRA_MODES][INTRA_MODES];
michael@0 61 unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES];
michael@0 62 vp9_coeff_count_model coef[TX_SIZES][BLOCK_TYPES];
michael@0 63 unsigned int eob_branch[TX_SIZES][BLOCK_TYPES][REF_TYPES]
michael@0 64 [COEF_BANDS][PREV_COEF_CONTEXTS];
michael@0 65 unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS]
michael@0 66 [SWITCHABLE_FILTERS];
michael@0 67 unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES];
michael@0 68 unsigned int intra_inter[INTRA_INTER_CONTEXTS][2];
michael@0 69 unsigned int comp_inter[COMP_INTER_CONTEXTS][2];
michael@0 70 unsigned int single_ref[REF_CONTEXTS][2][2];
michael@0 71 unsigned int comp_ref[REF_CONTEXTS][2];
michael@0 72 struct tx_counts tx;
michael@0 73 unsigned int mbskip[MBSKIP_CONTEXTS][2];
michael@0 74 nmv_context_counts mv;
michael@0 75 } FRAME_COUNTS;
michael@0 76
michael@0 77
michael@0 78 typedef enum {
michael@0 79 SINGLE_PREDICTION_ONLY = 0,
michael@0 80 COMP_PREDICTION_ONLY = 1,
michael@0 81 HYBRID_PREDICTION = 2,
michael@0 82 NB_PREDICTION_TYPES = 3,
michael@0 83 } COMPPREDMODE_TYPE;
michael@0 84
michael@0 85 typedef struct VP9Common {
michael@0 86 struct vpx_internal_error_info error;
michael@0 87
michael@0 88 DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
michael@0 89 DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
michael@0 90 #if CONFIG_ALPHA
michael@0 91 DECLARE_ALIGNED(16, int16_t, a_dequant[QINDEX_RANGE][8]);
michael@0 92 #endif
michael@0 93
michael@0 94 COLOR_SPACE color_space;
michael@0 95
michael@0 96 int width;
michael@0 97 int height;
michael@0 98 int display_width;
michael@0 99 int display_height;
michael@0 100 int last_width;
michael@0 101 int last_height;
michael@0 102
michael@0 103 // TODO(jkoleszar): this implies chroma ss right now, but could vary per
michael@0 104 // plane. Revisit as part of the future change to YV12_BUFFER_CONFIG to
michael@0 105 // support additional planes.
michael@0 106 int subsampling_x;
michael@0 107 int subsampling_y;
michael@0 108
michael@0 109 YV12_BUFFER_CONFIG *frame_to_show;
michael@0 110
michael@0 111 YV12_BUFFER_CONFIG yv12_fb[NUM_YV12_BUFFERS];
michael@0 112 int fb_idx_ref_cnt[NUM_YV12_BUFFERS]; /* reference counts */
michael@0 113 int ref_frame_map[NUM_REF_FRAMES]; /* maps fb_idx to reference slot */
michael@0 114
michael@0 115 // TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and
michael@0 116 // roll new_fb_idx into it.
michael@0 117
michael@0 118 // Each frame can reference ALLOWED_REFS_PER_FRAME buffers
michael@0 119 int active_ref_idx[ALLOWED_REFS_PER_FRAME];
michael@0 120 struct scale_factors active_ref_scale[ALLOWED_REFS_PER_FRAME];
michael@0 121 struct scale_factors_common active_ref_scale_comm[ALLOWED_REFS_PER_FRAME];
michael@0 122 int new_fb_idx;
michael@0 123
michael@0 124 YV12_BUFFER_CONFIG post_proc_buffer;
michael@0 125
michael@0 126 FRAME_TYPE last_frame_type; /* last frame's frame type for motion search.*/
michael@0 127 FRAME_TYPE frame_type;
michael@0 128
michael@0 129 int show_frame;
michael@0 130 int last_show_frame;
michael@0 131
michael@0 132 // Flag signaling that the frame is encoded using only INTRA modes.
michael@0 133 int intra_only;
michael@0 134
michael@0 135 int allow_high_precision_mv;
michael@0 136
michael@0 137 // Flag signaling that the frame context should be reset to default values.
michael@0 138 // 0 or 1 implies don't reset, 2 reset just the context specified in the
michael@0 139 // frame header, 3 reset all contexts.
michael@0 140 int reset_frame_context;
michael@0 141
michael@0 142 int frame_flags;
michael@0 143 // MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in
michael@0 144 // MODE_INFO (8-pixel) units.
michael@0 145 int MBs;
michael@0 146 int mb_rows, mi_rows;
michael@0 147 int mb_cols, mi_cols;
michael@0 148 int mode_info_stride;
michael@0 149
michael@0 150 /* profile settings */
michael@0 151 TX_MODE tx_mode;
michael@0 152
michael@0 153 int base_qindex;
michael@0 154 int y_dc_delta_q;
michael@0 155 int uv_dc_delta_q;
michael@0 156 int uv_ac_delta_q;
michael@0 157 #if CONFIG_ALPHA
michael@0 158 int a_dc_delta_q;
michael@0 159 int a_ac_delta_q;
michael@0 160 #endif
michael@0 161
michael@0 162 /* We allocate a MODE_INFO struct for each macroblock, together with
michael@0 163 an extra row on top and column on the left to simplify prediction. */
michael@0 164
michael@0 165 MODE_INFO *mip; /* Base of allocated array */
michael@0 166 MODE_INFO *mi; /* Corresponds to upper left visible macroblock */
michael@0 167 MODE_INFO *prev_mip; /* MODE_INFO array 'mip' from last decoded frame */
michael@0 168 MODE_INFO *prev_mi; /* 'mi' from last frame (points into prev_mip) */
michael@0 169
michael@0 170 MODE_INFO **mi_grid_base;
michael@0 171 MODE_INFO **mi_grid_visible;
michael@0 172 MODE_INFO **prev_mi_grid_base;
michael@0 173 MODE_INFO **prev_mi_grid_visible;
michael@0 174
michael@0 175 // Persistent mb segment id map used in prediction.
michael@0 176 unsigned char *last_frame_seg_map;
michael@0 177
michael@0 178 INTERPOLATION_TYPE mcomp_filter_type;
michael@0 179
michael@0 180 loop_filter_info_n lf_info;
michael@0 181
michael@0 182 int refresh_frame_context; /* Two state 0 = NO, 1 = YES */
michael@0 183
michael@0 184 int ref_frame_sign_bias[MAX_REF_FRAMES]; /* Two state 0, 1 */
michael@0 185
michael@0 186 struct loopfilter lf;
michael@0 187 struct segmentation seg;
michael@0 188
michael@0 189 // Context probabilities for reference frame prediction
michael@0 190 int allow_comp_inter_inter;
michael@0 191 MV_REFERENCE_FRAME comp_fixed_ref;
michael@0 192 MV_REFERENCE_FRAME comp_var_ref[2];
michael@0 193 COMPPREDMODE_TYPE comp_pred_mode;
michael@0 194
michael@0 195 FRAME_CONTEXT fc; /* this frame entropy */
michael@0 196 FRAME_CONTEXT frame_contexts[NUM_FRAME_CONTEXTS];
michael@0 197 unsigned int frame_context_idx; /* Context to use/update */
michael@0 198 FRAME_COUNTS counts;
michael@0 199
michael@0 200 unsigned int current_video_frame;
michael@0 201 int version;
michael@0 202
michael@0 203 #if CONFIG_VP9_POSTPROC
michael@0 204 struct postproc_state postproc_state;
michael@0 205 #endif
michael@0 206
michael@0 207 int error_resilient_mode;
michael@0 208 int frame_parallel_decoding_mode;
michael@0 209
michael@0 210 int log2_tile_cols, log2_tile_rows;
michael@0 211 } VP9_COMMON;
michael@0 212
michael@0 213 // ref == 0 => LAST_FRAME
michael@0 214 // ref == 1 => GOLDEN_FRAME
michael@0 215 // ref == 2 => ALTREF_FRAME
michael@0 216 static YV12_BUFFER_CONFIG *get_frame_ref_buffer(VP9_COMMON *cm, int ref) {
michael@0 217 return &cm->yv12_fb[cm->active_ref_idx[ref]];
michael@0 218 }
michael@0 219
michael@0 220 static YV12_BUFFER_CONFIG *get_frame_new_buffer(VP9_COMMON *cm) {
michael@0 221 return &cm->yv12_fb[cm->new_fb_idx];
michael@0 222 }
michael@0 223
michael@0 224 static int get_free_fb(VP9_COMMON *cm) {
michael@0 225 int i;
michael@0 226 for (i = 0; i < NUM_YV12_BUFFERS; i++)
michael@0 227 if (cm->fb_idx_ref_cnt[i] == 0)
michael@0 228 break;
michael@0 229
michael@0 230 assert(i < NUM_YV12_BUFFERS);
michael@0 231 cm->fb_idx_ref_cnt[i] = 1;
michael@0 232 return i;
michael@0 233 }
michael@0 234
michael@0 235 static void ref_cnt_fb(int *buf, int *idx, int new_idx) {
michael@0 236 if (buf[*idx] > 0)
michael@0 237 buf[*idx]--;
michael@0 238
michael@0 239 *idx = new_idx;
michael@0 240
michael@0 241 buf[new_idx]++;
michael@0 242 }
michael@0 243
michael@0 244 static int mi_cols_aligned_to_sb(int n_mis) {
michael@0 245 return ALIGN_POWER_OF_TWO(n_mis, MI_BLOCK_SIZE_LOG2);
michael@0 246 }
michael@0 247
michael@0 248 static INLINE const vp9_prob* get_partition_probs(VP9_COMMON *cm, int ctx) {
michael@0 249 return cm->frame_type == KEY_FRAME ? vp9_kf_partition_probs[ctx]
michael@0 250 : cm->fc.partition_prob[ctx];
michael@0 251 }
michael@0 252
michael@0 253 static INLINE void set_skip_context(
michael@0 254 MACROBLOCKD *xd,
michael@0 255 ENTROPY_CONTEXT *above_context[MAX_MB_PLANE],
michael@0 256 ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16],
michael@0 257 int mi_row, int mi_col) {
michael@0 258 const int above_idx = mi_col * 2;
michael@0 259 const int left_idx = (mi_row * 2) & 15;
michael@0 260 int i;
michael@0 261 for (i = 0; i < MAX_MB_PLANE; i++) {
michael@0 262 struct macroblockd_plane *const pd = &xd->plane[i];
michael@0 263 pd->above_context = above_context[i] + (above_idx >> pd->subsampling_x);
michael@0 264 pd->left_context = left_context[i] + (left_idx >> pd->subsampling_y);
michael@0 265 }
michael@0 266 }
michael@0 267
michael@0 268 static void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile,
michael@0 269 int mi_row, int bh,
michael@0 270 int mi_col, int bw,
michael@0 271 int mi_rows, int mi_cols) {
michael@0 272 xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8);
michael@0 273 xd->mb_to_bottom_edge = ((mi_rows - bh - mi_row) * MI_SIZE) * 8;
michael@0 274 xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8);
michael@0 275 xd->mb_to_right_edge = ((mi_cols - bw - mi_col) * MI_SIZE) * 8;
michael@0 276
michael@0 277 // Are edges available for intra prediction?
michael@0 278 xd->up_available = (mi_row != 0);
michael@0 279 xd->left_available = (mi_col > tile->mi_col_start);
michael@0 280 }
michael@0 281
michael@0 282 static void set_prev_mi(VP9_COMMON *cm) {
michael@0 283 const int use_prev_in_find_mv_refs = cm->width == cm->last_width &&
michael@0 284 cm->height == cm->last_height &&
michael@0 285 !cm->error_resilient_mode &&
michael@0 286 !cm->intra_only &&
michael@0 287 cm->last_show_frame;
michael@0 288 // Special case: set prev_mi to NULL when the previous mode info
michael@0 289 // context cannot be used.
michael@0 290 cm->prev_mi = use_prev_in_find_mv_refs ?
michael@0 291 cm->prev_mip + cm->mode_info_stride + 1 : NULL;
michael@0 292 }
michael@0 293
michael@0 294 static INLINE int frame_is_intra_only(const VP9_COMMON *const cm) {
michael@0 295 return cm->frame_type == KEY_FRAME || cm->intra_only;
michael@0 296 }
michael@0 297
michael@0 298 static INLINE void update_partition_context(
michael@0 299 PARTITION_CONTEXT *above_seg_context,
michael@0 300 PARTITION_CONTEXT left_seg_context[8],
michael@0 301 int mi_row, int mi_col,
michael@0 302 BLOCK_SIZE sb_type,
michael@0 303 BLOCK_SIZE sb_size) {
michael@0 304 PARTITION_CONTEXT *above_ctx = above_seg_context + mi_col;
michael@0 305 PARTITION_CONTEXT *left_ctx = left_seg_context + (mi_row & MI_MASK);
michael@0 306
michael@0 307 const int bsl = b_width_log2(sb_size), bs = (1 << bsl) / 2;
michael@0 308 const int bwl = b_width_log2(sb_type);
michael@0 309 const int bhl = b_height_log2(sb_type);
michael@0 310 const int boffset = b_width_log2(BLOCK_64X64) - bsl;
michael@0 311 const char pcval0 = ~(0xe << boffset);
michael@0 312 const char pcval1 = ~(0xf << boffset);
michael@0 313 const char pcvalue[2] = {pcval0, pcval1};
michael@0 314
michael@0 315 assert(MAX(bwl, bhl) <= bsl);
michael@0 316
michael@0 317 // update the partition context at the end notes. set partition bits
michael@0 318 // of block sizes larger than the current one to be one, and partition
michael@0 319 // bits of smaller block sizes to be zero.
michael@0 320 vpx_memset(above_ctx, pcvalue[bwl == bsl], bs);
michael@0 321 vpx_memset(left_ctx, pcvalue[bhl == bsl], bs);
michael@0 322 }
michael@0 323
michael@0 324 static INLINE int partition_plane_context(
michael@0 325 const PARTITION_CONTEXT *above_seg_context,
michael@0 326 const PARTITION_CONTEXT left_seg_context[8],
michael@0 327 int mi_row, int mi_col,
michael@0 328 BLOCK_SIZE sb_type) {
michael@0 329 const PARTITION_CONTEXT *above_ctx = above_seg_context + mi_col;
michael@0 330 const PARTITION_CONTEXT *left_ctx = left_seg_context + (mi_row & MI_MASK);
michael@0 331
michael@0 332 int bsl = mi_width_log2(sb_type), bs = 1 << bsl;
michael@0 333 int above = 0, left = 0, i;
michael@0 334 int boffset = mi_width_log2(BLOCK_64X64) - bsl;
michael@0 335
michael@0 336 assert(mi_width_log2(sb_type) == mi_height_log2(sb_type));
michael@0 337 assert(bsl >= 0);
michael@0 338 assert(boffset >= 0);
michael@0 339
michael@0 340 for (i = 0; i < bs; i++) {
michael@0 341 above |= above_ctx[i];
michael@0 342 left |= left_ctx[i];
michael@0 343 }
michael@0 344 above = (above & (1 << boffset)) > 0;
michael@0 345 left = (left & (1 << boffset)) > 0;
michael@0 346
michael@0 347 return (left * 2 + above) + bsl * PARTITION_PLOFFSET;
michael@0 348 }
michael@0 349
michael@0 350 #endif // VP9_COMMON_VP9_ONYXC_INT_H_

mercurial