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

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

Issue 1339513003: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 3 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_mcomp.c ('k') | source/libvpx/vp9/encoder/vp9_ratectrl.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) 2014 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2014 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 <limits.h> 12 #include <limits.h>
13 #include <math.h> 13 #include <math.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 15
16 #include "./vp9_rtcd.h" 16 #include "./vp9_rtcd.h"
17 #include "./vpx_dsp_rtcd.h" 17 #include "./vpx_dsp_rtcd.h"
18 18
19 #include "vpx_dsp/vpx_dsp_common.h"
19 #include "vpx_mem/vpx_mem.h" 20 #include "vpx_mem/vpx_mem.h"
20 #include "vpx_ports/mem.h" 21 #include "vpx_ports/mem.h"
21 22
22 #include "vp9/common/vp9_blockd.h" 23 #include "vp9/common/vp9_blockd.h"
23 #include "vp9/common/vp9_common.h" 24 #include "vp9/common/vp9_common.h"
24 #include "vp9/common/vp9_mvref_common.h" 25 #include "vp9/common/vp9_mvref_common.h"
25 #include "vp9/common/vp9_pred_common.h" 26 #include "vp9/common/vp9_pred_common.h"
26 #include "vp9/common/vp9_reconinter.h" 27 #include "vp9/common/vp9_reconinter.h"
27 #include "vp9/common/vp9_reconintra.h" 28 #include "vp9/common/vp9_reconintra.h"
28 #include "vp9/common/vp9_scan.h" 29 #include "vp9/common/vp9_scan.h"
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 } 681 }
681 } 682 }
682 683
683 if (*skippable == 0) { 684 if (*skippable == 0) {
684 *rate <<= 10; 685 *rate <<= 10;
685 *rate += (eob_cost << 8); 686 *rate += (eob_cost << 8);
686 } 687 }
687 } 688 }
688 #endif 689 #endif
689 690
690 static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE bsize, 691 static void model_rd_for_sb_uv(VP9_COMP *cpi, BLOCK_SIZE plane_bsize,
691 MACROBLOCK *x, MACROBLOCKD *xd, 692 MACROBLOCK *x, MACROBLOCKD *xd,
692 int *out_rate_sum, int64_t *out_dist_sum, 693 int *out_rate_sum, int64_t *out_dist_sum,
693 unsigned int *var_y, unsigned int *sse_y) { 694 unsigned int *var_y, unsigned int *sse_y,
695 int start_plane, int stop_plane) {
694 // Note our transform coeffs are 8 times an orthogonal transform. 696 // Note our transform coeffs are 8 times an orthogonal transform.
695 // Hence quantizer step is also 8 times. To get effective quantizer 697 // Hence quantizer step is also 8 times. To get effective quantizer
696 // we need to divide by 8 before sending to modeling function. 698 // we need to divide by 8 before sending to modeling function.
697 unsigned int sse; 699 unsigned int sse;
698 int rate; 700 int rate;
699 int64_t dist; 701 int64_t dist;
700 int i; 702 int i;
701 703
702 *out_rate_sum = 0; 704 *out_rate_sum = 0;
703 *out_dist_sum = 0; 705 *out_dist_sum = 0;
704 706
705 for (i = 1; i <= 2; ++i) { 707 for (i = start_plane; i <= stop_plane; ++i) {
706 struct macroblock_plane *const p = &x->plane[i]; 708 struct macroblock_plane *const p = &x->plane[i];
707 struct macroblockd_plane *const pd = &xd->plane[i]; 709 struct macroblockd_plane *const pd = &xd->plane[i];
708 const uint32_t dc_quant = pd->dequant[0]; 710 const uint32_t dc_quant = pd->dequant[0];
709 const uint32_t ac_quant = pd->dequant[1]; 711 const uint32_t ac_quant = pd->dequant[1];
710 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); 712 const BLOCK_SIZE bs = plane_bsize;
711 unsigned int var; 713 unsigned int var;
712 714
713 if (!x->color_sensitivity[i - 1]) 715 if (!x->color_sensitivity[i - 1])
714 continue; 716 continue;
715 717
716 var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, 718 var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride,
717 pd->dst.buf, pd->dst.stride, &sse); 719 pd->dst.buf, pd->dst.stride, &sse);
718 *var_y += var; 720 *var_y += var;
719 *sse_y += sse; 721 *sse_y += sse;
720 722
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 struct macroblock_plane *const p = &x->plane[0]; 887 struct macroblock_plane *const p = &x->plane[0];
886 struct macroblockd_plane *const pd = &xd->plane[0]; 888 struct macroblockd_plane *const pd = &xd->plane[0];
887 const BLOCK_SIZE bsize_tx = txsize_to_bsize[tx_size]; 889 const BLOCK_SIZE bsize_tx = txsize_to_bsize[tx_size];
888 uint8_t *const src_buf_base = p->src.buf; 890 uint8_t *const src_buf_base = p->src.buf;
889 uint8_t *const dst_buf_base = pd->dst.buf; 891 uint8_t *const dst_buf_base = pd->dst.buf;
890 const int src_stride = p->src.stride; 892 const int src_stride = p->src.stride;
891 const int dst_stride = pd->dst.stride; 893 const int dst_stride = pd->dst.stride;
892 int i, j; 894 int i, j;
893 int rate; 895 int rate;
894 int64_t dist; 896 int64_t dist;
895 int64_t this_sse = INT64_MAX;
896 int is_skippable;
897 897
898 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j); 898 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
899 assert(plane == 0);
900 (void) plane;
901 899
902 p->src.buf = &src_buf_base[4 * (j * src_stride + i)]; 900 p->src.buf = &src_buf_base[4 * (j * src_stride + i)];
903 pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)]; 901 pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)];
904 // Use source buffer as an approximation for the fully reconstructed buffer. 902 // Use source buffer as an approximation for the fully reconstructed buffer.
905 vp9_predict_intra_block(xd, b_width_log2_lookup[plane_bsize], 903 vp9_predict_intra_block(xd, b_width_log2_lookup[plane_bsize],
906 tx_size, args->mode, 904 tx_size, args->mode,
907 x->skip_encode ? p->src.buf : pd->dst.buf, 905 x->skip_encode ? p->src.buf : pd->dst.buf,
908 x->skip_encode ? src_stride : dst_stride, 906 x->skip_encode ? src_stride : dst_stride,
909 pd->dst.buf, dst_stride, 907 pd->dst.buf, dst_stride,
910 i, j, 0); 908 i, j, plane);
911 909
912 // TODO(jingning): This needs further refactoring. 910 if (plane == 0) {
913 block_yrd(cpi, x, &rate, &dist, &is_skippable, &this_sse, 0, 911 int64_t this_sse = INT64_MAX;
914 bsize_tx, VPXMIN(tx_size, TX_16X16)); 912 int is_skippable;
915 x->skip_txfm[0] = is_skippable; 913 // TODO(jingning): This needs further refactoring.
916 rate += vp9_cost_bit(vp9_get_skip_prob(&cpi->common, xd), is_skippable); 914 block_yrd(cpi, x, &rate, &dist, &is_skippable, &this_sse, 0,
915 bsize_tx, VPXMIN(tx_size, TX_16X16));
916 x->skip_txfm[0] = is_skippable;
917 // TODO(jingning): Skip is signalled per prediciton block not per tx block.
918 rate += vp9_cost_bit(vp9_get_skip_prob(&cpi->common, xd), is_skippable);
919 } else {
920 unsigned int var, sse;
921 model_rd_for_sb_uv(cpi, plane_bsize, x, xd, &rate, &dist, &var, &sse,
922 plane, plane);
923 }
917 924
918 p->src.buf = src_buf_base; 925 p->src.buf = src_buf_base;
919 pd->dst.buf = dst_buf_base; 926 pd->dst.buf = dst_buf_base;
920 args->rate += rate; 927 args->rate += rate;
921 args->dist += dist; 928 args->dist += dist;
922 } 929 }
923 930
924 static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][4] = { 931 static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][4] = {
925 {THR_DC, THR_V_PRED, THR_H_PRED, THR_TM}, 932 {THR_DC, THR_V_PRED, THR_H_PRED, THR_TM},
926 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV}, 933 {THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV},
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 } 1442 }
1436 } else { 1443 } else {
1437 this_rdc.rate += cm->interp_filter == SWITCHABLE ? 1444 this_rdc.rate += cm->interp_filter == SWITCHABLE ?
1438 vp9_get_switchable_rate(cpi, xd) : 0; 1445 vp9_get_switchable_rate(cpi, xd) : 0;
1439 this_rdc.rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); 1446 this_rdc.rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1);
1440 } 1447 }
1441 1448
1442 if (x->color_sensitivity[0] || x->color_sensitivity[1]) { 1449 if (x->color_sensitivity[0] || x->color_sensitivity[1]) {
1443 int uv_rate = 0; 1450 int uv_rate = 0;
1444 int64_t uv_dist = 0; 1451 int64_t uv_dist = 0;
1452 const BLOCK_SIZE uv_bsize = get_plane_block_size(bsize, &xd->plane[1]);
1445 if (x->color_sensitivity[0]) 1453 if (x->color_sensitivity[0])
1446 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 1); 1454 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 1);
1447 if (x->color_sensitivity[1]) 1455 if (x->color_sensitivity[1])
1448 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 2); 1456 vp9_build_inter_predictors_sbp(xd, mi_row, mi_col, bsize, 2);
1449 model_rd_for_sb_uv(cpi, bsize, x, xd, &uv_rate, &uv_dist, 1457 model_rd_for_sb_uv(cpi, uv_bsize, x, xd, &uv_rate, &uv_dist,
1450 &var_y, &sse_y); 1458 &var_y, &sse_y, 1, 2);
1451 this_rdc.rate += uv_rate; 1459 this_rdc.rate += uv_rate;
1452 this_rdc.dist += uv_dist; 1460 this_rdc.dist += uv_dist;
1453 } 1461 }
1454 1462
1455 this_rdc.rate += rate_mv; 1463 this_rdc.rate += rate_mv;
1456 this_rdc.rate += 1464 this_rdc.rate +=
1457 cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]][INTER_OFFSET( 1465 cpi->inter_mode_cost[x->mbmi_ext->mode_context[ref_frame]][INTER_OFFSET(
1458 this_mode)]; 1466 this_mode)];
1459 this_rdc.rate += ref_frame_cost[ref_frame]; 1467 this_rdc.rate += ref_frame_cost[ref_frame];
1460 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, this_rdc.rate, this_rdc.dist); 1468 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, this_rdc.rate, this_rdc.dist);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 continue; 1571 continue;
1564 1572
1565 mbmi->mode = this_mode; 1573 mbmi->mode = this_mode;
1566 mbmi->ref_frame[0] = INTRA_FRAME; 1574 mbmi->ref_frame[0] = INTRA_FRAME;
1567 args.mode = this_mode; 1575 args.mode = this_mode;
1568 args.rate = 0; 1576 args.rate = 0;
1569 args.dist = 0; 1577 args.dist = 0;
1570 mbmi->tx_size = intra_tx_size; 1578 mbmi->tx_size = intra_tx_size;
1571 vp9_foreach_transformed_block_in_plane(xd, bsize, 0, 1579 vp9_foreach_transformed_block_in_plane(xd, bsize, 0,
1572 estimate_block_intra, &args); 1580 estimate_block_intra, &args);
1581 // Inter and intra RD will mismatch in scale for non-screen content.
1582 if (cpi->oxcf.content == VP9E_CONTENT_SCREEN) {
1583 if (x->color_sensitivity[0])
1584 vp9_foreach_transformed_block_in_plane(xd, bsize, 1,
1585 estimate_block_intra, &args);
1586 if (x->color_sensitivity[1])
1587 vp9_foreach_transformed_block_in_plane(xd, bsize, 2,
1588 estimate_block_intra, &args);
1589 }
1573 this_rdc.rate = args.rate; 1590 this_rdc.rate = args.rate;
1574 this_rdc.dist = args.dist; 1591 this_rdc.dist = args.dist;
1575 this_rdc.rate += cpi->mbmode_cost[this_mode]; 1592 this_rdc.rate += cpi->mbmode_cost[this_mode];
1576 this_rdc.rate += ref_frame_cost[INTRA_FRAME]; 1593 this_rdc.rate += ref_frame_cost[INTRA_FRAME];
1577 this_rdc.rate += intra_cost_penalty; 1594 this_rdc.rate += intra_cost_penalty;
1578 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv, 1595 this_rdc.rdcost = RDCOST(x->rdmult, x->rddiv,
1579 this_rdc.rate, this_rdc.dist); 1596 this_rdc.rate, this_rdc.dist);
1580 1597
1581 if (this_rdc.rdcost < best_rdc.rdcost) { 1598 if (this_rdc.rdcost < best_rdc.rdcost) {
1582 best_rdc = this_rdc; 1599 best_rdc = this_rdc;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 } 1925 }
1909 } 1926 }
1910 mbmi->mode = xd->mi[0]->bmi[3].as_mode; 1927 mbmi->mode = xd->mi[0]->bmi[3].as_mode;
1911 ctx->mic = *(xd->mi[0]); 1928 ctx->mic = *(xd->mi[0]);
1912 ctx->mbmi_ext = *x->mbmi_ext; 1929 ctx->mbmi_ext = *x->mbmi_ext;
1913 ctx->skip_txfm[0] = SKIP_TXFM_NONE; 1930 ctx->skip_txfm[0] = SKIP_TXFM_NONE;
1914 ctx->skip = 0; 1931 ctx->skip = 0;
1915 // Dummy assignment for speed -5. No effect in speed -6. 1932 // Dummy assignment for speed -5. No effect in speed -6.
1916 rd_cost->rdcost = best_rd; 1933 rd_cost->rdcost = best_rd;
1917 } 1934 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_mcomp.c ('k') | source/libvpx/vp9/encoder/vp9_ratectrl.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698