Gstreamer: linking playbin2

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
) 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

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

  • 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.

    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

    seems like until i manage to figure out a way to update everything (a
    nightmare i’m having,) i’ll be unable to implement any plugins with
    playbin2. sad…

    i’ve tried this in lieu of #add_ghost_pad :

    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”)
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

2011/3/22 J. K. [email protected]:

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

Did you try Gst::Bin#add_pad ? The doc are quite old…


Vincent C.

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

Vincent C. wrote in post #988739:

2011/3/22 J. K. [email protected]:

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

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.

2011/3/24 Louis S. [email protected]:

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
can be adapted to the ruby case.


Vincent C.

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

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:

    #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

I can’t get audio tags to work though.