# Gstreamer "level" plugin

**URL:** <https://www.ruby-forum.com/t/gstreamer-level-plugin/204731>\
**Category:** Ruby-Gnome 2\
**Created:** [March 19, 2011, 10:16pm UTC](https://www.ruby-forum.com/t/gstreamer-level-plugin/204731 "2011-03-19T22:16:12Z")\
**Posts on this page:** 4\
**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 19, 2011, 10:16pm UTC](https://www.ruby-forum.com/t/gstreamer-level-plugin/204731/1 "2011-03-19T22:16:12Z")

</div>

hello all,

i would like to implement a peak db meter through gstreamer (thanks to  
marcin for posting his meter module) - and i’m wondering about the use  
of the “level” plugin.

i see from the gstreamer documentation (  
[level](http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-level.html))  
that the plugin emits a message called “level” at a given interval…  
unfortunately i really can’t make heads nor tails of the documentation’s  
example as it’s written in C (i believe,) and i’m just a simple ruby  
guy…

anyone have experience with this plugin and how to catch the messages?  
i’ve watched my bus for messages after creating the plugin and adding it  
to my pipeline, but don’t see any of type “level”.

plugin.messages? returns true, and plugin.get\_state shows it playing,  
so i assume it is correctly added to the pipeline, and sending messages

- i just can’t figure out how to catch and parse them.

here’s a code snippet:  
…  
@pipeline = Gst::ElementFactory.make(“playbin2”)  
@plugin = Gst::ElementFactory.make(“level”)  
@pipeline.add(@plugin)  
bus = @pipeline.bus  
bus.add\_watch {|bus, message|p message; true}

… truncated

then i play the pipeline - i get state changed, element, stream status,  
and tag messages, but nothing that looks like “level” being regularly  
emitted.

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 20, 2011, 2:22pm UTC](https://www.ruby-forum.com/t/gstreamer-level-plugin/204731/2 "2011-03-20T14:22:38Z")

</div>

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

> hello all,

Hi

> anyone have experience with this plugin and how to catch the messages?  
> i’ve watched my bus for messages after creating the plugin and adding it  
> to my pipeline, but don’t see any of type “level”.

The message\_handler function in C sample code shows that level message  
are GST\_MESSAGE\_ELEMENT kind ones. Then infos are parsed from the  
structure retrieved from the message.

Here is the same sample in ruby :

require ‘gst’

audiotestsrc=Gst::ElementFactory.make(“audiotestsrc”)  
audioconvert=Gst::ElementFactory.make(“audioconvert”)  
level=Gst::ElementFactory.make(“level”)  
fakesink=Gst::ElementFactory.make(“fakesink”)  
pipeline=Gst::Pipeline.new  
pipeline.add(audiotestsrc, audioconvert, level, fakesink)  
#pipeline.add(audiotestsrc, audioconvert, fakesink)  
audiotestsrc \>\> audioconvert \>\> level \>\> fakesink  
pipeline.ready  
pipeline.bus.add\_watch {|bus, message|  
case message  
when Gst::MessageError  
puts message.parse  
when Gst::MessageElement  
struc=message.structure  
if struc.name==“level”  
p struc[“rms”][0]  
struc.each{|key, val| puts “#{key}=#{val}”}  
end  
end  
true  
}

mainloop=GLib::MainLoop.new  
pipeline.play  
mainloop.run

–  
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 20, 2011, 5:14pm UTC](https://www.ruby-forum.com/t/gstreamer-level-plugin/204731/3 "2011-03-20T17:14:57Z")

</div>

vincent -

i saw that the message was of element type, but didn’t know how to  
catch it - greatly appreciate the translation to ruby, i’m getting the  
hang of C, but it’s still a bit tricky for me to translate from C to  
ruby.

going to play around and see what i come up with…

thanks again,

-jk

---

<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 20, 2011, 6:49pm UTC](https://www.ruby-forum.com/t/gstreamer-level-plugin/204731/4 "2011-03-20T18:49:31Z")

</div>

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

> vincent -
> 
> i saw that the message was of element type, but didn’t know how to  
> catch it - greatly appreciate the translation to ruby, i’m getting the  
> hang of C, but it’s still a bit tricky for me to translate from C to  
> ruby.
> 
> going to play around and see what i come up with…
> 
> thanks again,

You are welcome.

> [Best Open Source Mac Front-Ends 2023](http://p.sf.net/sfu/internap-sfd2d)
> 
> * * *
> 
> ruby-gnome2-devel-en mailing list  
> removed\_email\_address@domain.invalid  
> [ruby-gnome2-devel-en List Signup and Options](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)

–  
Vincent C.
