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

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

Issue 958693004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 10 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_skin_detection.h » ('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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 dist_block(plane, block, tx_size, args); 502 dist_block(plane, block, tx_size, args);
503 #endif // CONFIG_VP9_HIGHBITDEPTH 503 #endif // CONFIG_VP9_HIGHBITDEPTH
504 } else if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 2) { 504 } else if (x->skip_txfm[(plane << 2) + (block >> (tx_size << 1))] == 2) {
505 // compute DC coefficient 505 // compute DC coefficient
506 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block); 506 tran_low_t *const coeff = BLOCK_OFFSET(x->plane[plane].coeff, block);
507 tran_low_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block); 507 tran_low_t *const dqcoeff = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block);
508 vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size); 508 vp9_xform_quant_dc(x, plane, block, plane_bsize, tx_size);
509 args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4; 509 args->sse = x->bsse[(plane << 2) + (block >> (tx_size << 1))] << 4;
510 args->dist = args->sse; 510 args->dist = args->sse;
511 if (x->plane[plane].eobs[block]) { 511 if (x->plane[plane].eobs[block]) {
512 int64_t dc_correct = coeff[0] * coeff[0] - 512 const int64_t orig_sse = (int64_t)coeff[0] * coeff[0];
513 (coeff[0] - dqcoeff[0]) * (coeff[0] - dqcoeff[0]); 513 const int64_t resd_sse = coeff[0] - dqcoeff[0];
514 int64_t dc_correct = orig_sse - resd_sse * resd_sse;
514 #if CONFIG_VP9_HIGHBITDEPTH 515 #if CONFIG_VP9_HIGHBITDEPTH
515 dc_correct >>= ((xd->bd - 8) * 2); 516 dc_correct >>= ((xd->bd - 8) * 2);
516 #endif 517 #endif
517 if (tx_size != TX_32X32) 518 if (tx_size != TX_32X32)
518 dc_correct >>= 2; 519 dc_correct >>= 2;
519 520
520 args->dist = MAX(0, args->sse - dc_correct); 521 args->dist = MAX(0, args->sse - dc_correct);
521 } 522 }
522 } else { 523 } else {
523 // skip forward transform 524 // skip forward transform
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1852 best_rd = bsi->rdstat[i][mode_idx].brdcost; 1853 best_rd = bsi->rdstat[i][mode_idx].brdcost;
1853 } 1854 }
1854 } /*for each 4x4 mode*/ 1855 } /*for each 4x4 mode*/
1855 1856
1856 if (best_rd == INT64_MAX) { 1857 if (best_rd == INT64_MAX) {
1857 int iy, midx; 1858 int iy, midx;
1858 for (iy = i + 1; iy < 4; ++iy) 1859 for (iy = i + 1; iy < 4; ++iy)
1859 for (midx = 0; midx < INTER_MODES; ++midx) 1860 for (midx = 0; midx < INTER_MODES; ++midx)
1860 bsi->rdstat[iy][midx].brdcost = INT64_MAX; 1861 bsi->rdstat[iy][midx].brdcost = INT64_MAX;
1861 bsi->segment_rd = INT64_MAX; 1862 bsi->segment_rd = INT64_MAX;
1862 return INT64_MAX;; 1863 return INT64_MAX;
1863 } 1864 }
1864 1865
1865 mode_idx = INTER_OFFSET(mode_selected); 1866 mode_idx = INTER_OFFSET(mode_selected);
1866 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above)); 1867 vpx_memcpy(t_above, bsi->rdstat[i][mode_idx].ta, sizeof(t_above));
1867 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left)); 1868 vpx_memcpy(t_left, bsi->rdstat[i][mode_idx].tl, sizeof(t_left));
1868 1869
1869 set_and_cost_bmi_mvs(cpi, xd, i, mode_selected, mode_mv[mode_selected], 1870 set_and_cost_bmi_mvs(cpi, xd, i, mode_selected, mode_mv[mode_selected],
1870 frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost, 1871 frame_mv, seg_mvs[i], bsi->ref_mv, x->nmvjointcost,
1871 x->mvcost); 1872 x->mvcost);
1872 1873
1873 br += bsi->rdstat[i][mode_idx].brate; 1874 br += bsi->rdstat[i][mode_idx].brate;
1874 bd += bsi->rdstat[i][mode_idx].bdist; 1875 bd += bsi->rdstat[i][mode_idx].bdist;
1875 block_sse += bsi->rdstat[i][mode_idx].bsse; 1876 block_sse += bsi->rdstat[i][mode_idx].bsse;
1876 segmentyrate += bsi->rdstat[i][mode_idx].byrate; 1877 segmentyrate += bsi->rdstat[i][mode_idx].byrate;
1877 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; 1878 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost;
1878 1879
1879 if (this_segment_rd > bsi->segment_rd) { 1880 if (this_segment_rd > bsi->segment_rd) {
1880 int iy, midx; 1881 int iy, midx;
1881 for (iy = i + 1; iy < 4; ++iy) 1882 for (iy = i + 1; iy < 4; ++iy)
1882 for (midx = 0; midx < INTER_MODES; ++midx) 1883 for (midx = 0; midx < INTER_MODES; ++midx)
1883 bsi->rdstat[iy][midx].brdcost = INT64_MAX; 1884 bsi->rdstat[iy][midx].brdcost = INT64_MAX;
1884 bsi->segment_rd = INT64_MAX; 1885 bsi->segment_rd = INT64_MAX;
1885 return INT64_MAX;; 1886 return INT64_MAX;
1886 } 1887 }
1887 } 1888 }
1888 } /* for each label */ 1889 } /* for each label */
1889 1890
1890 bsi->r = br; 1891 bsi->r = br;
1891 bsi->d = bd; 1892 bsi->d = bd;
1892 bsi->segment_yrate = segmentyrate; 1893 bsi->segment_yrate = segmentyrate;
1893 bsi->segment_rd = this_segment_rd; 1894 bsi->segment_rd = this_segment_rd;
1894 bsi->sse = block_sse; 1895 bsi->sse = block_sse;
1895 1896
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 MACROBLOCKD *const xd = &x->e_mbd; 2020 MACROBLOCKD *const xd = &x->e_mbd;
2020 MODE_INFO *const mi = xd->mi[0].src_mi; 2021 MODE_INFO *const mi = xd->mi[0].src_mi;
2021 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame]; 2022 int_mv *const candidates = mi->mbmi.ref_mvs[ref_frame];
2022 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf; 2023 const struct scale_factors *const sf = &cm->frame_refs[ref_frame - 1].sf;
2023 2024
2024 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this 2025 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this
2025 // use the UV scaling factors. 2026 // use the UV scaling factors.
2026 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); 2027 vp9_setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf);
2027 2028
2028 // Gets an initial list of candidate vectors from neighbours and orders them 2029 // Gets an initial list of candidate vectors from neighbours and orders them
2029 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col); 2030 vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col,
2031 NULL, NULL);
2030 2032
2031 // Candidate refinement carried out at encoder and decoder 2033 // Candidate refinement carried out at encoder and decoder
2032 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, 2034 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates,
2033 &frame_nearest_mv[ref_frame], 2035 &frame_nearest_mv[ref_frame],
2034 &frame_near_mv[ref_frame]); 2036 &frame_near_mv[ref_frame]);
2035 2037
2036 // Further refinement that is encode side only to test the top few candidates 2038 // Further refinement that is encode side only to test the top few candidates
2037 // in full and choose the best as the centre point for subsequent searches. 2039 // in full and choose the best as the centre point for subsequent searches.
2038 // The current implementation doesn't support scaling. 2040 // The current implementation doesn't support scaling.
2039 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8) 2041 if (!vp9_is_scaled(sf) && block_size >= BLOCK_8X8)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 2099
2098 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64) { 2100 if (cpi->sf.adaptive_motion_search && bsize < BLOCK_64X64) {
2099 int boffset = 2 * (b_width_log2_lookup[BLOCK_64X64] - 2101 int boffset = 2 * (b_width_log2_lookup[BLOCK_64X64] -
2100 MIN(b_height_log2_lookup[bsize], b_width_log2_lookup[bsize])); 2102 MIN(b_height_log2_lookup[bsize], b_width_log2_lookup[bsize]));
2101 step_param = MAX(step_param, boffset); 2103 step_param = MAX(step_param, boffset);
2102 } 2104 }
2103 2105
2104 if (cpi->sf.adaptive_motion_search) { 2106 if (cpi->sf.adaptive_motion_search) {
2105 int bwl = b_width_log2_lookup[bsize]; 2107 int bwl = b_width_log2_lookup[bsize];
2106 int bhl = b_height_log2_lookup[bsize]; 2108 int bhl = b_height_log2_lookup[bsize];
2107 int i;
2108 int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4); 2109 int tlevel = x->pred_mv_sad[ref] >> (bwl + bhl + 4);
2109 2110
2110 if (tlevel < 5) 2111 if (tlevel < 5)
2111 step_param += 2; 2112 step_param += 2;
2112 2113
2113 for (i = LAST_FRAME; i <= ALTREF_FRAME && cm->show_frame; ++i) { 2114 // prev_mv_sad is not setup for dynamically scaled frames.
2114 if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) { 2115 if (cpi->oxcf.resize_mode != RESIZE_DYNAMIC) {
2115 x->pred_mv[ref].row = 0; 2116 int i;
2116 x->pred_mv[ref].col = 0; 2117 for (i = LAST_FRAME; i <= ALTREF_FRAME && cm->show_frame; ++i) {
2117 tmp_mv->as_int = INVALID_MV; 2118 if ((x->pred_mv_sad[ref] >> 3) > x->pred_mv_sad[i]) {
2119 x->pred_mv[ref].row = 0;
2120 x->pred_mv[ref].col = 0;
2121 tmp_mv->as_int = INVALID_MV;
2118 2122
2119 if (scaled_ref_frame) { 2123 if (scaled_ref_frame) {
2120 int i; 2124 int i;
2121 for (i = 0; i < MAX_MB_PLANE; i++) 2125 for (i = 0; i < MAX_MB_PLANE; ++i)
2122 xd->plane[i].pre[0] = backup_yv12[i]; 2126 xd->plane[i].pre[0] = backup_yv12[i];
2127 }
2128 return;
2123 } 2129 }
2124 return;
2125 } 2130 }
2126 } 2131 }
2127 } 2132 }
2128 2133
2129 mvp_full = pred_mv[x->mv_best_ref_index[ref]]; 2134 mvp_full = pred_mv[x->mv_best_ref_index[ref]];
2130 2135
2131 mvp_full.col >>= 3; 2136 mvp_full.col >>= 3;
2132 mvp_full.row >>= 3; 2137 mvp_full.row >>= 3;
2133 2138
2134 bestsme = vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb, 2139 bestsme = vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb,
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
3040 case ALTREF_FRAME: 3045 case ALTREF_FRAME:
3041 ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK; 3046 ref_frame_skip_mask[0] |= ALT_REF_MODE_MASK;
3042 break; 3047 break;
3043 case NONE: 3048 case NONE:
3044 case MAX_REF_FRAMES: 3049 case MAX_REF_FRAMES:
3045 assert(0 && "Invalid Reference frame"); 3050 assert(0 && "Invalid Reference frame");
3046 break; 3051 break;
3047 } 3052 }
3048 } 3053 }
3049 3054
3050 if (ref_frame_skip_mask[0] & (1 << ref_frame) && 3055 if ((ref_frame_skip_mask[0] & (1 << ref_frame)) &&
3051 ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame))) 3056 (ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame))))
3052 continue; 3057 continue;
3053 3058
3054 if (mode_skip_mask[ref_frame] & (1 << this_mode)) 3059 if (mode_skip_mask[ref_frame] & (1 << this_mode))
3055 continue; 3060 continue;
3056 3061
3057 // Test best rd so far against threshold for trying this mode. 3062 // Test best rd so far against threshold for trying this mode.
3058 if (best_mode_skippable && sf->schedule_mode_search) 3063 if (best_mode_skippable && sf->schedule_mode_search)
3059 mode_threshold[mode_index] <<= 1; 3064 mode_threshold[mode_index] <<= 1;
3060 3065
3061 if (best_rd < mode_threshold[mode_index]) 3066 if (best_rd < mode_threshold[mode_index])
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
3510 } 3515 }
3511 3516
3512 for (plane = max_plane; plane < MAX_MB_PLANE; ++plane) { 3517 for (plane = max_plane; plane < MAX_MB_PLANE; ++plane) {
3513 x->plane[plane].eobs = ctx->eobs_pbuf[plane][2]; 3518 x->plane[plane].eobs = ctx->eobs_pbuf[plane][2];
3514 has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane); 3519 has_high_freq_coeff |= vp9_has_high_freq_in_plane(x, bsize, plane);
3515 } 3520 }
3516 3521
3517 best_mode_skippable |= !has_high_freq_coeff; 3522 best_mode_skippable |= !has_high_freq_coeff;
3518 } 3523 }
3519 3524
3525 assert(best_mode_index >= 0);
3526
3520 store_coding_context(x, ctx, best_mode_index, best_pred_diff, 3527 store_coding_context(x, ctx, best_mode_index, best_pred_diff,
3521 best_tx_diff, best_filter_diff, best_mode_skippable); 3528 best_tx_diff, best_filter_diff, best_mode_skippable);
3522 } 3529 }
3523 3530
3524 void vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi, 3531 void vp9_rd_pick_inter_mode_sb_seg_skip(VP9_COMP *cpi,
3525 TileDataEnc *tile_data, 3532 TileDataEnc *tile_data,
3526 MACROBLOCK *x, 3533 MACROBLOCK *x,
3527 RD_COST *rd_cost, 3534 RD_COST *rd_cost,
3528 BLOCK_SIZE bsize, 3535 BLOCK_SIZE bsize,
3529 PICK_MODE_CONTEXT *ctx, 3536 PICK_MODE_CONTEXT *ctx,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3743 ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << LAST_FRAME); 3750 ref_frame_skip_mask[0] |= (1 << GOLDEN_FRAME) | (1 << LAST_FRAME);
3744 break; 3751 break;
3745 case NONE: 3752 case NONE:
3746 case MAX_REF_FRAMES: 3753 case MAX_REF_FRAMES:
3747 assert(0 && "Invalid Reference frame"); 3754 assert(0 && "Invalid Reference frame");
3748 break; 3755 break;
3749 } 3756 }
3750 } 3757 }
3751 } 3758 }
3752 3759
3753 if (ref_frame_skip_mask[0] & (1 << ref_frame) && 3760 if ((ref_frame_skip_mask[0] & (1 << ref_frame)) &&
3754 ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame))) 3761 (ref_frame_skip_mask[1] & (1 << MAX(0, second_ref_frame))))
3755 continue; 3762 continue;
3756 3763
3757 // Test best rd so far against threshold for trying this mode. 3764 // Test best rd so far against threshold for trying this mode.
3758 if (rd_less_than_thresh(best_rd, 3765 if (rd_less_than_thresh(best_rd,
3759 rd_opt->threshes[segment_id][bsize][ref_index], 3766 rd_opt->threshes[segment_id][bsize][ref_index],
3760 tile_data->thresh_freq_fact[bsize][ref_index])) 3767 tile_data->thresh_freq_fact[bsize][ref_index]))
3761 continue; 3768 continue;
3762 3769
3763 comp_pred = second_ref_frame > INTRA_FRAME; 3770 comp_pred = second_ref_frame > INTRA_FRAME;
3764 if (comp_pred) { 3771 if (comp_pred) {
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
4225 if (cm->interp_filter == SWITCHABLE) 4232 if (cm->interp_filter == SWITCHABLE)
4226 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); 4233 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0);
4227 } else { 4234 } else {
4228 vp9_zero(best_filter_diff); 4235 vp9_zero(best_filter_diff);
4229 } 4236 }
4230 4237
4231 store_coding_context(x, ctx, best_ref_index, 4238 store_coding_context(x, ctx, best_ref_index,
4232 best_pred_diff, best_tx_diff, best_filter_diff, 0); 4239 best_pred_diff, best_tx_diff, best_filter_diff, 0);
4233 } 4240 }
4234 4241
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_rd.c ('k') | source/libvpx/vp9/encoder/vp9_skin_detection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698