#include static GMainLoop *loop; GstElement *pipeline; GstPad *videopad = NULL, *audiopad = NULL; static gboolean my_bus_callback (GstBus *bus, GstMessage *message, gpointer data) { gchar* f; GstCaps* caps; g_print ("Got %s message\n", GST_MESSAGE_TYPE_NAME (message)); switch (GST_MESSAGE_TYPE (message)) { case GST_MESSAGE_STATE_CHANGED: { GstState old, new, pending; gst_message_parse_state_changed (message, &old, &new, &pending); #if 0 g_debug ("state changed: %s: %u, %u, %u", GST_OBJECT_NAME (message->src), old, new, pending); #endif if (new == GST_STATE_PLAYING && GST_MESSAGE_SRC(message) == pipeline) { /* video */ caps = gst_pad_get_negotiated_caps(videopad); f = gst_caps_to_string(caps); g_print("%s\n", f); gst_caps_unref (caps); /* audio */ caps = gst_pad_get_negotiated_caps(audiopad); f = gst_caps_to_string(caps); g_print("%s\n", f); gst_caps_unref (caps); /* our job is done */ gst_element_set_state (pipeline, GST_STATE_NULL); g_main_loop_quit (loop); } break; } 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; } static void cb_newpad (GstElement *decodebin, GstPad *pad, gboolean last, gpointer data) { GstCaps *caps; GstStructure *str; GstElement *fakesink; /* get caps/struct */ caps = gst_pad_get_caps (pad); str = gst_caps_get_structure (caps, 0); /* check media type */ if (g_strrstr (gst_structure_get_name (str), "audio")) { audiopad = pad; fakesink = gst_element_factory_make ("fakesink", "audiofakesink"); g_print("Audio Done (%d).\n", (int)audiopad); } else { videopad = pad; fakesink = gst_element_factory_make ("fakesink", "videofakesink"); g_print("Video Done (%d).\n", (int)videopad); } /* attach to fakesink */ gst_bin_add_many (GST_BIN (pipeline), fakesink, NULL); GstPad* sinkpad = gst_element_get_pad (fakesink, "sink"); g_print("Sinkpad: %d.\n", (int)sinkpad); gst_pad_link (pad, sinkpad); gst_caps_unref(caps); } gint main (gint argc, gchar *argv[]) { GstElement *src, *dec, *conv, *sink; GstPad *audiopad; GstBus *bus; /* init GStreamer */ gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); /* make sure we have input */ if (argc != 2) { g_print ("Usage: %s \n", argv[0]); return -1; } /* setup */ pipeline = gst_pipeline_new ("pipeline"); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_watch (bus, my_bus_callback, loop); gst_object_unref (bus); src = gst_element_factory_make ("filesrc", "source"); g_object_set (G_OBJECT (src), "location", argv[1], NULL); dec = gst_element_factory_make ("decodebin2", "decoder"); g_signal_connect (dec, "new-decoded-pad", G_CALLBACK (cb_newpad), NULL); gst_bin_add_many (GST_BIN (pipeline), src, dec, NULL); gst_element_link (src, dec); /* run */ gst_element_set_state (pipeline, GST_STATE_PLAYING); g_main_loop_run (loop); /* cleanup */ gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (GST_OBJECT (pipeline)); return 0; }