ruby-gstreamer 不发送 EOS 消息
我已经设法让它播放声音,但它从未收到 EOS 消息。 因此脚本永远不会退出。
require 'gst'
main_loop = GLib::MainLoop.new
pipeline = Gst::Pipeline.new "audio-player"
source = Gst::ElementFactory.make "filesrc", "file-source"
source.location = "/usr/share/sounds/gnome/default/alerts/bark.ogg"
decoder = Gst::ElementFactory.make "decodebin", "decoder"
conv = Gst::ElementFactory.make "audioconvert", "converter"
sink = Gst::ElementFactory.make "alsasink", "output"
pipeline.add source, decoder, conv, sink
source >> decoder
conv >> sink
decoder.signal_connect "pad-added" do |element, pad, data|
pad >> conv['sink']
end
pipeline.bus.add_watch do |bus, message|
puts "Message: #{message.inspect}"
case message.type
when Gst::Message::Type::ERROR
puts message.structure["debug"]
main_loop.quit
when Gst::Message::Type::EOS
puts 'End of stream'
main_loop.quit
end
end
pipeline.play
begin
puts 'Running main loop'
main_loop.run
ensure
puts 'Shutting down main loop'
pipeline.stop
end
I've managed to make it play sound but it never gets EOS message.
And thus script never exits.
require 'gst'
main_loop = GLib::MainLoop.new
pipeline = Gst::Pipeline.new "audio-player"
source = Gst::ElementFactory.make "filesrc", "file-source"
source.location = "/usr/share/sounds/gnome/default/alerts/bark.ogg"
decoder = Gst::ElementFactory.make "decodebin", "decoder"
conv = Gst::ElementFactory.make "audioconvert", "converter"
sink = Gst::ElementFactory.make "alsasink", "output"
pipeline.add source, decoder, conv, sink
source >> decoder
conv >> sink
decoder.signal_connect "pad-added" do |element, pad, data|
pad >> conv['sink']
end
pipeline.bus.add_watch do |bus, message|
puts "Message: #{message.inspect}"
case message.type
when Gst::Message::Type::ERROR
puts message.structure["debug"]
main_loop.quit
when Gst::Message::Type::EOS
puts 'End of stream'
main_loop.quit
end
end
pipeline.play
begin
puts 'Running main loop'
main_loop.run
ensure
puts 'Shutting down main loop'
pipeline.stop
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。与所有可能遇到同样问题的人分享。
真正的问题是该块没有返回
true
。它必须返回true
才能保持监视。这在 GStreamer 文档的深处有记录,但在 ruby-gnome2 文档中没有提及。I've found a solution. Sharing with everybody who may run into same problem.
The real problem was that block didn't return
true
. It has to returntrue
to be kept in watch. This is documented somewhere deep in GStreamer docs but is not mentioned in ruby-gnome2 docs.应该是:
错误也一样
should be:
same goes for ERROR