Sha256: 9f139b75fe12922e98c80eed3ee2938d3a61931c439c1cb3e64929971bd2cc01

Contents?: true

Size: 1.46 KB

Versions: 42

Compression:

Stored size: 1.46 KB

Contents

#!/usr/bin/env ruby

### TODO: I want to set link in build_pipeline.

unless ARGV.size == 1
  puts "Usage: #{$0} [file]"
  exit 1
end

require 'gst'

XML_FILE = "/tmp/pipeline.xml"
PIPELINE_NAME = "our-pipeline"

def build_pipeline(file)
  source = Gst::ElementFactory.make("filesrc")
  decoder = Gst::ElementFactory.make("decodebin")
  audio_converter = Gst::ElementFactory.make("audioconvert")
  audio_resample = Gst::ElementFactory.make("audioresample")
  audio_sink = Gst::ElementFactory.make("autoaudiosink")
  source.location = file
  pipeline = Gst::Pipeline.new(PIPELINE_NAME)
  pipeline.add(source, decoder, audio_converter, audio_resample, audio_sink)
  pipeline
end

def write_pipeline(pipeline, file)
  Gst::XML.write_file(pipeline, file)
end

def read_pipeline(file)
  xml = Gst::XML.new
  xml.parse_file(file)
  pipeline = xml.get_element(PIPELINE_NAME)
  children = pipeline.children
  source, decoder, audio_converter, audio_resample, audio_sink = children
  source >> decoder
  audio_converter >> audio_resample >> audio_sink
  decoder.signal_connect("new-decoded-pad") do |element, pad|
    sink_pad = audio_converter.get_pad("sink")
    pad.link(sink_pad)
  end
  pipeline
end

def play_pipeline(pipeline)
  pipeline.play
  loop = GLib::MainLoop.new(nil, false)
  begin
    loop.run
  rescue Interrupt
  ensure
    pipeline.stop
  end
end

pipeline = build_pipeline(ARGV.first)
write_pipeline(pipeline, XML_FILE)
pipeline = read_pipeline(XML_FILE)
play_pipeline(pipeline)

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
gstreamer-1.1.6-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.6 sample/xml-player.rb
gstreamer-1.1.5-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.5 sample/xml-player.rb
gstreamer-1.1.4-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.4 sample/xml-player.rb
gstreamer-1.1.3-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.3 sample/xml-player.rb
gstreamer-1.1.2 sample/xml-player.rb
gstreamer-1.1.2-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.1-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.1 sample/xml-player.rb
gstreamer-1.1.0-x86-mingw32 sample/xml-player.rb
gstreamer-1.1.0 sample/xml-player.rb
gstreamer-1.0.3 sample/xml-player.rb
gstreamer-1.0.2 sample/xml-player.rb
gstreamer-1.0.1 sample/xml-player.rb
gstreamer-1.0.0 sample/xml-player.rb
gstreamer-0.90.9 sample/xml-player.rb
gstreamer-0.90.8 sample/xml-player.rb