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 | 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 "vp8/common/onyxc_int.h" | 14 #include "vp8/common/onyxc_int.h" |
15 #include "vp8/common/blockd.h" | 15 #include "vp8/common/blockd.h" |
16 #include "onyx_int.h" | 16 #include "onyx_int.h" |
17 #include "vp8/common/systemdependent.h" | 17 #include "vp8/common/systemdependent.h" |
18 #include "quantize.h" | 18 #include "quantize.h" |
19 #include "vp8/common/alloccommon.h" | 19 #include "vp8/common/alloccommon.h" |
20 #include "mcomp.h" | 20 #include "mcomp.h" |
21 #include "firstpass.h" | 21 #include "firstpass.h" |
22 #include "psnr.h" | 22 #include "psnr.h" |
23 #include "vpx_scale/vpxscale.h" | 23 #include "vpx_scale/vpx_scale.h" |
24 #include "vp8/common/extend.h" | 24 #include "vp8/common/extend.h" |
25 #include "ratectrl.h" | 25 #include "ratectrl.h" |
26 #include "vp8/common/quant_common.h" | 26 #include "vp8/common/quant_common.h" |
27 #include "segmentation.h" | 27 #include "segmentation.h" |
28 #if CONFIG_POSTPROC | 28 #if CONFIG_POSTPROC |
29 #include "vp8/common/postproc.h" | 29 #include "vp8/common/postproc.h" |
30 #endif | 30 #endif |
31 #include "vpx_mem/vpx_mem.h" | 31 #include "vpx_mem/vpx_mem.h" |
32 #include "vp8/common/swapyv12buffer.h" | 32 #include "vp8/common/swapyv12buffer.h" |
33 #include "vp8/common/threading.h" | 33 #include "vp8/common/threading.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 lc->active_worst_quality = cpi->active_worst_quality; | 232 lc->active_worst_quality = cpi->active_worst_quality; |
233 lc->best_quality = cpi->best_quality; | 233 lc->best_quality = cpi->best_quality; |
234 lc->active_best_quality = cpi->active_best_quality; | 234 lc->active_best_quality = cpi->active_best_quality; |
235 lc->ni_av_qi = cpi->ni_av_qi; | 235 lc->ni_av_qi = cpi->ni_av_qi; |
236 lc->ni_tot_qi = cpi->ni_tot_qi; | 236 lc->ni_tot_qi = cpi->ni_tot_qi; |
237 lc->ni_frames = cpi->ni_frames; | 237 lc->ni_frames = cpi->ni_frames; |
238 lc->avg_frame_qindex = cpi->avg_frame_qindex; | 238 lc->avg_frame_qindex = cpi->avg_frame_qindex; |
239 lc->rate_correction_factor = cpi->rate_correction_factor; | 239 lc->rate_correction_factor = cpi->rate_correction_factor; |
240 lc->key_frame_rate_correction_factor = cpi->key_frame_rate_correction_factor
; | 240 lc->key_frame_rate_correction_factor = cpi->key_frame_rate_correction_factor
; |
241 lc->gf_rate_correction_factor = cpi->gf_rate_correction_factor; | 241 lc->gf_rate_correction_factor = cpi->gf_rate_correction_factor; |
242 lc->zbin_over_quant = cpi->zbin_over_quant; | 242 lc->zbin_over_quant = cpi->mb.zbin_over_quant; |
243 lc->inter_frame_target = cpi->inter_frame_target; | 243 lc->inter_frame_target = cpi->inter_frame_target; |
244 lc->total_byte_count = cpi->total_byte_count; | 244 lc->total_byte_count = cpi->total_byte_count; |
245 lc->filter_level = cpi->common.filter_level; | 245 lc->filter_level = cpi->common.filter_level; |
246 | 246 |
247 lc->last_frame_percent_intra = cpi->last_frame_percent_intra; | 247 lc->last_frame_percent_intra = cpi->last_frame_percent_intra; |
248 | 248 |
249 memcpy (lc->count_mb_ref_frame_usage, | 249 memcpy (lc->count_mb_ref_frame_usage, |
250 cpi->count_mb_ref_frame_usage, | 250 cpi->mb.count_mb_ref_frame_usage, |
251 sizeof(cpi->count_mb_ref_frame_usage)); | 251 sizeof(cpi->mb.count_mb_ref_frame_usage)); |
252 } | 252 } |
253 | 253 |
254 static void restore_layer_context(VP8_COMP *cpi, const int layer) | 254 static void restore_layer_context(VP8_COMP *cpi, const int layer) |
255 { | 255 { |
256 LAYER_CONTEXT *lc = &cpi->layer_context[layer]; | 256 LAYER_CONTEXT *lc = &cpi->layer_context[layer]; |
257 | 257 |
258 /* Restore layer dependent coding state */ | 258 /* Restore layer dependent coding state */ |
259 cpi->current_layer = layer; | 259 cpi->current_layer = layer; |
260 cpi->target_bandwidth = lc->target_bandwidth; | 260 cpi->target_bandwidth = lc->target_bandwidth; |
261 cpi->oxcf.target_bandwidth = lc->target_bandwidth; | 261 cpi->oxcf.target_bandwidth = lc->target_bandwidth; |
262 cpi->oxcf.starting_buffer_level = lc->starting_buffer_level; | 262 cpi->oxcf.starting_buffer_level = lc->starting_buffer_level; |
263 cpi->oxcf.optimal_buffer_level = lc->optimal_buffer_level; | 263 cpi->oxcf.optimal_buffer_level = lc->optimal_buffer_level; |
264 cpi->oxcf.maximum_buffer_size = lc->maximum_buffer_size; | 264 cpi->oxcf.maximum_buffer_size = lc->maximum_buffer_size; |
265 cpi->oxcf.starting_buffer_level_in_ms = lc->starting_buffer_level_in_ms; | 265 cpi->oxcf.starting_buffer_level_in_ms = lc->starting_buffer_level_in_ms; |
266 cpi->oxcf.optimal_buffer_level_in_ms = lc->optimal_buffer_level_in_ms; | 266 cpi->oxcf.optimal_buffer_level_in_ms = lc->optimal_buffer_level_in_ms; |
267 cpi->oxcf.maximum_buffer_size_in_ms = lc->maximum_buffer_size_in_ms; | 267 cpi->oxcf.maximum_buffer_size_in_ms = lc->maximum_buffer_size_in_ms; |
268 cpi->buffer_level = lc->buffer_level; | 268 cpi->buffer_level = lc->buffer_level; |
269 cpi->bits_off_target = lc->bits_off_target; | 269 cpi->bits_off_target = lc->bits_off_target; |
270 cpi->total_actual_bits = lc->total_actual_bits; | 270 cpi->total_actual_bits = lc->total_actual_bits; |
271 cpi->active_worst_quality = lc->active_worst_quality; | 271 cpi->active_worst_quality = lc->active_worst_quality; |
272 cpi->active_best_quality = lc->active_best_quality; | 272 cpi->active_best_quality = lc->active_best_quality; |
273 cpi->ni_av_qi = lc->ni_av_qi; | 273 cpi->ni_av_qi = lc->ni_av_qi; |
274 cpi->ni_tot_qi = lc->ni_tot_qi; | 274 cpi->ni_tot_qi = lc->ni_tot_qi; |
275 cpi->ni_frames = lc->ni_frames; | 275 cpi->ni_frames = lc->ni_frames; |
276 cpi->avg_frame_qindex = lc->avg_frame_qindex; | 276 cpi->avg_frame_qindex = lc->avg_frame_qindex; |
277 cpi->rate_correction_factor = lc->rate_correction_factor; | 277 cpi->rate_correction_factor = lc->rate_correction_factor; |
278 cpi->key_frame_rate_correction_factor = lc->key_frame_rate_correction_factor
; | 278 cpi->key_frame_rate_correction_factor = lc->key_frame_rate_correction_factor
; |
279 cpi->gf_rate_correction_factor = lc->gf_rate_correction_factor; | 279 cpi->gf_rate_correction_factor = lc->gf_rate_correction_factor; |
280 cpi->zbin_over_quant = lc->zbin_over_quant; | 280 cpi->mb.zbin_over_quant = lc->zbin_over_quant; |
281 cpi->inter_frame_target = lc->inter_frame_target; | 281 cpi->inter_frame_target = lc->inter_frame_target; |
282 cpi->total_byte_count = lc->total_byte_count; | 282 cpi->total_byte_count = lc->total_byte_count; |
283 cpi->common.filter_level = lc->filter_level; | 283 cpi->common.filter_level = lc->filter_level; |
284 | 284 |
285 cpi->last_frame_percent_intra = lc->last_frame_percent_intra; | 285 cpi->last_frame_percent_intra = lc->last_frame_percent_intra; |
286 | 286 |
287 memcpy (cpi->count_mb_ref_frame_usage, | 287 memcpy (cpi->mb.count_mb_ref_frame_usage, |
288 lc->count_mb_ref_frame_usage, | 288 lc->count_mb_ref_frame_usage, |
289 sizeof(cpi->count_mb_ref_frame_usage)); | 289 sizeof(cpi->mb.count_mb_ref_frame_usage)); |
290 } | 290 } |
291 | 291 |
292 static void setup_features(VP8_COMP *cpi) | 292 static void setup_features(VP8_COMP *cpi) |
293 { | 293 { |
294 // If segmentation enabled set the update flags | 294 // If segmentation enabled set the update flags |
295 if ( cpi->mb.e_mbd.segmentation_enabled ) | 295 if ( cpi->mb.e_mbd.segmentation_enabled ) |
296 { | 296 { |
297 cpi->mb.e_mbd.update_mb_segmentation_map = 1; | 297 cpi->mb.e_mbd.update_mb_segmentation_map = 1; |
298 cpi->mb.e_mbd.update_mb_segmentation_data = 1; | 298 cpi->mb.e_mbd.update_mb_segmentation_data = 1; |
299 } | 299 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 vpx_free(cpi->tok); | 349 vpx_free(cpi->tok); |
350 cpi->tok = 0; | 350 cpi->tok = 0; |
351 | 351 |
352 /* Structure used to monitor GF usage */ | 352 /* Structure used to monitor GF usage */ |
353 vpx_free(cpi->gf_active_flags); | 353 vpx_free(cpi->gf_active_flags); |
354 cpi->gf_active_flags = 0; | 354 cpi->gf_active_flags = 0; |
355 | 355 |
356 /* Activity mask based per mb zbin adjustments */ | 356 /* Activity mask based per mb zbin adjustments */ |
357 vpx_free(cpi->mb_activity_map); | 357 vpx_free(cpi->mb_activity_map); |
358 cpi->mb_activity_map = 0; | 358 cpi->mb_activity_map = 0; |
359 vpx_free(cpi->mb_norm_activity_map); | |
360 cpi->mb_norm_activity_map = 0; | |
361 | 359 |
362 vpx_free(cpi->mb.pip); | 360 vpx_free(cpi->mb.pip); |
363 cpi->mb.pip = 0; | 361 cpi->mb.pip = 0; |
364 | 362 |
365 #if CONFIG_MULTITHREAD | 363 #if CONFIG_MULTITHREAD |
366 vpx_free(cpi->mt_current_mb_col); | 364 vpx_free(cpi->mt_current_mb_col); |
367 cpi->mt_current_mb_col = NULL; | 365 cpi->mt_current_mb_col = NULL; |
368 #endif | 366 #endif |
369 } | 367 } |
370 | 368 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 int Speed = cpi->Speed; | 634 int Speed = cpi->Speed; |
637 int i; | 635 int i; |
638 VP8_COMMON *cm = &cpi->common; | 636 VP8_COMMON *cm = &cpi->common; |
639 int last_improved_quant = sf->improved_quant; | 637 int last_improved_quant = sf->improved_quant; |
640 int ref_frames; | 638 int ref_frames; |
641 | 639 |
642 /* Initialise default mode frequency sampling variables */ | 640 /* Initialise default mode frequency sampling variables */ |
643 for (i = 0; i < MAX_MODES; i ++) | 641 for (i = 0; i < MAX_MODES; i ++) |
644 { | 642 { |
645 cpi->mode_check_freq[i] = 0; | 643 cpi->mode_check_freq[i] = 0; |
646 cpi->mode_test_hit_counts[i] = 0; | |
647 cpi->mode_chosen_counts[i] = 0; | 644 cpi->mode_chosen_counts[i] = 0; |
648 } | 645 } |
649 | 646 |
650 cpi->mbs_tested_so_far = 0; | 647 cpi->mb.mbs_tested_so_far = 0; |
651 | 648 |
652 /* best quality defaults */ | 649 /* best quality defaults */ |
653 sf->RD = 1; | 650 sf->RD = 1; |
654 sf->search_method = NSTEP; | 651 sf->search_method = NSTEP; |
655 sf->improved_quant = 1; | 652 sf->improved_quant = 1; |
656 sf->improved_dct = 1; | 653 sf->improved_dct = 1; |
657 sf->auto_filter = 1; | 654 sf->auto_filter = 1; |
658 sf->recode_loop = 1; | 655 sf->recode_loop = 1; |
659 sf->quarter_pixel_search = 1; | 656 sf->quarter_pixel_search = 1; |
660 sf->half_pixel_search = 1; | 657 sf->half_pixel_search = 1; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 | 831 |
835 int min = 2000; | 832 int min = 2000; |
836 | 833 |
837 if (cpi->oxcf.encode_breakout > 2000) | 834 if (cpi->oxcf.encode_breakout > 2000) |
838 min = cpi->oxcf.encode_breakout; | 835 min = cpi->oxcf.encode_breakout; |
839 | 836 |
840 min >>= 7; | 837 min >>= 7; |
841 | 838 |
842 for (i = 0; i < min; i++) | 839 for (i = 0; i < min; i++) |
843 { | 840 { |
844 sum += cpi->error_bins[i]; | 841 sum += cpi->mb.error_bins[i]; |
845 } | 842 } |
846 | 843 |
847 total_skip = sum; | 844 total_skip = sum; |
848 sum = 0; | 845 sum = 0; |
849 | 846 |
850 /* i starts from 2 to make sure thresh started from 2048 */ | 847 /* i starts from 2 to make sure thresh started from 2048 */ |
851 for (; i < 1024; i++) | 848 for (; i < 1024; i++) |
852 { | 849 { |
853 sum += cpi->error_bins[i]; | 850 sum += cpi->mb.error_bins[i]; |
854 | 851 |
855 if (10 * sum >= (unsigned int)(cpi->Speed - 6)*(total_mbs - tota
l_skip)) | 852 if (10 * sum >= (unsigned int)(cpi->Speed - 6)*(total_mbs - tota
l_skip)) |
856 break; | 853 break; |
857 } | 854 } |
858 | 855 |
859 i--; | 856 i--; |
860 thresh = (i << 7); | 857 thresh = (i << 7); |
861 | 858 |
862 if (thresh < 2000) | 859 if (thresh < 2000) |
863 thresh = 2000; | 860 thresh = 2000; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 } | 895 } |
899 else | 896 else |
900 { | 897 { |
901 cm->filter_type = SIMPLE_LOOPFILTER; | 898 cm->filter_type = SIMPLE_LOOPFILTER; |
902 } | 899 } |
903 | 900 |
904 /* This has a big hit on quality. Last resort */ | 901 /* This has a big hit on quality. Last resort */ |
905 if (Speed >= 15) | 902 if (Speed >= 15) |
906 sf->half_pixel_search = 0; | 903 sf->half_pixel_search = 0; |
907 | 904 |
908 vpx_memset(cpi->error_bins, 0, sizeof(cpi->error_bins)); | 905 vpx_memset(cpi->mb.error_bins, 0, sizeof(cpi->mb.error_bins)); |
909 | 906 |
910 }; /* switch */ | 907 }; /* switch */ |
911 | 908 |
912 /* Slow quant, dct and trellis not worthwhile for first pass | 909 /* Slow quant, dct and trellis not worthwhile for first pass |
913 * so make sure they are always turned off. | 910 * so make sure they are always turned off. |
914 */ | 911 */ |
915 if ( cpi->pass == 1 ) | 912 if ( cpi->pass == 1 ) |
916 { | 913 { |
917 sf->improved_quant = 0; | 914 sf->improved_quant = 0; |
918 sf->optimize_coefficients = 0; | 915 sf->optimize_coefficients = 0; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 { | 1070 { |
1074 #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING | 1071 #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
1075 unsigned int tokens = 8 * 24 * 16; /* one MB for each thread */ | 1072 unsigned int tokens = 8 * 24 * 16; /* one MB for each thread */ |
1076 #else | 1073 #else |
1077 unsigned int tokens = cm->mb_rows * cm->mb_cols * 24 * 16; | 1074 unsigned int tokens = cm->mb_rows * cm->mb_cols * 24 * 16; |
1078 #endif | 1075 #endif |
1079 CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); | 1076 CHECK_MEM_ERROR(cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok))); |
1080 } | 1077 } |
1081 | 1078 |
1082 /* Data used for real time vc mode to see if gf needs refreshing */ | 1079 /* Data used for real time vc mode to see if gf needs refreshing */ |
1083 cpi->inter_zz_count = 0; | |
1084 cpi->zeromv_count = 0; | 1080 cpi->zeromv_count = 0; |
1085 cpi->gf_bad_count = 0; | |
1086 cpi->gf_update_recommended = 0; | |
1087 | 1081 |
1088 | 1082 |
1089 /* Structures used to monitor GF usage */ | 1083 /* Structures used to monitor GF usage */ |
1090 vpx_free(cpi->gf_active_flags); | 1084 vpx_free(cpi->gf_active_flags); |
1091 CHECK_MEM_ERROR(cpi->gf_active_flags, | 1085 CHECK_MEM_ERROR(cpi->gf_active_flags, |
1092 vpx_calloc(sizeof(*cpi->gf_active_flags), | 1086 vpx_calloc(sizeof(*cpi->gf_active_flags), |
1093 cm->mb_rows * cm->mb_cols)); | 1087 cm->mb_rows * cm->mb_cols)); |
1094 cpi->gf_active_count = cm->mb_rows * cm->mb_cols; | 1088 cpi->gf_active_count = cm->mb_rows * cm->mb_cols; |
1095 | 1089 |
1096 vpx_free(cpi->mb_activity_map); | 1090 vpx_free(cpi->mb_activity_map); |
1097 CHECK_MEM_ERROR(cpi->mb_activity_map, | 1091 CHECK_MEM_ERROR(cpi->mb_activity_map, |
1098 vpx_calloc(sizeof(*cpi->mb_activity_map), | 1092 vpx_calloc(sizeof(*cpi->mb_activity_map), |
1099 cm->mb_rows * cm->mb_cols)); | 1093 cm->mb_rows * cm->mb_cols)); |
1100 | 1094 |
1101 vpx_free(cpi->mb_norm_activity_map); | |
1102 CHECK_MEM_ERROR(cpi->mb_norm_activity_map, | |
1103 vpx_calloc(sizeof(*cpi->mb_norm_activity_map), | |
1104 cm->mb_rows * cm->mb_cols)); | |
1105 | |
1106 /* allocate memory for storing last frame's MVs for MV prediction. */ | 1095 /* allocate memory for storing last frame's MVs for MV prediction. */ |
1107 vpx_free(cpi->lfmv); | 1096 vpx_free(cpi->lfmv); |
1108 CHECK_MEM_ERROR(cpi->lfmv, vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2), | 1097 CHECK_MEM_ERROR(cpi->lfmv, vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2), |
1109 sizeof(*cpi->lfmv))); | 1098 sizeof(*cpi->lfmv))); |
1110 vpx_free(cpi->lf_ref_frame_sign_bias); | 1099 vpx_free(cpi->lf_ref_frame_sign_bias); |
1111 CHECK_MEM_ERROR(cpi->lf_ref_frame_sign_bias, | 1100 CHECK_MEM_ERROR(cpi->lf_ref_frame_sign_bias, |
1112 vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2), | 1101 vpx_calloc((cm->mb_rows+2) * (cm->mb_cols+2), |
1113 sizeof(*cpi->lf_ref_frame_sign_bias))); | 1102 sizeof(*cpi->lf_ref_frame_sign_bias))); |
1114 vpx_free(cpi->lf_ref_frame); | 1103 vpx_free(cpi->lf_ref_frame); |
1115 CHECK_MEM_ERROR(cpi->lf_ref_frame, | 1104 CHECK_MEM_ERROR(cpi->lf_ref_frame, |
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 { | 1914 { |
1926 cpi->avg_encode_time = 0; | 1915 cpi->avg_encode_time = 0; |
1927 cpi->avg_pick_mode_time = 0; | 1916 cpi->avg_pick_mode_time = 0; |
1928 } | 1917 } |
1929 | 1918 |
1930 vp8_set_speed_features(cpi); | 1919 vp8_set_speed_features(cpi); |
1931 | 1920 |
1932 /* Set starting values of RD threshold multipliers (128 = *1) */ | 1921 /* Set starting values of RD threshold multipliers (128 = *1) */ |
1933 for (i = 0; i < MAX_MODES; i++) | 1922 for (i = 0; i < MAX_MODES; i++) |
1934 { | 1923 { |
1935 cpi->rd_thresh_mult[i] = 128; | 1924 cpi->mb.rd_thresh_mult[i] = 128; |
1936 } | 1925 } |
1937 | 1926 |
1938 #ifdef ENTROPY_STATS | 1927 #ifdef ENTROPY_STATS |
1939 init_mv_ref_counts(); | 1928 init_mv_ref_counts(); |
1940 #endif | 1929 #endif |
1941 | 1930 |
1942 #if CONFIG_MULTITHREAD | 1931 #if CONFIG_MULTITHREAD |
1943 if(vp8cx_create_encoder_threads(cpi)) | 1932 if(vp8cx_create_encoder_threads(cpi)) |
1944 { | 1933 { |
1945 vp8_remove_compressor(&cpi); | 1934 vp8_remove_compressor(&cpi); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2003 cpi->fn_ptr[BLOCK_8X16].copymem = vp8_copy32xn; | 1992 cpi->fn_ptr[BLOCK_8X16].copymem = vp8_copy32xn; |
2004 cpi->fn_ptr[BLOCK_8X8].copymem = vp8_copy32xn; | 1993 cpi->fn_ptr[BLOCK_8X8].copymem = vp8_copy32xn; |
2005 cpi->fn_ptr[BLOCK_4X4].copymem = vp8_copy32xn; | 1994 cpi->fn_ptr[BLOCK_4X4].copymem = vp8_copy32xn; |
2006 #endif | 1995 #endif |
2007 | 1996 |
2008 cpi->full_search_sad = vp8_full_search_sad; | 1997 cpi->full_search_sad = vp8_full_search_sad; |
2009 cpi->diamond_search_sad = vp8_diamond_search_sad; | 1998 cpi->diamond_search_sad = vp8_diamond_search_sad; |
2010 cpi->refining_search_sad = vp8_refining_search_sad; | 1999 cpi->refining_search_sad = vp8_refining_search_sad; |
2011 | 2000 |
2012 /* make sure frame 1 is okay */ | 2001 /* make sure frame 1 is okay */ |
2013 cpi->error_bins[0] = cpi->common.MBs; | 2002 cpi->mb.error_bins[0] = cpi->common.MBs; |
2014 | 2003 |
2015 /* vp8cx_init_quantizer() is first called here. Add check in | 2004 /* vp8cx_init_quantizer() is first called here. Add check in |
2016 * vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only | 2005 * vp8cx_frame_init_quantizer() so that vp8cx_init_quantizer is only |
2017 * called later when needed. This will avoid unnecessary calls of | 2006 * called later when needed. This will avoid unnecessary calls of |
2018 * vp8cx_init_quantizer() for every frame. | 2007 * vp8cx_init_quantizer() for every frame. |
2019 */ | 2008 */ |
2020 vp8cx_init_quantizer(cpi); | 2009 vp8cx_init_quantizer(cpi); |
2021 | 2010 |
2022 vp8_loop_filter_init(cm); | 2011 vp8_loop_filter_init(cm); |
2023 | 2012 |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2592 int tmp_height; | 2581 int tmp_height; |
2593 | 2582 |
2594 if (cm->vert_scale == 3) | 2583 if (cm->vert_scale == 3) |
2595 tmp_height = 9; | 2584 tmp_height = 9; |
2596 else | 2585 else |
2597 tmp_height = 11; | 2586 tmp_height = 11; |
2598 | 2587 |
2599 Scale2Ratio(cm->horiz_scale, &hr, &hs); | 2588 Scale2Ratio(cm->horiz_scale, &hr, &hs); |
2600 Scale2Ratio(cm->vert_scale, &vr, &vs); | 2589 Scale2Ratio(cm->vert_scale, &vr, &vs); |
2601 | 2590 |
2602 vp8_scale_frame(sd, &cpi->scaled_source, cm->temp_scale_frame.y_buffer, | 2591 vpx_scale_frame(sd, &cpi->scaled_source, cm->temp_scale_frame.y_buffer, |
2603 tmp_height, hs, hr, vs, vr, 0); | 2592 tmp_height, hs, hr, vs, vr, 0); |
2604 | 2593 |
2605 vp8_yv12_extend_frame_borders(&cpi->scaled_source); | 2594 vp8_yv12_extend_frame_borders(&cpi->scaled_source); |
2606 cpi->Source = &cpi->scaled_source; | 2595 cpi->Source = &cpi->scaled_source; |
2607 #endif | 2596 #endif |
2608 } | 2597 } |
2609 else | 2598 else |
2610 cpi->Source = sd; | 2599 cpi->Source = sd; |
2611 } | 2600 } |
2612 | 2601 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2776 if (cpi->frames_till_gf_update_due > 0) | 2765 if (cpi->frames_till_gf_update_due > 0) |
2777 cpi->frames_till_gf_update_due--; | 2766 cpi->frames_till_gf_update_due--; |
2778 | 2767 |
2779 if (cpi->common.frames_till_alt_ref_frame) | 2768 if (cpi->common.frames_till_alt_ref_frame) |
2780 cpi->common.frames_till_alt_ref_frame --; | 2769 cpi->common.frames_till_alt_ref_frame --; |
2781 | 2770 |
2782 cpi->common.frames_since_golden ++; | 2771 cpi->common.frames_since_golden ++; |
2783 | 2772 |
2784 if (cpi->common.frames_since_golden > 1) | 2773 if (cpi->common.frames_since_golden > 1) |
2785 { | 2774 { |
2786 cpi->recent_ref_frame_usage[INTRA_FRAME] += cpi->count_mb_ref_frame_
usage[INTRA_FRAME]; | 2775 cpi->recent_ref_frame_usage[INTRA_FRAME] += |
2787 cpi->recent_ref_frame_usage[LAST_FRAME] += cpi->count_mb_ref_frame_u
sage[LAST_FRAME]; | 2776 cpi->mb.count_mb_ref_frame_usage[INTRA_FRAME]; |
2788 cpi->recent_ref_frame_usage[GOLDEN_FRAME] += cpi->count_mb_ref_frame
_usage[GOLDEN_FRAME]; | 2777 cpi->recent_ref_frame_usage[LAST_FRAME] += |
2789 cpi->recent_ref_frame_usage[ALTREF_FRAME] += cpi->count_mb_ref_frame
_usage[ALTREF_FRAME]; | 2778 cpi->mb.count_mb_ref_frame_usage[LAST_FRAME]; |
| 2779 cpi->recent_ref_frame_usage[GOLDEN_FRAME] += |
| 2780 cpi->mb.count_mb_ref_frame_usage[GOLDEN_FRAME]; |
| 2781 cpi->recent_ref_frame_usage[ALTREF_FRAME] += |
| 2782 cpi->mb.count_mb_ref_frame_usage[ALTREF_FRAME]; |
2790 } | 2783 } |
2791 } | 2784 } |
2792 } | 2785 } |
2793 | 2786 |
2794 /* This function updates the reference frame probability estimates that | 2787 /* This function updates the reference frame probability estimates that |
2795 * will be used during mode selection | 2788 * will be used during mode selection |
2796 */ | 2789 */ |
2797 static void update_rd_ref_frame_probs(VP8_COMP *cpi) | 2790 static void update_rd_ref_frame_probs(VP8_COMP *cpi) |
2798 { | 2791 { |
2799 VP8_COMMON *cm = &cpi->common; | 2792 VP8_COMMON *cm = &cpi->common; |
2800 | 2793 |
2801 const int *const rfct = cpi->count_mb_ref_frame_usage; | 2794 const int *const rfct = cpi->mb.count_mb_ref_frame_usage; |
2802 const int rf_intra = rfct[INTRA_FRAME]; | 2795 const int rf_intra = rfct[INTRA_FRAME]; |
2803 const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRA
ME]; | 2796 const int rf_inter = rfct[LAST_FRAME] + rfct[GOLDEN_FRAME] + rfct[ALTREF_FRA
ME]; |
2804 | 2797 |
2805 if (cm->frame_type == KEY_FRAME) | 2798 if (cm->frame_type == KEY_FRAME) |
2806 { | 2799 { |
2807 cpi->prob_intra_coded = 255; | 2800 cpi->prob_intra_coded = 255; |
2808 cpi->prob_last_coded = 128; | 2801 cpi->prob_last_coded = 128; |
2809 cpi->prob_gf_coded = 128; | 2802 cpi->prob_gf_coded = 128; |
2810 } | 2803 } |
2811 else if (!(rf_intra + rf_inter)) | 2804 else if (!(rf_intra + rf_inter)) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2858 cpi->kf_boost = 0; | 2851 cpi->kf_boost = 0; |
2859 | 2852 |
2860 if (cpi->Speed > 11) | 2853 if (cpi->Speed > 11) |
2861 return 0; | 2854 return 0; |
2862 | 2855 |
2863 /* Clear down mmx registers */ | 2856 /* Clear down mmx registers */ |
2864 vp8_clear_system_state(); | 2857 vp8_clear_system_state(); |
2865 | 2858 |
2866 if ((cpi->compressor_speed == 2) && (cpi->Speed >= 5) && (cpi->sf.RD == 0)) | 2859 if ((cpi->compressor_speed == 2) && (cpi->Speed >= 5) && (cpi->sf.RD == 0)) |
2867 { | 2860 { |
2868 double change = 1.0 * abs((int)(cpi->intra_error - cpi->last_intra_error
)) / (1 + cpi->last_intra_error); | 2861 double change = 1.0 * abs((int)(cpi->mb.intra_error - |
2869 double change2 = 1.0 * abs((int)(cpi->prediction_error - cpi->last_predi
ction_error)) / (1 + cpi->last_prediction_error); | 2862 cpi->last_intra_error)) / (1 + cpi->last_intra_error); |
| 2863 double change2 = 1.0 * abs((int)(cpi->mb.prediction_error - |
| 2864 cpi->last_prediction_error)) / (1 + cpi->last_prediction_error); |
2870 double minerror = cm->MBs * 256; | 2865 double minerror = cm->MBs * 256; |
2871 | 2866 |
2872 #if 0 | 2867 cpi->last_intra_error = cpi->mb.intra_error; |
| 2868 cpi->last_prediction_error = cpi->mb.prediction_error; |
2873 | 2869 |
2874 if (10 * cpi->intra_error / (1 + cpi->prediction_error) < 15 | 2870 if (10 * cpi->mb.intra_error / (1 + cpi->mb.prediction_error) < 15 |
2875 && cpi->prediction_error > minerror | 2871 && cpi->mb.prediction_error > minerror |
2876 && (change > .25 || change2 > .25)) | |
2877 { | |
2878 FILE *f = fopen("intra_inter.stt", "a"); | |
2879 | |
2880 if (cpi->prediction_error <= 0) | |
2881 cpi->prediction_error = 1; | |
2882 | |
2883 fprintf(f, "%d %d %d %d %14.4f\n", | |
2884 cm->current_video_frame, | |
2885 (int) cpi->prediction_error, | |
2886 (int) cpi->intra_error, | |
2887 (int)((10 * cpi->intra_error) / cpi->prediction_error), | |
2888 change); | |
2889 | |
2890 fclose(f); | |
2891 } | |
2892 | |
2893 #endif | |
2894 | |
2895 cpi->last_intra_error = cpi->intra_error; | |
2896 cpi->last_prediction_error = cpi->prediction_error; | |
2897 | |
2898 if (10 * cpi->intra_error / (1 + cpi->prediction_error) < 15 | |
2899 && cpi->prediction_error > minerror | |
2900 && (change > .25 || change2 > .25)) | 2872 && (change > .25 || change2 > .25)) |
2901 { | 2873 { |
2902 /*(change > 1.4 || change < .75)&& cpi->this_frame_percent_intra > c
pi->last_frame_percent_intra + 3*/ | 2874 /*(change > 1.4 || change < .75)&& cpi->this_frame_percent_intra > c
pi->last_frame_percent_intra + 3*/ |
2903 return 1; | 2875 return 1; |
2904 } | 2876 } |
2905 | 2877 |
2906 return 0; | 2878 return 0; |
2907 | 2879 |
2908 } | 2880 } |
2909 | 2881 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3153 if (cm->refresh_last_frame) | 3125 if (cm->refresh_last_frame) |
3154 { | 3126 { |
3155 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_LAST_FRAME; | 3127 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_LAST_FRAME; |
3156 cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FRAME; | 3128 cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FRAME; |
3157 cm->lst_fb_idx = cm->new_fb_idx; | 3129 cm->lst_fb_idx = cm->new_fb_idx; |
3158 | 3130 |
3159 #if CONFIG_MULTI_RES_ENCODING | 3131 #if CONFIG_MULTI_RES_ENCODING |
3160 cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame; | 3132 cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame; |
3161 #endif | 3133 #endif |
3162 } | 3134 } |
| 3135 |
| 3136 #if CONFIG_TEMPORAL_DENOISING |
| 3137 if (cpi->oxcf.noise_sensitivity) |
| 3138 { |
| 3139 /* we shouldn't have to keep multiple copies as we know in advance which |
| 3140 * buffer we should start - for now to get something up and running |
| 3141 * I've chosen to copy the buffers |
| 3142 */ |
| 3143 if (cm->frame_type == KEY_FRAME) |
| 3144 { |
| 3145 int i; |
| 3146 vp8_yv12_copy_frame( |
| 3147 cpi->Source, |
| 3148 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); |
| 3149 |
| 3150 vp8_yv12_extend_frame_borders( |
| 3151 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); |
| 3152 |
| 3153 for (i = 2; i < MAX_REF_FRAMES - 1; i++) |
| 3154 vp8_yv12_copy_frame( |
| 3155 &cpi->denoiser.yv12_running_avg[LAST_FRAME], |
| 3156 &cpi->denoiser.yv12_running_avg[i]); |
| 3157 } |
| 3158 else /* For non key frames */ |
| 3159 { |
| 3160 vp8_yv12_extend_frame_borders( |
| 3161 &cpi->denoiser.yv12_running_avg[INTRA_FRAME]); |
| 3162 |
| 3163 if (cm->refresh_alt_ref_frame || cm->copy_buffer_to_arf) |
| 3164 { |
| 3165 vp8_yv12_copy_frame( |
| 3166 &cpi->denoiser.yv12_running_avg[INTRA_FRAME], |
| 3167 &cpi->denoiser.yv12_running_avg[ALTREF_FRAME]); |
| 3168 } |
| 3169 if (cm->refresh_golden_frame || cm->copy_buffer_to_gf) |
| 3170 { |
| 3171 vp8_yv12_copy_frame( |
| 3172 &cpi->denoiser.yv12_running_avg[INTRA_FRAME], |
| 3173 &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]); |
| 3174 } |
| 3175 if(cm->refresh_last_frame) |
| 3176 { |
| 3177 vp8_yv12_copy_frame( |
| 3178 &cpi->denoiser.yv12_running_avg[INTRA_FRAME], |
| 3179 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); |
| 3180 } |
| 3181 } |
| 3182 |
| 3183 } |
| 3184 #endif |
| 3185 |
3163 } | 3186 } |
3164 | 3187 |
3165 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) | 3188 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) |
3166 { | 3189 { |
3167 const FRAME_TYPE frame_type = cm->frame_type; | 3190 const FRAME_TYPE frame_type = cm->frame_type; |
3168 | 3191 |
3169 if (cm->no_lpf) | 3192 if (cm->no_lpf) |
3170 { | 3193 { |
3171 cm->filter_level = 0; | 3194 cm->filter_level = 0; |
3172 } | 3195 } |
(...skipping 23 matching lines...) Expand all Loading... |
3196 if (cpi->b_multi_threaded) | 3219 if (cpi->b_multi_threaded) |
3197 sem_post(&cpi->h_event_end_lpf); /* signal that we have set filter_level
*/ | 3220 sem_post(&cpi->h_event_end_lpf); /* signal that we have set filter_level
*/ |
3198 #endif | 3221 #endif |
3199 | 3222 |
3200 if (cm->filter_level > 0) | 3223 if (cm->filter_level > 0) |
3201 { | 3224 { |
3202 vp8_loop_filter_frame(cm, &cpi->mb.e_mbd, frame_type); | 3225 vp8_loop_filter_frame(cm, &cpi->mb.e_mbd, frame_type); |
3203 } | 3226 } |
3204 | 3227 |
3205 vp8_yv12_extend_frame_borders(cm->frame_to_show); | 3228 vp8_yv12_extend_frame_borders(cm->frame_to_show); |
3206 #if CONFIG_TEMPORAL_DENOISING | |
3207 if (cpi->oxcf.noise_sensitivity) | |
3208 { | |
3209 | |
3210 | |
3211 /* we shouldn't have to keep multiple copies as we know in advance which | |
3212 * buffer we should start - for now to get something up and running | |
3213 * I've chosen to copy the buffers | |
3214 */ | |
3215 if (cm->frame_type == KEY_FRAME) | |
3216 { | |
3217 int i; | |
3218 vp8_yv12_copy_frame( | |
3219 cpi->Source, | |
3220 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); | |
3221 | |
3222 vp8_yv12_extend_frame_borders( | |
3223 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); | |
3224 | |
3225 for (i = 2; i < MAX_REF_FRAMES - 1; i++) | |
3226 vp8_yv12_copy_frame( | |
3227 cpi->Source, | |
3228 &cpi->denoiser.yv12_running_avg[i]); | |
3229 } | |
3230 else /* For non key frames */ | |
3231 { | |
3232 vp8_yv12_extend_frame_borders( | |
3233 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); | |
3234 | |
3235 if (cm->refresh_alt_ref_frame || cm->copy_buffer_to_arf) | |
3236 { | |
3237 vp8_yv12_copy_frame( | |
3238 &cpi->denoiser.yv12_running_avg[LAST_FRAME], | |
3239 &cpi->denoiser.yv12_running_avg[ALTREF_FRAME]); | |
3240 } | |
3241 if (cm->refresh_golden_frame || cm->copy_buffer_to_gf) | |
3242 { | |
3243 vp8_yv12_copy_frame( | |
3244 &cpi->denoiser.yv12_running_avg[LAST_FRAME], | |
3245 &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]); | |
3246 } | |
3247 } | |
3248 | |
3249 } | |
3250 #endif | |
3251 | 3229 |
3252 } | 3230 } |
3253 | 3231 |
3254 static void encode_frame_to_data_rate | 3232 static void encode_frame_to_data_rate |
3255 ( | 3233 ( |
3256 VP8_COMP *cpi, | 3234 VP8_COMP *cpi, |
3257 unsigned long *size, | 3235 unsigned long *size, |
3258 unsigned char *dest, | 3236 unsigned char *dest, |
3259 unsigned char* dest_end, | 3237 unsigned char* dest_end, |
3260 unsigned int *frame_flags | 3238 unsigned int *frame_flags |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3324 } | 3302 } |
3325 else | 3303 else |
3326 #endif | 3304 #endif |
3327 cpi->per_frame_bandwidth = (int)(cpi->target_bandwidth / cpi->output_fr
ame_rate); | 3305 cpi->per_frame_bandwidth = (int)(cpi->target_bandwidth / cpi->output_fr
ame_rate); |
3328 | 3306 |
3329 /* Default turn off buffer to buffer copying */ | 3307 /* Default turn off buffer to buffer copying */ |
3330 cm->copy_buffer_to_gf = 0; | 3308 cm->copy_buffer_to_gf = 0; |
3331 cm->copy_buffer_to_arf = 0; | 3309 cm->copy_buffer_to_arf = 0; |
3332 | 3310 |
3333 /* Clear zbin over-quant value and mode boost values. */ | 3311 /* Clear zbin over-quant value and mode boost values. */ |
3334 cpi->zbin_over_quant = 0; | 3312 cpi->mb.zbin_over_quant = 0; |
3335 cpi->zbin_mode_boost = 0; | 3313 cpi->mb.zbin_mode_boost = 0; |
3336 | 3314 |
3337 /* Enable or disable mode based tweaking of the zbin | 3315 /* Enable or disable mode based tweaking of the zbin |
3338 * For 2 Pass Only used where GF/ARF prediction quality | 3316 * For 2 Pass Only used where GF/ARF prediction quality |
3339 * is above a threshold | 3317 * is above a threshold |
3340 */ | 3318 */ |
3341 cpi->zbin_mode_boost_enabled = 1; | 3319 cpi->mb.zbin_mode_boost_enabled = 1; |
3342 if (cpi->pass == 2) | 3320 if (cpi->pass == 2) |
3343 { | 3321 { |
3344 if ( cpi->gfu_boost <= 400 ) | 3322 if ( cpi->gfu_boost <= 400 ) |
3345 { | 3323 { |
3346 cpi->zbin_mode_boost_enabled = 0; | 3324 cpi->mb.zbin_mode_boost_enabled = 0; |
3347 } | 3325 } |
3348 } | 3326 } |
3349 | 3327 |
3350 /* Current default encoder behaviour for the altref sign bias */ | 3328 /* Current default encoder behaviour for the altref sign bias */ |
3351 if (cpi->source_alt_ref_active) | 3329 if (cpi->source_alt_ref_active) |
3352 cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1; | 3330 cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 1; |
3353 else | 3331 else |
3354 cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 0; | 3332 cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = 0; |
3355 | 3333 |
3356 /* Check to see if a key frame is signalled | 3334 /* Check to see if a key frame is signalled |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3403 | 3381 |
3404 // Set the loop filter deltas and segmentation map update | 3382 // Set the loop filter deltas and segmentation map update |
3405 setup_features(cpi); | 3383 setup_features(cpi); |
3406 | 3384 |
3407 /* The alternate reference frame cannot be active for a key frame */ | 3385 /* The alternate reference frame cannot be active for a key frame */ |
3408 cpi->source_alt_ref_active = 0; | 3386 cpi->source_alt_ref_active = 0; |
3409 | 3387 |
3410 /* Reset the RD threshold multipliers to default of * 1 (128) */ | 3388 /* Reset the RD threshold multipliers to default of * 1 (128) */ |
3411 for (i = 0; i < MAX_MODES; i++) | 3389 for (i = 0; i < MAX_MODES; i++) |
3412 { | 3390 { |
3413 cpi->rd_thresh_mult[i] = 128; | 3391 cpi->mb.rd_thresh_mult[i] = 128; |
3414 } | 3392 } |
3415 } | 3393 } |
3416 | 3394 |
3417 #if 0 | 3395 #if 0 |
3418 /* Experimental code for lagged compress and one pass | 3396 /* Experimental code for lagged compress and one pass |
3419 * Initialise one_pass GF frames stats | 3397 * Initialise one_pass GF frames stats |
3420 * Update stats used for GF selection | 3398 * Update stats used for GF selection |
3421 */ | 3399 */ |
3422 { | 3400 { |
3423 cpi->one_pass_frame_index = cm->current_video_frame % MAX_LAG_BUFFERS; | 3401 cpi->one_pass_frame_index = cm->current_video_frame % MAX_LAG_BUFFERS; |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4092 * & compute new Q to try... | 4070 * & compute new Q to try... |
4093 */ | 4071 */ |
4094 | 4072 |
4095 /* Frame is too large */ | 4073 /* Frame is too large */ |
4096 if (cpi->projected_frame_size > cpi->this_frame_target) | 4074 if (cpi->projected_frame_size > cpi->this_frame_target) |
4097 { | 4075 { |
4098 /* Raise Qlow as to at least the current value */ | 4076 /* Raise Qlow as to at least the current value */ |
4099 q_low = (Q < q_high) ? (Q + 1) : q_high; | 4077 q_low = (Q < q_high) ? (Q + 1) : q_high; |
4100 | 4078 |
4101 /* If we are using over quant do the same for zbin_oq_low */ | 4079 /* If we are using over quant do the same for zbin_oq_low */ |
4102 if (cpi->zbin_over_quant > 0) | 4080 if (cpi->mb.zbin_over_quant > 0) |
4103 zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (cpi->
zbin_over_quant + 1) : zbin_oq_high; | 4081 zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ? |
| 4082 (cpi->mb.zbin_over_quant + 1) : zbin_oq_high; |
4104 | 4083 |
4105 if (undershoot_seen) | 4084 if (undershoot_seen) |
4106 { | 4085 { |
4107 /* Update rate_correction_factor unless | 4086 /* Update rate_correction_factor unless |
4108 * cpi->active_worst_quality has changed. | 4087 * cpi->active_worst_quality has changed. |
4109 */ | 4088 */ |
4110 if (!active_worst_qchanged) | 4089 if (!active_worst_qchanged) |
4111 vp8_update_rate_correction_factors(cpi, 1); | 4090 vp8_update_rate_correction_factors(cpi, 1); |
4112 | 4091 |
4113 Q = (q_high + q_low + 1) / 2; | 4092 Q = (q_high + q_low + 1) / 2; |
4114 | 4093 |
4115 /* Adjust cpi->zbin_over_quant (only allowed when Q | 4094 /* Adjust cpi->zbin_over_quant (only allowed when Q |
4116 * is max) | 4095 * is max) |
4117 */ | 4096 */ |
4118 if (Q < MAXQ) | 4097 if (Q < MAXQ) |
4119 cpi->zbin_over_quant = 0; | 4098 cpi->mb.zbin_over_quant = 0; |
4120 else | 4099 else |
4121 { | 4100 { |
4122 zbin_oq_low = (cpi->zbin_over_quant < zbin_oq_high) ? (c
pi->zbin_over_quant + 1) : zbin_oq_high; | 4101 zbin_oq_low = (cpi->mb.zbin_over_quant < zbin_oq_high) ? |
4123 cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2; | 4102 (cpi->mb.zbin_over_quant + 1) : zbin_oq_high; |
| 4103 cpi->mb.zbin_over_quant = |
| 4104 (zbin_oq_high + zbin_oq_low) / 2; |
4124 } | 4105 } |
4125 } | 4106 } |
4126 else | 4107 else |
4127 { | 4108 { |
4128 /* Update rate_correction_factor unless | 4109 /* Update rate_correction_factor unless |
4129 * cpi->active_worst_quality has changed. | 4110 * cpi->active_worst_quality has changed. |
4130 */ | 4111 */ |
4131 if (!active_worst_qchanged) | 4112 if (!active_worst_qchanged) |
4132 vp8_update_rate_correction_factors(cpi, 0); | 4113 vp8_update_rate_correction_factors(cpi, 0); |
4133 | 4114 |
4134 Q = vp8_regulate_q(cpi, cpi->this_frame_target); | 4115 Q = vp8_regulate_q(cpi, cpi->this_frame_target); |
4135 | 4116 |
4136 while (((Q < q_low) || (cpi->zbin_over_quant < zbin_oq_low))
&& (Retries < 10)) | 4117 while (((Q < q_low) || |
| 4118 (cpi->mb.zbin_over_quant < zbin_oq_low)) && |
| 4119 (Retries < 10)) |
4137 { | 4120 { |
4138 vp8_update_rate_correction_factors(cpi, 0); | 4121 vp8_update_rate_correction_factors(cpi, 0); |
4139 Q = vp8_regulate_q(cpi, cpi->this_frame_target); | 4122 Q = vp8_regulate_q(cpi, cpi->this_frame_target); |
4140 Retries ++; | 4123 Retries ++; |
4141 } | 4124 } |
4142 } | 4125 } |
4143 | 4126 |
4144 overshoot_seen = 1; | 4127 overshoot_seen = 1; |
4145 } | 4128 } |
4146 /* Frame is too small */ | 4129 /* Frame is too small */ |
4147 else | 4130 else |
4148 { | 4131 { |
4149 if (cpi->zbin_over_quant == 0) | 4132 if (cpi->mb.zbin_over_quant == 0) |
4150 /* Lower q_high if not using over quant */ | 4133 /* Lower q_high if not using over quant */ |
4151 q_high = (Q > q_low) ? (Q - 1) : q_low; | 4134 q_high = (Q > q_low) ? (Q - 1) : q_low; |
4152 else | 4135 else |
4153 /* else lower zbin_oq_high */ | 4136 /* else lower zbin_oq_high */ |
4154 zbin_oq_high = (cpi->zbin_over_quant > zbin_oq_low) ? (cpi->
zbin_over_quant - 1) : zbin_oq_low; | 4137 zbin_oq_high = (cpi->mb.zbin_over_quant > zbin_oq_low) ? |
| 4138 (cpi->mb.zbin_over_quant - 1) : zbin_oq_low; |
4155 | 4139 |
4156 if (overshoot_seen) | 4140 if (overshoot_seen) |
4157 { | 4141 { |
4158 /* Update rate_correction_factor unless | 4142 /* Update rate_correction_factor unless |
4159 * cpi->active_worst_quality has changed. | 4143 * cpi->active_worst_quality has changed. |
4160 */ | 4144 */ |
4161 if (!active_worst_qchanged) | 4145 if (!active_worst_qchanged) |
4162 vp8_update_rate_correction_factors(cpi, 1); | 4146 vp8_update_rate_correction_factors(cpi, 1); |
4163 | 4147 |
4164 Q = (q_high + q_low) / 2; | 4148 Q = (q_high + q_low) / 2; |
4165 | 4149 |
4166 /* Adjust cpi->zbin_over_quant (only allowed when Q | 4150 /* Adjust cpi->zbin_over_quant (only allowed when Q |
4167 * is max) | 4151 * is max) |
4168 */ | 4152 */ |
4169 if (Q < MAXQ) | 4153 if (Q < MAXQ) |
4170 cpi->zbin_over_quant = 0; | 4154 cpi->mb.zbin_over_quant = 0; |
4171 else | 4155 else |
4172 cpi->zbin_over_quant = (zbin_oq_high + zbin_oq_low) / 2; | 4156 cpi->mb.zbin_over_quant = |
| 4157 (zbin_oq_high + zbin_oq_low) / 2; |
4173 } | 4158 } |
4174 else | 4159 else |
4175 { | 4160 { |
4176 /* Update rate_correction_factor unless | 4161 /* Update rate_correction_factor unless |
4177 * cpi->active_worst_quality has changed. | 4162 * cpi->active_worst_quality has changed. |
4178 */ | 4163 */ |
4179 if (!active_worst_qchanged) | 4164 if (!active_worst_qchanged) |
4180 vp8_update_rate_correction_factors(cpi, 0); | 4165 vp8_update_rate_correction_factors(cpi, 0); |
4181 | 4166 |
4182 Q = vp8_regulate_q(cpi, cpi->this_frame_target); | 4167 Q = vp8_regulate_q(cpi, cpi->this_frame_target); |
4183 | 4168 |
4184 /* Special case reset for qlow for constrained quality. | 4169 /* Special case reset for qlow for constrained quality. |
4185 * This should only trigger where there is very substantial | 4170 * This should only trigger where there is very substantial |
4186 * undershoot on a frame and the auto cq level is above | 4171 * undershoot on a frame and the auto cq level is above |
4187 * the user passsed in value. | 4172 * the user passsed in value. |
4188 */ | 4173 */ |
4189 if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) && | 4174 if ( (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) && |
4190 (Q < q_low) ) | 4175 (Q < q_low) ) |
4191 { | 4176 { |
4192 q_low = Q; | 4177 q_low = Q; |
4193 } | 4178 } |
4194 | 4179 |
4195 while (((Q > q_high) || (cpi->zbin_over_quant > zbin_oq_high
)) && (Retries < 10)) | 4180 while (((Q > q_high) || |
| 4181 (cpi->mb.zbin_over_quant > zbin_oq_high)) && |
| 4182 (Retries < 10)) |
4196 { | 4183 { |
4197 vp8_update_rate_correction_factors(cpi, 0); | 4184 vp8_update_rate_correction_factors(cpi, 0); |
4198 Q = vp8_regulate_q(cpi, cpi->this_frame_target); | 4185 Q = vp8_regulate_q(cpi, cpi->this_frame_target); |
4199 Retries ++; | 4186 Retries ++; |
4200 } | 4187 } |
4201 } | 4188 } |
4202 | 4189 |
4203 undershoot_seen = 1; | 4190 undershoot_seen = 1; |
4204 } | 4191 } |
4205 | 4192 |
4206 /* Clamp Q to upper and lower limits: */ | 4193 /* Clamp Q to upper and lower limits: */ |
4207 if (Q > q_high) | 4194 if (Q > q_high) |
4208 Q = q_high; | 4195 Q = q_high; |
4209 else if (Q < q_low) | 4196 else if (Q < q_low) |
4210 Q = q_low; | 4197 Q = q_low; |
4211 | 4198 |
4212 /* Clamp cpi->zbin_over_quant */ | 4199 /* Clamp cpi->zbin_over_quant */ |
4213 cpi->zbin_over_quant = (cpi->zbin_over_quant < zbin_oq_low) ? zbin_o
q_low : (cpi->zbin_over_quant > zbin_oq_high) ? zbin_oq_high : cpi->zbin_over_qu
ant; | 4200 cpi->mb.zbin_over_quant = (cpi->mb.zbin_over_quant < zbin_oq_low) ? |
| 4201 zbin_oq_low : (cpi->mb.zbin_over_quant > zbin_oq_high) ? |
| 4202 zbin_oq_high : cpi->mb.zbin_over_quant; |
4214 | 4203 |
4215 Loop = Q != last_q; | 4204 Loop = Q != last_q; |
4216 } | 4205 } |
4217 else | 4206 else |
4218 #endif | 4207 #endif |
4219 Loop = 0; | 4208 Loop = 0; |
4220 | 4209 |
4221 if (cpi->is_src_frame_alt_ref) | 4210 if (cpi->is_src_frame_alt_ref) |
4222 Loop = 0; | 4211 Loop = 0; |
4223 | 4212 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4285 } | 4274 } |
4286 } | 4275 } |
4287 | 4276 |
4288 /* Count last ref frame 0,0 usage on current encoded frame. */ | 4277 /* Count last ref frame 0,0 usage on current encoded frame. */ |
4289 { | 4278 { |
4290 int mb_row; | 4279 int mb_row; |
4291 int mb_col; | 4280 int mb_col; |
4292 /* Point to beginning of MODE_INFO arrays. */ | 4281 /* Point to beginning of MODE_INFO arrays. */ |
4293 MODE_INFO *tmp = cm->mi; | 4282 MODE_INFO *tmp = cm->mi; |
4294 | 4283 |
4295 cpi->inter_zz_count = 0; | |
4296 cpi->zeromv_count = 0; | 4284 cpi->zeromv_count = 0; |
4297 | 4285 |
4298 if(cm->frame_type != KEY_FRAME) | 4286 if(cm->frame_type != KEY_FRAME) |
4299 { | 4287 { |
4300 for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++) | 4288 for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++) |
4301 { | 4289 { |
4302 for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++) | 4290 for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++) |
4303 { | 4291 { |
4304 if(tmp->mbmi.mode == ZEROMV && tmp->mbmi.ref_frame == LAST_F
RAME) | |
4305 cpi->inter_zz_count++; | |
4306 if(tmp->mbmi.mode == ZEROMV) | 4292 if(tmp->mbmi.mode == ZEROMV) |
4307 cpi->zeromv_count++; | 4293 cpi->zeromv_count++; |
4308 tmp++; | 4294 tmp++; |
4309 } | 4295 } |
4310 tmp++; | 4296 tmp++; |
4311 } | 4297 } |
4312 } | 4298 } |
4313 } | 4299 } |
4314 | 4300 |
4315 #if CONFIG_MULTI_RES_ENCODING | 4301 #if CONFIG_MULTI_RES_ENCODING |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4725 cm->yv12_fb[cm->lst_fb_idx].frame_size, 1, recon_file); | 4711 cm->yv12_fb[cm->lst_fb_idx].frame_size, 1, recon_file); |
4726 fclose(recon_file); | 4712 fclose(recon_file); |
4727 } | 4713 } |
4728 #endif | 4714 #endif |
4729 | 4715 |
4730 /* DEBUG */ | 4716 /* DEBUG */ |
4731 /* vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show); */ | 4717 /* vp8_write_yuv_frame("encoder_recon.yuv", cm->frame_to_show); */ |
4732 | 4718 |
4733 | 4719 |
4734 } | 4720 } |
4735 | |
4736 | |
4737 static void check_gf_quality(VP8_COMP *cpi) | |
4738 { | |
4739 VP8_COMMON *cm = &cpi->common; | |
4740 int gf_active_pct = (100 * cpi->gf_active_count) / (cm->mb_rows * cm->mb_col
s); | |
4741 int gf_ref_usage_pct = (cpi->count_mb_ref_frame_usage[GOLDEN_FRAME] * 100) /
(cm->mb_rows * cm->mb_cols); | |
4742 int last_ref_zz_useage = (cpi->inter_zz_count * 100) / (cm->mb_rows * cm->mb
_cols); | |
4743 | |
4744 /* Gf refresh is not currently being signalled */ | |
4745 if (cpi->gf_update_recommended == 0) | |
4746 { | |
4747 if (cpi->common.frames_since_golden > 7) | |
4748 { | |
4749 /* Low use of gf */ | |
4750 if ((gf_active_pct < 10) || ((gf_active_pct + gf_ref_usage_pct) < 15
)) | |
4751 { | |
4752 /* ...but last frame zero zero usage is reasonbable so a | |
4753 * new gf might be appropriate | |
4754 */ | |
4755 if (last_ref_zz_useage >= 25) | |
4756 { | |
4757 cpi->gf_bad_count ++; | |
4758 | |
4759 /* Check that the condition is stable */ | |
4760 if (cpi->gf_bad_count >= 8) | |
4761 { | |
4762 cpi->gf_update_recommended = 1; | |
4763 cpi->gf_bad_count = 0; | |
4764 } | |
4765 } | |
4766 else | |
4767 /* Restart count as the background is not stable enough */ | |
4768 cpi->gf_bad_count = 0; | |
4769 } | |
4770 else | |
4771 /* Gf useage has picked up so reset count */ | |
4772 cpi->gf_bad_count = 0; | |
4773 } | |
4774 } | |
4775 /* If the signal is set but has not been read should we cancel it. */ | |
4776 else if (last_ref_zz_useage < 15) | |
4777 { | |
4778 cpi->gf_update_recommended = 0; | |
4779 cpi->gf_bad_count = 0; | |
4780 } | |
4781 | |
4782 #if 0 | |
4783 { | |
4784 FILE *f = fopen("gfneeded.stt", "a"); | |
4785 fprintf(f, "%10d %10d %10d %10d %10ld \n", | |
4786 cm->current_video_frame, | |
4787 cpi->common.frames_since_golden, | |
4788 gf_active_pct, gf_ref_usage_pct, | |
4789 cpi->gf_update_recommended); | |
4790 fclose(f); | |
4791 } | |
4792 | |
4793 #endif | |
4794 } | |
4795 | |
4796 #if !(CONFIG_REALTIME_ONLY) | 4721 #if !(CONFIG_REALTIME_ONLY) |
4797 static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest,
unsigned char * dest_end, unsigned int *frame_flags) | 4722 static void Pass2Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest,
unsigned char * dest_end, unsigned int *frame_flags) |
4798 { | 4723 { |
4799 | 4724 |
4800 if (!cpi->common.refresh_alt_ref_frame) | 4725 if (!cpi->common.refresh_alt_ref_frame) |
4801 vp8_second_pass(cpi); | 4726 vp8_second_pass(cpi); |
4802 | 4727 |
4803 encode_frame_to_data_rate(cpi, size, dest, dest_end, frame_flags); | 4728 encode_frame_to_data_rate(cpi, size, dest, dest_end, frame_flags); |
4804 cpi->twopass.bits_left -= 8 * *size; | 4729 cpi->twopass.bits_left -= 8 * *size; |
4805 | 4730 |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5089 | 5014 |
5090 /* Restore layer specific context & set frame rate */ | 5015 /* Restore layer specific context & set frame rate */ |
5091 layer = cpi->oxcf.layer_id[ | 5016 layer = cpi->oxcf.layer_id[ |
5092 cm->current_video_frame % cpi->oxcf.periodicity]; | 5017 cm->current_video_frame % cpi->oxcf.periodicity]; |
5093 restore_layer_context (cpi, layer); | 5018 restore_layer_context (cpi, layer); |
5094 vp8_new_frame_rate (cpi, cpi->layer_context[layer].frame_rate); | 5019 vp8_new_frame_rate (cpi, cpi->layer_context[layer].frame_rate); |
5095 } | 5020 } |
5096 | 5021 |
5097 if (cpi->compressor_speed == 2) | 5022 if (cpi->compressor_speed == 2) |
5098 { | 5023 { |
5099 if (cpi->oxcf.number_of_layers == 1) | |
5100 check_gf_quality(cpi); | |
5101 vpx_usec_timer_start(&tsctimer); | 5024 vpx_usec_timer_start(&tsctimer); |
5102 vpx_usec_timer_start(&ticktimer); | 5025 vpx_usec_timer_start(&ticktimer); |
5103 } | 5026 } |
5104 | 5027 |
5105 cpi->lf_zeromv_pct = (cpi->zeromv_count * 100)/cm->MBs; | 5028 cpi->lf_zeromv_pct = (cpi->zeromv_count * 100)/cm->MBs; |
5106 | 5029 |
5107 #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING | 5030 #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING |
5108 { | 5031 { |
5109 int i; | 5032 int i; |
5110 const int num_part = (1 << cm->multi_token_partition); | 5033 const int num_part = (1 << cm->multi_token_partition); |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5588 } | 5511 } |
5589 | 5512 |
5590 return Total; | 5513 return Total; |
5591 } | 5514 } |
5592 | 5515 |
5593 | 5516 |
5594 int vp8_get_quantizer(VP8_COMP *cpi) | 5517 int vp8_get_quantizer(VP8_COMP *cpi) |
5595 { | 5518 { |
5596 return cpi->common.base_qindex; | 5519 return cpi->common.base_qindex; |
5597 } | 5520 } |
OLD | NEW |