# Gstreamer: linking playbin2

**URL:** <https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773>\
**Category:** Ruby-Gnome 2\
**Created:** [March 21, 2011, 2:12pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773 "2011-03-21T14:12:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 21, 2011, 2:12pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/1 "2011-03-21T14:12:24Z")

</div>

hello,

i’m trying to understand how to connect ‘playbin2’ to other elements.  
i can connect a pipeline with the ‘mad’ decoder to the  
‘equalizer10-bands’ plugin like this:  
…  
@pipeline = Gst::Pipeline.new  
filesrc = Gst::ElementFactory.make(“filesrc”)  
filesrc.location = “./test.mp3”  
decoder = Gst::ElementFactory.make(“mad”)  
audioconvert=Gst::ElementFactory.make(“audioconvert”)  
sink = Gst::ElementFactory.make(“autoaudiosink”)  
@plug = Gst::ElementFactory.make(“equalizer-10bands”)  
@pipeline.add(filesrc, decoder, audioconvert, @plug, sink)

filesrc \>\> decoder \>\> audioconvert \>\> @plug \>\> sink  
@pipeline.ready  
@pipeline.play  
…

everything works nicely, and creating a simple gui i can control the  
eq with no problems.

i understand that the ‘playbin2’ element is quite different, in that  
it is a pipeline in and of itself. from what i’ve read (  
[http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-playbin2.html](http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-playbin2.html)  
) you must watch the bus for playbin2’s pads to be created, and then  
connect them.

i get plenty of messages watching the bus like this:  
…  
pipeline = Gst::ElementFactory.make(“playbin2”)  
audio = “/home/jk/ruby/audio tests/test.flac”  
pipeline.uri= GLib.filename\_to\_uri(audio)  
bus = pipeline.bus  
bus.add\_watch{|bus, message|  
puts message.type.name  
puts message.source  
puts message.structure  
puts  
true}  
…

it looks like lots of elements get automatically created and linked  
along the way, like the ‘audioconvert’ and ‘autoaudiosink’ elements that  
i create and link manually in the first example. i also see with “puts  
pipeline.sources” that it is the Gst::ElementURIDecodeBin that seems to  
be doing the decoding of mp3, ogg, wav, and flac files.

my question is, how / when / where to connect playbin2 to the  
equalizer? i imagine it is a matter of watching the bus for a specific  
event, and then linking elements at that point. what event in  
particular am i looking for? when i see it, how do i link things  
correctly?

thanks in advance for any ideas,

-j

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [March 22, 2011, 1:21pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/2 "2011-03-22T13:21:24Z")

</div>

hello,

well, i realized i was on the wrong track… reading more, and  
looking at this thread -  
[http://gstreamer-devel.966125.n4.nabble.com/level-element-in-playbin2-td989801.html](http://gstreamer-devel.966125.n4.nabble.com/level-element-in-playbin2-td989801.html)

- i figure that the way to link playbin2 is to create a bin with all the  
elements you want in it, link them, then create a ghost pad, and set  
that as the audiosink property of the playbin.

bin = Gst::Bin.new()  
conv = Gst::ElementFactory.make(“audioconvert”)  
@eq = Gst::ElementFactory.make(“equalizer-10bands”)  
sink = Gst::ElementFactory.make(“autoaudiosink”)

bin.add(conv)  
bin.add(@eq)  
bin.add(sink)

conv \>\> @eq \>\> sink

pipeline \>\> bin ## this plays, but eq does not function

# pipeline.add(bin) ## this gives no errors, but no sound either

anyone know of another or better way to make this work?

thanks  
-j

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [March 22, 2011, 4:18pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/3 "2011-03-22T16:18:35Z")

</div>

2011/3/22 J. K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> hello,

Hi

> easy enough, though unfortunately it seems like this is for the newest  
> gtk2 and/or gstreamer, because checking my Gst::Bin.instance\_methods,  
> shows no “#add\_ghost\_pad” as shown here -  
> [http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gst-bins-ghost-pads](http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gst-bins-ghost-pads) …

Did you try Gst::Bin#add\_pad ? The doc are quite old…

–  
Vincent C.

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [March 23, 2011, 4:06pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/4 "2011-03-23T16:06:56Z")

</div>

hello vincent -

i was looking at the #add\_pad method as well, and i’ve been playing  
around with it, but without any results as of yet.

#add\_pad takes a hash as an argument, where you set the pad name and  
direction (src or sink.)

i’ve tried this so far:

###################  
pipeline = Gst::ElementFactory.make(“playbin2”)  
audio = “/home/jk/ruby/audio tests/test.mp3”  
pipeline.uri= GLib.filename\_to\_uri(audio)

bin = Gst::Bin.new()  
conv = Gst::ElementFactory.make(“audioconvert”)  
@eq = Gst::ElementFactory.make(“equalizer-10bands”)  
autosink = Gst::ElementFactory.make(“autoaudiosink”)

pad1 = Gst::Pad.new({“direction” =\> Gst::Pad::SRC, “name” =\> “src”})  
pad2 = Gst::Pad.new({“direction” =\> Gst::Pad::SINK, “name” =\> “sink”})

pipeline.add\_pad(pad1)  
bin.add\_pad(pad2)

srcpad = pipeline.get\_pad(“src”)  
binpad = bin.get\_pad(“sink”)

#( this bit above stays the same, then i experiment with the following:  
)

# not using bin

conv \>\> @eq \>\> autosink  
srcpad \>\> conv.get\_pad(“sink”)  
pipeline.play #(this plays, but eq does not function)  
…

# using bin

bin.add(conv)  
bin.add(@eq)  
bin.add(autosink)  
conv \>\> @eq \>\> autosink  
srcpad \>\> binpad  
pipeline.play #(this also plays, but still no eq)  
############################

not sure, still fiddling with it. it seems that maybe the  
‘autoaudiosink’ is not really what’s producing the sound output, because  
it seems properly linked to the converter and eq.

watching the bus for element messages, i see that an ‘autoaudiosink’  
element is created automatically by playbin2 (as well as many others,)  
maybe this is what’s outputting the sound, and i need to find a way to  
link to it… dunno.

going to keep working at it, if i find anything i’ll let you know. if  
you think of anything else, please do the same…

thanks,

-j

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [March 24, 2011, 11:39pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/5 "2011-03-24T23:39:43Z")

</div>

Vincent C. wrote in post #988739:

> 2011/3/22 J. K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > hello,
> 
> Hi
> 
> > easy enough, though unfortunately it seems like this is for the newest  
> > gtk2 and/or gstreamer, because checking my Gst::Bin.instance\_methods,  
> > shows no “#add\_ghost\_pad” as shown here -  
> > [http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gst-bins-ghost-pads](http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gst-bins-ghost-pads) …
> 
> Did you try Gst::Bin#add\_pad ? The doc are quite old…

Does anyone know if ruby-gstreamer is still being maintained? Most of  
the commits seem to be 2008. I don’t think ghost pads are particularly  
new to gstreamer, though I’ve been mostly working with in C and was  
hoping to migrate a codebase to ruby.

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [March 25, 2011, 7:33pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/6 "2011-03-25T19:33:34Z")

</div>

2011/3/24 Louis S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > 
> > 
> > Did you try Gst::Bin#add\_pad ? The doc are quite old…
> 
> Does anyone know if ruby-gstreamer is still being maintained? Most of  
> the commits seem to be 2008. I don’t think ghost pads are particularly  
> new to gstreamer, though I’ve been mostly working with in C and was  
> hoping to migrate a codebase to ruby.

ruby-gstreamer is still maintained even if there are few commits . I  
pretty sure ghost pad can be used. Documentations on ruby-gstreamer  
are generally out of dated !

Unfortunatelly I have not yet added plugins elements to a playbin . I  
guess  
[http://gstreamer-devel.966125.n4.nabble.com/level-element-in-playbin2-td989801.html](http://gstreamer-devel.966125.n4.nabble.com/level-element-in-playbin2-td989801.html)  
can be adapted to the ruby case.

–  
Vincent C.

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [March 25, 2011, 2:16pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/7 "2011-03-25T14:16:33Z")

</div>

Louis S. wrote in post #989095:

> Vincent C. wrote in post #988739:
> 
> > Did you try Gst::Bin#add\_pad ? The doc are quite old…
> 
> Does anyone know if ruby-gstreamer is still being maintained? Most of  
> the commits seem to be 2008.

hi Louis,

unfortunately all the docs are very old. Vincent has provided some  
nice patches to gtk2 recently which implement gstreamer functions, but  
aside from that, it doesn’t seem that there’s much going on with  
ruby-gstreamer in terms of active development or maintenance.  
it’s a shame, as ruby-gst is (as far as i can tell) the best  
all-around audio library for ruby. i guess there aren’t that many of us  
using ruby for audio applications.  
linking playbin2 still has me stumped (though honestly i haven’t  
fooled with it much more since the last post.) if and when i get it  
figured out i’ll certainly post the solution here.

-j

---

<div class="post-metadata">

**Author:** ![j\_k](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e9bcb4/32.png) [@j\_k](https://www.ruby-forum.com/u/j_k)\
**Post date:** [May 18, 2012, 3:07pm UTC](https://www.ruby-forum.com/t/gstreamer-linking-playbin2/204773/8 "2012-05-18T15:07:40Z")

</div>

> linking playbin2 still has me stumped (though honestly i haven’t  
> fooled with it much more since the last post.) if and when i get it  
> figured out i’ll certainly post the solution here.

I have this working with this code:

```auto
    #make the playbin
    @playbin = Gst::ElementFactory.make("playbin2")

    bin = Gst::Bin.new()
    @eq = Gst::ElementFactory.make("equalizer-10bands")
    autosink = Gst::ElementFactory.make("autoaudiosink")

    bin.add(@eq)
    bin.add(autosink)
    @eq >> autosink

    eqpad = @eq.get_pad("sink")
    gpad = Gst::GhostPad.new("gpad", eqpad) # playbin2 requires a 
ghost pad
    bin.add_pad(gpad)

    @playbin.audio_sink = bin
```

In fact, there is a complete and nice ruby Player class at:  
[http://www.jezra.net/blog/Audio\_playing\_class\_in\_Ruby\_with\_Gstreamer](http://www.jezra.net/blog/Audio_playing_class_in_Ruby_with_Gstreamer)

I can’t get audio tags to work though.
