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

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

Issue 1302353004: 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_ratectrl.c ('k') | source/libvpx/vp9/encoder/vp9_rdopt.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
11 #include <assert.h> 11 #include <assert.h>
12 #include <math.h> 12 #include <math.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 14
15 #include "./vp9_rtcd.h" 15 #include "./vp9_rtcd.h"
16 16
17 #include "vpx_mem/vpx_mem.h" 17 #include "vpx_mem/vpx_mem.h"
18 #include "vpx_ports/bitops.h"
18 #include "vpx_ports/mem.h" 19 #include "vpx_ports/mem.h"
20 #include "vpx_ports/system_state.h"
19 21
20 #include "vp9/common/vp9_common.h" 22 #include "vp9/common/vp9_common.h"
21 #include "vp9/common/vp9_entropy.h" 23 #include "vp9/common/vp9_entropy.h"
22 #include "vp9/common/vp9_entropymode.h" 24 #include "vp9/common/vp9_entropymode.h"
23 #include "vp9/common/vp9_mvref_common.h" 25 #include "vp9/common/vp9_mvref_common.h"
24 #include "vp9/common/vp9_pred_common.h" 26 #include "vp9/common/vp9_pred_common.h"
25 #include "vp9/common/vp9_quant_common.h" 27 #include "vp9/common/vp9_quant_common.h"
26 #include "vp9/common/vp9_reconinter.h" 28 #include "vp9/common/vp9_reconinter.h"
27 #include "vp9/common/vp9_reconintra.h" 29 #include "vp9/common/vp9_reconintra.h"
28 #include "vp9/common/vp9_seg_common.h" 30 #include "vp9/common/vp9_seg_common.h"
29 #include "vp9/common/vp9_systemdependent.h"
30 31
31 #include "vp9/encoder/vp9_cost.h" 32 #include "vp9/encoder/vp9_cost.h"
32 #include "vp9/encoder/vp9_encodemb.h" 33 #include "vp9/encoder/vp9_encodemb.h"
33 #include "vp9/encoder/vp9_encodemv.h" 34 #include "vp9/encoder/vp9_encodemv.h"
34 #include "vp9/encoder/vp9_encoder.h" 35 #include "vp9/encoder/vp9_encoder.h"
35 #include "vp9/encoder/vp9_mcomp.h" 36 #include "vp9/encoder/vp9_mcomp.h"
36 #include "vp9/encoder/vp9_quantize.h" 37 #include "vp9/encoder/vp9_quantize.h"
37 #include "vp9/encoder/vp9_ratectrl.h" 38 #include "vp9/encoder/vp9_ratectrl.h"
38 #include "vp9/encoder/vp9_rd.h" 39 #include "vp9/encoder/vp9_rd.h"
39 #include "vp9/encoder/vp9_tokenize.h" 40 #include "vp9/encoder/vp9_tokenize.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 default: 165 default:
165 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); 166 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
166 return -1; 167 return -1;
167 } 168 }
168 #else 169 #else
169 int64_t rdmult = 88 * q * q / 24; 170 int64_t rdmult = 88 * q * q / 24;
170 #endif // CONFIG_VP9_HIGHBITDEPTH 171 #endif // CONFIG_VP9_HIGHBITDEPTH
171 if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { 172 if (cpi->oxcf.pass == 2 && (cpi->common.frame_type != KEY_FRAME)) {
172 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; 173 const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
173 const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index]; 174 const FRAME_UPDATE_TYPE frame_type = gf_group->update_type[gf_group->index];
174 const int boost_index = MIN(15, (cpi->rc.gfu_boost / 100)); 175 const int boost_index = VPXMIN(15, (cpi->rc.gfu_boost / 100));
175 176
176 rdmult = (rdmult * rd_frame_type_factor[frame_type]) >> 7; 177 rdmult = (rdmult * rd_frame_type_factor[frame_type]) >> 7;
177 rdmult += ((rdmult * rd_boost_factor[boost_index]) >> 7); 178 rdmult += ((rdmult * rd_boost_factor[boost_index]) >> 7);
178 } 179 }
180 if (rdmult < 1)
181 rdmult = 1;
179 return (int)rdmult; 182 return (int)rdmult;
180 } 183 }
181 184
182 static int compute_rd_thresh_factor(int qindex, vpx_bit_depth_t bit_depth) { 185 static int compute_rd_thresh_factor(int qindex, vpx_bit_depth_t bit_depth) {
183 double q; 186 double q;
184 #if CONFIG_VP9_HIGHBITDEPTH 187 #if CONFIG_VP9_HIGHBITDEPTH
185 switch (bit_depth) { 188 switch (bit_depth) {
186 case VPX_BITS_8: 189 case VPX_BITS_8:
187 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0; 190 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0;
188 break; 191 break;
189 case VPX_BITS_10: 192 case VPX_BITS_10:
190 q = vp9_dc_quant(qindex, 0, VPX_BITS_10) / 16.0; 193 q = vp9_dc_quant(qindex, 0, VPX_BITS_10) / 16.0;
191 break; 194 break;
192 case VPX_BITS_12: 195 case VPX_BITS_12:
193 q = vp9_dc_quant(qindex, 0, VPX_BITS_12) / 64.0; 196 q = vp9_dc_quant(qindex, 0, VPX_BITS_12) / 64.0;
194 break; 197 break;
195 default: 198 default:
196 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); 199 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
197 return -1; 200 return -1;
198 } 201 }
199 #else 202 #else
200 (void) bit_depth; 203 (void) bit_depth;
201 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0; 204 q = vp9_dc_quant(qindex, 0, VPX_BITS_8) / 4.0;
202 #endif // CONFIG_VP9_HIGHBITDEPTH 205 #endif // CONFIG_VP9_HIGHBITDEPTH
203 // TODO(debargha): Adjust the function below. 206 // TODO(debargha): Adjust the function below.
204 return MAX((int)(pow(q, RD_THRESH_POW) * 5.12), 8); 207 return VPXMAX((int)(pow(q, RD_THRESH_POW) * 5.12), 8);
205 } 208 }
206 209
207 void vp9_initialize_me_consts(VP9_COMP *cpi, MACROBLOCK *x, int qindex) { 210 void vp9_initialize_me_consts(VP9_COMP *cpi, MACROBLOCK *x, int qindex) {
208 #if CONFIG_VP9_HIGHBITDEPTH 211 #if CONFIG_VP9_HIGHBITDEPTH
209 switch (cpi->common.bit_depth) { 212 switch (cpi->common.bit_depth) {
210 case VPX_BITS_8: 213 case VPX_BITS_8:
211 x->sadperbit16 = sad_per_bit16lut_8[qindex]; 214 x->sadperbit16 = sad_per_bit16lut_8[qindex];
212 x->sadperbit4 = sad_per_bit4lut_8[qindex]; 215 x->sadperbit4 = sad_per_bit4lut_8[qindex];
213 break; 216 break;
214 case VPX_BITS_10: 217 case VPX_BITS_10:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 264 }
262 } 265 }
263 266
264 void vp9_initialize_rd_consts(VP9_COMP *cpi) { 267 void vp9_initialize_rd_consts(VP9_COMP *cpi) {
265 VP9_COMMON *const cm = &cpi->common; 268 VP9_COMMON *const cm = &cpi->common;
266 MACROBLOCK *const x = &cpi->td.mb; 269 MACROBLOCK *const x = &cpi->td.mb;
267 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd; 270 MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
268 RD_OPT *const rd = &cpi->rd; 271 RD_OPT *const rd = &cpi->rd;
269 int i; 272 int i;
270 273
271 vp9_clear_system_state(); 274 vpx_clear_system_state();
272 275
273 rd->RDDIV = RDDIV_BITS; // In bits (to multiply D by 128). 276 rd->RDDIV = RDDIV_BITS; // In bits (to multiply D by 128).
274 rd->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q); 277 rd->RDMULT = vp9_compute_rd_mult(cpi, cm->base_qindex + cm->y_dc_delta_q);
275 278
276 x->errorperbit = rd->RDMULT / RD_MULT_EPB_RATIO; 279 x->errorperbit = rd->RDMULT / RD_MULT_EPB_RATIO;
277 x->errorperbit += (x->errorperbit == 0); 280 x->errorperbit += (x->errorperbit == 0);
278 281
279 x->select_tx_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL && 282 x->select_tx_size = (cpi->sf.tx_size_search_method == USE_LARGESTALL &&
280 cm->frame_type != KEY_FRAME) ? 0 : 1; 283 cm->frame_type != KEY_FRAME) ? 0 : 1;
281 284
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // application - Part I: Fundamental Theory", IEEE Trans. Circ. 397 // application - Part I: Fundamental Theory", IEEE Trans. Circ.
395 // Sys. for Video Tech., April 1997. 398 // Sys. for Video Tech., April 1997.
396 if (var == 0) { 399 if (var == 0) {
397 *rate = 0; 400 *rate = 0;
398 *dist = 0; 401 *dist = 0;
399 } else { 402 } else {
400 int d_q10, r_q10; 403 int d_q10, r_q10;
401 static const uint32_t MAX_XSQ_Q10 = 245727; 404 static const uint32_t MAX_XSQ_Q10 = 245727;
402 const uint64_t xsq_q10_64 = 405 const uint64_t xsq_q10_64 =
403 (((uint64_t)qstep * qstep << (n_log2 + 10)) + (var >> 1)) / var; 406 (((uint64_t)qstep * qstep << (n_log2 + 10)) + (var >> 1)) / var;
404 const int xsq_q10 = (int)MIN(xsq_q10_64, MAX_XSQ_Q10); 407 const int xsq_q10 = (int)VPXMIN(xsq_q10_64, MAX_XSQ_Q10);
405 model_rd_norm(xsq_q10, &r_q10, &d_q10); 408 model_rd_norm(xsq_q10, &r_q10, &d_q10);
406 *rate = ((r_q10 << n_log2) + 2) >> 2; 409 *rate = ((r_q10 << n_log2) + 2) >> 2;
407 *dist = (var * (int64_t)d_q10 + 512) >> 10; 410 *dist = (var * (int64_t)d_q10 + 512) >> 10;
408 } 411 }
409 } 412 }
410 413
411 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size, 414 void vp9_get_entropy_contexts(BLOCK_SIZE bsize, TX_SIZE tx_size,
412 const struct macroblockd_plane *pd, 415 const struct macroblockd_plane *pd,
413 ENTROPY_CONTEXT t_above[16], 416 ENTROPY_CONTEXT t_above[16],
414 ENTROPY_CONTEXT t_left[16]) { 417 ENTROPY_CONTEXT t_left[16]) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 x->mbmi_ext->ref_mvs[ref_frame][1].as_int; 478 x->mbmi_ext->ref_mvs[ref_frame][1].as_int;
476 // Get the sad for each candidate reference mv. 479 // Get the sad for each candidate reference mv.
477 for (i = 0; i < num_mv_refs; ++i) { 480 for (i = 0; i < num_mv_refs; ++i) {
478 const MV *this_mv = &pred_mv[i]; 481 const MV *this_mv = &pred_mv[i];
479 int fp_row, fp_col; 482 int fp_row, fp_col;
480 483
481 if (i == 1 && near_same_nearest) 484 if (i == 1 && near_same_nearest)
482 continue; 485 continue;
483 fp_row = (this_mv->row + 3 + (this_mv->row >= 0)) >> 3; 486 fp_row = (this_mv->row + 3 + (this_mv->row >= 0)) >> 3;
484 fp_col = (this_mv->col + 3 + (this_mv->col >= 0)) >> 3; 487 fp_col = (this_mv->col + 3 + (this_mv->col >= 0)) >> 3;
485 max_mv = MAX(max_mv, MAX(abs(this_mv->row), abs(this_mv->col)) >> 3); 488 max_mv = VPXMAX(max_mv, VPXMAX(abs(this_mv->row), abs(this_mv->col)) >> 3);
486 489
487 if (fp_row ==0 && fp_col == 0 && zero_seen) 490 if (fp_row ==0 && fp_col == 0 && zero_seen)
488 continue; 491 continue;
489 zero_seen |= (fp_row ==0 && fp_col == 0); 492 zero_seen |= (fp_row ==0 && fp_col == 0);
490 493
491 ref_y_ptr =&ref_y_buffer[ref_y_stride * fp_row + fp_col]; 494 ref_y_ptr =&ref_y_buffer[ref_y_stride * fp_row + fp_col];
492 // Find sad for current vector. 495 // Find sad for current vector.
493 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride, 496 this_sad = cpi->fn_ptr[block_size].sdf(src_y_ptr, x->plane[0].src.stride,
494 ref_y_ptr, ref_y_stride); 497 ref_y_ptr, ref_y_stride);
495 // Note if it is the best so far. 498 // Note if it is the best so far.
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 const int idx = cpi->oxcf.mode == BEST; 622 const int idx = cpi->oxcf.mode == BEST;
620 memcpy(rd->thresh_mult_sub8x8, thresh_mult[idx], sizeof(thresh_mult[idx])); 623 memcpy(rd->thresh_mult_sub8x8, thresh_mult[idx], sizeof(thresh_mult[idx]));
621 } 624 }
622 625
623 void vp9_update_rd_thresh_fact(int (*factor_buf)[MAX_MODES], int rd_thresh, 626 void vp9_update_rd_thresh_fact(int (*factor_buf)[MAX_MODES], int rd_thresh,
624 int bsize, int best_mode_index) { 627 int bsize, int best_mode_index) {
625 if (rd_thresh > 0) { 628 if (rd_thresh > 0) {
626 const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES; 629 const int top_mode = bsize < BLOCK_8X8 ? MAX_REFS : MAX_MODES;
627 int mode; 630 int mode;
628 for (mode = 0; mode < top_mode; ++mode) { 631 for (mode = 0; mode < top_mode; ++mode) {
629 const BLOCK_SIZE min_size = MAX(bsize - 1, BLOCK_4X4); 632 const BLOCK_SIZE min_size = VPXMAX(bsize - 1, BLOCK_4X4);
630 const BLOCK_SIZE max_size = MIN(bsize + 2, BLOCK_64X64); 633 const BLOCK_SIZE max_size = VPXMIN(bsize + 2, BLOCK_64X64);
631 BLOCK_SIZE bs; 634 BLOCK_SIZE bs;
632 for (bs = min_size; bs <= max_size; ++bs) { 635 for (bs = min_size; bs <= max_size; ++bs) {
633 int *const fact = &factor_buf[bs][mode]; 636 int *const fact = &factor_buf[bs][mode];
634 if (mode == best_mode_index) { 637 if (mode == best_mode_index) {
635 *fact -= (*fact >> 4); 638 *fact -= (*fact >> 4);
636 } else { 639 } else {
637 *fact = MIN(*fact + RD_THRESH_INC, 640 *fact = VPXMIN(*fact + RD_THRESH_INC, rd_thresh * RD_THRESH_MAX_FACT);
638 rd_thresh * RD_THRESH_MAX_FACT);
639 } 641 }
640 } 642 }
641 } 643 }
642 } 644 }
643 } 645 }
644 646
645 int vp9_get_intra_cost_penalty(int qindex, int qdelta, 647 int vp9_get_intra_cost_penalty(int qindex, int qdelta,
646 vpx_bit_depth_t bit_depth) { 648 vpx_bit_depth_t bit_depth) {
647 const int q = vp9_dc_quant(qindex, qdelta, bit_depth); 649 const int q = vp9_dc_quant(qindex, qdelta, bit_depth);
648 #if CONFIG_VP9_HIGHBITDEPTH 650 #if CONFIG_VP9_HIGHBITDEPTH
649 switch (bit_depth) { 651 switch (bit_depth) {
650 case VPX_BITS_8: 652 case VPX_BITS_8:
651 return 20 * q; 653 return 20 * q;
652 case VPX_BITS_10: 654 case VPX_BITS_10:
653 return 5 * q; 655 return 5 * q;
654 case VPX_BITS_12: 656 case VPX_BITS_12:
655 return ROUND_POWER_OF_TWO(5 * q, 2); 657 return ROUND_POWER_OF_TWO(5 * q, 2);
656 default: 658 default:
657 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12"); 659 assert(0 && "bit_depth should be VPX_BITS_8, VPX_BITS_10 or VPX_BITS_12");
658 return -1; 660 return -1;
659 } 661 }
660 #else 662 #else
661 return 20 * q; 663 return 20 * q;
662 #endif // CONFIG_VP9_HIGHBITDEPTH 664 #endif // CONFIG_VP9_HIGHBITDEPTH
663 } 665 }
664 666
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_ratectrl.c ('k') | source/libvpx/vp9/encoder/vp9_rdopt.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698