shithub: libvpx

Download patch

ref: ae365775e77627d474fa26ae0367c3bb90f4ca1e
parent: ddafa2a11e72791c1e7dc84ed4deea4319fc069b
author: Marco Paniconi <[email protected]>
date: Wed Mar 13 09:46:12 EDT 2019

vp9-svc: Reorganize the simulcast mode

Set the lst/gld/alt_fb_idx and refresh flags for
key frames at the start of encoding (in svc_set_params).
This then avoids new code/function in update_references()
and in copy_flags_ref_update().

Change-Id: Id3503c0c628540c20f11a540c118c4ee4cf04848

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -3114,11 +3114,7 @@
 }
 
 void vp9_update_reference_frames(VP9_COMP *cpi) {
-  if (cpi->svc.simulcast_mode && is_one_pass_cbr_svc(cpi) &&
-      cpi->common.frame_type == KEY_FRAME)
-    vp9_svc_update_ref_frame_key_simulcast(cpi);
-  else
-    update_ref_frames(cpi);
+  update_ref_frames(cpi);
 
 #if CONFIG_VP9_TEMPORAL_DENOISING
   vp9_denoiser_update_ref_frame(cpi);
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -2209,11 +2209,47 @@
     }
   }
 
-  if (svc->simulcast_mode && svc->spatial_layer_id > 0 &&
-      svc->layer_context[layer].is_key_frame == 1) {
-    cm->frame_type = KEY_FRAME;
-    cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
-    target = calc_iframe_target_size_one_pass_cbr(cpi);
+  if (svc->simulcast_mode) {
+    if (svc->spatial_layer_id > 0 &&
+        svc->layer_context[layer].is_key_frame == 1) {
+      cm->frame_type = KEY_FRAME;
+      cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
+      target = calc_iframe_target_size_one_pass_cbr(cpi);
+    }
+    // Set the buffer idx and refresh flags for key frames in simulcast mode.
+    // Note the buffer slot for long-term reference is set below (line 2255),
+    // and alt_ref is used for that on key frame. So use last and golden for
+    // the other two normal slots.
+    if (cm->frame_type == KEY_FRAME) {
+      if (svc->number_spatial_layers == 2) {
+        if (svc->spatial_layer_id == 0) {
+          cpi->lst_fb_idx = 0;
+          cpi->gld_fb_idx = 2;
+          cpi->alt_fb_idx = 6;
+        } else if (svc->spatial_layer_id == 1) {
+          cpi->lst_fb_idx = 1;
+          cpi->gld_fb_idx = 3;
+          cpi->alt_fb_idx = 6;
+        }
+      } else if (svc->number_spatial_layers == 3) {
+        if (svc->spatial_layer_id == 0) {
+          cpi->lst_fb_idx = 0;
+          cpi->gld_fb_idx = 3;
+          cpi->alt_fb_idx = 6;
+        } else if (svc->spatial_layer_id == 1) {
+          cpi->lst_fb_idx = 1;
+          cpi->gld_fb_idx = 4;
+          cpi->alt_fb_idx = 6;
+        } else if (svc->spatial_layer_id == 2) {
+          cpi->lst_fb_idx = 2;
+          cpi->gld_fb_idx = 5;
+          cpi->alt_fb_idx = 7;
+        }
+      }
+      cpi->ext_refresh_last_frame = 1;
+      cpi->ext_refresh_golden_frame = 1;
+      cpi->ext_refresh_alt_ref_frame = 1;
+    }
   }
 
   // Check if superframe contains a sync layer request.
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -733,26 +733,6 @@
     }
   }
 
