Commit c7855b1a authored by Cheng Chen's avatar Cheng Chen

Add threshold to superblock filter level selection

Signal one bit to indicate whether current superblock reuses filter
level of previous superblock.
Try filtering and compute sse using previous filter level and search
the best possible filter level. If their diff is less than predefined
threshold, current superblock reuses previous level. Otherwise,
signal the best filter level.

Change-Id: Ibf125860883b774ef2464b62bb8b799b48258c64
parent 2eada612
......@@ -19,9 +19,9 @@
#include "aom/aom_codec.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_dsp/binary_codes_reader.h"
#include "aom_dsp/bitreader.h"
#include "aom_dsp/bitreader_buffer.h"
#include "aom_dsp/binary_codes_reader.h"
#include "aom_mem/aom_mem.h"
#include "aom_ports/mem.h"
#include "aom_ports/mem_ops.h"
......@@ -2550,11 +2550,18 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd,
prev_mi_row = mi_row;
prev_mi_col = mi_col - MAX_MIB_SIZE;
}
const uint8_t prev_lvl =
cm->mi_grid_visible[prev_mi_row * cm->mi_stride + prev_mi_col]
->mbmi.filt_lvl;
const unsigned int delta = aom_read_literal(r, LPF_DELTA_BITS, ACCT_STR);
const int reuse_prev_lvl = aom_read_literal(r, 1, ACCT_STR);
if (reuse_prev_lvl) {
filt_lvl = prev_lvl;
} else {
const unsigned int delta =
aom_read_literal(r, LPF_DELTA_BITS, ACCT_STR);
if (delta) {
const int sign = aom_read_literal(r, 1, ACCT_STR);
filt_lvl = sign ? prev_lvl + delta : prev_lvl - delta;
......@@ -2562,6 +2569,7 @@ static void decode_partition(AV1Decoder *const pbi, MACROBLOCKD *const xd,
filt_lvl = prev_lvl;
}
}
}
int row, col;
// set filter level for each mbmi
for (row = mi_row; row < mi_row + MAX_MIB_SIZE && row < cm->mi_rows;
......
......@@ -14,9 +14,9 @@
#include <stdio.h>
#include "aom/aom_encoder.h"
#include "aom_dsp/bitwriter_buffer.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_dsp/binary_codes_writer.h"
#include "aom_dsp/bitwriter_buffer.h"
#include "aom_mem/aom_mem.h"
#include "aom_ports/mem_ops.h"
#include "aom_ports/system_state.h"
......@@ -3153,6 +3153,9 @@ static void write_modes_sb(AV1_COMP *const cpi, const TileInfo *const tile,
const uint8_t curr_lvl = curr_mbmi->filt_lvl;
const uint8_t prev_lvl = prev_mbmi->filt_lvl;
aom_write_literal(w, curr_lvl == prev_lvl, 1);
if (curr_lvl != prev_lvl) {
const int sign = curr_lvl > prev_lvl;
const unsigned int delta = abs(curr_lvl - prev_lvl);
......@@ -3160,6 +3163,7 @@ static void write_modes_sb(AV1_COMP *const cpi, const TileInfo *const tile,
if (delta) aom_write_literal(w, sign, 1);
}
}
}
#endif
#if CONFIG_CDEF
......
......@@ -125,6 +125,7 @@ static int64_t try_filter_frame(const YV12_BUFFER_CONFIG *sd,
filt_err = compute_sb_y_sse(sd, cm->frame_to_show, mi_row, mi_col);
#endif // CONFIG_HIGHBITDEPTH
// TODO(chengchen): Copy the superblock only
// Re-instate the unfiltered frame
aom_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
......@@ -145,8 +146,13 @@ static int search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
// Make a copy of the unfiltered / processed recon buffer
aom_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf);
int64_t estimate_err =
try_filter_frame(sd, cpi, last_lvl, partial_frame, mi_row, mi_col);
int i;
for (i = min_filter_level; i <= max_filter_level; ++i) {
if (i == last_lvl) continue;
int64_t filt_err =
try_filter_frame(sd, cpi, i, partial_frame, mi_row, mi_col);
if (filt_err < best_err) {
......@@ -155,6 +161,15 @@ static int search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
}
}
// If previous sb filter level has similar filtering performance as current
// best filter level, use previous level such that we can only send one bit
// to indicate current filter level is the same as the previous.
const int64_t threshold = 700;
if ((mi_row > 0 || mi_col > 0) && abs(estimate_err - best_err) < threshold) {
best_err = estimate_err;
filt_best = last_lvl;
}
if (best_cost_ret) *best_cost_ret = RDCOST_DBL(x->rdmult, 0, best_err);
return filt_best;
}
......
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