Forum: Ruby-Gnome 2 gstreamer: linking playbin2

7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-03-21 14:12
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/gstreame...
)  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
7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-03-22 13:21
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-...
- 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...   ...

  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
C4a836af7263f84a4f7cc91ed6f3ae77?d=identicon&s=25 Vincent Carmona (vinc-mai)
on 2011-03-22 16:18
(Received via mailing list)
2011/3/22 J. K. <ruby-forum-incoming@andreas-s.net>:
> 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...  ...
>
Did you try Gst::Bin#add_pad ? The doc are quite old...



--
Vincent Carmona
7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-03-23 16:06
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
3832bcc4b566196e67c5ca98ec1bdda1?d=identicon&s=25 Louis S. (louis_s)
on 2011-03-24 23:39
Vincent Carmona wrote in post #988739:
> 2011/3/22 J. K. <ruby-forum-incoming@andreas-s.net>:
>> 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...  ...
>>
> 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.
5e3ddca8ea910cea06245c7b3c38007a?d=identicon&s=25 jake kaiden (lljk)
on 2011-03-25 14:16
Louis S. wrote in post #989095:
> Vincent Carmona 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
C4a836af7263f84a4f7cc91ed6f3ae77?d=identicon&s=25 Vincent Carmona (vinc-mai)
on 2011-03-25 19:33
(Received via mailing list)
2011/3/24 Louis S. <ruby-forum-incoming@andreas-s.net>:
>>>
>> 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-...
can be adapted to the ruby case.

--
Vincent Carmona
5e2910753aa8d0b3a4060ccd0fd33b50?d=identicon&s=25 Michael K. (michael_k31)
on 2012-05-18 15:07
>   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:

[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
[/code]

In fact, there is a complete and nice ruby Player class at:
http://www.jezra.net/blog/Audio_playing_class_in_R...

I can't get audio tags to work though.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.