Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_rdopt.c

Issue 1217053002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rd.c ('k') | source/libvpx/vp9/encoder/vp9_resize.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1797 PREDICTION_MODE mode_selected = ZEROMV; 1797 PREDICTION_MODE mode_selected = ZEROMV;
1798 int64_t best_rd = INT64_MAX; 1798 int64_t best_rd = INT64_MAX;
1799 const int i = idy * 2 + idx; 1799 const int i = idy * 2 + idx;
1800 int ref; 1800 int ref;
1801 1801
1802 for (ref = 0; ref < 1 + has_second_rf; ++ref) { 1802 for (ref = 0; ref < 1 + has_second_rf; ++ref) {
1803 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; 1803 const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
1804 frame_mv[ZEROMV][frame].as_int = 0; 1804 frame_mv[ZEROMV][frame].as_int = 0;
1805 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col, 1805 vp9_append_sub8x8_mvs_for_idx(cm, xd, tile, i, ref, mi_row, mi_col,
1806 &frame_mv[NEARESTMV][frame], 1806 &frame_mv[NEARESTMV][frame],
1807 &frame_mv[NEARMV][frame]); 1807 &frame_mv[NEARMV][frame],
1808 xd->mi[0]->mbmi.mode_context);
1808 } 1809 }
1809 1810
1810 // search for the best motion vector on this segment 1811 // search for the best motion vector on this segment
1811 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { 1812 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) {
1812 const struct buf_2d orig_src = x->plane[0].src; 1813 const struct buf_2d orig_src = x->plane[0].src;
1813 struct buf_2d orig_pre[2]; 1814 struct buf_2d orig_pre[2];
1814 1815
1815 mode_idx = INTER_OFFSET(this_mode); 1816 mode_idx = INTER_OFFSET(this_mode);
1816 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; 1817 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX;
1817 if (!(inter_mode_mask & (1 << this_mode))) 1818 if (!(inter_mode_mask & (1 << this_mode)))
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 2113
2113 return bsi->segment_rd; 2114 return bsi->segment_rd;
2114 } 2115 }
2115 2116
2116 static void estimate_ref_frame_costs(const VP9_COMMON *cm, 2117 static void estimate_ref_frame_costs(const VP9_COMMON *cm,
2117 const MACROBLOCKD *xd, 2118 const MACROBLOCKD *xd,
2118 int segment_id, 2119 int segment_id,
2119 unsigned int *ref_costs_single, 2120 unsigned int *ref_costs_single,
2120 unsigned int *ref_costs_comp, 2121 unsigned int *ref_costs_comp,
2121 vp9_prob *comp_mode_p) { 2122 vp9_prob *comp_mode_p) {
2122 int seg_ref_active = vp9_segfeature_active(&cm->seg, segment_id, 2123 int seg_ref_active = segfeature_active(&cm->seg, segment_id,
2123 SEG_LVL_REF_FRAME); 2124 SEG_LVL_REF_FRAME);
2124 if (seg_ref_active) { 2125 if (seg_ref_active) {
2125 memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single)); 2126 memset(ref_costs_single, 0, MAX_REF_FRAMES * sizeof(*ref_costs_single));
2126 memset(ref_costs_comp, 0, MAX_REF_FRAMES * sizeof(*ref_costs_comp)); 2127 memset(ref_costs_comp, 0, MAX_REF_FRAMES * sizeof(*ref_costs_comp));
2127 *comp_mode_p = 128; 2128 *comp_mode_p = 128;
2128 } else { 2129 } else {
2129 vp9_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd); 2130 vp9_prob intra_inter_p = vp9_get_intra_inter_prob(cm, xd);
2130 vp9_prob comp_inter_p = 128; 2131 vp9_prob comp_inter_p = 128;
2131 2132
2132 if (cm->reference_mode == REFERENCE_MODE_SELECT) { 2133 if (cm->reference_mode == REFERENCE_MODE_SELECT) {
2133 comp_inter_p = vp9_get_reference_mode_prob(cm, xd); 2134 comp_inter_p = vp9_get_reference_mode_prob(cm, xd);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
2213 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 2214 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
2214 2215
2215 assert(yv12 != NULL); 2216 assert(yv12 != NULL);
2216 2217
2217 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this 2218 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
2218 // use the UV scaling factors. 2219 // use the UV scaling factors.
2219 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); 2220 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf);
2220 2221
2221 // Gets an initial list of candidate vectors from neighbours and orders them 2222 // Gets an initial list of candidate vectors from neighbours and orders them
2222 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col, 2223 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col,
2223 NULL, NULL); 2224 NULL, NULL, xd->mi[0]->mbmi.mode_context);
2224 2225
2225 // Candidate refinement carried out at encoder and decoder 2226 // Candidate refinement carried out at encoder and decoder
2226 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, 2227 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
2227 &frame_nearest_mv[ref_frame], 2228 &frame_nearest_mv[ref_frame],
2228 &frame_near_mv[ref_frame]); 2229 &frame_near_mv[ref_frame]);
2229 2230
2230 // Further refinement that is encode side only to test the top few candidates 2231 // Further refinement that is encode side only to test the top few candidates
2231 // in full and choose the best as the centre point for subsequent searches. 2232 // in full and choose the best as the centre point for subsequent searches.
2232 // The current implementation doesn't support scaling. 2233 // The current implementation doesn't support scaling.
2233 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) 2234 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8)
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
2999 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) { 3000 for (i = LAST_FRAME; i <= ALTREF_FRAME; ++i) {
3000 // Skip fixed mv modes for poor references 3001 // Skip fixed mv modes for poor references
3001 if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) { 3002 if ((x->pred_mv_sad[ref_frame] >> 2) > x->pred_mv_sad[i]) {
3002 mode_skip_mask[ref_frame] |= INTER_NEAREST_NEAR_ZERO; 3003 mode_skip_mask[ref_frame] |= INTER_NEAREST_NEAR_ZERO;
3003 break; 3004 break;
3004 } 3005 }
3005 } 3006 }
3006 } 3007 }
3007 // If the segment reference frame feature is enabled.... 3008 // If the segment reference frame feature is enabled....
3008 // then do nothing if the current ref frame is not allowed.. 3009 // then do nothing if the current ref frame is not allowed..
3009 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && 3010 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
3010 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { 3011 get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
3011 ref_frame_skip_mask[0] |= (1 << ref_frame); 3012 ref_frame_skip_mask[0] |= (1 << ref_frame);
3012 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK; 3013 ref_frame_skip_mask[1] |= SECOND_REF_FRAME_MASK;
3013 } 3014 }
3014 } 3015 }
3015 3016
3016 // Disable this drop out case if the ref frame 3017 // Disable this drop out case if the ref frame
3017 // segment level feature is enabled for this segment. This is to 3018 // segment level feature is enabled for this segment. This is to
3018 // prevent the possibility that we end up unable to pick any mode. 3019 // prevent the possibility that we end up unable to pick any mode.
3019 if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { 3020 if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) {
3020 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, 3021 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
3021 // unless ARNR filtering is enabled in which case we want 3022 // unless ARNR filtering is enabled in which case we want
3022 // an unfiltered alternative. We allow near/nearest as well 3023 // an unfiltered alternative. We allow near/nearest as well
3023 // because they may result in zero-zero MVs but be cheaper. 3024 // because they may result in zero-zero MVs but be cheaper.
3024 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { 3025 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) {
3025 ref_frame_skip_mask[0] = (1 << LAST_FRAME) | (1 << GOLDEN_FRAME); 3026 ref_frame_skip_mask[0] = (1 << LAST_FRAME) | (1 << GOLDEN_FRAME);
3026 ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK; 3027 ref_frame_skip_mask[1] = SECOND_REF_FRAME_MASK;
3027 mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO; 3028 mode_skip_mask[ALTREF_FRAME] = ~INTER_NEAREST_NEAR_ZERO;
3028 if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0) 3029 if (frame_mv[NEARMV][ALTREF_FRAME].as_int != 0)
3029 mode_skip_mask[ALTREF_FRAME] |= (1 << NEARMV); 3030 mode_skip_mask[ALTREF_FRAME] |= (1 << NEARMV);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
3188 if (comp_pred) { 3189 if (comp_pred) {
3189 if (!cpi->allow_comp_inter_inter) 3190 if (!cpi->allow_comp_inter_inter)
3190 continue; 3191 continue;
3191 3192
3192 // Skip compound inter modes if ARF is not available. 3193 // Skip compound inter modes if ARF is not available.
3193 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) 3194 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3194 continue; 3195 continue;
3195 3196
3196 // Do not allow compound prediction if the segment level reference frame 3197 // Do not allow compound prediction if the segment level reference frame
3197 // feature is in use as in this case there can only be one reference. 3198 // feature is in use as in this case there can only be one reference.
3198 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) 3199 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
3199 continue; 3200 continue;
3200 3201
3201 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && 3202 if ((mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
3202 best_mode_index >= 0 && best_mbmode.ref_frame[0] == INTRA_FRAME) 3203 best_mode_index >= 0 && best_mbmode.ref_frame[0] == INTRA_FRAME)
3203 continue; 3204 continue;
3204 3205
3205 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; 3206 mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
3206 } else { 3207 } else {
3207 if (ref_frame != INTRA_FRAME) 3208 if (ref_frame != INTRA_FRAME)
3208 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; 3209 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
3630 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp, 3631 estimate_ref_frame_costs(cm, xd, segment_id, ref_costs_single, ref_costs_comp,
3631 &comp_mode_p); 3632 &comp_mode_p);
3632 3633
3633 for (i = 0; i < MAX_REF_FRAMES; ++i) 3634 for (i = 0; i < MAX_REF_FRAMES; ++i)
3634 x->pred_sse[i] = INT_MAX; 3635 x->pred_sse[i] = INT_MAX;
3635 for (i = LAST_FRAME; i < MAX_REF_FRAMES; ++i) 3636 for (i = LAST_FRAME; i < MAX_REF_FRAMES; ++i)
3636 x->pred_mv_sad[i] = INT_MAX; 3637 x->pred_mv_sad[i] = INT_MAX;
3637 3638
3638 rd_cost->rate = INT_MAX; 3639 rd_cost->rate = INT_MAX;
3639 3640
3640 assert(vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)); 3641 assert(segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP));
3641 3642
3642 mbmi->mode = ZEROMV; 3643 mbmi->mode = ZEROMV;
3643 mbmi->uv_mode = DC_PRED; 3644 mbmi->uv_mode = DC_PRED;
3644 mbmi->ref_frame[0] = LAST_FRAME; 3645 mbmi->ref_frame[0] = LAST_FRAME;
3645 mbmi->ref_frame[1] = NONE; 3646 mbmi->ref_frame[1] = NONE;
3646 mbmi->mv[0].as_int = 0; 3647 mbmi->mv[0].as_int = 0;
3647 x->skip = 1; 3648 x->skip = 1;
3648 3649
3649 if (cm->interp_filter != BILINEAR) { 3650 if (cm->interp_filter != BILINEAR) {
3650 best_filter = EIGHTTAP; 3651 best_filter = EIGHTTAP;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
3842 continue; 3843 continue;
3843 3844
3844 comp_pred = second_ref_frame > INTRA_FRAME; 3845 comp_pred = second_ref_frame > INTRA_FRAME;
3845 if (comp_pred) { 3846 if (comp_pred) {
3846 if (!cpi->allow_comp_inter_inter) 3847 if (!cpi->allow_comp_inter_inter)
3847 continue; 3848 continue;
3848 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) 3849 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame]))
3849 continue; 3850 continue;
3850 // Do not allow compound prediction if the segment level reference frame 3851 // Do not allow compound prediction if the segment level reference frame
3851 // feature is in use as in this case there can only be one reference. 3852 // feature is in use as in this case there can only be one reference.
3852 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) 3853 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME))
3853 continue; 3854 continue;
3854 3855
3855 if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) && 3856 if ((sf->mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) &&
3856 best_mbmode.ref_frame[0] == INTRA_FRAME) 3857 best_mbmode.ref_frame[0] == INTRA_FRAME)
3857 continue; 3858 continue;
3858 } 3859 }
3859 3860
3860 // TODO(jingning, jkoleszar): scaling reference frame not supported for 3861 // TODO(jingning, jkoleszar): scaling reference frame not supported for
3861 // sub8x8 blocks. 3862 // sub8x8 blocks.
3862 if (ref_frame > INTRA_FRAME && 3863 if (ref_frame > INTRA_FRAME &&
3863 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf)) 3864 vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf))
3864 continue; 3865 continue;
3865 3866
3866 if (second_ref_frame > INTRA_FRAME && 3867 if (second_ref_frame > INTRA_FRAME &&
3867 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf)) 3868 vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf))
3868 continue; 3869 continue;
3869 3870
3870 if (comp_pred) 3871 if (comp_pred)
3871 mode_excluded = cm->reference_mode == SINGLE_REFERENCE; 3872 mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
3872 else if (ref_frame != INTRA_FRAME) 3873 else if (ref_frame != INTRA_FRAME)
3873 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE; 3874 mode_excluded = cm->reference_mode == COMPOUND_REFERENCE;
3874 3875
3875 // If the segment reference frame feature is enabled.... 3876 // If the segment reference frame feature is enabled....
3876 // then do nothing if the current ref frame is not allowed.. 3877 // then do nothing if the current ref frame is not allowed..
3877 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && 3878 if (segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) &&
3878 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) { 3879 get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != (int)ref_frame) {
3879 continue; 3880 continue;
3880 // Disable this drop out case if the ref frame 3881 // Disable this drop out case if the ref frame
3881 // segment level feature is enabled for this segment. This is to 3882 // segment level feature is enabled for this segment. This is to
3882 // prevent the possibility that we end up unable to pick any mode. 3883 // prevent the possibility that we end up unable to pick any mode.
3883 } else if (!vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) { 3884 } else if (!segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) {
3884 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, 3885 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame,
3885 // unless ARNR filtering is enabled in which case we want 3886 // unless ARNR filtering is enabled in which case we want
3886 // an unfiltered alternative. We allow near/nearest as well 3887 // an unfiltered alternative. We allow near/nearest as well
3887 // because they may result in zero-zero MVs but be cheaper. 3888 // because they may result in zero-zero MVs but be cheaper.
3888 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) 3889 if (cpi->rc.is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0))
3889 continue; 3890 continue;
3890 } 3891 }
3891 3892
3892 mbmi->tx_size = TX_4X4; 3893 mbmi->tx_size = TX_4X4;
3893 mbmi->uv_mode = DC_PRED; 3894 mbmi->uv_mode = DC_PRED;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
4304 } 4305 }
4305 if (cm->interp_filter == SWITCHABLE) 4306 if (cm->interp_filter == SWITCHABLE)
4306 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); 4307 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
4307 } else { 4308 } else {
4308 vp9_zero(best_filter_diff); 4309 vp9_zero(best_filter_diff);
4309 } 4310 }
4310 4311
4311 store_coding_context(x, ctx, best_ref_index, 4312 store_coding_context(x, ctx, best_ref_index,
4312 best_pred_diff, best_tx_diff, best_filter_diff, 0); 4313 best_pred_diff, best_tx_diff, best_filter_diff, 0);
4313 } 4314 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rd.c ('k') | source/libvpx/vp9/encoder/vp9_resize.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698