mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 19:55:32 +00:00
deviceprovider: Do static probe on start as fallback
For providers that don't support dynamic probing, just fall back to doing a static one on start() to make the UI developers life easier. This also means that the monitor doesn't need to call _can_monitor() before calling start. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/353>
This commit is contained in:
parent
3cfda6d6eb
commit
44ef5a7c8c
3 changed files with 60 additions and 45 deletions
|
@ -510,14 +510,13 @@ again:
|
|||
while (pending) {
|
||||
GstDeviceProvider *provider = pending->data;
|
||||
|
||||
if (gst_device_provider_can_monitor (provider)) {
|
||||
GST_OBJECT_UNLOCK (monitor);
|
||||
GST_OBJECT_UNLOCK (monitor);
|
||||
|
||||
if (!gst_device_provider_start (provider))
|
||||
goto start_failed;
|
||||
if (!gst_device_provider_start (provider))
|
||||
goto start_failed;
|
||||
|
||||
GST_OBJECT_LOCK (monitor);
|
||||
|
||||
GST_OBJECT_LOCK (monitor);
|
||||
}
|
||||
started = g_list_prepend (started, provider);
|
||||
pending = g_list_delete_link (pending, pending);
|
||||
|
||||
|
@ -579,8 +578,7 @@ gst_device_monitor_stop (GstDeviceMonitor * monitor)
|
|||
while (started) {
|
||||
GstDeviceProvider *provider = started->data;
|
||||
|
||||
if (gst_device_provider_can_monitor (provider))
|
||||
gst_device_provider_stop (provider);
|
||||
gst_device_provider_stop (provider);
|
||||
|
||||
started = g_list_delete_link (started, started);
|
||||
gst_object_unref (provider);
|
||||
|
|
|
@ -389,6 +389,9 @@ gst_device_provider_get_metadata (GstDeviceProvider * provider,
|
|||
* Gets a list of devices that this provider understands. This may actually
|
||||
* probe the hardware if the provider is not currently started.
|
||||
*
|
||||
* If the provider has been started, this will returned the same #GstDevice
|
||||
* objedcts that have been returned by the #GST_MESSAGE_DEVICE_ADDED messages.
|
||||
*
|
||||
* Returns: (transfer full) (element-type GstDevice): a #GList of
|
||||
* #GstDevice
|
||||
*
|
||||
|
@ -435,6 +438,10 @@ gst_device_provider_get_devices (GstDeviceProvider * provider)
|
|||
* user of the object, gst_device_provider_stop() needs to be called the same
|
||||
* number of times.
|
||||
*
|
||||
* After this function has been called, gst_device_provider_get_devices() will
|
||||
* return the same objects that have been received from the
|
||||
* #GST_MESSAGE_DEVICE_ADDED messages and will no longer probe.
|
||||
*
|
||||
* Returns: %TRUE if the device providering could be started
|
||||
*
|
||||
* Since: 1.4
|
||||
|
@ -459,8 +466,27 @@ gst_device_provider_start (GstDeviceProvider * provider)
|
|||
|
||||
gst_bus_set_flushing (provider->priv->bus, FALSE);
|
||||
|
||||
if (klass->start)
|
||||
if (klass->start) {
|
||||
ret = klass->start (provider);
|
||||
} else {
|
||||
GList *devices = NULL, *item;
|
||||
|
||||
devices = klass->probe (provider);
|
||||
|
||||
for (item = devices; item; item = item->next) {
|
||||
GstDevice *device = GST_DEVICE (item->data);
|
||||
gboolean was_floating = g_object_is_floating (item->data);
|
||||
|
||||
gst_device_provider_device_add (provider, device);
|
||||
|
||||
if (!was_floating)
|
||||
g_object_unref (item->data);
|
||||
}
|
||||
|
||||
g_list_free (devices);
|
||||
|
||||
ret = TRUE;
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
provider->priv->started_count++;
|
||||
|
@ -514,7 +540,6 @@ gst_device_provider_stop (GstDeviceProvider * provider)
|
|||
g_mutex_unlock (&provider->priv->start_lock);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* gst_device_provider_get_factory:
|
||||
* @provider: a #GstDeviceProvider to request the device provider factory of.
|
||||
|
|
|
@ -38,11 +38,10 @@ typedef struct _GstTestDeviceClass
|
|||
|
||||
GType gst_test_device_get_type (void);
|
||||
|
||||
G_DEFINE_TYPE (GstTestDevice, gst_test_device, GST_TYPE_DEVICE);
|
||||
|
||||
G_DEFINE_TYPE (GstTestDevice, gst_test_device, GST_TYPE_DEVICE)
|
||||
|
||||
static GstElement *gst_test_device_create_element (GstDevice * device,
|
||||
const gchar * name)
|
||||
static GstElement *
|
||||
gst_test_device_create_element (GstDevice * device, const gchar * name)
|
||||
{
|
||||
return gst_bin_new (name);
|
||||
}
|
||||
|
@ -140,19 +139,19 @@ typedef struct _GstTestDeviceProviderClass
|
|||
|
||||
GType gst_test_device_provider_get_type (void);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GstTestDeviceProvider, gst_test_device_provider,
|
||||
GST_TYPE_DEVICE_PROVIDER)
|
||||
GST_TYPE_DEVICE_PROVIDER);
|
||||
|
||||
int num_devices = 1;
|
||||
|
||||
static GList *devices = NULL;
|
||||
|
||||
static GList *gst_test_device_provider_probe (GstDeviceProvider * provider)
|
||||
static GList *
|
||||
gst_test_device_provider_probe (GstDeviceProvider * provider)
|
||||
{
|
||||
GList *devs;
|
||||
int i;
|
||||
GList *devs = NULL;
|
||||
|
||||
devs = g_list_copy (devices);
|
||||
g_list_foreach (devs, (GFunc) gst_object_ref, NULL);
|
||||
for (i = 0; i < num_devices; i++)
|
||||
devs = g_list_prepend (devs, test_device_new ());
|
||||
|
||||
return devs;
|
||||
}
|
||||
|
@ -233,24 +232,26 @@ GST_START_TEST (test_device_provider)
|
|||
register_test_device_provider ();
|
||||
|
||||
dp = gst_device_provider_factory_get_by_name ("testdeviceprovider");
|
||||
num_devices = 0;
|
||||
fail_unless (dp != NULL);
|
||||
fail_unless (gst_device_provider_get_devices (dp) == NULL);
|
||||
|
||||
devices = g_list_append (NULL, test_device_new ());
|
||||
num_devices = 1;
|
||||
|
||||
devs = gst_device_provider_get_devices (dp);
|
||||
fail_unless (g_list_length (devs) == 1);
|
||||
fail_unless_equals_pointer (devs->data, devices->data);
|
||||
fail_unless (GST_IS_DEVICE (devs->data));
|
||||
g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
fail_if (gst_device_provider_can_monitor (dp));
|
||||
fail_if (gst_device_provider_start (dp));
|
||||
fail_unless (gst_device_provider_start (dp));
|
||||
|
||||
bus = gst_device_provider_get_bus (dp);
|
||||
fail_unless (GST_IS_BUS (bus));
|
||||
gst_object_unref (bus);
|
||||
|
||||
g_list_free_full (devices, (GDestroyNotify) gst_object_unref);
|
||||
gst_device_provider_stop (dp);
|
||||
|
||||
gst_object_unref (dp);
|
||||
}
|
||||
|
||||
|
@ -269,13 +270,11 @@ typedef struct _GstTestDeviceProviderMonitorClass
|
|||
|
||||
GType gst_test_device_provider_monitor_get_type (void);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (GstTestDeviceProviderMonitor, gst_test_device_provider_monitor,
|
||||
GST_TYPE_DEVICE_PROVIDER)
|
||||
GST_TYPE_DEVICE_PROVIDER);
|
||||
|
||||
|
||||
static gboolean
|
||||
gst_test_device_provider_monitor_start (GstDeviceProvider * monitor)
|
||||
static gboolean
|
||||
gst_test_device_provider_monitor_start (GstDeviceProvider * monitor)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -320,8 +319,6 @@ GST_START_TEST (test_device_provider_monitor)
|
|||
|
||||
register_test_device_provider_monitor ();
|
||||
|
||||
devices = g_list_append (NULL, test_device_new ());
|
||||
|
||||
dp = gst_device_provider_factory_get_by_name ("testdeviceprovidermonitor");
|
||||
|
||||
bus = gst_device_provider_get_bus (dp);
|
||||
|
@ -394,8 +391,6 @@ GST_START_TEST (test_device_provider_monitor)
|
|||
|
||||
/* Is singleton, so system keeps a ref */
|
||||
ASSERT_OBJECT_REFCOUNT (dp, "monitor", 1);
|
||||
|
||||
g_list_free_full (devices, (GDestroyNotify) gst_object_unref);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
@ -420,8 +415,6 @@ GST_START_TEST (test_device_monitor)
|
|||
|
||||
mon = gst_device_monitor_new ();
|
||||
|
||||
devices = g_list_append (NULL, test_device_new ());
|
||||
|
||||
devs = gst_device_monitor_get_devices (mon);
|
||||
fail_unless (devs == NULL);
|
||||
|
||||
|
@ -440,23 +433,23 @@ GST_START_TEST (test_device_monitor)
|
|||
fail_unless (id > 0);
|
||||
devs = gst_device_monitor_get_devices (mon);
|
||||
fail_unless (g_list_length (devs) == 1);
|
||||
fail_unless_equals_pointer (devs->data, devices->data);
|
||||
fail_unless (GST_IS_DEVICE (devs->data));
|
||||
g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
id2 = gst_device_monitor_add_filter (mon, "Test1", NULL);
|
||||
fail_unless (id2 > 0);
|
||||
devs = gst_device_monitor_get_devices (mon);
|
||||
fail_unless (g_list_length (devs) == 2);
|
||||
fail_unless_equals_pointer (devs->data, devices->data);
|
||||
fail_unless_equals_pointer (devs->next->data, devices->data);
|
||||
fail_unless (GST_IS_DEVICE (devs->data));
|
||||
fail_unless (GST_IS_DEVICE (devs->next->data));
|
||||
g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
fail_unless (gst_device_monitor_remove_filter (mon, id));
|
||||
|
||||
devs = gst_device_monitor_get_devices (mon);
|
||||
fail_unless (g_list_length (devs) == 2);
|
||||
fail_unless_equals_pointer (devs->data, devices->data);
|
||||
fail_unless_equals_pointer (devs->next->data, devices->data);
|
||||
fail_unless (GST_IS_DEVICE (devs->data));
|
||||
fail_unless (GST_IS_DEVICE (devs->next->data));
|
||||
g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
|
||||
|
@ -464,7 +457,7 @@ GST_START_TEST (test_device_monitor)
|
|||
|
||||
devs = gst_device_monitor_get_devices (mon);
|
||||
fail_unless (g_list_length (devs) == 1);
|
||||
fail_unless_equals_pointer (devs->data, devices->data);
|
||||
fail_unless (GST_IS_DEVICE (devs->data));
|
||||
g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
gst_device_monitor_stop (mon);
|
||||
|
@ -476,7 +469,7 @@ GST_START_TEST (test_device_monitor)
|
|||
|
||||
devs = gst_device_monitor_get_devices (mon);
|
||||
fail_unless (g_list_length (devs) == 1);
|
||||
fail_unless_equals_pointer (devs->data, devices->data);
|
||||
fail_unless (GST_IS_DEVICE (devs->data));
|
||||
g_list_free_full (devs, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
fail_unless (gst_device_monitor_start (mon));
|
||||
|
@ -530,7 +523,6 @@ GST_START_TEST (test_device_monitor)
|
|||
|
||||
gst_object_unref (dp);
|
||||
gst_object_unref (dp2);
|
||||
g_list_free_full (devices, (GDestroyNotify) gst_object_unref);
|
||||
|
||||
/* should work fine without any filters */
|
||||
mon = gst_device_monitor_new ();
|
||||
|
|
Loading…
Reference in a new issue