Blame gst/gstdeviceprovider.c

Packit f546b1
/* GStreamer
Packit f546b1
 * Copyright (C) 2012 Olivier Crete <olivier.crete@collabora.com>
Packit f546b1
 *
Packit f546b1
 * gstdeviceprovider.c: Device probing and monitoring
Packit f546b1
 *
Packit f546b1
 * This library is free software; you can redistribute it and/or
Packit f546b1
 * modify it under the terms of the GNU Library General Public
Packit f546b1
 * License as published by the Free Software Foundation; either
Packit f546b1
 * version 2 of the License, or (at your option) any later version.
Packit f546b1
 *
Packit f546b1
 * This library is distributed in the hope that it will be useful,
Packit f546b1
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit f546b1
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit f546b1
 * Library General Public License for more details.
Packit f546b1
 *
Packit f546b1
 * You should have received a copy of the GNU Library General Public
Packit f546b1
 * License along with this library; if not, write to the
Packit f546b1
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit f546b1
 * Boston, MA 02111-1307, USA.
Packit f546b1
 */
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * SECTION:gstdeviceprovider
Packit f546b1
 * @title: GstDeviceProvider
Packit f546b1
 * @short_description: A device provider
Packit f546b1
 * @see_also: #GstDevice, #GstDeviceMonitor
Packit f546b1
 *
Packit f546b1
 * A #GstDeviceProvider subclass is provided by a plugin that handles devices
Packit f546b1
 * if there is a way to programatically list connected devices. It can also
Packit f546b1
 * optionally provide updates to the list of connected devices.
Packit f546b1
 *
Packit f546b1
 * Each #GstDeviceProvider subclass is a singleton, a plugin should
Packit f546b1
 * normally provide a single subclass for all devices.
Packit f546b1
 *
Packit f546b1
 * Applications would normally use a #GstDeviceMonitor to monitor devices
Packit f546b1
 * from all relevant providers.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
