| 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 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "vp9/encoder/vp9_speed_features.h" | 44 #include "vp9/encoder/vp9_speed_features.h" |
| 45 #if CONFIG_INTERNAL_STATS | 45 #if CONFIG_INTERNAL_STATS |
| 46 #include "vp9/encoder/vp9_ssim.h" | 46 #include "vp9/encoder/vp9_ssim.h" |
| 47 #endif | 47 #endif |
| 48 #include "vp9/encoder/vp9_temporal_filter.h" | 48 #include "vp9/encoder/vp9_temporal_filter.h" |
| 49 #include "vp9/encoder/vp9_resize.h" | 49 #include "vp9/encoder/vp9_resize.h" |
| 50 #include "vp9/encoder/vp9_svc_layercontext.h" | 50 #include "vp9/encoder/vp9_svc_layercontext.h" |
| 51 | 51 |
| 52 void vp9_coef_tree_initialize(); | 52 void vp9_coef_tree_initialize(); |
| 53 | 53 |
| 54 #define DEFAULT_INTERP_FILTER SWITCHABLE | |
| 55 | |
| 56 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ | 54 #define SHARP_FILTER_QTHRESH 0 /* Q threshold for 8-tap sharp filter */ |
| 57 | 55 |
| 58 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv | 56 #define ALTREF_HIGH_PRECISION_MV 1 // Whether to use high precision mv |
| 59 // for altref computation. | 57 // for altref computation. |
| 60 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision | 58 #define HIGH_PRECISION_MV_QTHRESH 200 // Q threshold for high precision |
| 61 // mv. Choose a very high value for | 59 // mv. Choose a very high value for |
| 62 // now so that HIGH_PRECISION is always | 60 // now so that HIGH_PRECISION is always |
| 63 // chosen. | 61 // chosen. |
| 64 | 62 |
| 65 // #define OUTPUT_YUV_REC | 63 // #define OUTPUT_YUV_REC |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 cm->last_frame_seg_map = NULL; | 165 cm->last_frame_seg_map = NULL; |
| 168 vpx_free(cpi->coding_context.last_frame_seg_map_copy); | 166 vpx_free(cpi->coding_context.last_frame_seg_map_copy); |
| 169 cpi->coding_context.last_frame_seg_map_copy = NULL; | 167 cpi->coding_context.last_frame_seg_map_copy = NULL; |
| 170 | 168 |
| 171 vpx_free(cpi->complexity_map); | 169 vpx_free(cpi->complexity_map); |
| 172 cpi->complexity_map = NULL; | 170 cpi->complexity_map = NULL; |
| 173 | 171 |
| 174 vp9_cyclic_refresh_free(cpi->cyclic_refresh); | 172 vp9_cyclic_refresh_free(cpi->cyclic_refresh); |
| 175 cpi->cyclic_refresh = NULL; | 173 cpi->cyclic_refresh = NULL; |
| 176 | 174 |
| 177 vp9_free_frame_buffers(cm); | 175 vp9_free_ref_frame_buffers(cm); |
| 178 vp9_free_context_buffers(cm); | 176 vp9_free_context_buffers(cm); |
| 179 | 177 |
| 180 vp9_free_frame_buffer(&cpi->last_frame_uf); | 178 vp9_free_frame_buffer(&cpi->last_frame_uf); |
| 181 vp9_free_frame_buffer(&cpi->scaled_source); | 179 vp9_free_frame_buffer(&cpi->scaled_source); |
| 182 vp9_free_frame_buffer(&cpi->scaled_last_source); | 180 vp9_free_frame_buffer(&cpi->scaled_last_source); |
| 183 vp9_free_frame_buffer(&cpi->alt_ref_buffer); | 181 vp9_free_frame_buffer(&cpi->alt_ref_buffer); |
| 184 vp9_lookahead_destroy(cpi->lookahead); | 182 vp9_lookahead_destroy(cpi->lookahead); |
| 185 | 183 |
| 186 vpx_free(cpi->tok); | 184 vpx_free(cpi->tok); |
| 187 cpi->tok = 0; | 185 cpi->tok = 0; |
| 188 | 186 |
| 189 vp9_free_pc_tree(cpi); | 187 vp9_free_pc_tree(cpi); |
| 190 | 188 |
| 191 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { | 189 for (i = 0; i < cpi->svc.number_spatial_layers; ++i) { |
| 192 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; | 190 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i]; |
| 193 vpx_free(lc->rc_twopass_stats_in.buf); | 191 vpx_free(lc->rc_twopass_stats_in.buf); |
| 194 lc->rc_twopass_stats_in.buf = NULL; | 192 lc->rc_twopass_stats_in.buf = NULL; |
| 195 lc->rc_twopass_stats_in.sz = 0; | 193 lc->rc_twopass_stats_in.sz = 0; |
| 196 } | 194 } |
| 197 | 195 |
| 198 if (cpi->source_diff_var != NULL) { | 196 if (cpi->source_diff_var != NULL) { |
| 199 vpx_free(cpi->source_diff_var); | 197 vpx_free(cpi->source_diff_var); |
| 200 cpi->source_diff_var = NULL; | 198 cpi->source_diff_var = NULL; |
| 201 } | 199 } |
| 202 | 200 |
| 203 #if CONFIG_FP_MB_STATS | 201 for (i = 0; i < MAX_LAG_BUFFERS; ++i) { |
| 204 if (cpi->use_fp_mb_stats) { | 202 vp9_free_frame_buffer(&cpi->svc.scaled_frames[i]); |
| 205 vpx_free(cpi->twopass.this_frame_mb_stats.mb_stats); | |
| 206 cpi->twopass.this_frame_mb_stats.mb_stats = NULL; | |
| 207 } | 203 } |
| 208 #endif | 204 vpx_memset(&cpi->svc.scaled_frames[0], 0, |
| 205 MAX_LAG_BUFFERS * sizeof(cpi->svc.scaled_frames[0])); |
| 209 } | 206 } |
| 210 | 207 |
| 211 static void save_coding_context(VP9_COMP *cpi) { | 208 static void save_coding_context(VP9_COMP *cpi) { |
| 212 CODING_CONTEXT *const cc = &cpi->coding_context; | 209 CODING_CONTEXT *const cc = &cpi->coding_context; |
| 213 VP9_COMMON *cm = &cpi->common; | 210 VP9_COMMON *cm = &cpi->common; |
| 214 | 211 |
| 215 // Stores a snapshot of key state variables which can subsequently be | 212 // Stores a snapshot of key state variables which can subsequently be |
| 216 // restored with a call to vp9_restore_coding_context. These functions are | 213 // restored with a call to vp9_restore_coding_context. These functions are |
| 217 // intended for use in a re-code loop in vp9_compress_frame where the | 214 // intended for use in a re-code loop in vp9_compress_frame where the |
| 218 // quantizer value is adjusted between loop iterations. | 215 // quantizer value is adjusted between loop iterations. |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, | 417 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, |
| 421 oxcf->width, oxcf->height, | 418 oxcf->width, oxcf->height, |
| 422 cm->subsampling_x, cm->subsampling_y, | 419 cm->subsampling_x, cm->subsampling_y, |
| 423 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) | 420 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 424 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 421 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 425 "Failed to allocate altref buffer"); | 422 "Failed to allocate altref buffer"); |
| 426 } | 423 } |
| 427 | 424 |
| 428 static void alloc_ref_frame_buffers(VP9_COMP *cpi) { | 425 static void alloc_ref_frame_buffers(VP9_COMP *cpi) { |
| 429 VP9_COMMON *const cm = &cpi->common; | 426 VP9_COMMON *const cm = &cpi->common; |
| 430 if (vp9_alloc_frame_buffers(cm, cm->width, cm->height)) | 427 if (vp9_alloc_ref_frame_buffers(cm, cm->width, cm->height)) |
| 431 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 428 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 432 "Failed to allocate frame buffers"); | 429 "Failed to allocate frame buffers"); |
| 433 } | 430 } |
| 434 | 431 |
| 435 static void alloc_util_frame_buffers(VP9_COMP *cpi) { | 432 static void alloc_util_frame_buffers(VP9_COMP *cpi) { |
| 436 VP9_COMMON *const cm = &cpi->common; | 433 VP9_COMMON *const cm = &cpi->common; |
| 437 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, | 434 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, |
| 438 cm->width, cm->height, | 435 cm->width, cm->height, |
| 439 cm->subsampling_x, cm->subsampling_y, | 436 cm->subsampling_x, cm->subsampling_y, |
| 440 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) | 437 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 467 unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); | 464 unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols); |
| 468 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); | 465 CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); |
| 469 } | 466 } |
| 470 | 467 |
| 471 vp9_setup_pc_tree(&cpi->common, cpi); | 468 vp9_setup_pc_tree(&cpi->common, cpi); |
| 472 } | 469 } |
| 473 | 470 |
| 474 static void update_frame_size(VP9_COMP *cpi) { | 471 static void update_frame_size(VP9_COMP *cpi) { |
| 475 VP9_COMMON *const cm = &cpi->common; | 472 VP9_COMMON *const cm = &cpi->common; |
| 476 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 473 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
| 477 vp9_update_frame_size(cm); | 474 |
| 475 vp9_set_mb_mi(cm, cm->width, cm->height); |
| 476 vp9_init_context_buffers(cm); |
| 478 init_macroblockd(cm, xd); | 477 init_macroblockd(cm, xd); |
| 478 |
| 479 if (cpi->use_svc && cpi->svc.number_temporal_layers == 1) { |
| 480 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, |
| 481 cm->width, cm->height, |
| 482 cm->subsampling_x, cm->subsampling_y, |
| 483 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 484 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 485 "Failed to reallocate alt_ref_buffer"); |
| 486 } |
| 479 } | 487 } |
| 480 | 488 |
| 481 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { | 489 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { |
| 482 cpi->oxcf.framerate = framerate < 0.1 ? 30 : framerate; | 490 cpi->oxcf.framerate = framerate < 0.1 ? 30 : framerate; |
| 483 vp9_rc_update_framerate(cpi); | 491 vp9_rc_update_framerate(cpi); |
| 484 } | 492 } |
| 485 | 493 |
| 486 int64_t vp9_rescale(int64_t val, int64_t num, int denom) { | 494 int64_t vp9_rescale(int64_t val, int64_t num, int denom) { |
| 487 int64_t llnum = num; | 495 int64_t llnum = num; |
| 488 int64_t llden = denom; | 496 int64_t llden = denom; |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); | 629 rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size); |
| 622 rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size); | 630 rc->buffer_level = MIN(rc->buffer_level, rc->maximum_buffer_size); |
| 623 | 631 |
| 624 // Set up frame rate and related parameters rate control values. | 632 // Set up frame rate and related parameters rate control values. |
| 625 vp9_new_framerate(cpi, cpi->oxcf.framerate); | 633 vp9_new_framerate(cpi, cpi->oxcf.framerate); |
| 626 | 634 |
| 627 // Set absolute upper and lower quality limits | 635 // Set absolute upper and lower quality limits |
| 628 rc->worst_quality = cpi->oxcf.worst_allowed_q; | 636 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
| 629 rc->best_quality = cpi->oxcf.best_allowed_q; | 637 rc->best_quality = cpi->oxcf.best_allowed_q; |
| 630 | 638 |
| 631 cm->interp_filter = DEFAULT_INTERP_FILTER; | 639 cm->interp_filter = cpi->sf.default_interp_filter; |
| 632 | 640 |
| 633 cm->display_width = cpi->oxcf.width; | 641 cm->display_width = cpi->oxcf.width; |
| 634 cm->display_height = cpi->oxcf.height; | 642 cm->display_height = cpi->oxcf.height; |
| 635 | 643 |
| 636 if (cpi->initial_width) { | 644 if (cpi->initial_width) { |
| 637 // Increasing the size of the frame beyond the first seen frame, or some | 645 // Increasing the size of the frame beyond the first seen frame, or some |
| 638 // otherwise signaled maximum size, is not supported. | 646 // otherwise signaled maximum size, is not supported. |
| 639 // TODO(jkoleszar): exit gracefully. | 647 // TODO(jkoleszar): exit gracefully. |
| 640 assert(cm->width <= cpi->initial_width); | 648 assert(cm->width <= cpi->initial_width); |
| 641 assert(cm->height <= cpi->initial_height); | 649 assert(cm->height <= cpi->initial_height); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 | 743 |
| 736 vp9_rtcd(); | 744 vp9_rtcd(); |
| 737 | 745 |
| 738 cpi->use_svc = 0; | 746 cpi->use_svc = 0; |
| 739 | 747 |
| 740 init_config(cpi, oxcf); | 748 init_config(cpi, oxcf); |
| 741 vp9_rc_init(&cpi->oxcf, cpi->pass, &cpi->rc); | 749 vp9_rc_init(&cpi->oxcf, cpi->pass, &cpi->rc); |
| 742 | 750 |
| 743 cm->current_video_frame = 0; | 751 cm->current_video_frame = 0; |
| 744 | 752 |
| 745 // Set reference frame sign bias for ALTREF frame to 1 (for now) | |
| 746 cm->ref_frame_sign_bias[ALTREF_FRAME] = 1; | |
| 747 | |
| 748 cpi->gold_is_last = 0; | 753 cpi->gold_is_last = 0; |
| 749 cpi->alt_is_last = 0; | 754 cpi->alt_is_last = 0; |
| 750 cpi->gold_is_alt = 0; | 755 cpi->gold_is_alt = 0; |
| 751 | 756 |
| 752 cpi->skippable_frame = 0; | 757 cpi->skippable_frame = 0; |
| 753 | 758 |
| 754 // Create the encoder segmentation map and set all entries to 0 | 759 // Create the encoder segmentation map and set all entries to 0 |
| 755 CHECK_MEM_ERROR(cm, cpi->segmentation_map, | 760 CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
| 756 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 761 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
| 757 | 762 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 771 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / | 776 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / |
| 772 sizeof(cpi->mbgraph_stats[0])); i++) { | 777 sizeof(cpi->mbgraph_stats[0])); i++) { |
| 773 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, | 778 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, |
| 774 vpx_calloc(cm->MBs * | 779 vpx_calloc(cm->MBs * |
| 775 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); | 780 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
| 776 } | 781 } |
| 777 | 782 |
| 778 #if CONFIG_FP_MB_STATS | 783 #if CONFIG_FP_MB_STATS |
| 779 cpi->use_fp_mb_stats = 0; | 784 cpi->use_fp_mb_stats = 0; |
| 780 if (cpi->use_fp_mb_stats) { | 785 if (cpi->use_fp_mb_stats) { |
| 781 // a place holder for the mb stats obtained from the first pass | 786 // a place holder used to store the first pass mb stats in the first pass |
| 782 CHECK_MEM_ERROR(cm, cpi->twopass.this_frame_mb_stats.mb_stats, | 787 CHECK_MEM_ERROR(cm, cpi->twopass.frame_mb_stats_buf, |
| 783 vpx_calloc(cm->MBs * sizeof(FIRSTPASS_MB_STATS), 1)); | 788 vpx_calloc(cm->MBs * sizeof(uint8_t), 1)); |
| 784 } else { | 789 } else { |
| 785 cpi->twopass.this_frame_mb_stats.mb_stats = NULL; | 790 cpi->twopass.frame_mb_stats_buf = NULL; |
| 786 } | 791 } |
| 787 #endif | 792 #endif |
| 788 | 793 |
| 789 cpi->refresh_alt_ref_frame = 0; | 794 cpi->refresh_alt_ref_frame = 0; |
| 790 | 795 |
| 791 // Note that at the moment multi_arf will not work with svc. | 796 // Note that at the moment multi_arf will not work with svc. |
| 792 // For the current check in all the execution paths are defaulted to 0 | 797 // For the current check in all the execution paths are defaulted to 0 |
| 793 // pending further tuning and testing. The code is left in place here | 798 // pending further tuning and testing. The code is left in place here |
| 794 // as a place holder in regard to the required paths. | 799 // as a place holder in regard to the required paths. |
| 795 cpi->multi_arf_last_grp_enabled = 0; | 800 cpi->multi_arf_last_grp_enabled = 0; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 const int layer_id = (int)stats[i].spatial_layer_id; | 923 const int layer_id = (int)stats[i].spatial_layer_id; |
| 919 if (layer_id >= 0 && layer_id < oxcf->ss_number_layers | 924 if (layer_id >= 0 && layer_id < oxcf->ss_number_layers |
| 920 && stats_copy[layer_id] != NULL) { | 925 && stats_copy[layer_id] != NULL) { |
| 921 *stats_copy[layer_id] = stats[i]; | 926 *stats_copy[layer_id] = stats[i]; |
| 922 ++stats_copy[layer_id]; | 927 ++stats_copy[layer_id]; |
| 923 } | 928 } |
| 924 } | 929 } |
| 925 | 930 |
| 926 vp9_init_second_pass_spatial_svc(cpi); | 931 vp9_init_second_pass_spatial_svc(cpi); |
| 927 } else { | 932 } else { |
| 933 #if CONFIG_FP_MB_STATS |
| 934 if (cpi->use_fp_mb_stats) { |
| 935 const size_t psz = cpi->common.MBs * sizeof(uint8_t); |
| 936 const int ps = (int)(oxcf->firstpass_mb_stats_in.sz / psz); |
| 937 |
| 938 cpi->twopass.firstpass_mb_stats.mb_stats_start = |
| 939 oxcf->firstpass_mb_stats_in.buf; |
| 940 cpi->twopass.firstpass_mb_stats.mb_stats_end = |
| 941 cpi->twopass.firstpass_mb_stats.mb_stats_start + |
| 942 (ps - 1) * cpi->common.MBs * sizeof(uint8_t); |
| 943 } |
| 944 #endif |
| 945 |
| 928 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; | 946 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 929 cpi->twopass.stats_in = cpi->twopass.stats_in_start; | 947 cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 930 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; | 948 cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1]; |
| 931 | 949 |
| 932 vp9_init_second_pass(cpi); | 950 vp9_init_second_pass(cpi); |
| 933 } | 951 } |
| 934 } | 952 } |
| 935 | 953 |
| 936 set_speed_features(cpi); | 954 set_speed_features(cpi); |
| 937 | 955 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 #endif | 1126 #endif |
| 1109 | 1127 |
| 1110 dealloc_compressor_data(cpi); | 1128 dealloc_compressor_data(cpi); |
| 1111 vpx_free(cpi->tok); | 1129 vpx_free(cpi->tok); |
| 1112 | 1130 |
| 1113 for (i = 0; i < sizeof(cpi->mbgraph_stats) / | 1131 for (i = 0; i < sizeof(cpi->mbgraph_stats) / |
| 1114 sizeof(cpi->mbgraph_stats[0]); ++i) { | 1132 sizeof(cpi->mbgraph_stats[0]); ++i) { |
| 1115 vpx_free(cpi->mbgraph_stats[i].mb_stats); | 1133 vpx_free(cpi->mbgraph_stats[i].mb_stats); |
| 1116 } | 1134 } |
| 1117 | 1135 |
| 1136 #if CONFIG_FP_MB_STATS |
| 1137 if (cpi->use_fp_mb_stats) { |
| 1138 vpx_free(cpi->twopass.frame_mb_stats_buf); |
| 1139 cpi->twopass.frame_mb_stats_buf = NULL; |
| 1140 } |
| 1141 #endif |
| 1142 |
| 1118 vp9_remove_common(&cpi->common); | 1143 vp9_remove_common(&cpi->common); |
| 1119 vpx_free(cpi); | 1144 vpx_free(cpi); |
| 1120 | 1145 |
| 1121 #if CONFIG_DENOISING | 1146 #if CONFIG_DENOISING |
| 1122 #ifdef OUTPUT_YUV_DENOISED | 1147 #ifdef OUTPUT_YUV_DENOISED |
| 1123 fclose(yuv_denoised_file); | 1148 fclose(yuv_denoised_file); |
| 1124 #endif | 1149 #endif |
| 1125 #endif | 1150 #endif |
| 1126 #ifdef OUTPUT_YUV_SRC | 1151 #ifdef OUTPUT_YUV_SRC |
| 1127 fclose(yuv_file); | 1152 fclose(yuv_file); |
| (...skipping 922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2050 cpi->skippable_frame = (!frame_is_intra_only(&cpi->common) && | 2075 cpi->skippable_frame = (!frame_is_intra_only(&cpi->common) && |
| 2051 twopass->stats_in - 2 > twopass->stats_in_start && | 2076 twopass->stats_in - 2 > twopass->stats_in_start && |
| 2052 twopass->stats_in < twopass->stats_in_end && | 2077 twopass->stats_in < twopass->stats_in_end && |
| 2053 (twopass->stats_in - 1)->pcnt_inter - (twopass->stats_in - 1)->pcnt_motion | 2078 (twopass->stats_in - 1)->pcnt_inter - (twopass->stats_in - 1)->pcnt_motion |
| 2054 == 1 && | 2079 == 1 && |
| 2055 (twopass->stats_in - 2)->pcnt_inter - (twopass->stats_in - 2)->pcnt_motion | 2080 (twopass->stats_in - 2)->pcnt_inter - (twopass->stats_in - 2)->pcnt_motion |
| 2056 == 1 && | 2081 == 1 && |
| 2057 twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1); | 2082 twopass->stats_in->pcnt_inter - twopass->stats_in->pcnt_motion == 1); |
| 2058 } | 2083 } |
| 2059 | 2084 |
| 2085 static void set_arf_sign_bias(VP9_COMP *cpi) { |
| 2086 VP9_COMMON *const cm = &cpi->common; |
| 2087 int arf_sign_bias; |
| 2088 |
| 2089 if ((cpi->pass == 2) && cpi->multi_arf_allowed) { |
| 2090 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2091 arf_sign_bias = cpi->rc.source_alt_ref_active && |
| 2092 (!cpi->refresh_alt_ref_frame || |
| 2093 (gf_group->rf_level[gf_group->index] == GF_ARF_LOW)); |
| 2094 } else { |
| 2095 arf_sign_bias = |
| 2096 (cpi->rc.source_alt_ref_active && !cpi->refresh_alt_ref_frame); |
| 2097 } |
| 2098 cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; |
| 2099 } |
| 2100 |
| 2060 static void encode_frame_to_data_rate(VP9_COMP *cpi, | 2101 static void encode_frame_to_data_rate(VP9_COMP *cpi, |
| 2061 size_t *size, | 2102 size_t *size, |
| 2062 uint8_t *dest, | 2103 uint8_t *dest, |
| 2063 unsigned int *frame_flags) { | 2104 unsigned int *frame_flags) { |
| 2064 VP9_COMMON *const cm = &cpi->common; | 2105 VP9_COMMON *const cm = &cpi->common; |
| 2065 TX_SIZE t; | 2106 TX_SIZE t; |
| 2066 int q; | 2107 int q; |
| 2067 int top_index; | 2108 int top_index; |
| 2068 int bottom_index; | 2109 int bottom_index; |
| 2069 | 2110 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2082 vp9_scale_references(cpi); | 2123 vp9_scale_references(cpi); |
| 2083 | 2124 |
| 2084 vp9_clear_system_state(); | 2125 vp9_clear_system_state(); |
| 2085 | 2126 |
| 2086 // Enable or disable mode based tweaking of the zbin. | 2127 // Enable or disable mode based tweaking of the zbin. |
| 2087 // For 2 pass only used where GF/ARF prediction quality | 2128 // For 2 pass only used where GF/ARF prediction quality |
| 2088 // is above a threshold. | 2129 // is above a threshold. |
| 2089 cpi->zbin_mode_boost = 0; | 2130 cpi->zbin_mode_boost = 0; |
| 2090 cpi->zbin_mode_boost_enabled = 0; | 2131 cpi->zbin_mode_boost_enabled = 0; |
| 2091 | 2132 |
| 2092 // Current default encoder behavior for the altref sign bias. | 2133 // Set the arf sign bias for this frame. |
| 2093 cm->ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active; | 2134 set_arf_sign_bias(cpi); |
| 2094 | 2135 |
| 2095 // Set default state for segment based loop filter update flags. | 2136 // Set default state for segment based loop filter update flags. |
| 2096 cm->lf.mode_ref_delta_update = 0; | 2137 cm->lf.mode_ref_delta_update = 0; |
| 2097 | 2138 |
| 2098 // Initialize cpi->mv_step_param to default based on max resolution. | 2139 // Initialize cpi->mv_step_param to default based on max resolution. |
| 2099 cpi->mv_step_param = vp9_init_search_range(max_mv_def); | 2140 cpi->mv_step_param = vp9_init_search_range(max_mv_def); |
| 2100 // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. | 2141 // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. |
| 2101 if (sf->mv.auto_mv_step_size) { | 2142 if (sf->mv.auto_mv_step_size) { |
| 2102 if (frame_is_intra_only(cm)) { | 2143 if (frame_is_intra_only(cm)) { |
| 2103 // Initialize max_mv_magnitude for use in the first INTER frame | 2144 // Initialize max_mv_magnitude for use in the first INTER frame |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2210 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], | 2251 vp9_write_yuv_frame_420(&cpi->denoiser.running_avg_y[INTRA_FRAME], |
| 2211 yuv_denoised_file); | 2252 yuv_denoised_file); |
| 2212 } | 2253 } |
| 2213 #endif | 2254 #endif |
| 2214 #endif | 2255 #endif |
| 2215 | 2256 |
| 2216 // Decide q and q bounds. | 2257 // Decide q and q bounds. |
| 2217 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); | 2258 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); |
| 2218 | 2259 |
| 2219 if (!frame_is_intra_only(cm)) { | 2260 if (!frame_is_intra_only(cm)) { |
| 2220 cm->interp_filter = DEFAULT_INTERP_FILTER; | 2261 cm->interp_filter = cpi->sf.default_interp_filter; |
| 2221 /* TODO: Decide this more intelligently */ | 2262 /* TODO: Decide this more intelligently */ |
| 2222 vp9_set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); | 2263 vp9_set_high_precision_mv(cpi, q < HIGH_PRECISION_MV_QTHRESH); |
| 2223 } | 2264 } |
| 2224 | 2265 |
| 2225 if (cpi->sf.recode_loop == DISALLOW_RECODE) { | 2266 if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 2226 encode_without_recode_loop(cpi, q); | 2267 encode_without_recode_loop(cpi, q); |
| 2227 } else { | 2268 } else { |
| 2228 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); | 2269 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); |
| 2229 } | 2270 } |
| 2230 | 2271 |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2479 } | 2520 } |
| 2480 cpi->last_time_stamp_seen = cpi->source->ts_start; | 2521 cpi->last_time_stamp_seen = cpi->source->ts_start; |
| 2481 cpi->last_end_time_stamp_seen = cpi->source->ts_end; | 2522 cpi->last_end_time_stamp_seen = cpi->source->ts_end; |
| 2482 } | 2523 } |
| 2483 | 2524 |
| 2484 // Returns 0 if this is not an alt ref else the offset of the source frame | 2525 // Returns 0 if this is not an alt ref else the offset of the source frame |
| 2485 // used as the arf midpoint. | 2526 // used as the arf midpoint. |
| 2486 static int get_arf_src_index(VP9_COMP *cpi) { | 2527 static int get_arf_src_index(VP9_COMP *cpi) { |
| 2487 RATE_CONTROL *const rc = &cpi->rc; | 2528 RATE_CONTROL *const rc = &cpi->rc; |
| 2488 int arf_src_index = 0; | 2529 int arf_src_index = 0; |
| 2489 if (is_altref_enabled(&cpi->oxcf)) { | 2530 if (is_altref_enabled(cpi)) { |
| 2490 if (cpi->pass == 2) { | 2531 if (cpi->pass == 2) { |
| 2491 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; | 2532 const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 2492 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { | 2533 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { |
| 2493 arf_src_index = gf_group->arf_src_offset[gf_group->index]; | 2534 arf_src_index = gf_group->arf_src_offset[gf_group->index]; |
| 2494 } | 2535 } |
| 2495 } else if (rc->source_alt_ref_pending) { | 2536 } else if (rc->source_alt_ref_pending) { |
| 2496 arf_src_index = rc->frames_till_gf_update_due; | 2537 arf_src_index = rc->frames_till_gf_update_due; |
| 2497 } | 2538 } |
| 2498 } | 2539 } |
| 2499 return arf_src_index; | 2540 return arf_src_index; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2558 cpi->refresh_alt_ref_frame = 0; | 2599 cpi->refresh_alt_ref_frame = 0; |
| 2559 | 2600 |
| 2560 // Should we encode an arf frame. | 2601 // Should we encode an arf frame. |
| 2561 arf_src_index = get_arf_src_index(cpi); | 2602 arf_src_index = get_arf_src_index(cpi); |
| 2562 if (arf_src_index) { | 2603 if (arf_src_index) { |
| 2563 assert(arf_src_index <= rc->frames_to_key); | 2604 assert(arf_src_index <= rc->frames_to_key); |
| 2564 | 2605 |
| 2565 #ifdef CONFIG_SPATIAL_SVC | 2606 #ifdef CONFIG_SPATIAL_SVC |
| 2566 if (is_spatial_svc) | 2607 if (is_spatial_svc) |
| 2567 cpi->source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, | 2608 cpi->source = vp9_svc_lookahead_peek(cpi, cpi->lookahead, |
| 2568 arf_src_index, 1); | 2609 arf_src_index, 0); |
| 2569 else | 2610 else |
| 2570 #endif | 2611 #endif |
| 2571 cpi->source = vp9_lookahead_peek(cpi->lookahead, arf_src_index); | 2612 cpi->source = vp9_lookahead_peek(cpi->lookahead, arf_src_index); |
| 2572 if (cpi->source != NULL) { | 2613 if (cpi->source != NULL) { |
| 2573 cpi->alt_ref_source = cpi->source; | 2614 cpi->alt_ref_source = cpi->source; |
| 2574 | 2615 |
| 2616 #ifdef CONFIG_SPATIAL_SVC |
| 2617 if (is_spatial_svc && cpi->svc.spatial_layer_id > 0) { |
| 2618 int i; |
| 2619 // Reference a hidden frame from a lower layer |
| 2620 for (i = cpi->svc.spatial_layer_id - 1; i >= 0; --i) { |
| 2621 if (cpi->oxcf.ss_play_alternate[i]) { |
| 2622 cpi->gld_fb_idx = cpi->svc.layer_context[i].alt_ref_idx; |
| 2623 break; |
| 2624 } |
| 2625 } |
| 2626 } |
| 2627 cpi->svc.layer_context[cpi->svc.spatial_layer_id].has_alt_frame = 1; |
| 2628 #endif |
| 2629 |
| 2575 if (cpi->oxcf.arnr_max_frames > 0) { | 2630 if (cpi->oxcf.arnr_max_frames > 0) { |
| 2576 // Produce the filtered ARF frame. | 2631 // Produce the filtered ARF frame. |
| 2577 vp9_temporal_filter(cpi, arf_src_index); | 2632 vp9_temporal_filter(cpi, arf_src_index); |
| 2578 vp9_extend_frame_borders(&cpi->alt_ref_buffer); | 2633 vp9_extend_frame_borders(&cpi->alt_ref_buffer); |
| 2579 force_src_buffer = &cpi->alt_ref_buffer; | 2634 force_src_buffer = &cpi->alt_ref_buffer; |
| 2580 } | 2635 } |
| 2581 | 2636 |
| 2582 cm->show_frame = 0; | 2637 cm->show_frame = 0; |
| 2583 cpi->refresh_alt_ref_frame = 1; | 2638 cpi->refresh_alt_ref_frame = 1; |
| 2584 cpi->refresh_golden_frame = 0; | 2639 cpi->refresh_golden_frame = 0; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2780 cpi->total_y += psnr.psnr[1]; | 2835 cpi->total_y += psnr.psnr[1]; |
| 2781 cpi->total_u += psnr.psnr[2]; | 2836 cpi->total_u += psnr.psnr[2]; |
| 2782 cpi->total_v += psnr.psnr[3]; | 2837 cpi->total_v += psnr.psnr[3]; |
| 2783 cpi->total_sq_error += psnr.sse[0]; | 2838 cpi->total_sq_error += psnr.sse[0]; |
| 2784 cpi->total_samples += psnr.samples[0]; | 2839 cpi->total_samples += psnr.samples[0]; |
| 2785 | 2840 |
| 2786 { | 2841 { |
| 2787 PSNR_STATS psnr2; | 2842 PSNR_STATS psnr2; |
| 2788 double frame_ssim2 = 0, weight = 0; | 2843 double frame_ssim2 = 0, weight = 0; |
| 2789 #if CONFIG_VP9_POSTPROC | 2844 #if CONFIG_VP9_POSTPROC |
| 2845 // TODO(agrange) Add resizing of post-proc buffer in here when the |
| 2846 // encoder is changed to use on-demand buffer allocation. |
| 2790 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, | 2847 vp9_deblock(cm->frame_to_show, &cm->post_proc_buffer, |
| 2791 cm->lf.filter_level * 10 / 6); | 2848 cm->lf.filter_level * 10 / 6); |
| 2792 #endif | 2849 #endif |
| 2793 vp9_clear_system_state(); | 2850 vp9_clear_system_state(); |
| 2794 | 2851 |
| 2795 calc_psnr(orig, pp, &psnr2); | 2852 calc_psnr(orig, pp, &psnr2); |
| 2796 | 2853 |
| 2797 cpi->totalp += psnr2.psnr[0]; | 2854 cpi->totalp += psnr2.psnr[0]; |
| 2798 cpi->totalp_y += psnr2.psnr[1]; | 2855 cpi->totalp_y += psnr2.psnr[1]; |
| 2799 cpi->totalp_u += psnr2.psnr[2]; | 2856 cpi->totalp_u += psnr2.psnr[2]; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2897 | 2954 |
| 2898 if (horiz_mode > ONETWO || vert_mode > ONETWO) | 2955 if (horiz_mode > ONETWO || vert_mode > ONETWO) |
| 2899 return -1; | 2956 return -1; |
| 2900 | 2957 |
| 2901 Scale2Ratio(horiz_mode, &hr, &hs); | 2958 Scale2Ratio(horiz_mode, &hr, &hs); |
| 2902 Scale2Ratio(vert_mode, &vr, &vs); | 2959 Scale2Ratio(vert_mode, &vr, &vs); |
| 2903 | 2960 |
| 2904 // always go to the next whole number | 2961 // always go to the next whole number |
| 2905 cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; | 2962 cm->width = (hs - 1 + cpi->oxcf.width * hr) / hs; |
| 2906 cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; | 2963 cm->height = (vs - 1 + cpi->oxcf.height * vr) / vs; |
| 2907 | |
| 2908 assert(cm->width <= cpi->initial_width); | 2964 assert(cm->width <= cpi->initial_width); |
| 2909 assert(cm->height <= cpi->initial_height); | 2965 assert(cm->height <= cpi->initial_height); |
| 2966 |
| 2910 update_frame_size(cpi); | 2967 update_frame_size(cpi); |
| 2968 |
| 2911 return 0; | 2969 return 0; |
| 2912 } | 2970 } |
| 2913 | 2971 |
| 2914 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, | 2972 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width, |
| 2915 unsigned int height) { | 2973 unsigned int height) { |
| 2916 VP9_COMMON *cm = &cpi->common; | 2974 VP9_COMMON *cm = &cpi->common; |
| 2917 | 2975 |
| 2918 check_initial_width(cpi, 1, 1); | 2976 check_initial_width(cpi, 1, 1); |
| 2919 | 2977 |
| 2920 if (width) { | 2978 if (width) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2933 cm->height = height; | 2991 cm->height = height; |
| 2934 if (cm->height * 5 < cpi->initial_height) { | 2992 if (cm->height * 5 < cpi->initial_height) { |
| 2935 cm->height = cpi->initial_height / 5 + 1; | 2993 cm->height = cpi->initial_height / 5 + 1; |
| 2936 printf("Warning: Desired height too small, changed to %d\n", cm->height); | 2994 printf("Warning: Desired height too small, changed to %d\n", cm->height); |
| 2937 } | 2995 } |
| 2938 if (cm->height > cpi->initial_height) { | 2996 if (cm->height > cpi->initial_height) { |
| 2939 cm->height = cpi->initial_height; | 2997 cm->height = cpi->initial_height; |
| 2940 printf("Warning: Desired height too large, changed to %d\n", cm->height); | 2998 printf("Warning: Desired height too large, changed to %d\n", cm->height); |
| 2941 } | 2999 } |
| 2942 } | 3000 } |
| 2943 | |
| 2944 assert(cm->width <= cpi->initial_width); | 3001 assert(cm->width <= cpi->initial_width); |
| 2945 assert(cm->height <= cpi->initial_height); | 3002 assert(cm->height <= cpi->initial_height); |
| 3003 |
| 2946 update_frame_size(cpi); | 3004 update_frame_size(cpi); |
| 3005 |
| 2947 return 0; | 3006 return 0; |
| 2948 } | 3007 } |
| 2949 | 3008 |
| 2950 void vp9_set_svc(VP9_COMP *cpi, int use_svc) { | 3009 void vp9_set_svc(VP9_COMP *cpi, int use_svc) { |
| 2951 cpi->use_svc = use_svc; | 3010 cpi->use_svc = use_svc; |
| 2952 return; | 3011 return; |
| 2953 } | 3012 } |
| 2954 | 3013 |
| 2955 int vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b) { | 3014 int vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b) { |
| 2956 assert(a->y_crop_width == b->y_crop_width); | 3015 assert(a->y_crop_width == b->y_crop_width); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2996 if (flags & VP8_EFLAG_NO_UPD_ARF) | 3055 if (flags & VP8_EFLAG_NO_UPD_ARF) |
| 2997 upd ^= VP9_ALT_FLAG; | 3056 upd ^= VP9_ALT_FLAG; |
| 2998 | 3057 |
| 2999 vp9_update_reference(cpi, upd); | 3058 vp9_update_reference(cpi, upd); |
| 3000 } | 3059 } |
| 3001 | 3060 |
| 3002 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 3061 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
| 3003 vp9_update_entropy(cpi, 0); | 3062 vp9_update_entropy(cpi, 0); |
| 3004 } | 3063 } |
| 3005 } | 3064 } |
| OLD | NEW |