diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index cda3b5d6d3d43dc265fbb24585f67f4b00cb6363..e4e7b9a4e0b44f8620101e9dc3c2882874d96559 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -1447,77 +1447,6 @@ static int calc_arf_boost( return arf_boost; } -void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame, - int group_boost) { - int half_gf_int; - int frames_after_arf; - int frames_bwd = cpi->oxcf.arnr_max_frames - 1; - int frames_fwd = cpi->oxcf.arnr_max_frames - 1; - int q; - - // Define the arnr filter width for this group of frames: - // We only filter frames that lie within a distance of half - // the GF interval from the ARF frame. We also have to trap - // cases where the filter extends beyond the end of clip. - // Note: this_frame->frame has been updated in the loop - // so it now points at the ARF frame. - half_gf_int = cpi->baseline_gf_interval >> 1; - frames_after_arf = (int)(cpi->twopass.total_stats->count - this_frame - 1); - - switch (cpi->oxcf.arnr_type) { - case 1: // Backward filter - frames_fwd = 0; - if (frames_bwd > half_gf_int) - frames_bwd = half_gf_int; - break; - - case 2: // Forward filter - if (frames_fwd > half_gf_int) - frames_fwd = half_gf_int; - if (frames_fwd > frames_after_arf) - frames_fwd = frames_after_arf; - frames_bwd = 0; - break; - - case 3: // Centered filter - default: - frames_fwd >>= 1; - if (frames_fwd > frames_after_arf) - frames_fwd = frames_after_arf; - if (frames_fwd > half_gf_int) - frames_fwd = half_gf_int; - - frames_bwd = frames_fwd; - - // For even length filter there is one more frame backward - // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff. - if (frames_bwd < half_gf_int) - frames_bwd += (cpi->oxcf.arnr_max_frames + 1) & 0x1; - break; - } - - cpi->active_arnr_frames = frames_bwd + 1 + frames_fwd; - - // Adjust the strength based on active max q - q = ((int)vp9_convert_qindex_to_q(cpi->active_worst_quality) >> 1); - if (q > 8) { - cpi->active_arnr_strength = cpi->oxcf.arnr_strength; - } else { - cpi->active_arnr_strength = cpi->oxcf.arnr_strength - (8 - q); - if (cpi->active_arnr_strength < 0) - cpi->active_arnr_strength = 0; - } - - // Adjust number of frames in filter and strength based on gf boost level. - if (cpi->active_arnr_frames > (group_boost / 150)) { - cpi->active_arnr_frames = (group_boost / 150); - cpi->active_arnr_frames += !(cpi->active_arnr_frames & 1); - } - if (cpi->active_arnr_strength > (group_boost / 300)) { - cpi->active_arnr_strength = (group_boost / 300); - } -} - #if CONFIG_MULTIPLE_ARF // Work out the frame coding order for a GF or an ARF group. // The current implementation codes frames in their natural order for a diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index afc5fb51b8d0e98810a57b8267dd0404335abcfd..dc02f146e2ff5a173f6ed87d9f2bf8ebc036aa8b 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -82,10 +82,6 @@ extern double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source, #endif -// TODO(agrange) Move this function. -extern void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame, - int group_boost); - // #define OUTPUT_YUV_REC #ifdef OUTPUT_YUV_SRC diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c index 22a12f4a8558978014a7aaaf1e8cbb44f6f957c4..cf84fa1e582aa5d93b8a541fcfa32d5eb40fd85d 100644 --- a/vp9/encoder/vp9_temporal_filter.c +++ b/vp9/encoder/vp9_temporal_filter.c @@ -482,3 +482,74 @@ void vp9_temporal_filter_prepare(VP9_COMP *cpi, int distance) { frames_to_blur_backward, strength); } + +void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame, + const int group_boost) { + int half_gf_int; + int frames_after_arf; + int frames_bwd = cpi->oxcf.arnr_max_frames - 1; + int frames_fwd = cpi->oxcf.arnr_max_frames - 1; + int q; + + // Define the arnr filter width for this group of frames: + // We only filter frames that lie within a distance of half + // the GF interval from the ARF frame. We also have to trap + // cases where the filter extends beyond the end of clip. + // Note: this_frame->frame has been updated in the loop + // so it now points at the ARF frame. + half_gf_int = cpi->baseline_gf_interval >> 1; + frames_after_arf = (int)(cpi->twopass.total_stats->count - this_frame - 1); + + switch (cpi->oxcf.arnr_type) { + case 1: // Backward filter + frames_fwd = 0; + if (frames_bwd > half_gf_int) + frames_bwd = half_gf_int; + break; + + case 2: // Forward filter + if (frames_fwd > half_gf_int) + frames_fwd = half_gf_int; + if (frames_fwd > frames_after_arf) + frames_fwd = frames_after_arf; + frames_bwd = 0; + break; + + case 3: // Centered filter + default: + frames_fwd >>= 1; + if (frames_fwd > frames_after_arf) + frames_fwd = frames_after_arf; + if (frames_fwd > half_gf_int) + frames_fwd = half_gf_int; + + frames_bwd = frames_fwd; + + // For even length filter there is one more frame backward + // than forward: e.g. len=6 ==> bbbAff, len=7 ==> bbbAfff. + if (frames_bwd < half_gf_int) + frames_bwd += (cpi->oxcf.arnr_max_frames + 1) & 0x1; + break; + } + + cpi->active_arnr_frames = frames_bwd + 1 + frames_fwd; + + // Adjust the strength based on active max q + q = ((int)vp9_convert_qindex_to_q(cpi->active_worst_quality) >> 1); + if (q > 8) { + cpi->active_arnr_strength = cpi->oxcf.arnr_strength; + } else { + cpi->active_arnr_strength = cpi->oxcf.arnr_strength - (8 - q); + if (cpi->active_arnr_strength < 0) + cpi->active_arnr_strength = 0; + } + + // Adjust number of frames in filter and strength based on gf boost level. + if (cpi->active_arnr_frames > (group_boost / 150)) { + cpi->active_arnr_frames = (group_boost / 150); + cpi->active_arnr_frames += !(cpi->active_arnr_frames & 1); + } + if (cpi->active_arnr_strength > (group_boost / 300)) { + cpi->active_arnr_strength = (group_boost / 300); + } +} diff --git a/vp9/encoder/vp9_temporal_filter.h b/vp9/encoder/vp9_temporal_filter.h index f3ca8c6169107123325d73914498f69c5812f74d..c5f3b467e5403a09d983eaf2c126147b1c6bb22d 100644 --- a/vp9/encoder/vp9_temporal_filter.h +++ b/vp9/encoder/vp9_temporal_filter.h @@ -12,5 +12,7 @@ #define VP9_ENCODER_VP9_TEMPORAL_FILTER_H_ void vp9_temporal_filter_prepare(VP9_COMP *cpi, int distance); +void configure_arnr_filter(VP9_COMP *cpi, const unsigned int this_frame, + const int group_boost); #endif // VP9_ENCODER_VP9_TEMPORAL_FILTER_H_