[Spice-devel] [PATCH spice 12/12] server: Add h264 support to the GStreamer video encoder.

Francois Gouget fgouget at codeweavers.com
Wed Jun 10 08:41:09 PDT 2015


Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
---

Having support for h264 is interesting in its own right but this shows 
adding extra codecs is quite easy.

 server/gstreamer_encoder.c | 17 ++++++++++++++++-
 server/red_dispatcher.c    |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/server/gstreamer_encoder.c b/server/gstreamer_encoder.c
index 6a47668..451518f 100644
--- a/server/gstreamer_encoder.c
+++ b/server/gstreamer_encoder.c
@@ -204,6 +204,9 @@ static gboolean construct_pipeline(GstEncoder *encoder, const SpiceBitmap *bitma
     case SPICE_VIDEO_CODEC_TYPE_VP8:
         gstenc_name = "vp8enc";
         break;
+    case SPICE_VIDEO_CODEC_TYPE_H264:
+        gstenc_name = "x264enc";
+        break;
     default:
         spice_warning("unsupported codec type %d", encoder->base.codec_type);
         return FALSE;
@@ -254,6 +257,17 @@ static gboolean construct_pipeline(GstEncoder *encoder, const SpiceBitmap *bitma
                      "threads", g_get_num_processors() - 1,
                      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 latency */
+                     "intra-refresh", TRUE,
+                     "sliced-threads", TRUE,
+                     "speed-preset", 1, /* ultrafast */
+                     NULL);
+        break;
     default:
         spice_warning("unknown encoder type %d", encoder->base.codec_type);
         reset_pipeline(encoder);
@@ -587,7 +601,8 @@ GstEncoder *create_gstreamer_encoder(SpiceVideoCodecType codec_type, uint64_t st
 
     spice_assert(!cbs || (cbs && cbs->get_roundtrip_ms && cbs->get_source_fps));
     if (codec_type != SPICE_VIDEO_CODEC_TYPE_MJPEG &&
-        codec_type != SPICE_VIDEO_CODEC_TYPE_VP8) {
+        codec_type != SPICE_VIDEO_CODEC_TYPE_VP8 &&
+        codec_type != SPICE_VIDEO_CODEC_TYPE_H264) {
         spice_warning("unsupported codec type %d", codec_type);
         return NULL;
     }
diff --git a/server/red_dispatcher.c b/server/red_dispatcher.c
index 08623e2..a034949 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -267,12 +267,14 @@ static create_video_encoder_proc 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},
 };
 
-- 
2.1.4


More information about the Spice-devel mailing list