[gst-devel] why/when are state changes needed in dynamically modified pipelines?

Daniel Lenski dlenski at gmail.com
Wed Sep 12 15:47:47 CEST 2007


Okay... sorry to keep up the annoying questions everyone :-)  I've
(finally) narrowed down the  bug in my auto-transcoder to the
following question:

When and why are state changes needed in dynamic pipeline creation?

In the GStreamer manual (this page:
http://gstreamer.freedesktop.org/data/doc/gstreamer/head/manual/html/section-dynamic.html),
the sample code dynamically adds an element to the pipeline.  It sets
the element's state to READY immediately before linking it to the
previously existing element, and then sets it to PAUSED immediately
afterwards:

  if (sinkelement != audiosink) {
    gst_bin_add (GST_BIN (pipeline), sinkelement);
    gst_element_set_state (sinkelement, GST_STATE_READY);
  }
  pad = gst_element_get_pad (sinkelement, padname);
  gst_pad_link (srcpad, pad);
  if (sinkelement != audiosink) {
    gst_element_set_state (sinkelement, GST_STATE_PAUSED);
  }

Why is this necessary?

I've found it only (seems to be) needed with the decodebin element,
and then only sometimes... for some stream types things apparently
work without it.  In my python code I do this:

  # bin contains a typefind already... we're in it's have-type handler

  decodebin = gst.element_factory_make('decodebin')
  bin.add(decodebin)
  convert = gst.element_factory_make('audioconvert')
  bin.add(convert)
  # add a bunch more elements after the decodebin...

  # set up callback to dynamically link decodebin to the following element
  decodebin.connect('new-decoded-pad', self.new_decoded_pad,
convert.get_pad('sink'))

  bin.set_state(gst.STATE_READY) # put the bin, with new elements,
into READY state
  bin.typefind.link(decodebin) # link the typefind to the new decodebin element
  gst.element_link_many(convert, ...) # link the rest of the elements
together...
  self.set_state(gst.STATE_PAUSED) # put the bin into PAUSED state

So, I see that I can make my code work reliably by linking newly added
elements only after having put them into the READY state.  But I still
don't understand the rationale for this.  The manual doesn't really
explain when state changes are needed for dynamically modified
pipeines.  Can someone explain to me how to figure this out??

Thanks!

Dan Lenski




More information about the gstreamer-devel mailing list