OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // The baseline rd thresholds for breaking out of the rd loop for | 59 // The baseline rd thresholds for breaking out of the rd loop for |
60 // certain modes are assumed to be based on 8x8 blocks. | 60 // certain modes are assumed to be based on 8x8 blocks. |
61 // This table is used to correct for block size. | 61 // This table is used to correct for block size. |
62 // The factors here are << 2 (2 = x0.5, 32 = x8 etc). | 62 // The factors here are << 2 (2 = x0.5, 32 = x8 etc). |
63 static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES] = { | 63 static const uint8_t rd_thresh_block_size_factor[BLOCK_SIZES] = { |
64 2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32 | 64 2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32 |
65 }; | 65 }; |
66 | 66 |
67 static void fill_mode_costs(VP9_COMP *cpi) { | 67 static void fill_mode_costs(VP9_COMP *cpi) { |
68 const FRAME_CONTEXT *const fc = &cpi->common.fc; | 68 const FRAME_CONTEXT *const fc = cpi->common.fc; |
69 int i, j; | 69 int i, j; |
70 | 70 |
71 for (i = 0; i < INTRA_MODES; ++i) | 71 for (i = 0; i < INTRA_MODES; ++i) |
72 for (j = 0; j < INTRA_MODES; ++j) | 72 for (j = 0; j < INTRA_MODES; ++j) |
73 vp9_cost_tokens(cpi->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j], | 73 vp9_cost_tokens(cpi->y_mode_costs[i][j], vp9_kf_y_mode_prob[i][j], |
74 vp9_intra_mode_tree); | 74 vp9_intra_mode_tree); |
75 | 75 |
76 vp9_cost_tokens(cpi->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree); | 76 vp9_cost_tokens(cpi->mbmode_cost, fc->y_mode_prob[1], vp9_intra_mode_tree); |
77 vp9_cost_tokens(cpi->intra_uv_mode_cost[KEY_FRAME], | 77 vp9_cost_tokens(cpi->intra_uv_mode_cost[KEY_FRAME], |
78 vp9_kf_uv_mode_prob[TM_PRED], vp9_intra_mode_tree); | 78 vp9_kf_uv_mode_prob[TM_PRED], vp9_intra_mode_tree); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 x->errorperbit = rd->RDMULT / RD_MULT_EPB_RATIO; | 274 x->errorperbit = rd->RDMULT / RD_MULT_EPB_RATIO; |
275 x->errorperbit += (x->errorperbit == 0); | 275 x->errorperbit += (x->errorperbit == 0); |
276 | 276 |
277 x->select_tx_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && | 277 x->select_tx_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && |
278 cm->frame_type != KEY_FRAME) ? 0 : 1; | 278 cm->frame_type != KEY_FRAME) ? 0 : 1; |
279 | 279 |
280 set_block_thresholds(cm, rd); | 280 set_block_thresholds(cm, rd); |
281 | 281 |
282 if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) { | 282 if (!cpi->sf.use_nonrd_pick_mode || cm->frame_type == KEY_FRAME) { |
283 fill_token_costs(x->token_costs, cm->fc.coef_probs); | 283 fill_token_costs(x->token_costs, cm->fc->coef_probs); |
284 | 284 |
285 for (i = 0; i < PARTITION_CONTEXTS; ++i) | 285 for (i = 0; i < PARTITION_CONTEXTS; ++i) |
286 vp9_cost_tokens(cpi->partition_cost[i], get_partition_probs(cm, i), | 286 vp9_cost_tokens(cpi->partition_cost[i], get_partition_probs(cm, i), |
287 vp9_partition_tree); | 287 vp9_partition_tree); |
288 } | 288 } |
289 | 289 |
290 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1 || | 290 if (!cpi->sf.use_nonrd_pick_mode || (cm->current_video_frame & 0x07) == 1 || |
291 cm->frame_type == KEY_FRAME) { | 291 cm->frame_type == KEY_FRAME) { |
292 fill_mode_costs(cpi); | 292 fill_mode_costs(cpi); |
293 | 293 |
294 if (!frame_is_intra_only(cm)) { | 294 if (!frame_is_intra_only(cm)) { |
295 vp9_build_nmv_cost_table(x->nmvjointcost, | 295 vp9_build_nmv_cost_table(x->nmvjointcost, |
296 cm->allow_high_precision_mv ? x->nmvcost_hp | 296 cm->allow_high_precision_mv ? x->nmvcost_hp |
297 : x->nmvcost, | 297 : x->nmvcost, |
298 &cm->fc.nmvc, cm->allow_high_precision_mv); | 298 &cm->fc->nmvc, cm->allow_high_precision_mv); |
299 | 299 |
300 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) | 300 for (i = 0; i < INTER_MODE_CONTEXTS; ++i) |
301 vp9_cost_tokens((int *)cpi->inter_mode_cost[i], | 301 vp9_cost_tokens((int *)cpi->inter_mode_cost[i], |
302 cm->fc.inter_mode_probs[i], vp9_inter_mode_tree); | 302 cm->fc->inter_mode_probs[i], vp9_inter_mode_tree); |
303 } | 303 } |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { | 307 static void model_rd_norm(int xsq_q10, int *r_q10, int *d_q10) { |
308 // NOTE: The tables below must be of the same size. | 308 // NOTE: The tables below must be of the same size. |
309 | 309 |
310 // The functions described below are sampled at the four most significant | 310 // The functions described below are sampled at the four most significant |
311 // bits of x^2 + 8 / 256. | 311 // bits of x^2 + 8 / 256. |
312 | 312 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 int i; | 451 int i; |
452 int zero_seen = 0; | 452 int zero_seen = 0; |
453 int best_index = 0; | 453 int best_index = 0; |
454 int best_sad = INT_MAX; | 454 int best_sad = INT_MAX; |
455 int this_sad = INT_MAX; | 455 int this_sad = INT_MAX; |
456 int max_mv = 0; | 456 int max_mv = 0; |
457 uint8_t *src_y_ptr = x->plane[0].src.buf; | 457 uint8_t *src_y_ptr = x->plane[0].src.buf; |
458 uint8_t *ref_y_ptr; | 458 uint8_t *ref_y_ptr; |
459 const int num_mv_refs = MAX_MV_REF_CANDIDATES + | 459 const int num_mv_refs = MAX_MV_REF_CANDIDATES + |
460 (cpi->sf.adaptive_motion_search && | 460 (cpi->sf.adaptive_motion_search && |
461 block_size < cpi->sf.max_partition_size); | 461 block_size < x->max_partition_size); |
462 | 462 |
463 MV pred_mv[3]; | 463 MV pred_mv[3]; |
464 pred_mv[0] = mbmi->ref_mvs[ref_frame][0].as_mv; | 464 pred_mv[0] = mbmi->ref_mvs[ref_frame][0].as_mv; |
465 pred_mv[1] = mbmi->ref_mvs[ref_frame][1].as_mv; | 465 pred_mv[1] = mbmi->ref_mvs[ref_frame][1].as_mv; |
466 pred_mv[2] = x->pred_mv[ref_frame]; | 466 pred_mv[2] = x->pred_mv[ref_frame]; |
467 | 467 |
468 // Get the sad for each candidate reference mv. | 468 // Get the sad for each candidate reference mv. |
469 for (i = 0; i < num_mv_refs; ++i) { | 469 for (i = 0; i < num_mv_refs; ++i) { |
470 const MV *this_mv = &pred_mv[i]; | 470 const MV *this_mv = &pred_mv[i]; |
471 | 471 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 rd->thresh_mult[THR_V_PRED] += 2000; | 584 rd->thresh_mult[THR_V_PRED] += 2000; |
585 rd->thresh_mult[THR_D45_PRED ] += 2500; | 585 rd->thresh_mult[THR_D45_PRED ] += 2500; |
586 rd->thresh_mult[THR_D135_PRED] += 2500; | 586 rd->thresh_mult[THR_D135_PRED] += 2500; |
587 rd->thresh_mult[THR_D117_PRED] += 2500; | 587 rd->thresh_mult[THR_D117_PRED] += 2500; |
588 rd->thresh_mult[THR_D153_PRED] += 2500; | 588 rd->thresh_mult[THR_D153_PRED] += 2500; |
589 rd->thresh_mult[THR_D207_PRED] += 2500; | 589 rd->thresh_mult[THR_D207_PRED] += 2500; |
590 rd->thresh_mult[THR_D63_PRED] += 2500; | 590 rd->thresh_mult[THR_D63_PRED] += 2500; |
591 } | 591 } |
592 | 592 |
593 void vp9_set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) { | 593 void vp9_set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) { |
594 const SPEED_FEATURES *const sf = &cpi->sf; | 594 static const int thresh_mult[2][MAX_REFS] = |
| 595 {{2500, 2500, 2500, 4500, 4500, 2500}, |
| 596 {2000, 2000, 2000, 4000, 4000, 2000}}; |
595 RD_OPT *const rd = &cpi->rd; | 597 RD_OPT *const rd = &cpi->rd; |
596 int i; | 598 const int idx = cpi->oxcf.mode == BEST; |
| 599 vpx_memcpy(rd->thresh_mult_sub8x8, thresh_mult[idx], |
| 600 sizeof(thresh_mult[idx])); |
| 601 } |
597 | 602 |
598 for (i = 0; i < MAX_REFS; ++i) | 603 void vp9_update_rd_thresh_fact(int (*factor_buf)[MAX_MODES], int rd_thresh, |
599 rd->thresh_mult_sub8x8[i] = cpi->oxcf.mode == BEST ? -500 : 0; | 604 int bsize, int best_mode_index) { |
600 | 605 if (rd_thresh > 0) { |
601 rd->thresh_mult_sub8x8[THR_LAST] += 2500; | 606 const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES; |
602 rd->thresh_mult_sub8x8[THR_GOLD] += 2500; | 607 int mode; |
603 rd->thresh_mult_sub8x8[THR_ALTR] += 2500; | 608 for (mode = 0; mode < top_mode; ++mode) { |
604 rd->thresh_mult_sub8x8[THR_INTRA] += 2500; | 609 const BLOCK_SIZE min_size = MAX(bsize - 1, BLOCK_4X4); |
605 rd->thresh_mult_sub8x8[THR_COMP_LA] += 4500; | 610 const BLOCK_SIZE max_size = MIN(bsize + 2, BLOCK_64X64); |
606 rd->thresh_mult_sub8x8[THR_COMP_GA] += 4500; | 611 BLOCK_SIZE bs; |
607 | 612 for (bs = min_size; bs <= max_size; ++bs) { |
608 // Check for masked out split cases. | 613 int *const fact = &factor_buf[bs][mode]; |
609 for (i = 0; i < MAX_REFS; ++i) | 614 if (mode == best_mode_index) { |
610 if (sf->disable_split_mask & (1 << i)) | 615 *fact -= (*fact >> 4); |
611 rd->thresh_mult_sub8x8[i] = INT_MAX; | 616 } else { |
| 617 *fact = MIN(*fact + RD_THRESH_INC, |
| 618 rd_thresh * RD_THRESH_MAX_FACT); |
| 619 } |
| 620 } |
| 621 } |
| 622 } |
612 } | 623 } |
613 | 624 |
614 int vp9_get_intra_cost_penalty(int qindex, int qdelta, | 625 int vp9_get_intra_cost_penalty(int qindex, int qdelta, |
615 vpx_bit_depth_t bit_depth) { | 626 vpx_bit_depth_t bit_depth) { |
616 const int q = vp9_dc_quant(qindex, qdelta, bit_depth); | 627 const int q = vp9_dc_quant(qindex, qdelta, bit_depth); |
617 #if CONFIG_VP9_HIGHBITDEPTH | 628 #if CONFIG_VP9_HIGHBITDEPTH |
618 switch (bit_depth) { | 629 switch (bit_depth) { |
619 case VPX_BITS_8: | 630 case VPX_BITS_8: |
620 return 20 * q; | 631 return 20 * q; |
621 case VPX_BITS_10: | 632 case VPX_BITS_10: |
622 return 5 * q; | 633 return 5 * q; |
623 case VPX_BITS_12: | 634 case VPX_BITS_12: |
624 return ROUND_POWER_OF_TWO(5 * q, 2); | 635 return ROUND_POWER_OF_TWO(5 * q, 2); |
625 default: | 636 default: |
626 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); | 637 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); |
627 return -1; | 638 return -1; |
628 } | 639 } |
629 #else | 640 #else |
630 return 20 * q; | 641 return 20 * q; |
631 #endif // CONFIG_VP9_HIGHBITDEPTH | 642 #endif // CONFIG_VP9_HIGHBITDEPTH |
632 } | 643 } |
633 | 644 |
OLD | NEW |