diff options
author | Sven Gothel <[email protected]> | 2012-04-16 20:50:06 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-16 20:50:06 +0200 |
commit | 10935e1ec0d8ed677bc3fddfaa8cd73898a3bcbf (patch) | |
tree | 6d453f72b3024670a6ed5c03454ef54ad4a04ba0 /src/test-native/gst | |
parent | 62e5686fb583ad991d5811baf242d40d21952e27 (diff) |
Add native tests for libav/ffmpeg and gst
Diffstat (limited to 'src/test-native/gst')
-rw-r--r-- | src/test-native/gst/helloworld-auto.c | 112 | ||||
-rw-r--r-- | src/test-native/gst/helloworld-playbin.c | 75 | ||||
-rw-r--r-- | src/test-native/gst/helloworld-playbin2.c | 75 | ||||
-rw-r--r-- | src/test-native/gst/helloworld.c | 142 | ||||
-rw-r--r-- | src/test-native/gst/make.sh | 5 |
5 files changed, 409 insertions, 0 deletions
diff --git a/src/test-native/gst/helloworld-auto.c b/src/test-native/gst/helloworld-auto.c new file mode 100644 index 000000000..6381c9c93 --- /dev/null +++ b/src/test-native/gst/helloworld-auto.c @@ -0,0 +1,112 @@ +#include <gst/gst.h> +#include <glib.h> + + +static gboolean +my_bus_callback (GstBus *bus, + GstMessage *msg, + gpointer data) +{ + GMainLoop *loop = (GMainLoop *) data; + + switch (GST_MESSAGE_TYPE (msg)) { + + case GST_MESSAGE_EOS: + g_print ("End of stream\n"); + g_main_loop_quit (loop); + break; + + case GST_MESSAGE_ERROR: { + gchar *debug; + GError *error; + + gst_message_parse_error (msg, &error, &debug); + g_free (debug); + + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + + g_main_loop_quit (loop); + break; + } + default: + break; + } + + return TRUE; +} + + +static gboolean +idle_exit_loop (gpointer data) +{ + g_main_loop_quit ((GMainLoop *) data); + + /* once */ + return FALSE; +} + +static void +cb_typefound (GstElement *typefind, + guint probability, + GstCaps *caps, + gpointer data) +{ + GMainLoop *loop = data; + gchar *type; + + type = gst_caps_to_string (caps); + g_print ("Media type %s found, probability %d%%\n", type, probability); + g_free (type); + + /* since we connect to a signal in the pipeline thread context, we need + * to set an idle handler to exit the main loop in the mainloop context. + * Normally, your app should not need to worry about such things. */ + g_idle_add (idle_exit_loop, loop); +} + +gint +main (gint argc, + gchar *argv[]) +{ + GMainLoop *loop; + GstElement *pipeline, *filesrc, *typefind, *fakesink; + GstBus *bus; + + /* init GStreamer */ + gst_init (&argc, &argv); + loop = g_main_loop_new (NULL, FALSE); + + /* check args */ + if (argc != 2) { + g_print ("Usage: %s <filename>\n", argv[0]); + return -1; + } + + /* create a new pipeline to hold the elements */ + pipeline = gst_pipeline_new ("pipe"); + + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_watch (bus, my_bus_callback, NULL); + gst_object_unref (bus); + + /* create file source and typefind element */ + filesrc = gst_element_factory_make ("filesrc", "source"); + g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); + typefind = gst_element_factory_make ("typefind", "typefinder"); + g_signal_connect (typefind, "have-type", G_CALLBACK (cb_typefound), loop); + fakesink = gst_element_factory_make ("fakesink", "sink"); + + /* setup */ + gst_bin_add_many (GST_BIN (pipeline), filesrc, typefind, fakesink, NULL); + gst_element_link_many (filesrc, typefind, fakesink, NULL); + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); + g_main_loop_run (loop); + + /* unset */ + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); + gst_object_unref (GST_OBJECT (pipeline)); + + return 0; +} + diff --git a/src/test-native/gst/helloworld-playbin.c b/src/test-native/gst/helloworld-playbin.c new file mode 100644 index 000000000..c5a42fe6c --- /dev/null +++ b/src/test-native/gst/helloworld-playbin.c @@ -0,0 +1,75 @@ +#include <gst/gst.h> +#include <glib.h> + + +static gboolean +my_bus_callback (GstBus *bus, + GstMessage *msg, + gpointer data) +{ + GMainLoop *loop = (GMainLoop *) data; + + switch (GST_MESSAGE_TYPE (msg)) { + + case GST_MESSAGE_EOS: + g_print ("End of stream\n"); + g_main_loop_quit (loop); + break; + + case GST_MESSAGE_ERROR: { + gchar *debug; + GError *error; + + gst_message_parse_error (msg, &error, &debug); + g_free (debug); + + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + + g_main_loop_quit (loop); + break; + } + default: + break; + } + + return TRUE; +} + +gint +main (gint argc, + gchar *argv[]) +{ + GMainLoop *loop; + GstElement *play; + GstBus *bus; + + /* init GStreamer */ + gst_init (&argc, &argv); + loop = g_main_loop_new (NULL, FALSE); + + /* make sure we have a URI */ + if (argc != 2) { + g_print ("Usage: %s <URI>\n", argv[0]); + return -1; + } + + /* set up */ + play = gst_element_factory_make ("playbin", "play"); + g_object_set (G_OBJECT (play), "uri", argv[1], NULL); + + bus = gst_pipeline_get_bus (GST_PIPELINE (play)); + gst_bus_add_watch (bus, my_bus_callback, loop); + gst_object_unref (bus); + + gst_element_set_state (play, GST_STATE_PLAYING); + + /* now run */ + g_main_loop_run (loop); + + /* also clean up */ + gst_element_set_state (play, GST_STATE_NULL); + gst_object_unref (GST_OBJECT (play)); + + return 0; +} diff --git a/src/test-native/gst/helloworld-playbin2.c b/src/test-native/gst/helloworld-playbin2.c new file mode 100644 index 000000000..b31e3e5c6 --- /dev/null +++ b/src/test-native/gst/helloworld-playbin2.c @@ -0,0 +1,75 @@ +#include <gst/gst.h> +#include <glib.h> + + +static gboolean +my_bus_callback (GstBus *bus, + GstMessage *msg, + gpointer data) +{ + GMainLoop *loop = (GMainLoop *) data; + + switch (GST_MESSAGE_TYPE (msg)) { + + case GST_MESSAGE_EOS: + g_print ("End of stream\n"); + g_main_loop_quit (loop); + break; + + case GST_MESSAGE_ERROR: { + gchar *debug; + GError *error; + + gst_message_parse_error (msg, &error, &debug); + g_free (debug); + + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + + g_main_loop_quit (loop); + break; + } + default: + break; + } + + return TRUE; +} + +gint +main (gint argc, + gchar *argv[]) +{ + GMainLoop *loop; + GstElement *play; + GstBus *bus; + + /* init GStreamer */ + gst_init (&argc, &argv); + loop = g_main_loop_new (NULL, FALSE); + + /* make sure we have a URI */ + if (argc != 2) { + g_print ("Usage: %s <URI>\n", argv[0]); + return -1; + } + + /* set up */ + play = gst_element_factory_make ("playbin2", "play"); + g_object_set (G_OBJECT (play), "uri", argv[1], NULL); + + bus = gst_pipeline_get_bus (GST_PIPELINE (play)); + gst_bus_add_watch (bus, my_bus_callback, loop); + gst_object_unref (bus); + + gst_element_set_state (play, GST_STATE_PLAYING); + + /* now run */ + g_main_loop_run (loop); + + /* also clean up */ + gst_element_set_state (play, GST_STATE_NULL); + gst_object_unref (GST_OBJECT (play)); + + return 0; +} diff --git a/src/test-native/gst/helloworld.c b/src/test-native/gst/helloworld.c new file mode 100644 index 000000000..6d991898d --- /dev/null +++ b/src/test-native/gst/helloworld.c @@ -0,0 +1,142 @@ +#include <gst/gst.h> +#include <glib.h> + + +static gboolean +bus_call (GstBus *bus, + GstMessage *msg, + gpointer data) +{ + GMainLoop *loop = (GMainLoop *) data; + + switch (GST_MESSAGE_TYPE (msg)) { + + case GST_MESSAGE_EOS: + g_print ("End of stream\n"); + g_main_loop_quit (loop); + break; + + case GST_MESSAGE_ERROR: { + gchar *debug; + GError *error; + + gst_message_parse_error (msg, &error, &debug); + g_free (debug); + + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + + g_main_loop_quit (loop); + break; + } + default: + break; + } + + return TRUE; +} + + +static void +on_pad_added (GstElement *element, + GstPad *pad, + gpointer data) +{ + GstPad *sinkpad; + GstElement *decoder = (GstElement *) data; + + /* We can now link this pad with the vorbis-decoder sink pad */ + g_print ("Dynamic pad created, linking demuxer/decoder\n"); + + sinkpad = gst_element_get_static_pad (decoder, "sink"); + + gst_pad_link (pad, sinkpad); + + gst_object_unref (sinkpad); +} + + + +int +main (int argc, + char *argv[]) +{ + GMainLoop *loop; + + GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink; + GstBus *bus; + + /* Initialisation */ + gst_init (&argc, &argv); + + loop = g_main_loop_new (NULL, FALSE); + + + /* Check input arguments */ + if (argc != 2) { + g_printerr ("Usage: %s <Ogg/Vorbis filename>\n", argv[0]); + return -1; + } + + + /* Create gstreamer elements */ + pipeline = gst_pipeline_new ("audio-player"); + source = gst_element_factory_make ("filesrc", "file-source"); + demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); + decoder = gst_element_factory_make ("vorbisdec", "vorbis-decoder"); + conv = gst_element_factory_make ("audioconvert", "converter"); + sink = gst_element_factory_make ("autoaudiosink", "audio-output"); + + if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) { + g_printerr ("One element could not be created. Exiting.\n"); + return -1; + } + + /* Set up the pipeline */ + + /* we set the input filename to the source element */ + g_object_set (G_OBJECT (source), "location", argv[1], NULL); + + /* we add a message handler */ + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_watch (bus, bus_call, loop); + gst_object_unref (bus); + + /* we add all elements into the pipeline */ + /* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */ + gst_bin_add_many (GST_BIN (pipeline), + source, demuxer, decoder, conv, sink, NULL); + + /* we link the elements together */ + /* file-source -> ogg-demuxer ~> vorbis-decoder -> converter -> alsa-output */ + gst_element_link (source, demuxer); + gst_element_link_many (decoder, conv, sink, NULL); + g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder); + + /* note that the demuxer will be linked to the decoder dynamically. + The reason is that Ogg may contain various streams (for example + audio and video). The source pad(s) will be created at run time, + by the demuxer when it detects the amount and nature of streams. + Therefore we connect a callback function which will be executed + when the "pad-added" is emitted.*/ + + + /* Set the pipeline to "playing" state*/ + g_print ("Now playing: %s\n", argv[1]); + gst_element_set_state (pipeline, GST_STATE_PLAYING); + + + /* Iterate */ + g_print ("Running...\n"); + g_main_loop_run (loop); + + + /* Out of the main loop, clean up nicely */ + g_print ("Returned, stopping playback\n"); + gst_element_set_state (pipeline, GST_STATE_NULL); + + g_print ("Deleting pipeline\n"); + gst_object_unref (GST_OBJECT (pipeline)); + + return 0; +} diff --git a/src/test-native/gst/make.sh b/src/test-native/gst/make.sh new file mode 100644 index 000000000..23e54a272 --- /dev/null +++ b/src/test-native/gst/make.sh @@ -0,0 +1,5 @@ +gcc -Wall helloworld.c -o helloworld $(pkg-config --cflags --libs gstreamer-0.10) +gcc -Wall helloworld-auto.c -o helloworld-auto $(pkg-config --cflags --libs gstreamer-0.10) +gcc -Wall helloworld-playbin.c -o helloworld-playbin $(pkg-config --cflags --libs gstreamer-0.10) +gcc -Wall helloworld-playbin2.c -o helloworld-playbin2 $(pkg-config --cflags --libs gstreamer-0.10) + |