Packit f546b1
#ifdef HAVE_CONFIG_H
Packit f546b1
#include "config.h"
Packit f546b1
#endif
Packit f546b1
Packit f546b1
#include "gst_private.h"
Packit f546b1
Packit f546b1
#include "gstdeviceprovider.h"
Packit f546b1
Packit f546b1
#include "gstelementmetadata.h"
Packit f546b1
#include "gstquark.h"
Packit f546b1
Packit f546b1
struct _GstDeviceProviderPrivate
Packit f546b1
{
Packit f546b1
  GstBus *bus;
Packit f546b1
Packit f546b1
  GMutex start_lock;
Packit f546b1
Packit f546b1
  gboolean started_count;
Packit f546b1
Packit f546b1
  GList *hidden_providers;
Packit f546b1
};
Packit f546b1
Packit f546b1
enum
Packit f546b1
{
Packit f546b1
  PROVIDER_HIDDEN,
Packit f546b1
  PROVIDER_UNHIDDEN,
Packit f546b1
  LAST_SIGNAL
Packit f546b1
};
Packit f546b1
Packit f546b1
static guint gst_device_provider_signals[LAST_SIGNAL] = { 0 };
Packit f546b1
Packit f546b1
/* this is used in gstelementfactory.c:gst_element_register() */
Packit f546b1
GQuark __gst_deviceproviderclass_factory = 0;
Packit f546b1
Packit f546b1
static void gst_device_provider_class_init (GstDeviceProviderClass * klass);
Packit f546b1
static void gst_device_provider_init (GstDeviceProvider * element);
Packit f546b1
static void gst_device_provider_base_class_init (gpointer g_class);
Packit f546b1
static void gst_device_provider_dispose (GObject * object);
Packit f546b1
static void gst_device_provider_finalize (GObject * object);
Packit f546b1
Packit f546b1
static gpointer gst_device_provider_parent_class = NULL;
Packit f546b1
Packit f546b1
GType
Packit f546b1
gst_device_provider_get_type (void)
Packit f546b1
{
Packit f546b1
  static volatile gsize gst_device_provider_type = 0;
Packit f546b1
Packit f546b1
  if (g_once_init_enter (&gst_device_provider_type)) {
Packit f546b1
    GType _type;
Packit f546b1
    static const GTypeInfo element_info = {
Packit f546b1
      sizeof (GstDeviceProviderClass),
Packit f546b1
      gst_device_provider_base_class_init,
Packit f546b1
      NULL,                     /* base_class_finalize */
Packit f546b1
      (GClassInitFunc) gst_device_provider_class_init,
Packit f546b1
      NULL,
Packit f546b1
      NULL,
Packit f546b1
      sizeof (GstDeviceProvider),
Packit f546b1
      0,
Packit f546b1
      (GInstanceInitFunc) gst_device_provider_init,
Packit f546b1
      NULL
Packit f546b1
    };
Packit f546b1
Packit f546b1
    _type = g_type_register_static (GST_TYPE_OBJECT, "GstDeviceProvider",
Packit f546b1
        &element_info, G_TYPE_FLAG_ABSTRACT);
Packit f546b1
Packit f546b1
    __gst_deviceproviderclass_factory =
Packit f546b1
        g_quark_from_static_string ("GST_DEVICEPROVIDERCLASS_FACTORY");
Packit f546b1
    g_once_init_leave (&gst_device_provider_type, _type);
Packit f546b1
  }
Packit f546b1
  return gst_device_provider_type;
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_device_provider_base_class_init (gpointer g_class)
Packit f546b1
{
Packit f546b1
  GstDeviceProviderClass *klass = GST_DEVICE_PROVIDER_CLASS (g_class);
Packit f546b1
Packit f546b1
  /* Copy the element details here so elements can inherit the
Packit f546b1
   * details from their base class and classes only need to set
Packit f546b1
   * the details in class_init instead of base_init */
Packit f546b1
  klass->metadata =
Packit f546b1
      klass->metadata ? gst_structure_copy (klass->metadata) :
Packit f546b1
      gst_structure_new_empty ("metadata");
Packit f546b1
Packit f546b1
  klass->factory = g_type_get_qdata (G_TYPE_FROM_CLASS (klass),
Packit f546b1
      __gst_deviceproviderclass_factory);
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_device_provider_class_init (GstDeviceProviderClass * klass)
Packit f546b1
{
Packit f546b1
  GObjectClass *gobject_class = (GObjectClass *) klass;
Packit f546b1
Packit f546b1
  gst_device_provider_parent_class = g_type_class_peek_parent (klass);
Packit f546b1
Packit f546b1
  g_type_class_add_private (klass, sizeof (GstDeviceProviderPrivate));
Packit f546b1
Packit f546b1
  gobject_class->dispose = gst_device_provider_dispose;
Packit f546b1
  gobject_class->finalize = gst_device_provider_finalize;
Packit f546b1
Packit f546b1
  gst_device_provider_signals[PROVIDER_HIDDEN] =
Packit f546b1
      g_signal_new ("provider-hidden", G_TYPE_FROM_CLASS (klass),
Packit f546b1
      G_SIGNAL_RUN_FIRST, 0, NULL,
Packit f546b1
      NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_STRING);
Packit f546b1
Packit f546b1
  gst_device_provider_signals[PROVIDER_UNHIDDEN] =
Packit f546b1
      g_signal_new ("provider-unhidden", G_TYPE_FROM_CLASS (klass),
Packit f546b1
      G_SIGNAL_RUN_FIRST, 0, NULL,
Packit f546b1
      NULL, g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_STRING);
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_device_provider_init (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  provider->priv = G_TYPE_INSTANCE_GET_PRIVATE (provider,
Packit f546b1
      GST_TYPE_DEVICE_PROVIDER, GstDeviceProviderPrivate);
Packit f546b1
Packit f546b1
  g_mutex_init (&provider->priv->start_lock);
Packit f546b1
Packit f546b1
  provider->priv->bus = gst_bus_new ();
Packit f546b1
  gst_bus_set_flushing (provider->priv->bus, TRUE);
Packit f546b1
}
Packit f546b1
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_device_provider_dispose (GObject * object)
Packit f546b1
{
Packit f546b1
  GstDeviceProvider *provider = GST_DEVICE_PROVIDER (object);
Packit f546b1
Packit f546b1
  gst_object_replace ((GstObject **) & provider->priv->bus, NULL);
Packit f546b1
Packit f546b1
  GST_OBJECT_LOCK (provider);
Packit f546b1
  g_list_free_full (provider->devices, (GDestroyNotify) gst_object_unparent);
Packit f546b1
  provider->devices = NULL;
Packit f546b1
  GST_OBJECT_UNLOCK (provider);
Packit f546b1
Packit f546b1
  G_OBJECT_CLASS (gst_device_provider_parent_class)->dispose (object);
Packit f546b1
}
Packit f546b1
Packit f546b1
static void
Packit f546b1
gst_device_provider_finalize (GObject * object)
Packit f546b1
{
Packit f546b1
  GstDeviceProvider *provider = GST_DEVICE_PROVIDER (object);
Packit f546b1
Packit f546b1
  g_mutex_clear (&provider->priv->start_lock);
Packit f546b1
Packit f546b1
  G_OBJECT_CLASS (gst_device_provider_parent_class)->finalize (object);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_class_add_metadata:
Packit f546b1
 * @klass: class to set metadata for
Packit f546b1
 * @key: the key to set
Packit f546b1
 * @value: the value to set
Packit f546b1
 *
Packit f546b1
 * Set @key with @value as metadata in @klass.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_class_add_metadata (GstDeviceProviderClass * klass,
Packit f546b1
    const gchar * key, const gchar * value)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER_CLASS (klass));
Packit f546b1
  g_return_if_fail (key != NULL);
Packit f546b1
  g_return_if_fail (value != NULL);
Packit f546b1
Packit f546b1
  gst_structure_set ((GstStructure *) klass->metadata,
Packit f546b1
      key, G_TYPE_STRING, value, NULL);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_class_add_static_metadata:
Packit f546b1
 * @klass: class to set metadata for
Packit f546b1
 * @key: the key to set
Packit f546b1
 * @value: (transfer full): the value to set
Packit f546b1
 *
Packit f546b1
 * Set @key with @value as metadata in @klass.
Packit f546b1
 *
Packit f546b1
 * Same as gst_device_provider_class_add_metadata(), but @value must be a static string
Packit f546b1
 * or an inlined string, as it will not be copied. (GStreamer plugins will
Packit f546b1
 * be made resident once loaded, so this function can be used even from
Packit f546b1
 * dynamically loaded plugins.)
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_class_add_static_metadata (GstDeviceProviderClass * klass,
Packit f546b1
    const gchar * key, const gchar * value)
Packit f546b1
{
Packit f546b1
  GValue val = G_VALUE_INIT;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER_CLASS (klass));
Packit f546b1
  g_return_if_fail (key != NULL);
Packit f546b1
  g_return_if_fail (value != NULL);
Packit f546b1
Packit f546b1
  g_value_init (&val, G_TYPE_STRING);
Packit f546b1
  g_value_set_static_string (&val, value);
Packit f546b1
  gst_structure_take_value ((GstStructure *) klass->metadata, key, &val;;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_class_set_metadata:
Packit f546b1
 * @klass: class to set metadata for
Packit f546b1
 * @longname: The long English name of the device provider. E.g. "File Sink"
Packit f546b1
 * @classification: String describing the type of device provider, as an
Packit f546b1
 *  unordered list separated with slashes ('/'). See draft-klass.txt of the
Packit f546b1
 *  design docs
Packit f546b1
 * for more details and common types. E.g: "Sink/File"
Packit f546b1
 * @description: Sentence describing the purpose of the device provider.
Packit f546b1
 * E.g: "Write stream to a file"
Packit f546b1
 * @author: Name and contact details of the author(s). Use \n to separate
Packit f546b1
 * multiple author metadata. E.g: "Joe Bloggs <joe.blogs at foo.com>"
Packit f546b1
 *
Packit f546b1
 * Sets the detailed information for a #GstDeviceProviderClass.
Packit f546b1
 *
Packit f546b1
 * > This function is for use in _class_init functions only.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_class_set_metadata (GstDeviceProviderClass * klass,
Packit f546b1
    const gchar * longname, const gchar * classification,
Packit f546b1
    const gchar * description, const gchar * author)
Packit f546b1
{
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER_CLASS (klass));
Packit f546b1
  g_return_if_fail (longname != NULL && *longname != '\0');
Packit f546b1
  g_return_if_fail (classification != NULL && *classification != '\0');
Packit f546b1
  g_return_if_fail (description != NULL && *description != '\0');
Packit f546b1
  g_return_if_fail (author != NULL && *author != '\0');
Packit f546b1
Packit f546b1
  gst_structure_id_set ((GstStructure *) klass->metadata,
Packit f546b1
      GST_QUARK (ELEMENT_METADATA_LONGNAME), G_TYPE_STRING, longname,
Packit f546b1
      GST_QUARK (ELEMENT_METADATA_KLASS), G_TYPE_STRING, classification,
Packit f546b1
      GST_QUARK (ELEMENT_METADATA_DESCRIPTION), G_TYPE_STRING, description,
Packit f546b1
      GST_QUARK (ELEMENT_METADATA_AUTHOR), G_TYPE_STRING, author, NULL);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_class_set_static_metadata:
Packit f546b1
 * @klass: class to set metadata for
Packit f546b1
 * @longname: (transfer full): The long English name of the element. E.g. "File Sink"
Packit f546b1
 * @classification: (transfer full): String describing the type of element, as
Packit f546b1
 * an unordered list separated with slashes ('/'). See draft-klass.txt of the
Packit f546b1
 * design docs for more details and common types. E.g: "Sink/File"
Packit f546b1
 * @description: (transfer full): Sentence describing the purpose of the
Packit f546b1
 * element.  E.g: "Write stream to a file"
Packit f546b1
 * @author: (transfer full): Name and contact details of the author(s). Use \n
Packit f546b1
 * to separate multiple author metadata. E.g: "Joe Bloggs <joe.blogs at
Packit f546b1
 * foo.com>"
Packit f546b1
 *
Packit f546b1
 * Sets the detailed information for a #GstDeviceProviderClass.
Packit f546b1
 *
Packit f546b1
 * > This function is for use in _class_init functions only.
Packit f546b1
 *
Packit f546b1
 * Same as gst_device_provider_class_set_metadata(), but @longname, @classification,
Packit f546b1
 * @description, and @author must be static strings or inlined strings, as
Packit f546b1
 * they will not be copied. (GStreamer plugins will be made resident once
Packit f546b1
 * loaded, so this function can be used even from dynamically loaded plugins.)
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_class_set_static_metadata (GstDeviceProviderClass * klass,
Packit f546b1
    const gchar * longname, const gchar * classification,
Packit f546b1
    const gchar * description, const gchar * author)
Packit f546b1
{
Packit f546b1
  GstStructure *s = (GstStructure *) klass->metadata;
Packit f546b1
  GValue val = G_VALUE_INIT;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER_CLASS (klass));
Packit f546b1
  g_return_if_fail (longname != NULL && *longname != '\0');
Packit f546b1
  g_return_if_fail (classification != NULL && *classification != '\0');
Packit f546b1
  g_return_if_fail (description != NULL && *description != '\0');
Packit f546b1
  g_return_if_fail (author != NULL && *author != '\0');
Packit f546b1
Packit f546b1
  g_value_init (&val, G_TYPE_STRING);
Packit f546b1
Packit f546b1
  g_value_set_static_string (&val, longname);
Packit f546b1
  gst_structure_id_set_value (s, GST_QUARK (ELEMENT_METADATA_LONGNAME), &val;;
Packit f546b1
Packit f546b1
  g_value_set_static_string (&val, classification);
Packit f546b1
  gst_structure_id_set_value (s, GST_QUARK (ELEMENT_METADATA_KLASS), &val;;
Packit f546b1
Packit f546b1
  g_value_set_static_string (&val, description);
Packit f546b1
  gst_structure_id_set_value (s, GST_QUARK (ELEMENT_METADATA_DESCRIPTION),
Packit f546b1
      &val;;
Packit f546b1
Packit f546b1
  g_value_set_static_string (&val, author);
Packit f546b1
  gst_structure_id_take_value (s, GST_QUARK (ELEMENT_METADATA_AUTHOR), &val;;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_class_get_metadata:
Packit f546b1
 * @klass: class to get metadata for
Packit f546b1
 * @key: the key to get
Packit f546b1
 *
Packit f546b1
 * Get metadata with @key in @klass.
Packit f546b1
 *
Packit f546b1
 * Returns: (nullable): the metadata for @key.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
const gchar *
Packit f546b1
gst_device_provider_class_get_metadata (GstDeviceProviderClass * klass,
Packit f546b1
    const gchar * key)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER_CLASS (klass), NULL);
Packit f546b1
  g_return_val_if_fail (key != NULL, NULL);
Packit f546b1
Packit f546b1
  return gst_structure_get_string ((GstStructure *) klass->metadata, key);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_get_metadata:
Packit f546b1
 * @provider: provider to get metadata for
Packit f546b1
 * @key: the key to get
Packit f546b1
 *
Packit f546b1
 * Get metadata with @key in @provider.
Packit f546b1
 *
Packit f546b1
 * Returns: the metadata for @key.
Packit f546b1
 *
Packit f546b1
 * Since: 1.14
Packit f546b1
 */
Packit f546b1
const gchar *
Packit f546b1
gst_device_provider_get_metadata (GstDeviceProvider * provider,
Packit f546b1
    const gchar * key)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), NULL);
Packit f546b1
  g_return_val_if_fail (key != NULL, NULL);
Packit f546b1
Packit f546b1
  return
Packit f546b1
      gst_device_provider_class_get_metadata (GST_DEVICE_PROVIDER_GET_CLASS
Packit f546b1
      (provider), key);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_get_devices:
Packit f546b1
 * @provider: A #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * Gets a list of devices that this provider understands. This may actually
Packit f546b1
 * probe the hardware if the provider is not currently started.
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full) (element-type GstDevice): a #GList of
Packit f546b1
 *   #GstDevice
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
Packit f546b1
GList *
Packit f546b1
gst_device_provider_get_devices (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  GstDeviceProviderClass *klass;
Packit f546b1
  GList *devices = NULL;
Packit f546b1
  gboolean started;
Packit f546b1
  GList *item;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), NULL);
Packit f546b1
  klass = GST_DEVICE_PROVIDER_GET_CLASS (provider);
Packit f546b1
Packit f546b1
  g_mutex_lock (&provider->priv->start_lock);
Packit f546b1
  started = (provider->priv->started_count > 0);
Packit f546b1
Packit f546b1
  if (started) {
Packit f546b1
    GST_OBJECT_LOCK (provider);
Packit f546b1
    for (item = provider->devices; item; item = item->next)
Packit f546b1
      devices = g_list_prepend (devices, gst_object_ref (item->data));
Packit f546b1
    GST_OBJECT_UNLOCK (provider);
Packit f546b1
  } else if (klass->probe)
Packit f546b1
    devices = klass->probe (provider);
Packit f546b1
Packit f546b1
  g_mutex_unlock (&provider->priv->start_lock);
Packit f546b1
Packit f546b1
  return devices;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_start:
Packit f546b1
 * @provider: A #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * Starts providering the devices. This will cause #GST_MESSAGE_DEVICE_ADDED
Packit f546b1
 * and #GST_MESSAGE_DEVICE_REMOVED messages to be posted on the provider's bus
Packit f546b1
 * when devices are added or removed from the system.
Packit f546b1
 *
Packit f546b1
 * Since the #GstDeviceProvider is a singleton,
Packit f546b1
 * gst_device_provider_start() may already have been called by another
Packit f546b1
 * user of the object, gst_device_provider_stop() needs to be called the same
Packit f546b1
 * number of times.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the device providering could be started
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
Packit f546b1
gboolean
Packit f546b1
gst_device_provider_start (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  GstDeviceProviderClass *klass;
Packit f546b1
  gboolean ret = FALSE;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), FALSE);
Packit f546b1
  klass = GST_DEVICE_PROVIDER_GET_CLASS (provider);
Packit f546b1
Packit f546b1
  g_mutex_lock (&provider->priv->start_lock);
Packit f546b1
Packit f546b1
  if (provider->priv->started_count > 0) {
Packit f546b1
    ret = TRUE;
Packit f546b1
    goto started;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  if (klass->start)
Packit f546b1
    ret = klass->start (provider);
Packit f546b1
Packit f546b1
  if (ret) {
Packit f546b1
    provider->priv->started_count++;
Packit f546b1
    gst_bus_set_flushing (provider->priv->bus, FALSE);
Packit f546b1
  }
Packit f546b1
Packit f546b1
started:
Packit f546b1
Packit f546b1
  g_mutex_unlock (&provider->priv->start_lock);
Packit f546b1
Packit f546b1
  return ret;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_stop:
Packit f546b1
 * @provider: A #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * Decreases the use-count by one. If the use count reaches zero, this
Packit f546b1
 * #GstDeviceProvider will stop providering the devices. This needs to be
Packit f546b1
 * called the same number of times that gst_device_provider_start() was called.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
Packit f546b1
void
Packit f546b1
gst_device_provider_stop (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  GstDeviceProviderClass *klass;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER (provider));
Packit f546b1
  klass = GST_DEVICE_PROVIDER_GET_CLASS (provider);
Packit f546b1
Packit f546b1
  g_mutex_lock (&provider->priv->start_lock);
Packit f546b1
Packit f546b1
  if (provider->priv->started_count == 1) {
Packit f546b1
    gst_bus_set_flushing (provider->priv->bus, TRUE);
Packit f546b1
    if (klass->stop)
Packit f546b1
      klass->stop (provider);
Packit f546b1
    GST_OBJECT_LOCK (provider);
Packit f546b1
    g_list_free_full (provider->devices, (GDestroyNotify) gst_object_unparent);
Packit f546b1
    provider->devices = NULL;
Packit f546b1
    GST_OBJECT_UNLOCK (provider);
Packit f546b1
  } else if (provider->priv->started_count < 1) {
Packit f546b1
    g_critical
Packit f546b1
        ("Trying to stop a GstDeviceProvider %s which is already stopped",
Packit f546b1
        GST_OBJECT_NAME (provider));
Packit f546b1
  }
Packit f546b1
Packit f546b1
  provider->priv->started_count--;
Packit f546b1
  g_mutex_unlock (&provider->priv->start_lock);
Packit f546b1
}
Packit f546b1
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_get_factory:
Packit f546b1
 * @provider: a #GstDeviceProvider to request the device provider factory of.
Packit f546b1
 *
Packit f546b1
 * Retrieves the factory that was used to create this device provider.
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer none): the #GstDeviceProviderFactory used for
Packit f546b1
 *     creating this device provider. no refcounting is needed.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
GstDeviceProviderFactory *
Packit f546b1
gst_device_provider_get_factory (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), NULL);
Packit f546b1
Packit f546b1
  return GST_DEVICE_PROVIDER_GET_CLASS (provider)->factory;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_can_provider:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * If this function returns %TRUE, then the device provider can provider if
