<br>you should be adding respective queue before the audio and video decoder (essentially after the demuxer), and in the on_pad_added connect to the sinkpad of those queue.<br><br><div class="gmail_quote">On Thu, Nov 26, 2009 at 9:19 PM, Sedji Gaouaou <span dir="ltr">&lt;<a href="mailto:sedji.gaouaou@atmel.com">sedji.gaouaou@atmel.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi all,<br>
<br>
I am a newbe with gstreamer, and I am currently writting a application<br>
which will play a .avi file.<br>
But I have a problem when trying to play both audio and video.<br>
<br>
Here is my application:<br>
In the main, if I comment the audio(gst_bin_add_many and<br>
gst_element_link_many) then the video works fine. Same thing appends if<br>
I comment the video part then the audio play just fine, but when trying<br>
both the video doesn&#39;t even start??<br>
<br>
Am I missing something?<br>
<br>
Regards,<br>
Sedji<br>
<br>
<br>
#include &lt;gst/gst.h&gt;<br>
#include &lt;glib.h&gt;<br>
#include &lt;string.h&gt;<br>
<br>
<br>
static GstElement *source, *demuxer, *vdqueue, *adqueue, *vdsink,<br>
*adsink, *decvd, *decad;<br>
<br>
void on_pad_added (GstElement *element, GstPad *pad)<br>
{<br>
        g_debug (&quot;Signal: pad-added&quot;);<br>
        GstCaps *caps;<br>
        GstStructure *str;<br>
<br>
        caps = gst_pad_get_caps (pad);<br>
        g_assert (caps != NULL);<br>
        str = gst_caps_get_structure (caps, 0);<br>
        g_assert (str != NULL);<br>
<br>
        if (g_strrstr (gst_structure_get_name (str), &quot;video&quot;)) {<br>
                g_debug (&quot;Linking video pad to dec_vd&quot;);<br>
                // Link it actually<br>
                GstPad *targetsink = gst_element_get_pad (decvd, &quot;sink&quot;);<br>
                g_assert (targetsink != NULL);<br>
                gst_pad_link (pad, targetsink);<br>
                gst_object_unref (targetsink);<br>
        }<br>
<br>
        if (g_strrstr (gst_structure_get_name (str), &quot;audio&quot;)) {<br>
                g_debug (&quot;Linking audio pad to dec_ad&quot;);<br>
                // Link it actually<br>
                GstPad *targetsink = gst_element_get_pad (decad, &quot;sink&quot;);<br>
                g_assert (targetsink != NULL);<br>
                gst_pad_link (pad, targetsink);<br>
                gst_object_unref (targetsink);<br>
        }<br>
<br>
        gst_caps_unref (caps);<br>
}<br>
<br>
static gboolean<br>
bus_call (GstBus     *bus,<br>
           GstMessage *msg,<br>
           gpointer    data)<br>
{<br>
        GMainLoop *loop = (GMainLoop *) data;<br>
<br>
        switch (GST_MESSAGE_TYPE (msg)) {<br>
                case GST_MESSAGE_EOS:<br>
                        g_print (&quot;End of stream\n&quot;);<br>
                        g_main_loop_quit (loop);<br>
                        break;<br>
                case GST_MESSAGE_ERROR: {<br>
                        gchar  *debug;<br>
                        GError *error;<br>
<br>
                        gst_message_parse_error (msg, &amp;error, &amp;debug);<br>
                        g_free (debug);<br>
<br>
                        g_printerr (&quot;Error: %s\n&quot;, error-&gt;message);<br>
                        g_error_free (error);<br>
<br>
                        g_main_loop_quit (loop);<br>
                        break;<br>
                }<br>
                default:<br>
                        break;<br>
        }<br>
<br>
        return TRUE;<br>
}<br>
<br>
int<br>
main (int   argc,<br>
       char *argv[])<br>
{<br>
        GMainLoop *loop;<br>
<br>
        GstElement *pipeline;<br>
        GstBus *bus;<br>
<br>
        /* Initialisation */<br>
        gst_init (&amp;argc, &amp;argv);<br>
<br>
        loop = g_main_loop_new (NULL, FALSE);<br>
<br>
<br>
        /* Check input arguments */<br>
        if (argc != 2) {<br>
                g_printerr (&quot;Usage: %s &lt;Video H264 filename&gt;\n&quot;, argv[0]);<br>
                return -1;<br>
        }<br>
<br>
        /* Create gstreamer elements */<br>
        pipeline        = gst_pipeline_new (&quot;media-player&quot;);<br>
        source          = gst_element_factory_make (&quot;filesrc&quot;,&quot;file-source&quot;);<br>
        demuxer         = gst_element_factory_make (&quot;avidemux&quot;,&quot;avi-demuxer&quot;);<br>
        decvd           = gst_element_factory_make (&quot;x170&quot;, &quot;video-decoder&quot;);<br>
        decad           = gst_element_factory_make (&quot;mad&quot;, &quot;mp3-decoder&quot;);<br>
        vdsink          = gst_element_factory_make (&quot;ximagesink&quot;, &quot;video-sink&quot;);<br>
        vdqueue         = gst_element_factory_make (&quot;multiqueue&quot;, &quot;video-queue&quot;);<br>
        adqueue         = gst_element_factory_make (&quot;multiqueue&quot;, &quot;audio-queue&quot;);<br>
        adsink          = gst_element_factory_make (&quot;osssink&quot;, &quot;audio-sink&quot;);<br>
<br>
        /* if needed to be set to MPEG4(value 4), default is AUTO */<br>
        //g_object_set (decvd, &quot;codec&quot;, 4, NULL);<br>
        /* output format: RGB16 (i.e 2) */<br>
        g_object_set (decvd, &quot;output&quot;, 2, NULL);<br>
        /* Scaling value */<br>
        g_object_set (decvd, &quot;scaling&quot;, 1.0, NULL);<br>
        /* Threshold of the VDEC to sync audio and video */<br>
        g_object_set (decvd, &quot;inbuf-thresh&quot;, 100000, NULL);<br>
<br>
        if (!pipeline || !source || !demuxer || !decvd || !vdsink || !vdqueue<br>
|| !decad || !adqueue || !adsink) {<br>
                g_printerr (&quot;One element could not be created. Exiting.\n&quot;);<br>
                return -1;<br>
        }<br>
<br>
        /* Set up the pipeline */<br>
<br>
        /* we set the input filename to the source element */<br>
        g_object_set (G_OBJECT (source), &quot;location&quot;, argv[1], NULL);<br>
<br>
        /* we add a message handler */<br>
        bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));<br>
        gst_bus_add_watch (bus, bus_call, loop);<br>
        gst_object_unref (bus);<br>
