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

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

Issue 1015483002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 9 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
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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 int segment_id) { 409 int segment_id) {
410 VP9_COMMON * const cm = &cpi->common; 410 VP9_COMMON * const cm = &cpi->common;
411 variance_node vt; 411 variance_node vt;
412 const int block_width = num_8x8_blocks_wide_lookup[bsize]; 412 const int block_width = num_8x8_blocks_wide_lookup[bsize];
413 const int block_height = num_8x8_blocks_high_lookup[bsize]; 413 const int block_height = num_8x8_blocks_high_lookup[bsize];
414 414
415 assert(block_height == block_width); 415 assert(block_height == block_width);
416 tree_to_node(data, bsize, &vt); 416 tree_to_node(data, bsize, &vt);
417 417
418 // No 64x64 blocks on segments other than base (un-boosted) segment. 418 // No 64x64 blocks on segments other than base (un-boosted) segment.
419 if (segment_id != CR_SEGMENT_ID_BASE && bsize == BLOCK_64X64) 419 if (cyclic_refresh_segment_id_boosted(segment_id) && bsize == BLOCK_64X64)
420 return 0; 420 return 0;
421 421
422 // For bsize=bsize_min (16x16/8x8 for 8x8/4x4 downsampling), select if 422 // For bsize=bsize_min (16x16/8x8 for 8x8/4x4 downsampling), select if
423 // variance is below threshold, otherwise split will be selected. 423 // variance is below threshold, otherwise split will be selected.
424 // No check for vert/horiz split as too few samples for variance. 424 // No check for vert/horiz split as too few samples for variance.
425 if (bsize == bsize_min) { 425 if (bsize == bsize_min) {
426 get_variance(&vt.part_variances->none); 426 get_variance(&vt.part_variances->none);
427 if (mi_col + block_width / 2 < cm->mi_cols && 427 if (mi_col + block_width / 2 < cm->mi_cols &&
428 mi_row + block_height / 2 < cm->mi_rows && 428 mi_row + block_height / 2 < cm->mi_rows &&
429 vt.part_variances->none.variance < threshold) { 429 vt.part_variances->none.variance < threshold) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 } 474 }
475 475
476 return 0; 476 return 0;
477 } 477 }
478 return 0; 478 return 0;
479 } 479 }
480 480
481 481
482 void vp9_set_vbp_thresholds(VP9_COMP *cpi, int q) { 482 void vp9_set_vbp_thresholds(VP9_COMP *cpi, int q) {
483 SPEED_FEATURES *const sf = &cpi->sf; 483 SPEED_FEATURES *const sf = &cpi->sf;
484 if (sf->partition_search_type != VAR_BASED_PARTITION) { 484 if (sf->partition_search_type != VAR_BASED_PARTITION &&
485 sf->partition_search_type != REFERENCE_PARTITION) {
485 return; 486 return;
486 } else { 487 } else {
487 VP9_COMMON *const cm = &cpi->common; 488 VP9_COMMON *const cm = &cpi->common;
488 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 489 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
489 const int is_key_frame = (cm->frame_type == KEY_FRAME); 490 const int is_key_frame = (cm->frame_type == KEY_FRAME);
490 const int use_4x4_partition = is_key_frame; 491 const int use_4x4_partition = is_key_frame;
491 const int low_res = (cm->width <= 352 && cm->height <= 288); 492 const int low_res = (cm->width <= 352 && cm->height <= 288);
492 const int threshold_multiplier = is_key_frame ? 80 : 4; 493 const int threshold_multiplier = is_key_frame ? 80 : 4;
493 const int64_t threshold_base = (int64_t)(threshold_multiplier * 494 const int64_t threshold_base = (int64_t)(threshold_multiplier *
494 vp9_convert_qindex_to_q(q, cm->bit_depth)); 495 vp9_convert_qindex_to_q(q, cm->bit_depth));
(...skipping 12 matching lines...) Expand all
507 // use_4x4_partition = (variance4x4downsample[i2 + j] == 1); 508 // use_4x4_partition = (variance4x4downsample[i2 + j] == 1);
508 // If 4x4 partition is not used, then 8x8 partition will be selected 509 // If 4x4 partition is not used, then 8x8 partition will be selected
509 // if variance of 16x16 block is very high, so use larger threshold 510 // if variance of 16x16 block is very high, so use larger threshold
510 // for 16x16 (threshold_bsize_min) in that case. 511 // for 16x16 (threshold_bsize_min) in that case.
511 cpi->vbp_threshold_16x16 = (use_4x4_partition) ? 512 cpi->vbp_threshold_16x16 = (use_4x4_partition) ?
512 cpi->vbp_threshold : cpi->vbp_threshold_bsize_min; 513 cpi->vbp_threshold : cpi->vbp_threshold_bsize_min;
513 cpi->vbp_bsize_min = (use_4x4_partition) ? BLOCK_8X8 : BLOCK_16X16; 514 cpi->vbp_bsize_min = (use_4x4_partition) ? BLOCK_8X8 : BLOCK_16X16;
514 } 515 }
515 } 516 }
516 517
517 #if CONFIG_VP9_HIGHBITDEPTH
518 #define GLOBAL_MOTION 0
519 #else
520 #define GLOBAL_MOTION 1
521 #endif
522
523 // This function chooses partitioning based on the variance between source and 518 // This function chooses partitioning based on the variance between source and
524 // reconstructed last, where variance is computed for down-sampled inputs. 519 // reconstructed last, where variance is computed for down-sampled inputs.
525 static void choose_partitioning(VP9_COMP *cpi, 520 static void choose_partitioning(VP9_COMP *cpi,
526 const TileInfo *const tile, 521 const TileInfo *const tile,
527 MACROBLOCK *x, 522 MACROBLOCK *x,
528 int mi_row, int mi_col) { 523 int mi_row, int mi_col) {
529 VP9_COMMON * const cm = &cpi->common; 524 VP9_COMMON * const cm = &cpi->common;
530 MACROBLOCKD *xd = &x->e_mbd; 525 MACROBLOCKD *xd = &x->e_mbd;
531 int i, j, k, m; 526 int i, j, k, m;
532 v64x64 vt; 527 v64x64 vt;
(...skipping 23 matching lines...) Expand all
556 pixels_wide += (xd->mb_to_right_edge >> 3); 551 pixels_wide += (xd->mb_to_right_edge >> 3);
557 if (xd->mb_to_bottom_edge < 0) 552 if (xd->mb_to_bottom_edge < 0)
558 pixels_high += (xd->mb_to_bottom_edge >> 3); 553 pixels_high += (xd->mb_to_bottom_edge >> 3);
559 554
560 s = x->plane[0].src.buf; 555 s = x->plane[0].src.buf;
561 sp = x->plane[0].src.stride; 556 sp = x->plane[0].src.stride;
562 557
563 if (!is_key_frame) { 558 if (!is_key_frame) {
564 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi; 559 MB_MODE_INFO *mbmi = &xd->mi[0].src_mi->mbmi;
565 unsigned int uv_sad; 560 unsigned int uv_sad;
566 #if GLOBAL_MOTION 561 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME);
567 unsigned int y_sad; 562
563 const YV12_BUFFER_CONFIG *yv12_g = get_ref_frame_buffer(cpi, GOLDEN_FRAME);
564 unsigned int y_sad, y_sad_g;
568 BLOCK_SIZE bsize; 565 BLOCK_SIZE bsize;
569 #endif
570 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME);
571 assert(yv12 != NULL);
572 vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col,
573 &cm->frame_refs[LAST_FRAME - 1].sf);
574 mbmi->ref_frame[0] = LAST_FRAME;
575 mbmi->ref_frame[1] = NONE;
576 mbmi->sb_type = BLOCK_64X64;
577 mbmi->mv[0].as_int = 0;
578 mbmi->interp_filter = BILINEAR;
579
580 #if GLOBAL_MOTION
581 if (mi_row + 4 < cm->mi_rows && mi_col + 4 < cm->mi_cols) 566 if (mi_row + 4 < cm->mi_rows && mi_col + 4 < cm->mi_cols)
582 bsize = BLOCK_64X64; 567 bsize = BLOCK_64X64;
583 else if (mi_row + 4 < cm->mi_rows && mi_col + 4 >= cm->mi_cols) 568 else if (mi_row + 4 < cm->mi_rows && mi_col + 4 >= cm->mi_cols)
584 bsize = BLOCK_32X64; 569 bsize = BLOCK_32X64;
585 else if (mi_row + 4 >= cm->mi_rows && mi_col + 4 < cm->mi_cols) 570 else if (mi_row + 4 >= cm->mi_rows && mi_col + 4 < cm->mi_cols)
586 bsize = BLOCK_64X32; 571 bsize = BLOCK_64X32;
587 else 572 else
588 bsize = BLOCK_32X32; 573 bsize = BLOCK_32X32;
589 574
575 assert(yv12 != NULL);
576
577 if (yv12_g && yv12_g != yv12) {
578 vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
579 &cm->frame_refs[GOLDEN_FRAME - 1].sf);
580 y_sad_g = cpi->fn_ptr[bsize].sdf(x->plane[0].src.buf,
581 x->plane[0].src.stride,
582 xd->plane[0].pre[0].buf,
583 xd->plane[0].pre[0].stride);
584 } else {
585 y_sad_g = UINT_MAX;
586 }
587
588 vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col,
589 &cm->frame_refs[LAST_FRAME - 1].sf);
590 mbmi->ref_frame[0] = LAST_FRAME;
591 mbmi->ref_frame[1] = NONE;
592 mbmi->sb_type = BLOCK_64X64;
593 mbmi->mv[0].as_int = 0;
594 mbmi->interp_filter = BILINEAR;
595
590 y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize); 596 y_sad = vp9_int_pro_motion_estimation(cpi, x, bsize);
591 x->pred_mv[LAST_FRAME] = mbmi->mv[0].as_mv; 597 if (y_sad_g < y_sad) {
592 #endif 598 vp9_setup_pre_planes(xd, 0, yv12_g, mi_row, mi_col,
599 &cm->frame_refs[GOLDEN_FRAME - 1].sf);
600 mbmi->ref_frame[0] = GOLDEN_FRAME;
601 mbmi->mv[0].as_int = 0;
602 y_sad = y_sad_g;
603 } else {
604 x->pred_mv[LAST_FRAME] = mbmi->mv[0].as_mv;
605 }
593 606
594 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_64X64); 607 vp9_build_inter_predictors_sb(xd, mi_row, mi_col, BLOCK_64X64);
595 608
596 for (i = 1; i <= 2; ++i) { 609 for (i = 1; i <= 2; ++i) {
597 struct macroblock_plane *p = &x->plane[i]; 610 struct macroblock_plane *p = &x->plane[i];
598 struct macroblockd_plane *pd = &xd->plane[i]; 611 struct macroblockd_plane *pd = &xd->plane[i];
599 #if GLOBAL_MOTION
600 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); 612 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd);
601 #else 613
602 const BLOCK_SIZE bs = get_plane_block_size(BLOCK_64X64, pd);
603 #endif
604 if (bs == BLOCK_INVALID) 614 if (bs == BLOCK_INVALID)
605 uv_sad = INT_MAX; 615 uv_sad = UINT_MAX;
606 else 616 else
607 uv_sad = cpi->fn_ptr[bs].sdf(p->src.buf, p->src.stride, 617 uv_sad = cpi->fn_ptr[bs].sdf(p->src.buf, p->src.stride,
608 pd->dst.buf, pd->dst.stride); 618 pd->dst.buf, pd->dst.stride);
609 619
610 #if GLOBAL_MOTION 620 x->color_sensitivity[i - 1] = uv_sad > (y_sad >> 2);
611 x->color_sensitivity[i - 1] = uv_sad * 4 > y_sad;
612 #else
613 x->color_sensitivity[i - 1] = (uv_sad > 512);
614 #endif
615 } 621 }
616 622
617 d = xd->plane[0].dst.buf; 623 d = xd->plane[0].dst.buf;
618 dp = xd->plane[0].dst.stride; 624 dp = xd->plane[0].dst.stride;
619 } else { 625 } else {
620 d = VP9_VAR_OFFS; 626 d = VP9_VAR_OFFS;
621 dp = 0; 627 dp = 0;
622 #if CONFIG_VP9_HIGHBITDEPTH 628 #if CONFIG_VP9_HIGHBITDEPTH
623 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { 629 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
624 switch (xd->bd) { 630 switch (xd->bd) {
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 static void encode_b_rt(VP9_COMP *cpi, ThreadData *td, 1586 static void encode_b_rt(VP9_COMP *cpi, ThreadData *td,
1581 const TileInfo *const tile, 1587 const TileInfo *const tile,
1582 TOKENEXTRA **tp, int mi_row, int mi_col, 1588 TOKENEXTRA **tp, int mi_row, int mi_col,
1583 int output_enabled, BLOCK_SIZE bsize, 1589 int output_enabled, BLOCK_SIZE bsize,
1584 PICK_MODE_CONTEXT *ctx) { 1590 PICK_MODE_CONTEXT *ctx) {
1585 MACROBLOCK *const x = &td->mb; 1591 MACROBLOCK *const x = &td->mb;
1586 set_offsets(cpi, tile, x, mi_row, mi_col, bsize); 1592 set_offsets(cpi, tile, x, mi_row, mi_col, bsize);
1587 update_state_rt(cpi, td, ctx, mi_row, mi_col, bsize); 1593 update_state_rt(cpi, td, ctx, mi_row, mi_col, bsize);
1588 1594
1589 #if CONFIG_VP9_TEMPORAL_DENOISING 1595 #if CONFIG_VP9_TEMPORAL_DENOISING
1590 if (cpi->oxcf.noise_sensitivity > 0 && output_enabled) { 1596 if (cpi->oxcf.noise_sensitivity > 0 && output_enabled &&
1597 cpi->common.frame_type != KEY_FRAME) {
1591 vp9_denoiser_denoise(&cpi->denoiser, x, mi_row, mi_col, 1598 vp9_denoiser_denoise(&cpi->denoiser, x, mi_row, mi_col,
1592 MAX(BLOCK_8X8, bsize), ctx); 1599 MAX(BLOCK_8X8, bsize), ctx);
1593 } 1600 }
1594 #endif 1601 #endif
1595 1602
1596 encode_superblock(cpi, td, tp, output_enabled, mi_row, mi_col, bsize, ctx); 1603 encode_superblock(cpi, td, tp, output_enabled, mi_row, mi_col, bsize, ctx);
1597 update_stats(&cpi->common, td); 1604 update_stats(&cpi->common, td);
1598 1605
1599 (*tp)->token = EOSB_TOKEN; 1606 (*tp)->token = EOSB_TOKEN;
1600 (*tp)++; 1607 (*tp)++;
(...skipping 1901 matching lines...) Expand 10 before | Expand all | Expand 10 after
3502 if (!seg_skip) 3509 if (!seg_skip)
3503 bsize = sf->always_this_block_size; 3510 bsize = sf->always_this_block_size;
3504 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); 3511 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize);
3505 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, 3512 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
3506 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); 3513 BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
3507 break; 3514 break;
3508 case REFERENCE_PARTITION: 3515 case REFERENCE_PARTITION:
3509 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64); 3516 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64);
3510 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && 3517 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled &&
3511 xd->mi[0].src_mi->mbmi.segment_id) { 3518 xd->mi[0].src_mi->mbmi.segment_id) {
3512 auto_partition_range(cpi, tile_info, xd, mi_row, mi_col, 3519 x->max_partition_size = BLOCK_64X64;
3513 &x->min_partition_size, 3520 x->min_partition_size = BLOCK_8X8;
3514 &x->max_partition_size);
3515 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, 3521 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col,
3516 BLOCK_64X64, &dummy_rdc, 1, 3522 BLOCK_64X64, &dummy_rdc, 1,
3517 INT64_MAX, td->pc_root); 3523 INT64_MAX, td->pc_root);
3518 } else { 3524 } else {
3519 choose_partitioning(cpi, tile_info, x, mi_row, mi_col); 3525 choose_partitioning(cpi, tile_info, x, mi_row, mi_col);
3520 nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, 3526 nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col,
3521 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); 3527 BLOCK_64X64, 1, &dummy_rdc, td->pc_root);
3522 } 3528 }
3523 3529
3524 break; 3530 break;
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 4109
4104 for (y = 0; y < mi_height; y++) 4110 for (y = 0; y < mi_height; y++)
4105 for (x = 0; x < mi_width; x++) 4111 for (x = 0; x < mi_width; x++)
4106 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) 4112 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows)
4107 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size; 4113 mi_8x8[mis * y + x].src_mi->mbmi.tx_size = tx_size;
4108 } 4114 }
4109 ++td->counts->tx.tx_totals[mbmi->tx_size]; 4115 ++td->counts->tx.tx_totals[mbmi->tx_size];
4110 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])]; 4116 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])];
4111 } 4117 }
4112 } 4118 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_aq_cyclicrefresh.c ('k') | source/libvpx/vp9/encoder/vp9_encoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698