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

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

Issue 1162573005: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 6 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_encodeframe.h ('k') | source/libvpx/vp9/encoder/vp9_encodemb.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 <limits.h> 11 #include <limits.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 #include "./vpx_dsp_rtcd.h"
16 #include "./vpx_config.h" 17 #include "./vpx_config.h"
17 18
19 #include "vpx_ports/mem.h"
18 #include "vpx_ports/vpx_timer.h" 20 #include "vpx_ports/vpx_timer.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_idct.h" 25 #include "vp9/common/vp9_idct.h"
24 #include "vp9/common/vp9_mvref_common.h" 26 #include "vp9/common/vp9_mvref_common.h"
25 #include "vp9/common/vp9_pred_common.h" 27 #include "vp9/common/vp9_pred_common.h"
26 #include "vp9/common/vp9_quant_common.h" 28 #include "vp9/common/vp9_quant_common.h"
27 #include "vp9/common/vp9_reconintra.h" 29 #include "vp9/common/vp9_reconintra.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 v->sum_square_error = s2; 355 v->sum_square_error = s2;
354 v->sum_error = s; 356 v->sum_error = s;
355 v->log2_count = c; 357 v->log2_count = c;
356 } 358 }
357 359
358 static void get_variance(var *v) { 360 static void get_variance(var *v) {
359 v->variance = (int)(256 * (v->sum_square_error - 361 v->variance = (int)(256 * (v->sum_square_error -
360 ((v->sum_error * v->sum_error) >> v->log2_count)) >> v->log2_count); 362 ((v->sum_error * v->sum_error) >> v->log2_count)) >> v->log2_count);
361 } 363 }
362 364
363 void sum_2_variances(const var *a, const var *b, var *r) { 365 static void sum_2_variances(const var *a, const var *b, var *r) {
364 assert(a->log2_count == b->log2_count); 366 assert(a->log2_count == b->log2_count);
365 fill_variance(a->sum_square_error + b->sum_square_error, 367 fill_variance(a->sum_square_error + b->sum_square_error,
366 a->sum_error + b->sum_error, a->log2_count + 1, r); 368 a->sum_error + b->sum_error, a->log2_count + 1, r);
367 } 369 }
368 370
369 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { 371 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) {
370 variance_node node; 372 variance_node node;
371 tree_to_node(data, bsize, &node); 373 tree_to_node(data, bsize, &node);
372 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); 374 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]);
373 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); 375 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 set_block_size(cpi, xd, mi_row + block_height / 2, mi_col, subsize); 457 set_block_size(cpi, xd, mi_row + block_height / 2, mi_col, subsize);
456 return 1; 458 return 1;
457 } 459 }
458 } 460 }
459 461
460 return 0; 462 return 0;
461 } 463 }
462 return 0; 464 return 0;
463 } 465 }
464 466
465 void vp9_set_vbp_thresholds(VP9_COMP *cpi, int q) { 467 // Set the variance split thresholds for following the block sizes:
468 // 0 - threshold_64x64, 1 - threshold_32x32, 2 - threshold_16x16,
469 // 3 - vbp_threshold_8x8. vbp_threshold_8x8 (to split to 4x4 partition) is
470 // currently only used on key frame.
471 static void set_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) {
472 VP9_COMMON *const cm = &cpi->common;
473 const int is_key_frame = (cm->frame_type == KEY_FRAME);
474 const int threshold_multiplier = is_key_frame ? 20 : 1;
475 const int64_t threshold_base = (int64_t)(threshold_multiplier *
476 cpi->y_dequant[q][1]);
477 if (is_key_frame) {
478 thresholds[0] = threshold_base;
479 thresholds[1] = threshold_base >> 2;
480 thresholds[2] = threshold_base >> 2;
481 thresholds[3] = threshold_base << 2;
482 } else {
483 thresholds[1] = threshold_base;
484 if (cm->width <= 352 && cm->height <= 288) {
485 thresholds[0] = threshold_base >> 2;
486 thresholds[2] = threshold_base << 3;
487 } else {
488 thresholds[0] = threshold_base;
489 thresholds[1] = (5 * threshold_base) >> 2;
490 if (cm->width >= 1920 && cm->height >= 1080)
491 thresholds[1] = (7 * threshold_base) >> 2;
492 thresholds[2] = threshold_base << cpi->oxcf.speed;
493 }
494 }
495 }
496
497 void vp9_set_variance_partition_thresholds(VP9_COMP *cpi, int q) {
498 VP9_COMMON *const cm = &cpi->common;
466 SPEED_FEATURES *const sf = &cpi->sf; 499 SPEED_FEATURES *const sf = &cpi->sf;
500 const int is_key_frame = (cm->frame_type == KEY_FRAME);
467 if (sf->partition_search_type != VAR_BASED_PARTITION && 501 if (sf->partition_search_type != VAR_BASED_PARTITION &&
468 sf->partition_search_type != REFERENCE_PARTITION) { 502 sf->partition_search_type != REFERENCE_PARTITION) {
469 return; 503 return;
470 } else { 504 } else {
471 VP9_COMMON *const cm = &cpi->common; 505 set_vbp_thresholds(cpi, cpi->vbp_thresholds, q);
472 const int is_key_frame = (cm->frame_type == KEY_FRAME); 506 // The thresholds below are not changed locally.
473 const int threshold_multiplier = is_key_frame ? 20 : 1;
474 const int64_t threshold_base = (int64_t)(threshold_multiplier *
475 cpi->y_dequant[q][1]);
476
477 // TODO(marpan): Allow 4x4 partitions for inter-frames.
478 // use_4x4_partition = (variance4x4downsample[i2 + j] == 1);
479 // If 4x4 partition is not used, then 8x8 partition will be selected
480 // if variance of 16x16 block is very high, so use larger threshold
481 // for 16x16 (threshold_bsize_min) in that case.
482
483 // Array index: 0 - threshold_64x64; 1 - threshold_32x32;
484 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
485 if (is_key_frame) { 507 if (is_key_frame) {
486 cpi->vbp_thresholds[0] = threshold_base;
487 cpi->vbp_thresholds[1] = threshold_base >> 2;
488 cpi->vbp_thresholds[2] = threshold_base >> 2;
489 cpi->vbp_thresholds[3] = threshold_base << 2;
490 cpi->vbp_threshold_sad = 0; 508 cpi->vbp_threshold_sad = 0;
491 cpi->vbp_bsize_min = BLOCK_8X8; 509 cpi->vbp_bsize_min = BLOCK_8X8;
492 } else { 510 } else {
493 cpi->vbp_thresholds[1] = threshold_base; 511 if (cm->width <= 352 && cm->height <= 288)
494 if (cm->width <= 352 && cm->height <= 288) {
495 cpi->vbp_thresholds[0] = threshold_base >> 2;
496 cpi->vbp_thresholds[2] = threshold_base << 3;
497 cpi->vbp_threshold_sad = 100; 512 cpi->vbp_threshold_sad = 100;
498 } else { 513 else
499 cpi->vbp_thresholds[0] = threshold_base;
500 cpi->vbp_thresholds[1] = (5 * threshold_base) >> 2;
501 cpi->vbp_thresholds[2] = threshold_base << cpi->oxcf.speed;
502 cpi->vbp_threshold_sad = (cpi->y_dequant[q][1] << 1) > 1000 ? 514 cpi->vbp_threshold_sad = (cpi->y_dequant[q][1] << 1) > 1000 ?
503 (cpi->y_dequant[q][1] << 1) : 1000; 515 (cpi->y_dequant[q][1] << 1) : 1000;
504 }
505 cpi->vbp_bsize_min = BLOCK_16X16; 516 cpi->vbp_bsize_min = BLOCK_16X16;
506 } 517 }
507 cpi->vbp_threshold_minmax = 15 + (q >> 3); 518 cpi->vbp_threshold_minmax = 15 + (q >> 3);
508 } 519 }
509 } 520 }
510 521
511 // Compute the minmax over the 8x8 subblocks. 522 // Compute the minmax over the 8x8 subblocks.
512 static int compute_minmax_8x8(const uint8_t *s, int sp, const uint8_t *d, 523 static int compute_minmax_8x8(const uint8_t *s, int sp, const uint8_t *d,
513 int dp, int x16_idx, int y16_idx, 524 int dp, int x16_idx, int y16_idx,
514 #if CONFIG_VP9_HIGHBITDEPTH 525 #if CONFIG_VP9_HIGHBITDEPTH
(...skipping 28 matching lines...) Expand all
543 #endif 554 #endif
544 if ((max - min) > minmax_max) 555 if ((max - min) > minmax_max)
545 minmax_max = (max - min); 556 minmax_max = (max - min);
546 if ((max - min) < minmax_min) 557 if ((max - min) < minmax_min)
547 minmax_min = (max - min); 558 minmax_min = (max - min);
548 } 559 }
549 } 560 }
550 return (minmax_max - minmax_min); 561 return (minmax_max - minmax_min);
551 } 562 }
552 563
553 static void modify_vbp_thresholds(VP9_COMP *cpi, int64_t thresholds[], int q) {
554 VP9_COMMON *const cm = &cpi->common;
555 const int64_t threshold_base = (int64_t)(cpi->y_dequant[q][1]);
556
557 // Array index: 0 - threshold_64x64; 1 - threshold_32x32;
558 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
559 thresholds[1] = threshold_base;
560 if (cm->width <= 352 && cm->height <= 288) {
561 thresholds[0] = threshold_base >> 2;
562 thresholds[2] = threshold_base << 3;
563 } else {
564 thresholds[0] = threshold_base;
565 thresholds[1] = (5 * threshold_base) >> 2;
566 thresholds[2] = threshold_base << cpi->oxcf.speed;
567 }
568 }
569
570 static void fill_variance_4x4avg(const uint8_t *s, int sp, const uint8_t *d, 564 static void fill_variance_4x4avg(const uint8_t *s, int sp, const uint8_t *d,
571 int dp, int x8_idx, int y8_idx, v8x8 *vst, 565 int dp, int x8_idx, int y8_idx, v8x8 *vst,
572 #if CONFIG_VP9_HIGHBITDEPTH 566 #if CONFIG_VP9_HIGHBITDEPTH
573 int highbd_flag, 567 int highbd_flag,
574 #endif 568 #endif
575 int pixels_wide, 569 int pixels_wide,
576 int pixels_high, 570 int pixels_high,
577 int is_key_frame) { 571 int is_key_frame) {
578 int k; 572 int k;
579 for (k = 0; k < 4; k++) { 573 for (k = 0; k < 4; k++) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 int variance4x4downsample[16]; 666 int variance4x4downsample[16];
673 667
674 int segment_id = CR_SEGMENT_ID_BASE; 668 int segment_id = CR_SEGMENT_ID_BASE;
675 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) { 669 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) {
676 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map : 670 const uint8_t *const map = cm->seg.update_map ? cpi->segmentation_map :
677 cm->last_frame_seg_map; 671 cm->last_frame_seg_map;
678 segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col); 672 segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col);
679 673
680 if (cyclic_refresh_segment_id_boosted(segment_id)) { 674 if (cyclic_refresh_segment_id_boosted(segment_id)) {
681 int q = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); 675 int q = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
682 modify_vbp_thresholds(cpi, thresholds, q); 676 set_vbp_thresholds(cpi, thresholds, q);
683 } 677 }
684 } 678 }
685 679
686 set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64); 680 set_offsets(cpi, tile, x, mi_row, mi_col, BLOCK_64X64);
687 681
688 if (xd->mb_to_right_edge < 0) 682 if (xd->mb_to_right_edge < 0)
689 pixels_wide += (xd->mb_to_right_edge >> 3); 683 pixels_wide += (xd->mb_to_right_edge >> 3);
690 if (xd->mb_to_bottom_edge < 0) 684 if (xd->mb_to_bottom_edge < 0)
691 pixels_high += (xd->mb_to_bottom_edge >> 3); 685 pixels_high += (xd->mb_to_bottom_edge >> 3);
692 686
(...skipping 23 matching lines...) Expand all
716 } 710 }
717 711
718 vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col, 712 vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col,
719 &cm->frame_refs[LAST_FRAME - 1].sf); 713 &cm->frame_refs[LAST_FRAME - 1].sf);
720 mbmi->ref_frame[0] = LAST_FRAME; 714 mbmi->ref_frame[0] = LAST_FRAME;
721 mbmi->ref_frame[1] = NONE; 715 mbmi->ref_frame[1] = NONE;
722 mbmi->sb_type = BLOCK_64X64; 716 mbmi->sb_type = BLOCK_64X64;
723 mbmi->mv[0].as_int = 0; 717 mbmi->mv[0].as_int = 0;
724 mbmi->interp_filter = BILINEAR; 718 mbmi->interp_filter = BILINEAR;
725 719
726 y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize); 720 y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize, mi_row, mi_col);
727 if (y_sad_g < y_sad) { 721 if (y_sad_g < y_sad) {
728 vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col, 722 vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
729 &cm->frame_refs[GOLDEN_FRAME - 1].sf); 723 &cm->frame_refs[GOLDEN_FRAME - 1].sf);
730 mbmi->ref_frame[0] = GOLDEN_FRAME; 724 mbmi->ref_frame[0] = GOLDEN_FRAME;
731 mbmi->mv[0].as_int = 0; 725 mbmi->mv[0].as_int = 0;
732 y_sad = y_sad_g; 726 y_sad = y_sad_g;
733 } else { 727 } else {
734 x->pred_mv[LAST_FRAME] = mbmi->mv[0].as_mv; 728 x->pred_mv[LAST_FRAME] = mbmi->mv[0].as_mv;
735 } 729 }
736 730
(...skipping 2927 matching lines...) Expand 10 before | Expand all | Expand 10 after
3664 int i, j; 3658 int i, j;
3665 3659
3666 memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0])); 3660 memset(hist, 0, VAR_HIST_BINS * sizeof(hist[0]));
3667 3661
3668 for (i = 0; i < cm->mb_rows; i++) { 3662 for (i = 0; i < cm->mb_rows; i++) {
3669 for (j = 0; j < cm->mb_cols; j++) { 3663 for (j = 0; j < cm->mb_cols; j++) {
3670 #if CONFIG_VP9_HIGHBITDEPTH 3664 #if CONFIG_VP9_HIGHBITDEPTH
3671 if (cm->use_highbitdepth) { 3665 if (cm->use_highbitdepth) {
3672 switch (cm->bit_depth) { 3666 switch (cm->bit_depth) {
3673 case VPX_BITS_8: 3667 case VPX_BITS_8:
3674 vp9_highbd_get16x16var(src, src_stride, last_src, last_stride, 3668 vpx_highbd_8_get16x16var(src, src_stride, last_src, last_stride,
3675 &var16->sse, &var16->sum); 3669 &var16->sse, &var16->sum);
3676 break; 3670 break;
3677 case VPX_BITS_10: 3671 case VPX_BITS_10:
3678 vp9_highbd_10_get16x16var(src, src_stride, last_src, last_stride, 3672 vpx_highbd_10_get16x16var(src, src_stride, last_src, last_stride,
3679 &var16->sse, &var16->sum); 3673 &var16->sse, &var16->sum);
3680 break; 3674 break;
3681 case VPX_BITS_12: 3675 case VPX_BITS_12:
3682 vp9_highbd_12_get16x16var(src, src_stride, last_src, last_stride, 3676 vpx_highbd_12_get16x16var(src, src_stride, last_src, last_stride,
3683 &var16->sse, &var16->sum); 3677 &var16->sse, &var16->sum);
3684 break; 3678 break;
3685 default: 3679 default:
3686 assert(0 && "cm->bit_depth should be VPX_BITS_8, VPX_BITS_10" 3680 assert(0 && "cm->bit_depth should be VPX_BITS_8, VPX_BITS_10"
3687 " or VPX_BITS_12"); 3681 " or VPX_BITS_12");
3688 return -1; 3682 return -1;
3689 } 3683 }
3690 } else { 3684 } else {
3691 vp9_get16x16var(src, src_stride, last_src, last_stride, 3685 vpx_get16x16var(src, src_stride, last_src, last_stride,
3692 &var16->sse, &var16->sum); 3686 &var16->sse, &var16->sum);
3693 } 3687 }
3694 #else 3688 #else
3695 vp9_get16x16var(src, src_stride, last_src, last_stride, 3689 vpx_get16x16var(src, src_stride, last_src, last_stride,
3696 &var16->sse, &var16->sum); 3690 &var16->sse, &var16->sum);
3697 #endif // CONFIG_VP9_HIGHBITDEPTH 3691 #endif // CONFIG_VP9_HIGHBITDEPTH
3698 var16->var = var16->sse - 3692 var16->var = var16->sse -
3699 (((uint32_t)var16->sum * var16->sum) >> 8); 3693 (((uint32_t)var16->sum * var16->sum) >> 8);
3700 3694
3701 if (var16->var >= VAR_HIST_MAX_BG_VAR) 3695 if (var16->var >= VAR_HIST_MAX_BG_VAR)
3702 hist[VAR_HIST_BINS - 1]++; 3696 hist[VAR_HIST_BINS - 1]++;
3703 else 3697 else
3704 hist[var16->var / VAR_HIST_FACTOR]++; 3698 hist[var16->var / VAR_HIST_FACTOR]++;
3705 3699
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
4220 4214
4221 for (y = 0; y < mi_height; y++) 4215 for (y = 0; y < mi_height; y++)
4222 for (x = 0; x < mi_width; x++) 4216 for (x = 0; x < mi_width; x++)
4223 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) 4217 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows)
4224 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; 4218 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size;
4225 } 4219 }
4226 ++td->counts->tx.tx_totals[mbmi->tx_size]; 4220 ++td->counts->tx.tx_totals[mbmi->tx_size];
4227 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])]; 4221 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])];
4228 } 4222 }
4229 } 4223 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encodeframe.h ('k') | source/libvpx/vp9/encoder/vp9_encodemb.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698