title: Gstreamer linking decodebin2 to autovideosink
body: <p>I'm trying to add some processing logic to a program that chugs away on a local video file, but I'm having some trouble understanding how to translate the following (successfull) gst-launch command into code (and supply it with a "pad-added" callback):</p>
  
  <p><code>gst-launch filesrc location=/path/to/my/video.avi ! decodebin2 ! autovideosink</code></p>
  
  <p>I've tried my hand at gstreamer's <a href="http://docs.gstreamer.com/display/GstSDK/Basic+tutorial+3%3a+Dynamic+pipelines" rel="nofollow">basic-tutorial-3</a>, using <code>decodebin2</code> in place of <code>audioconvert</code>:</p>
  
  <pre><code>data.source = gst_element_factory_make("filesrc", "source");
  data.convert = gst_element_factory_make("decodebin2", "uridecoder");
  data.sink = gst_element_factory_make("autovideosink", "autodetect");
  </code></pre>
  
  <p>However, I am never able to link <code>data.convert</code> to <code>data.sink</code>, as it is outlined in the example; the <code>gst_element_link(data.convert, data.sink)</code> always fails.  I suspect there's some special treatment for <code>decodebin2</code>.  Some gstreamer users have metioned <a href="http://gstreamer-devel.966125.n4.nabble.com/Using-a-Bin-td2997320.html" rel="nofollow">using ghostpads and seperate bins</a>, which after a swift attempt, also yielded no success:</p>
  
  <pre><code>data.bin = gst_bin_new("processing-bin");
  gst_bin_add_many(GST_BIN(data.bin), data.decoder, data.sink, NULL);
  gst_element_add_pad(data.bin, 
                      gst_ghost_pad_new("bin_sink",
                                        gst_element_get_static_pad(data.decoder,"sink")));
  </code></pre>
  
  <p>I'm a little confused as how to continue debugging.  Does anyone else have any pointers?</p>
  
  <p>Here is a boiled down gist of the current code: (<a href="https://gist.github.com/3266690" rel="nofollow">gist</a>)</p>
  
  <p>====</p>
  
  <p>Update: My callback is now firing, I think it was because I had an incorrect filename for the filesrc location (whoops)  </p>
  
  <p>Now, after following the advice below, I am able to confirm that I'm getting audio and video caps types and check against them in the pad-added callback.  However, I'm now getting the following "not-linked" error after one frame of pad processing:</p>
  
  <pre><code>Debugging information: gstavidemux.c(5187): gst_avi_demux_loop (): /GstPipeline:gstreamer-test/GstBin:processing-bin/GstDecodeBin2:uridecoder/GstAviDemux:avidemux0:
  streaming stopped, reason not-linked
  </code></pre>