Gstreamer-gi

Hello

I tried to port to port
http://cgit.freedesktop.org/gstreamer/gstreamer/tree/tests/examples/helloworld/helloworld.c
to
ruby.

My firsts remarks are :

Gst.init method crashes if called more than
once. gobject-introspection/loader.rb is redefining the method (line
74).

Default argument for Gst.init method is ARGV. Why is that? I would
rather
use nil or empty string The arguments for the current ruby script have
usually nothing to do with gst.

ARGV is chaged by Gst.init method. It caused me some troubles.

A lot of constant are not defined by introspection (e.g. VERSION,
Message::ERROR)

Methods returning boolean does not end by ?.

The code I used with some more remark.
unless uri=ARGV[0]
STDERR.puts “usage: #{$0} uri”
exit 1
end

require ‘gst’
#p ARGV
Gst.init#TODO put it in gst.rb
#p Gst.init#2nd call crash the app
#p ARGV#Gst.init change ARGV!
Gst::Message::ERROR=1<<1#Not defined!
Gst::Message::EOS=1<<0

loop=GLib::MainLoop.new(nil, false)
playbin=Gst::ElementFactory.make(‘playbin’)#TODO test return
playbin.bus.add_watch(1){|_, message|#Need an argument!
#p message.parse#no more magic parse based on class!
case message.type
when Gst::Message::EOS
loop.quit
when Gst::Message::ERROR
p message.parse_error#crash
else
p message.type
end
true
}

uri=Gst.filename_to_uri(uri) unless Gst.uri_is_valid(uri)#use
uri_is_valid?
for method name
playbin.uri=uri
playbin.volume=0.2
#playbin.play#No more convenient methods
playbin.state=Gst::State::PLAYING
at_exit{p ‘Exit. TODO: cleaning’}
loop.run

in lib/gst.rb file

module Gst
class << self
@initialized = false
def init(argv=ARGV)
return if @initialized

At that point @initialized is nil and not false !

module Gst
@initialized = false
class << self
def init(argv=ARGV)
return if @initialized

seems to do what was expected but I am not sure why.

Except for points 2 and 3 I have at the moment no idea on how to improve
the code. gobject-introspection is black magic !

Hi,

In CAENqjqcu6X1pFYGnkr9WBy8ojirH=removed_email_address@domain.invalid
“[ruby-gnome2-devel-en] Gstreamer-gi” on Sat, 9 Feb 2013 19:01:45
+0100,
Vincent C. [email protected] wrote:

I tried to port to port

http://cgit.freedesktop.org/gstreamer/gstreamer/tree/tests/examples/helloworld/helloworld.c

to
ruby.

Thanks for trying it!
A Japanese also working on it. And some problems were
fixed. He and I are working on gstreamer-gi/ directory:
https://github.com/ruby-gnome2/ruby-gnome2/tree/master/gstreamer-gi

You can use it by the following commands:
% git clone GitHub - ruby-gnome/ruby-gnome: A set of bindings for the GNOME libraries to use from Ruby.
% cd ruby-gnome2
[ruby-gnome2]% cd glib2
[glib2]% ruby extconf.rb
[glib2]% make
[glib2]% cd …/gobject-introspection
[gobject-introspection]% ruby extconf.rb
[gobject-introspection]% make
[gobject-introspection]% cd …/gstreamer-gi
[gstreamer-gi]% ruby extconf.rb
[gstreamer-gi]% make
[gstreamer-gi]% ruby
-I …/glib2/lib
-I …/glib2/ext/glib2
-I …/gobject-introspection/lib
-I …/gobject-introspection/ext/gobject-introspection
helloworld.rb

My firsts remarks are :

Gst.init method crashes if called more than
once. gobject-introspection/loader.rb is redefining the method (line 74).

Thanks. I’ve fixed it:
gstreamer-gi: don't override Gst.init · ruby-gnome/ruby-gnome@5dfad0a · GitHub

