[spice v16 20/23] streaming: Dynamically adjust the GStreamer encoder bitrate if possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is faster and lets the encoder leverage past bitrate shaping
history to attain the target faster.

Signed-off-by: Francois Gouget <fgouget@xxxxxxxxxxxxxxx>
---
 server/gstreamer-encoder.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/server/gstreamer-encoder.c b/server/gstreamer-encoder.c
index b4facc9..b94656b 100644
--- a/server/gstreamer-encoder.c
+++ b/server/gstreamer-encoder.c
@@ -99,6 +99,9 @@ typedef struct SpiceGstEncoder {
     GstElement *gstenc;
     GParamSpec *gstenc_bitrate_param;
 
+    /* True if the encoder's bitrate can be modified while playing. */
+    gboolean gstenc_bitrate_is_dynamic;
+
     /* Pipeline parameters to modify before the next frame. */
 #   define SPICE_GST_VIDEO_PIPELINE_STATE    0x1
 #   define SPICE_GST_VIDEO_PIPELINE_BITRATE  0x2
@@ -473,9 +476,16 @@ static void add_frame(SpiceGstEncoder *encoder, uint32_t frame_mm_time,
 
 /* ---------- Encoder bit rate control ---------- */
 
+static void set_gstenc_bitrate(SpiceGstEncoder *encoder);
+
 static void set_video_bit_rate(SpiceGstEncoder *encoder, uint64_t bit_rate)
 {
-    if (abs(bit_rate - encoder->video_bit_rate) > encoder->video_bit_rate * SPICE_GST_VIDEO_BITRATE_MARGIN) {
+    if (encoder->video_bit_rate != bit_rate &&
+        encoder->gstenc_bitrate_is_dynamic) {
+        encoder->video_bit_rate = bit_rate;
+        set_gstenc_bitrate(encoder);
+
+    } else  if (abs(bit_rate - encoder->video_bit_rate) > encoder->video_bit_rate * SPICE_GST_VIDEO_BITRATE_MARGIN) {
         encoder->video_bit_rate = bit_rate;
         set_pipeline_changes(encoder, SPICE_GST_VIDEO_PIPELINE_BITRATE);
     }
@@ -945,7 +955,9 @@ static gboolean create_pipeline(SpiceGstEncoder *encoder)
     if (encoder->gstenc_bitrate_param == NULL) {
         encoder->gstenc_bitrate_param = g_object_class_find_property(class, "target-bitrate");
     }
-    if (!encoder->gstenc_bitrate_param) {
+    if (encoder->gstenc_bitrate_param) {
+        encoder->gstenc_bitrate_is_dynamic = (encoder->gstenc_bitrate_param->flags & GST_PARAM_MUTABLE_PLAYING);
+    } else {
         spice_warning("GStreamer error: could not find the %s bitrate parameter", gstenc_name);
     }
 
-- 
2.8.1

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]