Packit f546b1
 * devices are added or removed. Otherwise, it can only do static probing.
Packit f546b1
 *
Packit f546b1
 * Returns: %TRUE if the #GstDeviceProvider support providering, %FALSE otherwise
Packit f546b1
 */
Packit f546b1
gboolean
Packit f546b1
gst_device_provider_can_monitor (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  GstDeviceProviderClass *klass;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), FALSE);
Packit f546b1
  klass = GST_DEVICE_PROVIDER_GET_CLASS (provider);
Packit f546b1
Packit f546b1
  if (klass->start)
Packit f546b1
    return TRUE;
Packit f546b1
  else
Packit f546b1
    return FALSE;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_get_bus:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * Gets the #GstBus of this #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full): a #GstBus
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
GstBus *
Packit f546b1
gst_device_provider_get_bus (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), NULL);
Packit f546b1
Packit f546b1
  return gst_object_ref (provider->priv->bus);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_device_add:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 * @device: (transfer floating): a #GstDevice that has been added
Packit f546b1
 *
Packit f546b1
 * Posts a message on the provider's #GstBus to inform applications that
Packit f546b1
 * a new device has been added.
Packit f546b1
 *
Packit f546b1
 * This is for use by subclasses.
Packit f546b1
 *
Packit f546b1
 * @device's reference count will be incremented, and any floating reference
