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

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

Issue 478033002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp8/encoder/ethreading.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
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 cpi->cyclic_refresh_map[i]++; 606 cpi->cyclic_refresh_map[i]++;
607 607
608 i++; 608 i++;
609 if (i == mbs_in_frame) 609 if (i == mbs_in_frame)
610 i = 0; 610 i = 0;
611 611
612 } 612 }
613 while(block_count && i != cpi->cyclic_refresh_mode_index); 613 while(block_count && i != cpi->cyclic_refresh_mode_index);
614 614
615 cpi->cyclic_refresh_mode_index = i; 615 cpi->cyclic_refresh_mode_index = i;
616
617 #if CONFIG_TEMPORAL_DENOISING
618 if (cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive &&
619 Q < (int)cpi->denoiser.denoise_pars.qp_thresh) {
620 // Under aggressive denoising mode, use segmentation to turn off loop
621 // filter below some qp thresh. The loop filter is turned off for all
622 // blocks that have been encoded as ZEROMV LAST x frames in a row,
623 // where x is set by cpi->denoiser.denoise_pars.consec_zerolast.
624 // This is to avoid "dot" artifacts that can occur from repeated
625 // loop filtering on noisy input source.
626 cpi->cyclic_refresh_q = Q;
627 lf_adjustment = -MAX_LOOP_FILTER;
628 for (i = 0; i < mbs_in_frame; ++i) {
629 seg_map[i] = (cpi->consec_zero_last[i] >
630 cpi->denoiser.denoise_pars.consec_zerolast) ? 1 : 0;
631 }
632 }
633 #endif
616 } 634 }
617 635
618 /* Activate segmentation. */ 636 /* Activate segmentation. */
619 cpi->mb.e_mbd.update_mb_segmentation_map = 1; 637 cpi->mb.e_mbd.update_mb_segmentation_map = 1;
620 cpi->mb.e_mbd.update_mb_segmentation_data = 1; 638 cpi->mb.e_mbd.update_mb_segmentation_data = 1;
621 enable_segmentation(cpi); 639 enable_segmentation(cpi);
622 640
623 /* Set up the quant segment data */ 641 /* Set up the quant segment data */
624 feature_data[MB_LVL_ALT_Q][0] = 0; 642 feature_data[MB_LVL_ALT_Q][0] = 0;
625 feature_data[MB_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q); 643 feature_data[MB_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q);
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 1275
1258 #endif 1276 #endif
1259 1277
1260 vpx_free(cpi->tplist); 1278 vpx_free(cpi->tplist);
1261 CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cm->mb_rows)); 1279 CHECK_MEM_ERROR(cpi->tplist, vpx_malloc(sizeof(TOKENLIST) * cm->mb_rows));
1262 1280
1263 #if CONFIG_TEMPORAL_DENOISING 1281 #if CONFIG_TEMPORAL_DENOISING
1264 if (cpi->oxcf.noise_sensitivity > 0) { 1282 if (cpi->oxcf.noise_sensitivity > 0) {
1265 vp8_denoiser_free(&cpi->denoiser); 1283 vp8_denoiser_free(&cpi->denoiser);
1266 vp8_denoiser_allocate(&cpi->denoiser, width, height, 1284 vp8_denoiser_allocate(&cpi->denoiser, width, height,
1267 cm->mb_rows, cm->mb_cols); 1285 cm->mb_rows, cm->mb_cols,
1286 cpi->oxcf.noise_sensitivity);
1268 } 1287 }
1269 #endif 1288 #endif
1270 } 1289 }
1271 1290
1272 1291
1273 /* Quant MOD */ 1292 /* Quant MOD */
1274 static const int q_trans[] = 1293 static const int q_trans[] =
1275 { 1294 {
1276 0, 1, 2, 3, 4, 5, 7, 8, 1295 0, 1, 2, 3, 4, 5, 7, 8,
1277 9, 10, 12, 13, 15, 17, 18, 19, 1296 9, 10, 12, 13, 15, 17, 18, 19,
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 cpi->is_src_frame_alt_ref = 0; 1772 cpi->is_src_frame_alt_ref = 0;
1754 1773
1755 #if CONFIG_TEMPORAL_DENOISING 1774 #if CONFIG_TEMPORAL_DENOISING
1756 if (cpi->oxcf.noise_sensitivity) 1775 if (cpi->oxcf.noise_sensitivity)
1757 { 1776 {
1758 if (!cpi->denoiser.yv12_mc_running_avg.buffer_alloc) 1777 if (!cpi->denoiser.yv12_mc_running_avg.buffer_alloc)
1759 { 1778 {
1760 int width = (cpi->oxcf.Width + 15) & ~15; 1779 int width = (cpi->oxcf.Width + 15) & ~15;
1761 int height = (cpi->oxcf.Height + 15) & ~15; 1780 int height = (cpi->oxcf.Height + 15) & ~15;
1762 vp8_denoiser_allocate(&cpi->denoiser, width, height, 1781 vp8_denoiser_allocate(&cpi->denoiser, width, height,
1763 cpi->common.mb_rows, cpi->common.mb_cols); 1782 cm->mb_rows, cm->mb_cols,
1783 cpi->oxcf.noise_sensitivity);
1764 } 1784 }
1765 } 1785 }
1766 #endif 1786 #endif
1767 1787
1768 #if 0 1788 #if 0
1769 /* Experimental RD Code */ 1789 /* Experimental RD Code */
1770 cpi->frame_distortion = 0; 1790 cpi->frame_distortion = 0;
1771 cpi->last_frame_distortion = 0; 1791 cpi->last_frame_distortion = 0;
1772 #endif 1792 #endif
1773 1793
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 cpi->one_pass_frame_stats[i].frame_mvc_abs = 0.0; 1900 cpi->one_pass_frame_stats[i].frame_mvc_abs = 0.0;
1881 } 1901 }
1882 } 1902 }
1883 #endif 1903 #endif
1884 1904
1885 /* Should we use the cyclic refresh method. 1905 /* Should we use the cyclic refresh method.
1886 * Currently this is tied to error resilliant mode 1906 * Currently this is tied to error resilliant mode
1887 */ 1907 */
1888 cpi->cyclic_refresh_mode_enabled = cpi->oxcf.error_resilient_mode; 1908 cpi->cyclic_refresh_mode_enabled = cpi->oxcf.error_resilient_mode;
1889 cpi->cyclic_refresh_mode_max_mbs_perframe = (cpi->common.mb_rows * cpi->comm on.mb_cols) / 5; 1909 cpi->cyclic_refresh_mode_max_mbs_perframe = (cpi->common.mb_rows * cpi->comm on.mb_cols) / 5;
1910 if (cpi->oxcf.number_of_layers == 1) {
1911 cpi->cyclic_refresh_mode_max_mbs_perframe =
1912 (cpi->common.mb_rows * cpi->common.mb_cols) / 20;
1913 } else if (cpi->oxcf.number_of_layers == 2) {
1914 cpi->cyclic_refresh_mode_max_mbs_perframe =
1915 (cpi->common.mb_rows * cpi->common.mb_cols) / 10;
1916 }
1890 cpi->cyclic_refresh_mode_index = 0; 1917 cpi->cyclic_refresh_mode_index = 0;
1891 cpi->cyclic_refresh_q = 32; 1918 cpi->cyclic_refresh_q = 32;
1892 1919
1893 if (cpi->cyclic_refresh_mode_enabled) 1920 if (cpi->cyclic_refresh_mode_enabled)
1894 { 1921 {
1895 CHECK_MEM_ERROR(cpi->cyclic_refresh_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1)); 1922 CHECK_MEM_ERROR(cpi->cyclic_refresh_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
1896 } 1923 }
1897 else 1924 else
1898 cpi->cyclic_refresh_map = (signed char *) NULL; 1925 cpi->cyclic_refresh_map = (signed char *) NULL;
1899 1926
1927 CHECK_MEM_ERROR(cpi->consec_zero_last,
1928 vpx_calloc(cpi->common.mb_rows * cpi->common.mb_cols, 1));
1929
1900 #ifdef VP8_ENTROPY_STATS 1930 #ifdef VP8_ENTROPY_STATS
1901 init_context_counters(); 1931 init_context_counters();
1902 #endif 1932 #endif
1903 1933
1904 /*Initialize the feed-forward activity masking.*/ 1934 /*Initialize the feed-forward activity masking.*/
1905 cpi->activity_avg = 90<<12; 1935 cpi->activity_avg = 90<<12;
1906 1936
1907 /* Give a sensible default for the first frame. */ 1937 /* Give a sensible default for the first frame. */
1908 cpi->frames_since_key = 8; 1938 cpi->frames_since_key = 8;
1909 cpi->key_frame_frequency = cpi->oxcf.key_freq; 1939 cpi->key_frame_frequency = cpi->oxcf.key_freq;
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 vp8cx_remove_encoder_threads(cpi); 2440 vp8cx_remove_encoder_threads(cpi);
2411 #endif 2441 #endif
2412 2442
2413 #if CONFIG_TEMPORAL_DENOISING 2443 #if CONFIG_TEMPORAL_DENOISING
2414 vp8_denoiser_free(&cpi->denoiser); 2444 vp8_denoiser_free(&cpi->denoiser);
2415 #endif 2445 #endif
2416 dealloc_compressor_data(cpi); 2446 dealloc_compressor_data(cpi);
2417 vpx_free(cpi->mb.ss); 2447 vpx_free(cpi->mb.ss);
2418 vpx_free(cpi->tok); 2448 vpx_free(cpi->tok);
2419 vpx_free(cpi->cyclic_refresh_map); 2449 vpx_free(cpi->cyclic_refresh_map);
2450 vpx_free(cpi->consec_zero_last);
2420 2451
2421 vp8_remove_common(&cpi->common); 2452 vp8_remove_common(&cpi->common);
2422 vpx_free(cpi); 2453 vpx_free(cpi);
2423 *ptr = 0; 2454 *ptr = 0;
2424 2455
2425 #ifdef OUTPUT_YUV_SRC 2456 #ifdef OUTPUT_YUV_SRC
2426 fclose(yuv_file); 2457 fclose(yuv_file);
2427 #endif 2458 #endif
2428 #ifdef OUTPUT_YUV_DENOISED 2459 #ifdef OUTPUT_YUV_DENOISED
2429 fclose(yuv_denoised_file); 2460 fclose(yuv_denoised_file);
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
3112 3143
3113 if (cm->frame_type == KEY_FRAME) 3144 if (cm->frame_type == KEY_FRAME)
3114 { 3145 {
3115 yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FRAME | VP8_ALTR_FRAME ; 3146 yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FRAME | VP8_ALTR_FRAME ;
3116 3147
3117 yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME; 3148 yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
3118 yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME; 3149 yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
3119 3150
3120 cm->alt_fb_idx = cm->gld_fb_idx = cm->new_fb_idx; 3151 cm->alt_fb_idx = cm->gld_fb_idx = cm->new_fb_idx;
3121 3152
3122 #if CONFIG_MULTI_RES_ENCODING
3123 cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame; 3153 cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame;
3124 cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame; 3154 cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame;
3125 #endif
3126 } 3155 }
3127 else /* For non key frames */ 3156 else /* For non key frames */
3128 { 3157 {
3129 if (cm->refresh_alt_ref_frame) 3158 if (cm->refresh_alt_ref_frame)
3130 { 3159 {
3131 assert(!cm->copy_buffer_to_arf); 3160 assert(!cm->copy_buffer_to_arf);
3132 3161
3133 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_ALTR_FRAME; 3162 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_ALTR_FRAME;
3134 cm->yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME; 3163 cm->yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
3135 cm->alt_fb_idx = cm->new_fb_idx; 3164 cm->alt_fb_idx = cm->new_fb_idx;
3136 3165
3137 #if CONFIG_MULTI_RES_ENCODING
3138 cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame; 3166 cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame;
3139 #endif
3140 } 3167 }
3141 else if (cm->copy_buffer_to_arf) 3168 else if (cm->copy_buffer_to_arf)
3142 { 3169 {
3143 assert(!(cm->copy_buffer_to_arf & ~0x3)); 3170 assert(!(cm->copy_buffer_to_arf & ~0x3));
3144 3171
3145 if (cm->copy_buffer_to_arf == 1) 3172 if (cm->copy_buffer_to_arf == 1)
3146 { 3173 {
3147 if(cm->alt_fb_idx != cm->lst_fb_idx) 3174 if(cm->alt_fb_idx != cm->lst_fb_idx)
3148 { 3175 {
3149 yv12_fb[cm->lst_fb_idx].flags |= VP8_ALTR_FRAME; 3176 yv12_fb[cm->lst_fb_idx].flags |= VP8_ALTR_FRAME;
3150 yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME; 3177 yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
3151 cm->alt_fb_idx = cm->lst_fb_idx; 3178 cm->alt_fb_idx = cm->lst_fb_idx;
3152 3179
3153 #if CONFIG_MULTI_RES_ENCODING
3154 cpi->current_ref_frames[ALTREF_FRAME] = 3180 cpi->current_ref_frames[ALTREF_FRAME] =
3155 cpi->current_ref_frames[LAST_FRAME]; 3181 cpi->current_ref_frames[LAST_FRAME];
3156 #endif
3157 } 3182 }
3158 } 3183 }
3159 else /* if (cm->copy_buffer_to_arf == 2) */ 3184 else /* if (cm->copy_buffer_to_arf == 2) */
3160 { 3185 {
3161 if(cm->alt_fb_idx != cm->gld_fb_idx) 3186 if(cm->alt_fb_idx != cm->gld_fb_idx)
3162 { 3187 {
3163 yv12_fb[cm->gld_fb_idx].flags |= VP8_ALTR_FRAME; 3188 yv12_fb[cm->gld_fb_idx].flags |= VP8_ALTR_FRAME;
3164 yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME; 3189 yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
3165 cm->alt_fb_idx = cm->gld_fb_idx; 3190 cm->alt_fb_idx = cm->gld_fb_idx;
3166 3191
3167 #if CONFIG_MULTI_RES_ENCODING
3168 cpi->current_ref_frames[ALTREF_FRAME] = 3192 cpi->current_ref_frames[ALTREF_FRAME] =
3169 cpi->current_ref_frames[GOLDEN_FRAME]; 3193 cpi->current_ref_frames[GOLDEN_FRAME];
3170 #endif
3171 } 3194 }
3172 } 3195 }
3173 } 3196 }
3174 3197
3175 if (cm->refresh_golden_frame) 3198 if (cm->refresh_golden_frame)
3176 { 3199 {
3177 assert(!cm->copy_buffer_to_gf); 3200 assert(!cm->copy_buffer_to_gf);
3178 3201
3179 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FRAME; 3202 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_GOLD_FRAME;
3180 cm->yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME; 3203 cm->yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
3181 cm->gld_fb_idx = cm->new_fb_idx; 3204 cm->gld_fb_idx = cm->new_fb_idx;
3182 3205
3183 #if CONFIG_MULTI_RES_ENCODING
3184 cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame; 3206 cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame;
3185 #endif
3186 } 3207 }
3187 else if (cm->copy_buffer_to_gf) 3208 else if (cm->copy_buffer_to_gf)
3188 { 3209 {
3189 assert(!(cm->copy_buffer_to_arf & ~0x3)); 3210 assert(!(cm->copy_buffer_to_arf & ~0x3));
3190 3211
3191 if (cm->copy_buffer_to_gf == 1) 3212 if (cm->copy_buffer_to_gf == 1)
3192 { 3213 {
3193 if(cm->gld_fb_idx != cm->lst_fb_idx) 3214 if(cm->gld_fb_idx != cm->lst_fb_idx)
3194 { 3215 {
3195 yv12_fb[cm->lst_fb_idx].flags |= VP8_GOLD_FRAME; 3216 yv12_fb[cm->lst_fb_idx].flags |= VP8_GOLD_FRAME;
3196 yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME; 3217 yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
3197 cm->gld_fb_idx = cm->lst_fb_idx; 3218 cm->gld_fb_idx = cm->lst_fb_idx;
3198 3219
3199 #if CONFIG_MULTI_RES_ENCODING
3200 cpi->current_ref_frames[GOLDEN_FRAME] = 3220 cpi->current_ref_frames[GOLDEN_FRAME] =
3201 cpi->current_ref_frames[LAST_FRAME]; 3221 cpi->current_ref_frames[LAST_FRAME];
3202 #endif
3203 } 3222 }
3204 } 3223 }
3205 else /* if (cm->copy_buffer_to_gf == 2) */ 3224 else /* if (cm->copy_buffer_to_gf == 2) */
3206 { 3225 {
3207 if(cm->alt_fb_idx != cm->gld_fb_idx) 3226 if(cm->alt_fb_idx != cm->gld_fb_idx)
3208 { 3227 {
3209 yv12_fb[cm->alt_fb_idx].flags |= VP8_GOLD_FRAME; 3228 yv12_fb[cm->alt_fb_idx].flags |= VP8_GOLD_FRAME;
3210 yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME; 3229 yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
3211 cm->gld_fb_idx = cm->alt_fb_idx; 3230 cm->gld_fb_idx = cm->alt_fb_idx;
3212 3231
3213 #if CONFIG_MULTI_RES_ENCODING
3214 cpi->current_ref_frames[GOLDEN_FRAME] = 3232 cpi->current_ref_frames[GOLDEN_FRAME] =
3215 cpi->current_ref_frames[ALTREF_FRAME]; 3233 cpi->current_ref_frames[ALTREF_FRAME];
3216 #endif
3217 } 3234 }
3218 } 3235 }
3219 } 3236 }
3220 } 3237 }
3221 3238
3222 if (cm->refresh_last_frame) 3239 if (cm->refresh_last_frame)
3223 { 3240 {
3224 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_LAST_FRAME; 3241 cm->yv12_fb[cm->new_fb_idx].flags |= VP8_LAST_FRAME;
3225 cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FRAME; 3242 cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FRAME;
3226 cm->lst_fb_idx = cm->new_fb_idx; 3243 cm->lst_fb_idx = cm->new_fb_idx;
3227 3244
3228 #if CONFIG_MULTI_RES_ENCODING
3229 cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame; 3245 cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame;
3230 #endif
3231 } 3246 }
3232 3247
3233 #if CONFIG_TEMPORAL_DENOISING 3248 #if CONFIG_TEMPORAL_DENOISING
3234 if (cpi->oxcf.noise_sensitivity) 3249 if (cpi->oxcf.noise_sensitivity)
3235 { 3250 {
3236 /* we shouldn't have to keep multiple copies as we know in advance which 3251 /* we shouldn't have to keep multiple copies as we know in advance which
3237 * buffer we should start - for now to get something up and running 3252 * buffer we should start - for now to get something up and running
3238 * I've chosen to copy the buffers 3253 * I've chosen to copy the buffers
3239 */ 3254 */
3240 if (cm->frame_type == KEY_FRAME) 3255 if (cm->frame_type == KEY_FRAME)
(...skipping 20 matching lines...) Expand all
3261 &cpi->denoiser.yv12_running_avg[INTRA_FRAME], 3276 &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
3262 &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]); 3277 &cpi->denoiser.yv12_running_avg[GOLDEN_FRAME]);
3263 } 3278 }
3264 if(cm->refresh_last_frame) 3279 if(cm->refresh_last_frame)
3265 { 3280 {
3266 vp8_yv12_copy_frame( 3281 vp8_yv12_copy_frame(
3267 &cpi->denoiser.yv12_running_avg[INTRA_FRAME], 3282 &cpi->denoiser.yv12_running_avg[INTRA_FRAME],
3268 &cpi->denoiser.yv12_running_avg[LAST_FRAME]); 3283 &cpi->denoiser.yv12_running_avg[LAST_FRAME]);
3269 } 3284 }
3270 } 3285 }
3286 if (cpi->oxcf.noise_sensitivity == 4)
3287 vp8_yv12_copy_frame(cpi->Source, &cpi->denoiser.yv12_last_source);
3271 3288
3272 } 3289 }
3273 #endif 3290 #endif
3274 3291
3275 } 3292 }
3276 3293
3294 static void process_denoiser_mode_change(VP8_COMP *cpi) {
3295 const VP8_COMMON *const cm = &cpi->common;
3296 int i, j;
3297 int total = 0;
3298 int num_blocks = 0;
3299 // Number of blocks skipped along row/column in computing the
3300 // nmse (normalized mean square error) of source.
3301 int skip = 2;
3302 // Only select blocks for computing nmse that have been encoded
3303 // as ZERO LAST min_consec_zero_last frames in a row.
3304 int min_consec_zero_last = 10;
3305 // Decision is tested for changing the denoising mode every
3306 // num_mode_change times this function is called. Note that this
3307 // function called every 8 frames, so (8 * num_mode_change) is number
3308 // of frames where denoising mode change is tested for switch.
3309 int num_mode_change = 15;
3310 // Framerate factor, to compensate for larger mse at lower framerates.
3311 // TODO(marpan): Adjust this factor,
3312 int fac_framerate = cpi->output_framerate < 25.0f ? 80 : 100;
3313 int tot_num_blocks = cm->mb_rows * cm->mb_cols;
3314 int ystride = cpi->Source->y_stride;
3315 unsigned char *src = cpi->Source->y_buffer;
3316 unsigned char *dst = cpi->denoiser.yv12_last_source.y_buffer;
3317 static const unsigned char const_source[16] = {
3318 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
3319 128, 128, 128};
3320
3321 // Loop through the Y plane, every skip blocks along rows and columns,
3322 // summing the normalized mean square error, only for blocks that have
3323 // been encoded as ZEROMV LAST at least min_consec_zero_last least frames in
3324 // a row and have small sum difference between current and previous frame.
3325 // Normalization here is by the contrast of the current frame block.
3326 for (i = 0; i < cm->Height; i += 16 * skip) {
3327 int block_index_row = (i >> 4) * cm->mb_cols;
3328 for (j = 0; j < cm->Width; j += 16 * skip) {
3329 int index = block_index_row + (j >> 4);
3330 if (cpi->consec_zero_last[index] >= min_consec_zero_last) {
3331 unsigned int sse;
3332 const unsigned int mse = vp8_mse16x16(src + j,
3333 ystride,
3334 dst + j,
3335 ystride,
3336 &sse);
3337 const unsigned int var = vp8_variance16x16(src + j,
3338 ystride,
3339 dst + j,
3340 ystride,
3341 &sse);
3342 // Only consider this block as valid for noise measurement
3343 // if the sum_diff average of the current and previous frame
3344 // is small (to avoid effects from lighting change).
3345 if ((mse - var) < 256) {
3346 const unsigned int act = vp8_variance16x16(src + j,
3347 ystride,
3348 const_source,
3349 0,
3350 &sse);
3351 if (act > 0)
3352 total += mse / act;
3353 num_blocks++;
3354 }
3355 }
3356 }
3357 src += 16 * skip * ystride;
3358 dst += 16 * skip * ystride;
3359 }
3360 total = total * fac_framerate / 100;
3361
3362 // Only consider this frame as valid sample if we have computed nmse over
3363 // at least ~1/16 blocks, and Total > 0 (Total == 0 can happen if the
3364 // application inputs duplicate frames, or contrast is all zero).
3365 if (total > 0 &&
3366 (num_blocks > (tot_num_blocks >> 4))) {
3367 // Update the recursive mean square source_diff.
3368 if (cpi->denoiser.nmse_source_diff_count == 0)
3369 // First sample in new interval.
3370 cpi->denoiser.nmse_source_diff = total;
3371 else
3372 // For subsequent samples, use average with weight ~1/4 for new sample.
3373 cpi->denoiser.nmse_source_diff = (int)((total >> 2) +
3374 3 * (cpi->denoiser.nmse_source_diff >> 2));
3375 cpi->denoiser.nmse_source_diff_count++;
3376 }
3377 // Check for changing the denoiser mode, when we have obtained #samples =
3378 // num_mode_change.
3379 if (cpi->denoiser.nmse_source_diff_count == num_mode_change) {
3380 // Check for going up: from normal to aggressive mode.
3381 if ((cpi->denoiser.denoiser_mode = kDenoiserOnYUV) &&
3382 (cpi->denoiser.nmse_source_diff >
3383 cpi->denoiser.threshold_aggressive_mode)) {
3384 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive);
3385 } else {
3386 // Check for going down: from aggressive to normal mode.
3387 if ((cpi->denoiser.denoiser_mode = kDenoiserOnYUVAggressive) &&
3388 (cpi->denoiser.nmse_source_diff <
3389 cpi->denoiser.threshold_aggressive_mode)) {
3390 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV);
3391 }
3392 }
3393 // Reset metric and counter for next interval.
3394 cpi->denoiser.nmse_source_diff = 0;
3395 cpi->denoiser.nmse_source_diff_count = 0;
3396 }
3397 }
3398
3277 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm) 3399 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm)
3278 { 3400 {
3279 const FRAME_TYPE frame_type = cm->frame_type; 3401 const FRAME_TYPE frame_type = cm->frame_type;
3280 3402
3281 if (cm->no_lpf) 3403 if (cm->no_lpf)
3282 { 3404 {
3283 cm->filter_level = 0; 3405 cm->filter_level = 0;
3284 } 3406 }
3285 else 3407 else
3286 { 3408 {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
3423 /* Check to see if a key frame is signaled 3545 /* Check to see if a key frame is signaled
3424 * For two pass with auto key frame enabled cm->frame_type may already 3546 * For two pass with auto key frame enabled cm->frame_type may already
3425 * be set, but not for one pass. 3547 * be set, but not for one pass.
3426 */ 3548 */
3427 if ((cm->current_video_frame == 0) || 3549 if ((cm->current_video_frame == 0) ||
3428 (cm->frame_flags & FRAMEFLAGS_KEY) || 3550 (cm->frame_flags & FRAMEFLAGS_KEY) ||
3429 (cpi->oxcf.auto_key && (cpi->frames_since_key % cpi->key_frame_frequency == 0))) 3551 (cpi->oxcf.auto_key && (cpi->frames_since_key % cpi->key_frame_frequency == 0)))
3430 { 3552 {
3431 /* Key frame from VFW/auto-keyframe/first frame */ 3553 /* Key frame from VFW/auto-keyframe/first frame */
3432 cm->frame_type = KEY_FRAME; 3554 cm->frame_type = KEY_FRAME;
3555 #if CONFIG_TEMPORAL_DENOISING
3556 if (cpi->oxcf.noise_sensitivity == 4) {
3557 // For adaptive mode, reset denoiser to normal mode on key frame.
3558 vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV);
3559 }
3560 #endif
3433 } 3561 }
3434 3562
3435 #if CONFIG_MULTI_RES_ENCODING 3563 #if CONFIG_MULTI_RES_ENCODING
3436 /* In multi-resolution encoding, frame_type is decided by lowest-resolution 3564 /* In multi-resolution encoding, frame_type is decided by lowest-resolution
3437 * encoder. Same frame_type is adopted while encoding at other resolution. 3565 * encoder. Same frame_type is adopted while encoding at other resolution.
3438 */ 3566 */
3439 if (cpi->oxcf.mr_encoder_id) 3567 if (cpi->oxcf.mr_encoder_id)
3440 { 3568 {
3441 LOWER_RES_FRAME_INFO* low_res_frame_info 3569 LOWER_RES_FRAME_INFO* low_res_frame_info
3442 = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info; 3570 = (LOWER_RES_FRAME_INFO*)cpi->oxcf.mr_low_res_mode_info;
(...skipping 13 matching lines...) Expand all
3456 cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[GOLDEN_FRAM E] 3584 cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[GOLDEN_FRAM E]
3457 == low_res_frame_info->low_res_ref_frames[GOLDEN_FRAME] ); 3585 == low_res_frame_info->low_res_ref_frames[GOLDEN_FRAME] );
3458 3586
3459 if (cpi->ref_frame_flags & VP8_ALTR_FRAME) 3587 if (cpi->ref_frame_flags & VP8_ALTR_FRAME)
3460 cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[ALTREF_FRAM E] 3588 cpi->mr_low_res_mv_avail &= (cpi->current_ref_frames[ALTREF_FRAM E]
3461 == low_res_frame_info->low_res_ref_frames[ALTREF_FRAME] ); 3589 == low_res_frame_info->low_res_ref_frames[ALTREF_FRAME] );
3462 } 3590 }
3463 } 3591 }
3464 #endif 3592 #endif
3465 3593
3594 // Find the reference frame closest to the current frame.
3595 cpi->closest_reference_frame = LAST_FRAME;
3596 if (cm->frame_type != KEY_FRAME) {
3597 int i;
3598 MV_REFERENCE_FRAME closest_ref = INTRA_FRAME;
3599 if (cpi->ref_frame_flags & VP8_LAST_FRAME) {
3600 closest_ref = LAST_FRAME;
3601 } else if (cpi->ref_frame_flags & VP8_GOLD_FRAME) {
3602 closest_ref = GOLDEN_FRAME;
3603 } else if (cpi->ref_frame_flags & VP8_ALTR_FRAME) {
3604 closest_ref = ALTREF_FRAME;
3605 }
3606 for (i = 1; i <= 3; i++) {
3607 vpx_ref_frame_type_t ref_frame_type = (vpx_ref_frame_type_t)
3608 ((i == 3) ? 4 : i);
3609 if (cpi->ref_frame_flags & ref_frame_type) {
3610 if ((cm->current_video_frame - cpi->current_ref_frames[i]) <
3611 (cm->current_video_frame - cpi->current_ref_frames[closest_ref])) {
3612 closest_ref = i;
3613 }
3614 }
3615 }
3616 cpi->closest_reference_frame = closest_ref;
3617 }
3618
3466 /* Set various flags etc to special state if it is a key frame */ 3619 /* Set various flags etc to special state if it is a key frame */
3467 if (cm->frame_type == KEY_FRAME) 3620 if (cm->frame_type == KEY_FRAME)
3468 { 3621 {
3469 int i; 3622 int i;
3470 3623
3471 // Set the loop filter deltas and segmentation map update 3624 // Set the loop filter deltas and segmentation map update
3472 setup_features(cpi); 3625 setup_features(cpi);
3473 3626
3474 /* The alternate reference frame cannot be active for a key frame */ 3627 /* The alternate reference frame cannot be active for a key frame */
3475 cpi->source_alt_ref_active = 0; 3628 cpi->source_alt_ref_active = 0;
3476 3629
3477 /* Reset the RD threshold multipliers to default of * 1 (128) */ 3630 /* Reset the RD threshold multipliers to default of * 1 (128) */
3478 for (i = 0; i < MAX_MODES; i++) 3631 for (i = 0; i < MAX_MODES; i++)
3479 { 3632 {
3480 cpi->mb.rd_thresh_mult[i] = 128; 3633 cpi->mb.rd_thresh_mult[i] = 128;
3481 } 3634 }
3635
3636 // Reset the zero_last counter to 0 on key frame.
3637 vpx_memset(cpi->consec_zero_last, 0, cm->mb_rows * cm->mb_cols);
3482 } 3638 }
3483 3639
3484 #if 0 3640 #if 0
3485 /* Experimental code for lagged compress and one pass 3641 /* Experimental code for lagged compress and one pass
3486 * Initialise one_pass GF frames stats 3642 * Initialise one_pass GF frames stats
3487 * Update stats used for GF selection 3643 * Update stats used for GF selection
3488 */ 3644 */
3489 { 3645 {
3490 cpi->one_pass_frame_index = cm->current_video_frame % MAX_LAG_BUFFERS; 3646 cpi->one_pass_frame_index = cm->current_video_frame % MAX_LAG_BUFFERS;
3491 3647
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
3893 4049
3894 if (cpi->Source->y_stride < 0) 4050 if (cpi->Source->y_stride < 0)
3895 { 4051 {
3896 src += cpi->Source->y_stride * (cpi->Source->y_height - 1); 4052 src += cpi->Source->y_stride * (cpi->Source->y_height - 1);
3897 } 4053 }
3898 } 4054 }
3899 } 4055 }
3900 4056
3901 #endif 4057 #endif
3902 4058
4059
3903 #ifdef OUTPUT_YUV_SRC 4060 #ifdef OUTPUT_YUV_SRC
3904 vp8_write_yuv_frame(yuv_file, cpi->Source); 4061 vp8_write_yuv_frame(yuv_file, cpi->Source);
3905 #endif 4062 #endif
3906 4063
3907 do 4064 do
3908 { 4065 {
3909 vp8_clear_system_state(); 4066 vp8_clear_system_state();
3910 4067
3911 vp8_set_quantizer(cpi, Q); 4068 vp8_set_quantizer(cpi, Q);
3912 4069
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3988 * and background refresh. 4145 * and background refresh.
3989 */ 4146 */
3990 Q = vp8_regulate_q(cpi, cpi->this_frame_target); 4147 Q = vp8_regulate_q(cpi, cpi->this_frame_target);
3991 if (cpi->cyclic_refresh_mode_enabled) 4148 if (cpi->cyclic_refresh_mode_enabled)
3992 { 4149 {
3993 if (cpi->current_layer==0) 4150 if (cpi->current_layer==0)
3994 cyclic_background_refresh(cpi, Q, 0); 4151 cyclic_background_refresh(cpi, Q, 0);
3995 else 4152 else
3996 disable_segmentation(cpi); 4153 disable_segmentation(cpi);
3997 } 4154 }
4155 // Reset the consec_zero_last counter on key frame.
4156 vpx_memset(cpi->consec_zero_last, 0, cm->mb_rows * cm->mb_cols);
3998 vp8_set_quantizer(cpi, Q); 4157 vp8_set_quantizer(cpi, Q);
3999 } 4158 }
4000 4159
4001 vp8_setup_key_frame(cpi); 4160 vp8_setup_key_frame(cpi);
4002 } 4161 }
4003 4162
4004 4163
4005 4164
4006 #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING 4165 #if CONFIG_REALTIME_ONLY & CONFIG_ONTHEFLY_BITPACKING
4007 { 4166 {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
4376 MODE_INFO *tmp = cm->mi; 4535 MODE_INFO *tmp = cm->mi;
4377 4536
4378 cpi->zeromv_count = 0; 4537 cpi->zeromv_count = 0;
4379 4538
4380 if(cm->frame_type != KEY_FRAME) 4539 if(cm->frame_type != KEY_FRAME)
4381 { 4540 {
4382 for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++) 4541 for (mb_row = 0; mb_row < cm->mb_rows; mb_row ++)
4383 { 4542 {
4384 for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++) 4543 for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++)
4385 { 4544 {
4386 if(tmp->mbmi.mode == ZEROMV) 4545 if (tmp->mbmi.mode == ZEROMV &&
4546 tmp->mbmi.ref_frame == LAST_FRAME)
4387 cpi->zeromv_count++; 4547 cpi->zeromv_count++;
4388 tmp++; 4548 tmp++;
4389 } 4549 }
4390 tmp++; 4550 tmp++;
4391 } 4551 }
4392 } 4552 }
4393 } 4553 }
4394 4554
4395 #if CONFIG_MULTI_RES_ENCODING 4555 #if CONFIG_MULTI_RES_ENCODING
4396 vp8_cal_dissimilarity(cpi); 4556 vp8_cal_dissimilarity(cpi);
(...skipping 21 matching lines...) Expand all
4418 * cm->refresh_golden_frame is set we copy the old GF over to the ARF buffer 4578 * cm->refresh_golden_frame is set we copy the old GF over to the ARF buffer
4419 * This is purely an encoder decision at present. 4579 * This is purely an encoder decision at present.
4420 */ 4580 */
4421 if (!cpi->oxcf.error_resilient_mode && cm->refresh_golden_frame) 4581 if (!cpi->oxcf.error_resilient_mode && cm->refresh_golden_frame)
4422 cm->copy_buffer_to_arf = 2; 4582 cm->copy_buffer_to_arf = 2;
4423 else 4583 else
4424 cm->copy_buffer_to_arf = 0; 4584 cm->copy_buffer_to_arf = 0;
4425 4585
4426 cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx]; 4586 cm->frame_to_show = &cm->yv12_fb[cm->new_fb_idx];
4427 4587
4588 #if CONFIG_TEMPORAL_DENOISING
4589 // For the adaptive denoising mode (noise_sensitivity == 4), sample the mse
4590 // of source diff (between current and previous frame), and determine if we
4591 // should switch the denoiser mode. Sampling refers to computing the mse for
4592 // a sub-sample of the frame (i.e., skip x blocks along row/column), and
4593 // only for blocks in that set that have used ZEROMV LAST, along with some
4594 // constraint on the sum diff between blocks. This process is called every
4595 // ~8 frames, to further reduce complexity.
4596 if (cpi->oxcf.noise_sensitivity == 4 &&
4597 cpi->frames_since_key % 8 == 0 &&
4598 cm->frame_type != KEY_FRAME) {
4599 process_denoiser_mode_change(cpi);
4600 }
4601 #endif
4602
4428 #if CONFIG_MULTITHREAD 4603 #if CONFIG_MULTITHREAD
4429 if (cpi->b_multi_threaded) 4604 if (cpi->b_multi_threaded)
4430 { 4605 {
4431 /* start loopfilter in separate thread */ 4606 /* start loopfilter in separate thread */
4432 sem_post(&cpi->h_event_start_lpf); 4607 sem_post(&cpi->h_event_start_lpf);
4433 cpi->b_lpf_running = 1; 4608 cpi->b_lpf_running = 1;
4434 } 4609 }
4435 else 4610 else
4436 #endif 4611 #endif
4437 { 4612 {
(...skipping 1113 matching lines...) Expand 10 before | Expand all | Expand 10 after
5551 } 5726 }
5552 5727
5553 return Total; 5728 return Total;
5554 } 5729 }
5555 5730
5556 5731
5557 int vp8_get_quantizer(VP8_COMP *cpi) 5732 int vp8_get_quantizer(VP8_COMP *cpi)
5558 { 5733 {
5559 return cpi->common.base_qindex; 5734 return cpi->common.base_qindex;
5560 } 5735 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/ethreading.c ('k') | source/libvpx/vp8/encoder/onyx_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698