[Spice-devel,v7,11/23] server: Add h264 support to the GStreamer video encoder

Submitted by Francois Gouget on Dec. 16, 2015, 3:19 p.m.

Details

Message ID alpine.DEB.2.20.1512161125180.16981@amboise
State New
Headers show
Series "Add GStreamer support for video streaming" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget Dec. 16, 2015, 3:19 p.m.
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 server/gstreamer-encoder.c | 17 ++++++++++++++++-
 server/reds.c              |  2 ++
 server/video-encoder.h     |  2 +-
 3 files changed, 19 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/gstreamer-encoder.c b/server/gstreamer-encoder.c
index 11be91b..fe07852 100644
--- a/server/gstreamer-encoder.c
+++ b/server/gstreamer-encoder.c
@@ -231,6 +231,9 @@  static gboolean create_pipeline(SpiceGstEncoder *encoder)
     case SPICE_VIDEO_CODEC_TYPE_VP8:
         gstenc_name = "vp8enc";
         break;
+    case SPICE_VIDEO_CODEC_TYPE_H264:
+        gstenc_name = "x264enc";
+        break;
     default:
         /* gstreamer_encoder_new() should have rejected this codec type */
         spice_warning("unsupported codec type %d", encoder->base.codec_type);
@@ -296,6 +299,17 @@  static gboolean configure_pipeline(SpiceGstEncoder *encoder,
                      NULL);
         break;
         }
+    case SPICE_VIDEO_CODEC_TYPE_H264:
+        g_object_set(G_OBJECT(encoder->gstenc),
+                     "bitrate", encoder->bit_rate / 1024,
+                     "byte-stream", TRUE,
+                     "aud", FALSE,
+                     "tune", 4, /* zero-frame latency */
+                     "sliced-threads", TRUE, /* zero-frame latency */
+                     "speed-preset", 1, /* ultrafast */
+                     "intra-refresh", TRUE, /* uniform compressed frame sizes */
+                     NULL);
+        break;
     default:
         /* gstreamer_encoder_new() should have rejected this codec type */
         spice_warning("unknown encoder type %d", encoder->base.codec_type);
@@ -700,7 +714,8 @@  VideoEncoder *gstreamer_encoder_new(SpiceVideoCodecType codec_type,
                                     void *cbs_opaque)
 {
     spice_return_val_if_fail(codec_type == SPICE_VIDEO_CODEC_TYPE_MJPEG ||
-                             codec_type == SPICE_VIDEO_CODEC_TYPE_VP8, NULL);
+                             codec_type == SPICE_VIDEO_CODEC_TYPE_VP8 ||
+                             codec_type == SPICE_VIDEO_CODEC_TYPE_H264, NULL);
 
     GError *err = NULL;
     if (!gst_init_check(NULL, NULL, &err)) {
diff --git a/server/reds.c b/server/reds.c
index b4bb4d1..a2c812e 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3422,12 +3422,14 @@  static new_video_encoder_t video_encoder_procs[] = {
 static const EnumNames video_codec_names[] = {
     {SPICE_VIDEO_CODEC_TYPE_MJPEG, "mjpeg"},
     {SPICE_VIDEO_CODEC_TYPE_VP8, "vp8"},
+    {SPICE_VIDEO_CODEC_TYPE_H264, "h264"},
     {0, NULL},
 };
 
 static const EnumNames video_cap_names[] = {
     {SPICE_DISPLAY_CAP_CODEC_MJPEG, "mjpeg"},
     {SPICE_DISPLAY_CAP_CODEC_VP8, "vp8"},
+    {SPICE_DISPLAY_CAP_CODEC_H264, "h264"},
     {0, NULL},
 };
 
diff --git a/server/video-encoder.h b/server/video-encoder.h
index db520eb..edfb392 100644
--- a/server/video-encoder.h
+++ b/server/video-encoder.h
@@ -193,6 +193,6 @@  VideoEncoder* gstreamer_encoder_new(SpiceVideoCodecType codec_type,
                                     void *cbs_opaque);
 #endif
 
-#define VIDEO_ENCODER_DEFAULT_PREFERENCE "spice:mjpeg;gstreamer:mjpeg;gstreamer:vp8"
+#define VIDEO_ENCODER_DEFAULT_PREFERENCE "spice:mjpeg;gstreamer:mjpeg;gstreamer:h264;gstreamer:vp8"
 
 #endif