# Gst-gi: read-metadata sample

**URL:** <https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613>\
**Category:** Ruby-Gnome 2\
**Created:** [February 11, 2013, 8:11pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613 "2013-02-11T20:11:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 11, 2013, 8:11pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/1 "2013-02-11T20:11:29Z")

</div>

Hi all

I am working slowly on translating  
[http://cgit.freedesktop.org/gstreamer/gstreamer/tree/tests/examples/metadata/read-metadata.cin](http://cgit.freedesktop.org/gstreamer/gstreamer/tree/tests/examples/metadata/read-metadata.cin)  
ruby.

By the way I have commited a fix on Gst::Element#pause method.

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 12, 2013, 1:35pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/2 "2013-02-12T13:35:02Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] gst-gi: read-metadata sample” on Mon, 11 Feb  
2013 20:10:59 +0100,  
Vincent C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am working slowly on translatinghttp://cgit.freedesktop.org/gstreamer/  
> gstreamer/tree/tests/examples/metadata/read-metadata.c in ruby.

Thanks.

> By the way I have commited a fix onGst::Element#pause method.

Thanks. I’ve confirmed it. (Sorry for my typo. :\<)

–  
kou

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 15, 2013, 2:33pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/3 "2013-02-15T14:33:20Z")

</div>

Hi,

In [CAENqjqc8Tnvn=removed\_email\_address@domain.invalid](mailto:CAENqjqc8Tnvn=removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] gst-gi: read-metadata sample” on Wed, 13  
Feb 2013 21:48:13 +0100,  
Vincent C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Linkingfilesrc anddecodebin elements in pipeline does not seems to be  
> enough to read a file. I get:  
> GStreamer encountered a general stream error.  
> gstbaseparse.c(3008): gst\_base\_parse\_loop (): /GstPipeline:pipeline/  
> GstDecodeBin:decodebin/GstMpegAudioParse:mpegaudioparse0:  
> streaming stopped, reason not-linked  
> I do not what step in the C sample I am missing. Can I have help on that point  
> ?

It seems that the C sample just ignores it:  
[http://cgit.freedesktop.org/gstreamer/gstreamer/tree/tests/examples/metadata/read-metadata.c#n60](http://cgit.freedesktop.org/gstreamer/gstreamer/tree/tests/examples/metadata/read-metadata.c#n60)

> Gst::Message#parse\_tag returnsa array.Can it return more than 1 list?If  
> not I believe we should change for a Gst::TagList.

Could you give me a file that has tag?

> Getter methods are not aliased (:get\_attr but no :attr)

get\_state? “get\_” isn’t removed from get\_XXX that requires  
one or more arguments. This is a rule of Ruby-GNOME2 packages.

> Methods (at least Pipeline#get\_state) can be called with more arguments than  
> the maximum number ofarguments.

I’ve added the number of arguments validation.

> Allforeachmethods should be named each.
> 
> Callingforeach on aGst::TagList object raises  
> /usr/local/lib/site\_ruby/1.9.1/gobject-introspection/loader.rb:256:in `invoke': TODO: func callback is not supported yet. (NotImplementedError) from /usr/local/lib/site_ruby/1.9.1/gobject-introspection/loader.rb:256:in `block in load\_method\_info’  
> from ./es.rb:67:in `’

I’ll check them after I get a sample file that has tags.

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 13, 2013, 9:49pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/4 "2013-02-13T21:49:00Z")

</div>

Hi

I am still figthing with this sample. The non working code can be seem  
at  
the end of the mail.  
It is a little bit complicate (class definition) for a short sample.

Here are my findings so far:

Linking filesrc and decodebin elements in pipeline does not seems to be  
enough to read a file. I get:  
GStreamer encountered a general stream error.  
gstbaseparse.c(3008): gst\_base\_parse\_loop ():  
/GstPipeline:pipeline/GstDecodeBin:decodebin/GstMpegAudioParse:mpegaudioparse0:  
streaming stopped, reason not-linked  
I do not what step in the C sample I am missing. Can I have help on that  
point ?  
I used playbin element to tested the tag part of the code.

Gst::Message#parse\_tag returns a array. Can it return more than 1 list?  
If  
not I believe we should change for a Gst::TagList.

Getter methods are not aliased (:get\_attr but no :attr)

Methods (at least Pipeline#get\_state) can be called with more arguments  
than the maximum number of arguments.

All foreach methods should be named each.

Calling foreach on a Gst::TagList object raises  
/usr/local/lib/site\_ruby/1.9.1/gobject-introspection/loader.rb:256:in  
`invoke': TODO: func callback is not supported yet. (NotImplementedError) from /usr/local/lib/site_ruby/1.9.1/gobject-introspection/loader.rb:256:in`block in load\_method\_info’  
from ./es.rb:67:in `’

code:

# encoding: utf-8

if ARGV.length \< 1  
puts "usage: #{$0} "  
exit 1  
end

require ‘gst’  
Gst.init

#TODO define Exceptions  
class Pipeline \< Gst::Pipeline  
@@new\_pipe\_per\_file=true  
#@@new\_pipe\_per\_file=false

def self.pipeline  
if @@new\_pipe\_per\_file  
new(“pipeline”)  
else  
@pipeline||=new(“pipeline”)  
end  
end

attr\_reader :location

def initialize(name)  
pipeline=super  
@source=Gst::ElementFactory.make(“filesrc”, “source”)  
raise “‘filesrc’ gstreamer plugin missing” if @source.nil?  
decodebin=Gst::ElementFactory.make(“decodebin”, “decodebin”)  
raise “‘decodebin’ gstreamer plugin missing” if decodebin.nil?  
pipeline \<\< @source \<\< decodebin  
@source \>\> decodebin  
pipeline  
end

def location=(file)  
@location=file  
@source.location=@location  
end

def stop  
super  
check\_state\_returned(super)  
end

def pause  
check\_state\_returned(super)  
end

def bus  
(@bus||=super) || raise(“Bus not found”)  
end

def tags  
tags=Gst::TagList.new  
while message=bus.pop  
#case message#Not working  
case message.type  
when Gst::MessageType::ERROR  
puts message.parse\_error  
when Gst::MessageType::EOS  
puts “EOS”  
break  
when Gst::MessageType::TAG  
tags.merge(message.parse\_tag.first, Gst::TagMergeMode::KEEP)#parse\_tag  
return a array. Why? Can it return more than 1 list. If not change  
behaviour.  
end  
end  
tags  
end

private

def check\_state\_returned(sret)  
return if sret==Gst::StateChangeReturn::SUCCESS  
if sret==Gst::StateChangeReturn::ASYNC  
#Gst::Pipeline#state not defined (fixme ?)  
return if  
get\_state(5\*Gst::SECOND).first==Gst::StateChangeReturn::SUCCESS#is  
timeout  
really the 1st arg? No check on number of arguments.  
end  
#raise “State failed to changed”#Commented to see the debug message  
end  
end

ARGV.each do |filename|  
pipeline=Pipeline.pipeline  
pipeline.stop  
pipeline.location=filename  
begin

# Decodebin will only commit to PAUSED if it actually finds a type

# otherwise the state change fails

pipeline.pause  
tags=pipeline.tags  
if tags.empty?  
puts “No metadata found for #{filename}”  
else  
#tags.each do |tag|#TODO rename for all methods foreach. Not only for  
Gst::TagList  
tags.foreach do |tag|#gobject-introspection/loader.rb:256:in `invoke’:  
TODO: func callback is not supported yet. (NotImplementedError)  
p tag  
end  
end  
rescue =\> error  
puts “#{error.message} (#{filename})”  
next  
end  
end

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 15, 2013, 7:38pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/5 "2013-02-15T19:38:35Z")

</div>

Hi

I have attached a sample mp3 file with tags and a ruby script using  
playbin  
to read the tags as I amm not able to read them with decodebin (yet). No  
tag message is sent on the bus!

As stated before Gst::TagList#foreach is not impemented.  
Gst::TagList#merge  
does not seems to work correctly

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 15, 2013, 9:17pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/6 "2013-02-15T21:17:20Z")

</div>

> I have committed a fix in  
> GObjectIntrospection::Loader#define\_module\_function. validate\_arguments was  
> called with only the 1st argument.

By the way, helloworld sample is broken. Gst::ElementFactory.make  
expects  
2 arguments. I have a patch who fix it by aliasing and redefining the  
method in a gst/elementfactory.rb. Should I push it to the git repo? Or  
should we think how to define argument default value for a given list of  
methods at GObjectIntrospection level?

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 16, 2013, 9:21am UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/7 "2013-02-16T09:21:21Z")

