gstreamer/tests/threadstate/threadstate2.c
Wim Taymans 01085fa26a gst/gstbin.c: use gst_object_has_ancestor().
Original commit message from CVS:
* gst/gstbin.c: (bin_element_is_semi_sink), (gst_bin_change_state):
use gst_object_has_ancestor().

* gst/gstobject.c: (gst_object_has_ancestor):
* gst/gstobject.h:
gst_object_has_ancestor() copied from gstbin.c as it is a
usefull function.

* tests/instantiate/create.c: (create_all_elements):
* tests/lat.c: (handoff_src), (handoff_sink):
* tests/sched/runxml.c: (main):
* tests/seeking/seeking1.c: (main):
* tests/threadstate/threadstate2.c: (bus_handler), (timeout_func),
(main):
Fix compilation of some tests.
2005-09-27 09:57:20 +00:00

91 lines
2.1 KiB
C

#include <stdlib.h>
#include <gst/gst.h>
static GMainLoop *loop;
static gboolean EOS = FALSE;
/* this pipeline is:
* { filesrc ! mad ! osssink }
*/
static gboolean
bus_handler (GstBus * bus, GstMessage * message, gpointer data)
{
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_EOS:
g_print ("have eos, quitting\n");
EOS = TRUE;
if (g_main_loop_is_running (loop))
g_main_loop_quit (loop);
break;
default:
break;
}
return TRUE;
}
static gboolean
timeout_func (GMainLoop * loop)
{
g_main_loop_quit (loop);
return TRUE;
}
int
main (int argc, char *argv[])
{
GstElement *filesrc, *osssink;
GstElement *pipeline;
GstElement *mad;
gint x;
GstBus *bus;
gst_init (&argc, &argv);
if (argc != 2) {
g_print ("usage: %s <filename>\n", argv[0]);
exit (-1);
}
/* create a new pipeline to hold the elements */
pipeline = gst_pipeline_new ("pipeline");
g_assert (pipeline != NULL);
/* create a disk reader */
filesrc = gst_element_factory_make ("filesrc", "disk_source");
g_assert (filesrc != NULL);
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
/* and an audio sink */
osssink = gst_element_factory_make ("osssink", "play_audio");
g_assert (osssink != NULL);
/* did i mention that this is an mp3 player? */
mad = gst_element_factory_make ("mad", "mp3_decoder");
g_assert (mad != NULL);
gst_bin_add_many (GST_BIN (pipeline), filesrc, mad, osssink, NULL);
gst_element_link_many (filesrc, mad, osssink, NULL);
loop = g_main_loop_new (NULL, FALSE);
g_timeout_add (2 * 1000, (GSourceFunc) timeout_func, loop);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, GST_MESSAGE_ANY, (GstBusFunc) bus_handler, pipeline);
for (x = 0; x < 10; x++) {
g_print ("playing %d\n", x);
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
g_main_loop_run (loop);
if (EOS)
break;
g_print ("pausing %d\n", x);
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED);
g_main_loop_run (loop);
}
exit (0);
}