[ruby-gnome2-doc-cvs] [Hiki] create - tut-gst-queues

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 3月 5日 (金) 01:11:13 JST


-------------------------
REMOTE_ADDR = 195.207.101.112
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-gst-queues
-------------------------
= Queues

A Gst::Queue is a filter element. Queues can be used to link two elements in such way that the data can be buffered.

A buffer that is sinked to a Queue will not automatically be pushed to the next linked element but will be buffered. It will be pushed to the next element as soon as a Gst::Pad#pull is called on the queue's source pad.

Queues are mostly used in conjunction with a Gst::Thread to provide an external link for the thread elements. You could have one thread feeding buffers into a Gst::Queue and another thread repeadedly calling Gst::Pad#pull on the queue to feed its internal elements.

Below is a figure of a two-threaded decoder. We have one thread (the main execution thread) reading the data from a file, and another thread decoding the data. 

{{image_left("queue.png")}}
{{br}}

The standard GStreamer queue implementation has some properties that can be changed using their accessors methods. To set the maximum number of buffers that can be queued to 30, do:

  queue.max_level = 30

The following MP3 player shows you how to create the above pipeline using a thread and a queue.

  require 'gst'

  Gst.init
  unless ARGV.size == 1
      $stderr.puts "Usage: "{__FILE__} <mp3 filename>"
      exit 1
  end

  playing = true

  # create a new thread to hold the elements
  thread = Gst::Thread.new

  # create a new bin to hold the elements
  bin = Gst::Bin.new

  # create a disk reader
  filesrc = Gst::ElementFactory.make("filesrc")
  filesrc.location = ARGV.first
  filesrc.signal_connect("eos") do
      puts "have eos, quitting..."
      playing = false
  end

  # a decoder
  decoder = Gst::ElementFactory.make("mad")

  # and an audio sink
  audiosink = Gst::ElementFactory.make("osssink")
  
  # create our queue
  queue = Gst::ElementFactory.make("queue")

  # add objects to the main bin
  thread.add(decode, audiosink)
  bin.add(filesrc, queue, thread)

  # link elements
  filesrc >> queue >> decode >> audiosink

  # start playing
  bin.play

  while playing do
      bin.iterate
  end

  bin.stop





ruby-gnome2-cvs メーリングリストの案内
Back to archive index