<br>
        /* we add all elements into the pipeline */<br>
        /* file-source | avi-demuxer |  x170-decoder | ximagesink<br>
         *                           | mad | audioconvert | osssink*/<br>
<br>
        /* demux only */<br>
        gst_bin_add_many (GST_BIN (pipeline),<br>
                     source, demuxer, NULL);<br>
<br>
        /* video only */<br>
        gst_bin_add_many (GST_BIN (pipeline),<br>
                     decvd, vdqueue, vdsink, NULL);<br>
<br>
        /* audio only */<br>
        gst_bin_add_many (GST_BIN (pipeline),<br>
                     decad, adqueue, adsink, NULL);<br>
<br>
        /* we link the elements together */<br>
        /* file-source -&gt; demuxer ~&gt; decoder -&gt; image sink */<br>
        gst_element_link (source, demuxer);<br>
<br>
        if(!gst_element_link_many(decvd, vdqueue, vdsink, NULL)) {<br>
                printf(&quot;problem linking video elements!!!!!\n&quot;);<br>
                return FALSE;<br>
        }<br>
<br>
        if(!gst_element_link_many( decad, adqueue, adsink, NULL)) {<br>
                printf(&quot;problem linking audio elements!!!!!\n&quot;);<br>
                return FALSE;<br>
        }<br>
<br>
        gst_element_link_pads (demuxer, &quot;video&quot;, vdqueue, &quot;sink&quot;);<br>
        gst_element_link_pads (demuxer, &quot;audio&quot;, adqueue, &quot;sink&quot;);<br>
<br>
        g_signal_connect (demuxer, &quot;pad-added&quot;, G_CALLBACK (on_pad_added), NULL);<br>
<br>
        /* note that the demuxer will be linked to the decoder dynamically.<br>
        The reason is that Ogg may contain various streams (for example<br>
        audio and video). The source pad(s) will be created at run time,<br>
        by the demuxer when it detects the amount and nature of streams.<br>
        Therefore we connect a callback function which will be executed<br>
        when the &quot;pad-added&quot; is emitted.*/<br>
<br>
        /* Set the pipeline to &quot;playing&quot; state*/<br>
        g_print (&quot;Now playing: %s\n&quot;, argv[1]);<br>
        gst_element_set_state (pipeline, GST_STATE_PLAYING);<br>
<br>
<br>
        /* Iterate */<br>
        g_print (&quot;Running...\n&quot;);<br>
        g_main_loop_run (loop);<br>
<br>
<br>
        /* Out of the main loop, clean up nicely */<br>
        g_print (&quot;Returned, stopping playback\n&quot;);<br>
        gst_element_set_state (pipeline, GST_STATE_NULL);<br>
<br>
        g_print (&quot;Deleting pipeline\n&quot;);<br>
        gst_object_unref (GST_OBJECT (pipeline));<br>
<br>
        return 0;<br>
}<br>
<br>
<br>
------------------------------------------------------------------------------<br>
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day<br>
trial. Simplify your report design, integration and deployment - and focus on<br>
what you do best, core application coding. Discover what&#39;s new with<br>
Crystal Reports now.  <a href="http://p.sf.net/sfu/bobj-july" target="_blank">http://p.sf.net/sfu/bobj-july</a><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>
</blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.linkedin.com/in/kapilagrawal">http://www.linkedin.com/in/kapilagrawal</a><br>