frame_superres: Send scale every frame
The superres scale was accidentally only sent if the current frame was
a key frame or if the current resolution was not used by any of the
reference frames. This patch separates the superres scale from the
current resolution to simplify its coding and makes sure that it is
written for every frame.
Change-Id: I419912c833cdc9670fc5a8ea1d67393d72ce402d
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 7d13dc3..2221ea4 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2778,25 +2778,12 @@
#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) {
- cm->superres_width = cm->width;
- cm->superres_height = cm->height;
+static void setup_superres_scale(AV1_COMMON *const cm,
+ struct aom_read_bit_buffer *rb) {
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 =
- cm->width * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
- *height =
- cm->height * cm->superres_scale_numerator / SUPERRES_SCALE_DENOMINATOR;
} else {
// 1:1 scaling - ie. no scaling, scale not provided
cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
@@ -2849,11 +2836,8 @@
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);
-#endif // CONFIG_FRAME_SUPERRES
resize_context_buffers(cm, width, height);
+ setup_render_size(cm, rb);
lock_buffer_pool(pool);
if (aom_realloc_frame_buffer(
@@ -4301,6 +4285,9 @@
set_sb_size(cm, BLOCK_64X64);
#endif // CONFIG_EXT_PARTITION
+#if CONFIG_FRAME_SUPERRES
+ setup_superres_scale(cm, rb);
+#endif // CONFIG_FRAME_SUPERRES
setup_loopfilter(cm, rb);
#if CONFIG_CDEF
setup_cdef(cm, rb);
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index ef665f6..bba481c 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -4230,7 +4230,7 @@
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
+ // 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);
@@ -4240,27 +4240,10 @@
static void write_frame_size(const AV1_COMMON *cm,
struct aom_write_bit_buffer *wb) {
-#if CONFIG_FRAME_SUPERRES
- // If SUPERRES scaling is happening, write the full resolution instead of the
- // downscaled resolution. The decoder will reduce this resolution itself.
- if (cm->superres_scale_numerator != SUPERRES_SCALE_DENOMINATOR) {
- aom_wb_write_literal(wb, cm->superres_width - 1, 16);
- aom_wb_write_literal(wb, cm->superres_height - 1, 16);
- } else {
-#endif // CONFIG_FRAME_SUPERRES
- aom_wb_write_literal(wb, cm->width - 1, 16);
- aom_wb_write_literal(wb, cm->height - 1, 16);
-#if CONFIG_FRAME_SUPERRES
- }
-#endif // CONFIG_FRAME_SUPERRES
+ aom_wb_write_literal(wb, cm->width - 1, 16);
+ aom_wb_write_literal(wb, cm->height - 1, 16);
- // TODO(afergs): Also write something different to render_size?
- // When superres scales, they'll be almost guaranteed to be
- // different on the other side.
write_render_size(cm, wb);
-#if CONFIG_FRAME_SUPERRES
- write_superres_scale(cm, wb);
-#endif // CONFIG_FRAME_SUPERRES
}
static void write_frame_size_with_refs(AV1_COMP *cpi,
@@ -4540,6 +4523,9 @@
assert(cm->sb_size == BLOCK_64X64);
#endif // CONFIG_EXT_PARTITION
+#if CONFIG_FRAME_SUPERRES
+ write_superres_scale(cm, wb);
+#endif // CONFIG_FRAME_SUPERRES
encode_loopfilter(cm, wb);
#if CONFIG_CDEF
encode_cdef(cm, wb);