Packit f546b1
 * will be removed (see gst_object_ref_sink()).
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_device_add (GstDeviceProvider * provider,
Packit f546b1
    GstDevice * device)
Packit f546b1
{
Packit f546b1
  GstMessage *message;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER (provider));
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE (device));
Packit f546b1
Packit f546b1
  if (!gst_object_set_parent (GST_OBJECT (device), GST_OBJECT (provider))) {
Packit f546b1
    GST_WARNING_OBJECT (provider, "Could not parent device %p to provider,"
Packit f546b1
        " it already has a parent", device);
Packit f546b1
    return;
Packit f546b1
  }
Packit f546b1
Packit f546b1
  GST_OBJECT_LOCK (provider);
Packit f546b1
  /* Take an additional reference so we can be sure nobody removed it from the
Packit f546b1
   * provider in the meantime and we can safely emit the message */
Packit f546b1
  gst_object_ref (device);
Packit f546b1
  provider->devices = g_list_prepend (provider->devices, device);
Packit f546b1
  GST_OBJECT_UNLOCK (provider);
Packit f546b1
Packit f546b1
  message = gst_message_new_device_added (GST_OBJECT (provider), device);
Packit f546b1
  gst_bus_post (provider->priv->bus, message);
Packit f546b1
  gst_object_unref (device);
