2013-01-09 02:30:44 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2013 Olivier Crete <olivier.crete@collabora.com>
|
|
|
|
*
|
2014-06-26 19:08:46 +00:00
|
|
|
* gstdevicemonitor.c: device monitor
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-06-20 20:55:06 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-26 19:08:46 +00:00
|
|
|
* SECTION:gstdevicemonitor
|
|
|
|
* @short_description: A device monitor and prober
|
2014-06-26 18:28:09 +00:00
|
|
|
* @see_also: #GstDevice, #GstDeviceProvider
|
2014-06-20 20:55:06 +00:00
|
|
|
*
|
2014-06-26 19:08:46 +00:00
|
|
|
* Applications should create a #GstDeviceMonitor when they want
|
2014-06-20 20:55:06 +00:00
|
|
|
* to probe, list and monitor devices of a specific type. The
|
2014-06-26 19:08:46 +00:00
|
|
|
* #GstDeviceMonitor will create the appropriate
|
2014-06-26 18:28:09 +00:00
|
|
|
* #GstDeviceProvider objects and manage them. It will then post
|
2014-06-20 20:55:06 +00:00
|
|
|
* messages on its #GstBus for devices that have been added and
|
|
|
|
* removed.
|
|
|
|
*
|
2014-06-26 21:13:12 +00:00
|
|
|
* The device monitor will monitor all devices matching the filters that
|
|
|
|
* the application has set.
|
|
|
|
*
|
2014-06-26 21:22:25 +00:00
|
|
|
*
|
2014-06-27 09:44:32 +00:00
|
|
|
* The basic use pattern of a device monitor is as follows:
|
2014-06-26 21:22:25 +00:00
|
|
|
* |[
|
|
|
|
* static gboolean
|
|
|
|
* my_bus_func (GstBus * bus, GstMessage * message, gpointer user_data)
|
|
|
|
* {
|
|
|
|
* GstDevice *device;
|
2014-09-03 16:38:16 +00:00
|
|
|
* gchar *name;
|
2014-06-26 21:22:25 +00:00
|
|
|
*
|
|
|
|
* switch (GST_MESSAGE_TYPE (message)) {
|
|
|
|
* case GST_MESSAGE_DEVICE_ADDED:
|
|
|
|
* gst_message_parse_device_added (message, &device);
|
|
|
|
* name = gst_device_get_display_name (device);
|
|
|
|
* g_print("Device added: %s\n", name);
|
|
|
|
* g_free (name);
|
|
|
|
* break;
|
|
|
|
* case GST_MESSAGE_DEVICE_REMOVED:
|
|
|
|
* gst_message_parse_device_removed (message, &device);
|
|
|
|
* name = gst_device_get_display_name (device);
|
|
|
|
* g_print("Device removed: %s\n", name);
|
|
|
|
* g_free (name);
|
|
|
|
* break;
|
|
|
|
* default:
|
|
|
|
* break;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* return G_SOURCE_CONTINUE;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* GstDeviceMonitor *
|
|
|
|
* setup_raw_video_source_device_monitor (void) {
|
|
|
|
* GstDeviceMonitor *monitor;
|
|
|
|
* GstBus *bus;
|
|
|
|
* GstCaps *caps;
|
|
|
|
*
|
|
|
|
* monitor = gst_device_monitor_new ();
|
|
|
|
*
|
|
|
|
* bus = gst_device_monitor_get_bus (monitor);
|
|
|
|
* gst_bus_add_watch (bus, my_bus_func, NULL);
|
|
|
|
* gst_object_unref (bus);
|
|
|
|
*
|
2014-09-03 16:38:16 +00:00
|
|
|
* caps = gst_caps_new_empty_simple ("video/x-raw");
|
2014-06-26 21:22:25 +00:00
|
|
|
* gst_device_monitor_add_filter (monitor, "Video/Source", caps);
|
|
|
|
* gst_caps_unref (caps);
|
|
|
|
*
|
|
|
|
* gst_device_monitor_start (monitor);
|
|
|
|
*
|
|
|
|
* return monitor;
|
|
|
|
* }
|
|
|
|
* ]|
|
|
|
|
*
|
2014-06-20 20:55:06 +00:00
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-03-17 08:51:45 +00:00
|
|
|
#include "gst_private.h"
|
2014-06-26 19:08:46 +00:00
|
|
|
#include "gstdevicemonitor.h"
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
struct _GstDeviceMonitorPrivate
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
|
|
|
gboolean started;
|
|
|
|
|
|
|
|
GstBus *bus;
|
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
GPtrArray *providers;
|
2013-01-09 02:30:44 +00:00
|
|
|
guint cookie;
|
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
GPtrArray *filters;
|
|
|
|
|
|
|
|
guint last_id;
|
2015-07-16 16:56:00 +00:00
|
|
|
GList *hidden;
|
|
|
|
gboolean show_all;
|
2013-01-09 02:30:44 +00:00
|
|
|
};
|
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
#define DEFAULT_SHOW_ALL FALSE
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_SHOW_ALL = 1,
|
|
|
|
};
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
G_DEFINE_TYPE (GstDeviceMonitor, gst_device_monitor, GST_TYPE_OBJECT);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
static void gst_device_monitor_dispose (GObject * object);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
struct DeviceFilter
|
|
|
|
{
|
|
|
|
guint id;
|
|
|
|
|
|
|
|
gchar **classesv;
|
|
|
|
GstCaps *caps;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_filter_free (struct DeviceFilter *filter)
|
|
|
|
{
|
|
|
|
g_strfreev (filter->classesv);
|
|
|
|
gst_caps_unref (filter->caps);
|
|
|
|
|
|
|
|
g_slice_free (struct DeviceFilter, filter);
|
|
|
|
}
|
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
static void
|
|
|
|
gst_device_monitor_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDeviceMonitor *monitor = GST_DEVICE_MONITOR (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_SHOW_ALL:
|
|
|
|
g_value_set_boolean (value,
|
|
|
|
gst_device_monitor_get_show_all_devices (monitor));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_device_monitor_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstDeviceMonitor *monitor = GST_DEVICE_MONITOR (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_SHOW_ALL:
|
|
|
|
gst_device_monitor_set_show_all_devices (monitor,
|
|
|
|
g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
static void
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_class_init (GstDeviceMonitorClass * klass)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstDeviceMonitorPrivate));
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
object_class->get_property = gst_device_monitor_get_property;
|
|
|
|
object_class->set_property = gst_device_monitor_set_property;
|
2014-06-26 19:08:46 +00:00
|
|
|
object_class->dispose = gst_device_monitor_dispose;
|
2015-07-16 16:56:00 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_SHOW_ALL,
|
|
|
|
g_param_spec_boolean ("show-all", "Show All",
|
|
|
|
"Show all devices, even those from hidden providers",
|
|
|
|
DEFAULT_SHOW_ALL, G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with monitor lock */
|
|
|
|
static gboolean
|
|
|
|
is_provider_hidden (GstDeviceMonitor * monitor, GList * hidden,
|
|
|
|
GstDeviceProvider * provider)
|
|
|
|
{
|
|
|
|
GstDeviceProviderFactory *factory;
|
|
|
|
|
|
|
|
if (monitor->priv->show_all)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
factory = gst_device_provider_get_factory (provider);
|
|
|
|
if (g_list_find_custom (hidden, GST_OBJECT_NAME (factory),
|
|
|
|
(GCompareFunc) g_strcmp0))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be called with monitor lock */
|
|
|
|
static void
|
|
|
|
update_hidden_providers_list (GList ** hidden, GstDeviceProvider * provider)
|
|
|
|
{
|
|
|
|
gchar **obs;
|
|
|
|
|
|
|
|
obs = gst_device_provider_get_hidden_providers (provider);
|
|
|
|
if (obs) {
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; obs[i]; i++)
|
|
|
|
*hidden = g_list_prepend (*hidden, obs[i]);
|
|
|
|
|
|
|
|
g_free (obs);
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bus_sync_message (GstBus * bus, GstMessage * message,
|
2014-06-26 19:08:46 +00:00
|
|
|
GstDeviceMonitor * monitor)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2014-03-16 15:19:49 +00:00
|
|
|
GstMessageType type = GST_MESSAGE_TYPE (message);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-03-16 15:19:49 +00:00
|
|
|
if (type == GST_MESSAGE_DEVICE_ADDED || type == GST_MESSAGE_DEVICE_REMOVED) {
|
2014-03-16 19:56:59 +00:00
|
|
|
gboolean matches;
|
2013-01-09 02:30:44 +00:00
|
|
|
GstDevice *device;
|
2015-07-16 16:56:00 +00:00
|
|
|
GstDeviceProvider *provider;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-03-16 15:19:49 +00:00
|
|
|
if (type == GST_MESSAGE_DEVICE_ADDED)
|
2013-01-09 02:30:44 +00:00
|
|
|
gst_message_parse_device_added (message, &device);
|
|
|
|
else
|
|
|
|
gst_message_parse_device_removed (message, &device);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
2015-07-16 16:56:00 +00:00
|
|
|
provider =
|
|
|
|
GST_DEVICE_PROVIDER (gst_object_get_parent (GST_OBJECT (device)));
|
|
|
|
if (is_provider_hidden (monitor, monitor->priv->hidden, provider)) {
|
|
|
|
matches = FALSE;
|
|
|
|
} else if (monitor->priv->filters->len) {
|
2014-06-26 21:13:12 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < monitor->priv->filters->len; i++) {
|
|
|
|
struct DeviceFilter *filter =
|
|
|
|
g_ptr_array_index (monitor->priv->filters, i);
|
|
|
|
GstCaps *caps;
|
|
|
|
|
|
|
|
caps = gst_device_get_caps (device);
|
|
|
|
matches = gst_caps_can_intersect (filter->caps, caps) &&
|
|
|
|
gst_device_has_classesv (device, filter->classesv);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
if (matches)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
matches = TRUE;
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
|
2015-08-08 15:59:51 +00:00
|
|
|
gst_object_unref (provider);
|
2014-06-26 21:13:12 +00:00
|
|
|
gst_object_unref (device);
|
|
|
|
|
2014-03-16 19:56:59 +00:00
|
|
|
if (matches)
|
2013-01-09 02:30:44 +00:00
|
|
|
gst_bus_post (monitor->priv->bus, gst_message_ref (message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_init (GstDeviceMonitor * self)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
2014-06-26 19:08:46 +00:00
|
|
|
GST_TYPE_DEVICE_MONITOR, GstDeviceMonitorPrivate);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
self->priv->show_all = DEFAULT_SHOW_ALL;
|
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
self->priv->bus = gst_bus_new ();
|
|
|
|
gst_bus_set_flushing (self->priv->bus, TRUE);
|
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
self->priv->providers = g_ptr_array_new ();
|
2014-06-26 21:13:12 +00:00
|
|
|
self->priv->filters = g_ptr_array_new_with_free_func (
|
|
|
|
(GDestroyNotify) device_filter_free);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
self->priv->last_id = 1;
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_remove (GstDeviceMonitor * self, guint i)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2014-06-26 18:28:09 +00:00
|
|
|
GstDeviceProvider *provider = g_ptr_array_index (self->priv->providers, i);
|
2013-01-09 02:30:44 +00:00
|
|
|
GstBus *bus;
|
|
|
|
|
2015-07-16 15:25:24 +00:00
|
|
|
g_ptr_array_remove_index (self->priv->providers, i);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
bus = gst_device_provider_get_bus (provider);
|
2013-01-09 02:30:44 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (bus, bus_sync_message, self);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
gst_object_unref (provider);
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_dispose (GObject * object)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2014-06-26 19:08:46 +00:00
|
|
|
GstDeviceMonitor *self = GST_DEVICE_MONITOR (object);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-11-28 13:17:54 +00:00
|
|
|
g_return_if_fail (!self->priv->started);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
if (self->priv->providers) {
|
|
|
|
while (self->priv->providers->len)
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_remove (self, self->priv->providers->len - 1);
|
2014-06-26 18:28:09 +00:00
|
|
|
g_ptr_array_unref (self->priv->providers);
|
|
|
|
self->priv->providers = NULL;
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-30 08:59:18 +00:00
|
|
|
if (self->priv->filters) {
|
|
|
|
g_ptr_array_unref (self->priv->filters);
|
|
|
|
self->priv->filters = NULL;
|
|
|
|
}
|
2014-06-26 21:13:12 +00:00
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
gst_object_replace ((GstObject **) & self->priv->bus, NULL);
|
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
G_OBJECT_CLASS (gst_device_monitor_parent_class)->dispose (object);
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-26 19:08:46 +00:00
|
|
|
* gst_device_monitor_get_devices:
|
2014-06-26 18:28:09 +00:00
|
|
|
* @monitor: A #GstDeviceProvider
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* Gets a list of devices from all of the relevant monitors. This may actually
|
2014-06-26 19:08:46 +00:00
|
|
|
* probe the hardware if the monitor is not currently started.
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full) (element-type GstDevice): a #GList of
|
|
|
|
* #GstDevice
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-01-09 02:30:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
GList *
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_get_devices (GstDeviceMonitor * monitor)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2015-07-16 16:56:00 +00:00
|
|
|
GList *devices = NULL, *hidden = NULL;
|
2013-01-09 02:30:44 +00:00
|
|
|
guint i;
|
|
|
|
guint cookie;
|
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), NULL);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_LOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (monitor->priv->filters->len == 0) {
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
GST_WARNING_OBJECT (monitor, "No filters have been set");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (monitor->priv->providers->len == 0) {
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
GST_WARNING_OBJECT (monitor, "No providers match the current filters");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
again:
|
|
|
|
|
|
|
|
g_list_free_full (devices, gst_object_unref);
|
2015-07-16 16:56:00 +00:00
|
|
|
g_list_free_full (hidden, g_free);
|
2013-01-09 02:30:44 +00:00
|
|
|
devices = NULL;
|
2015-07-16 16:56:00 +00:00
|
|
|
hidden = NULL;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
cookie = monitor->priv->cookie;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
for (i = 0; i < monitor->priv->providers->len; i++) {
|
2013-01-09 02:30:44 +00:00
|
|
|
GList *tmpdev;
|
2014-06-26 18:28:09 +00:00
|
|
|
GstDeviceProvider *provider =
|
|
|
|
gst_object_ref (g_ptr_array_index (monitor->priv->providers, i));
|
2013-01-09 02:30:44 +00:00
|
|
|
GList *item;
|
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
if (!is_provider_hidden (monitor, hidden, provider)) {
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
tmpdev = gst_device_provider_get_devices (provider);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
update_hidden_providers_list (&hidden, provider);
|
|
|
|
} else {
|
|
|
|
tmpdev = NULL;
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
for (item = tmpdev; item; item = item->next) {
|
|
|
|
GstDevice *dev = GST_DEVICE (item->data);
|
|
|
|
GstCaps *caps = gst_device_get_caps (dev);
|
2014-06-26 21:13:12 +00:00
|
|
|
guint j;
|
|
|
|
|
|
|
|
for (j = 0; j < monitor->priv->filters->len; j++) {
|
|
|
|
struct DeviceFilter *filter =
|
|
|
|
g_ptr_array_index (monitor->priv->filters, j);
|
2015-07-16 16:56:00 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (gst_caps_can_intersect (filter->caps, caps) &&
|
|
|
|
gst_device_has_classesv (dev, filter->classesv)) {
|
|
|
|
devices = g_list_prepend (devices, gst_object_ref (dev));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full (tmpdev, gst_object_unref);
|
2014-06-26 18:28:09 +00:00
|
|
|
gst_object_unref (provider);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
if (monitor->priv->cookie != cookie)
|
2013-01-09 02:30:44 +00:00
|
|
|
goto again;
|
|
|
|
}
|
2015-07-16 16:56:00 +00:00
|
|
|
g_list_free_full (hidden, g_free);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 15:25:24 +00:00
|
|
|
return g_list_reverse (devices);
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-26 19:08:46 +00:00
|
|
|
* gst_device_monitor_start:
|
|
|
|
* @monitor: A #GstDeviceMonitor
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* Starts monitoring the devices, one this has succeeded, the
|
2014-06-20 20:55:06 +00:00
|
|
|
* %GST_MESSAGE_DEVICE_ADDED and %GST_MESSAGE_DEVICE_REMOVED messages
|
|
|
|
* will be emitted on the bus when the list of devices changes.
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if the device monitoring could be started
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-01-09 02:30:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_start (GstDeviceMonitor * monitor)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2015-07-16 16:47:20 +00:00
|
|
|
guint cookie, i;
|
|
|
|
GList *pending = NULL, *started = NULL, *removed = NULL;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), FALSE);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_LOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (monitor->priv->filters->len == 0) {
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2014-06-27 09:44:32 +00:00
|
|
|
GST_WARNING_OBJECT (monitor, "No filters have been set, will expose all "
|
|
|
|
"devices found");
|
|
|
|
gst_device_monitor_add_filter (monitor, NULL, NULL);
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
2014-06-26 21:13:12 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
if (monitor->priv->providers->len == 0) {
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2014-06-26 21:13:12 +00:00
|
|
|
GST_WARNING_OBJECT (monitor, "No providers match the current filters");
|
2013-01-09 02:30:44 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
gst_bus_set_flushing (monitor->priv->bus, FALSE);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:47:20 +00:00
|
|
|
again:
|
|
|
|
cookie = monitor->priv->cookie;
|
|
|
|
|
|
|
|
g_list_free_full (pending, gst_object_unref);
|
|
|
|
pending = NULL;
|
|
|
|
removed = started;
|
|
|
|
started = NULL;
|
|
|
|
|
2014-06-26 18:28:09 +00:00
|
|
|
for (i = 0; i < monitor->priv->providers->len; i++) {
|
2015-07-16 16:47:20 +00:00
|
|
|
GstDeviceProvider *provider;
|
|
|
|
GList *find;
|
|
|
|
|
|
|
|
provider = g_ptr_array_index (monitor->priv->providers, i);
|
|
|
|
|
|
|
|
find = g_list_find (removed, provider);
|
|
|
|
if (find) {
|
|
|
|
/* this was already started, move to started list */
|
|
|
|
removed = g_list_remove_link (removed, find);
|
|
|
|
started = g_list_concat (started, find);
|
|
|
|
} else {
|
|
|
|
/* not started, add to pending list */
|
|
|
|
pending = g_list_append (pending, gst_object_ref (provider));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free_full (removed, gst_object_unref);
|
|
|
|
removed = NULL;
|
|
|
|
|
|
|
|
while (pending) {
|
|
|
|
GstDeviceProvider *provider = pending->data;
|
2014-06-26 21:13:12 +00:00
|
|
|
|
|
|
|
if (gst_device_provider_can_monitor (provider)) {
|
2015-07-16 16:47:20 +00:00
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:47:20 +00:00
|
|
|
if (!gst_device_provider_start (provider))
|
|
|
|
goto start_failed;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:47:20 +00:00
|
|
|
GST_OBJECT_LOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
2015-07-16 16:47:20 +00:00
|
|
|
started = g_list_prepend (started, provider);
|
|
|
|
pending = g_list_delete_link (pending, pending);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:47:20 +00:00
|
|
|
if (monitor->priv->cookie != cookie)
|
|
|
|
goto again;
|
|
|
|
}
|
2014-06-14 15:30:49 +00:00
|
|
|
monitor->priv->started = TRUE;
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:47:20 +00:00
|
|
|
g_list_free_full (started, gst_object_unref);
|
|
|
|
|
2013-01-09 02:30:44 +00:00
|
|
|
return TRUE;
|
2015-07-16 16:47:20 +00:00
|
|
|
|
|
|
|
start_failed:
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
gst_bus_set_flushing (monitor->priv->bus, TRUE);
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
|
|
|
|
while (started) {
|
|
|
|
GstDeviceProvider *provider = started->data;
|
|
|
|
|
|
|
|
gst_device_provider_stop (provider);
|
|
|
|
gst_object_unref (provider);
|
|
|
|
|
|
|
|
started = g_list_delete_link (started, started);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-26 19:08:46 +00:00
|
|
|
* gst_device_monitor_stop:
|
2014-06-26 18:28:09 +00:00
|
|
|
* @monitor: A #GstDeviceProvider
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* Stops monitoring the devices.
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-01-09 02:30:44 +00:00
|
|
|
*/
|
|
|
|
void
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_stop (GstDeviceMonitor * monitor)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
|
|
|
guint i;
|
2015-07-16 16:47:20 +00:00
|
|
|
GList *started = NULL;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 19:08:46 +00:00
|
|
|
g_return_if_fail (GST_IS_DEVICE_MONITOR (monitor));
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
gst_bus_set_flushing (monitor->priv->bus, TRUE);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_LOCK (monitor);
|
2014-06-26 21:13:12 +00:00
|
|
|
for (i = 0; i < monitor->priv->providers->len; i++) {
|
|
|
|
GstDeviceProvider *provider =
|
|
|
|
g_ptr_array_index (monitor->priv->providers, i);
|
|
|
|
|
2015-07-16 16:47:20 +00:00
|
|
|
started = g_list_prepend (started, gst_object_ref (provider));
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
|
|
|
|
while (started) {
|
|
|
|
GstDeviceProvider *provider = started->data;
|
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (gst_device_provider_can_monitor (provider))
|
|
|
|
gst_device_provider_stop (provider);
|
2015-07-16 16:47:20 +00:00
|
|
|
|
|
|
|
started = g_list_delete_link (started, started);
|
|
|
|
gst_object_unref (provider);
|
2014-06-26 21:13:12 +00:00
|
|
|
}
|
2015-07-16 16:47:20 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
2014-06-14 15:30:49 +00:00
|
|
|
monitor->priv->started = FALSE;
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
static void
|
|
|
|
provider_hidden (GstDeviceProvider * provider, const gchar * hidden,
|
|
|
|
GstDeviceMonitor * monitor)
|
|
|
|
{
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
monitor->priv->hidden =
|
|
|
|
g_list_prepend (monitor->priv->hidden, g_strdup (hidden));
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
provider_unhidden (GstDeviceProvider * provider, const gchar * hidden,
|
|
|
|
GstDeviceMonitor * monitor)
|
|
|
|
{
|
|
|
|
GList *find;
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
find =
|
|
|
|
g_list_find_custom (monitor->priv->hidden, hidden,
|
|
|
|
(GCompareFunc) g_strcmp0);
|
|
|
|
if (find) {
|
|
|
|
g_free (find->data);
|
|
|
|
monitor->priv->hidden = g_list_delete_link (monitor->priv->hidden, find);
|
|
|
|
}
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
}
|
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
/**
|
2014-06-26 21:13:12 +00:00
|
|
|
* gst_device_monitor_add_filter:
|
|
|
|
* @monitor: a device monitor
|
2014-07-01 06:39:18 +00:00
|
|
|
* @classes: (allow-none): device classes to use as filter or %NULL for any class
|
2014-06-26 21:13:12 +00:00
|
|
|
* @caps: (allow-none): the #GstCaps to filter or %NULL for ANY
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
2014-06-26 21:13:12 +00:00
|
|
|
* Adds a filter for which #GstDevice will be monitored, any device that matches
|
2016-01-14 19:00:59 +00:00
|
|
|
* all these classes and the #GstCaps will be returned.
|
|
|
|
*
|
|
|
|
* If this function is called multiple times to add more filters, each will be
|
|
|
|
* matched independently. That is, adding more filters will not further restrict
|
|
|
|
* what devices are matched.
|
|
|
|
*
|
|
|
|
* The #GstCaps supported by the device as returned by gst_device_get_caps() are
|
|
|
|
* not intersected with caps filters added using this function.
|
2014-06-26 21:13:12 +00:00
|
|
|
*
|
|
|
|
* Filters must be added before the #GstDeviceMonitor is started.
|
|
|
|
*
|
2015-06-14 14:25:52 +00:00
|
|
|
* Returns: The id of the new filter or 0 if no provider matched the filter's
|
2014-06-26 21:13:12 +00:00
|
|
|
* classes.
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
2014-06-26 21:13:12 +00:00
|
|
|
guint
|
|
|
|
gst_device_monitor_add_filter (GstDeviceMonitor * monitor,
|
|
|
|
const gchar * classes, GstCaps * caps)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
|
|
|
GList *factories = NULL;
|
2014-06-26 21:13:12 +00:00
|
|
|
struct DeviceFilter *filter;
|
|
|
|
guint id = 0;
|
|
|
|
gboolean matched = FALSE;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), 0);
|
|
|
|
g_return_val_if_fail (!monitor->priv->started, 0);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_LOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
filter = g_slice_new0 (struct DeviceFilter);
|
|
|
|
filter->id = monitor->priv->last_id++;
|
|
|
|
if (caps)
|
|
|
|
filter->caps = gst_caps_ref (caps);
|
|
|
|
else
|
|
|
|
filter->caps = gst_caps_new_any ();
|
|
|
|
if (classes)
|
|
|
|
filter->classesv = g_strsplit (classes, "/", 0);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
factories = gst_device_provider_factory_list_get_device_providers (1);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
while (factories) {
|
|
|
|
GstDeviceProviderFactory *factory = factories->data;
|
2014-06-14 15:30:49 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (gst_device_provider_factory_has_classesv (factory, filter->classesv)) {
|
|
|
|
GstDeviceProvider *provider;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
provider = gst_device_provider_factory_get (factory);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (provider) {
|
|
|
|
guint i;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
for (i = 0; i < monitor->priv->providers->len; i++) {
|
|
|
|
if (g_ptr_array_index (monitor->priv->providers, i) == provider) {
|
|
|
|
gst_object_unref (provider);
|
|
|
|
provider = NULL;
|
|
|
|
matched = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
if (provider) {
|
|
|
|
GstBus *bus = gst_device_provider_get_bus (provider);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2015-07-16 16:56:00 +00:00
|
|
|
update_hidden_providers_list (&monitor->priv->hidden, provider);
|
|
|
|
g_signal_connect (provider, "provider-hidden",
|
|
|
|
(GCallback) provider_hidden, monitor);
|
|
|
|
g_signal_connect (provider, "provider-unhidden",
|
|
|
|
(GCallback) provider_unhidden, monitor);
|
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
matched = TRUE;
|
|
|
|
gst_bus_enable_sync_message_emission (bus);
|
|
|
|
g_signal_connect (bus, "sync-message",
|
|
|
|
G_CALLBACK (bus_sync_message), monitor);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
g_ptr_array_add (monitor->priv->providers, provider);
|
|
|
|
monitor->priv->cookie++;
|
|
|
|
}
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
factories = g_list_remove (factories, factory);
|
2013-01-09 02:30:44 +00:00
|
|
|
gst_object_unref (factory);
|
|
|
|
}
|
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
/* Ensure there is no leak here */
|
|
|
|
g_assert (factories == NULL);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2016-01-14 18:55:05 +00:00
|
|
|
if (matched)
|
2014-06-26 21:13:12 +00:00
|
|
|
id = filter->id;
|
2016-01-14 18:55:05 +00:00
|
|
|
g_ptr_array_add (monitor->priv->filters, filter);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
return id;
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
/**
|
2014-06-26 21:13:12 +00:00
|
|
|
* gst_device_monitor_remove_filter:
|
2014-06-26 19:08:46 +00:00
|
|
|
* @monitor: a device monitor
|
2014-06-26 21:13:12 +00:00
|
|
|
* @filter_id: the id of the filter
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
2014-06-26 21:13:12 +00:00
|
|
|
* Removes a filter from the #GstDeviceMonitor using the id that was returned
|
|
|
|
* by gst_device_monitor_add_filter().
|
2014-06-20 20:55:06 +00:00
|
|
|
*
|
2014-06-26 21:13:12 +00:00
|
|
|
* Returns: %TRUE of the filter id was valid, %FALSE otherwise
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
2014-06-26 21:13:12 +00:00
|
|
|
gboolean
|
|
|
|
gst_device_monitor_remove_filter (GstDeviceMonitor * monitor, guint filter_id)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2014-06-26 21:13:12 +00:00
|
|
|
guint i, j;
|
|
|
|
gboolean removed = FALSE;
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), FALSE);
|
|
|
|
g_return_val_if_fail (!monitor->priv->started, FALSE);
|
|
|
|
g_return_val_if_fail (filter_id > 0, FALSE);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_LOCK (monitor);
|
2014-06-26 21:13:12 +00:00
|
|
|
for (i = 0; i < monitor->priv->filters->len; i++) {
|
|
|
|
struct DeviceFilter *filter = g_ptr_array_index (monitor->priv->filters, i);
|
|
|
|
|
|
|
|
if (filter->id == filter_id) {
|
|
|
|
g_ptr_array_remove_index (monitor->priv->filters, i);
|
|
|
|
removed = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (removed) {
|
|
|
|
for (i = 0; i < monitor->priv->providers->len; i++) {
|
|
|
|
GstDeviceProvider *provider =
|
|
|
|
g_ptr_array_index (monitor->priv->providers, i);
|
|
|
|
GstDeviceProviderFactory *factory =
|
|
|
|
gst_device_provider_get_factory (provider);
|
|
|
|
gboolean valid = FALSE;
|
|
|
|
|
|
|
|
for (j = 0; j < monitor->priv->filters->len; j++) {
|
|
|
|
struct DeviceFilter *filter =
|
|
|
|
g_ptr_array_index (monitor->priv->filters, j);
|
|
|
|
|
|
|
|
if (gst_device_provider_factory_has_classesv (factory,
|
|
|
|
filter->classesv)) {
|
|
|
|
valid = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
monitor->priv->cookie++;
|
|
|
|
gst_device_monitor_remove (monitor, i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
return removed;
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
2014-06-26 21:13:12 +00:00
|
|
|
|
|
|
|
|
2014-06-14 15:30:49 +00:00
|
|
|
/**
|
2014-06-26 19:08:46 +00:00
|
|
|
* gst_device_monitor_new:
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
2014-06-26 19:08:46 +00:00
|
|
|
* Create a new #GstDeviceMonitor
|
2014-06-20 20:55:06 +00:00
|
|
|
*
|
2014-06-26 19:08:46 +00:00
|
|
|
* Returns: (transfer full): a new device monitor.
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
2014-06-26 19:08:46 +00:00
|
|
|
GstDeviceMonitor *
|
|
|
|
gst_device_monitor_new (void)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2014-06-26 19:08:46 +00:00
|
|
|
return g_object_new (GST_TYPE_DEVICE_MONITOR, NULL);
|
2013-01-09 02:30:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-26 19:08:46 +00:00
|
|
|
* gst_device_monitor_get_bus:
|
2014-06-26 18:28:09 +00:00
|
|
|
* @monitor: a #GstDeviceProvider
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
2014-06-26 19:08:46 +00:00
|
|
|
* Gets the #GstBus of this #GstDeviceMonitor
|
2013-01-09 02:30:44 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): a #GstBus
|
2014-06-14 15:30:49 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-01-09 02:30:44 +00:00
|
|
|
*/
|
|
|
|
GstBus *
|
2014-06-26 19:08:46 +00:00
|
|
|
gst_device_monitor_get_bus (GstDeviceMonitor * monitor)
|
2013-01-09 02:30:44 +00:00
|
|
|
{
|
2014-06-26 19:08:46 +00:00
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), NULL);
|
2013-01-09 02:30:44 +00:00
|
|
|
|
|
|
|
return gst_object_ref (monitor->priv->bus);
|
|
|
|
}
|
2015-07-17 08:18:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_device_monitor_get_providers:
|
|
|
|
* @monitor: a #GstDeviceMonitor
|
|
|
|
*
|
|
|
|
* Get a list of the currently selected device provider factories.
|
|
|
|
*
|
|
|
|
* This
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (array zero-terminated=1) (element-type gchar*):
|
|
|
|
* A list of device provider factory names that are currently being
|
|
|
|
* monitored by @monitor or %NULL when nothing is being monitored.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gchar **
|
|
|
|
gst_device_monitor_get_providers (GstDeviceMonitor * monitor)
|
|
|
|
{
|
|
|
|
guint i, len;
|
|
|
|
gchar **res = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), NULL);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
len = monitor->priv->providers->len;
|
|
|
|
if (len == 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
res = g_new (gchar *, len + 1);
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
GstDeviceProvider *provider =
|
|
|
|
g_ptr_array_index (monitor->priv->providers, i);
|
|
|
|
GstDeviceProviderFactory *factory =
|
|
|
|
gst_device_provider_get_factory (provider);
|
|
|
|
|
|
|
|
res[i] = g_strdup (GST_OBJECT_NAME (factory));
|
|
|
|
}
|
|
|
|
res[i] = NULL;
|
|
|
|
|
|
|
|
done:
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2015-07-16 16:56:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_device_monitor_set_show_all_devices:
|
|
|
|
* @monitor: a #GstDeviceMonitor
|
|
|
|
* @show_all: show all devices
|
|
|
|
*
|
|
|
|
* Set if all devices should be visible, even those devices from hidden
|
|
|
|
* providers. Setting @show_all to true might show some devices multiple times.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_device_monitor_set_show_all_devices (GstDeviceMonitor * monitor,
|
|
|
|
gboolean show_all)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_DEVICE_MONITOR (monitor));
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
monitor->priv->show_all = show_all;
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_device_monitor_get_show_all_devices:
|
|
|
|
* @monitor: a #GstDeviceMonitor
|
|
|
|
*
|
|
|
|
* Get if @monitor is curretly showing all devices, even those from hidden
|
|
|
|
* providers.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE when all devices will be shown.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_device_monitor_get_show_all_devices (GstDeviceMonitor * monitor)
|
|
|
|
{
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_DEVICE_MONITOR (monitor), FALSE);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (monitor);
|
|
|
|
res = monitor->priv->show_all;
|
|
|
|
GST_OBJECT_UNLOCK (monitor);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|