Revert "frame_superres: Send scale every frame"

This reverts commit 846d67dd67a348650fa42bd97288d9642bd1cc26.

Writing the scale every frame was not the right decision. The correct
thing to do will be also writing the superres scale when the size is
set using a previous frame.

Change-Id: I0402e7f6d2b89ac7c386f81e8628198d22db5066
diff --git a/av1/decoder/decodeframe.c b/av1/decoder/decodeframe.c
index 0f81522..077d16b 100644
--- a/av1/decoder/decodeframe.c
+++ b/av1/decoder/decodeframe.c
@@ -2885,12 +2885,23 @@
 
 #if CONFIG_FRAME_SUPERRES
 // TODO(afergs): make "struct aom_read_bit_buffer *const rb"?
-static void setup_superres_scale(AV1_COMMON *const cm,
-                                 struct aom_read_bit_buffer *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
   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;
   } else {
     // 1:1 scaling - ie. no scaling, scale not provided
     cm->superres_scale_numerator = SUPERRES_SCALE_DENOMINATOR;
@@ -2943,8 +2954,11 @@
   int width, height;
   BufferPool *const pool = cm->buffer_pool;
   av1_read_frame_size(rb, &width, &height);
-  resize_context_buffers(cm, 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);
 
   lock_buffer_pool(pool);
   if (aom_realloc_frame_buffer(
@@ -3000,6 +3014,9 @@
   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);
+#endif  // CONFIG_FRAME_SUPERRES
   }
 
   if (width <= 0 || height <= 0)
@@ -4414,9 +4431,6 @@
   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 71d544a..6f01afe 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -4128,7 +4128,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);
@@ -4142,6 +4142,9 @@
   aom_wb_write_literal(wb, cm->height - 1, 16);
 
   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,
@@ -4443,9 +4446,6 @@
   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);