Packit f546b1
}
Packit f546b1
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_device_remove:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 * @device: a #GstDevice that has been removed
Packit f546b1
 *
Packit f546b1
 * Posts a message on the provider's #GstBus to inform applications that
Packit f546b1
 * a device has been removed.
Packit f546b1
 *
Packit f546b1
 * This is for use by subclasses.
Packit f546b1
 *
Packit f546b1
 * Since: 1.4
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_device_remove (GstDeviceProvider * provider,
Packit f546b1
    GstDevice * device)
Packit f546b1
{
Packit f546b1
  GstMessage *message;
Packit f546b1
  GList *item;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER (provider));
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE (device));
Packit f546b1
Packit f546b1
  GST_OBJECT_LOCK (provider);
Packit f546b1
  item = g_list_find (provider->devices, device);
Packit f546b1
  if (item) {
Packit f546b1
    provider->devices = g_list_delete_link (provider->devices, item);
Packit f546b1
  }
Packit f546b1
  GST_OBJECT_UNLOCK (provider);
Packit f546b1
Packit f546b1
  message = gst_message_new_device_removed (GST_OBJECT (provider), device);
Packit f546b1
  g_signal_emit_by_name (device, "removed");
Packit f546b1
  gst_bus_post (provider->priv->bus, message);
