shithub: libvpx

Download patch

ref: 04b3d49bac697b867af6292d270b5ec77b00b29e
parent: 00207bc81247af208397ca31cb74f02fa7254dbc
author: Marco Paniconi <marpan@google.com>
date: Wed Aug 29 11:05:46 EDT 2018

vp9-svc: Allow for setting framerate per spatial layer.

Add duration to set_svc_ref_frame_config.

BUG=b/113346831

Change-Id: I63613aed6b1183f98d04831600a6bdd645c740df

--- a/examples/vp9_spatial_svc_encoder.c
+++ b/examples/vp9_spatial_svc_encoder.c
@@ -925,6 +925,9 @@
                                         svc_ctx.spatial_layers, frame_cnt == 0,
                                         &ref_frame_config);
       }
+      ref_frame_config.duration[0] = frame_duration * 1;
+      ref_frame_config.duration[1] = frame_duration * 1;
+
       vpx_codec_control(&codec, VP9E_SET_SVC_REF_FRAME_CONFIG,
                         &ref_frame_config);
       // Keep track of input frames, to account for frame drops in rate control
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -6237,7 +6237,11 @@
 
   // adjust frame rates based on timestamps given
   if (cm->show_frame) {
-    adjust_frame_rate(cpi, source);
+    if (cpi->use_svc && cpi->svc.use_set_ref_frame_config &&
+        cpi->svc.duration[cpi->svc.spatial_layer_id] > 0)
+      vp9_svc_adjust_frame_rate(cpi);
+    else
+      adjust_frame_rate(cpi, source);
   }
 
   if (is_one_pass_cbr_svc(cpi)) {
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -1200,3 +1200,9 @@
   vp9_copy_flags_ref_update_idx(cpi);
   vp9_svc_update_ref_frame_buffer_idx(cpi);
 }
+
+void vp9_svc_adjust_frame_rate(VP9_COMP *cpi) {
+  int64_t this_duration =
+      cpi->svc.timebase_fac * cpi->svc.duration[cpi->svc.spatial_layer_id];
+  vp9_new_framerate(cpi, 10000000.0 / this_duration);
+}
--- a/vp9/encoder/vp9_svc_layercontext.h
+++ b/vp9/encoder/vp9_svc_layercontext.h
@@ -177,6 +177,10 @@
   int temporal_layer_id_per_spatial[VPX_SS_MAX_LAYERS];
 
   int first_spatial_layer_to_encode;
+
+  int64_t duration[VPX_SS_MAX_LAYERS];
+
+  int64_t timebase_fac;
 } SVC;
 
 struct VP9_COMP;
@@ -243,6 +247,8 @@
 void vp9_svc_update_ref_frame_buffer_idx(struct VP9_COMP *const cpi);
 
 void vp9_svc_update_ref_frame(struct VP9_COMP *const cpi);
+
+void vp9_svc_adjust_frame_rate(struct VP9_COMP *const cpi);
 
 #ifdef __cplusplus
 }  // extern "C"
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -1150,6 +1150,8 @@
     size_t size, cx_data_sz;
     unsigned char *cx_data;
 
+    cpi->svc.timebase_fac = timebase_units_to_ticks(timebase, 1);
+
     // Set up internal flags
     if (ctx->base.init_flags & VPX_CODEC_USE_PSNR) cpi->b_calculate_psnr = 1;
 
@@ -1537,6 +1539,7 @@
     cpi->svc.lst_fb_idx[sl] = data->lst_fb_idx[sl];
     cpi->svc.gld_fb_idx[sl] = data->gld_fb_idx[sl];
     cpi->svc.alt_fb_idx[sl] = data->alt_fb_idx[sl];
+    cpi->svc.duration[sl] = data->duration[sl];
   }
   return VPX_CODEC_OK;
 }
--- a/vpx/vp8cx.h
+++ b/vpx/vp8cx.h
@@ -810,6 +810,7 @@
   int reference_last[VPX_SS_MAX_LAYERS];    /**< Last as eference. */
   int reference_golden[VPX_SS_MAX_LAYERS];  /**< Golden as reference. */
   int reference_alt_ref[VPX_SS_MAX_LAYERS]; /**< Altref as reference. */
+  int64_t duration[VPX_SS_MAX_LAYERS];      /**< Duration per spatial layer. */
 } vpx_svc_ref_frame_config_t;
 
 /*!\brief VP9 svc frame dropping mode.