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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 best_error = pred_error[i]; | 382 best_error = pred_error[i]; |
383 best_mode = (MB_PREDICTION_MODE)i; | 383 best_mode = (MB_PREDICTION_MODE)i; |
384 } | 384 } |
385 } | 385 } |
386 | 386 |
387 | 387 |
388 mb->e_mbd.mode_info_context->mbmi.uv_mode = best_mode; | 388 mb->e_mbd.mode_info_context->mbmi.uv_mode = best_mode; |
389 | 389 |
390 } | 390 } |
391 | 391 |
392 static void update_mvcount(VP8_COMP *cpi, MACROBLOCKD *xd, int_mv *best_ref_mv) | 392 static void update_mvcount(MACROBLOCK *x, int_mv *best_ref_mv) |
393 { | 393 { |
| 394 MACROBLOCKD *xd = &x->e_mbd; |
394 /* Split MV modes currently not supported when RD is nopt enabled, | 395 /* Split MV modes currently not supported when RD is nopt enabled, |
395 * therefore, only need to modify MVcount in NEWMV mode. */ | 396 * therefore, only need to modify MVcount in NEWMV mode. */ |
396 if (xd->mode_info_context->mbmi.mode == NEWMV) | 397 if (xd->mode_info_context->mbmi.mode == NEWMV) |
397 { | 398 { |
398 cpi->MVcount[0][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.row - | 399 x->MVcount[0][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.row - |
399 best_ref_mv->as_mv.row) >> 1)]++; | 400 best_ref_mv->as_mv.row) >> 1)]++; |
400 cpi->MVcount[1][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.col - | 401 x->MVcount[1][mv_max+((xd->mode_info_context->mbmi.mv.as_mv.col - |
401 best_ref_mv->as_mv.col) >> 1)]++; | 402 best_ref_mv->as_mv.col) >> 1)]++; |
402 } | 403 } |
403 } | 404 } |
404 | 405 |
405 | 406 |
406 #if CONFIG_MULTI_RES_ENCODING | 407 #if CONFIG_MULTI_RES_ENCODING |
407 static | 408 static |
408 void get_lower_res_motion_info(VP8_COMP *cpi, MACROBLOCKD *xd, int *dissim, | 409 void get_lower_res_motion_info(VP8_COMP *cpi, MACROBLOCKD *xd, int *dissim, |
409 int *parent_ref_frame, | 410 int *parent_ref_frame, |
410 MB_PREDICTION_MODE *parent_mode, | 411 MB_PREDICTION_MODE *parent_mode, |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 ref_frame_map[1], | 673 ref_frame_map[1], |
673 cpi->common.ref_frame_sign_bias); | 674 cpi->common.ref_frame_sign_bias); |
674 | 675 |
675 mode_mv = mode_mv_sb[sign_bias]; | 676 mode_mv = mode_mv_sb[sign_bias]; |
676 best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int; | 677 best_ref_mv.as_int = best_ref_mv_sb[sign_bias].as_int; |
677 } | 678 } |
678 | 679 |
679 get_predictor_pointers(cpi, plane, recon_yoffset, recon_uvoffset); | 680 get_predictor_pointers(cpi, plane, recon_yoffset, recon_uvoffset); |
680 | 681 |
681 /* Count of the number of MBs tested so far this frame */ | 682 /* Count of the number of MBs tested so far this frame */ |
682 cpi->mbs_tested_so_far++; | 683 x->mbs_tested_so_far++; |
683 | 684 |
684 *returnintra = INT_MAX; | 685 *returnintra = INT_MAX; |
685 x->skip = 0; | 686 x->skip = 0; |
686 | 687 |
687 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; | 688 x->e_mbd.mode_info_context->mbmi.ref_frame = INTRA_FRAME; |
688 | 689 |
689 /* If the frame has big static background and current MB is in low | 690 /* If the frame has big static background and current MB is in low |
690 * motion area, its mode decision is biased to ZEROMV mode. | 691 * motion area, its mode decision is biased to ZEROMV mode. |
691 */ | 692 */ |
692 calculate_zeromv_rd_adjustment(cpi, x, &rd_adjustment); | 693 calculate_zeromv_rd_adjustment(cpi, x, &rd_adjustment); |
693 | 694 |
694 /* if we encode a new mv this is important | 695 /* if we encode a new mv this is important |
695 * find the best new motion vector | 696 * find the best new motion vector |
696 */ | 697 */ |
697 for (mode_index = 0; mode_index < MAX_MODES; mode_index++) | 698 for (mode_index = 0; mode_index < MAX_MODES; mode_index++) |
698 { | 699 { |
699 int frame_cost; | 700 int frame_cost; |
700 int this_rd = INT_MAX; | 701 int this_rd = INT_MAX; |
701 int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]]; | 702 int this_ref_frame = ref_frame_map[vp8_ref_frame_order[mode_index]]; |
702 | 703 |
703 if (best_rd <= cpi->rd_threshes[mode_index]) | 704 if (best_rd <= x->rd_threshes[mode_index]) |
704 continue; | 705 continue; |
705 | 706 |
706 if (this_ref_frame < 0) | 707 if (this_ref_frame < 0) |
707 continue; | 708 continue; |
708 | 709 |
709 x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame; | 710 x->e_mbd.mode_info_context->mbmi.ref_frame = this_ref_frame; |
710 | 711 |
711 /* everything but intra */ | 712 /* everything but intra */ |
712 if (x->e_mbd.mode_info_context->mbmi.ref_frame) | 713 if (x->e_mbd.mode_info_context->mbmi.ref_frame) |
713 { | 714 { |
(...skipping 24 matching lines...) Expand all Loading... |
738 else if(vp8_mode_order[mode_index] == NEWMV && dissim==0 | 739 else if(vp8_mode_order[mode_index] == NEWMV && dissim==0 |
739 && best_ref_mv.as_int==parent_ref_mv.as_int) | 740 && best_ref_mv.as_int==parent_ref_mv.as_int) |
740 continue; | 741 continue; |
741 } | 742 } |
742 #endif | 743 #endif |
743 } | 744 } |
744 | 745 |
745 /* Check to see if the testing frequency for this mode is at its max | 746 /* Check to see if the testing frequency for this mode is at its max |
746 * If so then prevent it from being tested and increase the threshold | 747 * If so then prevent it from being tested and increase the threshold |
747 * for its testing */ | 748 * for its testing */ |
748 if (cpi->mode_test_hit_counts[mode_index] && | 749 if (x->mode_test_hit_counts[mode_index] && |
749 (cpi->mode_check_freq[mode_index] > 1)) | 750 (cpi->mode_check_freq[mode_index] > 1)) |
750 { | 751 { |
751 if (cpi->mbs_tested_so_far <= (cpi->mode_check_freq[mode_index] * | 752 if (x->mbs_tested_so_far <= (cpi->mode_check_freq[mode_index] * |
752 cpi->mode_test_hit_counts[mode_index])) | 753 x->mode_test_hit_counts[mode_index])) |
753 { | 754 { |
754 /* Increase the threshold for coding this mode to make it less | 755 /* Increase the threshold for coding this mode to make it less |
755 * likely to be chosen */ | 756 * likely to be chosen */ |
756 cpi->rd_thresh_mult[mode_index] += 4; | 757 x->rd_thresh_mult[mode_index] += 4; |
757 | 758 |
758 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) | 759 if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT) |
759 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT; | 760 x->rd_thresh_mult[mode_index] = MAX_THRESHMULT; |
760 | 761 |
761 cpi->rd_threshes[mode_index] = | 762 x->rd_threshes[mode_index] = |
762 (cpi->rd_baseline_thresh[mode_index] >> 7) * | 763 (cpi->rd_baseline_thresh[mode_index] >> 7) * |
763 cpi->rd_thresh_mult[mode_index]; | 764 x->rd_thresh_mult[mode_index]; |
764 continue; | 765 continue; |
765 } | 766 } |
766 } | 767 } |
767 | 768 |
768 /* We have now reached the point where we are going to test the current | 769 /* We have now reached the point where we are going to test the current |
769 * mode so increment the counter for the number of times it has been | 770 * mode so increment the counter for the number of times it has been |
770 * tested */ | 771 * tested */ |
771 cpi->mode_test_hit_counts[mode_index] ++; | 772 x->mode_test_hit_counts[mode_index] ++; |
772 | 773 |
773 rate2 = 0; | 774 rate2 = 0; |
774 distortion2 = 0; | 775 distortion2 = 0; |
775 | 776 |
776 this_mode = vp8_mode_order[mode_index]; | 777 this_mode = vp8_mode_order[mode_index]; |
777 | 778 |
778 x->e_mbd.mode_info_context->mbmi.mode = this_mode; | 779 x->e_mbd.mode_info_context->mbmi.mode = this_mode; |
779 x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED; | 780 x->e_mbd.mode_info_context->mbmi.uv_mode = DC_PRED; |
780 | 781 |
781 /* Work out the cost assosciated with selecting the reference frame */ | 782 /* Work out the cost assosciated with selecting the reference frame */ |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 *returnrate = rate2; | 1102 *returnrate = rate2; |
1102 *returndistortion = distortion2; | 1103 *returndistortion = distortion2; |
1103 best_rd_sse = sse; | 1104 best_rd_sse = sse; |
1104 best_rd = this_rd; | 1105 best_rd = this_rd; |
1105 vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, | 1106 vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, |
1106 sizeof(MB_MODE_INFO)); | 1107 sizeof(MB_MODE_INFO)); |
1107 | 1108 |
1108 /* Testing this mode gave rise to an improvement in best error | 1109 /* Testing this mode gave rise to an improvement in best error |
1109 * score. Lower threshold a bit for next time | 1110 * score. Lower threshold a bit for next time |
1110 */ | 1111 */ |
1111 cpi->rd_thresh_mult[mode_index] = | 1112 x->rd_thresh_mult[mode_index] = |
1112 (cpi->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? | 1113 (x->rd_thresh_mult[mode_index] >= (MIN_THRESHMULT + 2)) ? |
1113 cpi->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT; | 1114 x->rd_thresh_mult[mode_index] - 2 : MIN_THRESHMULT; |
1114 cpi->rd_threshes[mode_index] = | 1115 x->rd_threshes[mode_index] = |
1115 (cpi->rd_baseline_thresh[mode_index] >> 7) * | 1116 (cpi->rd_baseline_thresh[mode_index] >> 7) * |
1116 cpi->rd_thresh_mult[mode_index]; | 1117 x->rd_thresh_mult[mode_index]; |
1117 } | 1118 } |
1118 | 1119 |
1119 /* If the mode did not help improve the best error case then raise the | 1120 /* If the mode did not help improve the best error case then raise the |
1120 * threshold for testing that mode next time around. | 1121 * threshold for testing that mode next time around. |
1121 */ | 1122 */ |
1122 else | 1123 else |
1123 { | 1124 { |
1124 cpi->rd_thresh_mult[mode_index] += 4; | 1125 x->rd_thresh_mult[mode_index] += 4; |
1125 | 1126 |
1126 if (cpi->rd_thresh_mult[mode_index] > MAX_THRESHMULT) | 1127 if (x->rd_thresh_mult[mode_index] > MAX_THRESHMULT) |
1127 cpi->rd_thresh_mult[mode_index] = MAX_THRESHMULT; | 1128 x->rd_thresh_mult[mode_index] = MAX_THRESHMULT; |
1128 | 1129 |
1129 cpi->rd_threshes[mode_index] = | 1130 x->rd_threshes[mode_index] = |
1130 (cpi->rd_baseline_thresh[mode_index] >> 7) * | 1131 (cpi->rd_baseline_thresh[mode_index] >> 7) * |
1131 cpi->rd_thresh_mult[mode_index]; | 1132 x->rd_thresh_mult[mode_index]; |
1132 } | 1133 } |
1133 | 1134 |
1134 if (x->skip) | 1135 if (x->skip) |
1135 break; | 1136 break; |
1136 } | 1137 } |
1137 | 1138 |
1138 /* Reduce the activation RD thresholds for the best choice mode */ | 1139 /* Reduce the activation RD thresholds for the best choice mode */ |
1139 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thre
sh[best_mode_index] < (INT_MAX >> 2))) | 1140 if ((cpi->rd_baseline_thresh[best_mode_index] > 0) && (cpi->rd_baseline_thre
sh[best_mode_index] < (INT_MAX >> 2))) |
1140 { | 1141 { |
1141 int best_adjustment = (cpi->rd_thresh_mult[best_mode_index] >> 3); | 1142 int best_adjustment = (x->rd_thresh_mult[best_mode_index] >> 3); |
1142 | 1143 |
1143 cpi->rd_thresh_mult[best_mode_index] = | 1144 x->rd_thresh_mult[best_mode_index] = |
1144 (cpi->rd_thresh_mult[best_mode_index] | 1145 (x->rd_thresh_mult[best_mode_index] |
1145 >= (MIN_THRESHMULT + best_adjustment)) ? | 1146 >= (MIN_THRESHMULT + best_adjustment)) ? |
1146 cpi->rd_thresh_mult[best_mode_index] - best_adjustment : | 1147 x->rd_thresh_mult[best_mode_index] - best_adjustment : |
1147 MIN_THRESHMULT; | 1148 MIN_THRESHMULT; |
1148 cpi->rd_threshes[best_mode_index] = | 1149 x->rd_threshes[best_mode_index] = |
1149 (cpi->rd_baseline_thresh[best_mode_index] >> 7) * | 1150 (cpi->rd_baseline_thresh[best_mode_index] >> 7) * |
1150 cpi->rd_thresh_mult[best_mode_index]; | 1151 x->rd_thresh_mult[best_mode_index]; |
1151 } | 1152 } |
1152 | 1153 |
1153 | 1154 |
1154 { | 1155 { |
1155 int this_rdbin = (*returndistortion >> 7); | 1156 int this_rdbin = (*returndistortion >> 7); |
1156 | 1157 |
1157 if (this_rdbin >= 1024) | 1158 if (this_rdbin >= 1024) |
1158 { | 1159 { |
1159 this_rdbin = 1023; | 1160 this_rdbin = 1023; |
1160 } | 1161 } |
1161 | 1162 |
1162 cpi->error_bins[this_rdbin] ++; | 1163 x->error_bins[this_rdbin] ++; |
1163 } | 1164 } |
1164 | 1165 |
1165 #if CONFIG_TEMPORAL_DENOISING | 1166 #if CONFIG_TEMPORAL_DENOISING |
1166 if (cpi->oxcf.noise_sensitivity) | 1167 if (cpi->oxcf.noise_sensitivity) |
1167 { | 1168 { |
1168 if (x->best_sse_inter_mode == DC_PRED) | 1169 if (x->best_sse_inter_mode == DC_PRED) |
1169 { | 1170 { |
1170 /* No best MV found. */ | 1171 /* No best MV found. */ |
1171 x->best_sse_inter_mode = best_mbmode.mode; | 1172 x->best_sse_inter_mode = best_mbmode.mode; |
1172 x->best_sse_mv = best_mbmode.mv; | 1173 x->best_sse_mv = best_mbmode.mv; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 if (best_mbmode.mode <= B_PRED) | 1234 if (best_mbmode.mode <= B_PRED) |
1234 { | 1235 { |
1235 /* set mode_info_context->mbmi.uv_mode */ | 1236 /* set mode_info_context->mbmi.uv_mode */ |
1236 pick_intra_mbuv_mode(x); | 1237 pick_intra_mbuv_mode(x); |
1237 } | 1238 } |
1238 | 1239 |
1239 if (sign_bias | 1240 if (sign_bias |
1240 != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame]) | 1241 != cpi->common.ref_frame_sign_bias[xd->mode_info_context->mbmi.ref_frame]) |
1241 best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int; | 1242 best_ref_mv.as_int = best_ref_mv_sb[!sign_bias].as_int; |
1242 | 1243 |
1243 update_mvcount(cpi, &x->e_mbd, &best_ref_mv); | 1244 update_mvcount(x, &best_ref_mv); |
1244 } | 1245 } |
1245 | 1246 |
1246 | 1247 |
1247 void vp8_pick_intra_mode(VP8_COMP *cpi, MACROBLOCK *x, int *rate_) | 1248 void vp8_pick_intra_mode(MACROBLOCK *x, int *rate_) |
1248 { | 1249 { |
1249 int error4x4, error16x16 = INT_MAX; | 1250 int error4x4, error16x16 = INT_MAX; |
1250 int rate, best_rate = 0, distortion, best_sse; | 1251 int rate, best_rate = 0, distortion, best_sse; |
1251 MB_PREDICTION_MODE mode, best_mode = DC_PRED; | 1252 MB_PREDICTION_MODE mode, best_mode = DC_PRED; |
1252 int this_rd; | 1253 int this_rd; |
1253 unsigned int sse; | 1254 unsigned int sse; |
1254 BLOCK *b = &x->block[0]; | 1255 BLOCK *b = &x->block[0]; |
1255 MACROBLOCKD *xd = &x->e_mbd; | 1256 MACROBLOCKD *xd = &x->e_mbd; |
1256 | 1257 |
1257 xd->mode_info_context->mbmi.ref_frame = INTRA_FRAME; | 1258 xd->mode_info_context->mbmi.ref_frame = INTRA_FRAME; |
(...skipping 27 matching lines...) Expand all Loading... |
1285 error4x4 = pick_intra4x4mby_modes(x, &rate, | 1286 error4x4 = pick_intra4x4mby_modes(x, &rate, |
1286 &best_sse); | 1287 &best_sse); |
1287 if (error4x4 < error16x16) | 1288 if (error4x4 < error16x16) |
1288 { | 1289 { |
1289 xd->mode_info_context->mbmi.mode = B_PRED; | 1290 xd->mode_info_context->mbmi.mode = B_PRED; |
1290 best_rate = rate; | 1291 best_rate = rate; |
1291 } | 1292 } |
1292 | 1293 |
1293 *rate_ = best_rate; | 1294 *rate_ = best_rate; |
1294 } | 1295 } |
OLD | NEW |