Packit f546b1
  if (item)
Packit f546b1
    gst_object_unparent (GST_OBJECT (device));
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_get_hidden_providers:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 *
Packit f546b1
 * Get the provider factory names of the #GstDeviceProvider instances that
Packit f546b1
 * are hidden by @provider.
Packit f546b1
 *
Packit f546b1
 * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*):
Packit f546b1
 *   a list of hidden providers factory names or %NULL when
Packit f546b1
 *   nothing is hidden by @provider. Free with g_strfreev.
Packit f546b1
 *
Packit f546b1
 * Since: 1.6
Packit f546b1
 */
Packit f546b1
gchar **
Packit f546b1
gst_device_provider_get_hidden_providers (GstDeviceProvider * provider)
Packit f546b1
{
Packit f546b1
  GList *walk;
Packit f546b1
  guint i, len;
Packit f546b1
  gchar **res = NULL;
Packit f546b1
Packit f546b1
  g_return_val_if_fail (GST_IS_DEVICE_PROVIDER (provider), NULL);
Packit f546b1
Packit f546b1
  GST_OBJECT_LOCK (provider);
Packit f546b1
  len = g_list_length (provider->priv->hidden_providers);
Packit f546b1
  if (len == 0)
Packit f546b1
    goto done;
Packit f546b1
Packit f546b1
  res = g_new (gchar *, len + 1);
Packit f546b1
  for (i = 0, walk = provider->priv->hidden_providers; walk;
Packit f546b1
      walk = g_list_next (walk), i++)
Packit f546b1
    res[i] = g_strdup (walk->data);
Packit f546b1
  res[i] = NULL;
Packit f546b1
Packit f546b1
done:
Packit f546b1
  GST_OBJECT_UNLOCK (provider);
Packit f546b1
Packit f546b1
  return res;
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_hide_provider:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 * @name: a provider factory name
Packit f546b1
 *
Packit f546b1
 * Make @provider hide the devices from the factory with @name.
Packit f546b1
 *
Packit f546b1
 * This function is used when @provider will also provide the devices reported
Packit f546b1
 * by provider factory @name. A monitor should stop monitoring the
Packit f546b1
 * device provider with @name to avoid duplicate devices.
Packit f546b1
 *
Packit f546b1
 * Since: 1.6
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_hide_provider (GstDeviceProvider * provider,
Packit f546b1
    const gchar * name)
Packit f546b1
{
Packit f546b1
  GList *find;
Packit f546b1
  const gchar *hidden_name = NULL;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER (provider));
Packit f546b1
  g_return_if_fail (name != NULL);
Packit f546b1
Packit f546b1
  GST_OBJECT_LOCK (provider);
Packit f546b1
  find =
Packit f546b1
      g_list_find_custom (provider->priv->hidden_providers, name,
Packit f546b1
      (GCompareFunc) g_strcmp0);
Packit f546b1
  if (find == NULL) {
Packit f546b1
    hidden_name = name;
Packit f546b1
    provider->priv->hidden_providers =
Packit f546b1
        g_list_prepend (provider->priv->hidden_providers, g_strdup (name));
Packit f546b1
  }
Packit f546b1
  GST_OBJECT_UNLOCK (provider);
Packit f546b1
Packit f546b1
  if (hidden_name)
Packit f546b1
    g_signal_emit (provider, gst_device_provider_signals[PROVIDER_HIDDEN],
Packit f546b1
        0, hidden_name);
Packit f546b1
}
Packit f546b1
Packit f546b1
/**
Packit f546b1
 * gst_device_provider_unhide_provider:
Packit f546b1
 * @provider: a #GstDeviceProvider
Packit f546b1
 * @name: a provider factory name
Packit f546b1
 *
Packit f546b1
 * Make @provider unhide the devices from factory @name.
Packit f546b1
 *
Packit f546b1
 * This function is used when @provider will no longer provide the devices
Packit f546b1
 * reported by provider factory @name. A monitor should start
Packit f546b1
 * monitoring the devices from provider factory @name in order to see
Packit f546b1
 * all devices again.
Packit f546b1
 *
Packit f546b1
 * Since: 1.6
Packit f546b1
 */
