rtc: Fix prediction on keyframes for spatial layers

On superframes whose base is key: fix the reference
predicton structure so that the SL layer (for SL > 0)
only does the inter-layer prediction from the SL-1 layer.
This requires fixes to the sample encoder and in the
nonrd_pickmode.

In the current code SL2 was either predicting only from
SL0 (for ksvc), or it was predicting from both SL0 & SL1
(in non-ksvc mode), which was not the intended behavior.
So this fix improves the key frame quality for ksvc and
reduces the encode_time for non-ksvc.

Change-Id: Ifde750c741b53b42e4f27d493945036fb7e0e334
diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 8d96b86..2b3adcb 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -1798,8 +1798,9 @@
   int use_alt_ref_frame =
       cpi->ppi->use_svc || cpi->sf.rt_sf.use_nonrd_altref_frame;
   int use_golden_ref_frame = 1;
+  int use_last_ref_frame = 1;
 
-  use_ref_frame[LAST_FRAME] = 1;  // we never skip LAST
+  use_ref_frame[LAST_FRAME] = 1;
 
   if (cpi->rc.frames_since_golden == 0 && gf_temporal_ref) {
     use_golden_ref_frame = 0;
@@ -1836,8 +1837,14 @@
   use_golden_ref_frame =
       cpi->ref_frame_flags & AOM_GOLD_FLAG ? use_golden_ref_frame : 0;
 
+  if (cpi->ppi->use_svc)
+    use_last_ref_frame =
+        cpi->ref_frame_flags & AOM_LAST_FLAG ? use_last_ref_frame : 0;
+
   use_ref_frame[ALTREF_FRAME] = use_alt_ref_frame;
   use_ref_frame[GOLDEN_FRAME] = use_golden_ref_frame;
+  use_ref_frame[LAST_FRAME] = use_last_ref_frame;
+  assert(use_last_ref_frame || use_golden_ref_frame || use_alt_ref_frame);
 }
 
 /*!\brief Estimates best intra mode for inter mode search