Created
July 25, 2013 04:39
-
-
Save yujuwon/6076952 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <gst/gst.h> | |
| static GMainLoop *loop; | |
| static gboolean my_bus_callback (GstBus *bus, GstMessage *message, gpointer data) | |
| { | |
| g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message)); | |
| switch (GST_MESSAGE_TYPE (message)) { | |
| case GST_MESSAGE_ERROR: { | |
| GError *err; | |
| gchar *debug; | |
| gst_message_parse_error (message, &err, &debug); | |
| g_print ("Error: %s\n", err->message); | |
| g_error_free (err); | |
| g_free (debug); | |
| g_main_loop_quit (loop); | |
| break; | |
| } | |
| case GST_MESSAGE_EOS: | |
| /* end-of-stream */ | |
| g_main_loop_quit (loop); | |
| break; | |
| default: | |
| /* unhandled message */ | |
| break; | |
| } | |
| /* we want to be notified again the next time there is a message | |
| * on the bus, so returning TRUE (FALSE means we want to stop watching | |
| * for messages on the bus and our callback should not be called again) | |
| */ | |
| return TRUE; | |
| } | |
| gint main (gint argc, gchar *argv[]) | |
| { | |
| GstElement *pipeline; | |
| GstBus *bus; | |
| /* init */ | |
| gst_init (&argc, &argv); | |
| /* create pipeline, add handler */ | |
| pipeline = gst_pipeline_new ("my_pipeline"); | |
| /* adds a watch for new message on our pipeline’s message bus to | |
| * the default GLib main context, which is the main context that our | |
| * GLib main loop is attached to below | |
| */ | |
| bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); | |
| gst_bus_add_watch (bus, my_bus_callback, NULL); | |
| gst_object_unref (bus); | |
| [..] | |
| /* create a mainloop that runs/iterates the default GLib main context | |
| * (context NULL), in other words: makes the context check if anything | |
| * it watches for has happened. When a message has been posted on the | |
| * bus, the default main context will automatically call our | |
| * my_bus_callback() function to notify us of that message. | |
| * The main loop will be run until someone calls g_main_loop_quit() | |
| */ | |
| loop = g_main_loop_new (NULL, FALSE); | |
| g_main_loop_run (loop); | |
| /* clean up */ | |
| gst_element_set_state (pipeline, GST_STATE_NULL); | |
| gst_object_unref (pipeline); | |
| g_main_loop_unref (loop); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment