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 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include <math.h> | 12 #include <math.h> |
13 | 13 |
14 #include "./vp9_rtcd.h" | 14 #include "./vp9_rtcd.h" |
15 #include "./vpx_dsp_rtcd.h" | 15 #include "./vpx_dsp_rtcd.h" |
16 | 16 |
| 17 #include "vpx_dsp/vpx_dsp_common.h" |
17 #include "vpx_mem/vpx_mem.h" | 18 #include "vpx_mem/vpx_mem.h" |
18 #include "vpx_ports/mem.h" | 19 #include "vpx_ports/mem.h" |
19 #include "vpx_ports/system_state.h" | 20 #include "vpx_ports/system_state.h" |
20 | 21 |
21 #include "vp9/common/vp9_common.h" | 22 #include "vp9/common/vp9_common.h" |
22 #include "vp9/common/vp9_entropy.h" | 23 #include "vp9/common/vp9_entropy.h" |
23 #include "vp9/common/vp9_entropymode.h" | 24 #include "vp9/common/vp9_entropymode.h" |
24 #include "vp9/common/vp9_idct.h" | 25 #include "vp9/common/vp9_idct.h" |
25 #include "vp9/common/vp9_mvref_common.h" | 26 #include "vp9/common/vp9_mvref_common.h" |
26 #include "vp9/common/vp9_pred_common.h" | 27 #include "vp9/common/vp9_pred_common.h" |
(...skipping 3751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3778 int64_t this_rd = INT64_MAX; | 3779 int64_t this_rd = INT64_MAX; |
3779 int disable_skip = 0; | 3780 int disable_skip = 0; |
3780 int compmode_cost = 0; | 3781 int compmode_cost = 0; |
3781 int rate2 = 0, rate_y = 0, rate_uv = 0; | 3782 int rate2 = 0, rate_y = 0, rate_uv = 0; |
3782 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; | 3783 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
3783 int skippable = 0; | 3784 int skippable = 0; |
3784 int i; | 3785 int i; |
3785 int this_skip2 = 0; | 3786 int this_skip2 = 0; |
3786 int64_t total_sse = INT_MAX; | 3787 int64_t total_sse = INT_MAX; |
3787 int early_term = 0; | 3788 int early_term = 0; |
| 3789 struct buf_2d backup_yv12[2][MAX_MB_PLANE]; |
3788 | 3790 |
3789 ref_frame = vp9_ref_order[ref_index].ref_frame[0]; | 3791 ref_frame = vp9_ref_order[ref_index].ref_frame[0]; |
3790 second_ref_frame = vp9_ref_order[ref_index].ref_frame[1]; | 3792 second_ref_frame = vp9_ref_order[ref_index].ref_frame[1]; |
3791 | 3793 |
3792 // Look at the reference frame of the best mode so far and set the | 3794 // Look at the reference frame of the best mode so far and set the |
3793 // skip mask to look at a subset of the remaining modes. | 3795 // skip mask to look at a subset of the remaining modes. |
3794 if (ref_index > 2 && sf->mode_skip_start < MAX_MODES) { | 3796 if (ref_index > 2 && sf->mode_skip_start < MAX_MODES) { |
3795 if (ref_index == 3) { | 3797 if (ref_index == 3) { |
3796 switch (best_mbmode.ref_frame[0]) { | 3798 switch (best_mbmode.ref_frame[0]) { |
3797 case INTRA_FRAME: | 3799 case INTRA_FRAME: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3835 // Do not allow compound prediction if the segment level reference frame | 3837 // Do not allow compound prediction if the segment level reference frame |
3836 // feature is in use as in this case there can only be one reference. | 3838 // feature is in use as in this case there can only be one reference. |
3837 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | 3839 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
3838 continue; | 3840 continue; |
3839 | 3841 |
3840 if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && | 3842 if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && |
3841 best_mbmode.ref_frame[0] == INTRA_FRAME) | 3843 best_mbmode.ref_frame[0] == INTRA_FRAME) |
3842 continue; | 3844 continue; |
3843 } | 3845 } |
3844 | 3846 |
3845 // TODO(jingning, jkoleszar): scaling reference frame not supported for | |
3846 // sub8x8 blocks. | |
3847 if (ref_frame > INTRA_FRAME && | |
3848 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) | |
3849 continue; | |
3850 | |
3851 if (second_ref_frame > INTRA_FRAME && | |
3852 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) | |
3853 continue; | |
3854 | |
3855 if (comp_pred) | 3847 if (comp_pred) |
3856 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; | 3848 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; |
3857 else if (ref_frame != INTRA_FRAME) | 3849 else if (ref_frame != INTRA_FRAME) |
3858 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; | 3850 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; |
3859 | 3851 |
3860 // If the segment reference frame feature is enabled.... | 3852 // If the segment reference frame feature is enabled.... |
3861 // then do nothing if the current ref frame is not allowed.. | 3853 // then do nothing if the current ref frame is not allowed.. |
3862 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 3854 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
3863 get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { | 3855 get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { |
3864 continue; | 3856 continue; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3923 int tmp_best_skippable = 0; | 3915 int tmp_best_skippable = 0; |
3924 int switchable_filter_index; | 3916 int switchable_filter_index; |
3925 int_mv *second_ref = comp_pred ? | 3917 int_mv *second_ref = comp_pred ? |
3926 &x->mbmi_ext->ref_mvs[second_ref_frame][0] : NULL; | 3918 &x->mbmi_ext->ref_mvs[second_ref_frame][0] : NULL; |
3927 b_mode_info tmp_best_bmodes[16]; | 3919 b_mode_info tmp_best_bmodes[16]; |
3928 MB_MODE_INFO tmp_best_mbmode; | 3920 MB_MODE_INFO tmp_best_mbmode; |
3929 BEST_SEG_INFO bsi[SWITCHABLE_FILTERS]; | 3921 BEST_SEG_INFO bsi[SWITCHABLE_FILTERS]; |
3930 int pred_exists = 0; | 3922 int pred_exists = 0; |
3931 int uv_skippable; | 3923 int uv_skippable; |
3932 | 3924 |
| 3925 YV12_BUFFER_CONFIG *scaled_ref_frame[2] = {NULL, NULL}; |
| 3926 int ref; |
| 3927 |
| 3928 for (ref = 0; ref < 2; ++ref) { |
| 3929 scaled_ref_frame[ref] = mbmi->ref_frame[ref] > INTRA_FRAME ? |
| 3930 vp9_get_scaled_ref_frame(cpi, mbmi->ref_frame[ref]) : NULL; |
| 3931 |
| 3932 if (scaled_ref_frame[ref]) { |
| 3933 int i; |
| 3934 // Swap out the reference frame for a version that's been scaled to |
| 3935 // match the resolution of the current frame, allowing the existing |
| 3936 // motion search code to be used without additional modifications. |
| 3937 for (i = 0; i < MAX_MB_PLANE; i++) |
| 3938 backup_yv12[ref][i] = xd->plane[i].pre[ref]; |
| 3939 vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col, |
| 3940 NULL); |
| 3941 } |
| 3942 } |
| 3943 |
3933 this_rd_thresh = (ref_frame == LAST_FRAME) ? | 3944 this_rd_thresh = (ref_frame == LAST_FRAME) ? |
3934 rd_opt->threshes[segment_id][bsize][THR_LAST] : | 3945 rd_opt->threshes[segment_id][bsize][THR_LAST] : |
3935 rd_opt->threshes[segment_id][bsize][THR_ALTR]; | 3946 rd_opt->threshes[segment_id][bsize][THR_ALTR]; |
3936 this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? | 3947 this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? |
3937 rd_opt->threshes[segment_id][bsize][THR_GOLD] : this_rd_thresh; | 3948 rd_opt->threshes[segment_id][bsize][THR_GOLD] : this_rd_thresh; |
3938 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) | 3949 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; ++i) |
3939 filter_cache[i] = INT64_MAX; | 3950 filter_cache[i] = INT64_MAX; |
3940 | 3951 |
3941 if (cm->interp_filter != BILINEAR) { | 3952 if (cm->interp_filter != BILINEAR) { |
3942 tmp_best_filter = EIGHTTAP; | 3953 tmp_best_filter = EIGHTTAP; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4056 best_rd - VPXMIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), | 4067 best_rd - VPXMIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), |
4057 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); | 4068 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); |
4058 | 4069 |
4059 if (tmp_best_rdu > 0) { | 4070 if (tmp_best_rdu > 0) { |
4060 // If even the 'Y' rd value of split is higher than best so far | 4071 // If even the 'Y' rd value of split is higher than best so far |
4061 // then dont bother looking at UV | 4072 // then dont bother looking at UV |
4062 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, | 4073 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, |
4063 BLOCK_8X8); | 4074 BLOCK_8X8); |
4064 memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); | 4075 memset(x->skip_txfm, SKIP_TXFM_NONE, sizeof(x->skip_txfm)); |
4065 if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, | 4076 if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, |
4066 &uv_sse, BLOCK_8X8, tmp_best_rdu)) | 4077 &uv_sse, BLOCK_8X8, tmp_best_rdu)) { |
| 4078 for (ref = 0; ref < 2; ++ref) { |
| 4079 if (scaled_ref_frame[ref]) { |
| 4080 int i; |
| 4081 for (i = 0; i < MAX_MB_PLANE; ++i) |
| 4082 xd->plane[i].pre[ref] = backup_yv12[ref][i]; |
| 4083 } |
| 4084 } |
4067 continue; | 4085 continue; |
| 4086 } |
4068 | 4087 |
4069 rate2 += rate_uv; | 4088 rate2 += rate_uv; |
4070 distortion2 += distortion_uv; | 4089 distortion2 += distortion_uv; |
4071 skippable = skippable && uv_skippable; | 4090 skippable = skippable && uv_skippable; |
4072 total_sse += uv_sse; | 4091 total_sse += uv_sse; |
4073 } | 4092 } |
| 4093 |
| 4094 for (ref = 0; ref < 2; ++ref) { |
| 4095 if (scaled_ref_frame[ref]) { |
| 4096 // Restore the prediction frame pointers to their unscaled versions. |
| 4097 int i; |
| 4098 for (i = 0; i < MAX_MB_PLANE; ++i) |
| 4099 xd->plane[i].pre[ref] = backup_yv12[ref][i]; |
| 4100 } |
| 4101 } |
4074 } | 4102 } |
4075 | 4103 |
4076 if (cm->reference_mode == REFERENCE_MODE_SELECT) | 4104 if (cm->reference_mode == REFERENCE_MODE_SELECT) |
4077 rate2 += compmode_cost; | 4105 rate2 += compmode_cost; |
4078 | 4106 |
4079 // Estimate the reference frame signaling cost and add it | 4107 // Estimate the reference frame signaling cost and add it |
4080 // to the rolling cost variable. | 4108 // to the rolling cost variable. |
4081 if (second_ref_frame > INTRA_FRAME) { | 4109 if (second_ref_frame > INTRA_FRAME) { |
4082 rate2 += ref_costs_comp[ref_frame]; | 4110 rate2 += ref_costs_comp[ref_frame]; |
4083 } else { | 4111 } else { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4289 } | 4317 } |
4290 if (cm->interp_filter == SWITCHABLE) | 4318 if (cm->interp_filter == SWITCHABLE) |
4291 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 4319 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
4292 } else { | 4320 } else { |
4293 vp9_zero(best_filter_diff); | 4321 vp9_zero(best_filter_diff); |
4294 } | 4322 } |
4295 | 4323 |
4296 store_coding_context(x, ctx, best_ref_index, | 4324 store_coding_context(x, ctx, best_ref_index, |
4297 best_pred_diff, best_filter_diff, 0); | 4325 best_pred_diff, best_filter_diff, 0); |
4298 } | 4326 } |
OLD | NEW |