Commit 604abee5 authored by Seungha Yang's avatar Seungha Yang

gst-device-monitor: Don't print duplicated device

Print probed device only once to avoid confusion
parent 45ad89d8
Pipeline #68380 passed with stages
in 77 minutes and 46 seconds
......@@ -37,6 +37,7 @@ typedef struct
{
GMainLoop *loop;
GstDeviceMonitor *monitor;
GList *device_cache;
guint bus_watch_id;
} DevMonApp;
......@@ -242,17 +243,29 @@ device_removed (GstDevice * device)
static gboolean
bus_msg_handler (GstBus * bus, GstMessage * msg, gpointer user_data)
{
DevMonApp *app = (DevMonApp *) user_data;
GstDevice *device;
GList *find = NULL;
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_DEVICE_ADDED:
gst_message_parse_device_added (msg, &device);
print_device (device, FALSE);
gst_object_unref (device);
if (!g_list_find (app->device_cache, device)) {
app->device_cache = g_list_append (app->device_cache, device);
print_device (device, FALSE);
} else {
gst_object_unref (device);
}
break;
case GST_MESSAGE_DEVICE_REMOVED:
gst_message_parse_device_removed (msg, &device);
device_removed (device);
find = g_list_find (app->device_cache, device);
if (find) {
gst_object_unref (GST_OBJECT_CAST (find->data));
app->device_cache = g_list_delete_link (app->device_cache, find);
}
gst_object_unref (device);
break;
case GST_MESSAGE_DEVICE_CHANGED:
......@@ -336,6 +349,7 @@ main (int argc, char **argv)
app.loop = g_main_loop_new (NULL, FALSE);
app.monitor = gst_device_monitor_new ();
app.device_cache = NULL;
bus = gst_device_monitor_get_bus (app.monitor);
app.bus_watch_id = gst_bus_add_watch (bus, bus_msg_handler, &app);
......@@ -378,7 +392,7 @@ main (int argc, char **argv)
GstDevice *device = devices->data;
print_device (device, FALSE);
gst_object_unref (device);
app.device_cache = g_list_append (app.device_cache, device);
devices = g_list_delete_link (devices, devices);
}
} else {
......@@ -397,6 +411,8 @@ main (int argc, char **argv)
gst_device_monitor_stop (app.monitor);
gst_object_unref (app.monitor);
if (app.device_cache)
g_list_free_full (app.device_cache, (GDestroyNotify) gst_object_unref);
g_source_remove (app.bus_watch_id);
g_main_loop_unref (app.loop);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment