[Spice-devel] [spice v13 18/29] server: Dynamically adjust the GStreamer encoder bitrate if possible
Francois Gouget
fgouget at codeweavers.com
Tue Apr 19 07:50:22 UTC 2016
This is faster and lets the encoder leverage past bitrate shaping
history to attain the target faster.
Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---
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 2e1c11e..2af2bc4 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
@@ -472,9 +475,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);
}
@@ -952,7 +962,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.0.rc3
More information about the Spice-devel
mailing list