Packit f546b1
void
Packit f546b1
gst_device_provider_unhide_provider (GstDeviceProvider * provider,
Packit f546b1
    const gchar * name)
Packit f546b1
{
Packit f546b1
  GList *find;
Packit f546b1
  gchar *unhidden_name = NULL;
Packit f546b1
Packit f546b1
  g_return_if_fail (GST_IS_DEVICE_PROVIDER (provider));
Packit f546b1
  g_return_if_fail (name != NULL);
Packit f546b1
Packit f546b1
  GST_OBJECT_LOCK (provider);
Packit f546b1
  find =
Packit f546b1
      g_list_find_custom (provider->priv->hidden_providers, name,
Packit f546b1
      (GCompareFunc) g_strcmp0);
Packit f546b1
  if (find) {
Packit f546b1
    unhidden_name = find->data;
Packit f546b1
    provider->priv->hidden_providers =
Packit f546b1
        g_list_delete_link (provider->priv->hidden_providers, find);
Packit f546b1
  }
Packit f546b1
  GST_OBJECT_UNLOCK (provider);
Packit f546b1
Packit f546b1
  if (unhidden_name) {
Packit f546b1
    g_signal_emit (provider,
Packit f546b1
        gst_device_provider_signals[PROVIDER_UNHIDDEN], 0, unhidden_name);
Packit f546b1
    g_free (unhidden_name);
Packit f546b1
  }
Packit f546b1
}