-  if (svc->simulcast_mode && cpi->common.frame_type == KEY_FRAME) {
-    const int index = svc->number_spatial_layers == 3 ? sl - 1 : sl;
-    const int ltf = svc->buffer_gf_temporal_ref[index].idx;
-    if (svc->number_spatial_layers == 2) {
-      if (sl == 0)
-        svc->update_buffer_slot[sl] = 1 + 4;  // 0, 2
-      else if (sl == 1)
-        svc->update_buffer_slot[sl] = 2 + 8;  // 1, 3
-    } else if (svc->number_spatial_layers == 3) {
-      if (sl == 0)
-        svc->update_buffer_slot[sl] = 1 + 8;  // 0, 3
-      else if (sl == 1)
-        svc->update_buffer_slot[sl] = 2 + 16;  // 1, 4
-      else if (sl == 2)
-        svc->update_buffer_slot[sl] = 4 + 32;  // 2, 5
-    }
-    if (svc->use_gf_temporal_ref_current_layer)
-      svc->update_buffer_slot[sl] += (1 << ltf);
-  }
-
   // TODO(jianj): Remove these 3, deprecated.
   svc->update_last[sl] = (uint8_t)cpi->refresh_last_frame;
   svc->update_golden[sl] = (uint8_t)cpi->refresh_golden_frame;
@@ -1233,44 +1213,6 @@
   }
 }
 
-void vp9_svc_update_ref_frame_key_simulcast(VP9_COMP *const cpi) {
-  VP9_COMMON *const cm = &cpi->common;
-  SVC *const svc = &cpi->svc;
-  BufferPool *const pool = cm->buffer_pool;
-  const int sl_id = svc->spatial_layer_id;
-  const int tl_id = svc->temporal_layer_id;
-  const int num_sl = svc->number_spatial_layers;
-  // SL0:
-  // 3 spatial layers: update slot 0 and 3
-  // 2 spatial layers: update slot 0 and 2
-  // 1 spatial layer:  update slot 0 and 1
-  // SL1:
-  // 3 spatial layers: update slot 1, 4, and 6
-  // 2 spatial layers: update slot 1, 3, and 6
-  // slot 6 is for golden frame long temporal prediction.
-  // SL2: update slot 2, 5 and 7
-  // slot 7 is for golden frame long temporal prediction.
-  ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[sl_id], cm->new_fb_idx);
-  ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[num_sl + sl_id],
-             cm->new_fb_idx);
-  svc->fb_idx_spatial_layer_id[sl_id] = sl_id;
-  svc->fb_idx_temporal_layer_id[sl_id] = tl_id;
-  svc->fb_idx_spatial_layer_id[num_sl + sl_id] = sl_id;
-  svc->fb_idx_temporal_layer_id[num_sl + sl_id] = tl_id;
-  // Update slots for golden frame long temporal prediction.
-  if (svc->use_gf_temporal_ref_current_layer) {
-    const int index = num_sl == 3 ? sl_id - 1 : sl_id;
-    const int lt_buffer_index = svc->buffer_gf_temporal_ref[index].idx;
-    ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[lt_buffer_index],
-               cm->new_fb_idx);
-    svc->fb_idx_spatial_layer_id[lt_buffer_index] = sl_id;
-    svc->fb_idx_temporal_layer_id[lt_buffer_index] = tl_id;
-  }
-
-  vp9_copy_flags_ref_update_idx(cpi);
-  vp9_svc_update_ref_frame_buffer_idx(cpi);
-}
-
 void vp9_svc_update_ref_frame(VP9_COMP *const cpi) {
   VP9_COMMON *const cm = &cpi->common;
   SVC *const svc = &cpi->svc;
@@ -1290,7 +1232,7 @@
       if (i != cpi->lst_fb_idx && i != cpi->gld_fb_idx && i != cpi->alt_fb_idx)
         ref_cnt_fb(pool->frame_bufs, &cm->ref_frame_map[i], cm->new_fb_idx);
     }
-  } else if (cm->frame_type != KEY_FRAME) {
+  } else {
     if (cpi->refresh_last_frame) {
       svc->fb_idx_spatial_layer_id[cpi->lst_fb_idx] = svc->spatial_layer_id;
       svc->fb_idx_temporal_layer_id[cpi->lst_fb_idx] = svc->temporal_layer_id;