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 !