Commit e94df5cf authored by Cheng Chen's avatar Cheng Chen

Select filter level for U, V planes

Previously, U, V planes share the same filter level with Y.
Here, we search and pick the best filter level for U, V planes.
Selected filter levels are transmitted per frame.
This works with parallel_deblocking.

Coding gain on Google test set:
		Avg_psnr	ovr_psnr	ssim
lowres: 	-0.116		-0.120		-0.339
midres:		-0.218		-0.228		-0.338
hdres:		-0.260		-0.264		-0.365

Change-Id: I03d2ac47539f3eea9f3c4b08007bd6d3f4b73572
parent caca1355
......@@ -3038,7 +3038,16 @@ static void av1_filter_block_plane_horz(const AV1_COMMON *const cm,
void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
struct macroblockd_plane planes[MAX_MB_PLANE],
int start, int stop, int y_only) {
#if CONFIG_UV_LVL
// y_only no longer has its original meaning.
// Here it means which plane to filter
// when y_only = {0, 1, 2}, it means we are searching for filter level for
// Y/U/V plane individually.
const int plane_start = y_only;
const int plane_end = plane_start + 1;
#else
const int num_planes = y_only ? 1 : MAX_MB_PLANE;
#endif // CONFIG_UV_LVL
int mi_row, mi_col;
#if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_EXT_PARTITION_TYPES || \
......@@ -3061,7 +3070,11 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col);
#if CONFIG_UV_LVL
for (plane = plane_start; plane < plane_end; ++plane) {
#else
for (plane = 0; plane < num_planes; ++plane) {
#endif // CONFIG_UV_LVL
av1_filter_block_plane_non420_ver(cm, &planes[plane], mi + mi_col,
mi_row, mi_col, plane);
av1_filter_block_plane_non420_hor(cm, &planes[plane], mi + mi_col,
......@@ -3076,7 +3089,11 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MAX_MIB_SIZE) {
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col);
#if CONFIG_UV_LVL
for (int planeIdx = plane_start; planeIdx < plane_end; ++planeIdx) {
#else
for (int planeIdx = 0; planeIdx < num_planes; planeIdx += 1) {
#endif // CONFIG_UV_LVL
const int32_t scaleHorz = planes[planeIdx].subsampling_x;
const int32_t scaleVert = planes[planeIdx].subsampling_y;
av1_filter_block_plane_vert(
......@@ -3091,7 +3108,11 @@ void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer, AV1_COMMON *cm,
MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MAX_MIB_SIZE) {
av1_setup_dst_planes(planes, cm->sb_size, frame_buffer, mi_row, mi_col);
#if CONFIG_UV_LVL
for (int planeIdx = plane_start; planeIdx < plane_end; ++planeIdx) {
#else
for (int planeIdx = 0; planeIdx < num_planes; planeIdx += 1) {
#endif // CONFIG_UV_LVL
const int32_t scaleHorz = planes[planeIdx].subsampling_x;
const int32_t scaleVert = planes[planeIdx].subsampling_y;
av1_filter_block_plane_horz(
......
......@@ -37,6 +37,10 @@ enum lf_path {
struct loopfilter {
int filter_level;
#if CONFIG_UV_LVL
int filter_level_u;
int filter_level_v;
#endif
int sharpness_level;
int last_sharpness_level;
......
......@@ -2971,6 +2971,12 @@ static void decode_restoration(AV1_COMMON *cm, aom_reader *rb) {
static void setup_loopfilter(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
struct loopfilter *lf = &cm->lf;
lf->filter_level = aom_rb_read_literal(rb, 6);
#if CONFIG_UV_LVL
if (lf->filter_level > 0) {
lf->filter_level_u = aom_rb_read_literal(rb, 6);
lf->filter_level_v = aom_rb_read_literal(rb, 6);
}
#endif
lf->sharpness_level = aom_rb_read_literal(rb, 3);
// Read in loop filter deltas applied at the MB level based on mode or ref
......@@ -3926,9 +3932,20 @@ static const uint8_t *decode_tiles(AV1Decoder *pbi, const uint8_t *data,
}
#if CONFIG_VAR_TX || CONFIG_CB4X4
// Loopfilter the whole frame.
// Loopfilter the whole frame.
#if CONFIG_UV_LVL
if (cm->lf.filter_level > 0) {
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level, 0, 0);
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level_u, 1, 0);
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level_v, 2, 0);
}
#else
av1_loop_filter_frame(get_frame_new_buffer(cm), cm, &pbi->mb,
cm->lf.filter_level, 0, 0);
#endif // CONFIG_UV_LVL
#else
#if CONFIG_PARALLEL_DEBLOCKING
// Loopfilter all rows in the frame in the frame.
......
......@@ -3364,6 +3364,12 @@ static void encode_loopfilter(AV1_COMMON *cm, struct aom_write_bit_buffer *wb) {
// Encode the loop filter level and type
aom_wb_write_literal(wb, lf->filter_level, 6);
#if CONFIG_UV_LVL
if (lf->filter_level > 0) {
aom_wb_write_literal(wb, lf->filter_level_u, 6);
aom_wb_write_literal(wb, lf->filter_level_v, 6);
}
#endif
aom_wb_write_literal(wb, lf->sharpness_level, 3);
// Write out loop filter deltas applied at the MB level based on mode or
......
......@@ -3994,7 +3994,13 @@ static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
if (lf->filter_level > 0) {
#if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4
#if CONFIG_UV_LVL
av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_u, 1, 0);
av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level_v, 2, 0);
#else
av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
#endif // CONFIG_UV_LVL
#else
if (cpi->num_workers > 1)
av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane,
......
......@@ -38,13 +38,23 @@ int av1_get_max_filter_level(const AV1_COMP *cpi) {
static int64_t try_filter_frame(const YV12_BUFFER_CONFIG *sd,
AV1_COMP *const cpi, int filt_level,
int partial_frame) {
int partial_frame
#if CONFIG_UV_LVL
,
int plane
#endif
) {
AV1_COMMON *const cm = &cpi->common;
int64_t filt_err;
#if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4
#if CONFIG_UV_LVL
av1_loop_filter_frame(cm->frame_to_show, cm, &cpi->td.mb.e_mbd, filt_level,
plane, partial_frame);
#else
av1_loop_filter_frame(cm->frame_to_show, cm, &cpi->td.mb.e_mbd, filt_level, 1,
partial_frame);
#endif // CONFIG_UV_LVL
#else
if (cpi->num_workers > 1)
av1_loop_filter_frame_mt(cm->frame_to_show, cm, cpi->td.mb.e_mbd.plane,
......@@ -55,6 +65,40 @@ static int64_t try_filter_frame(const YV12_BUFFER_CONFIG *sd,
1, partial_frame);
#endif
#if CONFIG_UV_LVL
#if CONFIG_HIGHBITDEPTH
if (cm->use_highbitdepth) {
if (plane == 0)
filt_err = aom_highbd_get_y_sse(sd, cm->frame_to_show);
else if (plane == 1)
filt_err = aom_highbd_get_u_sse(sd, cm->frame_to_show);
else
filt_err = aom_highbd_get_v_sse(sd, cm->frame_to_show);
} else {
if (plane == 0)
filt_err = aom_get_y_sse(sd, cm->frame_to_show);
else if (plane == 1)
filt_err = aom_get_u_sse(sd, cm->frame_to_show);
else
filt_err = aom_get_v_sse(sd, cm->frame_to_show);
}
#else
if (plane == 0)
filt_err = aom_get_y_sse(sd, cm->frame_to_show);
else if (plane == 1)
filt_err = aom_get_u_sse(sd, cm->frame_to_show);
else
filt_err = aom_get_v_sse(sd, cm->frame_to_show);
#endif // CONFIG_HIGHBITDEPTH
// Re-instate the unfiltered frame
if (plane == 0)
aom_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
else if (plane == 1)
aom_yv12_copy_u(&cpi->last_frame_uf, cm->frame_to_show);
else
aom_yv12_copy_v(&cpi->last_frame_uf, cm->frame_to_show);
#else
#if CONFIG_HIGHBITDEPTH
if (cm->use_highbitdepth) {
filt_err = aom_highbd_get_y_sse(sd, cm->frame_to_show);
......@@ -67,12 +111,18 @@ static int64_t try_filter_frame(const YV12_BUFFER_CONFIG *sd,
// Re-instate the unfiltered frame
aom_yv12_copy_y(&cpi->last_frame_uf, cm->frame_to_show);
#endif // CONFIG_UV_LVL
return filt_err;
}
int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
int partial_frame, double *best_cost_ret) {
int partial_frame, double *best_cost_ret
#if CONFIG_UV_LVL
,
int plane
#endif
) {
const AV1_COMMON *const cm = &cpi->common;
const struct loopfilter *const lf = &cm->lf;
const int min_filter_level = 0;
......@@ -82,9 +132,20 @@ int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
int filt_best;
MACROBLOCK *x = &cpi->td.mb;
// Start the search at the previous frame filter level unless it is now out of
// range.
// Start the search at the previous frame filter level unless it is now out of
// range.
#if CONFIG_UV_LVL
int lvl;
switch (plane) {
case 0: lvl = lf->filter_level; break;
case 1: lvl = lf->filter_level_u; break;
case 2: lvl = lf->filter_level_v; break;
default: lvl = lf->filter_level; break;
}
int filt_mid = clamp(lvl, min_filter_level, max_filter_level);
#else
int filt_mid = clamp(lf->filter_level, min_filter_level, max_filter_level);
#endif // CONFIG_UV_LVL
int filter_step = filt_mid < 16 ? 4 : filt_mid / 4;
// Sum squared error at each filter level
int64_t ss_err[MAX_LOOP_FILTER + 1];
......@@ -92,10 +153,23 @@ int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
// Set each entry to -1
memset(ss_err, 0xFF, sizeof(ss_err));
#if CONFIG_UV_LVL
if (plane == 0)
aom_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf);
else if (plane == 1)
aom_yv12_copy_u(cm->frame_to_show, &cpi->last_frame_uf);
else if (plane == 2)
aom_yv12_copy_v(cm->frame_to_show, &cpi->last_frame_uf);
#else
// Make a copy of the unfiltered / processed recon buffer
aom_yv12_copy_y(cm->frame_to_show, &cpi->last_frame_uf);
#endif // CONFIG_UV_LVL
#if CONFIG_UV_LVL
best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame, plane);
#else
best_err = try_filter_frame(sd, cpi, filt_mid, partial_frame);
#endif // CONFIG_UV_LVL
filt_best = filt_mid;
ss_err[filt_mid] = best_err;
......@@ -115,7 +189,12 @@ int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
if (filt_direction <= 0 && filt_low != filt_mid) {
// Get Low filter error score
if (ss_err[filt_low] < 0) {
#if CONFIG_UV_LVL
ss_err[filt_low] =
try_filter_frame(sd, cpi, filt_low, partial_frame, plane);
#else
ss_err[filt_low] = try_filter_frame(sd, cpi, filt_low, partial_frame);
#endif // CONFIG_UV_LVL
}
// If value is close to the best so far then bias towards a lower loop
// filter value.
......@@ -131,7 +210,12 @@ int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
// Now look at filt_high
if (filt_direction >= 0 && filt_high != filt_mid) {
if (ss_err[filt_high] < 0) {
#if CONFIG_UV_LVL
ss_err[filt_high] =
try_filter_frame(sd, cpi, filt_high, partial_frame, plane);
#else
ss_err[filt_high] = try_filter_frame(sd, cpi, filt_high, partial_frame);
#endif // CONFIG_UV_LVL
}
// If value is significantly better than previous best, bias added against
// raising filter value
......@@ -197,7 +281,16 @@ void av1_pick_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
if (cm->frame_type == KEY_FRAME) filt_guess -= 4;
lf->filter_level = clamp(filt_guess, min_filter_level, max_filter_level);
} else {
#if CONFIG_UV_LVL
lf->filter_level = av1_search_filter_level(
sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 0);
lf->filter_level_u = av1_search_filter_level(
sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 1);
lf->filter_level_v = av1_search_filter_level(
sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL, 2);
#else
lf->filter_level = av1_search_filter_level(
sd, cpi, method == LPF_PICK_FROM_SUBIMAGE, NULL);
#endif // CONFIG_UV_LVL
}
}
......@@ -21,8 +21,13 @@ extern "C" {
struct yv12_buffer_config;
struct AV1_COMP;
int av1_get_max_filter_level(const AV1_COMP *cpi);
#if CONFIG_UV_LVL
int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
int partial_frame, double *err, int plane);
#else
int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi,
int partial_frame, double *err);
#endif
void av1_pick_filter_level(const struct yv12_buffer_config *sd,
struct AV1_COMP *cpi, LPF_PICK_METHOD method);
#ifdef __cplusplus
......
......@@ -337,6 +337,7 @@ EXPERIMENT_LIST="
var_tx_no_tx_mode
mrc_tx
lpf_direct
uv_lvl
"
CONFIG_LIST="
dependency_tracking
......
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