Default argument for Gst.init method is ARGV. Why is that? I would rather
use nil or empty string$B!D(B The arguments for the current ruby script have
usually nothing to do with gst.

Umm… I thought “–gst-debug-level=3” like argument may be
useful…

You can pass empty arguments by:

Gst.init([])

ARGV is chaged by Gst.init method. It caused me some troubles.

I’ve fixed it:
gstreamer-gi: don't add $0 to arguments · ruby-gnome/ruby-gnome@f854789 · GitHub

A lot of constant are not defined by introspection (e.g. VERSION,
Message::ERROR$B!D(B)

It had been fixed in master. Could you try master?

VERSION → Gst.version
Message::ERROR → Gst::MessageType::ERROR

Methods returning boolean does not end by ?.

It is Gst.uri_is_valid, isn’t it?

I’ve fixed it:
gi: use Rubyish method name for constructor and function · ruby-gnome/ruby-gnome@6b31424 · GitHub
gstreamer-gi: use Rubyish method name · ruby-gnome/ruby-gnome@e2e1b6b · GitHub

Gst.uri_is_valid was renamed to Gst.valid_uri?

The code I used with some more remark.

Thanks!

unless uri=ARGV[0]
STDERR.puts “usage: #{$0} uri”
exit 1
end

require ‘gst’
#p ARGV
Gst.init#TODO put it in gst.rb

#p Gst.init#2nd call crash the app

Fixed.

#p ARGV#Gst.init change ARGV!

Gst::Message::ERROR=1<<1#Not defined!
Gst::Message::EOS=1<<0

They can be removed.

loop=GLib::MainLoop.new(nil, false)
playbin=Gst::ElementFactory.make(‘playbin’)#TODO test return
playbin.bus.add_watch(1){|_, message|#Need an argument!

Fixed:
gstreamer-gi: priority of add_watch can be omitted · ruby-gnome/ruby-gnome@381a458 · GitHub

#p message.parse#no more magic parse based on class!
case message.type
when Gst::Message::EOS
loop.quit
when Gst::Message::ERROR
p message.parse_error#crash

Umm… I’ll consider about it…

#playbin.play#No more convenient methods
I’ve added it:
gstreamer-gi: add convenience methods to Element · ruby-gnome/ruby-gnome@a700faf · GitHub

playbin.state=Gst::State::PLAYING
at_exit{p ‘Exit. TODO: cleaning’}
loop.run

module Gst
@initialized = false
class << self
def init(argv=ARGV)
return if @initialized

seems to do what was expected but I am not sure why.

Oh! I’ve fixed it:
gstreamer-gi: fix initialize @initialized location · ruby-gnome/ruby-gnome@c6bcbef · GitHub

      gobject-introspection is black magic !

I think so too. :slight_smile:

Thanks for your report!
It is very helpful!

kou

On Sun, 2013-02-10 at 13:40 +0900, Kouhei S. wrote:

Thanks. I’ve fixed it:

I’ve fixed it:

It had been fixed in master. Could you try master?

Gst.uri_is_valid was renamed to Gst.valid_uri?

Fixed.

I’ve added it:

Oh! I’ve fixed it:

I think so too. :slight_smile:

Wow! Amazing response.

Thank you Kou for your hard work!

Regards
Grant

Thanks for this reply and these fast fixes.

One remark: I would have worked on a copy of ARGV inside Gst module, to
be
sure ARGV is left untouched outside. Then you can set @init_arguments
with
what you want and undo the last commit in this point.

-def init(argv=ARGV)
+def init(argv=ARGV.dup)

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gstreamer-gi” on Sun, 10 Feb 2013 15:50:11
+0100,
Vincent C. [email protected] wrote:

Thanks for this reply and these fast fixes.

You’re welcome. :slight_smile:

Now, we have workable script:
https://github.com/ruby-gnome2/ruby-gnome2/blob/master/gstreamer-gi/sample/helloworld.rb

One remark: I would have worked on a copy ofARGV inside Gst module, to be
sureARGV is left untouched outside. Then you can set@init_arguments with
what you want and undo the last commit in this point.

-def init(argv=ARGV)
+def init(argv=ARGV.dup)

I stopped using ARGV.

Now:
def init(*argv)

Users who want to customize GStreamer initialization should
pass parameters to Gst.init explicitly. For example:

Gst.init(“–gst-debug-level=3”)

Thanks,

kou