[Spice-devel] [PATCH v4 1/2] gstreamer-encoder: Use an env var to override converter format (v3)

Frediano Ziglio freddy77 at gmail.com
Mon Nov 13 20:42:51 UTC 2023


Il giorno mar 17 ott 2023 alle ore 08:45 Vivek Kasireddy
<vivek.kasireddy at intel.com> ha scritto:
>
> If we use the x264enc encoder to encode a stream, then videoconvert
> would convert the BGRx data into Y444, which is the preferred format
> for x264enc. However, some decoders particularly the ones that are
> h/w based cannot work with Y444 if it was the format used by the
> encoder. Therefore, to address these situations, we need a way to
> override the format used during the encoding stage which can be
> accomplished by using the environment variable introduced in this
> patch: SPICE_CONVERTER_PREFERRED_FORMAT.
>
> For example, using NV12 as the output format for the videoconvert
> element would allow us to pair a s/w based encoder (such as x264enc)
> with a h/w based decoder (such as msdkh264dec) for decoding the
> stream as most h/w based decoders only work with NV12 format given
> its popularity.
>
> Note that choosing an encoder format such as NV12 over Y444 would
> probably result in decreased video quality although it would be
> compatible with more decoders. Ideally, the client and server need
> to negotiate a suitable format dynamically but the current
> capabilities do not allow for such exchange.
>
> v2:
> - Add the environment variable to override encoding format
> - Augment the commit message to explain the impact of overriding
>   the default encoding format (Frediano)
>
> v3:
> - Free converter when pipeline creation fails due to invalid codec
> - Rebase on master
>
> Cc: Frediano Ziglio <freddy77 at gmail.com>
> Cc: Dongwon Kim <dongwon.kim at intel.com>
> Based-on-patch-by: Hazwan Arif Mazlan <hazwan.arif.mazlan at intel.com>
> Signed-off-by: Jin Chung Teng <jin.chung.teng at intel.com>
> Signed-off-by: Vivek Kasireddy <vivek.kasireddy at intel.com>
> ---
>  server/gstreamer-encoder.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/server/gstreamer-encoder.c b/server/gstreamer-encoder.c
> index d08de35a..7a75923d 100644
> --- a/server/gstreamer-encoder.c
> +++ b/server/gstreamer-encoder.c
> @@ -861,13 +861,25 @@ static const gchar* get_gst_codec_name(const SpiceGstEncoder *encoder)
>      }
>  }
>
> +static gchar *get_gst_converter(void)
> +{
> +    gchar *converter, *pref_format;
> +    pref_format = getenv("SPICE_CONVERTER_PREFERRED_FORMAT");
> +    if (pref_format) {
> +        converter = g_strconcat("videoconvert ! video/x-raw,format=", pref_format, NULL);
> +    } else {
> +        converter = g_strdup("videoconvert");
> +    }
> +    return converter;
> +}
> +

Hi,
  probably my paranoia. We get an environment variable every time we
try to create a new pipeline and we put whatever string from the
environment to the pipeline string, potentially filenames or anything.
I wrote these changes to avoid these behaviour
https://gitlab.freedesktop.org/fziglio/spice/-/commit/85bc1e3deb92f0e02ad7bfa68828d1b7d4f424fb.
Also I added this
https://gitlab.freedesktop.org/fziglio/spice/-/commit/7fcd6608bd79c390f7595534a9f70d8e1f3b7b86
to make CI happier.


>  static gboolean create_pipeline(SpiceGstEncoder *encoder)
>  {
> -    const gchar *converter = "videoconvert";
>      const gchar* gstenc_name = get_gst_codec_name(encoder);
>      if (!gstenc_name) {
>          return FALSE;
>      }
> +    gchar* converter = get_gst_converter();
>      gchar* gstenc_opts;
>      switch (encoder->base.codec_type)
>      {
> @@ -910,6 +922,7 @@ static gboolean create_pipeline(SpiceGstEncoder *encoder)
>      default:
>          /* gstreamer_encoder_new() should have rejected this codec type */
>          spice_warning("unsupported codec type %d", encoder->base.codec_type);
> +        g_free(converter);
>          return FALSE;
>      }
>
> @@ -919,6 +932,7 @@ static gboolean create_pipeline(SpiceGstEncoder *encoder)
>                                    converter, gstenc_name, gstenc_opts);
>      spice_debug("GStreamer pipeline: %s", desc);
>      encoder->pipeline = gst_parse_launch_full(desc, NULL, GST_PARSE_FLAG_FATAL_ERRORS, &err);
> +    g_free(converter);
>      g_free(gstenc_opts);
>      g_free(desc);
>      if (!encoder->pipeline || err) {

Regards,
  Frediano


More information about the Spice-devel mailing list