diff --git a/src/Makefile.am b/src/Makefile.am index 3d2023d02..af5872354 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -145,9 +145,9 @@ test_subscribe_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS) ################################### pinosgstsource = gst/gstfdpay.h gst/gstfdpay.c \ - gst/gstfddepay.h gst/gstfddepay.c \ - gst/gsttmpfileallocator.h gst/gsttmpfileallocator.c \ - wire-protocol.h + gst/gstfddepay.h gst/gstfddepay.c \ + gst/gsttmpfileallocator.h gst/gsttmpfileallocator.c \ + wire-protocol.h pinosinclude_HEADERS = \ client/pinos.h \ @@ -210,6 +210,7 @@ libgstpinos_la_SOURCES = \ gst/gstpinos.c \ gst/gstfdpay.c \ gst/gstfddepay.c \ + gst/gstpinosdeviceprovider.c \ gst/gstpinossrc.c \ gst/gstpinossink.c @@ -219,7 +220,7 @@ libgstpinos_la_LIBADD = $(GST_BASE_LIBS) $(GST_LIBS) $(GLIB_LIBS) $(LIBM) -lgst libpinos-@PINOS_MAJORMINOR@.la libpinoscore-@PINOS_MAJORMINOR@.la libgstpinos_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS) -noinst_HEADERS = gst/gstpinossrc.h gst/gstpinossink.h gst/gstfdpay.h gst/gstfddepay.h +noinst_HEADERS = gst/gstpinossrc.h gst/gstpinossink.h gst/gstfdpay.h gst/gstfddepay.h gst/gstpinosdeviceprovider.h ################################### # Some minor stuff # diff --git a/src/client/context.c b/src/client/context.c index 4f539ce26..f97631254 100644 --- a/src/client/context.c +++ b/src/client/context.c @@ -555,6 +555,19 @@ pinos_context_connect (PinosContext *context, return TRUE; } +static void +finish_client_disconnect (PinosContext *context) +{ + PinosContextPrivate *priv = context->priv; + + g_clear_object (&priv->client); + g_clear_object (&priv->daemon); + g_bus_unwatch_name(priv->id); + priv->id = 0; + + context_set_state (context, PINOS_CONTEXT_STATE_UNCONNECTED); +} + static void on_client_disconnected (GObject *source_object, GAsyncResult *res, @@ -575,12 +588,7 @@ on_client_disconnected (GObject *source_object, } g_variant_unref (ret); - g_clear_object (&priv->client); - g_clear_object (&priv->daemon); - g_bus_unwatch_name(priv->id); - priv->id = 0; - - context_set_state (context, PINOS_CONTEXT_STATE_UNCONNECTED); + finish_client_disconnect (context); g_object_unref (context); } @@ -617,7 +625,11 @@ pinos_context_disconnect (PinosContext *context) g_return_val_if_fail (PINOS_IS_CONTEXT (context), FALSE); priv = context->priv; - g_return_val_if_fail (priv->client != NULL, FALSE); + + if (priv->client == NULL) { + finish_client_disconnect (context); + return TRUE; + } g_main_context_invoke (priv->context, (GSourceFunc) do_disconnect, diff --git a/src/client/context.h b/src/client/context.h index 8e4bee7b1..d3b468c19 100644 --- a/src/client/context.h +++ b/src/client/context.h @@ -67,11 +67,11 @@ typedef enum { * The state of a #PinosContext */ typedef enum { + PINOS_CONTEXT_STATE_ERROR = -1, PINOS_CONTEXT_STATE_UNCONNECTED = 0, PINOS_CONTEXT_STATE_CONNECTING = 1, PINOS_CONTEXT_STATE_REGISTERING = 2, PINOS_CONTEXT_STATE_READY = 3, - PINOS_CONTEXT_STATE_ERROR = 4 } PinosContextState; /** diff --git a/src/client/introspect.c b/src/client/introspect.c index 5bb66f685..9a9e5870e 100644 --- a/src/client/introspect.c +++ b/src/client/introspect.c @@ -33,7 +33,8 @@ * @cancelable: a #GCancellable * @user_data: user data passed to @cb * - * Call @cb for each source. + * Call @cb for each source. @cb will be called with NULL when there + * are no more sources to list. */ void pinos_context_list_source_info (PinosContext *context, @@ -49,9 +50,32 @@ pinos_context_list_source_info (PinosContext *context, GDBusProxy *proxy = walk->data; PinosSourceInfo info; + info.id = proxy; info.name = "gst"; cb (context, &info, user_data); } cb (context, NULL, user_data); } + +/** + * pinos_context_get_source_info: + * @context: a connected #PinosContext + * @id: a source id + * @flags: extra #PinosSourceInfoFlags + * @cb: a #PinosSourceInfoCallback + * @cancelable: a #GCancellable + * @user_data: user data passed to @cb + * + * Call @cb for each source. @cb will be called with NULL when there + * are no more sources to list. + */ +void +pinos_context_get_source_info_by_id (PinosContext *context, + gpointer id, + PinosSourceInfoFlags flags, + PinosSourceInfoCallback cb, + GCancellable *cancellable, + gpointer user_data) +{ +} diff --git a/src/client/introspect.h b/src/client/introspect.h index 4f2f27d29..761780ada 100644 --- a/src/client/introspect.h +++ b/src/client/introspect.h @@ -50,6 +50,7 @@ typedef enum { /** * PinosSourceInfo: + * @id: generic id of the source * @name: the name of the source * @properties: the properties of the source * @state: the current state of the source @@ -58,6 +59,7 @@ typedef enum { * The source information */ typedef struct { + gpointer id; const char *name; GVariant *properties; PinosSourceState state; @@ -78,11 +80,17 @@ typedef enum { typedef gboolean (*PinosSourceInfoCallback) (PinosContext *c, const PinosSourceInfo *info, gpointer userdata); -void pinos_context_list_source_info (PinosContext *context, - PinosSourceInfoFlags flags, - PinosSourceInfoCallback cb, - GCancellable *cancellable, - gpointer user_data); +void pinos_context_list_source_info (PinosContext *context, + PinosSourceInfoFlags flags, + PinosSourceInfoCallback cb, + GCancellable *cancellable, + gpointer user_data); +void pinos_context_get_source_info_by_id (PinosContext *context, + gpointer id, + PinosSourceInfoFlags flags, + PinosSourceInfoCallback cb, + GCancellable *cancellable, + gpointer user_data); G_END_DECLS diff --git a/src/client/stream.h b/src/client/stream.h index 118324eb5..95f257a67 100644 --- a/src/client/stream.h +++ b/src/client/stream.h @@ -41,12 +41,12 @@ typedef struct _PinosStreamClass PinosStreamClass; typedef struct _PinosStreamPrivate PinosStreamPrivate; typedef enum { + PINOS_STREAM_STATE_ERROR = -1, PINOS_STREAM_STATE_UNCONNECTED = 0, PINOS_STREAM_STATE_CONNECTING = 1, PINOS_STREAM_STATE_READY = 2, PINOS_STREAM_STATE_STARTING = 3, - PINOS_STREAM_STATE_STREAMING = 4, - PINOS_STREAM_STATE_ERROR = 5 + PINOS_STREAM_STATE_STREAMING = 4 } PinosStreamState; diff --git a/src/client/subscribe.c b/src/client/subscribe.c index bab65b117..a5e844a96 100644 --- a/src/client/subscribe.c +++ b/src/client/subscribe.c @@ -643,7 +643,7 @@ pinos_subscribe_class_init (PinosSubscribeClass * klass) 3, PINOS_TYPE_SUBSCRIPTION_EVENT, PINOS_TYPE_SUBSCRIPTION_FLAGS, - G_TYPE_DBUS_PROXY); + G_TYPE_POINTER); } static void diff --git a/src/client/subscribe.h b/src/client/subscribe.h index 382eb9944..cfaf62dce 100644 --- a/src/client/subscribe.h +++ b/src/client/subscribe.h @@ -87,16 +87,16 @@ PinosSubscribe * pinos_subscribe_new (void); PinosSubscriptionState pinos_subscribe_get_state (PinosSubscribe *subscribe); GError * pinos_subscribe_get_error (PinosSubscribe *subscribe); -void pinos_subscribe_get_proxy (PinosSubscribe *subscribe, - const gchar *name, - const gchar *object_path, - const gchar *interface_name, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -GDBusProxy * pinos_subscribe_get_proxy_finish (PinosSubscribe *subscribe, - GAsyncResult *res, - GError **error); +void pinos_subscribe_get_proxy (PinosSubscribe *subscribe, + const gchar *name, + const gchar *object_path, + const gchar *interface_name, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GDBusProxy * pinos_subscribe_get_proxy_finish (PinosSubscribe *subscribe, + GAsyncResult *res, + GError **error); diff --git a/src/gst/gstpinos.c b/src/gst/gstpinos.c index 44f95dfa5..37fa2b895 100644 --- a/src/gst/gstpinos.c +++ b/src/gst/gstpinos.c @@ -34,9 +34,12 @@ #include "gstpinossrc.h" #include "gstpinossink.h" +#include "gstpinosdeviceprovider.h" #include "gstfdpay.h" #include "gstfddepay.h" +GST_DEBUG_CATEGORY (pinos_debug); + static gboolean plugin_init (GstPlugin * plugin) { @@ -48,11 +51,18 @@ plugin_init (GstPlugin * plugin) GST_TYPE_PINOS_SRC); gst_element_register (plugin, "pinossink", GST_RANK_NONE, GST_TYPE_PINOS_SINK); + + if (!gst_device_provider_register (plugin, "pinosdeviceprovider", + GST_RANK_PRIMARY + 1, GST_TYPE_PINOS_DEVICE_PROVIDER)) + return FALSE; + + GST_DEBUG_CATEGORY_INIT (pinos_debug, "pinos", 0, "Pinos elements"); + return TRUE; } GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, pinos, - "Uses pinos to handle video streams", + "Uses pinos to handle media streams", plugin_init, VERSION, "LGPL", "pinos", "pinos.org") diff --git a/src/gst/gstpinosdeviceprovider.c b/src/gst/gstpinosdeviceprovider.c new file mode 100644 index 000000000..30a7ad68a --- /dev/null +++ b/src/gst/gstpinosdeviceprovider.c @@ -0,0 +1,613 @@ +/* GStreamer + * Copyright (C) 2012 Olivier Crete + * (C) 2015 Wim Taymans + * + * pinosdeviceprovider.c: pinos device probing and monitoring + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +#include "gstpinosdeviceprovider.h" +#include "gstpinossrc.h" +#include "gstpinossink.h" + +GST_DEBUG_CATEGORY_EXTERN (pinos_debug); +#define GST_CAT_DEFAULT pinos_debug + + +static GstDevice *gst_pinos_device_new (const gchar * device_name, + GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type); + +G_DEFINE_TYPE (GstPinosDeviceProvider, gst_pinos_device_provider, + GST_TYPE_DEVICE_PROVIDER); + +static void gst_pinos_device_provider_finalize (GObject * object); +static void gst_pinos_device_provider_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec); +static void gst_pinos_device_provider_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec); + + +static GList *gst_pinos_device_provider_probe (GstDeviceProvider * provider); +static gboolean gst_pinos_device_provider_start (GstDeviceProvider * provider); +static void gst_pinos_device_provider_stop (GstDeviceProvider * provider); + +enum +{ + PROP_0, + PROP_CLIENT_NAME, + PROP_LAST +}; + +static gchar * +pinos_client_name (void) +{ + const char *c; + + if ((c = g_get_application_name ())) + return g_strdup (c); + else + return g_strdup_printf ("GStreamer-pid-%lu", (gulong) getpid ()); +} + + +static void +gst_pinos_device_provider_class_init (GstPinosDeviceProviderClass * klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GstDeviceProviderClass *dm_class = GST_DEVICE_PROVIDER_CLASS (klass); + gchar *client_name; + + gobject_class->set_property = gst_pinos_device_provider_set_property; + gobject_class->get_property = gst_pinos_device_provider_get_property; + gobject_class->finalize = gst_pinos_device_provider_finalize; + + dm_class->probe = gst_pinos_device_provider_probe; + dm_class->start = gst_pinos_device_provider_start; + dm_class->stop = gst_pinos_device_provider_stop; + + client_name = pinos_client_name (); + g_object_class_install_property (gobject_class, + PROP_CLIENT_NAME, + g_param_spec_string ("client-name", "Client Name", + "The Pinos client_name_to_use", client_name, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | + GST_PARAM_MUTABLE_READY)); + g_free (client_name); + + gst_device_provider_class_set_static_metadata (dm_class, + "Pinos Device Provider", "Sink/Source/Audio/Video", + "List and provide Pinos source and sink devices", + "Wim Taymans "); +} + +static void +gst_pinos_device_provider_init (GstPinosDeviceProvider * self) +{ + self->client_name = pinos_client_name (); +} + +static void +gst_pinos_device_provider_finalize (GObject * object) +{ + GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object); + + g_free (self->client_name); + + G_OBJECT_CLASS (gst_pinos_device_provider_parent_class)->finalize (object); +} + + +static void +gst_pinos_device_provider_set_property (GObject * object, + guint prop_id, const GValue * value, GParamSpec * pspec) +{ + GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object); + + switch (prop_id) { + case PROP_CLIENT_NAME: + g_free (self->client_name); + if (!g_value_get_string (value)) { + GST_WARNING_OBJECT (self, + "Empty Pinos client name not allowed. " + "Resetting to default value"); + self->client_name = pinos_client_name (); + } else + self->client_name = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_pinos_device_provider_get_property (GObject * object, + guint prop_id, GValue * value, GParamSpec * pspec) +{ + GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (object); + + switch (prop_id) { + case PROP_CLIENT_NAME: + g_value_set_string (value, self->client_name); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static GstDevice * +new_source (const PinosSourceInfo *info) +{ + GstCaps *caps; + + caps = gst_caps_from_string (g_bytes_get_data (info->formats, NULL)); + + return gst_pinos_device_new (info->name, + caps, info->name, GST_PINOS_DEVICE_TYPE_SOURCE); +} + +typedef struct { + gboolean end; + GList **devices; +} InfoData; + +static gboolean +list_source_info_cb (PinosContext *c, + const PinosSourceInfo *info, + gpointer user_data) +{ + InfoData *data = user_data; + + if (info == NULL) { + data->end = TRUE; + return FALSE; + } + + *data->devices = g_list_prepend (*data->devices, gst_object_ref_sink (new_source (info))); + + return TRUE; +} + +static gboolean +get_source_info_cb (PinosContext *context, + const PinosSourceInfo *info, + gpointer user_data) +{ + GstPinosDeviceProvider *self = user_data; + GstDevice *dev; + + if (info == NULL) { + pinos_main_loop_signal (self->loop, FALSE); + return FALSE; + } + + dev = new_source (info); + + if (dev) + gst_device_provider_device_add (GST_DEVICE_PROVIDER (self), dev); + + return TRUE; +} + +static void +context_subscribe_cb (PinosContext *context, + PinosSubscriptionEvent type, + PinosSubscriptionFlags flags, + gpointer id, + gpointer user_data) +{ + GstPinosDeviceProvider *self = user_data; + GstDeviceProvider *provider = user_data; + + if (flags != PINOS_SUBSCRIPTION_FLAGS_SOURCE) + return; + + if (type == PINOS_SUBSCRIPTION_EVENT_NEW) { + if (flags == PINOS_SUBSCRIPTION_FLAGS_SOURCE) + pinos_context_get_source_info_by_id (context, + id, + PINOS_SOURCE_INFO_FLAGS_FORMATS, + get_source_info_cb, + NULL, + self); + } else if (type == PINOS_SUBSCRIPTION_EVENT_REMOVE) { + GstPinosDevice *dev = NULL; + GList *item; + + GST_OBJECT_LOCK (self); + for (item = provider->devices; item; item = item->next) { + dev = item->data; + + if (((flags == PINOS_SUBSCRIPTION_FLAGS_SOURCE && + dev->type == GST_PINOS_DEVICE_TYPE_SOURCE)) && + dev->id == id) { + gst_object_ref (dev); + break; + } + dev = NULL; + } + GST_OBJECT_UNLOCK (self); + + if (dev) { + gst_device_provider_device_remove (GST_DEVICE_PROVIDER (self), + GST_DEVICE (dev)); + gst_object_unref (dev); + } + } +} + +static GList * +gst_pinos_device_provider_probe (GstDeviceProvider * provider) +{ + GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (provider); + GMainContext *m = NULL; + PinosContext *c = NULL; + InfoData data; + + if (!(m = g_main_context_new ())) + return NULL; + + if (!(c = pinos_context_new (m, self->client_name, NULL))) + goto failed; + + g_main_context_push_thread_default (m); + + pinos_context_connect (c, PINOS_CONTEXT_FLAGS_NONE); + + for (;;) { + PinosContextState state; + + state = pinos_context_get_state (c); + + if (state <= 0) { + GST_ERROR_OBJECT (self, "Failed to connect: %s", + pinos_context_get_error (c)->message); + goto failed; + } + + if (state == PINOS_CONTEXT_STATE_READY) + break; + + /* Wait until something happens */ + g_main_context_iteration (m, TRUE); + } + GST_DEBUG_OBJECT (self, "connected"); + + data.end = FALSE; + data.devices = NULL; + pinos_context_list_source_info (c, + PINOS_SOURCE_INFO_FLAGS_FORMATS, + list_source_info_cb, + NULL, + &data); + for (;;) { + if (pinos_context_get_state (c) <= 0) + break; + if (data.end) + break; + g_main_context_iteration (m, TRUE); + } + + pinos_context_disconnect (c); + g_clear_object (&c); + + g_main_context_pop_thread_default (m); + g_clear_object (&m); + + return *data.devices; + +failed: + + return NULL; +} + +static void +context_state_notify (GObject *gobject, + GParamSpec *pspec, + gpointer user_data) +{ + GstPinosDeviceProvider *self = user_data; + PinosContext *context = PINOS_CONTEXT (gobject); + PinosContextState state; + + state= pinos_context_get_state (context); + + GST_DEBUG ("got context state %d", state); + + switch (state) { + case PINOS_CONTEXT_STATE_CONNECTING: + case PINOS_CONTEXT_STATE_REGISTERING: + break; + case PINOS_CONTEXT_STATE_UNCONNECTED: + case PINOS_CONTEXT_STATE_READY: + case PINOS_CONTEXT_STATE_ERROR: + GST_ERROR_OBJECT (self, "context error: %s", + pinos_context_get_error (context)->message); + break; + } + pinos_main_loop_signal (self->loop, FALSE); +} + +static gboolean +gst_pinos_device_provider_start (GstDeviceProvider * provider) +{ + GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (provider); + GError *error = NULL; + GMainContext *c; + + c = g_main_context_new (); + + if (!(self->loop = pinos_main_loop_new (c, "pinos-device-monitor"))) { + GST_ERROR_OBJECT (self, "Could not create pinos mainloop"); + goto mainloop_failed; + } + if (!pinos_main_loop_start (self->loop, &error)) { + GST_ERROR_OBJECT (self, "Could not start pinos mainloop: %s", error->message); + g_clear_object (&self->loop); + goto mainloop_failed; + } + + pinos_main_loop_lock (self->loop); + + if (!(self->context = pinos_context_new (c, self->client_name, NULL))) { + GST_ERROR_OBJECT (self, "Failed to create context"); + goto unlock_and_fail; + } + + g_signal_connect (self->context, + "notify::state", + (GCallback) context_state_notify, + self); + + g_object_set (self->context, + "subscription-mask", PINOS_SUBSCRIPTION_FLAGS_ALL, + NULL); + g_signal_connect (self->context, + "subscription-event", + (GCallback) context_subscribe_cb, + self); + + pinos_context_connect (self->context, PINOS_CONTEXT_FLAGS_NONE); + + for (;;) { + PinosContextState state; + + state = pinos_context_get_state (self->context); + + if (state <= 0) { + GST_ERROR_OBJECT (self, "Failed to connect: %s", + pinos_context_get_error (self->context)->message); + goto unlock_and_fail; + } + + if (state == PINOS_CONTEXT_STATE_READY) + break; + + /* Wait until the context is ready */ + pinos_main_loop_wait (self->loop); + } + GST_DEBUG_OBJECT (self, "connected"); + + pinos_context_list_source_info (self->context, + PINOS_SOURCE_INFO_FLAGS_FORMATS, + get_source_info_cb, + NULL, + self); + + for (;;) { + if (pinos_context_get_state (self->context) <= 0) + goto unlock_and_fail; + + pinos_main_loop_wait (self->loop); + } + pinos_main_loop_unlock (self->loop); + + return TRUE; + +mainloop_failed: + { + return FALSE; + } +unlock_and_fail: + { + pinos_main_loop_unlock (self->loop); + gst_pinos_device_provider_stop (provider); + return FALSE; + } +} + +static void +gst_pinos_device_provider_stop (GstDeviceProvider * provider) +{ + GstPinosDeviceProvider *self = GST_PINOS_DEVICE_PROVIDER (provider); + + if (self->context) { + pinos_context_disconnect (self->context); + } + pinos_main_loop_stop (self->loop); + + g_clear_object (&self->context); + g_clear_object (&self->loop); +} + +enum +{ + PROP_INTERNAL_NAME = 1, +}; + +G_DEFINE_TYPE (GstPinosDevice, gst_pinos_device, GST_TYPE_DEVICE); + +static void gst_pinos_device_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); +static void gst_pinos_device_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_pinos_device_finalize (GObject * object); +static GstElement *gst_pinos_device_create_element (GstDevice * device, + const gchar * name); +static gboolean gst_pinos_device_reconfigure_element (GstDevice * device, + GstElement * element); + +static void +gst_pinos_device_class_init (GstPinosDeviceClass * klass) +{ + GstDeviceClass *dev_class = GST_DEVICE_CLASS (klass); + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + dev_class->create_element = gst_pinos_device_create_element; + dev_class->reconfigure_element = gst_pinos_device_reconfigure_element; + + object_class->get_property = gst_pinos_device_get_property; + object_class->set_property = gst_pinos_device_set_property; + object_class->finalize = gst_pinos_device_finalize; + + g_object_class_install_property (object_class, PROP_INTERNAL_NAME, + g_param_spec_string ("internal-name", "Internal Pinos device name", + "The internal name of the Pinos device", "", + G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + +static void +gst_pinos_device_init (GstPinosDevice * device) +{ +} + +static void +gst_pinos_device_finalize (GObject * object) +{ + GstPinosDevice *device = GST_PINOS_DEVICE (object); + + g_free (device->internal_name); + + G_OBJECT_CLASS (gst_pinos_device_parent_class)->finalize (object); +} + +static GstElement * +gst_pinos_device_create_element (GstDevice * device, const gchar * name) +{ + GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device); + GstElement *elem; + + elem = gst_element_factory_make (pinos_dev->element, name); + g_object_set (elem, "source", pinos_dev->internal_name, NULL); + + return elem; +} + +static gboolean +gst_pinos_device_reconfigure_element (GstDevice * device, GstElement * element) +{ + GstPinosDevice *pinos_dev = GST_PINOS_DEVICE (device); + + if (!strcmp (pinos_dev->element, "pinossrc")) { + if (!GST_IS_PINOS_SRC (element)) + return FALSE; + } else if (!strcmp (pinos_dev->element, "pinossink")) { + if (!GST_IS_PINOS_SINK (element)) + return FALSE; + } else { + g_assert_not_reached (); + } + + g_object_set (element, "source", pinos_dev->internal_name, NULL); + + return TRUE; +} + +static GstDevice * +gst_pinos_device_new (const gchar * device_name, + GstCaps * caps, const gchar * internal_name, GstPinosDeviceType type) +{ + GstPinosDevice *gstdev; + const gchar *element = NULL; + const gchar *klass = NULL; + + g_return_val_if_fail (device_name, NULL); + g_return_val_if_fail (internal_name, NULL); + g_return_val_if_fail (caps, NULL); + + + switch (type) { + case GST_PINOS_DEVICE_TYPE_SOURCE: + element = "pinossrc"; + klass = "Audio/Source"; + break; + case GST_PINOS_DEVICE_TYPE_SINK: + element = "pinossink"; + klass = "Audio/Sink"; + break; + default: + g_assert_not_reached (); + break; + } + + + gstdev = g_object_new (GST_TYPE_PINOS_DEVICE, + "display-name", device_name, "caps", caps, "device-class", klass, + "internal-name", internal_name, NULL); + + gstdev->type = type; + gstdev->element = element; + + return GST_DEVICE (gstdev); +} + + +static void +gst_pinos_device_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstPinosDevice *device; + + device = GST_PINOS_DEVICE_CAST (object); + + switch (prop_id) { + case PROP_INTERNAL_NAME: + g_value_set_string (value, device->internal_name); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + + +static void +gst_pinos_device_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstPinosDevice *device; + + device = GST_PINOS_DEVICE_CAST (object); + + switch (prop_id) { + case PROP_INTERNAL_NAME: + device->internal_name = g_value_dup_string (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} diff --git a/src/gst/gstpinosdeviceprovider.h b/src/gst/gstpinosdeviceprovider.h new file mode 100644 index 000000000..9a65d2cd3 --- /dev/null +++ b/src/gst/gstpinosdeviceprovider.h @@ -0,0 +1,99 @@ +/* GStreamer + * Copyright (C) 2012 Olivier Crete + * (C) 2015 Wim Taymans + * + * pinosdeviceprovider.h: Device probing and monitoring + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_PINOS_DEVICE_PROVIDER_H__ +#define __GST_PINOS_DEVICE_PROVIDER_H__ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +G_BEGIN_DECLS + +typedef struct _GstPinosDeviceProvider GstPinosDeviceProvider; +typedef struct _GstPinosDeviceProviderClass GstPinosDeviceProviderClass; + +#define GST_TYPE_PINOS_DEVICE_PROVIDER (gst_pinos_device_provider_get_type()) +#define GST_IS_PINOS_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINOS_DEVICE_PROVIDER)) +#define GST_IS_PINOS_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINOS_DEVICE_PROVIDER)) +#define GST_PINOS_DEVICE_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINOS_DEVICE_PROVIDER, GstPinosDeviceProviderClass)) +#define GST_PINOS_DEVICE_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINOS_DEVICE_PROVIDER, GstPinosDeviceProvider)) +#define GST_PINOS_DEVICE_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE_PROVIDER, GstPinosDeviceProviderClass)) +#define GST_PINOS_DEVICE_PROVIDER_CAST(obj) ((GstPinosDeviceProvider *)(obj)) + +struct _GstPinosDeviceProvider { + GstDeviceProvider parent; + + gchar *client_name; + + GMainContext *maincontext; + PinosMainLoop *loop; + + PinosContext *context; +}; + +typedef enum { + GST_PINOS_DEVICE_TYPE_SOURCE, + GST_PINOS_DEVICE_TYPE_SINK, +} GstPinosDeviceType; + +struct _GstPinosDeviceProviderClass { + GstDeviceProviderClass parent_class; +}; + +GType gst_pinos_device_provider_get_type (void); + + +typedef struct _GstPinosDevice GstPinosDevice; +typedef struct _GstPinosDeviceClass GstPinosDeviceClass; + +#define GST_TYPE_PINOS_DEVICE (gst_pinos_device_get_type()) +#define GST_IS_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_PINOS_DEVICE)) +#define GST_IS_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_PINOS_DEVICE)) +#define GST_PINOS_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDeviceClass)) +#define GST_PINOS_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_PINOS_DEVICE, GstPinosDevice)) +#define GST_PINOS_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DEVICE, GstPinosDeviceClass)) +#define GST_PINOS_DEVICE_CAST(obj) ((GstPinosDevice *)(obj)) + +struct _GstPinosDevice { + GstDevice parent; + + GstPinosDeviceType type; + gpointer id; + gchar *internal_name; + const gchar *element; +}; + +struct _GstPinosDeviceClass { + GstDeviceClass parent_class; +}; + +GType gst_pinos_device_get_type (void); + +G_END_DECLS + +#endif /* __GST_PINOS_DEVICE_PROVIDER_H__ */ diff --git a/src/gst/gstpinossrc.c b/src/gst/gstpinossrc.c index d55203aca..9e4c03475 100644 --- a/src/gst/gstpinossrc.c +++ b/src/gst/gstpinossrc.c @@ -519,7 +519,7 @@ gst_pinos_src_open (GstPinosSrc * pinossrc) pinossrc->ctx = pinos_context_new (pinossrc->context, "test-client", NULL); g_signal_connect (pinossrc->ctx, "notify::state", (GCallback) on_context_notify, pinossrc); - pinos_context_connect(pinossrc->ctx, PINOS_CONTEXT_FLAGS_NONE); + pinos_context_connect (pinossrc->ctx, PINOS_CONTEXT_FLAGS_NONE); while (TRUE) { PinosContextState state = pinos_context_get_state (pinossrc->ctx); diff --git a/src/modules/gst/gst-manager.c b/src/modules/gst/gst-manager.c index 6ed68d00d..cd1a11579 100644 --- a/src/modules/gst/gst-manager.c +++ b/src/modules/gst/gst-manager.c @@ -80,7 +80,6 @@ bus_handler (GstBus *bus, gpointer user_data) { PinosGstManager *manager = user_data; - PinosGstManagerPrivate *priv = manager->priv; GstDevice *device; switch (GST_MESSAGE_TYPE (message)) { diff --git a/src/tests/test-subscribe.c b/src/tests/test-subscribe.c index a0a81423b..d0719bec1 100644 --- a/src/tests/test-subscribe.c +++ b/src/tests/test-subscribe.c @@ -30,22 +30,26 @@ dump_object (GDBusProxy *proxy) } static void -subscription_cb (PinosContext *context, PinosSubscriptionEvent type, PinosSubscriptionFlags flags, - GDBusProxy *object, gpointer user_data) +subscription_cb (PinosContext *context, + PinosSubscriptionEvent type, + PinosSubscriptionFlags flags, + gpointer id, + gpointer user_data) { switch (type) { case PINOS_SUBSCRIPTION_EVENT_NEW: - g_print ("object added %s\n", g_dbus_proxy_get_object_path (object)); - dump_object (object); + g_print ("object added %s\n", g_dbus_proxy_get_object_path (id)); + dump_object (G_DBUS_PROXY (id)); break; case PINOS_SUBSCRIPTION_EVENT_CHANGE: - g_print ("object changed %s\n", g_dbus_proxy_get_object_path (object)); - dump_object (object); + g_print ("object changed %s\n", g_dbus_proxy_get_object_path (id)); + dump_object (G_DBUS_PROXY (id)); break; case PINOS_SUBSCRIPTION_EVENT_REMOVE: - g_print ("object removed %s\n", g_dbus_proxy_get_object_path (object)); + g_print ("object removed %s\n", g_dbus_proxy_get_object_path (id)); + dump_object (G_DBUS_PROXY (id)); break; } }