Commit 1a96c3f5 authored by Rupert Swarbrick's avatar Rupert Swarbrick
Browse files

Simplify the search in pickrst.c

The end results should be essentially the same, except hopefully a
little better because the previous code got the costing slightly
wrong if there were multiple tiles.

The code was doing something quite complicated to search for the best
restoration types; this patch makes it much simpler. Basically,
av1_pick_filter_restoration loops over the planes in the image. For
each plane, it loops over the possible restoration types, calling
search_rest_type for each one.

search_rest_type iterates over the restoration units in the image,
resetting the current context on tile boundaries and calling
search_<rest_type> for each restoration unit.

The search_norestore function just computes the SSE error with no
restoration. The search_wiener and search_sgrproj functions compute
the best set of coefficients and then the resulting SSE error with
those coefficients (ignoring the bit cost, so the result can be
re-used for switchable restoration).

In all cases but search_norestore, the search function has to decide
what restoration type is best for each restoration unit. For example,
search_wiener could choose to enable or disable Wiener filtering on
this unit.

Eventually, search_rest_type calculates the RDCOST after summing bit
rates and SSE errors over the restoration units. This cost gets
returned to av1_pick_filter_restoration which can then choose the best
frame-level restoration type.

Change-Id: I9bc17eb47cc46413adae749a43a440825c41bba6
parent a29cef91
......@@ -545,12 +545,6 @@ static void dealloc_compressor_data(AV1_COMP *cpi) {
#if CONFIG_LOOP_RESTORATION
av1_free_restoration_buffers(cm);
aom_free_frame_buffer(&cpi->trial_frame_rst);
aom_free(cpi->extra_rstbuf);
{
int i;
for (i = 0; i < MAX_MB_PLANE; ++i)
av1_free_restoration_struct(&cpi->rst_search[i]);
}
#endif // CONFIG_LOOP_RESTORATION
aom_free_frame_buffer(&cpi->scaled_source);
aom_free_frame_buffer(&cpi->scaled_last_source);
......@@ -827,14 +821,6 @@ static void alloc_util_frame_buffers(AV1_COMP *cpi) {
AOM_BORDER_IN_PIXELS, cm->byte_alignment, NULL, NULL, NULL))
aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
"Failed to allocate trial restored frame buffer");
int extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE;
if (extra_rstbuf_sz > 0) {
aom_free(cpi->extra_rstbuf);
CHECK_MEM_ERROR(cm, cpi->extra_rstbuf,
(uint8_t *)aom_malloc(extra_rstbuf_sz));
} else {
cpi->extra_rstbuf = NULL;
}
#endif // CONFIG_LOOP_RESTORATION
if (aom_realloc_frame_buffer(&cpi->scaled_source, cm->width, cm->height,
......@@ -4260,16 +4246,6 @@ static void set_frame_size(AV1_COMP *cpi, int width, int height) {
"Failed to allocate frame buffer");
#if CONFIG_LOOP_RESTORATION
set_restoration_tilesize(
#if CONFIG_FRAME_SUPERRES
cm->superres_upscaled_width, cm->superres_upscaled_height,
#else
cm->width, cm->height,
#endif // CONFIG_FRAME_SUPERRES
cm->subsampling_x, cm->subsampling_y, cm->rst_info);
for (int i = 0; i < MAX_MB_PLANE; ++i)
cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
#if CONFIG_FRAME_SUPERRES
const int frame_width = cm->superres_upscaled_width;
const int frame_height = cm->superres_upscaled_height;
......@@ -4277,25 +4253,12 @@ static void set_frame_size(AV1_COMP *cpi, int width, int height) {
const int frame_width = cm->width;
const int frame_height = cm->height;
#endif
set_restoration_tilesize(frame_width, frame_height, cm->subsampling_x,
cm->subsampling_y, cm->rst_info);
for (int i = 0; i < MAX_MB_PLANE; ++i)
cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
av1_alloc_restoration_buffers(cm);
// Set up the rst_search RestorationInfo structures. These are the same as
// the rst_info ones except need their own arrays of types and coefficients,
// allocated in av1_alloc_restoration_struct.
for (int i = 0; i < MAX_MB_PLANE; ++i) {
RestorationInfo *search = &cpi->rst_search[i];
RestorationInfo *rsi = &cm->rst_info[i];
search->restoration_tilesize = rsi->restoration_tilesize;
search->procunit_width = rsi->procunit_width;
search->procunit_height = rsi->procunit_height;
av1_alloc_restoration_struct(cm, search, frame_width, frame_height);
#if CONFIG_STRIPED_LOOP_RESTORATION
// We can share boundary buffers between the search info and the main one
search->boundaries = rsi->boundaries;
#endif
}
#endif // CONFIG_LOOP_RESTORATION
alloc_util_frame_buffers(cpi); // TODO(afergs): Remove? Gets called anyways.
init_motion_estimation(cpi);
......
......@@ -435,9 +435,7 @@ typedef struct AV1_COMP {
YV12_BUFFER_CONFIG last_frame_uf;
#if CONFIG_LOOP_RESTORATION
YV12_BUFFER_CONFIG trial_frame_rst;
uint8_t *extra_rstbuf; // Extra buffers used in restoration search
RestorationInfo rst_search[MAX_MB_PLANE]; // Used for encoder side search
#endif // CONFIG_LOOP_RESTORATION
#endif
// Ambient reconstruction err target for force key frames
int64_t ambient_err;
......
This diff is collapsed.
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