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

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

Issue 1217053002: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 cm->free_mi = vp9_enc_free_mi; 1589 cm->free_mi = vp9_enc_free_mi;
1590 cm->setup_mi = vp9_enc_setup_mi; 1590 cm->setup_mi = vp9_enc_setup_mi;
1591 1591
1592 CHECK_MEM_ERROR(cm, cm->fc, 1592 CHECK_MEM_ERROR(cm, cm->fc,
1593 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc))); 1593 (FRAME_CONTEXT *)vpx_calloc(1, sizeof(*cm->fc)));
1594 CHECK_MEM_ERROR(cm, cm->frame_contexts, 1594 CHECK_MEM_ERROR(cm, cm->frame_contexts,
1595 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS, 1595 (FRAME_CONTEXT *)vpx_calloc(FRAME_CONTEXTS,
1596 sizeof(*cm->frame_contexts))); 1596 sizeof(*cm->frame_contexts)));
1597 1597
1598 cpi->use_svc = 0; 1598 cpi->use_svc = 0;
1599 cpi->resize_state = 0;
1600 cpi->resize_avg_qp = 0;
1601 cpi->resize_buffer_underflow = 0;
1599 cpi->common.buffer_pool = pool; 1602 cpi->common.buffer_pool = pool;
1600 1603
1601 init_config(cpi, oxcf); 1604 init_config(cpi, oxcf);
1602 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc); 1605 vp9_rc_init(&cpi->oxcf, oxcf->pass, &cpi->rc);
1603 1606
1604 cm->current_video_frame = 0; 1607 cm->current_video_frame = 0;
1605 cpi->partition_search_skippable_frame = 0; 1608 cpi->partition_search_skippable_frame = 0;
1606 cpi->tile_data = NULL; 1609 cpi->tile_data = NULL;
1607 1610
1608 realloc_segmentation_maps(cpi); 1611 realloc_segmentation_maps(cpi);
(...skipping 1256 matching lines...) Expand 10 before | Expand all | Expand 10 after
2865 2868
2866 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm)); 2869 recon_err = vp9_get_y_sse(cpi->Source, get_frame_new_buffer(cm));
2867 2870
2868 if (cpi->twopass.total_left_stats.coded_error != 0.0) 2871 if (cpi->twopass.total_left_stats.coded_error != 0.0)
2869 fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d" 2872 fprintf(f, "%10u %dx%d %d %d %10d %10d %10d %10d"
2870 "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" " 2873 "%10"PRId64" %10"PRId64" %5d %5d %10"PRId64" "
2871 "%10"PRId64" %10"PRId64" %10d " 2874 "%10"PRId64" %10"PRId64" %10d "
2872 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" 2875 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf"
2873 "%6d %6d %5d %5d %5d " 2876 "%6d %6d %5d %5d %5d "
2874 "%10"PRId64" %10.3lf" 2877 "%10"PRId64" %10.3lf"
2875 "%10lf %8u %10"PRId64" %10d %10d\n", 2878 "%10lf %8u %10"PRId64" %10d %10d %10d\n",
2876 cpi->common.current_video_frame, 2879 cpi->common.current_video_frame,
2877 cm->width, cm->height, 2880 cm->width, cm->height,
2878 cpi->rc.source_alt_ref_pending, 2881 cpi->rc.source_alt_ref_pending,
2879 cpi->rc.source_alt_ref_active, 2882 cpi->rc.source_alt_ref_active,
2880 cpi->rc.this_frame_target, 2883 cpi->rc.this_frame_target,
2881 cpi->rc.projected_frame_size, 2884 cpi->rc.projected_frame_size,
2882 cpi->rc.projected_frame_size / cpi->common.MBs, 2885 cpi->rc.projected_frame_size / cpi->common.MBs,
2883 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), 2886 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target),
2884 cpi->rc.vbr_bits_off_target, 2887 cpi->rc.vbr_bits_off_target,
2885 cpi->rc.vbr_bits_off_target_fast, 2888 cpi->rc.vbr_bits_off_target_fast,
2886 cpi->twopass.extend_minq, 2889 cpi->twopass.extend_minq,
2887 cpi->twopass.extend_minq_fast, 2890 cpi->twopass.extend_minq_fast,
2888 cpi->rc.total_target_vs_actual, 2891 cpi->rc.total_target_vs_actual,
2889 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target), 2892 (cpi->rc.starting_buffer_level - cpi->rc.bits_off_target),
2890 cpi->rc.total_actual_bits, cm->base_qindex, 2893 cpi->rc.total_actual_bits, cm->base_qindex,
2891 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth), 2894 vp9_convert_qindex_to_q(cm->base_qindex, cm->bit_depth),
2892 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0, 2895 (double)vp9_dc_quant(cm->base_qindex, 0, cm->bit_depth) / 4.0,
2893 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality, 2896 vp9_convert_qindex_to_q(cpi->twopass.active_worst_quality,
2894 cm->bit_depth), 2897 cm->bit_depth),
2895 cpi->rc.avg_q, 2898 cpi->rc.avg_q,
2896 vp9_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth), 2899 vp9_convert_qindex_to_q(cpi->oxcf.cq_level, cm->bit_depth),
2897 cpi->refresh_last_frame, cpi->refresh_golden_frame, 2900 cpi->refresh_last_frame, cpi->refresh_golden_frame,
2898 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, 2901 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost,
2899 cpi->twopass.bits_left, 2902 cpi->twopass.bits_left,
2900 cpi->twopass.total_left_stats.coded_error, 2903 cpi->twopass.total_left_stats.coded_error,
2901 cpi->twopass.bits_left / 2904 cpi->twopass.bits_left /
2902 (1 + cpi->twopass.total_left_stats.coded_error), 2905 (1 + cpi->twopass.total_left_stats.coded_error),
2903 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, 2906 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost,
2904 cpi->twopass.kf_zeromotion_pct); 2907 cpi->twopass.kf_zeromotion_pct,
2908 cpi->twopass.fr_content_type);
2905 2909
2906 fclose(f); 2910 fclose(f);
2907 2911
2908 if (0) { 2912 if (0) {
2909 FILE *const fmodes = fopen("Modes.stt", "a"); 2913 FILE *const fmodes = fopen("Modes.stt", "a");
2910 int i; 2914 int i;
2911 2915
2912 fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame, 2916 fprintf(fmodes, "%6d:%1d:%1d:%1d ", cpi->common.current_video_frame,
2913 cm->frame_type, cpi->refresh_golden_frame, 2917 cm->frame_type, cpi->refresh_golden_frame,
2914 cpi->refresh_alt_ref_frame); 2918 cpi->refresh_alt_ref_frame);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 ((oxcf->resize_mode == RESIZE_FIXED && cm->current_video_frame == 0) || 3028 ((oxcf->resize_mode == RESIZE_FIXED && cm->current_video_frame == 0) ||
3025 (oxcf->resize_mode == RESIZE_DYNAMIC && cpi->resize_pending))) { 3029 (oxcf->resize_mode == RESIZE_DYNAMIC && cpi->resize_pending))) {
3026 calculate_coded_size( 3030 calculate_coded_size(
3027 cpi, &oxcf->scaled_frame_width, &oxcf->scaled_frame_height); 3031 cpi, &oxcf->scaled_frame_width, &oxcf->scaled_frame_height);
3028 3032
3029 // There has been a change in frame size. 3033 // There has been a change in frame size.
3030 vp9_set_size_literal(cpi, oxcf->scaled_frame_width, 3034 vp9_set_size_literal(cpi, oxcf->scaled_frame_width,
3031 oxcf->scaled_frame_height); 3035 oxcf->scaled_frame_height);
3032 } 3036 }
3033 3037
3038 if (oxcf->pass == 0 &&
3039 oxcf->rc_mode == VPX_CBR &&
3040 !cpi->use_svc &&
3041 oxcf->resize_mode == RESIZE_DYNAMIC) {
3042 if (cpi->resize_state == 1) {
3043 oxcf->scaled_frame_width =
3044 (cm->width * cpi->resize_scale_num) / cpi->resize_scale_den;
3045 oxcf->scaled_frame_height =
3046 (cm->height * cpi->resize_scale_num) /cpi->resize_scale_den;
3047 } else if (cpi->resize_state == -1) {
3048 // Go back up to original size.
3049 oxcf->scaled_frame_width = oxcf->width;
3050 oxcf->scaled_frame_height = oxcf->height;
3051 }
3052 if (cpi->resize_state != 0) {
3053 // There has been a change in frame size.
3054 vp9_set_size_literal(cpi,
3055 oxcf->scaled_frame_width,
3056 oxcf->scaled_frame_height);
3057
3058 // TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
3059 set_mv_search_params(cpi);
3060 }
3061 }
3062
3034 if ((oxcf->pass == 2) && 3063 if ((oxcf->pass == 2) &&
3035 (!cpi->use_svc || 3064 (!cpi->use_svc ||
3036 (is_two_pass_svc(cpi) && 3065 (is_two_pass_svc(cpi) &&
3037 cpi->svc.encode_empty_frame_state != ENCODING))) { 3066 cpi->svc.encode_empty_frame_state != ENCODING))) {
3038 vp9_set_target_rate(cpi); 3067 vp9_set_target_rate(cpi);
3039 } 3068 }
3040 3069
3041 alloc_frame_mvs(cm, cm->new_fb_idx); 3070 alloc_frame_mvs(cm, cm->new_fb_idx);
3042 3071
3043 // Reset the frame pointers to the current frame size. 3072 // Reset the frame pointers to the current frame size.
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 // Don't refresh the last buffer for an ARF overlay frame. It will 3983 // Don't refresh the last buffer for an ARF overlay frame. It will
3955 // become the GF so preserve last as an alternative prediction option. 3984 // become the GF so preserve last as an alternative prediction option.
3956 cpi->refresh_last_frame = 0; 3985 cpi->refresh_last_frame = 0;
3957 } 3986 }
3958 } 3987 }
3959 3988
3960 #if CONFIG_INTERNAL_STATS 3989 #if CONFIG_INTERNAL_STATS
3961 extern double vp9_get_blockiness(const unsigned char *img1, int img1_pitch, 3990 extern double vp9_get_blockiness(const unsigned char *img1, int img1_pitch,
3962 const unsigned char *img2, int img2_pitch, 3991 const unsigned char *img2, int img2_pitch,
3963 int width, int height); 3992 int width, int height);
3964 #endif
3965 3993
3966 static void adjust_image_stat(double y, double u, double v, double all, 3994 static void adjust_image_stat(double y, double u, double v, double all,
3967 ImageStat *s) { 3995 ImageStat *s) {
3968 s->stat[Y] += y; 3996 s->stat[Y] += y;
3969 s->stat[U] += u; 3997 s->stat[U] += u;
3970 s->stat[V] += v; 3998 s->stat[V] += v;
3971 s->stat[ALL] += all; 3999 s->stat[ALL] += all;
3972 s->worst = MIN(s->worst, all); 4000 s->worst = MIN(s->worst, all);
3973 } 4001 }
4002 #endif // CONFIG_INTERNAL_STATS
3974 4003
3975 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, 4004 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
3976 size_t *size, uint8_t *dest, 4005 size_t *size, uint8_t *dest,
3977 int64_t *time_stamp, int64_t *time_end, int flush) { 4006 int64_t *time_stamp, int64_t *time_end, int flush) {
3978 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 4007 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
3979 VP9_COMMON *const cm = &cpi->common; 4008 VP9_COMMON *const cm = &cpi->common;
3980 BufferPool *const pool = cm->buffer_pool; 4009 BufferPool *const pool = cm->buffer_pool;
3981 RATE_CONTROL *const rc = &cpi->rc; 4010 RATE_CONTROL *const rc = &cpi->rc;
3982 struct vpx_usec_timer cmptimer; 4011 struct vpx_usec_timer cmptimer;
3983 YV12_BUFFER_CONFIG *force_src_buffer = NULL; 4012 YV12_BUFFER_CONFIG *force_src_buffer = NULL;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 // Start with a 0 size frame. 4186 // Start with a 0 size frame.
4158 *size = 0; 4187 *size = 0;
4159 4188
4160 cpi->frame_flags = *frame_flags; 4189 cpi->frame_flags = *frame_flags;
4161 4190
4162 if ((oxcf->pass == 2) && 4191 if ((oxcf->pass == 2) &&
4163 (!cpi->use_svc || 4192 (!cpi->use_svc ||
4164 (is_two_pass_svc(cpi) && 4193 (is_two_pass_svc(cpi) &&
4165 cpi->svc.encode_empty_frame_state != ENCODING))) { 4194 cpi->svc.encode_empty_frame_state != ENCODING))) {
4166 vp9_rc_get_second_pass_params(cpi); 4195 vp9_rc_get_second_pass_params(cpi);
4167 } else { 4196 } else if (oxcf->pass == 1) {
4168 set_frame_size(cpi); 4197 set_frame_size(cpi);
4169 } 4198 }
4170 4199
4171 for (i = 0; i < MAX_REF_FRAMES; ++i) 4200 for (i = 0; i < MAX_REF_FRAMES; ++i)
4172 cpi->scaled_ref_idx[i] = INVALID_IDX; 4201 cpi->scaled_ref_idx[i] = INVALID_IDX;
4173 4202
4174 if (oxcf->pass == 1 && 4203 if (oxcf->pass == 1 &&
4175 (!cpi->use_svc || is_two_pass_svc(cpi))) { 4204 (!cpi->use_svc || is_two_pass_svc(cpi))) {
4176 const int lossless = is_lossless_requested(oxcf); 4205 const int lossless = is_lossless_requested(oxcf);
4177 #if CONFIG_VP9_HIGHBITDEPTH 4206 #if CONFIG_VP9_HIGHBITDEPTH
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
4569 if (flags & VP8_EFLAG_NO_UPD_ARF) 4598 if (flags & VP8_EFLAG_NO_UPD_ARF)
4570 upd ^= VP9_ALT_FLAG; 4599 upd ^= VP9_ALT_FLAG;
4571 4600
4572 vp9_update_reference(cpi, upd); 4601 vp9_update_reference(cpi, upd);
4573 } 4602 }
4574 4603
4575 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { 4604 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) {
4576 vp9_update_entropy(cpi, 0); 4605 vp9_update_entropy(cpi, 0);
4577 } 4606 }
4578 } 4607 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.h ('k') | source/libvpx/vp9/encoder/vp9_ethread.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698