Skip to content

Commit

Permalink
device-monitor: fix device listing without --follow
Browse files Browse the repository at this point in the history
In !427, I removed the call to get_devices in order to always
print added devices from the bus handler, however this requires
the main loop to run until all pending messages have been consumed.

This commit achieves this by always running the main loop, and
simply adding an idle source to quit it in the non --follow case.
  • Loading branch information
MathieuDuponchelle committed Sep 30, 2019
1 parent 606ab04 commit 0e1da38
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/gst-device-monitor.c
Expand Up @@ -268,6 +268,13 @@ bus_msg_handler (GstBus * bus, GstMessage * msg, gpointer user_data)
return TRUE;
}

static gboolean
quit_loop (GMainLoop * loop)
{
g_main_loop_quit (loop);
return G_SOURCE_REMOVE;
}

int
main (int argc, char **argv)
{
Expand Down Expand Up @@ -364,12 +371,16 @@ main (int argc, char **argv)

GST_INFO ("Took %.2f seconds", g_timer_elapsed (timer, NULL));

if (follow) {
if (!follow) {
/* Consume all the messages pending on the bus and exit */
g_idle_add ((GSourceFunc) quit_loop, app.loop);
} else {
g_print ("Monitoring devices, waiting for devices to be removed or "
"new devices to be added...\n");
g_main_loop_run (app.loop);
}

g_main_loop_run (app.loop);

gst_device_monitor_stop (app.monitor);
gst_object_unref (app.monitor);

Expand Down

0 comments on commit 0e1da38

Please sign in to comment.