mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 06:58:56 +00:00
cairooverlay: Add a bus handler to the example to handle EOS/ERROR/WARNING
Also clean up the pipeline properly.
This commit is contained in:
parent
7f85827bf7
commit
1a8aa16612
1 changed files with 44 additions and 4 deletions
|
@ -29,6 +29,41 @@
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
on_message (GstBus * bus, GstMessage * message, gpointer user_data)
|
||||||
|
{
|
||||||
|
GMainLoop *loop = (GMainLoop *) user_data;
|
||||||
|
|
||||||
|
switch (GST_MESSAGE_TYPE (message)) {
|
||||||
|
case GST_MESSAGE_ERROR:{
|
||||||
|
GError *err = NULL;
|
||||||
|
gchar *debug;
|
||||||
|
|
||||||
|
gst_message_parse_error (message, &err, &debug);
|
||||||
|
g_critical ("Got ERROR: %s (%s)", err->message, GST_STR_NULL (debug));
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GST_MESSAGE_WARNING:{
|
||||||
|
GError *err = NULL;
|
||||||
|
gchar *debug;
|
||||||
|
|
||||||
|
gst_message_parse_warning (message, &err, &debug);
|
||||||
|
g_warning ("Got WARNING: %s (%s)", err->message, GST_STR_NULL (debug));
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GST_MESSAGE_EOS:
|
||||||
|
g_main_loop_quit (loop);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Datastructure to share the state we are interested in between
|
/* Datastructure to share the state we are interested in between
|
||||||
* prepare and render function. */
|
* prepare and render function. */
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -114,17 +149,22 @@ main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
GMainLoop *loop;
|
GMainLoop *loop;
|
||||||
GstElement *pipeline;
|
GstElement *pipeline;
|
||||||
CairoOverlayState *overlay_state;
|
GstBus *bus;
|
||||||
|
CairoOverlayState overlay_state = { FALSE, 0, 0 };
|
||||||
|
|
||||||
gst_init (&argc, &argv);
|
gst_init (&argc, &argv);
|
||||||
loop = g_main_loop_new (NULL, FALSE);
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
overlay_state = g_new0 (CairoOverlayState, 1);
|
pipeline = setup_gst_pipeline (&overlay_state);
|
||||||
pipeline = setup_gst_pipeline (overlay_state);
|
|
||||||
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
||||||
|
gst_bus_add_signal_watch (bus);
|
||||||
|
g_signal_connect (G_OBJECT (bus), "message", G_CALLBACK (on_message), loop);
|
||||||
|
gst_object_unref (GST_OBJECT (bus));
|
||||||
|
|
||||||
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
||||||
g_main_loop_run (loop);
|
g_main_loop_run (loop);
|
||||||
|
|
||||||
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
||||||
gst_object_unref (pipeline);
|
gst_object_unref (pipeline);
|
||||||
g_free (overlay_state);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue