Commit 11786b04 authored by Alex Converse's avatar Alex Converse Committed by Gerrit Code Review
Browse files

Merge "Refactor loop filter level search."

parents 05d2081d 8c2ae2d5
...@@ -34,6 +34,22 @@ static int get_max_filter_level(VP9_COMP *cpi, int base_qindex) { ...@@ -34,6 +34,22 @@ static int get_max_filter_level(VP9_COMP *cpi, int base_qindex) {
void vp9_set_alt_lf_level(VP9_COMP *cpi, int filt_val) { void vp9_set_alt_lf_level(VP9_COMP *cpi, int filt_val) {
} }
static int try_filter_frame(const YV12_BUFFER_CONFIG *sd, VP9_COMP *const cpi,
MACROBLOCKD *const xd, VP9_COMMON *const cm,
int filt_level, int partial) {
int filt_err;
vp9_set_alt_lf_level(cpi, filt_level);
vp9_loop_filter_frame(cm, xd, filt_level, 1, partial);
filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
// Re-instate the unfiltered frame
vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
return filt_err;
}
static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
int partial) { int partial) {
MACROBLOCKD *const xd = &cpi->mb.e_mbd; MACROBLOCKD *const xd = &cpi->mb.e_mbd;
...@@ -41,8 +57,7 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, ...@@ -41,8 +57,7 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
struct loopfilter *const lf = &cm->lf; struct loopfilter *const lf = &cm->lf;
const int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); const int min_filter_level = get_min_filter_level(cpi, cm->base_qindex);
const int max_filter_level = get_max_filter_level(cpi, cm->base_qindex); const int max_filter_level = get_max_filter_level(cpi, cm->base_qindex);
int best_err = 0; int best_err;
int filt_err = 0;
int filt_best; int filt_best;
int filt_direction = 0; int filt_direction = 0;
// Start the search at the previous frame filter level unless it is now out of // Start the search at the previous frame filter level unless it is now out of
...@@ -53,16 +68,9 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, ...@@ -53,16 +68,9 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
// Make a copy of the unfiltered / processed recon buffer // Make a copy of the unfiltered / processed recon buffer
vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf); vpx_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf);
// Get baseline error score best_err = try_filter_frame(sd, cpi, xd, cm, filt_mid, partial);
vp9_set_alt_lf_level(cpi, filt_mid);
vp9_loop_filter_frame(cm, xd, filt_mid, 1, partial);
best_err = vp9_calc_ss_err(sd, cm->frame_to_show);
filt_best = filt_mid; filt_best = filt_mid;
// Re-instate the unfiltered frame
vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
while (filter_step > 0) { while (filter_step > 0) {
const int filt_high = MIN(filt_mid + filter_step, max_filter_level); const int filt_high = MIN(filt_mid + filter_step, max_filter_level);
const int filt_low = MAX(filt_mid - filter_step, min_filter_level); const int filt_low = MAX(filt_mid - filter_step, min_filter_level);
...@@ -79,14 +87,7 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, ...@@ -79,14 +87,7 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
if (filt_direction <= 0 && filt_low != filt_mid) { if (filt_direction <= 0 && filt_low != filt_mid) {
// Get Low filter error score // Get Low filter error score
vp9_set_alt_lf_level(cpi, filt_low); int filt_err = try_filter_frame(sd, cpi, xd, cm, filt_low, partial);
vp9_loop_filter_frame(cm, xd, filt_low, 1, partial);
filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
// Re-instate the unfiltered frame
vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
// If value is close to the best so far then bias towards a lower loop // If value is close to the best so far then bias towards a lower loop
// filter value. // filter value.
if ((filt_err - bias) < best_err) { if ((filt_err - bias) < best_err) {
...@@ -100,14 +101,7 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi, ...@@ -100,14 +101,7 @@ static void search_filter_level(const YV12_BUFFER_CONFIG *sd, VP9_COMP *cpi,
// Now look at filt_high // Now look at filt_high
if (filt_direction >= 0 && filt_high != filt_mid) { if (filt_direction >= 0 && filt_high != filt_mid) {
vp9_set_alt_lf_level(cpi, filt_high); int filt_err = try_filter_frame(sd, cpi, xd, cm, filt_high, partial);
vp9_loop_filter_frame(cm, xd, filt_high, 1, partial);
filt_err = vp9_calc_ss_err(sd, cm->frame_to_show);
// Re-instate the unfiltered frame
vpx_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
// Was it better than the previous best? // Was it better than the previous best?
if (filt_err < (best_err - bias)) { if (filt_err < (best_err - bias)) {
best_err = filt_err; best_err = filt_err;
......
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