Add UV wiener loop restoration

Enables Wiener based loop restoration only for the UV
frames. The selfguided and domaintranform filters do not
work very well for UV components, hence they are disabled.
For each UV frame a single set of wiener parameters are
sent. They are applied tile-wise, but all tiles use the
same parameters.

BDRATE (Global PSNR) results:
-----------------------------
lowres: -1.266% (up from -0.666%, good improvement)
midres: -1.815% (up from -1.792%, tiny improvement)

Tiling on UV components will be explored subsequently.

Change-Id: Ib5be93121c4e88e05edf3c36c46488df3cfcd1e2
diff --git a/av1/encoder/bitstream.c b/av1/encoder/bitstream.c
index 6152652..9e153c5 100644
--- a/av1/encoder/bitstream.c
+++ b/av1/encoder/bitstream.c
@@ -3022,8 +3022,9 @@
 #if CONFIG_LOOP_RESTORATION
 static void encode_restoration_mode(AV1_COMMON *cm,
                                     struct aom_write_bit_buffer *wb) {
-  RestorationInfo *rst = &cm->rst_info;
-  switch (rst->frame_restoration_type) {
+  int p;
+  RestorationInfo *rsi = &cm->rst_info[0];
+  switch (rsi->frame_restoration_type) {
     case RESTORE_NONE:
       aom_wb_write_bit(wb, 0);
       aom_wb_write_bit(wb, 0);
@@ -3048,6 +3049,14 @@
       break;
     default: assert(0);
   }
+  for (p = 1; p < MAX_MB_PLANE; ++p) {
+    rsi = &cm->rst_info[p];
+    switch (rsi->frame_restoration_type) {
+      case RESTORE_NONE: aom_wb_write_bit(wb, 0); break;
+      case RESTORE_WIENER: aom_wb_write_bit(wb, 1); break;
+      default: assert(0);
+    }
+  }
 }
 
 static void write_wiener_filter(WienerInfo *wiener_info, aom_writer *wb) {
@@ -3079,8 +3088,8 @@
 }
 
 static void encode_restoration(AV1_COMMON *cm, aom_writer *wb) {
-  int i;
-  RestorationInfo *rsi = &cm->rst_info;
+  int i, p;
+  RestorationInfo *rsi = &cm->rst_info[0];
   if (rsi->frame_restoration_type != RESTORE_NONE) {
     if (rsi->frame_restoration_type == RESTORE_SWITCHABLE) {
       // RESTORE_SWITCHABLE
@@ -3121,6 +3130,14 @@
       }
     }
   }
+  for (p = 1; p < MAX_MB_PLANE; ++p) {
+    rsi = &cm->rst_info[p];
+    if (rsi->frame_restoration_type == RESTORE_WIENER) {
+      write_wiener_filter(&rsi->wiener_info[0], wb);
+    } else if (rsi->frame_restoration_type != RESTORE_NONE) {
+      assert(0);
+    }
+  }
 }
 #endif  // CONFIG_LOOP_RESTORATION