Thank you very much. It works now. :)<br>Here is what I did:<br><br>static void<br>cb_newpad (GstElement *decodebin,<br> GstPad *pad,<br> gboolean last,<br> gpointer data)<br>{<br> GstCaps *caps;<br>
GstStructure *str;<br> GstPad *audiopad,*videopad;<br> gchar *tex;<br><br> /* check media type */<br> caps = gst_pad_get_caps (pad);<br> str = gst_caps_get_structure (caps, 0);<br> tex = gst_structure_get_name(str);<br>
<br> if(g_strrstr(tex,"audio"))<br> {<br> audiopad = gst_element_get_static_pad (audio, "sink");<br> if(GST_PAD_IS_LINKED(audiopad))<br> {<br> g_object_unref(audiopad);<br> return;<br>
}<br> else<br> {<br> gst_pad_link(pad,audiopad);<br> g_object_unref(audiopad);<br> }<br> return;<br> }<br><br>Fariq.<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Message: 6<br>
Date: Thu, 22 Apr 2010 10:22:39 +0300<br>
From: Stefan Kost <<a href="mailto:ensonic@hora-obscura.de">ensonic@hora-obscura.de</a>><br>
Subject: Re: [gst-devel] Need help on using decodebin as media decoder<br>
To: Discussion of the development of GStreamer<br>
<<a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a>><br>
Message-ID: <<a href="mailto:4BCFF93F.3020109@hora-obscura.de">4BCFF93F.3020109@hora-obscura.de</a>><br>
Content-Type: text/plain; charset=ISO-8859-1<br>
<br>
Fariq Izwan wrote:<br>
> Hi good people,<br>
><br>
> I'm new to gstreamer and I have a problem of using decodebin as a<br>
> decoder to play video file. Below is my sample code that I use. The<br>
> code below runs fine for one stream of media. But if I want to play<br>
> both streams(audio and video), it doesn't work.<br>
> Can anyone tell me what I did wrong here? (Please don't suggest to use<br>
> playbin) :)<br>
><br>
> Thank you.<br>
><br>
> Fariq.<br>
><br>
> ####Sample code####<br>
><br>
> #include <gst/gst.h><br>
> #include <glib-2.0/glib/gprintf.h><br>
> #include <gstreamer-0.10/gst/gstelement.h><br>
> #include <glib-2.0/glib/gmessages.h><br>
><br>
> GstElement *pipeline, *audio,*video,*audioqueue,*videoqueue;<br>
><br>
> static void<br>
> cb_newpad (GstElement *decodebin,<br>
> GstPad *pad,<br>
> gboolean last,<br>
> gpointer data)<br>
> {<br>
> GstPad *audiopad,*videopad;<br>
><br>
> /* link audiopad */<br>
> audiopad = gst_element_get_static_pad (audio, "sink");<br>
> if (!GST_PAD_IS_LINKED (audiopad)) {<br>
> gst_pad_link (pad, audiopad);<br>
> g_print("audiopad has been linked");<br>
> g_object_unref (audiopad);<br>
> return;<br>
> }<br>
this is not correct. You would need to check the media-type of the caps<br>
on the provided pad. (Get the caps from the pad, the structure from the<br>
caps and check the name of the structure (audio/video/something-else).<br>
Depending on that you link the audio- or videobin.<br>
Also in the above code, you leak the audiopad, if it is linked already.<br>
The above code might work, if you check the result of gst_pad_link() and<br>
only return if that worked, otherwise you continie and try the next pad.<br>
<br>
Stefan<br>
<br>
> /* link videopad */<br>
> videopad = gst_element_get_static_pad(video,"sink");<br>
> if (!GST_PAD_IS_LINKED (videopad)) {<br>
> gst_pad_link(pad,videopad);<br>
> gst_element_link(videoqueue,video);<br>
> g_object_unref (videopad);<br>
> return;<br>
> }<br>
> }<br>
><br>
> gint<br>
> main (gint argc,<br>
> gchar *argv[])<br>
> {<br>
> GMainLoop *loop;<br>
> GstElement *src, *dec, *conv, *sink, *typefind,*typefind2;//*myplugin;<br>
> GstElement *convVid,*videosink;<br>
> GstPad *audiopad,*videopad;<br>
> GstBus *bus;<br>
><br>
> /* init GStreamer */<br>
> gst_init (&argc, &argv);<br>
> loop = g_main_loop_new (NULL, FALSE);<br>
><br>
> /* make sure we have input */<br>
> if (argc != 2) {<br>
> g_print ("Usage: %s <filename>\n", argv[0]);<br>
> return -1;<br>
> }<br>
><br>
> g_print("Playing %s \n",argv[1]);<br>
><br>
> /* setup */<br>
> pipeline = gst_pipeline_new ("pipeline");<br>
><br>
> bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));<br>
> gst_bus_add_watch (bus, my_bus_callback, loop);<br>
> gst_object_unref (bus);<br>
><br>
> src = gst_element_factory_make ("filesrc", "source");<br>
> g_object_set (G_OBJECT (src), "location", argv[1], NULL);<br>
> typefind = gst_element_factory_make("typefind","typefinder");<br>
> g_signal_connect(typefind,"have-type",G_CALLBACK(typefound_cb),loop);<br>
> dec = gst_element_factory_make ("decodebin", "decoder");<br>
> g_signal_connect (dec, "new-decoded-pad", G_CALLBACK (cb_newpad), NULL);<br>
> //myplugin = gst_element_factory_make("myplugin","MyPlugin");<br>
> audioqueue = gst_element_factory_make("queue","audioqueue");<br>
> videoqueue = gst_element_factory_make("queue","videoqueue");<br>
> gst_bin_add_many (GST_BIN (pipeline), src,typefind,dec,NULL);<br>
> gst_element_link_many (src,typefind,dec,NULL);<br>
><br>
> /* create audio output */<br>
> audio = gst_bin_new ("audiobin");<br>
> conv = gst_element_factory_make ("audioconvert", "aconv");<br>
> typefind2 = gst_element_factory_make("typefind","typefinder2");<br>
> //g_signal_connect(typefind2,"have-type",G_CALLBACK(typefound_cb),loop);<br>
> audiopad = gst_element_get_static_pad (audioqueue, "sink");<br>
> sink = gst_element_factory_make ("osssink", "sink");<br>
> gst_bin_add_many (GST_BIN (audio),audioqueue,conv,typefind2, sink,<br>
> NULL);<br>
> gst_element_link_many (audioqueue,conv,typefind2, sink,NULL);<br>
> gst_element_add_pad (audio,<br>
> gst_ghost_pad_new ("sink", audiopad));<br>
> gst_object_unref (audiopad);<br>
> gst_bin_add (GST_BIN (pipeline), audio);<br>
><br>
> /* create video output */<br>
> video = gst_bin_new("videobin");<br>
> convVid = gst_element_factory_make("ffmpegcolorspace","converter");<br>
> videopad = gst_element_get_static_pad(videoqueue,"sink");<br>
> videosink = gst_element_factory_make("xvimagesink","videosink");<br>
> gst_bin_add_many(GST_BIN(video),videoqueue,convVid,videosink,NULL);<br>
> gst_element_link_many(videoqueue,convVid,videosink,NULL);<br>
> gst_element_add_pad(video,gst_ghost_pad_new("sink",videopad));<br>
> gst_object_unref(videopad);<br>
> gst_bin_add(GST_BIN(pipeline),video);<br>
><br>
> /* run */<br>
> gst_element_set_state (pipeline, GST_STATE_PLAYING);<br>
> g_timeout_add (200, (GSourceFunc) cb_print_position, pipeline);<br>
> g_main_loop_run (loop);<br>
><br>
> /* cleanup */<br>
> gst_element_set_state (pipeline, GST_STATE_NULL);<br>
> gst_object_unref (GST_OBJECT (pipeline));<br>
><br>
> return 0;<br>
> }<br>
> ------------------------------------------------------------------------<br>
><br>
> ------------------------------------------------------------------------------<br>
><br>
> ------------------------------------------------------------------------<br>
><br>
> _______________________________________________<br>
> gstreamer-devel mailing list<br>
> <a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
> <a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
><br>
<br>
<br>
<br>
<br>
------------------------------<br>
<br>
------------------------------------------------------------------------------<br>
<br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
gstreamer-devel mailing list<br>
<a href="mailto:gstreamer-devel@lists.sourceforge.net">gstreamer-devel@lists.sourceforge.net</a><br>
<a href="https://lists.sourceforge.net/lists/listinfo/gstreamer-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/gstreamer-devel</a><br>
<br>
<br>
End of gstreamer-devel Digest, Vol 47, Issue 59<br>
***********************************************<br>
</blockquote><br></div><br>