<DIV>#include <gst/gst.h><BR>#include <glib.h><BR>static GstElement *a_queue,*v_queue,*audio,*pipeline=NULL; //volter<BR>GstBus *bus;<BR>GMainLoop *loop;<BR>gchar filepath[256]="test.ts";<BR>static GstState state = GST_STATE_NULL;</DIV>
<DIV>static int build_pipeline(gchar *location);<BR>static void play_cb (gchar * filepath);<BR>static void new_pad (GstElement *element, GstPad *pad, gpointer data);<BR>static void new_pad2 (GstElement *element, GstPad *pad, gpointer data);<BR>static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data);</DIV>
<DIV><BR>int main (int argc, char **argv)<BR>{<BR> gst_init (&argc, &argv);<BR> loop = g_main_loop_new (NULL, FALSE);</DIV>
<DIV> play_cb(filepath);</DIV>
<DIV> g_print ("Running\n");<BR> g_main_loop_run (loop);</DIV>
<DIV> gst_element_set_state (pipeline, GST_STATE_NULL);<BR> <BR> g_print("main-pipeline:%x\n",pipeline);<BR> <BR> gst_object_unref (GST_OBJECT (pipeline));</DIV>
<DIV> return 0;<BR>}</DIV>
<DIV> </DIV>
<DIV>static void play_cb (gchar * filepath)<BR>{</DIV>
<DIV> GstStateChangeReturn ret;<BR> <BR> build_pipeline(filepath);</DIV>
<DIV><BR> if (state != GST_STATE_PLAYING) {<BR> g_print ("PLAY pipeline\n");<BR> ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);<BR> if (ret == GST_STATE_CHANGE_FAILURE)<BR> goto failed;</DIV>
<DIV> state = GST_STATE_PLAYING;<BR> }<BR> return;</DIV>
<DIV>failed:<BR> {<BR> g_print ("PLAY failed\n");<BR> }<BR>}</DIV>
<DIV> </DIV>
<DIV>static int build_pipeline(gchar *location)<BR>{<BR> GstElement *filesrc,*ts_demux;<BR> GstElement *a_dec,*a_conv,*audiosink,*a_resample;<BR> GstStateChangeReturn ret;<BR> GstPad *audiopad,*queuesrcpad;//,*queuesinkpad<BR> </DIV>
<DIV> g_print("vesion 20070907\n");<BR> sleep(2);</DIV>
<DIV> </DIV>
<DIV> // create a new pipeline to hold the elements <BR> pipeline = gst_pipeline_new ("pipe");</DIV>
<DIV> </DIV>
<DIV> // create file source element<BR> filesrc = gst_element_factory_make ("filesrc", "source");<BR> if (!filesrc )<BR> {<BR> g_print ("source element could not be created\n");<BR> return -1;<BR> }<BR> g_object_set (G_OBJECT (filesrc), "location", location, NULL);<BR> gst_bin_add (GST_BIN (pipeline), filesrc);</DIV>
<DIV> </DIV>
<DIV> bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));<BR> gst_bus_add_watch (bus, bus_call, loop);<BR> gst_object_unref (bus);</DIV>
<DIV> </DIV>
<DIV>// create ts demux element<BR> ts_demux = gst_element_factory_make ("flutsdemux", "ts_demux");<BR> if (!ts_demux )<BR> {<BR> g_print ("ts_demux element could not be created\n");<BR> return -1;<BR> } <BR> gst_bin_add (GST_BIN (pipeline), ts_demux);<BR> gst_element_link (filesrc, ts_demux);<BR> <BR>//audio process....<BR>//create a queue bettwen demuxer and decoder, link ts_demux with queue<BR> a_queue = gst_element_factory_make ("queue", "a_queue");<BR> if (!a_queue )<BR> {<BR> g_print ("a_queue element could not be created\n");<BR> return -1;<BR> }<BR> gst_bin_add (GST_BIN (pipeline), a_queue);<BR> gst_element_set_state (a_queue, GST_STATE_READY);</DIV>
<DIV> //queuesinkpad = gst_element_get_pad (a_queue, "sink");<BR> queuesrcpad = gst_element_get_pad (a_queue, "src");</DIV>
<DIV> </DIV>
<DIV>g_signal_connect (ts_demux, "pad-added", G_CALLBACK (new_pad), NULL);<BR> //ts_demux src pad is dynamic...<BR> //gst_pad_link (gst_element_get_pad (ts_demux, "audio_%02d"), queuesinkpad);</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>//create audio decoder and link queue with a_dec<BR> a_dec = gst_element_factory_make ("flump3dec", "a_dec");<BR> gst_bin_add (GST_BIN (pipeline), a_dec);<BR> gst_pad_link (queuesrcpad,gst_element_get_pad (a_dec, "sink") );</DIV>
<DIV><BR>//create audio out bin<BR> audio=gst_bin_new ("audio");</DIV>
<DIV> a_conv = gst_element_factory_make ("audioconvert", "a_conv");<BR> a_resample=gst_element_factory_make ("audioresample", "a_resample");<BR> audiosink = gst_element_factory_make ("alsasink", "audiosink");<BR> if ( !a_conv || !a_resample || !audiosink) {<BR> g_print ("One element could not be created\n");<BR> return -1;<BR> }<BR> <BR> gst_bin_add_many (GST_BIN (audio), a_conv,a_resample,audiosink,NULL);<BR> gst_element_link_many (a_conv,a_resample,audiosink,NULL);<BR> <BR> //create ghost pad <BR> audiopad = gst_element_get_pad (a_conv, "sink");<BR> gst_element_add_pad (audio,gst_ghost_pad_new ("sink", audiopad));<BR> gst_bin_add (GST_BIN (pipeline), audio);</DIV>
<DIV> //link a_dec with audio out bin<BR> gst_pad_link (gst_element_get_pad (a_dec, "src"),audiopad );</DIV>
<DIV> gst_object_unref (audiopad);<BR> <BR> ret = gst_element_set_state (audio, GST_STATE_PLAYING);<BR> if (ret != GST_STATE_CHANGE_SUCCESS)<BR> g_printf("\nset audio out state : change state Expection!\n");</DIV>
<DIV><BR>//video process.......<BR>//....</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> ret = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);<BR> if (ret != GST_STATE_CHANGE_SUCCESS)<BR> g_printf("\nset pipeline bin state : change state Expection!\n");<BR> <BR> return 0;</DIV>
<DIV>}</DIV>
<DIV><BR>static void new_pad (GstElement *element, GstPad *pad, gpointer data)<BR>{<BR> GstPad *srcpad;<BR> g_print ("Dynamic pad created, linking demuxer and a_queue\n");<BR> <BR> srcpad = gst_element_get_pad (a_queue, "sink");<BR> gst_pad_link (pad, srcpad);<BR> <BR> gst_object_unref (srcpad);<BR> }</DIV>
<DIV> </DIV>
<DIV>static void new_pad2 (GstElement *element, GstPad *pad, gpointer data)<BR>{<BR> GstPad *srcpad;<BR> g_print ("Dynamic pad created, linking demuxer and v_queue\n");<BR> <BR> srcpad = gst_element_get_pad (v_queue, "sink");<BR> gst_pad_link (pad, srcpad);<BR> <BR> gst_object_unref (srcpad);<BR> }</DIV>
<DIV> </DIV>
<DIV>static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)<BR>{<BR> GMainLoop *loop = data;</DIV>
<DIV> switch (GST_MESSAGE_TYPE (msg))<BR> {<BR> case GST_MESSAGE_EOS:<BR> g_print ("End-of-stream\n");<BR> g_main_loop_quit (loop);<BR> break;<BR> case GST_MESSAGE_ERROR:<BR> {<BR> gchar *debug;<BR> GError *err;</DIV>
<DIV> gst_message_parse_error (msg, &err, &debug);<BR> g_free (debug);</DIV>
<DIV> g_print ("Error: %s\n", err->message);<BR> g_error_free (err);</DIV>
<DIV> g_main_loop_quit (loop);<BR> break;<BR> }<BR> default:<BR> break;<BR> }</DIV>
<DIV> return TRUE;<BR>}<BR></DIV>
<DIV> </DIV><br><!-- footer --><br>
<hr>
<font style="font-size:12px;line-height:15px;">独有“账号保险柜”保护密码,</font><a style="font-size:12px;line-height:15px; color:blue; text-decoration:underline;" href="http://adclient.163.com/event.ng/Type=click&FlightID=94603&AdID=96090&TargetID=1200&Values=31,43,51,60,72,85,91,100,110,312,332,499,587,701,702,733,734&Redirect=http://www.rising.com.cn/2008/trial/index.htm">“瑞星08版”开始免费</a>