| OLD | NEW |
| 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 <math.h> | 11 #include <math.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <limits.h> | 13 #include <limits.h> |
| 14 | 14 |
| 15 #include "./vp9_rtcd.h" | 15 #include "./vp9_rtcd.h" |
| 16 #include "./vpx_config.h" | 16 #include "./vpx_config.h" |
| 17 #include "./vpx_dsp_rtcd.h" | 17 #include "./vpx_dsp_rtcd.h" |
| 18 #include "./vpx_scale_rtcd.h" | 18 #include "./vpx_scale_rtcd.h" |
| 19 #include "vpx/internal/vpx_psnr.h" | 19 #include "vpx/internal/vpx_psnr.h" |
| 20 #include "vpx_dsp/vpx_filter.h" | 20 #include "vpx_dsp/vpx_filter.h" |
| 21 #if CONFIG_INTERNAL_STATS |
| 22 #include "vpx_dsp/ssim.h" |
| 23 #endif |
| 21 #include "vpx_ports/mem.h" | 24 #include "vpx_ports/mem.h" |
| 25 #include "vpx_ports/system_state.h" |
| 22 #include "vpx_ports/vpx_timer.h" | 26 #include "vpx_ports/vpx_timer.h" |
| 23 #include "vpx_scale/vpx_scale.h" | |
| 24 | 27 |
| 25 #include "vp9/common/vp9_alloccommon.h" | 28 #include "vp9/common/vp9_alloccommon.h" |
| 26 #include "vp9/common/vp9_filter.h" | 29 #include "vp9/common/vp9_filter.h" |
| 27 #include "vp9/common/vp9_idct.h" | 30 #include "vp9/common/vp9_idct.h" |
| 28 #if CONFIG_VP9_POSTPROC | 31 #if CONFIG_VP9_POSTPROC |
| 29 #include "vp9/common/vp9_postproc.h" | 32 #include "vp9/common/vp9_postproc.h" |
| 30 #endif | 33 #endif |
| 31 #include "vp9/common/vp9_reconinter.h" | 34 #include "vp9/common/vp9_reconinter.h" |
| 32 #include "vp9/common/vp9_reconintra.h" | 35 #include "vp9/common/vp9_reconintra.h" |
| 33 #include "vp9/common/vp9_systemdependent.h" | |
| 34 #include "vp9/common/vp9_tile_common.h" | 36 #include "vp9/common/vp9_tile_common.h" |
| 35 | 37 |
| 36 #include "vp9/encoder/vp9_aq_complexity.h" | 38 #include "vp9/encoder/vp9_aq_complexity.h" |
| 37 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" | 39 #include "vp9/encoder/vp9_aq_cyclicrefresh.h" |
| 38 #include "vp9/encoder/vp9_aq_variance.h" | 40 #include "vp9/encoder/vp9_aq_variance.h" |
| 39 #include "vp9/encoder/vp9_bitstream.h" | 41 #include "vp9/encoder/vp9_bitstream.h" |
| 40 #include "vp9/encoder/vp9_context_tree.h" | 42 #include "vp9/encoder/vp9_context_tree.h" |
| 41 #include "vp9/encoder/vp9_encodeframe.h" | 43 #include "vp9/encoder/vp9_encodeframe.h" |
| 42 #include "vp9/encoder/vp9_encodemv.h" | 44 #include "vp9/encoder/vp9_encodemv.h" |
| 43 #include "vp9/encoder/vp9_encoder.h" | 45 #include "vp9/encoder/vp9_encoder.h" |
| 44 #include "vp9/encoder/vp9_ethread.h" | 46 #include "vp9/encoder/vp9_ethread.h" |
| 45 #include "vp9/encoder/vp9_firstpass.h" | 47 #include "vp9/encoder/vp9_firstpass.h" |
| 46 #include "vp9/encoder/vp9_mbgraph.h" | 48 #include "vp9/encoder/vp9_mbgraph.h" |
| 47 #include "vp9/encoder/vp9_picklpf.h" | 49 #include "vp9/encoder/vp9_picklpf.h" |
| 48 #include "vp9/encoder/vp9_ratectrl.h" | 50 #include "vp9/encoder/vp9_ratectrl.h" |
| 49 #include "vp9/encoder/vp9_rd.h" | 51 #include "vp9/encoder/vp9_rd.h" |
| 50 #include "vp9/encoder/vp9_resize.h" | 52 #include "vp9/encoder/vp9_resize.h" |
| 51 #include "vp9/encoder/vp9_segmentation.h" | 53 #include "vp9/encoder/vp9_segmentation.h" |
| 52 #include "vp9/encoder/vp9_skin_detection.h" | 54 #include "vp9/encoder/vp9_skin_detection.h" |
| 53 #include "vp9/encoder/vp9_speed_features.h" | 55 #include "vp9/encoder/vp9_speed_features.h" |
| 54 #if CONFIG_INTERNAL_STATS | |
| 55 #include "vp9/encoder/vp9_ssim.h" | |
| 56 #endif | |
| 57 #include "vp9/encoder/vp9_svc_layercontext.h" | 56 #include "vp9/encoder/vp9_svc_layercontext.h" |
| 58 #include "vp9/encoder/vp9_temporal_filter.h" | 57 #include "vp9/encoder/vp9_temporal_filter.h" |
| 59 | 58 |
| 60 #define AM_SEGMENT_ID_INACTIVE 7 | 59 #define AM_SEGMENT_ID_INACTIVE 7 |
| 61 #define AM_SEGMENT_ID_ACTIVE 0 | 60 #define AM_SEGMENT_ID_ACTIVE 0 |
| 62 | 61 |
| 63 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ | 62 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 64 | 63 |
| 65 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv | 64 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 66 // for altref computation. | 65 // for altref computation. |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 373 |
| 375 vpx_free(cpi->active_map.map); | 374 vpx_free(cpi->active_map.map); |
| 376 cpi->active_map.map = NULL; | 375 cpi->active_map.map = NULL; |
| 377 | 376 |
| 378 vp9_free_ref_frame_buffers(cm->buffer_pool); | 377 vp9_free_ref_frame_buffers(cm->buffer_pool); |
| 379 #if CONFIG_VP9_POSTPROC | 378 #if CONFIG_VP9_POSTPROC |
| 380 vp9_free_postproc_buffers(cm); | 379 vp9_free_postproc_buffers(cm); |
| 381 #endif | 380 #endif |
| 382 vp9_free_context_buffers(cm); | 381 vp9_free_context_buffers(cm); |
| 383 | 382 |
| 384 vp9_free_frame_buffer(&cpi->last_frame_uf); | 383 vpx_free_frame_buffer(&cpi->last_frame_uf); |
| 385 vp9_free_frame_buffer(&cpi->scaled_source); | 384 vpx_free_frame_buffer(&cpi->scaled_source); |
| 386 vp9_free_frame_buffer(&cpi->scaled_last_source); | 385 vpx_free_frame_buffer(&cpi->scaled_last_source); |
| 387 vp9_free_frame_buffer(&cpi->alt_ref_buffer); | 386 vpx_free_frame_buffer(&cpi->alt_ref_buffer); |
| 388 vp9_lookahead_destroy(cpi->lookahead); | 387 vp9_lookahead_destroy(cpi->lookahead); |
| 389 | 388 |
| 390 vpx_free(cpi->tile_tok[0][0]); | 389 vpx_free(cpi->tile_tok[0][0]); |
| 391 cpi->tile_tok[0][0] = 0; | 390 cpi->tile_tok[0][0] = 0; |
| 392 | 391 |
| 393 vp9_free_pc_tree(&cpi->td); | 392 vp9_free_pc_tree(&cpi->td); |
| 394 | 393 |
| 395 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { | 394 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { |
| 396 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; | 395 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; |
| 397 vpx_free(lc->rc_twopass_stats_in.buf); | 396 vpx_free(lc->rc_twopass_stats_in.buf); |
| 398 lc->rc_twopass_stats_in.buf = NULL; | 397 lc->rc_twopass_stats_in.buf = NULL; |
| 399 lc->rc_twopass_stats_in.sz = 0; | 398 lc->rc_twopass_stats_in.sz = 0; |
| 400 } | 399 } |
| 401 | 400 |
| 402 if (cpi->source_diff_var != NULL) { | 401 if (cpi->source_diff_var != NULL) { |
| 403 vpx_free(cpi->source_diff_var); | 402 vpx_free(cpi->source_diff_var); |
| 404 cpi->source_diff_var = NULL; | 403 cpi->source_diff_var = NULL; |
| 405 } | 404 } |
| 406 | 405 |
| 407 for (i = 0; i < MAX_LAG_BUFFERS; ++i) { | 406 for (i = 0; i < MAX_LAG_BUFFERS; ++i) { |
| 408 vp9_free_frame_buffer(&cpi->svc.scaled_frames[i]); | 407 vpx_free_frame_buffer(&cpi->svc.scaled_frames[i]); |
| 409 } | 408 } |
| 410 memset(&cpi->svc.scaled_frames[0], 0, | 409 memset(&cpi->svc.scaled_frames[0], 0, |
| 411 MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0])); | 410 MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0])); |
| 412 | 411 |
| 413 vp9_free_frame_buffer(&cpi->svc.empty_frame.img); | 412 vpx_free_frame_buffer(&cpi->svc.empty_frame.img); |
| 414 memset(&cpi->svc.empty_frame, 0, sizeof(cpi->svc.empty_frame)); | 413 memset(&cpi->svc.empty_frame, 0, sizeof(cpi->svc.empty_frame)); |
| 415 } | 414 } |
| 416 | 415 |
| 417 static void save_coding_context(VP9_COMP *cpi) { | 416 static void save_coding_context(VP9_COMP *cpi) { |
| 418 CODING_CONTEXT *const cc = &cpi->coding_context; | 417 CODING_CONTEXT *const cc = &cpi->coding_context; |
| 419 VP9_COMMON *cm = &cpi->common; | 418 VP9_COMMON *cm = &cpi->common; |
| 420 | 419 |
| 421 // Stores a snapshot of key state variables which can subsequently be | 420 // Stores a snapshot of key state variables which can subsequently be |
| 422 // restored with a call to vp9_restore_coding_context. These functions are | 421 // restored with a call to vp9_restore_coding_context. These functions are |
| 423 // intended for use in a re-code loop in vp9_compress_frame where the | 422 // intended for use in a re-code loop in vp9_compress_frame where the |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 cm->subsampling_x, cm->subsampling_y, | 619 cm->subsampling_x, cm->subsampling_y, |
| 621 #if CONFIG_VP9_HIGHBITDEPTH | 620 #if CONFIG_VP9_HIGHBITDEPTH |
| 622 cm->use_highbitdepth, | 621 cm->use_highbitdepth, |
| 623 #endif | 622 #endif |
| 624 oxcf->lag_in_frames); | 623 oxcf->lag_in_frames); |
| 625 if (!cpi->lookahead) | 624 if (!cpi->lookahead) |
| 626 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 625 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 627 "Failed to allocate lag buffers"); | 626 "Failed to allocate lag buffers"); |
| 628 | 627 |
| 629 // TODO(agrange) Check if ARF is enabled and skip allocation if not. | 628 // TODO(agrange) Check if ARF is enabled and skip allocation if not. |
| 630 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, | 629 if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer, |
| 631 oxcf->width, oxcf->height, | 630 oxcf->width, oxcf->height, |
| 632 cm->subsampling_x, cm->subsampling_y, | 631 cm->subsampling_x, cm->subsampling_y, |
| 633 #if CONFIG_VP9_HIGHBITDEPTH | 632 #if CONFIG_VP9_HIGHBITDEPTH |
| 634 cm->use_highbitdepth, | 633 cm->use_highbitdepth, |
| 635 #endif | 634 #endif |
| 636 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 635 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 637 NULL, NULL, NULL)) | 636 NULL, NULL, NULL)) |
| 638 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 637 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 639 "Failed to allocate altref buffer"); | 638 "Failed to allocate altref buffer"); |
| 640 } | 639 } |
| 641 | 640 |
| 642 static void alloc_util_frame_buffers(VP9_COMP *cpi) { | 641 static void alloc_util_frame_buffers(VP9_COMP *cpi) { |
| 643 VP9_COMMON *const cm = &cpi->common; | 642 VP9_COMMON *const cm = &cpi->common; |
| 644 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, | 643 if (vpx_realloc_frame_buffer(&cpi->last_frame_uf, |
| 645 cm->width, cm->height, | 644 cm->width, cm->height, |
| 646 cm->subsampling_x, cm->subsampling_y, | 645 cm->subsampling_x, cm->subsampling_y, |
| 647 #if CONFIG_VP9_HIGHBITDEPTH | 646 #if CONFIG_VP9_HIGHBITDEPTH |
| 648 cm->use_highbitdepth, | 647 cm->use_highbitdepth, |
| 649 #endif | 648 #endif |
| 650 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 649 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 651 NULL, NULL, NULL)) | 650 NULL, NULL, NULL)) |
| 652 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 651 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 653 "Failed to allocate last frame buffer"); | 652 "Failed to allocate last frame buffer"); |
| 654 | 653 |
| 655 if (vp9_realloc_frame_buffer(&cpi->scaled_source, | 654 if (vpx_realloc_frame_buffer(&cpi->scaled_source, |
| 656 cm->width, cm->height, | 655 cm->width, cm->height, |
| 657 cm->subsampling_x, cm->subsampling_y, | 656 cm->subsampling_x, cm->subsampling_y, |
| 658 #if CONFIG_VP9_HIGHBITDEPTH | 657 #if CONFIG_VP9_HIGHBITDEPTH |
| 659 cm->use_highbitdepth, | 658 cm->use_highbitdepth, |
| 660 #endif | 659 #endif |
| 661 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 660 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 662 NULL, NULL, NULL)) | 661 NULL, NULL, NULL)) |
| 663 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 662 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 664 "Failed to allocate scaled source buffer"); | 663 "Failed to allocate scaled source buffer"); |
| 665 | 664 |
| 666 if (vp9_realloc_frame_buffer(&cpi->scaled_last_source, | 665 if (vpx_realloc_frame_buffer(&cpi->scaled_last_source, |
| 667 cm->width, cm->height, | 666 cm->width, cm->height, |
| 668 cm->subsampling_x, cm->subsampling_y, | 667 cm->subsampling_x, cm->subsampling_y, |
| 669 #if CONFIG_VP9_HIGHBITDEPTH | 668 #if CONFIG_VP9_HIGHBITDEPTH |
| 670 cm->use_highbitdepth, | 669 cm->use_highbitdepth, |
| 671 #endif | 670 #endif |
| 672 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 671 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 673 NULL, NULL, NULL)) | 672 NULL, NULL, NULL)) |
| 674 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 673 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 675 "Failed to allocate scaled last source buffer"); | 674 "Failed to allocate scaled last source buffer"); |
| 676 } | 675 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 vp9_set_mb_mi(cm, cm->width, cm->height); | 734 vp9_set_mb_mi(cm, cm->width, cm->height); |
| 736 vp9_init_context_buffers(cm); | 735 vp9_init_context_buffers(cm); |
| 737 vp9_init_macroblockd(cm, xd, NULL); | 736 vp9_init_macroblockd(cm, xd, NULL); |
| 738 cpi->td.mb.mbmi_ext_base = cpi->mbmi_ext_base; | 737 cpi->td.mb.mbmi_ext_base = cpi->mbmi_ext_base; |
| 739 memset(cpi->mbmi_ext_base, 0, | 738 memset(cpi->mbmi_ext_base, 0, |
| 740 cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); | 739 cm->mi_rows * cm->mi_cols * sizeof(*cpi->mbmi_ext_base)); |
| 741 | 740 |
| 742 set_tile_limits(cpi); | 741 set_tile_limits(cpi); |
| 743 | 742 |
| 744 if (is_two_pass_svc(cpi)) { | 743 if (is_two_pass_svc(cpi)) { |
| 745 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, | 744 if (vpx_realloc_frame_buffer(&cpi->alt_ref_buffer, |
| 746 cm->width, cm->height, | 745 cm->width, cm->height, |
| 747 cm->subsampling_x, cm->subsampling_y, | 746 cm->subsampling_x, cm->subsampling_y, |
| 748 #if CONFIG_VP9_HIGHBITDEPTH | 747 #if CONFIG_VP9_HIGHBITDEPTH |
| 749 cm->use_highbitdepth, | 748 cm->use_highbitdepth, |
| 750 #endif | 749 #endif |
| 751 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 750 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 752 NULL, NULL, NULL)) | 751 NULL, NULL, NULL)) |
| 753 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 752 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 754 "Failed to reallocate alt_ref_buffer"); | 753 "Failed to reallocate alt_ref_buffer"); |
| 755 } | 754 } |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1484 | 1483 |
| 1485 for (i = 0; i < MAX_SEGMENTS; i++) | 1484 for (i = 0; i < MAX_SEGMENTS; i++) |
| 1486 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; | 1485 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; |
| 1487 } | 1486 } |
| 1488 cpi->encode_breakout = cpi->oxcf.encode_breakout; | 1487 cpi->encode_breakout = cpi->oxcf.encode_breakout; |
| 1489 | 1488 |
| 1490 set_rc_buffer_sizes(rc, &cpi->oxcf); | 1489 set_rc_buffer_sizes(rc, &cpi->oxcf); |
| 1491 | 1490 |
| 1492 // Under a configuration change, where maximum_buffer_size may change, | 1491 // Under a configuration change, where maximum_buffer_size may change, |
| 1493 // keep buffer level clipped to the maximum allowed buffer size. | 1492 // keep buffer level clipped to the maximum allowed buffer size. |
| 1494 rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); | 1493 rc->bits_off_target = VPXMIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 1495 rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size); | 1494 rc->buffer_level = VPXMIN(rc->buffer_level, rc->maximum_buffer_size); |
| 1496 | 1495 |
| 1497 // Set up frame rate and related parameters rate control values. | 1496 // Set up frame rate and related parameters rate control values. |
| 1498 vp9_new_framerate(cpi, cpi->framerate); | 1497 vp9_new_framerate(cpi, cpi->framerate); |
| 1499 | 1498 |
| 1500 // Set absolute upper and lower quality limits | 1499 // Set absolute upper and lower quality limits |
| 1501 rc->worst_quality = cpi->oxcf.worst_allowed_q; | 1500 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 1502 rc->best_quality = cpi->oxcf.best_allowed_q; | 1501 rc->best_quality = cpi->oxcf.best_allowed_q; |
| 1503 | 1502 |
| 1504 cm->interp_filter = cpi->sf.default_interp_filter; | 1503 cm->interp_filter = cpi->sf.default_interp_filter; |
| 1505 | 1504 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1616 CHECK_MEM_ERROR(cm, cm->frame_contexts, | 1615 CHECK_MEM_ERROR(cm, cm->frame_contexts, |
| 1617 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, | 1616 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, |
| 1618 sizeof(*cm->frame_contexts))); | 1617 sizeof(*cm->frame_contexts))); |
| 1619 | 1618 |
| 1620 cpi->use_svc = 0; | 1619 cpi->use_svc = 0; |
| 1621 cpi->resize_state = 0; | 1620 cpi->resize_state = 0; |
| 1622 cpi->resize_avg_qp = 0; | 1621 cpi->resize_avg_qp = 0; |
| 1623 cpi->resize_buffer_underflow = 0; | 1622 cpi->resize_buffer_underflow = 0; |
| 1624 cpi->common.buffer_pool = pool; | 1623 cpi->common.buffer_pool = pool; |
| 1625 | 1624 |
| 1625 cpi->rc.high_source_sad = 0; |
| 1626 |
| 1626 init_config(cpi, oxcf); | 1627 init_config(cpi, oxcf); |
| 1627 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); | 1628 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); |
| 1628 | 1629 |
| 1629 cm->current_video_frame = 0; | 1630 cm->current_video_frame = 0; |
| 1630 cpi->partition_search_skippable_frame = 0; | 1631 cpi->partition_search_skippable_frame = 0; |
| 1631 cpi->tile_data = NULL; | 1632 cpi->tile_data = NULL; |
| 1632 | 1633 |
| 1633 realloc_segmentation_maps(cpi); | 1634 realloc_segmentation_maps(cpi); |
| 1634 | 1635 |
| 1635 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0], | 1636 CHECK_MEM_ERROR(cm, cpi->nmvcosts[0], |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 cpi->fastssim.worst = 100.0; | 1703 cpi->fastssim.worst = 100.0; |
| 1703 | 1704 |
| 1704 cpi->psnrhvs.worst = 100.0; | 1705 cpi->psnrhvs.worst = 100.0; |
| 1705 | 1706 |
| 1706 if (cpi->b_calculate_blockiness) { | 1707 if (cpi->b_calculate_blockiness) { |
| 1707 cpi->total_blockiness = 0; | 1708 cpi->total_blockiness = 0; |
| 1708 cpi->worst_blockiness = 0.0; | 1709 cpi->worst_blockiness = 0.0; |
| 1709 } | 1710 } |
| 1710 | 1711 |
| 1711 if (cpi->b_calculate_consistency) { | 1712 if (cpi->b_calculate_consistency) { |
| 1712 cpi->ssim_vars = vpx_malloc(sizeof(*cpi->ssim_vars)*720*480); | 1713 cpi->ssim_vars = vpx_malloc(sizeof(*cpi->ssim_vars) * |
| 1714 4 * cpi->common.mi_rows * cpi->common.mi_cols); |
| 1713 cpi->worst_consistency = 100.0; | 1715 cpi->worst_consistency = 100.0; |
| 1714 } | 1716 } |
| 1715 | 1717 |
| 1716 #endif | 1718 #endif |
| 1717 | 1719 |
| 1718 cpi->first_time_stamp_ever = INT64_MAX; | 1720 cpi->first_time_stamp_ever = INT64_MAX; |
| 1719 | 1721 |
| 1720 cal_nmvjointsadcost(cpi->td.mb.nmvjointsadcost); | 1722 cal_nmvjointsadcost(cpi->td.mb.nmvjointsadcost); |
| 1721 cpi->td.mb.nmvcost[0] = &cpi->nmvcosts[0][MV_MAX]; | 1723 cpi->td.mb.nmvcost[0] = &cpi->nmvcosts[0][MV_MAX]; |
| 1722 cpi->td.mb.nmvcost[1] = &cpi->nmvcosts[1][MV_MAX]; | 1724 cpi->td.mb.nmvcost[1] = &cpi->nmvcosts[1][MV_MAX]; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 void vp9_remove_compressor(VP9_COMP *cpi) { | 1920 void vp9_remove_compressor(VP9_COMP *cpi) { |
| 1919 VP9_COMMON *const cm = &cpi->common; | 1921 VP9_COMMON *const cm = &cpi->common; |
| 1920 unsigned int i; | 1922 unsigned int i; |
| 1921 int t; | 1923 int t; |
| 1922 | 1924 |
| 1923 if (!cpi) | 1925 if (!cpi) |
| 1924 return; | 1926 return; |
| 1925 | 1927 |
| 1926 if (cpi && (cm->current_video_frame > 0)) { | 1928 if (cpi && (cm->current_video_frame > 0)) { |
| 1927 #if CONFIG_INTERNAL_STATS | 1929 #if CONFIG_INTERNAL_STATS |
| 1928 vp9_clear_system_state(); | 1930 vpx_clear_system_state(); |
| 1929 | 1931 |
| 1930 if (cpi->oxcf.pass != 1) { | 1932 if (cpi->oxcf.pass != 1) { |
| 1931 char headings[512] = {0}; | 1933 char headings[512] = {0}; |
| 1932 char results[512] = {0}; | 1934 char results[512] = {0}; |
| 1933 FILE *f = fopen("opsnr.stt", "a"); | 1935 FILE *f = fopen("opsnr.stt", "a"); |
| 1934 double time_encoded = (cpi->last_end_time_stamp_seen | 1936 double time_encoded = (cpi->last_end_time_stamp_seen |
| 1935 - cpi->first_time_stamp_ever) / 10000000.000; | 1937 - cpi->first_time_stamp_ever) / 10000000.000; |
| 1936 double total_encode_time = (cpi->time_receive_data + | 1938 double total_encode_time = (cpi->time_receive_data + |
| 1937 cpi->time_compress_data) / 1000.000; | 1939 cpi->time_compress_data) / 1000.000; |
| 1938 const double dr = | 1940 const double dr = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1950 cpi->summed_weights, 8.0); | 1952 cpi->summed_weights, 8.0); |
| 1951 const double totalp_ssim = 100 * pow(cpi->summedp_quality / | 1953 const double totalp_ssim = 100 * pow(cpi->summedp_quality / |
| 1952 cpi->summedp_weights, 8.0); | 1954 cpi->summedp_weights, 8.0); |
| 1953 | 1955 |
| 1954 snprintf(headings, sizeof(headings), | 1956 snprintf(headings, sizeof(headings), |
| 1955 "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" | 1957 "Bitrate\tAVGPsnr\tGLBPsnr\tAVPsnrP\tGLPsnrP\t" |
| 1956 "VPXSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" | 1958 "VPXSSIM\tVPSSIMP\tFASTSIM\tPSNRHVS\t" |
| 1957 "WstPsnr\tWstSsim\tWstFast\tWstHVS"); | 1959 "WstPsnr\tWstSsim\tWstFast\tWstHVS"); |
| 1958 snprintf(results, sizeof(results), | 1960 snprintf(results, sizeof(results), |
| 1959 "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" | 1961 "%7.2f\t%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 1960 "%7.3f\t%7.3f\t%7.3f\t%7.3f" | 1962 "%7.3f\t%7.3f\t%7.3f\t%7.3f\t" |
| 1961 "%7.3f\t%7.3f\t%7.3f\t%7.3f", | 1963 "%7.3f\t%7.3f\t%7.3f\t%7.3f", |
| 1962 dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, | 1964 dr, cpi->psnr.stat[ALL] / cpi->count, total_psnr, |
| 1963 cpi->psnrp.stat[ALL] / cpi->count, totalp_psnr, | 1965 cpi->psnrp.stat[ALL] / cpi->count, totalp_psnr, |
| 1964 total_ssim, totalp_ssim, | 1966 total_ssim, totalp_ssim, |
| 1965 cpi->fastssim.stat[ALL] / cpi->count, | 1967 cpi->fastssim.stat[ALL] / cpi->count, |
| 1966 cpi->psnrhvs.stat[ALL] / cpi->count, | 1968 cpi->psnrhvs.stat[ALL] / cpi->count, |
| 1967 cpi->psnr.worst, cpi->worst_ssim, cpi->fastssim.worst, | 1969 cpi->psnr.worst, cpi->worst_ssim, cpi->fastssim.worst, |
| 1968 cpi->psnrhvs.worst); | 1970 cpi->psnrhvs.worst); |
| 1969 | 1971 |
| 1970 if (cpi->b_calculate_blockiness) { | 1972 if (cpi->b_calculate_blockiness) { |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2539 dst_widths[i], dst_strides[i], bd); | 2541 dst_widths[i], dst_strides[i], bd); |
| 2540 } else { | 2542 } else { |
| 2541 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i], | 2543 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i], |
| 2542 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]); | 2544 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]); |
| 2543 } | 2545 } |
| 2544 #else | 2546 #else |
| 2545 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i], | 2547 vp9_resize_plane(srcs[i], src_heights[i], src_widths[i], src_strides[i], |
| 2546 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]); | 2548 dsts[i], dst_heights[i], dst_widths[i], dst_strides[i]); |
| 2547 #endif // CONFIG_VP9_HIGHBITDEPTH | 2549 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2548 } | 2550 } |
| 2549 vp9_extend_frame_borders(dst); | 2551 vpx_extend_frame_borders(dst); |
| 2550 } | 2552 } |
| 2551 | 2553 |
| 2552 #if CONFIG_VP9_HIGHBITDEPTH | 2554 #if CONFIG_VP9_HIGHBITDEPTH |
| 2553 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, | 2555 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, |
| 2554 YV12_BUFFER_CONFIG *dst, int bd) { | 2556 YV12_BUFFER_CONFIG *dst, int bd) { |
| 2555 #else | 2557 #else |
| 2556 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, | 2558 static void scale_and_extend_frame(const YV12_BUFFER_CONFIG *src, |
| 2557 YV12_BUFFER_CONFIG *dst) { | 2559 YV12_BUFFER_CONFIG *dst) { |
| 2558 #endif // CONFIG_VP9_HIGHBITDEPTH | 2560 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2559 const int src_w = src->y_crop_width; | 2561 const int src_w = src->y_crop_width; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2579 src_stride + (x / factor) * src_w / dst_w; | 2581 src_stride + (x / factor) * src_w / dst_w; |
| 2580 uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor); | 2582 uint8_t *dst_ptr = dsts[i] + (y / factor) * dst_stride + (x / factor); |
| 2581 | 2583 |
| 2582 #if CONFIG_VP9_HIGHBITDEPTH | 2584 #if CONFIG_VP9_HIGHBITDEPTH |
| 2583 if (src->flags & YV12_FLAG_HIGHBITDEPTH) { | 2585 if (src->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 2584 vpx_highbd_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, | 2586 vpx_highbd_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, |
| 2585 kernel[x_q4 & 0xf], 16 * src_w / dst_w, | 2587 kernel[x_q4 & 0xf], 16 * src_w / dst_w, |
| 2586 kernel[y_q4 & 0xf], 16 * src_h / dst_h, | 2588 kernel[y_q4 & 0xf], 16 * src_h / dst_h, |
| 2587 16 / factor, 16 / factor, bd); | 2589 16 / factor, 16 / factor, bd); |
| 2588 } else { | 2590 } else { |
| 2589 vpx_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, | 2591 vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride, |
| 2590 kernel[x_q4 & 0xf], 16 * src_w / dst_w, | 2592 kernel[x_q4 & 0xf], 16 * src_w / dst_w, |
| 2591 kernel[y_q4 & 0xf], 16 * src_h / dst_h, | 2593 kernel[y_q4 & 0xf], 16 * src_h / dst_h, |
| 2592 16 / factor, 16 / factor); | 2594 16 / factor, 16 / factor); |
| 2593 } | 2595 } |
| 2594 #else | 2596 #else |
| 2595 vpx_convolve8(src_ptr, src_stride, dst_ptr, dst_stride, | 2597 vpx_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride, |
| 2596 kernel[x_q4 & 0xf], 16 * src_w / dst_w, | 2598 kernel[x_q4 & 0xf], 16 * src_w / dst_w, |
| 2597 kernel[y_q4 & 0xf], 16 * src_h / dst_h, | 2599 kernel[y_q4 & 0xf], 16 * src_h / dst_h, |
| 2598 16 / factor, 16 / factor); | 2600 16 / factor, 16 / factor); |
| 2599 #endif // CONFIG_VP9_HIGHBITDEPTH | 2601 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2600 } | 2602 } |
| 2601 } | 2603 } |
| 2602 } | 2604 } |
| 2603 | 2605 |
| 2604 vp9_extend_frame_borders(dst); | 2606 vpx_extend_frame_borders(dst); |
| 2605 } | 2607 } |
| 2606 | 2608 |
| 2607 static int scale_down(VP9_COMP *cpi, int q) { | 2609 static int scale_down(VP9_COMP *cpi, int q) { |
| 2608 RATE_CONTROL *const rc = &cpi->rc; | 2610 RATE_CONTROL *const rc = &cpi->rc; |
| 2609 GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2611 GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2610 int scale = 0; | 2612 int scale = 0; |
| 2611 assert(frame_is_kf_gf_arf(cpi)); | 2613 assert(frame_is_kf_gf_arf(cpi)); |
| 2612 | 2614 |
| 2613 if (rc->frame_size_selector == UNSCALED && | 2615 if (rc->frame_size_selector == UNSCALED && |
| 2614 q >= rc->rf_level_maxq[gf_group->rf_level[gf_group->index]]) { | 2616 q >= rc->rf_level_maxq[gf_group->rf_level[gf_group->index]]) { |
| 2615 const int max_size_thresh = (int)(rate_thresh_mult[SCALE_STEP1] | 2617 const int max_size_thresh = (int)(rate_thresh_mult[SCALE_STEP1] |
| 2616 * MAX(rc->this_frame_target, rc->avg_frame_bandwidth)); | 2618 * VPXMAX(rc->this_frame_target, rc->avg_frame_bandwidth)); |
| 2617 scale = rc->projected_frame_size > max_size_thresh ? 1 : 0; | 2619 scale = rc->projected_frame_size > max_size_thresh ? 1 : 0; |
| 2618 } | 2620 } |
| 2619 return scale; | 2621 return scale; |
| 2620 } | 2622 } |
| 2621 | 2623 |
| 2622 // Function to test for conditions that indicate we should loop | 2624 // Function to test for conditions that indicate we should loop |
| 2623 // back and recode a frame. | 2625 // back and recode a frame. |
| 2624 static int recode_loop_test(VP9_COMP *cpi, | 2626 static int recode_loop_test(VP9_COMP *cpi, |
| 2625 int high_limit, int low_limit, | 2627 int high_limit, int low_limit, |
| 2626 int q, int maxq, int minq) { | 2628 int q, int maxq, int minq) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2740 } | 2742 } |
| 2741 | 2743 |
| 2742 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { | 2744 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { |
| 2743 MACROBLOCKD *xd = &cpi->td.mb.e_mbd; | 2745 MACROBLOCKD *xd = &cpi->td.mb.e_mbd; |
| 2744 struct loopfilter *lf = &cm->lf; | 2746 struct loopfilter *lf = &cm->lf; |
| 2745 if (xd->lossless) { | 2747 if (xd->lossless) { |
| 2746 lf->filter_level = 0; | 2748 lf->filter_level = 0; |
| 2747 } else { | 2749 } else { |
| 2748 struct vpx_usec_timer timer; | 2750 struct vpx_usec_timer timer; |
| 2749 | 2751 |
| 2750 vp9_clear_system_state(); | 2752 vpx_clear_system_state(); |
| 2751 | 2753 |
| 2752 vpx_usec_timer_start(&timer); | 2754 vpx_usec_timer_start(&timer); |
| 2753 | 2755 |
| 2754 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick); | 2756 vp9_pick_filter_level(cpi->Source, cpi, cpi->sf.lpf_pick); |
| 2755 | 2757 |
| 2756 vpx_usec_timer_mark(&timer); | 2758 vpx_usec_timer_mark(&timer); |
| 2757 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); | 2759 cpi->time_pick_lpf += vpx_usec_timer_elapsed(&timer); |
| 2758 } | 2760 } |
| 2759 | 2761 |
| 2760 if (lf->filter_level > 0) { | 2762 if (lf->filter_level > 0) { |
| 2761 if (cpi->num_workers > 1) | 2763 if (cpi->num_workers > 1) |
| 2762 vp9_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane, | 2764 vp9_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane, |
| 2763 lf->filter_level, 0, 0, | 2765 lf->filter_level, 0, 0, |
| 2764 cpi->workers, cpi->num_workers, | 2766 cpi->workers, cpi->num_workers, |
| 2765 &cpi->lf_row_sync); | 2767 &cpi->lf_row_sync); |
| 2766 else | 2768 else |
| 2767 vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); | 2769 vp9_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0); |
| 2768 } | 2770 } |
| 2769 | 2771 |
| 2770 vp9_extend_frame_inner_borders(cm->frame_to_show); | 2772 vpx_extend_frame_inner_borders(cm->frame_to_show); |
| 2771 } | 2773 } |
| 2772 | 2774 |
| 2773 static INLINE void alloc_frame_mvs(const VP9_COMMON *cm, | 2775 static INLINE void alloc_frame_mvs(const VP9_COMMON *cm, |
| 2774 int buffer_idx) { | 2776 int buffer_idx) { |
| 2775 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; | 2777 RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx]; |
| 2776 if (new_fb_ptr->mvs == NULL || | 2778 if (new_fb_ptr->mvs == NULL || |
| 2777 new_fb_ptr->mi_rows < cm->mi_rows || | 2779 new_fb_ptr->mi_rows < cm->mi_rows || |
| 2778 new_fb_ptr->mi_cols < cm->mi_cols) { | 2780 new_fb_ptr->mi_cols < cm->mi_cols) { |
| 2779 vpx_free(new_fb_ptr->mvs); | 2781 vpx_free(new_fb_ptr->mvs); |
| 2780 new_fb_ptr->mvs = | 2782 new_fb_ptr->mvs = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2810 if (new_fb == INVALID_IDX) { | 2812 if (new_fb == INVALID_IDX) { |
| 2811 new_fb = get_free_fb(cm); | 2813 new_fb = get_free_fb(cm); |
| 2812 force_scaling = 1; | 2814 force_scaling = 1; |
| 2813 } | 2815 } |
| 2814 if (new_fb == INVALID_IDX) | 2816 if (new_fb == INVALID_IDX) |
| 2815 return; | 2817 return; |
| 2816 new_fb_ptr = &pool->frame_bufs[new_fb]; | 2818 new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 2817 if (force_scaling || | 2819 if (force_scaling || |
| 2818 new_fb_ptr->buf.y_crop_width != cm->width || | 2820 new_fb_ptr->buf.y_crop_width != cm->width || |
| 2819 new_fb_ptr->buf.y_crop_height != cm->height) { | 2821 new_fb_ptr->buf.y_crop_height != cm->height) { |
| 2820 vp9_realloc_frame_buffer(&new_fb_ptr->buf, | 2822 vpx_realloc_frame_buffer(&new_fb_ptr->buf, |
| 2821 cm->width, cm->height, | 2823 cm->width, cm->height, |
| 2822 cm->subsampling_x, cm->subsampling_y, | 2824 cm->subsampling_x, cm->subsampling_y, |
| 2823 cm->use_highbitdepth, | 2825 cm->use_highbitdepth, |
| 2824 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 2826 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 2825 NULL, NULL, NULL); | 2827 NULL, NULL, NULL); |
| 2826 scale_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth); | 2828 scale_and_extend_frame(ref, &new_fb_ptr->buf, (int)cm->bit_depth); |
| 2827 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; | 2829 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 2828 alloc_frame_mvs(cm, new_fb); | 2830 alloc_frame_mvs(cm, new_fb); |
| 2829 } | 2831 } |
| 2830 #else | 2832 #else |
| 2831 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { | 2833 if (ref->y_crop_width != cm->width || ref->y_crop_height != cm->height) { |
| 2832 RefCntBuffer *new_fb_ptr = NULL; | 2834 RefCntBuffer *new_fb_ptr = NULL; |
| 2833 int force_scaling = 0; | 2835 int force_scaling = 0; |
| 2834 int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; | 2836 int new_fb = cpi->scaled_ref_idx[ref_frame - 1]; |
| 2835 if (new_fb == INVALID_IDX) { | 2837 if (new_fb == INVALID_IDX) { |
| 2836 new_fb = get_free_fb(cm); | 2838 new_fb = get_free_fb(cm); |
| 2837 force_scaling = 1; | 2839 force_scaling = 1; |
| 2838 } | 2840 } |
| 2839 if (new_fb == INVALID_IDX) | 2841 if (new_fb == INVALID_IDX) |
| 2840 return; | 2842 return; |
| 2841 new_fb_ptr = &pool->frame_bufs[new_fb]; | 2843 new_fb_ptr = &pool->frame_bufs[new_fb]; |
| 2842 if (force_scaling || | 2844 if (force_scaling || |
| 2843 new_fb_ptr->buf.y_crop_width != cm->width || | 2845 new_fb_ptr->buf.y_crop_width != cm->width || |
| 2844 new_fb_ptr->buf.y_crop_height != cm->height) { | 2846 new_fb_ptr->buf.y_crop_height != cm->height) { |
| 2845 vp9_realloc_frame_buffer(&new_fb_ptr->buf, | 2847 vpx_realloc_frame_buffer(&new_fb_ptr->buf, |
| 2846 cm->width, cm->height, | 2848 cm->width, cm->height, |
| 2847 cm->subsampling_x, cm->subsampling_y, | 2849 cm->subsampling_x, cm->subsampling_y, |
| 2848 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 2850 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 2849 NULL, NULL, NULL); | 2851 NULL, NULL, NULL); |
| 2850 scale_and_extend_frame(ref, &new_fb_ptr->buf); | 2852 scale_and_extend_frame(ref, &new_fb_ptr->buf); |
| 2851 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; | 2853 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 2852 alloc_frame_mvs(cm, new_fb); | 2854 alloc_frame_mvs(cm, new_fb); |
| 2853 } | 2855 } |
| 2854 #endif // CONFIG_VP9_HIGHBITDEPTH | 2856 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 2855 } else { | 2857 } else { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2924 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) | 2926 for (l = 0; l < BAND_COEFF_CONTEXTS(k); ++l) |
| 2925 full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]); | 2927 full_to_model_count(model_count[i][j][k][l], full_count[i][j][k][l]); |
| 2926 } | 2928 } |
| 2927 | 2929 |
| 2928 #if 0 && CONFIG_INTERNAL_STATS | 2930 #if 0 && CONFIG_INTERNAL_STATS |
| 2929 static void output_frame_level_debug_stats(VP9_COMP *cpi) { | 2931 static void output_frame_level_debug_stats(VP9_COMP *cpi) { |
| 2930 VP9_COMMON *const cm = &cpi->common; | 2932 VP9_COMMON *const cm = &cpi->common; |
| 2931 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); | 2933 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 2932 int64_t recon_err; | 2934 int64_t recon_err; |
| 2933 | 2935 |
| 2934 vp9_clear_system_state(); | 2936 vpx_clear_system_state(); |
| 2935 | 2937 |
| 2936 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); | 2938 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); |
| 2937 | 2939 |
| 2938 if (cpi->twopass.total_left_stats.coded_error != 0.0) | 2940 if (cpi->twopass.total_left_stats.coded_error != 0.0) |
| 2939 fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" | 2941 fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" |
| 2940 "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " | 2942 "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " |
| 2941 "%10"PRId64" %10"PRId64" %10d " | 2943 "%10"PRId64" %10"PRId64" %10d " |
| 2942 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" | 2944 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 2943 "%6d %6d %5d %5d %5d " | 2945 "%6d %6d %5d %5d %5d " |
| 2944 "%10"PRId64" %10.3lf" | 2946 "%10"PRId64" %10.3lf" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2989 | 2991 |
| 2990 fprintf(fmodes, "\n"); | 2992 fprintf(fmodes, "\n"); |
| 2991 | 2993 |
| 2992 fclose(fmodes); | 2994 fclose(fmodes); |
| 2993 } | 2995 } |
| 2994 } | 2996 } |
| 2995 #endif | 2997 #endif |
| 2996 | 2998 |
| 2997 static void set_mv_search_params(VP9_COMP *cpi) { | 2999 static void set_mv_search_params(VP9_COMP *cpi) { |
| 2998 const VP9_COMMON *const cm = &cpi->common; | 3000 const VP9_COMMON *const cm = &cpi->common; |
| 2999 const unsigned int max_mv_def = MIN(cm->width, cm->height); | 3001 const unsigned int max_mv_def = VPXMIN(cm->width, cm->height); |
| 3000 | 3002 |
| 3001 // Default based on max resolution. | 3003 // Default based on max resolution. |
| 3002 cpi->mv_step_param = vp9_init_search_range(max_mv_def); | 3004 cpi->mv_step_param = vp9_init_search_range(max_mv_def); |
| 3003 | 3005 |
| 3004 if (cpi->sf.mv.auto_mv_step_size) { | 3006 if (cpi->sf.mv.auto_mv_step_size) { |
| 3005 if (frame_is_intra_only(cm)) { | 3007 if (frame_is_intra_only(cm)) { |
| 3006 // Initialize max_mv_magnitude for use in the first INTER frame | 3008 // Initialize max_mv_magnitude for use in the first INTER frame |
| 3007 // after a key/intra-only frame. | 3009 // after a key/intra-only frame. |
| 3008 cpi->max_mv_magnitude = max_mv_def; | 3010 cpi->max_mv_magnitude = max_mv_def; |
| 3009 } else { | 3011 } else { |
| 3010 if (cm->show_frame) { | 3012 if (cm->show_frame) { |
| 3011 // Allow mv_steps to correspond to twice the max mv magnitude found | 3013 // Allow mv_steps to correspond to twice the max mv magnitude found |
| 3012 // in the previous frame, capped by the default max_mv_magnitude based | 3014 // in the previous frame, capped by the default max_mv_magnitude based |
| 3013 // on resolution. | 3015 // on resolution. |
| 3014 cpi->mv_step_param = | 3016 cpi->mv_step_param = vp9_init_search_range( |
| 3015 vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude)); | 3017 VPXMIN(max_mv_def, 2 * cpi->max_mv_magnitude)); |
| 3016 } | 3018 } |
| 3017 cpi->max_mv_magnitude = 0; | 3019 cpi->max_mv_magnitude = 0; |
| 3018 } | 3020 } |
| 3019 } | 3021 } |
| 3020 } | 3022 } |
| 3021 | 3023 |
| 3022 static void set_size_independent_vars(VP9_COMP *cpi) { | 3024 static void set_size_independent_vars(VP9_COMP *cpi) { |
| 3023 vp9_set_speed_features_framesize_independent(cpi); | 3025 vp9_set_speed_features_framesize_independent(cpi); |
| 3024 vp9_set_rd_speed_thresholds(cpi); | 3026 vp9_set_rd_speed_thresholds(cpi); |
| 3025 vp9_set_rd_speed_thresholds_sub8x8(cpi); | 3027 vp9_set_rd_speed_thresholds_sub8x8(cpi); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3130 if ((oxcf->pass == 2) && | 3132 if ((oxcf->pass == 2) && |
| 3131 (!cpi->use_svc || | 3133 (!cpi->use_svc || |
| 3132 (is_two_pass_svc(cpi) && | 3134 (is_two_pass_svc(cpi) && |
| 3133 cpi->svc.encode_empty_frame_state != ENCODING))) { | 3135 cpi->svc.encode_empty_frame_state != ENCODING))) { |
| 3134 vp9_set_target_rate(cpi); | 3136 vp9_set_target_rate(cpi); |
| 3135 } | 3137 } |
| 3136 | 3138 |
| 3137 alloc_frame_mvs(cm, cm->new_fb_idx); | 3139 alloc_frame_mvs(cm, cm->new_fb_idx); |
| 3138 | 3140 |
| 3139 // Reset the frame pointers to the current frame size. | 3141 // Reset the frame pointers to the current frame size. |
| 3140 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), | 3142 vpx_realloc_frame_buffer(get_frame_new_buffer(cm), |
| 3141 cm->width, cm->height, | 3143 cm->width, cm->height, |
| 3142 cm->subsampling_x, cm->subsampling_y, | 3144 cm->subsampling_x, cm->subsampling_y, |
| 3143 #if CONFIG_VP9_HIGHBITDEPTH | 3145 #if CONFIG_VP9_HIGHBITDEPTH |
| 3144 cm->use_highbitdepth, | 3146 cm->use_highbitdepth, |
| 3145 #endif | 3147 #endif |
| 3146 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, | 3148 VP9_ENC_BORDER_IN_PIXELS, cm->byte_alignment, |
| 3147 NULL, NULL, NULL); | 3149 NULL, NULL, NULL); |
| 3148 | 3150 |
| 3149 alloc_util_frame_buffers(cpi); | 3151 alloc_util_frame_buffers(cpi); |
| 3150 init_motion_estimation(cpi); | 3152 init_motion_estimation(cpi); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3163 buf->y_crop_width, buf->y_crop_height, | 3165 buf->y_crop_width, buf->y_crop_height, |
| 3164 cm->width, cm->height, | 3166 cm->width, cm->height, |
| 3165 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? | 3167 (buf->flags & YV12_FLAG_HIGHBITDEPTH) ? |
| 3166 1 : 0); | 3168 1 : 0); |
| 3167 #else | 3169 #else |
| 3168 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | 3170 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
| 3169 buf->y_crop_width, buf->y_crop_height, | 3171 buf->y_crop_width, buf->y_crop_height, |
| 3170 cm->width, cm->height); | 3172 cm->width, cm->height); |
| 3171 #endif // CONFIG_VP9_HIGHBITDEPTH | 3173 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 3172 if (vp9_is_scaled(&ref_buf->sf)) | 3174 if (vp9_is_scaled(&ref_buf->sf)) |
| 3173 vp9_extend_frame_borders(buf); | 3175 vpx_extend_frame_borders(buf); |
| 3174 } else { | 3176 } else { |
| 3175 ref_buf->buf = NULL; | 3177 ref_buf->buf = NULL; |
| 3176 } | 3178 } |
| 3177 } | 3179 } |
| 3178 | 3180 |
| 3179 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); | 3181 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3180 } | 3182 } |
| 3181 | 3183 |
| 3182 static void encode_without_recode_loop(VP9_COMP *cpi) { | 3184 static void encode_without_recode_loop(VP9_COMP *cpi, |
| 3185 size_t *size, |
| 3186 uint8_t *dest) { |
| 3183 VP9_COMMON *const cm = &cpi->common; | 3187 VP9_COMMON *const cm = &cpi->common; |
| 3184 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. | 3188 int q = 0, bottom_index = 0, top_index = 0; // Dummy variables. |
| 3185 | 3189 |
| 3186 vp9_clear_system_state(); | 3190 vpx_clear_system_state(); |
| 3187 | 3191 |
| 3188 set_frame_size(cpi); | 3192 set_frame_size(cpi); |
| 3189 | 3193 |
| 3190 // For 1 pass CBR under dynamic resize mode: use faster scaling for source. | 3194 cpi->Source = vp9_scale_if_required(cm, |
| 3191 // Only for 2x2 scaling for now. | 3195 cpi->un_scaled_source, |
| 3196 &cpi->scaled_source); |
| 3197 if (cpi->unscaled_last_source != NULL) |
| 3198 cpi->Last_Source = vp9_scale_if_required(cm, |
| 3199 cpi->unscaled_last_source, |
| 3200 &cpi->scaled_last_source); |
| 3201 |
| 3192 if (cpi->oxcf.pass == 0 && | 3202 if (cpi->oxcf.pass == 0 && |
| 3193 cpi->oxcf.rc_mode == VPX_CBR && | 3203 cpi->oxcf.rc_mode == VPX_CBR && |
| 3194 cpi->oxcf.resize_mode == RESIZE_DYNAMIC && | 3204 cpi->resize_state == 0 && |
| 3195 cpi->un_scaled_source->y_width == (cm->width << 1) && | 3205 cm->frame_type != KEY_FRAME && |
| 3196 cpi->un_scaled_source->y_height == (cm->height << 1)) { | 3206 cpi->oxcf.content == VP9E_CONTENT_SCREEN) |
| 3197 cpi->Source = vp9_scale_if_required_fast(cm, | 3207 vp9_avg_source_sad(cpi); |
| 3198 cpi->un_scaled_source, | |
| 3199 &cpi->scaled_source); | |
| 3200 if (cpi->unscaled_last_source != NULL) | |
| 3201 cpi->Last_Source = vp9_scale_if_required_fast(cm, | |
| 3202 cpi->unscaled_last_source, | |
| 3203 &cpi->scaled_last_source); | |
| 3204 } else { | |
| 3205 cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, | |
| 3206 &cpi->scaled_source); | |
| 3207 if (cpi->unscaled_last_source != NULL) | |
| 3208 cpi->Last_Source = vp9_scale_if_required(cm, cpi->unscaled_last_source, | |
| 3209 &cpi->scaled_last_source); | |
| 3210 } | |
| 3211 | 3208 |
| 3212 if (frame_is_intra_only(cm) == 0) { | 3209 if (frame_is_intra_only(cm) == 0) { |
| 3213 vp9_scale_references(cpi); | 3210 vp9_scale_references(cpi); |
| 3214 } | 3211 } |
| 3215 | 3212 |
| 3216 set_size_independent_vars(cpi); | 3213 set_size_independent_vars(cpi); |
| 3217 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); | 3214 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 3218 | 3215 |
| 3219 vp9_set_quantizer(cm, q); | 3216 vp9_set_quantizer(cm, q); |
| 3220 vp9_set_variance_partition_thresholds(cpi, q); | 3217 vp9_set_variance_partition_thresholds(cpi, q); |
| 3221 | 3218 |
| 3222 setup_frame(cpi); | 3219 setup_frame(cpi); |
| 3223 | 3220 |
| 3224 suppress_active_map(cpi); | 3221 suppress_active_map(cpi); |
| 3225 // Variance adaptive and in frame q adjustment experiments are mutually | 3222 // Variance adaptive and in frame q adjustment experiments are mutually |
| 3226 // exclusive. | 3223 // exclusive. |
| 3227 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 3224 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
| 3228 vp9_vaq_frame_setup(cpi); | 3225 vp9_vaq_frame_setup(cpi); |
| 3229 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 3226 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 3230 vp9_setup_in_frame_q_adj(cpi); | 3227 vp9_setup_in_frame_q_adj(cpi); |
| 3231 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { | 3228 } else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
| 3232 vp9_cyclic_refresh_setup(cpi); | 3229 vp9_cyclic_refresh_setup(cpi); |
| 3233 } | 3230 } |
| 3234 apply_active_map(cpi); | 3231 apply_active_map(cpi); |
| 3235 | 3232 |
| 3236 // transform / motion compensation build reconstruction frame | 3233 // transform / motion compensation build reconstruction frame |
| 3237 vp9_encode_frame(cpi); | 3234 vp9_encode_frame(cpi); |
| 3238 | 3235 |
| 3236 // Check if we should drop this frame because of high overshoot. |
| 3237 // Only for frames where high temporal-source sad is detected. |
| 3238 if (cpi->oxcf.pass == 0 && |
| 3239 cpi->oxcf.rc_mode == VPX_CBR && |
| 3240 cpi->resize_state == 0 && |
| 3241 cm->frame_type != KEY_FRAME && |
| 3242 cpi->oxcf.content == VP9E_CONTENT_SCREEN && |
| 3243 cpi->rc.high_source_sad == 1) { |
| 3244 int frame_size = 0; |
| 3245 // Get an estimate of the encoded frame size. |
| 3246 save_coding_context(cpi); |
| 3247 vp9_pack_bitstream(cpi, dest, size); |
| 3248 restore_coding_context(cpi); |
| 3249 frame_size = (int)(*size) << 3; |
| 3250 // Check if encoded frame will overshoot too much, and if so, set the q and |
| 3251 // adjust some rate control parameters, and return to re-encode the frame. |
| 3252 if (vp9_encodedframe_overshoot(cpi, frame_size, &q)) { |
| 3253 vpx_clear_system_state(); |
| 3254 vp9_set_quantizer(cm, q); |
| 3255 vp9_set_variance_partition_thresholds(cpi, q); |
| 3256 suppress_active_map(cpi); |
| 3257 // Turn-off cyclic refresh for re-encoded frame. |
| 3258 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
| 3259 unsigned char *const seg_map = cpi->segmentation_map; |
| 3260 memset(seg_map, 0, cm->mi_rows * cm->mi_cols); |
| 3261 vp9_disable_segmentation(&cm->seg); |
| 3262 } |
| 3263 apply_active_map(cpi); |
| 3264 vp9_encode_frame(cpi); |
| 3265 } |
| 3266 } |
| 3267 |
| 3239 // Update some stats from cyclic refresh, and check if we should not update | 3268 // Update some stats from cyclic refresh, and check if we should not update |
| 3240 // golden reference, for non-SVC 1 pass CBR. | 3269 // golden reference, for non-SVC 1 pass CBR. |
| 3241 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && | 3270 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && |
| 3242 cm->frame_type != KEY_FRAME && | 3271 cm->frame_type != KEY_FRAME && |
| 3243 !cpi->use_svc && | 3272 !cpi->use_svc && |
| 3244 (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR)) | 3273 (cpi->oxcf.pass == 0 && cpi->oxcf.rc_mode == VPX_CBR)) |
| 3245 vp9_cyclic_refresh_check_golden_update(cpi); | 3274 vp9_cyclic_refresh_check_golden_update(cpi); |
| 3246 | 3275 |
| 3247 // Update the skip mb flag probabilities based on the distribution | 3276 // Update the skip mb flag probabilities based on the distribution |
| 3248 // seen in the last encoder iteration. | 3277 // seen in the last encoder iteration. |
| 3249 // update_base_skip_probs(cpi); | 3278 // update_base_skip_probs(cpi); |
| 3250 vp9_clear_system_state(); | 3279 vpx_clear_system_state(); |
| 3251 } | 3280 } |
| 3252 | 3281 |
| 3253 static void encode_with_recode_loop(VP9_COMP *cpi, | 3282 static void encode_with_recode_loop(VP9_COMP *cpi, |
| 3254 size_t *size, | 3283 size_t *size, |
| 3255 uint8_t *dest) { | 3284 uint8_t *dest) { |
| 3256 VP9_COMMON *const cm = &cpi->common; | 3285 VP9_COMMON *const cm = &cpi->common; |
| 3257 RATE_CONTROL *const rc = &cpi->rc; | 3286 RATE_CONTROL *const rc = &cpi->rc; |
| 3258 int bottom_index, top_index; | 3287 int bottom_index, top_index; |
| 3259 int loop_count = 0; | 3288 int loop_count = 0; |
| 3260 int loop_at_this_size = 0; | 3289 int loop_at_this_size = 0; |
| 3261 int loop = 0; | 3290 int loop = 0; |
| 3262 int overshoot_seen = 0; | 3291 int overshoot_seen = 0; |
| 3263 int undershoot_seen = 0; | 3292 int undershoot_seen = 0; |
| 3264 int frame_over_shoot_limit; | 3293 int frame_over_shoot_limit; |
| 3265 int frame_under_shoot_limit; | 3294 int frame_under_shoot_limit; |
| 3266 int q = 0, q_low = 0, q_high = 0; | 3295 int q = 0, q_low = 0, q_high = 0; |
| 3267 | 3296 |
| 3268 set_size_independent_vars(cpi); | 3297 set_size_independent_vars(cpi); |
| 3269 | 3298 |
| 3270 do { | 3299 do { |
| 3271 vp9_clear_system_state(); | 3300 vpx_clear_system_state(); |
| 3272 | 3301 |
| 3273 set_frame_size(cpi); | 3302 set_frame_size(cpi); |
| 3274 | 3303 |
| 3275 if (loop_count == 0 || cpi->resize_pending != 0) { | 3304 if (loop_count == 0 || cpi->resize_pending != 0) { |
| 3276 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); | 3305 set_size_dependent_vars(cpi, &q, &bottom_index, &top_index); |
| 3277 | 3306 |
| 3278 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. | 3307 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed. |
| 3279 set_mv_search_params(cpi); | 3308 set_mv_search_params(cpi); |
| 3280 | 3309 |
| 3281 // Reset the loop state for new frame size. | 3310 // Reset the loop state for new frame size. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3325 vp9_setup_in_frame_q_adj(cpi); | 3354 vp9_setup_in_frame_q_adj(cpi); |
| 3326 } | 3355 } |
| 3327 | 3356 |
| 3328 // transform / motion compensation build reconstruction frame | 3357 // transform / motion compensation build reconstruction frame |
| 3329 vp9_encode_frame(cpi); | 3358 vp9_encode_frame(cpi); |
| 3330 | 3359 |
| 3331 // Update the skip mb flag probabilities based on the distribution | 3360 // Update the skip mb flag probabilities based on the distribution |
| 3332 // seen in the last encoder iteration. | 3361 // seen in the last encoder iteration. |
| 3333 // update_base_skip_probs(cpi); | 3362 // update_base_skip_probs(cpi); |
| 3334 | 3363 |
| 3335 vp9_clear_system_state(); | 3364 vpx_clear_system_state(); |
| 3336 | 3365 |
| 3337 // Dummy pack of the bitstream using up to date stats to get an | 3366 // Dummy pack of the bitstream using up to date stats to get an |
| 3338 // accurate estimate of output frame size to determine if we need | 3367 // accurate estimate of output frame size to determine if we need |
| 3339 // to recode. | 3368 // to recode. |
| 3340 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { | 3369 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
| 3341 save_coding_context(cpi); | 3370 save_coding_context(cpi); |
| 3342 if (!cpi->sf.use_nonrd_pick_mode) | 3371 if (!cpi->sf.use_nonrd_pick_mode) |
| 3343 vp9_pack_bitstream(cpi, dest, size); | 3372 vp9_pack_bitstream(cpi, dest, size); |
| 3344 | 3373 |
| 3345 rc->projected_frame_size = (int)(*size) << 3; | 3374 rc->projected_frame_size = (int)(*size) << 3; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3378 // to make it better without undue risk of popping. | 3407 // to make it better without undue risk of popping. |
| 3379 if ((kf_err > high_err_target && | 3408 if ((kf_err > high_err_target && |
| 3380 rc->projected_frame_size <= frame_over_shoot_limit) || | 3409 rc->projected_frame_size <= frame_over_shoot_limit) || |
| 3381 (kf_err > low_err_target && | 3410 (kf_err > low_err_target && |
| 3382 rc->projected_frame_size <= frame_under_shoot_limit)) { | 3411 rc->projected_frame_size <= frame_under_shoot_limit)) { |
| 3383 // Lower q_high | 3412 // Lower q_high |
| 3384 q_high = q > q_low ? q - 1 : q_low; | 3413 q_high = q > q_low ? q - 1 : q_low; |
| 3385 | 3414 |
| 3386 // Adjust Q | 3415 // Adjust Q |
| 3387 q = (int)((q * high_err_target) / kf_err); | 3416 q = (int)((q * high_err_target) / kf_err); |
| 3388 q = MIN(q, (q_high + q_low) >> 1); | 3417 q = VPXMIN(q, (q_high + q_low) >> 1); |
| 3389 } else if (kf_err < low_err_target && | 3418 } else if (kf_err < low_err_target && |
| 3390 rc->projected_frame_size >= frame_under_shoot_limit) { | 3419 rc->projected_frame_size >= frame_under_shoot_limit) { |
| 3391 // The key frame is much better than the previous frame | 3420 // The key frame is much better than the previous frame |
| 3392 // Raise q_low | 3421 // Raise q_low |
| 3393 q_low = q < q_high ? q + 1 : q_high; | 3422 q_low = q < q_high ? q + 1 : q_high; |
| 3394 | 3423 |
| 3395 // Adjust Q | 3424 // Adjust Q |
| 3396 q = (int)((q * low_err_target) / kf_err); | 3425 q = (int)((q * low_err_target) / kf_err); |
| 3397 q = MIN(q, (q_high + q_low + 1) >> 1); | 3426 q = VPXMIN(q, (q_high + q_low + 1) >> 1); |
| 3398 } | 3427 } |
| 3399 | 3428 |
| 3400 // Clamp Q to upper and lower limits: | 3429 // Clamp Q to upper and lower limits: |
| 3401 q = clamp(q, q_low, q_high); | 3430 q = clamp(q, q_low, q_high); |
| 3402 | 3431 |
| 3403 loop = q != last_q; | 3432 loop = q != last_q; |
| 3404 } else if (recode_loop_test( | 3433 } else if (recode_loop_test( |
| 3405 cpi, frame_over_shoot_limit, frame_under_shoot_limit, | 3434 cpi, frame_over_shoot_limit, frame_under_shoot_limit, |
| 3406 q, MAX(q_high, top_index), bottom_index)) { | 3435 q, VPXMAX(q_high, top_index), bottom_index)) { |
| 3407 // Is the projected frame size out of range and are we allowed | 3436 // Is the projected frame size out of range and are we allowed |
| 3408 // to attempt to recode. | 3437 // to attempt to recode. |
| 3409 int last_q = q; | 3438 int last_q = q; |
| 3410 int retries = 0; | 3439 int retries = 0; |
| 3411 | 3440 |
| 3412 if (cpi->resize_pending == 1) { | 3441 if (cpi->resize_pending == 1) { |
| 3413 // Change in frame size so go back around the recode loop. | 3442 // Change in frame size so go back around the recode loop. |
| 3414 cpi->rc.frame_size_selector = | 3443 cpi->rc.frame_size_selector = |
| 3415 SCALE_STEP1 - cpi->rc.frame_size_selector; | 3444 SCALE_STEP1 - cpi->rc.frame_size_selector; |
| 3416 cpi->rc.next_frame_size_selector = cpi->rc.frame_size_selector; | 3445 cpi->rc.next_frame_size_selector = cpi->rc.frame_size_selector; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3438 if (undershoot_seen || loop_at_this_size > 1) { | 3467 if (undershoot_seen || loop_at_this_size > 1) { |
| 3439 // Update rate_correction_factor unless | 3468 // Update rate_correction_factor unless |
| 3440 vp9_rc_update_rate_correction_factors(cpi); | 3469 vp9_rc_update_rate_correction_factors(cpi); |
| 3441 | 3470 |
| 3442 q = (q_high + q_low + 1) / 2; | 3471 q = (q_high + q_low + 1) / 2; |
| 3443 } else { | 3472 } else { |
| 3444 // Update rate_correction_factor unless | 3473 // Update rate_correction_factor unless |
| 3445 vp9_rc_update_rate_correction_factors(cpi); | 3474 vp9_rc_update_rate_correction_factors(cpi); |
| 3446 | 3475 |
| 3447 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 3476 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
| 3448 bottom_index, MAX(q_high, top_index)); | 3477 bottom_index, VPXMAX(q_high, top_index)); |
| 3449 | 3478 |
| 3450 while (q < q_low && retries < 10) { | 3479 while (q < q_low && retries < 10) { |
| 3451 vp9_rc_update_rate_correction_factors(cpi); | 3480 vp9_rc_update_rate_correction_factors(cpi); |
| 3452 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, | 3481 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, |
| 3453 bottom_index, MAX(q_high, top_index)); | 3482 bottom_index, VPXMAX(q_high, top_index)); |
| 3454 retries++; | 3483 retries++; |
| 3455 } | 3484 } |
| 3456 } | 3485 } |
| 3457 | 3486 |
| 3458 overshoot_seen = 1; | 3487 overshoot_seen = 1; |
| 3459 } else { | 3488 } else { |
| 3460 // Frame is too small | 3489 // Frame is too small |
| 3461 q_high = q > q_low ? q - 1 : q_low; | 3490 q_high = q > q_low ? q - 1 : q_low; |
| 3462 | 3491 |
| 3463 if (overshoot_seen || loop_at_this_size > 1) { | 3492 if (overshoot_seen || loop_at_this_size > 1) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3546 cpi->ext_refresh_frame_context_pending = 0; | 3575 cpi->ext_refresh_frame_context_pending = 0; |
| 3547 } | 3576 } |
| 3548 if (cpi->ext_refresh_frame_flags_pending) { | 3577 if (cpi->ext_refresh_frame_flags_pending) { |
| 3549 cpi->refresh_last_frame = cpi->ext_refresh_last_frame; | 3578 cpi->refresh_last_frame = cpi->ext_refresh_last_frame; |
| 3550 cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; | 3579 cpi->refresh_golden_frame = cpi->ext_refresh_golden_frame; |
| 3551 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; | 3580 cpi->refresh_alt_ref_frame = cpi->ext_refresh_alt_ref_frame; |
| 3552 cpi->ext_refresh_frame_flags_pending = 0; | 3581 cpi->ext_refresh_frame_flags_pending = 0; |
| 3553 } | 3582 } |
| 3554 } | 3583 } |
| 3555 | 3584 |
| 3556 YV12_BUFFER_CONFIG *vp9_scale_if_required_fast(VP9_COMMON *cm, | |
| 3557 YV12_BUFFER_CONFIG *unscaled, | |
| 3558 YV12_BUFFER_CONFIG *scaled) { | |
| 3559 if (cm->mi_cols * MI_SIZE != unscaled->y_width || | |
| 3560 cm->mi_rows * MI_SIZE != unscaled->y_height) { | |
| 3561 // For 2x2 scaling down. | |
| 3562 vpx_scale_frame(unscaled, scaled, unscaled->y_buffer, 9, 2, 1, | |
| 3563 2, 1, 0); | |
| 3564 vp9_extend_frame_borders(scaled); | |
| 3565 return scaled; | |
| 3566 } else { | |
| 3567 return unscaled; | |
| 3568 } | |
| 3569 } | |
| 3570 | |
| 3571 YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm, | 3585 YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm, |
| 3572 YV12_BUFFER_CONFIG *unscaled, | 3586 YV12_BUFFER_CONFIG *unscaled, |
| 3573 YV12_BUFFER_CONFIG *scaled) { | 3587 YV12_BUFFER_CONFIG *scaled) { |
| 3574 if (cm->mi_cols * MI_SIZE != unscaled->y_width || | 3588 if (cm->mi_cols * MI_SIZE != unscaled->y_width || |
| 3575 cm->mi_rows * MI_SIZE != unscaled->y_height) { | 3589 cm->mi_rows * MI_SIZE != unscaled->y_height) { |
| 3576 #if CONFIG_VP9_HIGHBITDEPTH | 3590 #if CONFIG_VP9_HIGHBITDEPTH |
| 3577 scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth); | 3591 if (unscaled->y_width == (scaled->y_width << 1) && |
| 3592 unscaled->y_height == (scaled->y_height << 1)) |
| 3593 scale_and_extend_frame(unscaled, scaled, (int)cm->bit_depth); |
| 3594 else |
| 3595 scale_and_extend_frame_nonnormative(unscaled, scaled, (int)cm->bit_depth); |
| 3578 #else | 3596 #else |
| 3579 scale_and_extend_frame_nonnormative(unscaled, scaled); | 3597 // Use the faster normative (convolve8) scaling filter: for now only for |
| 3598 // scaling factor of 2. |
| 3599 if (unscaled->y_width == (scaled->y_width << 1) && |
| 3600 unscaled->y_height == (scaled->y_height << 1)) |
| 3601 scale_and_extend_frame(unscaled, scaled); |
| 3602 else |
| 3603 scale_and_extend_frame_nonnormative(unscaled, scaled); |
| 3580 #endif // CONFIG_VP9_HIGHBITDEPTH | 3604 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 3581 return scaled; | 3605 return scaled; |
| 3582 } else { | 3606 } else { |
| 3583 return unscaled; | 3607 return unscaled; |
| 3584 } | 3608 } |
| 3585 } | 3609 } |
| 3586 | 3610 |
| 3587 static void set_arf_sign_bias(VP9_COMP *cpi) { | 3611 static void set_arf_sign_bias(VP9_COMP *cpi) { |
| 3588 VP9_COMMON *const cm = &cpi->common; | 3612 VP9_COMMON *const cm = &cpi->common; |
| 3589 int arf_sign_bias; | 3613 int arf_sign_bias; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3629 static void encode_frame_to_data_rate(VP9_COMP *cpi, | 3653 static void encode_frame_to_data_rate(VP9_COMP *cpi, |
| 3630 size_t *size, | 3654 size_t *size, |
| 3631 uint8_t *dest, | 3655 uint8_t *dest, |
| 3632 unsigned int *frame_flags) { | 3656 unsigned int *frame_flags) { |
| 3633 VP9_COMMON *const cm = &cpi->common; | 3657 VP9_COMMON *const cm = &cpi->common; |
| 3634 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 3658 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 3635 struct segmentation *const seg = &cm->seg; | 3659 struct segmentation *const seg = &cm->seg; |
| 3636 TX_SIZE t; | 3660 TX_SIZE t; |
| 3637 | 3661 |
| 3638 set_ext_overrides(cpi); | 3662 set_ext_overrides(cpi); |
| 3639 vp9_clear_system_state(); | 3663 vpx_clear_system_state(); |
| 3640 | 3664 |
| 3641 // Set the arf sign bias for this frame. | 3665 // Set the arf sign bias for this frame. |
| 3642 set_arf_sign_bias(cpi); | 3666 set_arf_sign_bias(cpi); |
| 3643 | 3667 |
| 3644 // Set default state for segment based loop filter update flags. | 3668 // Set default state for segment based loop filter update flags. |
| 3645 cm->lf.mode_ref_delta_update = 0; | 3669 cm->lf.mode_ref_delta_update = 0; |
| 3646 | 3670 |
| 3647 if (cpi->oxcf.pass == 2 && | 3671 if (cpi->oxcf.pass == 2 && |
| 3648 cpi->sf.adaptive_interp_filter_search) | 3672 cpi->sf.adaptive_interp_filter_search) |
| 3649 cpi->sf.interp_filter_search_mask = | 3673 cpi->sf.interp_filter_search_mask = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3720 if (oxcf->pass == 0 && | 3744 if (oxcf->pass == 0 && |
| 3721 oxcf->rc_mode == VPX_CBR && | 3745 oxcf->rc_mode == VPX_CBR && |
| 3722 cm->frame_type != KEY_FRAME) { | 3746 cm->frame_type != KEY_FRAME) { |
| 3723 if (vp9_rc_drop_frame(cpi)) { | 3747 if (vp9_rc_drop_frame(cpi)) { |
| 3724 vp9_rc_postencode_update_drop_frame(cpi); | 3748 vp9_rc_postencode_update_drop_frame(cpi); |
| 3725 ++cm->current_video_frame; | 3749 ++cm->current_video_frame; |
| 3726 return; | 3750 return; |
| 3727 } | 3751 } |
| 3728 } | 3752 } |
| 3729 | 3753 |
| 3730 vp9_clear_system_state(); | 3754 vpx_clear_system_state(); |
| 3731 | 3755 |
| 3732 #if CONFIG_INTERNAL_STATS | 3756 #if CONFIG_INTERNAL_STATS |
| 3733 memset(cpi->mode_chosen_counts, 0, | 3757 memset(cpi->mode_chosen_counts, 0, |
| 3734 MAX_MODES * sizeof(*cpi->mode_chosen_counts)); | 3758 MAX_MODES * sizeof(*cpi->mode_chosen_counts)); |
| 3735 #endif | 3759 #endif |
| 3736 | 3760 |
| 3737 if (cpi->sf.recode_loop == DISALLOW_RECODE) { | 3761 if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 3738 encode_without_recode_loop(cpi); | 3762 encode_without_recode_loop(cpi, size, dest); |
| 3739 } else { | 3763 } else { |
| 3740 encode_with_recode_loop(cpi, size, dest); | 3764 encode_with_recode_loop(cpi, size, dest); |
| 3741 } | 3765 } |
| 3742 | 3766 |
| 3743 #if CONFIG_VP9_TEMPORAL_DENOISING | 3767 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 3744 #ifdef OUTPUT_YUV_DENOISED | 3768 #ifdef OUTPUT_YUV_DENOISED |
| 3745 if (oxcf->noise_sensitivity > 0) { | 3769 if (oxcf->noise_sensitivity > 0) { |
| 3746 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], | 3770 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], |
| 3747 yuv_denoised_file); | 3771 yuv_denoised_file); |
| 3748 } | 3772 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4022 step = (int)((this_duration - last_duration) * 10 / last_duration); | 4046 step = (int)((this_duration - last_duration) * 10 / last_duration); |
| 4023 } | 4047 } |
| 4024 | 4048 |
| 4025 if (this_duration) { | 4049 if (this_duration) { |
| 4026 if (step) { | 4050 if (step) { |
| 4027 vp9_new_framerate(cpi, 10000000.0 / this_duration); | 4051 vp9_new_framerate(cpi, 10000000.0 / this_duration); |
| 4028 } else { | 4052 } else { |
| 4029 // Average this frame's rate into the last second's average | 4053 // Average this frame's rate into the last second's average |
| 4030 // frame rate. If we haven't seen 1 second yet, then average | 4054 // frame rate. If we haven't seen 1 second yet, then average |
| 4031 // over the whole interval seen. | 4055 // over the whole interval seen. |
| 4032 const double interval = MIN((double)(source->ts_end | 4056 const double interval = VPXMIN( |
| 4033 - cpi->first_time_stamp_ever), 10000000.0); | 4057 (double)(source->ts_end - cpi->first_time_stamp_ever), 10000000.0); |
| 4034 double avg_duration = 10000000.0 / cpi->framerate; | 4058 double avg_duration = 10000000.0 / cpi->framerate; |
| 4035 avg_duration *= (interval - avg_duration + this_duration); | 4059 avg_duration *= (interval - avg_duration + this_duration); |
| 4036 avg_duration /= interval; | 4060 avg_duration /= interval; |
| 4037 | 4061 |
| 4038 vp9_new_framerate(cpi, 10000000.0 / avg_duration); | 4062 vp9_new_framerate(cpi, 10000000.0 / avg_duration); |
| 4039 } | 4063 } |
| 4040 } | 4064 } |
| 4041 cpi->last_time_stamp_seen = source->ts_start; | 4065 cpi->last_time_stamp_seen = source->ts_start; |
| 4042 cpi->last_end_time_stamp_seen = source->ts_end; | 4066 cpi->last_end_time_stamp_seen = source->ts_end; |
| 4043 } | 4067 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4077 // Current frame is an ARF overlay frame. | 4101 // Current frame is an ARF overlay frame. |
| 4078 cpi->alt_ref_source = NULL; | 4102 cpi->alt_ref_source = NULL; |
| 4079 | 4103 |
| 4080 // Don't refresh the last buffer for an ARF overlay frame. It will | 4104 // Don't refresh the last buffer for an ARF overlay frame. It will |
| 4081 // become the GF so preserve last as an alternative prediction option. | 4105 // become the GF so preserve last as an alternative prediction option. |
| 4082 cpi->refresh_last_frame = 0; | 4106 cpi->refresh_last_frame = 0; |
| 4083 } | 4107 } |
| 4084 } | 4108 } |
| 4085 | 4109 |
| 4086 #if CONFIG_INTERNAL_STATS | 4110 #if CONFIG_INTERNAL_STATS |
| 4087 extern double vp9_get_blockiness(const unsigned char *img1, int img1_pitch, | 4111 extern double vp9_get_blockiness(const uint8_t *img1, int img1_pitch, |
| 4088 const unsigned char *img2, int img2_pitch, | 4112 const uint8_t *img2, int img2_pitch, |
| 4089 int width, int height); | 4113 int width, int height); |
| 4090 | 4114 |
| 4091 static void adjust_image_stat(double y, double u, double v, double all, | 4115 static void adjust_image_stat(double y, double u, double v, double all, |
| 4092 ImageStat *s) { | 4116 ImageStat *s) { |
| 4093 s->stat[Y] += y; | 4117 s->stat[Y] += y; |
| 4094 s->stat[U] += u; | 4118 s->stat[U] += u; |
| 4095 s->stat[V] += v; | 4119 s->stat[V] += v; |
| 4096 s->stat[ALL] += all; | 4120 s->stat[ALL] += all; |
| 4097 s->worst = MIN(s->worst, all); | 4121 s->worst = VPXMIN(s->worst, all); |
| 4098 } | 4122 } |
| 4099 #endif // CONFIG_INTERNAL_STATS | 4123 #endif // CONFIG_INTERNAL_STATS |
| 4100 | 4124 |
| 4101 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, | 4125 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
| 4102 size_t *size, uint8_t *dest, | 4126 size_t *size, uint8_t *dest, |
| 4103 int64_t *time_stamp, int64_t *time_end, int flush) { | 4127 int64_t *time_stamp, int64_t *time_end, int flush) { |
| 4104 const VP9EncoderConfig *const oxcf = &cpi->oxcf; | 4128 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 4105 VP9_COMMON *const cm = &cpi->common; | 4129 VP9_COMMON *const cm = &cpi->common; |
| 4106 BufferPool *const pool = cm->buffer_pool; | 4130 BufferPool *const pool = cm->buffer_pool; |
| 4107 RATE_CONTROL *const rc = &cpi->rc; | 4131 RATE_CONTROL *const rc = &cpi->rc; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4170 break; | 4194 break; |
| 4171 } | 4195 } |
| 4172 } | 4196 } |
| 4173 } | 4197 } |
| 4174 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; | 4198 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; |
| 4175 #endif | 4199 #endif |
| 4176 | 4200 |
| 4177 if (oxcf->arnr_max_frames > 0) { | 4201 if (oxcf->arnr_max_frames > 0) { |
| 4178 // Produce the filtered ARF frame. | 4202 // Produce the filtered ARF frame. |
| 4179 vp9_temporal_filter(cpi, arf_src_index); | 4203 vp9_temporal_filter(cpi, arf_src_index); |
| 4180 vp9_extend_frame_borders(&cpi->alt_ref_buffer); | 4204 vpx_extend_frame_borders(&cpi->alt_ref_buffer); |
| 4181 force_src_buffer = &cpi->alt_ref_buffer; | 4205 force_src_buffer = &cpi->alt_ref_buffer; |
| 4182 } | 4206 } |
| 4183 | 4207 |
| 4184 cm->show_frame = 0; | 4208 cm->show_frame = 0; |
| 4185 cm->intra_only = 0; | 4209 cm->intra_only = 0; |
| 4186 cpi->refresh_alt_ref_frame = 1; | 4210 cpi->refresh_alt_ref_frame = 1; |
| 4187 cpi->refresh_golden_frame = 0; | 4211 cpi->refresh_golden_frame = 0; |
| 4188 cpi->refresh_last_frame = 0; | 4212 cpi->refresh_last_frame = 0; |
| 4189 rc->is_src_frame_alt_ref = 0; | 4213 rc->is_src_frame_alt_ref = 0; |
| 4190 rc->source_alt_ref_pending = 0; | 4214 rc->source_alt_ref_pending = 0; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4240 } | 4264 } |
| 4241 return -1; | 4265 return -1; |
| 4242 } | 4266 } |
| 4243 | 4267 |
| 4244 if (source->ts_start < cpi->first_time_stamp_ever) { | 4268 if (source->ts_start < cpi->first_time_stamp_ever) { |
| 4245 cpi->first_time_stamp_ever = source->ts_start; | 4269 cpi->first_time_stamp_ever = source->ts_start; |
| 4246 cpi->last_end_time_stamp_seen = source->ts_start; | 4270 cpi->last_end_time_stamp_seen = source->ts_start; |
| 4247 } | 4271 } |
| 4248 | 4272 |
| 4249 // Clear down mmx registers | 4273 // Clear down mmx registers |
| 4250 vp9_clear_system_state(); | 4274 vpx_clear_system_state(); |
| 4251 | 4275 |
| 4252 // adjust frame rates based on timestamps given | 4276 // adjust frame rates based on timestamps given |
| 4253 if (cm->show_frame) { | 4277 if (cm->show_frame) { |
| 4254 adjust_frame_rate(cpi, source); | 4278 adjust_frame_rate(cpi, source); |
| 4255 } | 4279 } |
| 4256 | 4280 |
| 4257 if (is_one_pass_cbr_svc(cpi)) { | 4281 if (is_one_pass_cbr_svc(cpi)) { |
| 4258 vp9_update_temporal_layer_framerate(cpi); | 4282 vp9_update_temporal_layer_framerate(cpi); |
| 4259 vp9_restore_layer_context(cpi); | 4283 vp9_restore_layer_context(cpi); |
| 4260 } | 4284 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4377 adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], | 4401 adjust_image_stat(psnr.psnr[1], psnr.psnr[2], psnr.psnr[3], |
| 4378 psnr.psnr[0], &cpi->psnr); | 4402 psnr.psnr[0], &cpi->psnr); |
| 4379 cpi->total_sq_error += psnr.sse[0]; | 4403 cpi->total_sq_error += psnr.sse[0]; |
| 4380 cpi->total_samples += psnr.samples[0]; | 4404 cpi->total_samples += psnr.samples[0]; |
| 4381 samples = psnr.samples[0]; | 4405 samples = psnr.samples[0]; |
| 4382 | 4406 |
| 4383 { | 4407 { |
| 4384 PSNR_STATS psnr2; | 4408 PSNR_STATS psnr2; |
| 4385 double frame_ssim2 = 0, weight = 0; | 4409 double frame_ssim2 = 0, weight = 0; |
| 4386 #if CONFIG_VP9_POSTPROC | 4410 #if CONFIG_VP9_POSTPROC |
| 4387 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, | 4411 if (vpx_alloc_frame_buffer(&cm->post_proc_buffer, |
| 4388 recon->y_crop_width, recon->y_crop_height, | 4412 recon->y_crop_width, recon->y_crop_height, |
| 4389 cm->subsampling_x, cm->subsampling_y, | 4413 cm->subsampling_x, cm->subsampling_y, |
| 4390 #if CONFIG_VP9_HIGHBITDEPTH | 4414 #if CONFIG_VP9_HIGHBITDEPTH |
| 4391 cm->use_highbitdepth, | 4415 cm->use_highbitdepth, |
| 4392 #endif | 4416 #endif |
| 4393 VP9_ENC_BORDER_IN_PIXELS, | 4417 VP9_ENC_BORDER_IN_PIXELS, |
| 4394 cm->byte_alignment) < 0) { | 4418 cm->byte_alignment) < 0) { |
| 4395 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 4419 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 4396 "Failed to allocate post processing buffer"); | 4420 "Failed to allocate post processing buffer"); |
| 4397 } | 4421 } |
| 4398 | 4422 |
| 4399 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, | 4423 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, |
| 4400 cm->lf.filter_level * 10 / 6); | 4424 cm->lf.filter_level * 10 / 6); |
| 4401 #endif | 4425 #endif |
| 4402 vp9_clear_system_state(); | 4426 vpx_clear_system_state(); |
| 4403 | 4427 |
| 4404 #if CONFIG_VP9_HIGHBITDEPTH | 4428 #if CONFIG_VP9_HIGHBITDEPTH |
| 4405 calc_highbd_psnr(orig, pp, &psnr2, cpi->td.mb.e_mbd.bd, | 4429 calc_highbd_psnr(orig, pp, &psnr2, cpi->td.mb.e_mbd.bd, |
| 4406 cpi->oxcf.input_bit_depth); | 4430 cpi->oxcf.input_bit_depth); |
| 4407 #else | 4431 #else |
| 4408 calc_psnr(orig, pp, &psnr2); | 4432 calc_psnr(orig, pp, &psnr2); |
| 4409 #endif // CONFIG_VP9_HIGHBITDEPTH | 4433 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 4410 | 4434 |
| 4411 cpi->totalp_sq_error += psnr2.sse[0]; | 4435 cpi->totalp_sq_error += psnr2.sse[0]; |
| 4412 cpi->totalp_samples += psnr2.samples[0]; | 4436 cpi->totalp_samples += psnr2.samples[0]; |
| 4413 adjust_image_stat(psnr2.psnr[1], psnr2.psnr[2], psnr2.psnr[3], | 4437 adjust_image_stat(psnr2.psnr[1], psnr2.psnr[2], psnr2.psnr[3], |
| 4414 psnr2.psnr[0], &cpi->psnrp); | 4438 psnr2.psnr[0], &cpi->psnrp); |
| 4415 | 4439 |
| 4416 #if CONFIG_VP9_HIGHBITDEPTH | 4440 #if CONFIG_VP9_HIGHBITDEPTH |
| 4417 if (cm->use_highbitdepth) { | 4441 if (cm->use_highbitdepth) { |
| 4418 frame_ssim2 = vp9_highbd_calc_ssim(orig, recon, &weight, | 4442 frame_ssim2 = vpx_highbd_calc_ssim(orig, recon, &weight, |
| 4419 (int)cm->bit_depth); | 4443 (int)cm->bit_depth); |
| 4420 } else { | 4444 } else { |
| 4421 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight); | 4445 frame_ssim2 = vpx_calc_ssim(orig, recon, &weight); |
| 4422 } | 4446 } |
| 4423 #else | 4447 #else |
| 4424 frame_ssim2 = vp9_calc_ssim(orig, recon, &weight); | 4448 frame_ssim2 = vpx_calc_ssim(orig, recon, &weight); |
| 4425 #endif // CONFIG_VP9_HIGHBITDEPTH | 4449 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 4426 | 4450 |
| 4427 cpi->worst_ssim= MIN(cpi->worst_ssim, frame_ssim2); | 4451 cpi->worst_ssim = VPXMIN(cpi->worst_ssim, frame_ssim2); |
| 4428 cpi->summed_quality += frame_ssim2 * weight; | 4452 cpi->summed_quality += frame_ssim2 * weight; |
| 4429 cpi->summed_weights += weight; | 4453 cpi->summed_weights += weight; |
| 4430 | 4454 |
| 4431 #if CONFIG_VP9_HIGHBITDEPTH | 4455 #if CONFIG_VP9_HIGHBITDEPTH |
| 4432 if (cm->use_highbitdepth) { | 4456 if (cm->use_highbitdepth) { |
| 4433 frame_ssim2 = vp9_highbd_calc_ssim( | 4457 frame_ssim2 = vpx_highbd_calc_ssim( |
| 4434 orig, &cm->post_proc_buffer, &weight, (int)cm->bit_depth); | 4458 orig, &cm->post_proc_buffer, &weight, (int)cm->bit_depth); |
| 4435 } else { | 4459 } else { |
| 4436 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight); | 4460 frame_ssim2 = vpx_calc_ssim(orig, &cm->post_proc_buffer, &weight); |
| 4437 } | 4461 } |
| 4438 #else | 4462 #else |
| 4439 frame_ssim2 = vp9_calc_ssim(orig, &cm->post_proc_buffer, &weight); | 4463 frame_ssim2 = vpx_calc_ssim(orig, &cm->post_proc_buffer, &weight); |
| 4440 #endif // CONFIG_VP9_HIGHBITDEPTH | 4464 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 4441 | 4465 |
| 4442 cpi->summedp_quality += frame_ssim2 * weight; | 4466 cpi->summedp_quality += frame_ssim2 * weight; |
| 4443 cpi->summedp_weights += weight; | 4467 cpi->summedp_weights += weight; |
| 4444 #if 0 | 4468 #if 0 |
| 4445 { | 4469 { |
| 4446 FILE *f = fopen("q_used.stt", "a"); | 4470 FILE *f = fopen("q_used.stt", "a"); |
| 4447 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", | 4471 fprintf(f, "%5d : Y%f7.3:U%f7.3:V%f7.3:F%f7.3:S%7.3f\n", |
| 4448 cpi->common.current_video_frame, y2, u2, v2, | 4472 cpi->common.current_video_frame, y2, u2, v2, |
| 4449 frame_psnr2, frame_ssim2); | 4473 frame_psnr2, frame_ssim2); |
| 4450 fclose(f); | 4474 fclose(f); |
| 4451 } | 4475 } |
| 4452 #endif | 4476 #endif |
| 4453 } | 4477 } |
| 4454 } | 4478 } |
| 4455 if (cpi->b_calculate_blockiness) { | 4479 if (cpi->b_calculate_blockiness) { |
| 4456 #if CONFIG_VP9_HIGHBITDEPTH | 4480 #if CONFIG_VP9_HIGHBITDEPTH |
| 4457 if (!cm->use_highbitdepth) | 4481 if (!cm->use_highbitdepth) |
| 4458 #endif | 4482 #endif |
| 4459 { | 4483 { |
| 4460 double frame_blockiness = vp9_get_blockiness( | 4484 double frame_blockiness = vp9_get_blockiness( |
| 4461 cpi->Source->y_buffer, cpi->Source->y_stride, | 4485 cpi->Source->y_buffer, cpi->Source->y_stride, |
| 4462 cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride, | 4486 cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride, |
| 4463 cpi->Source->y_width, cpi->Source->y_height); | 4487 cpi->Source->y_width, cpi->Source->y_height); |
| 4464 cpi->worst_blockiness = MAX(cpi->worst_blockiness, frame_blockiness); | 4488 cpi->worst_blockiness = |
| 4489 VPXMAX(cpi->worst_blockiness, frame_blockiness); |
| 4465 cpi->total_blockiness += frame_blockiness; | 4490 cpi->total_blockiness += frame_blockiness; |
| 4466 } | 4491 } |
| 4467 } | 4492 } |
| 4468 | 4493 |
| 4469 if (cpi->b_calculate_consistency) { | 4494 if (cpi->b_calculate_consistency) { |
| 4470 #if CONFIG_VP9_HIGHBITDEPTH | 4495 #if CONFIG_VP9_HIGHBITDEPTH |
| 4471 if (!cm->use_highbitdepth) | 4496 if (!cm->use_highbitdepth) |
| 4472 #endif | 4497 #endif |
| 4473 { | 4498 { |
| 4474 double this_inconsistency = vp9_get_ssim_metrics( | 4499 double this_inconsistency = vpx_get_ssim_metrics( |
| 4475 cpi->Source->y_buffer, cpi->Source->y_stride, | 4500 cpi->Source->y_buffer, cpi->Source->y_stride, |
| 4476 cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride, | 4501 cm->frame_to_show->y_buffer, cm->frame_to_show->y_stride, |
| 4477 cpi->Source->y_width, cpi->Source->y_height, cpi->ssim_vars, | 4502 cpi->Source->y_width, cpi->Source->y_height, cpi->ssim_vars, |
| 4478 &cpi->metrics, 1); | 4503 &cpi->metrics, 1); |
| 4479 | 4504 |
| 4480 const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); | 4505 const double peak = (double)((1 << cpi->oxcf.input_bit_depth) - 1); |
| 4481 double consistency = vpx_sse_to_psnr(samples, peak, | 4506 double consistency = vpx_sse_to_psnr(samples, peak, |
| 4482 (double)cpi->total_inconsistency); | 4507 (double)cpi->total_inconsistency); |
| 4483 if (consistency > 0.0) | 4508 if (consistency > 0.0) |
| 4484 cpi->worst_consistency = MIN(cpi->worst_consistency, | 4509 cpi->worst_consistency = |
| 4485 consistency); | 4510 VPXMIN(cpi->worst_consistency, consistency); |
| 4486 cpi->total_inconsistency += this_inconsistency; | 4511 cpi->total_inconsistency += this_inconsistency; |
| 4487 } | 4512 } |
| 4488 } | 4513 } |
| 4489 | 4514 |
| 4490 if (cpi->b_calculate_ssimg) { | 4515 if (cpi->b_calculate_ssimg) { |
| 4491 double y, u, v, frame_all; | 4516 double y, u, v, frame_all; |
| 4492 #if CONFIG_VP9_HIGHBITDEPTH | 4517 #if CONFIG_VP9_HIGHBITDEPTH |
| 4493 if (cm->use_highbitdepth) { | 4518 if (cm->use_highbitdepth) { |
| 4494 frame_all = vp9_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y, | 4519 frame_all = vpx_highbd_calc_ssimg(cpi->Source, cm->frame_to_show, &y, |
| 4495 &u, &v, (int)cm->bit_depth); | 4520 &u, &v, (int)cm->bit_depth); |
| 4496 } else { | 4521 } else { |
| 4497 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, | 4522 frame_all = vpx_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, |
| 4498 &v); | 4523 &v); |
| 4499 } | 4524 } |
| 4500 #else | 4525 #else |
| 4501 frame_all = vp9_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v); | 4526 frame_all = vpx_calc_ssimg(cpi->Source, cm->frame_to_show, &y, &u, &v); |
| 4502 #endif // CONFIG_VP9_HIGHBITDEPTH | 4527 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 4503 adjust_image_stat(y, u, v, frame_all, &cpi->ssimg); | 4528 adjust_image_stat(y, u, v, frame_all, &cpi->ssimg); |
| 4504 } | 4529 } |
| 4505 #if CONFIG_VP9_HIGHBITDEPTH | 4530 #if CONFIG_VP9_HIGHBITDEPTH |
| 4506 if (!cm->use_highbitdepth) | 4531 if (!cm->use_highbitdepth) |
| 4507 #endif | 4532 #endif |
| 4508 { | 4533 { |
| 4509 double y, u, v, frame_all; | 4534 double y, u, v, frame_all; |
| 4510 frame_all = vp9_calc_fastssim(cpi->Source, cm->frame_to_show, &y, &u, | 4535 frame_all = vpx_calc_fastssim(cpi->Source, cm->frame_to_show, &y, &u, |
| 4511 &v); | 4536 &v); |
| 4512 adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); | 4537 adjust_image_stat(y, u, v, frame_all, &cpi->fastssim); |
| 4513 /* TODO(JBB): add 10/12 bit support */ | 4538 /* TODO(JBB): add 10/12 bit support */ |
| 4514 } | 4539 } |
| 4515 #if CONFIG_VP9_HIGHBITDEPTH | 4540 #if CONFIG_VP9_HIGHBITDEPTH |
| 4516 if (!cm->use_highbitdepth) | 4541 if (!cm->use_highbitdepth) |
| 4517 #endif | 4542 #endif |
| 4518 { | 4543 { |
| 4519 double y, u, v, frame_all; | 4544 double y, u, v, frame_all; |
| 4520 frame_all = vp9_psnrhvs(cpi->Source, cm->frame_to_show, &y, &u, &v); | 4545 frame_all = vpx_psnrhvs(cpi->Source, cm->frame_to_show, &y, &u, &v); |
| 4521 adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); | 4546 adjust_image_stat(y, u, v, frame_all, &cpi->psnrhvs); |
| 4522 } | 4547 } |
| 4523 } | 4548 } |
| 4524 } | 4549 } |
| 4525 | 4550 |
| 4526 #endif | 4551 #endif |
| 4527 | 4552 |
| 4528 if (is_two_pass_svc(cpi)) { | 4553 if (is_two_pass_svc(cpi)) { |
| 4529 if (cpi->svc.encode_empty_frame_state == ENCODING) { | 4554 if (cpi->svc.encode_empty_frame_state == ENCODING) { |
| 4530 cpi->svc.encode_empty_frame_state = ENCODED; | 4555 cpi->svc.encode_empty_frame_state = ENCODED; |
| 4531 cpi->svc.encode_intra_empty_frame = 0; | 4556 cpi->svc.encode_intra_empty_frame = 0; |
| 4532 } | 4557 } |
| 4533 | 4558 |
| 4534 if (cm->show_frame) { | 4559 if (cm->show_frame) { |
| 4535 ++cpi->svc.spatial_layer_to_encode; | 4560 ++cpi->svc.spatial_layer_to_encode; |
| 4536 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers) | 4561 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers) |
| 4537 cpi->svc.spatial_layer_to_encode = 0; | 4562 cpi->svc.spatial_layer_to_encode = 0; |
| 4538 | 4563 |
| 4539 // May need the empty frame after an visible frame. | 4564 // May need the empty frame after an visible frame. |
| 4540 cpi->svc.encode_empty_frame_state = NEED_TO_ENCODE; | 4565 cpi->svc.encode_empty_frame_state = NEED_TO_ENCODE; |
| 4541 } | 4566 } |
| 4542 } else if (is_one_pass_cbr_svc(cpi)) { | 4567 } else if (is_one_pass_cbr_svc(cpi)) { |
| 4543 if (cm->show_frame) { | 4568 if (cm->show_frame) { |
| 4544 ++cpi->svc.spatial_layer_to_encode; | 4569 ++cpi->svc.spatial_layer_to_encode; |
| 4545 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers) | 4570 if (cpi->svc.spatial_layer_to_encode >= cpi->svc.number_spatial_layers) |
| 4546 cpi->svc.spatial_layer_to_encode = 0; | 4571 cpi->svc.spatial_layer_to_encode = 0; |
| 4547 } | 4572 } |
| 4548 } | 4573 } |
| 4574 vpx_clear_system_state(); |
| 4549 return 0; | 4575 return 0; |
| 4550 } | 4576 } |
| 4551 | 4577 |
| 4552 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, | 4578 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest, |
| 4553 vp9_ppflags_t *flags) { | 4579 vp9_ppflags_t *flags) { |
| 4554 VP9_COMMON *cm = &cpi->common; | 4580 VP9_COMMON *cm = &cpi->common; |
| 4555 #if !CONFIG_VP9_POSTPROC | 4581 #if !CONFIG_VP9_POSTPROC |
| 4556 (void)flags; | 4582 (void)flags; |
| 4557 #endif | 4583 #endif |
| 4558 | 4584 |
| 4559 if (!cm->show_frame) { | 4585 if (!cm->show_frame) { |
| 4560 return -1; | 4586 return -1; |
| 4561 } else { | 4587 } else { |
| 4562 int ret; | 4588 int ret; |
| 4563 #if CONFIG_VP9_POSTPROC | 4589 #if CONFIG_VP9_POSTPROC |
| 4564 ret = vp9_post_proc_frame(cm, dest, flags); | 4590 ret = vp9_post_proc_frame(cm, dest, flags); |
| 4565 #else | 4591 #else |
| 4566 if (cm->frame_to_show) { | 4592 if (cm->frame_to_show) { |
| 4567 *dest = *cm->frame_to_show; | 4593 *dest = *cm->frame_to_show; |
| 4568 dest->y_width = cm->width; | 4594 dest->y_width = cm->width; |
| 4569 dest->y_height = cm->height; | 4595 dest->y_height = cm->height; |
| 4570 dest->uv_width = cm->width >> cm->subsampling_x; | 4596 dest->uv_width = cm->width >> cm->subsampling_x; |
| 4571 dest->uv_height = cm->height >> cm->subsampling_y; | 4597 dest->uv_height = cm->height >> cm->subsampling_y; |
| 4572 ret = 0; | 4598 ret = 0; |
| 4573 } else { | 4599 } else { |
| 4574 ret = -1; | 4600 ret = -1; |
| 4575 } | 4601 } |
| 4576 #endif // !CONFIG_VP9_POSTPROC | 4602 #endif // !CONFIG_VP9_POSTPROC |
| 4577 vp9_clear_system_state(); | 4603 vpx_clear_system_state(); |
| 4578 return ret; | 4604 return ret; |
| 4579 } | 4605 } |
| 4580 } | 4606 } |
| 4581 | 4607 |
| 4582 int vp9_set_internal_size(VP9_COMP *cpi, | 4608 int vp9_set_internal_size(VP9_COMP *cpi, |
| 4583 VPX_SCALING horiz_mode, VPX_SCALING vert_mode) { | 4609 VPX_SCALING horiz_mode, VPX_SCALING vert_mode) { |
| 4584 VP9_COMMON *cm = &cpi->common; | 4610 VP9_COMMON *cm = &cpi->common; |
| 4585 int hr = 0, hs = 0, vr = 0, vs = 0; | 4611 int hr = 0, hs = 0, vr = 0, vs = 0; |
| 4586 | 4612 |
| 4587 if (horiz_mode > ONETWO || vert_mode > ONETWO) | 4613 if (horiz_mode > ONETWO || vert_mode > ONETWO) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4699 if (flags & VP8_EFLAG_NO_UPD_ARF) | 4725 if (flags & VP8_EFLAG_NO_UPD_ARF) |
| 4700 upd ^= VP9_ALT_FLAG; | 4726 upd ^= VP9_ALT_FLAG; |
| 4701 | 4727 |
| 4702 vp9_update_reference(cpi, upd); | 4728 vp9_update_reference(cpi, upd); |
| 4703 } | 4729 } |
| 4704 | 4730 |
| 4705 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 4731 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
| 4706 vp9_update_entropy(cpi, 0); | 4732 vp9_update_entropy(cpi, 0); |
| 4707 } | 4733 } |
| 4708 } | 4734 } |
| OLD | NEW |