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

Side by Side Diff: source/libvpx/vp8/encoder/onyx_if.c

Issue 1302353004: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: Created 5 years, 3 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/vp8/encoder/mr_dissim.c ('k') | source/libvpx/vp8/encoder/onyx_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 11
12 #include "vpx_config.h" 12 #include "vpx_config.h"
13 #include "./vpx_scale_rtcd.h" 13 #include "./vpx_scale_rtcd.h"
14 #include "./vpx_dsp_rtcd.h" 14 #include "./vpx_dsp_rtcd.h"
15 #include "./vp8_rtcd.h" 15 #include "./vp8_rtcd.h"
16 #include "vp8/common/onyxc_int.h" 16 #include "vp8/common/onyxc_int.h"
17 #include "vp8/common/blockd.h" 17 #include "vp8/common/blockd.h"
18 #include "onyx_int.h" 18 #include "onyx_int.h"
19 #include "vp8/common/systemdependent.h" 19 #include "vp8/common/systemdependent.h"
20 #include "quantize.h" 20 #include "vp8/encoder/quantize.h"
21 #include "vp8/common/alloccommon.h" 21 #include "vp8/common/alloccommon.h"
22 #include "mcomp.h" 22 #include "mcomp.h"
23 #include "firstpass.h" 23 #include "firstpass.h"
24 #include "vpx/internal/vpx_psnr.h" 24 #include "vpx/internal/vpx_psnr.h"
25 #include "vpx_scale/vpx_scale.h" 25 #include "vpx_scale/vpx_scale.h"
26 #include "vp8/common/extend.h" 26 #include "vp8/common/extend.h"
27 #include "ratectrl.h" 27 #include "ratectrl.h"
28 #include "vp8/common/quant_common.h" 28 #include "vp8/common/quant_common.h"
29 #include "segmentation.h" 29 #include "segmentation.h"
30 #if CONFIG_POSTPROC 30 #if CONFIG_POSTPROC
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest); 67 int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest);
68 68
69 extern void vp8_temporal_filter_prepare_c(VP8_COMP *cpi, int distance); 69 extern void vp8_temporal_filter_prepare_c(VP8_COMP *cpi, int distance);
70 70
71 static void set_default_lf_deltas(VP8_COMP *cpi); 71 static void set_default_lf_deltas(VP8_COMP *cpi);
72 72
73 extern const int vp8_gf_interval_table[101]; 73 extern const int vp8_gf_interval_table[101];
74 74
75 #if CONFIG_INTERNAL_STATS 75 #if CONFIG_INTERNAL_STATS
76 #include "math.h" 76 #include "math.h"
77 77 #include "vpx_dsp/ssim.h"
78 extern double vp8_calc_ssim
79 (
80 YV12_BUFFER_CONFIG *source,
81 YV12_BUFFER_CONFIG *dest,
82 int lumamask,
83 double *weight
84 );
85
86
87 extern double vp8_calc_ssimg
88 (
89 YV12_BUFFER_CONFIG *source,
90 YV12_BUFFER_CONFIG *dest,
91 double *ssim_y,
92 double *ssim_u,
93 double *ssim_v
94 );
95
96
97 #endif 78 #endif
98 79
99 80
100 #ifdef OUTPUT_YUV_SRC 81 #ifdef OUTPUT_YUV_SRC
101 FILE *yuv_file; 82 FILE *yuv_file;
102 #endif 83 #endif
103 #ifdef OUTPUT_YUV_DENOISED 84 #ifdef OUTPUT_YUV_DENOISED
104 FILE *yuv_denoised_file; 85 FILE *yuv_denoised_file;
105 #endif 86 #endif
106 87
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 * abs_delta = SEGMENT_ABSDATA (use the absolute values given). 509 * abs_delta = SEGMENT_ABSDATA (use the absolute values given).
529 * 510 *
530 */ 511 */
531 static void set_segment_data(VP8_COMP *cpi, signed char *feature_data, unsigned char abs_delta) 512 static void set_segment_data(VP8_COMP *cpi, signed char *feature_data, unsigned char abs_delta)
532 { 513 {
533 cpi->mb.e_mbd.mb_segement_abs_delta = abs_delta; 514 cpi->mb.e_mbd.mb_segement_abs_delta = abs_delta;
534 memcpy(cpi->segment_feature_data, feature_data, sizeof(cpi->segment_feature_ data)); 515 memcpy(cpi->segment_feature_data, feature_data, sizeof(cpi->segment_feature_ data));
535 } 516 }
536 517
537 518
538 static void segmentation_test_function(VP8_COMP *cpi)
539 {
540 unsigned char *seg_map;
541 signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
542
543 // Create a temporary map for segmentation data.
544 CHECK_MEM_ERROR(seg_map, vpx_calloc(cpi->common.mb_rows * cpi->common.mb_col s, 1));
545
546 // Set the segmentation Map
547 set_segmentation_map(cpi, seg_map);
548
549 // Activate segmentation.
550 enable_segmentation(cpi);
551
552 // Set up the quant segment data
553 feature_data[MB_LVL_ALT_Q][0] = 0;
554 feature_data[MB_LVL_ALT_Q][1] = 4;
555 feature_data[MB_LVL_ALT_Q][2] = 0;
556 feature_data[MB_LVL_ALT_Q][3] = 0;
557 // Set up the loop segment data
558 feature_data[MB_LVL_ALT_LF][0] = 0;
559 feature_data[MB_LVL_ALT_LF][1] = 0;
560 feature_data[MB_LVL_ALT_LF][2] = 0;
561 feature_data[MB_LVL_ALT_LF][3] = 0;
562
563 // Initialise the feature data structure
564 // SEGMENT_DELTADATA 0, SEGMENT_ABSDATA 1
565 set_segment_data(cpi, &feature_data[0][0], SEGMENT_DELTADATA);
566
567 // Delete sementation map
568 vpx_free(seg_map);
569
570 seg_map = 0;
571 }
572
573 /* A simple function to cyclically refresh the background at a lower Q */ 519 /* A simple function to cyclically refresh the background at a lower Q */
574 static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment) 520 static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
575 { 521 {
576 unsigned char *seg_map = cpi->segmentation_map; 522 unsigned char *seg_map = cpi->segmentation_map;
577 signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; 523 signed char feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
578 int i; 524 int i;
579 int block_count = cpi->cyclic_refresh_mode_max_mbs_perframe; 525 int block_count = cpi->cyclic_refresh_mode_max_mbs_perframe;
580 int mbs_in_frame = cpi->common.mb_rows * cpi->common.mb_cols; 526 int mbs_in_frame = cpi->common.mb_rows * cpi->common.mb_cols;
581 527
582 cpi->cyclic_refresh_q = Q / 2; 528 cpi->cyclic_refresh_q = Q / 2;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 cpi->mode_check_freq[THR_NEW3] = speed_map(Speed, 871 cpi->mode_check_freq[THR_NEW3] = speed_map(Speed,
926 mode_check_freq_map_new2); 872 mode_check_freq_map_new2);
927 cpi->mode_check_freq[THR_SPLIT1] = speed_map(Speed, 873 cpi->mode_check_freq[THR_SPLIT1] = speed_map(Speed,
928 mode_check_freq_map_split1); 874 mode_check_freq_map_split1);
929 cpi->mode_check_freq[THR_SPLIT2] = 875 cpi->mode_check_freq[THR_SPLIT2] =
930 cpi->mode_check_freq[THR_SPLIT3] = speed_map(Speed, 876 cpi->mode_check_freq[THR_SPLIT3] = speed_map(Speed,
931 mode_check_freq_map_split2); 877 mode_check_freq_map_split2);
932 Speed = cpi->Speed; 878 Speed = cpi->Speed;
933 switch (Mode) 879 switch (Mode)
934 { 880 {
935 #if !(CONFIG_REALTIME_ONLY) 881 #if !CONFIG_REALTIME_ONLY
936 case 0: /* best quality mode */ 882 case 0: /* best quality mode */
937 sf->first_step = 0; 883 sf->first_step = 0;
938 sf->max_step_search_steps = MAX_MVSEARCH_STEPS; 884 sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
939 break; 885 break;
940 case 1: 886 case 1:
941 case 3: 887 case 3:
942 if (Speed > 0) 888 if (Speed > 0)
943 { 889 {
944 /* Disable coefficient optimization above speed 0 */ 890 /* Disable coefficient optimization above speed 0 */
945 sf->optimize_coefficients = 0; 891 sf->optimize_coefficients = 0;
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 yuv_denoised_file = fopen("denoised.yuv", "ab"); 2023 yuv_denoised_file = fopen("denoised.yuv", "ab");
2078 #endif 2024 #endif
2079 2025
2080 #if 0 2026 #if 0
2081 framepsnr = fopen("framepsnr.stt", "a"); 2027 framepsnr = fopen("framepsnr.stt", "a");
2082 kf_list = fopen("kf_list.stt", "w"); 2028 kf_list = fopen("kf_list.stt", "w");
2083 #endif 2029 #endif
2084 2030
2085 cpi->output_pkt_list = oxcf->output_pkt_list; 2031 cpi->output_pkt_list = oxcf->output_pkt_list;
2086 2032
2087 #if !(CONFIG_REALTIME_ONLY) 2033 #if !CONFIG_REALTIME_ONLY
2088 2034
2089 if (cpi->pass == 1) 2035 if (cpi->pass == 1)
2090 { 2036 {
2091 vp8_init_first_pass(cpi); 2037 vp8_init_first_pass(cpi);
2092 } 2038 }
2093 else if (cpi->pass == 2) 2039 else if (cpi->pass == 2)
2094 { 2040 {
2095 size_t packet_sz = sizeof(FIRSTPASS_STATS); 2041 size_t packet_sz = sizeof(FIRSTPASS_STATS);
2096 int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); 2042 int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz);
2097 2043
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 2185
2240 void vp8_remove_compressor(VP8_COMP **ptr) 2186 void vp8_remove_compressor(VP8_COMP **ptr)
2241 { 2187 {
2242 VP8_COMP *cpi = *ptr; 2188 VP8_COMP *cpi = *ptr;
2243 2189
2244 if (!cpi) 2190 if (!cpi)
2245 return; 2191 return;
2246 2192
2247 if (cpi && (cpi->common.current_video_frame > 0)) 2193 if (cpi && (cpi->common.current_video_frame > 0))
2248 { 2194 {
2249 #if !(CONFIG_REALTIME_ONLY) 2195 #if !CONFIG_REALTIME_ONLY
2250 2196
2251 if (cpi->pass == 2) 2197 if (cpi->pass == 2)
2252 { 2198 {
2253 vp8_end_second_pass(cpi); 2199 vp8_end_second_pass(cpi);
2254 } 2200 }
2255 2201
2256 #endif 2202 #endif
2257 2203
2258 #ifdef VP8_ENTROPY_STATS 2204 #ifdef VP8_ENTROPY_STATS
2259 print_context_counters(); 2205 print_context_counters();
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
3030 2976
3031 if (cpi->prob_gf_coded < 10) 2977 if (cpi->prob_gf_coded < 10)
3032 cpi->prob_gf_coded = 10; 2978 cpi->prob_gf_coded = 10;
3033 } 2979 }
3034 if (!cpi->source_alt_ref_active) 2980 if (!cpi->source_alt_ref_active)
3035 cpi->prob_gf_coded = 255; 2981 cpi->prob_gf_coded = 255;
3036 } 2982 }
3037 } 2983 }
3038 2984
3039 2985
2986 #if !CONFIG_REALTIME_ONLY
3040 /* 1 = key, 0 = inter */ 2987 /* 1 = key, 0 = inter */
3041 static int decide_key_frame(VP8_COMP *cpi) 2988 static int decide_key_frame(VP8_COMP *cpi)
3042 { 2989 {
3043 VP8_COMMON *cm = &cpi->common; 2990 VP8_COMMON *cm = &cpi->common;
3044 2991
3045 int code_key_frame = 0; 2992 int code_key_frame = 0;
3046 2993
3047 cpi->kf_boost = 0; 2994 cpi->kf_boost = 0;
3048 2995
3049 if (cpi->Speed > 11) 2996 if (cpi->Speed > 11)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3097 (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra + 10)))) 3044 (cpi->this_frame_percent_intra > (cpi->last_frame_percent_intra + 10))))
3098 { 3045 {
3099 if (!cm->refresh_golden_frame) 3046 if (!cm->refresh_golden_frame)
3100 code_key_frame = 1; 3047 code_key_frame = 1;
3101 } 3048 }
3102 3049
3103 return code_key_frame; 3050 return code_key_frame;
3104 3051
3105 } 3052 }
3106 3053
3107 #if !(CONFIG_REALTIME_ONLY)
3108 static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned int *frame_flags) 3054 static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned int *frame_flags)
3109 { 3055 {
3110 (void) size; 3056 (void) size;
3111 (void) dest; 3057 (void) dest;
3112 (void) frame_flags; 3058 (void) frame_flags;
3113 vp8_set_quantizer(cpi, 26); 3059 vp8_set_quantizer(cpi, 26);
3114 3060
3115 vp8_first_pass(cpi); 3061 vp8_first_pass(cpi);
3116 } 3062 }
3117 #endif 3063 #endif
(...skipping 25 matching lines...) Expand all
3143 yframe = fopen(filename, "wb"); 3089 yframe = fopen(filename, "wb");
3144 3090
3145 for (i = 0; i < frame->uv_height; i++) 3091 for (i = 0; i < frame->uv_height; i++)
3146 fwrite(frame->v_buffer + i * frame->uv_stride, frame->uv_width, 1, yfram e); 3092 fwrite(frame->v_buffer + i * frame->uv_stride, frame->uv_width, 1, yfram e);
3147 3093
3148 fclose(yframe); 3094 fclose(yframe);
3149 } 3095 }
3150 #endif 3096 #endif
3151 /* return of 0 means drop frame */ 3097 /* return of 0 means drop frame */
3152 3098
3099 #if !CONFIG_REALTIME_ONLY
3153 /* Function to test for conditions that indeicate we should loop 3100 /* Function to test for conditions that indeicate we should loop
3154 * back and recode a frame. 3101 * back and recode a frame.
3155 */ 3102 */
3156 static int recode_loop_test( VP8_COMP *cpi, 3103 static int recode_loop_test( VP8_COMP *cpi,
3157 int high_limit, int low_limit, 3104 int high_limit, int low_limit,
3158 int q, int maxq, int minq ) 3105 int q, int maxq, int minq )
3159 { 3106 {
3160 int force_recode = 0; 3107 int force_recode = 0;
3161 VP8_COMMON *cm = &cpi->common; 3108 VP8_COMMON *cm = &cpi->common;
3162 3109
(...skipping 29 matching lines...) Expand all
3192 (cpi->active_best_quality > cpi->oxcf.cq_level)) 3139 (cpi->active_best_quality > cpi->oxcf.cq_level))
3193 { 3140 {
3194 force_recode = 1; 3141 force_recode = 1;
3195 cpi->active_best_quality = cpi->oxcf.cq_level; 3142 cpi->active_best_quality = cpi->oxcf.cq_level;
3196 } 3143 }
3197 } 3144 }
3198 } 3145 }
3199 3146
3200 return force_recode; 3147 return force_recode;
3201 } 3148 }
3149 #endif // !CONFIG_REALTIME_ONLY
3202 3150
3203 static void update_reference_frames(VP8_COMP *cpi) 3151 static void update_reference_frames(VP8_COMP *cpi)
3204 { 3152 {
3205 VP8_COMMON *cm = &cpi->common; 3153 VP8_COMMON *cm = &cpi->common;
3206 YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb; 3154 YV12_BUFFER_CONFIG *yv12_fb = cm->yv12_fb;
3207 3155
3208 /* At this point the new frame has been encoded. 3156 /* At this point the new frame has been encoded.
3209 * If any buffer copy / swapping is signaled it should be done here. 3157 * If any buffer copy / swapping is signaled it should be done here.
3210 */ 3158 */
3211 3159
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
3613 int Q; 3561 int Q;
3614 int frame_over_shoot_limit; 3562 int frame_over_shoot_limit;
3615 int frame_under_shoot_limit; 3563 int frame_under_shoot_limit;
3616 3564
3617 int Loop = 0; 3565 int Loop = 0;
3618 int loop_count; 3566 int loop_count;
3619 3567
3620 VP8_COMMON *cm = &cpi->common; 3568 VP8_COMMON *cm = &cpi->common;
3621 int active_worst_qchanged = 0; 3569 int active_worst_qchanged = 0;
3622 3570
3623 #if !(CONFIG_REALTIME_ONLY) 3571 #if !CONFIG_REALTIME_ONLY
3624 int q_low; 3572 int q_low;
3625 int q_high; 3573 int q_high;
3626 int zbin_oq_high; 3574 int zbin_oq_high;
3627 int zbin_oq_low = 0; 3575 int zbin_oq_low = 0;
3628 int top_index; 3576 int top_index;
3629 int bottom_index; 3577 int bottom_index;
3630 int overshoot_seen = 0; 3578 int overshoot_seen = 0;
3631 int undershoot_seen = 0; 3579 int undershoot_seen = 0;
3632 #endif 3580 #endif
3633 3581
(...skipping 18 matching lines...) Expand all
3652 3600
3653 if(cpi->force_next_frame_intra) 3601 if(cpi->force_next_frame_intra)
3654 { 3602 {
3655 cm->frame_type = KEY_FRAME; /* delayed intra frame */ 3603 cm->frame_type = KEY_FRAME; /* delayed intra frame */
3656 cpi->force_next_frame_intra = 0; 3604 cpi->force_next_frame_intra = 0;
3657 } 3605 }
3658 3606
3659 /* For an alt ref frame in 2 pass we skip the call to the second pass 3607 /* For an alt ref frame in 2 pass we skip the call to the second pass
3660 * function that sets the target bandwidth 3608 * function that sets the target bandwidth
3661 */ 3609 */
3662 #if !(CONFIG_REALTIME_ONLY) 3610 #if !CONFIG_REALTIME_ONLY
3663 3611
3664 if (cpi->pass == 2) 3612 if (cpi->pass == 2)
3665 { 3613 {
3666 if (cpi->common.refresh_alt_ref_frame) 3614 if (cpi->common.refresh_alt_ref_frame)
3667 { 3615 {
3668 /* Per frame bit target for the alt ref frame */ 3616 /* Per frame bit target for the alt ref frame */
3669 cpi->per_frame_bandwidth = cpi->twopass.gf_bits; 3617 cpi->per_frame_bandwidth = cpi->twopass.gf_bits;
3670 /* per second target bitrate */ 3618 /* per second target bitrate */
3671 cpi->target_bandwidth = (int)(cpi->twopass.gf_bits * 3619 cpi->target_bandwidth = (int)(cpi->twopass.gf_bits *
3672 cpi->output_framerate); 3620 cpi->output_framerate);
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
4161 4109
4162 if (cpi->active_best_quality < cpi->best_quality) 4110 if (cpi->active_best_quality < cpi->best_quality)
4163 cpi->active_best_quality = cpi->best_quality; 4111 cpi->active_best_quality = cpi->best_quality;
4164 4112
4165 if ( cpi->active_worst_quality < cpi->active_best_quality ) 4113 if ( cpi->active_worst_quality < cpi->active_best_quality )
4166 cpi->active_worst_quality = cpi->active_best_quality; 4114 cpi->active_worst_quality = cpi->active_best_quality;
4167 4115
4168 /* Determine initial Q to try */ 4116 /* Determine initial Q to try */
4169 Q = vp8_regulate_q(cpi, cpi->this_frame_target); 4117 Q = vp8_regulate_q(cpi, cpi->this_frame_target);
4170 4118
4171 #if !(CONFIG_REALTIME_ONLY) 4119 #if !CONFIG_REALTIME_ONLY
4172 4120
4173 /* Set highest allowed value for Zbin over quant */ 4121 /* Set highest allowed value for Zbin over quant */
4174 if (cm->frame_type == KEY_FRAME) 4122 if (cm->frame_type == KEY_FRAME)
4175 zbin_oq_high = 0; 4123 zbin_oq_high = 0;
4176 else if ((cpi->oxcf.number_of_layers == 1) && ((cm->refresh_alt_ref_frame || 4124 else if ((cpi->oxcf.number_of_layers == 1) && ((cm->refresh_alt_ref_frame ||
4177 (cm->refresh_golden_frame && !cpi->source_alt_ref_active)))) 4125 (cm->refresh_golden_frame && !cpi->source_alt_ref_active))))
4178 { 4126 {
4179 zbin_oq_high = 16; 4127 zbin_oq_high = 16;
4180 } 4128 }
4181 else 4129 else
4182 zbin_oq_high = ZBIN_OQ_MAX; 4130 zbin_oq_high = ZBIN_OQ_MAX;
4183 #endif 4131 #endif
4184 4132
4185 /* Setup background Q adjustment for error resilient mode. 4133 /* Setup background Q adjustment for error resilient mode.
4186 * For multi-layer encodes only enable this for the base layer. 4134 * For multi-layer encodes only enable this for the base layer.
4187 */ 4135 */
4188 if (cpi->cyclic_refresh_mode_enabled) 4136 if (cpi->cyclic_refresh_mode_enabled)
4189 { 4137 {
4190 // Special case for screen_content_mode with golden frame updates. 4138 // Special case for screen_content_mode with golden frame updates.
4191 int disable_cr_gf = (cpi->oxcf.screen_content_mode == 2 && 4139 int disable_cr_gf = (cpi->oxcf.screen_content_mode == 2 &&
4192 cm->refresh_golden_frame); 4140 cm->refresh_golden_frame);
4193 if (cpi->current_layer == 0 && cpi->force_maxqp == 0 && !disable_cr_gf) 4141 if (cpi->current_layer == 0 && cpi->force_maxqp == 0 && !disable_cr_gf)
4194 cyclic_background_refresh(cpi, Q, 0); 4142 cyclic_background_refresh(cpi, Q, 0);
4195 else 4143 else
4196 disable_segmentation(cpi); 4144 disable_segmentation(cpi);
4197 } 4145 }
4198 4146
4199 vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_sho ot_limit); 4147 vp8_compute_frame_size_bounds(cpi, &frame_under_shoot_limit, &frame_over_sho ot_limit);
4200 4148
4201 #if !(CONFIG_REALTIME_ONLY) 4149 #if !CONFIG_REALTIME_ONLY
4202 /* Limit Q range for the adaptive loop. */ 4150 /* Limit Q range for the adaptive loop. */
4203 bottom_index = cpi->active_best_quality; 4151 bottom_index = cpi->active_best_quality;
4204 top_index = cpi->active_worst_quality; 4152 top_index = cpi->active_worst_quality;
4205 q_low = cpi->active_best_quality; 4153 q_low = cpi->active_best_quality;
4206 q_high = cpi->active_worst_quality; 4154 q_high = cpi->active_worst_quality;
4207 #endif 4155 #endif
4208 4156
4209 vp8_save_coding_context(cpi); 4157 vp8_save_coding_context(cpi);
4210 4158
4211 loop_count = 0; 4159 loop_count = 0;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
4422 #endif 4370 #endif
4423 vp8_clear_system_state(); 4371 vp8_clear_system_state();
4424 4372
4425 /* Test to see if the stats generated for this frame indicate that 4373 /* Test to see if the stats generated for this frame indicate that
4426 * we should have coded a key frame (assuming that we didn't)! 4374 * we should have coded a key frame (assuming that we didn't)!
4427 */ 4375 */
4428 4376
4429 if (cpi->pass != 2 && cpi->oxcf.auto_key && cm->frame_type != KEY_FRAME 4377 if (cpi->pass != 2 && cpi->oxcf.auto_key && cm->frame_type != KEY_FRAME
4430 && cpi->compressor_speed != 2) 4378 && cpi->compressor_speed != 2)
4431 { 4379 {
4432 #if !(CONFIG_REALTIME_ONLY) 4380 #if !CONFIG_REALTIME_ONLY
4433 if (decide_key_frame(cpi)) 4381 if (decide_key_frame(cpi))
4434 { 4382 {
4435 /* Reset all our sizing numbers and recode */ 4383 /* Reset all our sizing numbers and recode */
4436 cm->frame_type = KEY_FRAME; 4384 cm->frame_type = KEY_FRAME;
4437 4385
4438 vp8_pick_frame_size(cpi); 4386 vp8_pick_frame_size(cpi);
4439 4387
4440 /* Clear the Alt reference frame active flag when we have 4388 /* Clear the Alt reference frame active flag when we have
4441 * a key frame 4389 * a key frame
4442 */ 4390 */
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4478 { 4426 {
4479 int over_size_percent = ((cpi->projected_frame_size - frame_over_sho ot_limit) * 100) / frame_over_shoot_limit; 4427 int over_size_percent = ((cpi->projected_frame_size - frame_over_sho ot_limit) * 100) / frame_over_shoot_limit;
4480 4428
4481 /* If so is there any scope for relaxing it */ 4429 /* If so is there any scope for relaxing it */
4482 while ((cpi->active_worst_quality < cpi->worst_quality) && (over_siz e_percent > 0)) 4430 while ((cpi->active_worst_quality < cpi->worst_quality) && (over_siz e_percent > 0))
4483 { 4431 {
4484 cpi->active_worst_quality++; 4432 cpi->active_worst_quality++;
4485 /* Assume 1 qstep = about 4% on frame size. */ 4433 /* Assume 1 qstep = about 4% on frame size. */
4486 over_size_percent = (int)(over_size_percent * 0.96); 4434 over_size_percent = (int)(over_size_percent * 0.96);
4487 } 4435 }
4488 #if !(CONFIG_REALTIME_ONLY) 4436 #if !CONFIG_REALTIME_ONLY
4489 top_index = cpi->active_worst_quality; 4437 top_index = cpi->active_worst_quality;
4490 #endif 4438 #endif // !CONFIG_REALTIME_ONLY
4491 /* If we have updated the active max Q do not call 4439 /* If we have updated the active max Q do not call
4492 * vp8_update_rate_correction_factors() this loop. 4440 * vp8_update_rate_correction_factors() this loop.
4493 */ 4441 */
4494 active_worst_qchanged = 1; 4442 active_worst_qchanged = 1;
4495 } 4443 }
4496 else 4444 else
4497 active_worst_qchanged = 0; 4445 active_worst_qchanged = 0;
4498 4446
4499 #if !(CONFIG_REALTIME_ONLY) 4447 #if !CONFIG_REALTIME_ONLY
4500 /* Special case handling for forced key frames */ 4448 /* Special case handling for forced key frames */
4501 if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced ) 4449 if ( (cm->frame_type == KEY_FRAME) && cpi->this_key_frame_forced )
4502 { 4450 {
4503 int last_q = Q; 4451 int last_q = Q;
4504 int kf_err = vp8_calc_ss_err(cpi->Source, 4452 int kf_err = vp8_calc_ss_err(cpi->Source,
4505 &cm->yv12_fb[cm->new_fb_idx]); 4453 &cm->yv12_fb[cm->new_fb_idx]);
4506 4454
4507 /* The key frame is not good enough */ 4455 /* The key frame is not good enough */
4508 if ( kf_err > ((cpi->ambient_err * 7) >> 3) ) 4456 if ( kf_err > ((cpi->ambient_err * 7) >> 3) )
4509 { 4457 {
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
5227 cm->yv12_fb[cm->lst_fb_idx].frame_size, 1, recon_file); 5175 cm->yv12_fb[cm->lst_fb_idx].frame_size, 1, recon_file);
5228 fclose(recon_file); 5176 fclose(recon_file);
5229 } 5177 }
5230 #endif 5178 #endif
5231 5179
5232 /* DEBUG */ 5180 /* DEBUG */
5233 /* vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show); */ 5181 /* vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show); */
5234 5182
5235 5183
5236 } 5184 }
5237 #if !(CONFIG_REALTIME_ONLY) 5185 #if !CONFIG_REALTIME_ONLY
5238 static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned char * dest_end, unsigned int *frame_flags) 5186 static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, unsigned char * dest_end, unsigned int *frame_flags)
5239 { 5187 {
5240 5188
5241 if (!cpi->common.refresh_alt_ref_frame) 5189 if (!cpi->common.refresh_alt_ref_frame)
5242 vp8_second_pass(cpi); 5190 vp8_second_pass(cpi);
5243 5191
5244 encode_frame_to_data_rate(cpi, size, dest, dest_end, frame_flags); 5192 encode_frame_to_data_rate(cpi, size, dest, dest_end, frame_flags);
5245 cpi->twopass.bits_left -= 8 * *size; 5193 cpi->twopass.bits_left -= 8 * *size;
5246 5194
5247 if (!cpi->common.refresh_alt_ref_frame) 5195 if (!cpi->common.refresh_alt_ref_frame)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
5311 vp8_clear_system_state(); 5259 vp8_clear_system_state();
5312 return VPX_CODEC_CORRUPT_FRAME; 5260 return VPX_CODEC_CORRUPT_FRAME;
5313 } 5261 }
5314 5262
5315 cpi->common.error.setjmp = 1; 5263 cpi->common.error.setjmp = 1;
5316 5264
5317 vpx_usec_timer_start(&cmptimer); 5265 vpx_usec_timer_start(&cmptimer);
5318 5266
5319 cpi->source = NULL; 5267 cpi->source = NULL;
5320 5268
5321 #if !(CONFIG_REALTIME_ONLY) 5269 #if !CONFIG_REALTIME_ONLY
5322 /* Should we code an alternate reference frame */ 5270 /* Should we code an alternate reference frame */
5323 if (cpi->oxcf.error_resilient_mode == 0 && 5271 if (cpi->oxcf.error_resilient_mode == 0 &&
5324 cpi->oxcf.play_alternate && 5272 cpi->oxcf.play_alternate &&
5325 cpi->source_alt_ref_pending) 5273 cpi->source_alt_ref_pending)
5326 { 5274 {
5327 if ((cpi->source = vp8_lookahead_peek(cpi->lookahead, 5275 if ((cpi->source = vp8_lookahead_peek(cpi->lookahead,
5328 cpi->frames_till_gf_update_due, 5276 cpi->frames_till_gf_update_due,
5329 PEEK_FORWARD))) 5277 PEEK_FORWARD)))
5330 { 5278 {
5331 cpi->alt_ref_source = cpi->source; 5279 cpi->alt_ref_source = cpi->source;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
5379 *frame_flags = cpi->source->flags; 5327 *frame_flags = cpi->source->flags;
5380 5328
5381 if (cpi->pass == 1 && cm->current_video_frame > 0) 5329 if (cpi->pass == 1 && cm->current_video_frame > 0)
5382 { 5330 {
5383 cpi->last_frame_unscaled_source = &cpi->last_source->img; 5331 cpi->last_frame_unscaled_source = &cpi->last_source->img;
5384 } 5332 }
5385 } 5333 }
5386 else 5334 else
5387 { 5335 {
5388 *size = 0; 5336 *size = 0;
5389 #if !(CONFIG_REALTIME_ONLY) 5337 #if !CONFIG_REALTIME_ONLY
5390 5338
5391 if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done) 5339 if (flush && cpi->pass == 1 && !cpi->twopass.first_pass_done)
5392 { 5340 {
5393 vp8_end_first_pass(cpi); /* get last stats packet */ 5341 vp8_end_first_pass(cpi); /* get last stats packet */
5394 cpi->twopass.first_pass_done = 1; 5342 cpi->twopass.first_pass_done = 1;
5395 } 5343 }
5396 5344
5397 #endif 5345 #endif
5398 5346
5399 return -1; 5347 return -1;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
5572 { 5520 {
5573 if(!cm->yv12_fb[i].flags) 5521 if(!cm->yv12_fb[i].flags)
5574 { 5522 {
5575 cm->new_fb_idx = i; 5523 cm->new_fb_idx = i;
5576 break; 5524 break;
5577 } 5525 }
5578 } 5526 }
5579 5527
5580 assert(i < NUM_YV12_BUFFERS ); 5528 assert(i < NUM_YV12_BUFFERS );
5581 } 5529 }
5582 #if !(CONFIG_REALTIME_ONLY) 5530 #if !CONFIG_REALTIME_ONLY
5583 5531
5584 if (cpi->pass == 1) 5532 if (cpi->pass == 1)
5585 { 5533 {
5586 Pass1Encode(cpi, size, dest, frame_flags); 5534 Pass1Encode(cpi, size, dest, frame_flags);
5587 } 5535 }
5588 else if (cpi->pass == 2) 5536 else if (cpi->pass == 2)
5589 { 5537 {
5590 Pass2Encode(cpi, size, dest, dest_end, frame_flags); 5538 Pass2Encode(cpi, size, dest, dest_end, frame_flags);
5591 } 5539 }
5592 else 5540 else
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
5734 5682
5735 cpi->totalp_y += vpx_sse_to_psnr(y_samples, 5683 cpi->totalp_y += vpx_sse_to_psnr(y_samples,
5736 255.0, (double)ye); 5684 255.0, (double)ye);
5737 cpi->totalp_u += vpx_sse_to_psnr(uv_samples, 5685 cpi->totalp_u += vpx_sse_to_psnr(uv_samples,
5738 255.0, (double)ue); 5686 255.0, (double)ue);
5739 cpi->totalp_v += vpx_sse_to_psnr(uv_samples, 5687 cpi->totalp_v += vpx_sse_to_psnr(uv_samples,
5740 255.0, (double)ve); 5688 255.0, (double)ve);
5741 cpi->total_sq_error2 += sq_error2; 5689 cpi->total_sq_error2 += sq_error2;
5742 cpi->totalp += frame_psnr2; 5690 cpi->totalp += frame_psnr2;
5743 5691
5744 frame_ssim2 = vp8_calc_ssim(cpi->Source, 5692 frame_ssim2 = vpx_calc_ssim(cpi->Source,
5745 &cm->post_proc_buffer, 1, &weight); 5693 &cm->post_proc_buffer, &weight);
5746 5694
5747 cpi->summed_quality += frame_ssim2 * weight; 5695 cpi->summed_quality += frame_ssim2 * weight;
5748 cpi->summed_weights += weight; 5696 cpi->summed_weights += weight;
5749 5697
5750 if (cpi->oxcf.number_of_layers > 1) 5698 if (cpi->oxcf.number_of_layers > 1)
5751 { 5699 {
5752 unsigned int i; 5700 unsigned int i;
5753 5701
5754 for (i=cpi->current_layer; 5702 for (i=cpi->current_layer;
5755 i<cpi->oxcf.number_of_layers; i++) 5703 i<cpi->oxcf.number_of_layers; i++)
5756 { 5704 {
5757 cpi->frames_in_layer[i]++; 5705 cpi->frames_in_layer[i]++;
5758 5706
5759 cpi->bytes_in_layer[i] += *size; 5707 cpi->bytes_in_layer[i] += *size;
5760 cpi->sum_psnr[i] += frame_psnr; 5708 cpi->sum_psnr[i] += frame_psnr;
5761 cpi->sum_psnr_p[i] += frame_psnr2; 5709 cpi->sum_psnr_p[i] += frame_psnr2;
5762 cpi->total_error2[i] += sq_error; 5710 cpi->total_error2[i] += sq_error;
5763 cpi->total_error2_p[i] += sq_error2; 5711 cpi->total_error2_p[i] += sq_error2;
5764 cpi->sum_ssim[i] += frame_ssim2 * weight; 5712 cpi->sum_ssim[i] += frame_ssim2 * weight;
5765 cpi->sum_weights[i] += weight; 5713 cpi->sum_weights[i] += weight;
5766 } 5714 }
5767 } 5715 }
5768 } 5716 }
5769 #endif 5717 #endif
5770 } 5718 }
5771 5719
5772 if (cpi->b_calculate_ssimg) 5720 if (cpi->b_calculate_ssimg)
5773 { 5721 {
5774 double y, u, v, frame_all; 5722 double y, u, v, frame_all;
5775 frame_all = vp8_calc_ssimg(cpi->Source, cm->frame_to_show, 5723 frame_all = vpx_calc_ssimg(cpi->Source, cm->frame_to_show,
5776 &y, &u, &v); 5724 &y, &u, &v);
5777 5725
5778 if (cpi->oxcf.number_of_layers > 1) 5726 if (cpi->oxcf.number_of_layers > 1)
5779 { 5727 {
5780 unsigned int i; 5728 unsigned int i;
5781 5729
5782 for (i=cpi->current_layer; 5730 for (i=cpi->current_layer;
5783 i<cpi->oxcf.number_of_layers; i++) 5731 i<cpi->oxcf.number_of_layers; i++)
5784 { 5732 {
5785 if (!cpi->b_calculate_psnr) 5733 if (!cpi->b_calculate_psnr)
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
6002 } 5950 }
6003 5951
6004 return Total; 5952 return Total;
6005 } 5953 }
6006 5954
6007 5955
6008 int vp8_get_quantizer(VP8_COMP *cpi) 5956 int vp8_get_quantizer(VP8_COMP *cpi)
6009 { 5957 {
6010 return cpi->common.base_qindex; 5958 return cpi->common.base_qindex;
6011 } 5959 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/mr_dissim.c ('k') | source/libvpx/vp8/encoder/onyx_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698