</div>

Hi,

In [CAENqjqc-01ZEsSR=removed\_email\_address@domain.invalid](mailto:CAENqjqc-01ZEsSR=removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] gst-gi: read-metadata sample” on Fri, 15  
Feb 2013 19:38:02 +0100,  
Vincent C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have attached a sample mp3 file with tags and a ruby script using playbin to  
> read the tags as I ammnot able to read them with decodebin (yet). No tag  
> message is sent on the bus!
> 
> As stated beforeGst::TagList#foreach is not impemented.Gst::TagList#merge  
> does not seems to work correctly

Thanks. I can confirm it with the file.  
And I’ve implemented the callback that is used by  
Gst::TagList#each. (I’ve mapped foreach to each. 🙂

And #parse\_tag returns Gst::TagList instead of an array of  
Gst::TagList.

Could you try master again?

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 17, 2013, 3:36am UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/8 "2013-02-17T03:36:48Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] gst-gi: read-metadata sample” on Sat, 16  
Feb 2013 15:04:31 +0100,  
Vincent C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Do we want to support conversion to an enumerator for object having an  
> each method ? There are very handy.  
> Would it ease the implementation to delegate loop and Proc gestion? Is too  
> hard to get an enumerator from a gobject?

I’ve implemented it. 🙂

> > And #parse\_tag returns Gst::TagList instead of an array of  
> > Gst::TagList
> 
> Works fine.

