[Spice-devel] [PATCH spice 11/13] server: Add h264 support to the GStreamer video encoder. (take 4)

Francois Gouget fgouget at codeweavers.com
Tue Jul 21 11:01:42 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.


Changes since take 3:
 - None.


 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 2ad1890..52b3e03 100644
--- a/server/gstreamer_encoder.c
+++ b/server/gstreamer_encoder.c
@@ -266,6 +266,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;
@@ -322,6 +325,17 @@ static gboolean construct_pipeline(GstEncoder *encoder, const SpiceBitmap *bitma
                      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);
@@ -674,7 +688,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 d896d00..14d3f86 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -268,12 +268,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