Initial changes for forward key frame

Preliminary changes on forward key frame related control. The full
solution will be available after the main piece is landed.

STATS_CHANGED

Change-Id: Ifac204ad15adbbb1f3356db29189850a5260cc11
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 6583998..c9e4e17 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -1128,13 +1128,13 @@
   if (!is_stat_generation_stage(cpi)) {
     // If this is a forward keyframe, mark as a show_existing_frame
     // TODO(bohanli): find a consistent condition for fwd keyframes
-    if (oxcf->kf_cfg.fwd_kf_enabled && (gf_group->index == gf_group->size) &&
+    if (oxcf->kf_cfg.fwd_kf_enabled &&
         gf_group->update_type[gf_group->index] == OVERLAY_UPDATE &&
-        gf_group->arf_index >= 0 && cpi->rc.frames_to_key == 0) {
+        cpi->rc.frames_to_key == 0) {
       frame_params.show_existing_frame = 1;
     } else {
       frame_params.show_existing_frame =
-          ((oxcf->algo_cfg.enable_overlay == 0 || cpi->show_existing_alt_ref) &&
+          (cpi->show_existing_alt_ref &&
            gf_group->update_type[gf_group->index] == OVERLAY_UPDATE) ||
           gf_group->update_type[gf_group->index] == INTNL_OVERLAY_UPDATE;
     }
diff --git a/av1/encoder/pass2_strategy.c b/av1/encoder/pass2_strategy.c
index d974b49..19b3195 100644
--- a/av1/encoder/pass2_strategy.c
+++ b/av1/encoder/pass2_strategy.c
@@ -2750,7 +2750,8 @@
   if (is_stat_consumption_stage(cpi) && !twopass->stats_in) return;
 
   const int update_type = gf_group->update_type[gf_group->index];
-  if (update_type != KF_UPDATE) frame_params->frame_type = INTER_FRAME;
+  frame_params->frame_type = gf_group->frame_type[gf_group->index];
+
   if (rc->frames_since_key > 0) frame_params->frame_type = INTER_FRAME;
 
   if (rc->frames_till_gf_update_due > 0 && !(frame_flags & FRAMEFLAGS_KEY)) {
@@ -2761,13 +2762,6 @@
     // If this is an arf frame then we dont want to read the stats file or
     // advance the input pointer as we already have what we need.
     if (update_type == ARF_UPDATE || update_type == INTNL_ARF_UPDATE) {
-      if (cpi->no_show_fwd_kf) {
-        assert(update_type == ARF_UPDATE);
-        frame_params->frame_type = KEY_FRAME;
-      } else {
-        frame_params->frame_type = INTER_FRAME;
-      }
-
       // Do the firstpass stats indicate that this frame is skippable for the
       // partition search?
       if (cpi->sf.part_sf.allow_partition_search_skip && oxcf->pass == 2) {
@@ -2905,6 +2899,8 @@
   }
   assert(gf_group->index < gf_group->size);
 
+  frame_params->frame_type = gf_group->frame_type[gf_group->index];
+
   // Do the firstpass stats indicate that this frame is skippable for the
   // partition search?
   if (cpi->sf.part_sf.allow_partition_search_skip && oxcf->pass == 2) {