Good. 🙂

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 16, 2013, 3:05pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/9 "2013-02-16T15:05:27Z")

</div>

Hi

2013/2/16 Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > message is sent on the bus!
> > 
> > As stated before Gst::TagList#foreach is not  
> > impemented. Gst::TagList#merge  
> > does not seems to work correctly
> 
> Thanks. I can confirm it with the file.  
> And I’ve implemented the callback that is used by  
> Gst::TagList#each. (I’ve mapped foreach to each. 🙂
> 
> It works fine!  
> Do we want to support conversion to an enumerator for object having an  
> each method ? There are very handy.  
> Would it ease the implementation to delegate loop and Proc gestion? Is  
> too  
> hard to get an enumerator from a gobject?

> [0, 1].each  
> =\> #\<Enumerator: [0, 1]:each\>  
> my\_taglist..each  
> =\> gobject-introspection/loader.rb:278:in `invoke': tried to create Proc object without a block (ArgumentError) => gobject-introspection/loader.rb:278:in `block in load\_method\_info’

> And #parse\_tag returns Gst::TagList instead of an array of  
> Gst::TagList
> 
> Works fine.

> thought  
> leadership blogs to news, videos, case studies, tutorials, tech docs,  
> whitepapers, evaluation guides, and opinion stories. Check out the most  
> recent posts - join the conversation now.  
> [http://goparallel.sourceforge.net/](http://goparallel.sourceforge.net/)
> 
> * * *
> 
> ruby-gnome2-devel-en mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en](https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en)

Thanks Kou for these implementations.

---

<div class="post-metadata">

**Author:** ![coubi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c68b51/32.png) [@coubi](https://www.ruby-forum.com/u/coubi)\
**Post date:** [February 17, 2013, 5:12pm UTC](https://www.ruby-forum.com/t/gst-gi-read-metadata-sample/229613/10 "2013-02-17T17:12:31Z")

</div>

Hi all

I still can read tags with decodebin element (see read-metada.rb). Tag  
signals are never emitted. Maybe it is due to my version of Gst. Can you  
try?

> Gst.version  
> =\> [1, 0, 1, 0]

Nethertheless I am able to read tags with playbin element.  
I found the TagList#each not very convenient. It does not iterate on  
each  
tag but gives the whole list and a tag name for each iteration.  
In es.rb I redifine each method to use a hash. Original each method is  
accessible via gi\_each in case someone needs access to GLib::Value  
objects.

What do you think?  
Should I commit TagList#to\_hash and TagList#each?  
In that should I use strings or symbols for hash keys? Usually I  
prefer symbols but here the keys are tag name
