From b68c1a62b29c5d0447a2b05bff677a932a3f91f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Fri, 3 Sep 2021 10:38:36 +0200 Subject: [PATCH] api: Add property to control playbin3 enablement --- lib/gst/clapper/gstclapper.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/gst/clapper/gstclapper.c b/lib/gst/clapper/gstclapper.c index d20f0a5b..f5ebb126 100644 --- a/lib/gst/clapper/gstclapper.c +++ b/lib/gst/clapper/gstclapper.c @@ -51,6 +51,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_clapper_debug); #define GST_CAT_DEFAULT gst_clapper_debug +#define DEFAULT_USE_PLAYBIN3 FALSE #define DEFAULT_STATE GST_CLAPPER_STATE_STOPPED #define DEFAULT_URI NULL #define DEFAULT_POSITION GST_CLOCK_TIME_NONE @@ -80,6 +81,7 @@ enum PROP_VIDEO_RENDERER, PROP_SIGNAL_DISPATCHER, PROP_MPRIS, + PROP_USE_PLAYBIN3, PROP_STATE, PROP_URI, PROP_SUBURI, @@ -324,6 +326,11 @@ gst_clapper_class_init (GstClapperClass * klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + param_specs[PROP_USE_PLAYBIN3] = + g_param_spec_boolean ("use-playbin3", "Use playbin3", "Use playbin3", + DEFAULT_USE_PLAYBIN3, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + param_specs[PROP_STATE] = g_param_spec_enum ("state", "Clapper State", "Current player state", GST_TYPE_CLAPPER_STATE, DEFAULT_STATE, G_PARAM_READABLE | @@ -685,6 +692,9 @@ gst_clapper_set_property (GObject * object, guint prop_id, case PROP_MPRIS: self->mpris = g_value_dup_object (value); break; + case PROP_USE_PLAYBIN3: + self->use_playbin3 = g_value_get_boolean (value); + break; case PROP_URI:{ g_mutex_lock (&self->lock); g_free (self->uri); @@ -3057,6 +3067,19 @@ element_setup_cb (GstElement * playbin, GstElement * element, GstClapper * self) } } +static void +_update_from_env (gboolean * enabled, const gchar * env_name) +{ + const gchar *env = g_getenv (env_name); + + if (env) { + if (g_str_has_prefix (env, "1")) + *enabled = TRUE; + else if (g_str_has_prefix (env, "0")) + *enabled = FALSE; + } +} + static gpointer gst_clapper_main (gpointer data) { @@ -3064,7 +3087,7 @@ gst_clapper_main (gpointer data) GstBus *bus; GSource *source; GstElement *scaletempo, *pipewiresink; - const gchar *pb_env, *pw_env; + const gchar *pw_env; GST_TRACE_OBJECT (self, "Starting main thread"); @@ -3076,9 +3099,7 @@ gst_clapper_main (gpointer data) g_source_attach (source, self->context); g_source_unref (source); - pb_env = g_getenv ("GST_CLAPPER_USE_PLAYBIN3"); - if (pb_env && g_str_has_prefix (pb_env, "1")) - self->use_playbin3 = TRUE; + _update_from_env (&self->use_playbin3, "GST_CLAPPER_USE_PLAYBIN3"); if (self->use_playbin3) { GST_DEBUG_OBJECT (self, "playbin3 enabled");