[Spice-devel,v6,13/26] server: Add h264 support to the GStreamer video encoder

Submitted by Francois Gouget on Oct. 14, 2015, 3:32 p.m.

Details

Message ID alpine.DEB.2.20.1510141419020.17509@amboise
State New
Headers show

Not browsing as part of any series.

Commit Message

Francois Gouget Oct. 14, 2015, 3:32 p.m.
Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 server/gstreamer_encoder.c | 17 ++++++++++++++++-
 server/red_dispatcher.c    |  2 ++
 2 files changed, 18 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/server/gstreamer_encoder.c b/server/gstreamer_encoder.c
index e31b7c1..2bc6e65 100644
--- a/server/gstreamer_encoder.c
+++ b/server/gstreamer_encoder.c
@@ -223,6 +223,9 @@  static gboolean construct_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);
@@ -274,6 +277,17 @@  static gboolean construct_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);
@@ -655,7 +669,8 @@  VideoEncoder *gstreamer_encoder_new(SpiceVideoCodecType codec_type,
 
     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 75cc53d..60eef24 100644
--- a/server/red_dispatcher.c
+++ b/server/red_dispatcher.c
@@ -268,12 +268,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},
 };
 

Comments

Looks good, ACK.


On Wed, Oct 14, 2015 at 05:32:46PM +0200, Francois Gouget wrote:
> Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
> ---
>  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 e31b7c1..2bc6e65 100644
> --- a/server/gstreamer_encoder.c
> +++ b/server/gstreamer_encoder.c
> @@ -223,6 +223,9 @@ static gboolean construct_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);
> @@ -274,6 +277,17 @@ static gboolean construct_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);
> @@ -655,7 +669,8 @@ VideoEncoder *gstreamer_encoder_new(SpiceVideoCodecType codec_type,
>  
>      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 75cc53d..60eef24 100644
> --- a/server/red_dispatcher.c
> +++ b/server/red_dispatcher.c
> @@ -268,12 +268,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},
>  };
>  
> -- 
> 2.6.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel