2003-02-10 20:08:59 +00:00
|
|
|
#include <stdlib.h>
|
2002-06-01 15:08:13 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2002-06-03 18:51:08 +00:00
|
|
|
/* this pipeline is:
|
|
|
|
* { filesrc ! mad ! osssink }
|
|
|
|
*/
|
|
|
|
|
2002-06-01 15:08:13 +00:00
|
|
|
/* eos will be called when the src element has an end of stream */
|
2003-01-09 14:15:37 +00:00
|
|
|
void eos(GstElement *element, gpointer data)
|
2002-06-01 15:08:13 +00:00
|
|
|
{
|
2003-01-09 14:15:37 +00:00
|
|
|
GstThread *thread = GST_THREAD (data);
|
2002-06-01 15:08:13 +00:00
|
|
|
g_print("have eos, quitting\n");
|
|
|
|
|
|
|
|
/* stop the bin */
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_NULL);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
|
|
|
gst_main_quit();
|
|
|
|
}
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
int main(int argc,char *argv[])
|
2002-06-01 15:08:13 +00:00
|
|
|
{
|
|
|
|
GstElement *filesrc, *osssink;
|
|
|
|
GstElement *thread;
|
|
|
|
GstElement *mad;
|
|
|
|
gint x;
|
|
|
|
|
|
|
|
gst_init(&argc,&argv);
|
|
|
|
|
|
|
|
if (argc != 2) {
|
2003-01-09 14:15:37 +00:00
|
|
|
g_print ("usage: %s <filename>\n", argv[0]);
|
|
|
|
exit (-1);
|
2002-06-01 15:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create a new thread to hold the elements */
|
2003-01-09 14:15:37 +00:00
|
|
|
thread = gst_thread_new ("thread");
|
|
|
|
g_assert (thread != NULL);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
|
|
|
/* create a disk reader */
|
2003-01-09 14:15:37 +00:00
|
|
|
filesrc = gst_element_factory_make ("filesrc", "disk_source");
|
|
|
|
g_assert (filesrc != NULL);
|
|
|
|
g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
|
|
|
|
g_signal_connect (G_OBJECT (filesrc), "eos",
|
|
|
|
G_CALLBACK (eos), thread);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
|
|
|
/* and an audio sink */
|
2003-01-09 14:15:37 +00:00
|
|
|
osssink = gst_element_factory_make ("osssink", "play_audio");
|
|
|
|
g_assert (osssink != NULL);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
|
|
|
/* did i mention that this is an mp3 player? */
|
2003-01-09 14:15:37 +00:00
|
|
|
mad = gst_element_factory_make ("mad", "mp3_decoder");
|
|
|
|
g_assert (mad != NULL);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
gst_bin_add_many (GST_BIN (thread), filesrc, mad, osssink, NULL);
|
|
|
|
gst_element_link_many (filesrc, mad, osssink, NULL);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
|
|
|
for (x = 0 ; x < 10 ; x++){
|
2003-01-09 14:15:37 +00:00
|
|
|
g_print ("playing %d\n", x);
|
|
|
|
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PLAYING);
|
2003-06-29 14:05:49 +00:00
|
|
|
g_usleep (G_USEC_PER_SEC * 2);
|
2002-06-01 15:08:13 +00:00
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
g_print ("pausing %d\n", x);
|
|
|
|
gst_element_set_state (GST_ELEMENT (thread), GST_STATE_PAUSED);
|
2003-06-29 14:05:49 +00:00
|
|
|
g_usleep (G_USEC_PER_SEC * 2);
|
2002-06-01 15:08:13 +00:00
|
|
|
}
|
|
|
|
|
2003-01-09 14:15:37 +00:00
|
|
|
exit (0);
|
2002-06-01 15:08:13 +00:00
|
|
|
}
|