tests/playback: quit from main loop

Listen for eos and error signal to quit main loop.

https://bugzilla.gnome.org/show_bug.cgi?id=739346
This commit is contained in:
Ravi Kiran K N 2014-10-29 16:28:28 +05:30 committed by Luis de Bethencourt
parent d86aba27ce
commit e0028c77f6
3 changed files with 48 additions and 3 deletions

View file

@ -139,11 +139,18 @@ link_failed:
}
}
static void
error_eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
{
g_main_loop_quit (main_loop);
}
gint
main (gint argc, gchar * argv[])
{
GstElement *pipeline, *filesrc, *decodebin;
GstStateChangeReturn res;
GstBus *bus;
gst_init (&argc, &argv);
@ -154,6 +161,13 @@ main (gint argc, gchar * argv[])
decodebin = gst_element_factory_make ("decodebin", "decodebin");
g_assert (decodebin);
loop = g_main_loop_new (NULL, TRUE);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "message::eos", G_CALLBACK (error_eos_cb), loop);
g_signal_connect (bus, "message::error", G_CALLBACK (error_eos_cb), loop);
g_signal_connect (G_OBJECT (decodebin), "pad-added",
G_CALLBACK (pad_added_cb), pipeline);
@ -193,7 +207,6 @@ main (gint argc, gchar * argv[])
}
/* go in the mainloop now */
loop = g_main_loop_new (NULL, TRUE);
g_main_loop_run (loop);
return 0;

View file

@ -18,11 +18,20 @@
*/
#include <gst/gst.h>
static GMainLoop *loop;
static void
error_eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
{
g_main_loop_quit (main_loop);
}
gint
main (gint argc, gchar * argv[])
{
GstElement *player;
GstStateChangeReturn res;
GstBus *bus;
gst_init (&argc, &argv);
@ -31,13 +40,20 @@ main (gint argc, gchar * argv[])
g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
loop = g_main_loop_new (NULL, TRUE);
bus = gst_pipeline_get_bus (GST_PIPELINE (player));
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "message::eos", G_CALLBACK (error_eos_cb), loop);
g_signal_connect (bus, "message::error", G_CALLBACK (error_eos_cb), loop);
res = gst_element_set_state (player, GST_STATE_PLAYING);
if (res == GST_STATE_CHANGE_FAILURE) {
g_print ("could not play\n");
return -1;
}
g_main_loop_run (g_main_loop_new (NULL, TRUE));
g_main_loop_run (loop);
return 0;
}

View file

@ -28,11 +28,20 @@
#include <gst/gst.h>
static GMainLoop *loop;
static void
error_eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
{
g_main_loop_quit (main_loop);
}
gint
main (gint argc, gchar * argv[])
{
GstElement *player;
GstStateChangeReturn res;
GstBus *bus;
gst_init (&argc, &argv);
@ -44,6 +53,13 @@ main (gint argc, gchar * argv[])
exit (-1);
}
loop = g_main_loop_new (NULL, TRUE);
bus = gst_pipeline_get_bus (GST_PIPELINE (player));
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "message::eos", G_CALLBACK (error_eos_cb), loop);
g_signal_connect (bus, "message::error", G_CALLBACK (error_eos_cb), loop);
g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
g_print ("play...\n");
@ -93,7 +109,7 @@ main (gint argc, gchar * argv[])
return -1;
}
g_main_loop_run (g_main_loop_new (NULL, TRUE));
g_main_loop_run (loop);
return 0;
}