| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 3 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license | 5 * Use of this source code is governed by a BSD-style license |
| 6 * that can be found in the LICENSE file in the root of the source | 6 * that can be found in the LICENSE file in the root of the source |
| 7 * tree. An additional intellectual property rights grant can be found | 7 * tree. An additional intellectual property rights grant can be found |
| 8 * in the file PATENTS. All contributing project authors may | 8 * in the file PATENTS. All contributing project authors may |
| 9 * be found in the AUTHORS file in the root of the source tree. | 9 * be found in the AUTHORS file in the root of the source tree. |
| 10 */ | 10 */ |
| 11 | 11 |
| 12 #include "vp9/common/vp9_common.h" |
| 12 #include "vp9/common/vp9_pred_common.h" | 13 #include "vp9/common/vp9_pred_common.h" |
| 13 #include "vp9/common/vp9_seg_common.h" | 14 #include "vp9/common/vp9_seg_common.h" |
| 15 #include "vp9/common/vp9_treecoder.h" |
| 14 | 16 |
| 15 // TBD prediction functions for various bitstream signals | 17 // TBD prediction functions for various bitstream signals |
| 16 | 18 |
| 17 // Returns a context number for the given MB prediction signal | 19 // Returns a context number for the given MB prediction signal |
| 18 unsigned char vp9_get_pred_context(const VP9_COMMON *const cm, | 20 unsigned char vp9_get_pred_context(const VP9_COMMON *const cm, |
| 19 const MACROBLOCKD *const xd, | 21 const MACROBLOCKD *const xd, |
| 20 PRED_ID pred_id) { | 22 PRED_ID pred_id) { |
| 21 int pred_context; | 23 int pred_context; |
| 22 MODE_INFO *m = xd->mode_info_context; | 24 MODE_INFO *m = xd->mode_info_context; |
| 23 | 25 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 216 } |
| 215 | 217 |
| 216 return pred_flag; | 218 return pred_flag; |
| 217 } | 219 } |
| 218 | 220 |
| 219 // This function sets the status of the given prediction signal. | 221 // This function sets the status of the given prediction signal. |
| 220 // I.e. is the predicted value for the given signal correct. | 222 // I.e. is the predicted value for the given signal correct. |
| 221 void vp9_set_pred_flag(MACROBLOCKD *const xd, | 223 void vp9_set_pred_flag(MACROBLOCKD *const xd, |
| 222 PRED_ID pred_id, | 224 PRED_ID pred_id, |
| 223 unsigned char pred_flag) { | 225 unsigned char pred_flag) { |
| 224 #if CONFIG_SUPERBLOCKS | |
| 225 const int mis = xd->mode_info_stride; | 226 const int mis = xd->mode_info_stride; |
| 226 #endif | |
| 227 | 227 |
| 228 switch (pred_id) { | 228 switch (pred_id) { |
| 229 case PRED_SEG_ID: | 229 case PRED_SEG_ID: |
| 230 xd->mode_info_context->mbmi.seg_id_predicted = pred_flag; | 230 xd->mode_info_context->mbmi.seg_id_predicted = pred_flag; |
| 231 #if CONFIG_SUPERBLOCKS | 231 if (xd->mode_info_context->mbmi.sb_type) { |
| 232 if (xd->mode_info_context->mbmi.encoded_as_sb) { | 232 #define sub(a, b) (b) < 0 ? (a) + (b) : (a) |
| 233 if (xd->mb_to_right_edge >= 0) | 233 const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; |
| 234 xd->mode_info_context[1].mbmi.seg_id_predicted = pred_flag; | 234 const int x_mbs = sub(n_mbs, xd->mb_to_right_edge >> 7); |
| 235 if (xd->mb_to_bottom_edge >= 0) { | 235 const int y_mbs = sub(n_mbs, xd->mb_to_bottom_edge >> 7); |
| 236 xd->mode_info_context[mis].mbmi.seg_id_predicted = pred_flag; | 236 int x, y; |
| 237 if (xd->mb_to_right_edge >= 0) | 237 |
| 238 xd->mode_info_context[mis + 1].mbmi.seg_id_predicted = pred_flag; | 238 for (y = 0; y < y_mbs; y++) { |
| 239 for (x = !y; x < x_mbs; x++) { |
| 240 xd->mode_info_context[y * mis + x].mbmi.seg_id_predicted = |
| 241 pred_flag; |
| 242 } |
| 239 } | 243 } |
| 240 } | 244 } |
| 241 #endif | |
| 242 break; | 245 break; |
| 243 | 246 |
| 244 case PRED_REF: | 247 case PRED_REF: |
| 245 xd->mode_info_context->mbmi.ref_predicted = pred_flag; | 248 xd->mode_info_context->mbmi.ref_predicted = pred_flag; |
| 246 #if CONFIG_SUPERBLOCKS | 249 if (xd->mode_info_context->mbmi.sb_type) { |
| 247 if (xd->mode_info_context->mbmi.encoded_as_sb) { | 250 const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; |
| 248 if (xd->mb_to_right_edge >= 0) | 251 const int x_mbs = sub(n_mbs, xd->mb_to_right_edge >> 7); |
| 249 xd->mode_info_context[1].mbmi.ref_predicted = pred_flag; | 252 const int y_mbs = sub(n_mbs, xd->mb_to_bottom_edge >> 7); |
| 250 if (xd->mb_to_bottom_edge >= 0) { | 253 int x, y; |
| 251 xd->mode_info_context[mis].mbmi.ref_predicted = pred_flag; | 254 |
| 252 if (xd->mb_to_right_edge >= 0) | 255 for (y = 0; y < y_mbs; y++) { |
| 253 xd->mode_info_context[mis + 1].mbmi.ref_predicted = pred_flag; | 256 for (x = !y; x < x_mbs; x++) { |
| 257 xd->mode_info_context[y * mis + x].mbmi.ref_predicted = pred_flag; |
| 258 } |
| 254 } | 259 } |
| 255 } | 260 } |
| 256 #endif | |
| 257 break; | 261 break; |
| 258 | 262 |
| 259 case PRED_MBSKIP: | 263 case PRED_MBSKIP: |
| 260 xd->mode_info_context->mbmi.mb_skip_coeff = pred_flag; | 264 xd->mode_info_context->mbmi.mb_skip_coeff = pred_flag; |
| 261 #if CONFIG_SUPERBLOCKS | 265 if (xd->mode_info_context->mbmi.sb_type) { |
| 262 if (xd->mode_info_context->mbmi.encoded_as_sb) { | 266 const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; |
| 263 if (xd->mb_to_right_edge >= 0) | 267 const int x_mbs = sub(n_mbs, xd->mb_to_right_edge >> 7); |
| 264 xd->mode_info_context[1].mbmi.mb_skip_coeff = pred_flag; | 268 const int y_mbs = sub(n_mbs, xd->mb_to_bottom_edge >> 7); |
| 265 if (xd->mb_to_bottom_edge >= 0) { | 269 int x, y; |
| 266 xd->mode_info_context[mis].mbmi.mb_skip_coeff = pred_flag; | 270 |
| 267 if (xd->mb_to_right_edge >= 0) | 271 for (y = 0; y < y_mbs; y++) { |
| 268 xd->mode_info_context[mis + 1].mbmi.mb_skip_coeff = pred_flag; | 272 for (x = !y; x < x_mbs; x++) { |
| 273 xd->mode_info_context[y * mis + x].mbmi.mb_skip_coeff = pred_flag; |
| 274 } |
| 269 } | 275 } |
| 270 } | 276 } |
| 271 #endif | |
| 272 break; | 277 break; |
| 273 | 278 |
| 274 default: | 279 default: |
| 275 // TODO *** add error trap code. | 280 // TODO *** add error trap code. |
| 276 break; | 281 break; |
| 277 } | 282 } |
| 278 } | 283 } |
| 279 | 284 |
| 280 | 285 |
| 281 // The following contain the guts of the prediction code used to | 286 // The following contain the guts of the prediction code used to |
| 282 // peredict various bitstream signals. | 287 // peredict various bitstream signals. |
| 283 | 288 |
| 284 // Macroblock segment id prediction function | 289 // Macroblock segment id prediction function |
| 285 unsigned char vp9_get_pred_mb_segid(const VP9_COMMON *const cm, | 290 unsigned char vp9_get_pred_mb_segid(const VP9_COMMON *const cm, |
| 286 const MACROBLOCKD *const xd, int MbIndex) { | 291 const MACROBLOCKD *const xd, int MbIndex) { |
| 287 // Currently the prediction for the macroblock segment ID is | 292 // Currently the prediction for the macroblock segment ID is |
| 288 // the value stored for this macroblock in the previous frame. | 293 // the value stored for this macroblock in the previous frame. |
| 289 #if CONFIG_SUPERBLOCKS | 294 if (!xd->mode_info_context->mbmi.sb_type) { |
| 290 if (!xd->mode_info_context->mbmi.encoded_as_sb) { | |
| 291 #endif | |
| 292 return cm->last_frame_seg_map[MbIndex]; | 295 return cm->last_frame_seg_map[MbIndex]; |
| 293 #if CONFIG_SUPERBLOCKS | |
| 294 } else { | 296 } else { |
| 295 int seg_id = cm->last_frame_seg_map[MbIndex]; | 297 const int n_mbs = 1 << xd->mode_info_context->mbmi.sb_type; |
| 296 int mb_col = MbIndex % cm->mb_cols; | 298 const int mb_col = MbIndex % cm->mb_cols; |
| 297 int mb_row = MbIndex / cm->mb_cols; | 299 const int mb_row = MbIndex / cm->mb_cols; |
| 298 if (mb_col + 1 < cm->mb_cols) | 300 const int x_mbs = MIN(n_mbs, cm->mb_cols - mb_col); |
| 299 seg_id = seg_id && cm->last_frame_seg_map[MbIndex + 1]; | 301 const int y_mbs = MIN(n_mbs, cm->mb_rows - mb_row); |
| 300 if (mb_row + 1 < cm->mb_rows) { | 302 int x, y; |
| 301 seg_id = seg_id && cm->last_frame_seg_map[MbIndex + cm->mb_cols]; | 303 unsigned seg_id = -1; |
| 302 if (mb_col + 1 < cm->mb_cols) | 304 |
| 303 seg_id = seg_id && cm->last_frame_seg_map[MbIndex + cm->mb_cols + 1]; | 305 for (y = mb_row; y < mb_row + y_mbs; y++) { |
| 306 for (x = mb_col; x < mb_col + x_mbs; x++) { |
| 307 seg_id = MIN(seg_id, cm->last_frame_seg_map[cm->mb_cols * y + x]); |
| 308 } |
| 304 } | 309 } |
| 310 |
| 305 return seg_id; | 311 return seg_id; |
| 306 } | 312 } |
| 307 #endif | |
| 308 } | 313 } |
| 309 | 314 |
| 310 MV_REFERENCE_FRAME vp9_get_pred_ref(const VP9_COMMON *const cm, | 315 MV_REFERENCE_FRAME vp9_get_pred_ref(const VP9_COMMON *const cm, |
| 311 const MACROBLOCKD *const xd) { | 316 const MACROBLOCKD *const xd) { |
| 312 MODE_INFO *m = xd->mode_info_context; | 317 MODE_INFO *m = xd->mode_info_context; |
| 313 | 318 |
| 314 MV_REFERENCE_FRAME left; | 319 MV_REFERENCE_FRAME left; |
| 315 MV_REFERENCE_FRAME above; | 320 MV_REFERENCE_FRAME above; |
| 316 MV_REFERENCE_FRAME above_left; | 321 MV_REFERENCE_FRAME above_left; |
| 317 MV_REFERENCE_FRAME pred_ref = LAST_FRAME; | 322 MV_REFERENCE_FRAME pred_ref = LAST_FRAME; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 381 |
| 377 return pred_ref; | 382 return pred_ref; |
| 378 } | 383 } |
| 379 | 384 |
| 380 // Functions to computes a set of modified reference frame probabilities | 385 // Functions to computes a set of modified reference frame probabilities |
| 381 // to use when the prediction of the reference frame value fails | 386 // to use when the prediction of the reference frame value fails |
| 382 void vp9_calc_ref_probs(int *count, vp9_prob *probs) { | 387 void vp9_calc_ref_probs(int *count, vp9_prob *probs) { |
| 383 int tot_count; | 388 int tot_count; |
| 384 | 389 |
| 385 tot_count = count[0] + count[1] + count[2] + count[3]; | 390 tot_count = count[0] + count[1] + count[2] + count[3]; |
| 386 if (tot_count) { | 391 probs[0] = get_prob(count[0], tot_count); |
| 387 probs[0] = (vp9_prob)((count[0] * 255 + (tot_count >> 1)) / tot_count); | |
| 388 probs[0] += !probs[0]; | |
| 389 } else | |
| 390 probs[0] = 128; | |
| 391 | 392 |
| 392 tot_count -= count[0]; | 393 tot_count -= count[0]; |
| 393 if (tot_count) { | 394 probs[1] = get_prob(count[1], tot_count); |
| 394 probs[1] = (vp9_prob)((count[1] * 255 + (tot_count >> 1)) / tot_count); | |
| 395 probs[1] += !probs[1]; | |
| 396 } else | |
| 397 probs[1] = 128; | |
| 398 | 395 |
| 399 tot_count -= count[1]; | 396 tot_count -= count[1]; |
| 400 if (tot_count) { | 397 probs[2] = get_prob(count[2], tot_count); |
| 401 probs[2] = (vp9_prob)((count[2] * 255 + (tot_count >> 1)) / tot_count); | |
| 402 probs[2] += !probs[2]; | |
| 403 } else | |
| 404 probs[2] = 128; | |
| 405 | |
| 406 } | 398 } |
| 407 | 399 |
| 408 // Computes a set of modified conditional probabilities for the reference frame | 400 // Computes a set of modified conditional probabilities for the reference frame |
| 409 // Values willbe set to 0 for reference frame options that are not possible | 401 // Values willbe set to 0 for reference frame options that are not possible |
| 410 // because wither they were predicted and prediction has failed or because | 402 // because wither they were predicted and prediction has failed or because |
| 411 // they are not allowed for a given segment. | 403 // they are not allowed for a given segment. |
| 412 void vp9_compute_mod_refprobs(VP9_COMMON *const cm) { | 404 void vp9_compute_mod_refprobs(VP9_COMMON *const cm) { |
| 413 int norm_cnt[MAX_REF_FRAMES]; | 405 int norm_cnt[MAX_REF_FRAMES]; |
| 414 int intra_count; | 406 int intra_count; |
| 415 int inter_count; | 407 int inter_count; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 cm->mod_refprobs[ALTREF_FRAME][2] = 0; // This branch implicit | 448 cm->mod_refprobs[ALTREF_FRAME][2] = 0; // This branch implicit |
| 457 | 449 |
| 458 // Score the reference frames based on overal frequency. | 450 // Score the reference frames based on overal frequency. |
| 459 // These scores contribute to the prediction choices. | 451 // These scores contribute to the prediction choices. |
| 460 // Max score 17 min 1 | 452 // Max score 17 min 1 |
| 461 cm->ref_scores[INTRA_FRAME] = 1 + (intra_count * 16 / 255); | 453 cm->ref_scores[INTRA_FRAME] = 1 + (intra_count * 16 / 255); |
| 462 cm->ref_scores[LAST_FRAME] = 1 + (last_count * 16 / 255); | 454 cm->ref_scores[LAST_FRAME] = 1 + (last_count * 16 / 255); |
| 463 cm->ref_scores[GOLDEN_FRAME] = 1 + (gf_count * 16 / 255); | 455 cm->ref_scores[GOLDEN_FRAME] = 1 + (gf_count * 16 / 255); |
| 464 cm->ref_scores[ALTREF_FRAME] = 1 + (arf_count * 16 / 255); | 456 cm->ref_scores[ALTREF_FRAME] = 1 + (arf_count * 16 / 255); |
| 465 } | 457 } |
| OLD | NEW |