Commit adf285f6 authored by Adrian Grange's avatar Adrian Grange Committed by Gerrit Code Review
Browse files

Merge "Move configure_arnr_filter function" into experimental

parents cbd6eaa9 9b84d113
......@@ -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
......
......@@ -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
......
......@@ -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);
}
}
......@@ -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_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment