Bring back sframe support

The code that setup sframe support was accidently removed in previous
commit #97803fc7. This commit bring the logic back to restore the
support for sframe.

BUG=aomedia:2540

Change-Id: I106bdf61d163e0b60b8c49cc0d2b7d660bc1c1c6
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index aa2a6f6..197d910 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -1791,6 +1791,39 @@
     this_frame = this_frame_copy;
   } else {
     frame_params->frame_type = INTER_FRAME;
+    const int altref_enabled = is_altref_enabled(cpi);
+    const int sframe_dist = cpi->oxcf.sframe_dist;
+    const int sframe_mode = cpi->oxcf.sframe_mode;
+    const int sframe_enabled = cpi->oxcf.sframe_enabled;
+    const int update_type = gf_group->update_type[gf_group->index];
+    CurrentFrame *const current_frame = &cpi->common.current_frame;
+    if (sframe_enabled) {
+      if (altref_enabled) {
+        if (sframe_mode == 1) {
+          // sframe_mode == 1: insert sframe if it matches altref frame.
+          if (current_frame->frame_number % sframe_dist == 0 &&
+              current_frame->frame_number != 0 && update_type == ARF_UPDATE) {
+            frame_params->frame_type = S_FRAME;
+          }
+        } else {
+          // sframe_mode != 1: if sframe will be inserted at the next available
+          // altref frame
+          if (current_frame->frame_number % sframe_dist == 0 &&
+              current_frame->frame_number != 0) {
+            rc->sframe_due = 1;
+          }
+          if (rc->sframe_due && update_type == ARF_UPDATE) {
+            frame_params->frame_type = S_FRAME;
+            rc->sframe_due = 0;
+          }
+        }
+      } else {
+        if (current_frame->frame_number % sframe_dist == 0 &&
+            current_frame->frame_number != 0) {
+          frame_params->frame_type = S_FRAME;
+        }
+      }
+    }
   }
 
   // Define a new GF/ARF group. (Should always enter here for key frames).