diff options
Diffstat (limited to 'third_party/aom/av1/encoder/picklpf.c')
-rw-r--r-- | third_party/aom/av1/encoder/picklpf.c | 111 |
1 files changed, 98 insertions, 13 deletions
diff --git a/third_party/aom/av1/encoder/picklpf.c b/third_party/aom/av1/encoder/picklpf.c index fc0ea485d..26fd55ef0 100644 --- a/third_party/aom/av1/encoder/picklpf.c +++ b/third_party/aom/av1/encoder/picklpf.c @@ -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 @@ -154,8 +238,7 @@ int av1_search_filter_level(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi, // Update best error best_err = ss_err[filt_best]; - if (best_cost_ret) - *best_cost_ret = RDCOST_DBL(x->rdmult, x->rddiv, 0, best_err); + if (best_cost_ret) *best_cost_ret = RDCOST_DBL(x->rdmult, 0, best_err); return filt_best; } @@ -198,14 +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 } - -#if CONFIG_EXT_TILE - // TODO(any): 0 loopfilter level is only necessary if individual tile - // decoding is required. We need to communicate this requirement to this - // code and force loop filter level 0 only if required. - if (cm->tile_encoding_mode) lf->filter_level = 0; -#endif // CONFIG_EXT_TILE } |