Commit d2bcbb56 authored by Fergus Simpson's avatar Fergus Simpson

frame_superres: Post encode/decode upscaling

This patch implements the post-encode and post-decode upscaling for the
frame superresolution experiment to work.

Upscaling happens after cdef and before loop restoration.

For now, this patch forces on random-superres.

The patch also cleans up some broken rate control hooks from VP9
days, to be brought back later when the resize and superres tools
are stable.

Change-Id: If0a8f69224dfaa0f4ae7703bd429ea2af953c7a6
parent 8e689e4b
......@@ -302,6 +302,8 @@ typedef struct AV1Common {
#if CONFIG_FRAME_SUPERRES
// The numerator of the superres scale; the denominator is fixed.
uint8_t superres_scale_numerator;
int superres_upscaled_width;
int superres_upscaled_height;
#endif // CONFIG_FRAME_SUPERRES
#if CONFIG_LOOP_RESTORATION
RestorationInfo rst_info[MAX_MB_PLANE];
......
......@@ -816,10 +816,10 @@ void av1_highbd_resize_frame444(const uint8_t *const y, int y_stride,
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_HIGHBITDEPTH
static void resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
void av1_resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
YV12_BUFFER_CONFIG *dst, int bd) {
#else
static void resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
void av1_resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
YV12_BUFFER_CONFIG *dst) {
#endif // CONFIG_HIGHBITDEPTH
// TODO(dkovalev): replace YV12_BUFFER_CONFIG with aom_image_t
......@@ -855,8 +855,8 @@ static void resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
YV12_BUFFER_CONFIG *av1_scale_if_required_fast(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *unscaled,
YV12_BUFFER_CONFIG *scaled) {
if (cm->mi_cols * MI_SIZE != unscaled->y_width ||
cm->mi_rows * MI_SIZE != unscaled->y_height) {
if (cm->width != unscaled->y_crop_width ||
cm->height != unscaled->y_crop_height) {
// For 2x2 scaling down.
aom_scale_frame(unscaled, scaled, unscaled->y_buffer, 9, 2, 1, 2, 1, 0);
aom_extend_frame_borders(scaled);
......@@ -869,14 +869,107 @@ YV12_BUFFER_CONFIG *av1_scale_if_required_fast(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *unscaled,
YV12_BUFFER_CONFIG *scaled) {
if (cm->width != unscaled->y_width || cm->height != unscaled->y_height) {
if (cm->width != unscaled->y_crop_width ||
cm->height != unscaled->y_crop_height) {
#if CONFIG_HIGHBITDEPTH
resize_and_extend_frame(unscaled, scaled, (int)cm->bit_depth);
av1_resize_and_extend_frame(unscaled, scaled, (int)cm->bit_depth);
#else
resize_and_extend_frame(unscaled, scaled);
av1_resize_and_extend_frame(unscaled, scaled);
#endif // CONFIG_HIGHBITDEPTH
return scaled;
} else {
return unscaled;
}
}
#if CONFIG_FRAME_SUPERRES
void av1_calculate_superres_size(const AV1_COMMON *cm, int *width,
int *height) {
*width = *width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
*height = *height * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
}
// TODO(afergs): Look for in-place upscaling
// TODO(afergs): aom_ vs av1_ functions? Which can I use?
// Upscale decoded image.
void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool) {
if (av1_superres_unscaled(cm)) return;
YV12_BUFFER_CONFIG copy_buffer;
memset(&copy_buffer, 0, sizeof(copy_buffer));
YV12_BUFFER_CONFIG *const frame_to_show = get_frame_new_buffer(cm);
if (aom_alloc_frame_buffer(&copy_buffer, cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
#ifdef CONFIG_HIGHBITDEPTH
cm->use_highbitdepth,
#endif // CONFIG_HIGHBITDEPTH
AOM_BORDER_IN_PIXELS, cm->byte_alignment))
aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,
"Failed to allocate copy buffer for superres upscaling");
// Copy function assumes the frames are the same size, doesn't copy bit_depth.
aom_yv12_copy_frame(frame_to_show, &copy_buffer);
copy_buffer.bit_depth = frame_to_show->bit_depth;
assert(copy_buffer.y_crop_width == cm->width);
assert(copy_buffer.y_crop_height == cm->height);
// Realloc the current frame buffer at a higher resolution in place.
if (pool != NULL) {
// Use callbacks if on the decoder.
aom_codec_frame_buffer_t *fb =
&pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer;
aom_release_frame_buffer_cb_fn_t release_fb_cb = pool->release_fb_cb;
aom_get_frame_buffer_cb_fn_t cb = pool->get_fb_cb;
void *cb_priv = pool->cb_priv;
// Realloc with callback does not release the frame buffer - release first.
if (release_fb_cb(cb_priv, fb))
aom_internal_error(
&cm->error, AOM_CODEC_MEM_ERROR,
"Failed to free current frame buffer before superres upscaling");
if (aom_realloc_frame_buffer(
frame_to_show, cm->superres_upscaled_width,
cm->superres_upscaled_height, cm->subsampling_x, cm->subsampling_y,
#ifdef CONFIG_HIGHBITDEPTH
cm->use_highbitdepth,
#endif // CONFIG_HIGHBITDEPTH
AOM_BORDER_IN_PIXELS, cm->byte_alignment, fb, cb, cb_priv))
aom_internal_error(
&cm->error, AOM_CODEC_MEM_ERROR,
"Failed to allocate current frame buffer for superres upscaling");
} else {
// Don't use callbacks on the encoder.
if (aom_alloc_frame_buffer(frame_to_show, cm->superres_upscaled_width,
cm->superres_upscaled_height, cm->subsampling_x,
cm->subsampling_y,
#ifdef CONFIG_HIGHBITDEPTH
cm->use_highbitdepth,
#endif // CONFIG_HIGHBITDEPTH
AOM_BORDER_IN_PIXELS, cm->byte_alignment))
aom_internal_error(
&cm->error, AOM_CODEC_MEM_ERROR,
"Failed to reallocate current frame buffer for superres upscaling");
}
// TODO(afergs): verify frame_to_show is correct after realloc
// encoder:
// decoder:
frame_to_show->bit_depth = copy_buffer.bit_depth;
assert(frame_to_show->y_crop_width == cm->superres_upscaled_width);
assert(frame_to_show->y_crop_height == cm->superres_upscaled_height);
// Scale up and back into frame_to_show.
assert(frame_to_show->y_crop_width != cm->width);
assert(frame_to_show->y_crop_height != cm->height);
#if CONFIG_HIGHBITDEPTH
av1_resize_and_extend_frame(&copy_buffer, frame_to_show, (int)cm->bit_depth);
#else
av1_resize_and_extend_frame(&copy_buffer, frame_to_show);
#endif // CONFIG_HIGHBITDEPTH
// Free the copy buffer
aom_free_frame_buffer(&copy_buffer);
}
#endif // CONFIG_FRAME_SUPERRES
......@@ -63,6 +63,14 @@ void av1_highbd_resize_frame444(const uint8_t *const y, int y_stride,
int owidth, int bd);
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_HIGHBITDEPTH
void av1_resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
YV12_BUFFER_CONFIG *dst, int bd);
#else
void av1_resize_and_extend_frame(const YV12_BUFFER_CONFIG *src,
YV12_BUFFER_CONFIG *dst);
#endif // CONFIG_HIGHBITDEPTH
YV12_BUFFER_CONFIG *av1_scale_if_required_fast(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *unscaled,
YV12_BUFFER_CONFIG *scaled);
......@@ -71,6 +79,21 @@ YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm,
YV12_BUFFER_CONFIG *unscaled,
YV12_BUFFER_CONFIG *scaled);
#if CONFIG_FRAME_SUPERRES
// This is the size after superress scaling, which could be 1:1.
// Superres scaling happens after regular downscaling.
// TODO(afergs): Limit overall reduction to 1/2 of the original size
void av1_calculate_superres_size(const AV1_COMMON *cm, int *width, int *height);
void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool);
// Returns 1 if a superres upscaled frame is unscaled and 0 otherwise.
static INLINE int av1_superres_unscaled(const AV1_COMMON *cm) {
return (cm->superres_scale_numerator == SUPERRES_SCALE_DENOMINATOR);
}
#endif // CONFIG_FRAME_SUPERRES
#ifdef __cplusplus
} // extern "C"
#endif
......
......@@ -49,6 +49,9 @@
#include "av1/common/quant_common.h"
#include "av1/common/reconinter.h"
#include "av1/common/reconintra.h"
#if CONFIG_FRAME_SUPERRES
#include "av1/common/resize.h"
#endif // CONFIG_FRAME_SUPERRES
#include "av1/common/seg_common.h"
#include "av1/common/thread_common.h"
#include "av1/common/tile_common.h"
......@@ -2203,6 +2206,7 @@ static void decode_block(AV1Decoder *const pbi, MACROBLOCKD *const xd,
partition,
#endif
bsize);
#if !(CONFIG_MOTION_VAR && CONFIG_NCOBMC)
#if CONFIG_SUPERTX
if (!supertx_enabled)
......@@ -3020,31 +3024,30 @@ static InterpFilter read_frame_interp_filter(struct aom_read_bit_buffer *rb) {
}
static void setup_render_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
#if CONFIG_FRAME_SUPERRES
cm->render_width = cm->superres_upscaled_width;
cm->render_height = cm->superres_upscaled_height;
#else
cm->render_width = cm->width;
cm->render_height = cm->height;
#endif // CONFIG_FRAME_SUPERRES
if (aom_rb_read_bit(rb))
av1_read_frame_size(rb, &cm->render_width, &cm->render_height);
}
#if CONFIG_FRAME_SUPERRES
// TODO(afergs): make "struct aom_read_bit_buffer *const rb"?
static void setup_superres_size(AV1_COMMON *const cm,
struct aom_read_bit_buffer *rb, int *width,
int *height) {
// TODO(afergs): Save input resolution - it's the upscaled resolution
static void setup_superres(AV1_COMMON *const cm, struct aom_read_bit_buffer *rb,
int *width, int *height) {
cm->superres_upscaled_width = *width;
cm->superres_upscaled_height = *height;
if (aom_rb_read_bit(rb)) {
cm->superres_scale_numerator =
(uint8_t)aom_rb_read_literal(rb, SUPERRES_SCALE_BITS);
cm->superres_scale_numerator += SUPERRES_SCALE_NUMERATOR_MIN;
// Don't edit cm->width or cm->height directly, or the buffers won't get
// resized correctly
// TODO(afergs): Should the render resolution not be modified? It's the same
// by default (ie. when it isn't sent)...
// resize_context_buffers() will change cm->width to equal cm->render_width,
// then they'll be the same again
*width = *width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
*height =
*width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
av1_calculate_superres_size(cm, width, height);
} else {
// 1:1 scaling - ie. no scaling, scale not provided
cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
......@@ -3097,10 +3100,10 @@ static void setup_frame_size(AV1_COMMON *cm, struct aom_read_bit_buffer *rb) {
int width, height;
BufferPool *const pool = cm->buffer_pool;
av1_read_frame_size(rb, &width, &height);
setup_render_size(cm, rb);
#if CONFIG_FRAME_SUPERRES
setup_superres_size(cm, rb, &width, &height);
setup_superres(cm, rb, &width, &height);
#endif // CONFIG_FRAME_SUPERRES
setup_render_size(cm, rb);
resize_context_buffers(cm, width, height);
lock_buffer_pool(pool);
......@@ -3149,6 +3152,9 @@ static void setup_frame_size_with_refs(AV1_COMMON *cm,
height = buf->y_crop_height;
cm->render_width = buf->render_width;
cm->render_height = buf->render_height;
#if CONFIG_FRAME_SUPERRES
setup_superres(cm, rb, &width, &height);
#endif // CONFIG_FRAME_SUPERRES
found = 1;
break;
}
......@@ -3156,10 +3162,10 @@ static void setup_frame_size_with_refs(AV1_COMMON *cm,
if (!found) {
av1_read_frame_size(rb, &width, &height);
setup_render_size(cm, rb);
#if CONFIG_FRAME_SUPERRES
setup_superres_size(cm, rb, &width, &height);
setup_superres(cm, rb, &width, &height);
#endif // CONFIG_FRAME_SUPERRES
setup_render_size(cm, rb);
}
if (width <= 0 || height <= 0)
......@@ -5186,6 +5192,19 @@ static void make_update_tile_list_dec(AV1Decoder *pbi, int tile_rows,
}
#endif
#if CONFIG_FRAME_SUPERRES
void superres_post_decode(AV1Decoder *pbi) {
AV1_COMMON *const cm = &pbi->common;
BufferPool *const pool = cm->buffer_pool;
if (av1_superres_unscaled(cm)) return;
lock_buffer_pool(pool);
av1_superres_upscale(cm, pool);
unlock_buffer_pool(pool);
}
#endif // CONFIG_FRAME_SUPERRES
void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data,
const uint8_t *data_end, const uint8_t **p_data_end) {
AV1_COMMON *const cm = &pbi->common;
......@@ -5281,14 +5300,23 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data,
#if CONFIG_TEMPMV_SIGNALING
if (cm->use_prev_frame_mvs) {
assert(!cm->error_resilient_mode && cm->prev_frame &&
cm->width == last_fb_ref_buf->buf->y_width &&
cm->height == last_fb_ref_buf->buf->y_height &&
#if CONFIG_FRAME_SUPERRES
cm->width == cm->last_width && cm->height == cm->last_height &&
#else
cm->width == last_fb_ref_buf->buf->y_crop_width &&
cm->height == last_fb_ref_buf->buf->y_crop_height &&
#endif // CONFIG_FRAME_SUPERRES
!cm->prev_frame->intra_only);
}
#else
cm->use_prev_frame_mvs = !cm->error_resilient_mode && cm->prev_frame &&
#if CONFIG_FRAME_SUPERRES
cm->width == cm->last_width &&
cm->height == cm->last_height &&
#else
cm->width == cm->prev_frame->buf.y_crop_width &&
cm->height == cm->prev_frame->buf.y_crop_height &&
#endif // CONFIG_FRAME_SUPERRES
!cm->last_intra_only && cm->last_show_frame &&
(cm->last_frame_type != KEY_FRAME);
#endif // CONFIG_TEMPMV_SIGNALING
......@@ -5361,6 +5389,10 @@ void av1_decode_frame(AV1Decoder *pbi, const uint8_t *data,
}
#endif // CONFIG_CDEF
#if CONFIG_FRAME_SUPERRES
superres_post_decode(pbi);
#endif // CONFIG_FRAME_SUPERRES
#if CONFIG_LOOP_RESTORATION
if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
......
......@@ -444,7 +444,10 @@ int av1_receive_compressed_data(AV1Decoder *pbi, size_t size,
// border.
if (pbi->dec_tile_row == -1 && pbi->dec_tile_col == -1)
#endif // CONFIG_EXT_TILE
aom_extend_frame_inner_borders(cm->frame_to_show);
// TODO(debargha): Fix encoder side mv range, so that we can use the
// inner border extension. As of now use the larger extension.
// aom_extend_frame_inner_borders(cm->frame_to_show);
aom_extend_frame_borders(cm->frame_to_show);
aom_clear_system_state();
......
......@@ -352,10 +352,7 @@ void av1_cyclic_refresh_check_golden_update(AV1_COMP *const cpi) {
// For video conference clips, if the background has high motion in current
// frame because of the camera movement, set this frame as the golden frame.
// Use 70% and 5% as the thresholds for golden frame refreshing.
// Also, force this frame as a golden update frame if this frame will change
// the resolution (av1_resize_pending != 0).
if (av1_resize_pending(cpi) ||
(cnt1 * 10 > (70 * rows * cols) && cnt2 * 20 < cnt1)) {
if (cnt1 * 10 > (70 * rows * cols) && cnt2 * 20 < cnt1) {
av1_cyclic_refresh_set_golden_update(cpi);
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
......
......@@ -4172,8 +4172,7 @@ static uint32_t write_tiles(AV1_COMP *const cpi, uint8_t *const dst,
static void write_render_size(const AV1_COMMON *cm,
struct aom_write_bit_buffer *wb) {
const int scaling_active =
cm->width != cm->render_width || cm->height != cm->render_height;
const int scaling_active = !av1_resize_unscaled(cm);
aom_wb_write_bit(wb, scaling_active);
if (scaling_active) {
aom_wb_write_literal(wb, cm->render_width - 1, 16);
......@@ -4189,7 +4188,6 @@ static void write_superres_scale(const AV1_COMMON *const cm,
aom_wb_write_bit(wb, 0); // no scaling
} else {
aom_wb_write_bit(wb, 1); // scaling, write scale factor
// TODO(afergs): write factor to the compressed header instead
aom_wb_write_literal(
wb, cm->superres_scale_numerator - SUPERRES_SCALE_NUMERATOR_MIN,
SUPERRES_SCALE_BITS);
......@@ -4199,13 +4197,15 @@ static void write_superres_scale(const AV1_COMMON *const cm,
static void write_frame_size(const AV1_COMMON *cm,
struct aom_write_bit_buffer *wb) {
aom_wb_write_literal(wb, cm->width - 1, 16);
aom_wb_write_literal(wb, cm->height - 1, 16);
write_render_size(cm, wb);
#if CONFIG_FRAME_SUPERRES
aom_wb_write_literal(wb, cm->superres_upscaled_width - 1, 16);
aom_wb_write_literal(wb, cm->superres_upscaled_height - 1, 16);
write_superres_scale(cm, wb);
#else
aom_wb_write_literal(wb, cm->width - 1, 16);
aom_wb_write_literal(wb, cm->height - 1, 16);
#endif // CONFIG_FRAME_SUPERRES
write_render_size(cm, wb);
}
static void write_frame_size_with_refs(AV1_COMP *cpi,
......@@ -4218,20 +4218,26 @@ static void write_frame_size_with_refs(AV1_COMP *cpi,
YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, ref_frame);
if (cfg != NULL) {
#if CONFIG_FRAME_SUPERRES
found = cm->superres_upscaled_width == cfg->y_crop_width &&
cm->superres_upscaled_height == cfg->y_crop_height;
#else
found =
cm->width == cfg->y_crop_width && cm->height == cfg->y_crop_height;
#endif
found &= cm->render_width == cfg->render_width &&
cm->render_height == cfg->render_height;
}
aom_wb_write_bit(wb, found);
if (found) {
#if CONFIG_FRAME_SUPERRES
write_superres_scale(cm, wb);
#endif // CONFIG_FRAME_SUPERRES
break;
}
}
if (!found) {
write_frame_size(cm, wb);
}
if (!found) write_frame_size(cm, wb);
}
static void write_sync_code(struct aom_write_bit_buffer *wb) {
......@@ -4370,11 +4376,6 @@ static void write_uncompressed_header(AV1_COMP *cpi,
}
#endif
#if CONFIG_FRAME_SUPERRES
// TODO(afergs): Remove - this is just to stop superres from breaking
cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
#endif // CONFIG_FRAME_SUPERRES
if (cm->frame_type == KEY_FRAME) {
write_sync_code(wb);
write_bitdepth_colorspace_sampling(cm, wb);
......
......@@ -4860,17 +4860,31 @@ static void encode_frame_internal(AV1_COMP *cpi) {
#if CONFIG_TEMPMV_SIGNALING
if (cm->prev_frame) {
cm->use_prev_frame_mvs &= !cm->error_resilient_mode &&
cm->width == cm->prev_frame->buf.y_width &&
cm->height == cm->prev_frame->buf.y_height &&
#if CONFIG_FRAME_SUPERRES
cm->width == cm->last_width &&
cm->height == cm->last_height &&
#else
cm->width == cm->prev_frame->buf.y_crop_width &&
cm->height == cm->prev_frame->buf.y_crop_height &&
#endif // CONFIG_FRAME_SUPERRES
!cm->intra_only && !cm->prev_frame->intra_only;
} else {
cm->use_prev_frame_mvs = 0;
}
#else
cm->use_prev_frame_mvs = !cm->error_resilient_mode && cm->prev_frame &&
if (cm->prev_frame) {
cm->use_prev_frame_mvs = !cm->error_resilient_mode &&
#if CONFIG_FRAME_SUPERRES
cm->width == cm->last_width &&
cm->height == cm->last_height &&
#else
cm->width == cm->prev_frame->buf.y_crop_width &&
cm->height == cm->prev_frame->buf.y_crop_height &&
#endif // CONFIG_FRAME_SUPERRES
!cm->intra_only && cm->last_show_frame;
} else {
cm->use_prev_frame_mvs = 0;
}
#endif // CONFIG_TEMPMV_SIGNALING
// Special case: set prev_mi to NULL when the previous mode info
......
......@@ -2099,10 +2099,6 @@ AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
cpi->resize_state = 0;
cpi->resize_avg_qp = 0;
cpi->resize_buffer_underflow = 0;
cpi->resize_scale_num = 16;
cpi->resize_scale_den = 16;
cpi->resize_next_scale_num = 16;
cpi->resize_next_scale_den = 16;
cpi->common.buffer_pool = pool;
......@@ -2450,6 +2446,8 @@ AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
av1_loop_filter_init(cm);
#if CONFIG_FRAME_SUPERRES
cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
cm->superres_upscaled_width = oxcf->scaled_frame_width;
cm->superres_upscaled_height = oxcf->scaled_frame_height;
#endif // CONFIG_FRAME_SUPERRES
#if CONFIG_LOOP_RESTORATION
av1_loop_restoration_precal();
......@@ -3380,61 +3378,6 @@ void av1_update_reference_frames(AV1_COMP *cpi) {
#endif // DUMP_REF_FRAME_IMAGES
}
static void loopfilter_frame(AV1_COMP *cpi, AV1_COMMON *cm) {
MACROBLOCKD *xd = &cpi->td.mb.e_mbd;
struct loopfilter *lf = &cm->lf;
if (is_lossless_requested(&cpi->oxcf)) {
lf->filter_level = 0;
} else {
struct aom_usec_timer timer;
aom_clear_system_state();
aom_usec_timer_start(&timer);
av1_pick_filter_level(cpi->source, cpi, cpi->sf.lpf_pick);
aom_usec_timer_mark(&timer);
cpi->time_pick_lpf += aom_usec_timer_elapsed(&timer);
}
if (lf->filter_level > 0) {
#if CONFIG_VAR_TX || CONFIG_EXT_PARTITION || CONFIG_CB4X4
av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
#else
if (cpi->num_workers > 1)
av1_loop_filter_frame_mt(cm->frame_to_show, cm, xd->plane,
lf->filter_level, 0, 0, cpi->workers,
cpi->num_workers, &cpi->lf_row_sync);
else
av1_loop_filter_frame(cm->frame_to_show, cm, xd, lf->filter_level, 0, 0);
#endif
}
#if CONFIG_CDEF
if (is_lossless_requested(&cpi->oxcf)) {
cm->cdef_bits = 0;
cm->cdef_strengths[0] = 0;
cm->nb_cdef_strengths = 1;
} else {
// Find cm->dering_level, cm->clpf_strength_u and cm->clpf_strength_v
av1_cdef_search(cm->frame_to_show, cpi->source, cm, xd,
cpi->oxcf.speed > 0);
// Apply the filter
av1_cdef_frame(cm->frame_to_show, cm, xd);
}
#endif
#if CONFIG_LOOP_RESTORATION
av1_pick_filter_restoration(cpi->source, cpi, cpi->sf.lpf_pick);
if (cm->rst_info[0].frame_restoration_type != RESTORE_NONE ||
cm->rst_info[1].frame_restoration_type != RESTORE_NONE ||
cm->rst_info[2].frame_restoration_type != RESTORE_NONE) {
av1_loop_restoration_frame(cm->frame_to_show, cm, cm->rst_info, 7, 0, NULL);
}
#endif // CONFIG_LOOP_RESTORATION
aom_extend_frame_inner_borders(cm->frame_to_show);
}
static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, int buffer_idx) {
RefCntBuffer *const new_fb_ptr = &cm->buffer_pool->frame_bufs[buffer_idx];
if (new_fb_ptr->mvs == NULL || new_fb_ptr->mi_rows < cm->mi_rows ||
......@@ -3789,56 +3732,19 @@ static void set_restoration_tilesize(int width, int height,
}
#endif // CONFIG_LOOP_RESTORATION
static void set_scaled_size(AV1_COMP *cpi) {
AV1_COMMON *const cm = &cpi->common;
AV1EncoderConfig *const oxcf = &cpi->oxcf;
// TODO(afergs): Replace with call to av1_resize_pending? Could replace
// scaled_size_set as well.
// TODO(afergs): Realistically, if resize_pending is true, then the other
// conditions must already be satisfied.
// Try this first:
// av1_resize_pending &&
// (DYNAMIC && (1 Pass CBR || 2 Pass VBR)
// STATIC && FIRST_FRAME)
// Really, av1_resize_pending should just reflect the above.
// TODO(afergs): Allow fixed resizing in AOM_CBR mode?
// 2 Pass VBR: Resize if fixed resize and first frame, or dynamic resize and
// a resize is pending.
// 1 Pass CBR: Resize if dynamic resize and resize pending.
if ((oxcf->pass == 2 && oxcf->rc_mode == AOM_VBR &&
((oxcf->resize_mode == RESIZE_FIXED && cm->current_video_frame == 0) ||
(oxcf->resize_mode == RESIZE_DYNAMIC && av1_resize_pending(cpi)))) ||
(oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR &&
oxcf->resize_mode == RESIZE_DYNAMIC && av1_resize_pending(cpi))) {
// TODO(afergs): This feels hacky... Should it just set? Should
// av1_set_next_scaled_size be a library function?
av1_calculate_next_scaled_size(cpi, &oxcf->scaled_frame_width,
&oxcf->scaled_frame_height);
}
}
static void set_frame_size(AV1_COMP *cpi, int width, int height) {
int ref_frame;
AV1_COMMON *const cm = &cpi->common;
AV1EncoderConfig *const oxcf = &cpi->oxcf;
MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
int ref_frame;
if (width != cm->width || height != cm->height) {
// There has been a change in the encoded frame size
av1_set_size_literal(cpi, width, height);
// TODO(agrange) Scale cpi->max_mv_magnitude if frame-size has changed.
// TODO(afergs): Make condition just (pass == 0) or (rc_mode == CBR) -
// UNLESS CBR starts allowing FIXED resizing. Then the resize
// mode will need to get checked too.
if (oxcf->pass == 0 && oxcf->rc_mode == AOM_CBR &&
oxcf->resize_mode == RESIZE_DYNAMIC)
set_mv_search_params(cpi); // TODO(afergs): Needed? Caller calls after...
set_mv_search_params(cpi);
}
#if !CONFIG_XIPHRC
if (oxcf->pass == 2) {
if (cpi->oxcf.pass == 2) {
av1_set_target_rate(cpi);
}
#endif
......@@ -3857,6 +3763,7 @@ static void set_frame_size(AV1_COMP *cpi, int width, int height) {
"Failed to allocate frame buffer");
#if CONFIG_LOOP_RESTORATION
// TODO(afergs): Use cm->superres_upscaled_(width|height)
set_restoration_tilesize(cm->width, cm->height, cm->rst_info);
for (int i = 0; i < MAX_MB_PLANE; ++i)
cm->rst_info[i].frame_restoration_type = RESTORE_NONE;
......@@ -3915,16 +3822,124 @@ static void set_frame_size(AV1_COMP *cpi, int width, int height) {
}
static void setup_frame_size(AV1_COMP *cpi) {
set_scaled_size(cpi);
#if CONFIG_FRAME_SUPERRES
int encode_width;
int encode_height;
av1_calculate_superres_size(cpi, &encode_width, &encode_height);
av1_calculate_next_scaled_size(cpi, &encode_width, &encode_height);
#if CONFIG_FRAME_SUPERRES
AV1_COMMON *cm = &cpi->common;
cm->superres_upscaled_width = encode_width;