[spice-gtk,2/2] Let user rank gstreamer element

Submitted by Snir Sheriber on Dec. 31, 2017, 3:46 p.m.

Details

Message ID 20171231154625.30010-3-ssheribe@redhat.com
State New
Headers show
Series "stream decoding using gstreamer" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Snir Sheriber Dec. 31, 2017, 3:46 p.m.
User can now rank a gstreamer element with high rank
by setting SPICE_GST_RANK_HIGH to the element's name.
This can be used to prioritize specific decoder to
be chosen by playbin.
---
 src/channel-display-gst.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
index af87fb5..fe3918d 100644
--- a/src/channel-display-gst.c
+++ b/src/channel-display-gst.c
@@ -340,6 +340,27 @@  static void app_source_setup(GstElement *pipeline G_GNUC_UNUSED,
     gst_caps_unref(caps);
     decoder->appsrc = GST_APP_SRC(gst_object_ref(source));
 }
+
+static void gst_factory_rank_high(void) {
+    GstRegistry *registry = NULL;
+    GstElementFactory *factory = NULL;
+    const gchar *name = NULL;
+
+
+    registry = gst_registry_get ();
+    if (!registry) return;
+
+    name = g_getenv("SPICE_GST_RANK_HIGH");
+    if (!name) return;
+
+    factory = gst_element_factory_find (name);
+    if (!factory) return;
+
+    gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory), GST_RANK_PRIMARY + 1);
+
+    gst_registry_add_feature (registry, GST_PLUGIN_FEATURE (factory));
+    return;
+}
 #endif
 
 static gboolean create_pipeline(SpiceGstDecoder *decoder)
@@ -358,6 +379,8 @@  static gboolean create_pipeline(SpiceGstDecoder *decoder)
         return FALSE;
     }
 
+    gst_factory_rank_high();
+
     convert = gst_element_factory_make("autovideoconvert", "autovideoconvert");
     download = gst_element_factory_make("gldownload", "gldownload");
     appsink = gst_element_factory_make("appsink", "appsink");

Comments

On Sun, 2017-12-31 at 17:46 +0200, Snir Sheriber wrote:
> User can now rank a gstreamer element with high rank
> by setting SPICE_GST_RANK_HIGH to the element's name.
> This can be used to prioritize specific decoder to
> be chosen by playbin.
> ---
>  src/channel-display-gst.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
> index af87fb5..fe3918d 100644
> --- a/src/channel-display-gst.c
> +++ b/src/channel-display-gst.c
> @@ -340,6 +340,27 @@ static void app_source_setup(GstElement
> *pipeline G_GNUC_UNUSED,
>      gst_caps_unref(caps);
>      decoder->appsrc = GST_APP_SRC(gst_object_ref(source));
>  }
> +
> +static void gst_factory_rank_high(void) {

Not a huge deal, but in general I'd avoid a gst_ prefix in application
code. Perhaps spice_gst_factory_rank_high() instead?

> +    GstRegistry *registry = NULL;
> +    GstElementFactory *factory = NULL;
> +    const gchar *name = NULL;
> +
> +
> +    registry = gst_registry_get ();
> +    if (!registry) return;
> +
> +    name = g_getenv("SPICE_GST_RANK_HIGH");

Is there ever a case where you'd want to specify rank for more than a
single element? Would it make sense to treat this as a comma-separated
list? Maybe overkill.

> +    if (!name) return;
> +
> +    factory = gst_element_factory_find (name);
> +    if (!factory) return;
> +
> +    gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory),
> GST_RANK_PRIMARY + 1);
> +
> +    gst_registry_add_feature (registry, GST_PLUGIN_FEATURE
> (factory));
> +    return;
> +}
>  #endif
>  
>  static gboolean create_pipeline(SpiceGstDecoder *decoder)
> @@ -358,6 +379,8 @@ static gboolean create_pipeline(SpiceGstDecoder
> *decoder)
>          return FALSE;
>      }
>  
> +    gst_factory_rank_high();
> +
>      convert = gst_element_factory_make("autovideoconvert",
> "autovideoconvert");
>      download = gst_element_factory_make("gldownload", "gldownload");
>      appsink = gst_element_factory_make("appsink", "appsink");


Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Hi,


On 01/02/2018 10:22 PM, Jonathon Jongsma wrote:
> On Sun, 2017-12-31 at 17:46 +0200, Snir Sheriber wrote:
>> User can now rank a gstreamer element with high rank
>> by setting SPICE_GST_RANK_HIGH to the element's name.
>> This can be used to prioritize specific decoder to
>> be chosen by playbin.
>> ---
>>   src/channel-display-gst.c | 23 +++++++++++++++++++++++
>>   1 file changed, 23 insertions(+)
>>
>> diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c
>> index af87fb5..fe3918d 100644
>> --- a/src/channel-display-gst.c
>> +++ b/src/channel-display-gst.c
>> @@ -340,6 +340,27 @@ static void app_source_setup(GstElement
>> *pipeline G_GNUC_UNUSED,
>>       gst_caps_unref(caps);
>>       decoder->appsrc = GST_APP_SRC(gst_object_ref(source));
>>   }
>> +
>> +static void gst_factory_rank_high(void) {
> Not a huge deal, but in general I'd avoid a gst_ prefix in application
> code. Perhaps spice_gst_factory_rank_high() instead?
>
>> +    GstRegistry *registry = NULL;
>> +    GstElementFactory *factory = NULL;
>> +    const gchar *name = NULL;
>> +
>> +
>> +    registry = gst_registry_get ();
>> +    if (!registry) return;
>> +
>> +    name = g_getenv("SPICE_GST_RANK_HIGH");
> Is there ever a case where you'd want to specify rank for more than a
> single element? Would it make sense to treat this as a comma-separated
> list? Maybe overkill.

True, actually in second though I'm not sure this patch is even
needed, if another plugin is available and has higher\same rank
i want to believe it should also works better\similarly.
It was useful for me in order to choose specific plugin while i had
another one that does the same thing installed, not sure it's a
common use case.

Snir.
>> +    if (!name) return;
>> +
>> +    factory = gst_element_factory_find (name);
>> +    if (!factory) return;
>> +
>> +    gst_plugin_feature_set_rank (GST_PLUGIN_FEATURE (factory),
>> GST_RANK_PRIMARY + 1);
>> +
>> +    gst_registry_add_feature (registry, GST_PLUGIN_FEATURE
>> (factory));
>> +    return;
>> +}
>>   #endif
>>   
>>   static gboolean create_pipeline(SpiceGstDecoder *decoder)
>> @@ -358,6 +379,8 @@ static gboolean create_pipeline(SpiceGstDecoder
>> *decoder)
>>           return FALSE;
>>       }
>>   
>> +    gst_factory_rank_high();
>> +
>>       convert = gst_element_factory_make("autovideoconvert",
>> "autovideoconvert");
>>       download = gst_element_factory_make("gldownload", "gldownload");
>>       appsink = gst_element_factory_make("appsink", "appsink");
>
> Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
>