[gst-devel] where is the error,please?
Volter Yen
volter619 at 163.com
Wed Sep 12 08:52:29 CEST 2007
#include <gst/gst.h>
#include <glib.h>
static GstElement *a_queue,*v_queue,*audio,*pipeline=NULL; //volter
GstBus *bus;
GMainLoop *loop;
gchar filepath[256]="test.ts";
static GstState state = GST_STATE_NULL;static int build_pipeline(gchar *location);
static void play_cb (gchar * filepath);
static void new_pad (GstElement *element, GstPad *pad, gpointer data);
static void new_pad2 (GstElement *element, GstPad *pad, gpointer data);
static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data);
int main (int argc, char **argv)
{
gst_init (&argc, &argv);
loop = g_main_loop_new (NULL, FALSE); play_cb(filepath); g_print ("Running\n");
g_main_loop_run (loop); gst_element_set_state (pipeline, GST_STATE_NULL);
g_print("main-pipeline:%x\n",pipeline);
gst_object_unref (GST_OBJECT (pipeline)); return 0;
} static void play_cb (gchar * filepath)
{ GstStateChangeReturn ret;
build_pipeline(filepath);
if (state != GST_STATE_PLAYING) {
g_print ("PLAY pipeline\n");
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
if (ret == GST_STATE_CHANGE_FAILURE)
goto failed; state = GST_STATE_PLAYING;
}
return;failed:
{
g_print ("PLAY failed\n");
}
} static int build_pipeline(gchar *location)
{
GstElement *filesrc,*ts_demux;
GstElement *a_dec,*a_conv,*audiosink,*a_resample;
GstStateChangeReturn ret;
GstPad *audiopad,*queuesrcpad;//,*queuesinkpad
g_print("vesion 20070907\n");
sleep(2); // create a new pipeline to hold the elements
pipeline = gst_pipeline_new ("pipe"); // create file source element
filesrc = gst_element_factory_make ("filesrc", "source");
if (!filesrc )
{
g_print ("source element could not be created\n");
return -1;
}
g_object_set (G_OBJECT (filesrc), "location", location, NULL);
gst_bin_add (GST_BIN (pipeline), filesrc); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_bus_add_watch (bus, bus_call, loop);
gst_object_unref (bus); // create ts demux element
ts_demux = gst_element_factory_make ("flutsdemux", "ts_demux");
if (!ts_demux )
{
g_print ("ts_demux element could not be created\n");
return -1;
}
gst_bin_add (GST_BIN (pipeline), ts_demux);
gst_element_link (filesrc, ts_demux);
//audio process....
//create a queue bettwen demuxer and decoder, link ts_demux with queue
a_queue = gst_element_factory_make ("queue", "a_queue");
if (!a_queue )
{
g_print ("a_queue element could not be created\n");
return -1;
}
gst_bin_add (GST_BIN (pipeline), a_queue);
gst_element_set_state (a_queue, GST_STATE_READY); //queuesinkpad = gst_element_get_pad (a_queue, "sink");
queuesrcpad = gst_element_get_pad (a_queue, "src"); g_signal_connect (ts_demux, "pad-added", G_CALLBACK (new_pad), NULL);
//ts_demux src pad is dynamic...
//gst_pad_link (gst_element_get_pad (ts_demux, "audio_%02d"), queuesinkpad); //create audio decoder and link queue with a_dec
a_dec = gst_element_factory_make ("flump3dec", "a_dec");
gst_bin_add (GST_BIN (pipeline), a_dec);
gst_pad_link (queuesrcpad,gst_element_get_pad (a_dec, "sink") );
//create audio out bin
audio=gst_bin_new ("audio"); a_conv = gst_element_factory_make ("audioconvert", "a_conv");
a_resample=gst_element_factory_make ("audioresample", "a_resample");
audiosink = gst_element_factory_make ("alsasink", "audiosink");
if ( !a_conv || !a_resample || !audiosink) {
g_print ("One element could not be created\n");
return -1;
}
gst_bin_add_many (GST_BIN (audio), a_conv,a_resample,audiosink,NULL);
gst_element_link_many (a_conv,a_resample,audiosink,NULL);
//create ghost pad
audiopad = gst_element_get_pad (a_conv, "sink");
gst_element_add_pad (audio,gst_ghost_pad_new ("sink", audiopad));
gst_bin_add (GST_BIN (pipeline), audio); //link a_dec with audio out bin
gst_pad_link (gst_element_get_pad (a_dec, "src"),audiopad ); gst_object_unref (audiopad);
ret = gst_element_set_state (audio, GST_STATE_PLAYING);
if (ret != GST_STATE_CHANGE_SUCCESS)
g_printf("\nset audio out state : change state Expection!\n");
//video process.......
//.... ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
if (ret != GST_STATE_CHANGE_SUCCESS)
g_printf("\nset pipeline bin state : change state Expection!\n");
return 0;}
static void new_pad (GstElement *element, GstPad *pad, gpointer data)
{
GstPad *srcpad;
g_print ("Dynamic pad created, linking demuxer and a_queue\n");
srcpad = gst_element_get_pad (a_queue, "sink");
gst_pad_link (pad, srcpad);
gst_object_unref (srcpad);
} static void new_pad2 (GstElement *element, GstPad *pad, gpointer data)
{
GstPad *srcpad;
g_print ("Dynamic pad created, linking demuxer and v_queue\n");
srcpad = gst_element_get_pad (v_queue, "sink");
gst_pad_link (pad, srcpad);
gst_object_unref (srcpad);
} static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
{
GMainLoop *loop = 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 *err; gst_message_parse_error (msg, &err, &debug);
g_free (debug); g_print ("Error: %s\n", err->message);
g_error_free (err); g_main_loop_quit (loop);
break;
}
default:
break;
} return TRUE;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20070912/770d2db3/attachment.htm>
More information about the gstreamer-devel
mailing list