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 [email protected]id
“[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 https://github.com/ruby-gnome2/ruby-gnome2
% 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:
https://github.com/ruby-gnome2/ruby-gnome2/commit/5dfad0adff6f199917e00e95460c8be74824ca4a

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:
https://github.com/ruby-gnome2/ruby-gnome2/commit/f854789cb89486e742c69129ccb1c2b8f1e4ffd9

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:
https://github.com/ruby-gnome2/ruby-gnome2/commit/6b314248389ee6b55d8c8871f0783fd78880e880
https://github.com/ruby-gnome2/ruby-gnome2/commit/e2e1b6be2608995350e5883cf9f3af682996774c

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:
https://github.com/ruby-gnome2/ruby-gnome2/commit/381a4583408d26d06a346f2abd208f21255da1ab

#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:
https://github.com/ruby-gnome2/ruby-gnome2/commit/a700faf0d8ca131dc4e7422e1cc150c74a4e1214

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:
https://github.com/ruby-gnome2/ruby-gnome2/commit/c6bcbef174c63e43d9ee55c6a73e55feb440874c

      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 [email protected]_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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs