1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_onyxc_int.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,350 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#ifndef VP9_COMMON_VP9_ONYXC_INT_H_ 1.15 +#define VP9_COMMON_VP9_ONYXC_INT_H_ 1.16 + 1.17 +#include "./vpx_config.h" 1.18 +#include "vpx/internal/vpx_codec_internal.h" 1.19 +#include "./vp9_rtcd.h" 1.20 +#include "vp9/common/vp9_loopfilter.h" 1.21 +#include "vp9/common/vp9_entropymv.h" 1.22 +#include "vp9/common/vp9_entropy.h" 1.23 +#include "vp9/common/vp9_entropymode.h" 1.24 +#include "vp9/common/vp9_quant_common.h" 1.25 +#include "vp9/common/vp9_tile_common.h" 1.26 + 1.27 +#if CONFIG_VP9_POSTPROC 1.28 +#include "vp9/common/vp9_postproc.h" 1.29 +#endif 1.30 + 1.31 +#define ALLOWED_REFS_PER_FRAME 3 1.32 + 1.33 +#define NUM_REF_FRAMES_LOG2 3 1.34 +#define NUM_REF_FRAMES (1 << NUM_REF_FRAMES_LOG2) 1.35 + 1.36 +// 1 scratch frame for the new frame, 3 for scaled references on the encoder 1.37 +// TODO(jkoleszar): These 3 extra references could probably come from the 1.38 +// normal reference pool. 1.39 +#define NUM_YV12_BUFFERS (NUM_REF_FRAMES + 4) 1.40 + 1.41 +#define NUM_FRAME_CONTEXTS_LOG2 2 1.42 +#define NUM_FRAME_CONTEXTS (1 << NUM_FRAME_CONTEXTS_LOG2) 1.43 + 1.44 +typedef struct frame_contexts { 1.45 + vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1]; 1.46 + vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1]; 1.47 + vp9_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1]; 1.48 + vp9_coeff_probs_model coef_probs[TX_SIZES][BLOCK_TYPES]; 1.49 + vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS] 1.50 + [SWITCHABLE_FILTERS - 1]; 1.51 + vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1]; 1.52 + vp9_prob intra_inter_prob[INTRA_INTER_CONTEXTS]; 1.53 + vp9_prob comp_inter_prob[COMP_INTER_CONTEXTS]; 1.54 + vp9_prob single_ref_prob[REF_CONTEXTS][2]; 1.55 + vp9_prob comp_ref_prob[REF_CONTEXTS]; 1.56 + struct tx_probs tx_probs; 1.57 + vp9_prob mbskip_probs[MBSKIP_CONTEXTS]; 1.58 + nmv_context nmvc; 1.59 +} FRAME_CONTEXT; 1.60 + 1.61 +typedef struct { 1.62 + unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES]; 1.63 + unsigned int uv_mode[INTRA_MODES][INTRA_MODES]; 1.64 + unsigned int partition[PARTITION_CONTEXTS][PARTITION_TYPES]; 1.65 + vp9_coeff_count_model coef[TX_SIZES][BLOCK_TYPES]; 1.66 + unsigned int eob_branch[TX_SIZES][BLOCK_TYPES][REF_TYPES] 1.67 + [COEF_BANDS][PREV_COEF_CONTEXTS]; 1.68 + unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS] 1.69 + [SWITCHABLE_FILTERS]; 1.70 + unsigned int inter_mode[INTER_MODE_CONTEXTS][INTER_MODES]; 1.71 + unsigned int intra_inter[INTRA_INTER_CONTEXTS][2]; 1.72 + unsigned int comp_inter[COMP_INTER_CONTEXTS][2]; 1.73 + unsigned int single_ref[REF_CONTEXTS][2][2]; 1.74 + unsigned int comp_ref[REF_CONTEXTS][2]; 1.75 + struct tx_counts tx; 1.76 + unsigned int mbskip[MBSKIP_CONTEXTS][2]; 1.77 + nmv_context_counts mv; 1.78 +} FRAME_COUNTS; 1.79 + 1.80 + 1.81 +typedef enum { 1.82 + SINGLE_PREDICTION_ONLY = 0, 1.83 + COMP_PREDICTION_ONLY = 1, 1.84 + HYBRID_PREDICTION = 2, 1.85 + NB_PREDICTION_TYPES = 3, 1.86 +} COMPPREDMODE_TYPE; 1.87 + 1.88 +typedef struct VP9Common { 1.89 + struct vpx_internal_error_info error; 1.90 + 1.91 + DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]); 1.92 + DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]); 1.93 +#if CONFIG_ALPHA 1.94 + DECLARE_ALIGNED(16, int16_t, a_dequant[QINDEX_RANGE][8]); 1.95 +#endif 1.96 + 1.97 + COLOR_SPACE color_space; 1.98 + 1.99 + int width; 1.100 + int height; 1.101 + int display_width; 1.102 + int display_height; 1.103 + int last_width; 1.104 + int last_height; 1.105 + 1.106 + // TODO(jkoleszar): this implies chroma ss right now, but could vary per 1.107 + // plane. Revisit as part of the future change to YV12_BUFFER_CONFIG to 1.108 + // support additional planes. 1.109 + int subsampling_x; 1.110 + int subsampling_y; 1.111 + 1.112 + YV12_BUFFER_CONFIG *frame_to_show; 1.113 + 1.114 + YV12_BUFFER_CONFIG yv12_fb[NUM_YV12_BUFFERS]; 1.115 + int fb_idx_ref_cnt[NUM_YV12_BUFFERS]; /* reference counts */ 1.116 + int ref_frame_map[NUM_REF_FRAMES]; /* maps fb_idx to reference slot */ 1.117 + 1.118 + // TODO(jkoleszar): could expand active_ref_idx to 4, with 0 as intra, and 1.119 + // roll new_fb_idx into it. 1.120 + 1.121 + // Each frame can reference ALLOWED_REFS_PER_FRAME buffers 1.122 + int active_ref_idx[ALLOWED_REFS_PER_FRAME]; 1.123 + struct scale_factors active_ref_scale[ALLOWED_REFS_PER_FRAME]; 1.124 + struct scale_factors_common active_ref_scale_comm[ALLOWED_REFS_PER_FRAME]; 1.125 + int new_fb_idx; 1.126 + 1.127 + YV12_BUFFER_CONFIG post_proc_buffer; 1.128 + 1.129 + FRAME_TYPE last_frame_type; /* last frame's frame type for motion search.*/ 1.130 + FRAME_TYPE frame_type; 1.131 + 1.132 + int show_frame; 1.133 + int last_show_frame; 1.134 + 1.135 + // Flag signaling that the frame is encoded using only INTRA modes. 1.136 + int intra_only; 1.137 + 1.138 + int allow_high_precision_mv; 1.139 + 1.140 + // Flag signaling that the frame context should be reset to default values. 1.141 + // 0 or 1 implies don't reset, 2 reset just the context specified in the 1.142 + // frame header, 3 reset all contexts. 1.143 + int reset_frame_context; 1.144 + 1.145 + int frame_flags; 1.146 + // MBs, mb_rows/cols is in 16-pixel units; mi_rows/cols is in 1.147 + // MODE_INFO (8-pixel) units. 1.148 + int MBs; 1.149 + int mb_rows, mi_rows; 1.150 + int mb_cols, mi_cols; 1.151 + int mode_info_stride; 1.152 + 1.153 + /* profile settings */ 1.154 + TX_MODE tx_mode; 1.155 + 1.156 + int base_qindex; 1.157 + int y_dc_delta_q; 1.158 + int uv_dc_delta_q; 1.159 + int uv_ac_delta_q; 1.160 +#if CONFIG_ALPHA 1.161 + int a_dc_delta_q; 1.162 + int a_ac_delta_q; 1.163 +#endif 1.164 + 1.165 + /* We allocate a MODE_INFO struct for each macroblock, together with 1.166 + an extra row on top and column on the left to simplify prediction. */ 1.167 + 1.168 + MODE_INFO *mip; /* Base of allocated array */ 1.169 + MODE_INFO *mi; /* Corresponds to upper left visible macroblock */ 1.170 + MODE_INFO *prev_mip; /* MODE_INFO array 'mip' from last decoded frame */ 1.171 + MODE_INFO *prev_mi; /* 'mi' from last frame (points into prev_mip) */ 1.172 + 1.173 + MODE_INFO **mi_grid_base; 1.174 + MODE_INFO **mi_grid_visible; 1.175 + MODE_INFO **prev_mi_grid_base; 1.176 + MODE_INFO **prev_mi_grid_visible; 1.177 + 1.178 + // Persistent mb segment id map used in prediction. 1.179 + unsigned char *last_frame_seg_map; 1.180 + 1.181 + INTERPOLATION_TYPE mcomp_filter_type; 1.182 + 1.183 + loop_filter_info_n lf_info; 1.184 + 1.185 + int refresh_frame_context; /* Two state 0 = NO, 1 = YES */ 1.186 + 1.187 + int ref_frame_sign_bias[MAX_REF_FRAMES]; /* Two state 0, 1 */ 1.188 + 1.189 + struct loopfilter lf; 1.190 + struct segmentation seg; 1.191 + 1.192 + // Context probabilities for reference frame prediction 1.193 + int allow_comp_inter_inter; 1.194 + MV_REFERENCE_FRAME comp_fixed_ref; 1.195 + MV_REFERENCE_FRAME comp_var_ref[2]; 1.196 + COMPPREDMODE_TYPE comp_pred_mode; 1.197 + 1.198 + FRAME_CONTEXT fc; /* this frame entropy */ 1.199 + FRAME_CONTEXT frame_contexts[NUM_FRAME_CONTEXTS]; 1.200 + unsigned int frame_context_idx; /* Context to use/update */ 1.201 + FRAME_COUNTS counts; 1.202 + 1.203 + unsigned int current_video_frame; 1.204 + int version; 1.205 + 1.206 +#if CONFIG_VP9_POSTPROC 1.207 + struct postproc_state postproc_state; 1.208 +#endif 1.209 + 1.210 + int error_resilient_mode; 1.211 + int frame_parallel_decoding_mode; 1.212 + 1.213 + int log2_tile_cols, log2_tile_rows; 1.214 +} VP9_COMMON; 1.215 + 1.216 +// ref == 0 => LAST_FRAME 1.217 +// ref == 1 => GOLDEN_FRAME 1.218 +// ref == 2 => ALTREF_FRAME 1.219 +static YV12_BUFFER_CONFIG *get_frame_ref_buffer(VP9_COMMON *cm, int ref) { 1.220 + return &cm->yv12_fb[cm->active_ref_idx[ref]]; 1.221 +} 1.222 + 1.223 +static YV12_BUFFER_CONFIG *get_frame_new_buffer(VP9_COMMON *cm) { 1.224 + return &cm->yv12_fb[cm->new_fb_idx]; 1.225 +} 1.226 + 1.227 +static int get_free_fb(VP9_COMMON *cm) { 1.228 + int i; 1.229 + for (i = 0; i < NUM_YV12_BUFFERS; i++) 1.230 + if (cm->fb_idx_ref_cnt[i] == 0) 1.231 + break; 1.232 + 1.233 + assert(i < NUM_YV12_BUFFERS); 1.234 + cm->fb_idx_ref_cnt[i] = 1; 1.235 + return i; 1.236 +} 1.237 + 1.238 +static void ref_cnt_fb(int *buf, int *idx, int new_idx) { 1.239 + if (buf[*idx] > 0) 1.240 + buf[*idx]--; 1.241 + 1.242 + *idx = new_idx; 1.243 + 1.244 + buf[new_idx]++; 1.245 +} 1.246 + 1.247 +static int mi_cols_aligned_to_sb(int n_mis) { 1.248 + return ALIGN_POWER_OF_TWO(n_mis, MI_BLOCK_SIZE_LOG2); 1.249 +} 1.250 + 1.251 +static INLINE const vp9_prob* get_partition_probs(VP9_COMMON *cm, int ctx) { 1.252 + return cm->frame_type == KEY_FRAME ? vp9_kf_partition_probs[ctx] 1.253 + : cm->fc.partition_prob[ctx]; 1.254 +} 1.255 + 1.256 +static INLINE void set_skip_context( 1.257 + MACROBLOCKD *xd, 1.258 + ENTROPY_CONTEXT *above_context[MAX_MB_PLANE], 1.259 + ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16], 1.260 + int mi_row, int mi_col) { 1.261 + const int above_idx = mi_col * 2; 1.262 + const int left_idx = (mi_row * 2) & 15; 1.263 + int i; 1.264 + for (i = 0; i < MAX_MB_PLANE; i++) { 1.265 + struct macroblockd_plane *const pd = &xd->plane[i]; 1.266 + pd->above_context = above_context[i] + (above_idx >> pd->subsampling_x); 1.267 + pd->left_context = left_context[i] + (left_idx >> pd->subsampling_y); 1.268 + } 1.269 +} 1.270 + 1.271 +static void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile, 1.272 + int mi_row, int bh, 1.273 + int mi_col, int bw, 1.274 + int mi_rows, int mi_cols) { 1.275 + xd->mb_to_top_edge = -((mi_row * MI_SIZE) * 8); 1.276 + xd->mb_to_bottom_edge = ((mi_rows - bh - mi_row) * MI_SIZE) * 8; 1.277 + xd->mb_to_left_edge = -((mi_col * MI_SIZE) * 8); 1.278 + xd->mb_to_right_edge = ((mi_cols - bw - mi_col) * MI_SIZE) * 8; 1.279 + 1.280 + // Are edges available for intra prediction? 1.281 + xd->up_available = (mi_row != 0); 1.282 + xd->left_available = (mi_col > tile->mi_col_start); 1.283 +} 1.284 + 1.285 +static void set_prev_mi(VP9_COMMON *cm) { 1.286 + const int use_prev_in_find_mv_refs = cm->width == cm->last_width && 1.287 + cm->height == cm->last_height && 1.288 + !cm->error_resilient_mode && 1.289 + !cm->intra_only && 1.290 + cm->last_show_frame; 1.291 + // Special case: set prev_mi to NULL when the previous mode info 1.292 + // context cannot be used. 1.293 + cm->prev_mi = use_prev_in_find_mv_refs ? 1.294 + cm->prev_mip + cm->mode_info_stride + 1 : NULL; 1.295 +} 1.296 + 1.297 +static INLINE int frame_is_intra_only(const VP9_COMMON *const cm) { 1.298 + return cm->frame_type == KEY_FRAME || cm->intra_only; 1.299 +} 1.300 + 1.301 +static INLINE void update_partition_context( 1.302 + PARTITION_CONTEXT *above_seg_context, 1.303 + PARTITION_CONTEXT left_seg_context[8], 1.304 + int mi_row, int mi_col, 1.305 + BLOCK_SIZE sb_type, 1.306 + BLOCK_SIZE sb_size) { 1.307 + PARTITION_CONTEXT *above_ctx = above_seg_context + mi_col; 1.308 + PARTITION_CONTEXT *left_ctx = left_seg_context + (mi_row & MI_MASK); 1.309 + 1.310 + const int bsl = b_width_log2(sb_size), bs = (1 << bsl) / 2; 1.311 + const int bwl = b_width_log2(sb_type); 1.312 + const int bhl = b_height_log2(sb_type); 1.313 + const int boffset = b_width_log2(BLOCK_64X64) - bsl; 1.314 + const char pcval0 = ~(0xe << boffset); 1.315 + const char pcval1 = ~(0xf << boffset); 1.316 + const char pcvalue[2] = {pcval0, pcval1}; 1.317 + 1.318 + assert(MAX(bwl, bhl) <= bsl); 1.319 + 1.320 + // update the partition context at the end notes. set partition bits 1.321 + // of block sizes larger than the current one to be one, and partition 1.322 + // bits of smaller block sizes to be zero. 1.323 + vpx_memset(above_ctx, pcvalue[bwl == bsl], bs); 1.324 + vpx_memset(left_ctx, pcvalue[bhl == bsl], bs); 1.325 +} 1.326 + 1.327 +static INLINE int partition_plane_context( 1.328 + const PARTITION_CONTEXT *above_seg_context, 1.329 + const PARTITION_CONTEXT left_seg_context[8], 1.330 + int mi_row, int mi_col, 1.331 + BLOCK_SIZE sb_type) { 1.332 + const PARTITION_CONTEXT *above_ctx = above_seg_context + mi_col; 1.333 + const PARTITION_CONTEXT *left_ctx = left_seg_context + (mi_row & MI_MASK); 1.334 + 1.335 + int bsl = mi_width_log2(sb_type), bs = 1 << bsl; 1.336 + int above = 0, left = 0, i; 1.337 + int boffset = mi_width_log2(BLOCK_64X64) - bsl; 1.338 + 1.339 + assert(mi_width_log2(sb_type) == mi_height_log2(sb_type)); 1.340 + assert(bsl >= 0); 1.341 + assert(boffset >= 0); 1.342 + 1.343 + for (i = 0; i < bs; i++) { 1.344 + above |= above_ctx[i]; 1.345 + left |= left_ctx[i]; 1.346 + } 1.347 + above = (above & (1 << boffset)) > 0; 1.348 + left = (left & (1 << boffset)) > 0; 1.349 + 1.350 + return (left * 2 + above) + bsl * PARTITION_PLOFFSET; 1.351 +} 1.352 + 1.353 +#endif // VP9_COMMON_VP9_ONYXC_INT_H_