ARTICLE

GStreamer Dynamic Pads, Explained

by | Fri 3 Nov 2006

*(for an intro to GStreamer, see [my previous article](https://archivedblog.jonobacon.com/?p=750))*

You know, one thing that gets people confused in GStreamer is the idea of *Dynamic Pads*. Some elements, most notably the `decodebin` and `gnlcomposition` only have certain pads at certain times. This is because they figure out what kind of content they are processing, and apply the relevant pads where needed. This is often told to new users, but then they wonder how exactly these dynamic pads are handled.

Here is how it works, using `decodebin` as an example:

* When the pipeline is run, the `decodebin` generates a signal that says a new pad has been added. In the case of `decodebin` this is the `new-decoded-pad` signal, in the case of `gnlcomposition` this is a `pad-added` signal.
* You hook this signal up to your own callback, such as `OnDecodedPad()`.
* The signal passes your callback the pad that was added and some other stuff. You then link this pad to the next element along in the pipeline. So if your pipeline is `filesrc ! decodebin ! audioconvert ! alsasink`, the pad passed to your `OnDecodeBin()` method would be linked to the `audioconvert`.

To outline this, I have written a sample script to show how it works:

#!/usr/bin/python

import pygst
pygst.require(“0.10”)
import gst
import pygtk
import gtk

class Main:
def __init__(self):
self.pipeline = gst.Pipeline(“mypipeline”)

self.filesrc = gst.element_factory_make(“filesrc”, “source”)
self.pipeline.add(self.filesrc)
self.filesrc.set_property(“location”, “/home/jono/Desktop/jonobacon-voicesoffreedom.ogg”)

self.decode = gst.element_factory_make(“decodebin”, “decode”)
self.decode.connect(“new-decoded-pad”, self.OnDynamicPad)
self.pipeline.add(self.decode)

self.filesrc.link(self.decode)

self.convert = gst.element_factory_make(“audioconvert”, “convert”)
self.pipeline.add(self.convert)

self.sink = gst.element_factory_make(“alsasink”, “sink”)
self.pipeline.add(self.sink)

self.convert.link(self.sink)

self.pipeline.set_state(gst.STATE_PLAYING)

def OnDynamicPad(self, dbin, pad, islast):
print “OnDynamicPad Called!”
pad.link(self.convert.get_pad(“sink”))

start=Main()
gtk.main()

You can grab the script from [here](https://archivedblog.jonobacon.com/files/decodebin.py). Hope this helps some of you. 🙂

An invitation-only accelerator that develops industry-leading community engagement and growth via personalized training, coaching, and accountability...all tailored to your company's needs.

Want to read some more?

Happy Holidays

Happy Holidays

Just a quick note to wish all of you a happy, restful, and peaceful holidays, however and whoever you spend it with. Take care, folks, and I look forward to seeing you in 2015!

The Impact of One Person

The Impact of One Person

I am 35 years old and *people* never cease to surprise me. My trip home from Los Angeles today was a good example of this. It was a tortuous affair that should have been a quick hop from LA to Oakland, popping on BArt, and then getting home for a cup of tea and an...

Feedback Requested: Great Examples of Community

Feedback Requested: Great Examples of Community

Folks, I need to ask for some help. Like many, I have some go-to examples of great communities. This includes Wikipedia, OpenStreetmap, Ubuntu, Debian, Linux, and others. Many of these are software related, many of them are Open Source. I would like to ask your...

Ubuntu Governance Reboot: Five Proposals

Ubuntu Governance Reboot: Five Proposals

Sorry, this is *long*, but hang in there. A little while back I wrote [a blog post](https://archivedblog.jonobacon.com/2014/11/14/ubuntu-governance-reboot/) that seemed to inspire some people and ruffle the feathers of some others. It was designed as a...

Ubuntu Governance: Reboot?

Ubuntu Governance: Reboot?

For many years Ubuntu has had a comprehensive governance structure. At the top of the tree are the Community Council (community policy) and the Technical Board (technical policy). Below those boards are sub-councils such as the IRC, Forum, and LoCo councils, and...

Dealing With Disrespect: The Video

Dealing With Disrespect: The Video

A while back I wrote and released a free e-book called [Dealing With Disrespect](https://www.dealingwithdisrespect.com/). It is a book that provides a short, simple to read, free guide for handling personalized, mean-spirited, disrespectful, and in some cases,...