From ec1d4619a78e5bc658e55ca59f48ae8566b6f976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Mon, 26 Apr 2021 22:30:01 +0200 Subject: [PATCH] API: make "state" into a property --- lib/gst/clapper/gstclapper.c | 31 +++++++++++++++++++++++++++++++ lib/gst/clapper/gstclapper.h | 4 ++++ src/player.js | 2 -- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/gst/clapper/gstclapper.c b/lib/gst/clapper/gstclapper.c index 580dcf78..f0c2b2b2 100644 --- a/lib/gst/clapper/gstclapper.c +++ b/lib/gst/clapper/gstclapper.c @@ -50,6 +50,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_clapper_debug); #define GST_CAT_DEFAULT gst_clapper_debug +#define DEFAULT_STATE GST_CLAPPER_STATE_STOPPED #define DEFAULT_URI NULL #define DEFAULT_POSITION GST_CLOCK_TIME_NONE #define DEFAULT_DURATION GST_CLOCK_TIME_NONE @@ -75,6 +76,7 @@ enum PROP_0, PROP_VIDEO_RENDERER, PROP_SIGNAL_DISPATCHER, + PROP_STATE, PROP_URI, PROP_SUBURI, PROP_POSITION, @@ -268,6 +270,7 @@ gst_clapper_init (GstClapper * self) self->last_seek_time = GST_CLOCK_TIME_NONE; self->inhibit_sigs = FALSE; self->needs_info_update = FALSE; + self->app_state = GST_CLAPPER_STATE_STOPPED; GST_TRACE_OBJECT (self, "Initialized"); } @@ -297,6 +300,11 @@ gst_clapper_class_init (GstClapperClass * klass) 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 | + G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + param_specs[PROP_URI] = g_param_spec_string ("uri", "URI", "Current URI", DEFAULT_URI, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); @@ -730,6 +738,11 @@ gst_clapper_get_property (GObject * object, guint prop_id, GstClapper *self = GST_CLAPPER (object); switch (prop_id) { + case PROP_STATE: + g_mutex_lock (&self->lock); + g_value_set_enum (value, self->app_state); + g_mutex_unlock (&self->lock); + break; case PROP_URI: g_mutex_lock (&self->lock); g_value_set_string (value, self->uri); @@ -3442,6 +3455,24 @@ remove_seek_source (GstClapper * self) self->seek_source = NULL; } +/** + * gst_clapper_get_state: + * @clapper: #GstClapper instance + * + * Returns: Current player state + */ +GstClapperState +gst_clapper_get_state (GstClapper * self) +{ + GstClapperState state; + + g_return_val_if_fail (GST_IS_CLAPPER (self), DEFAULT_STATE); + + g_object_get (self, "state", &state, NULL); + + return state; +} + /** * gst_clapper_get_uri: * @clapper: #GstClapper instance diff --git a/lib/gst/clapper/gstclapper.h b/lib/gst/clapper/gstclapper.h index 44bb20b0..73e8f995 100644 --- a/lib/gst/clapper/gstclapper.h +++ b/lib/gst/clapper/gstclapper.h @@ -170,6 +170,10 @@ void gst_clapper_stop (GstClapper *clapper GST_CLAPPER_API void gst_clapper_seek (GstClapper *clapper, GstClockTime position); +GST_CLAPPER_API +GstClapperState + gst_clapper_get_state (GstClapper *clapper); + GST_CLAPPER_API GstClapperSeekMode gst_clapper_get_seek_mode (GstClapper *clapper); diff --git a/src/player.js b/src/player.js index d0e66945..b0278547 100644 --- a/src/player.js +++ b/src/player.js @@ -33,7 +33,6 @@ class ClapperPlayer extends GstClapper.Clapper this.widget = gtk4plugin.video_sink.widget; this.widget.add_css_class('videowidget'); - this.state = GstClapper.ClapperState.STOPPED; this.visualization_enabled = false; this.webserver = null; @@ -518,7 +517,6 @@ class ClapperPlayer extends GstClapper.Clapper _onStateChanged(player, state) { - this.state = state; this.emitWs('state_changed', state); if(state !== GstClapper.ClapperState.BUFFERING) {