[ruby-gnome2-doc-cvs] [Hiki] update - tut-gst-pads-elem

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 4月 1日 (木) 20:54:19 JST


-------------------------
REMOTE_ADDR = 195.207.101.112
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/en/?tut-gst-pads-elem
-------------------------
  = Getting Pads from an Element
+ {{link("tut-gst-plugins", nil, "tut-gst", "tut-gst-pads-caps")}}
  
  As we have seen in the previous chapter (Gst::Element), the pads (Gst::Pad) are the element's links with the outside world.
  
  The specific type of media that the element can handle will be exposed by the pads. The description of this media type is done with capabilities (Gst::Caps).
  
  Once you have created an element, you can get one of its pads with:
  
    src_pad = element.get_pad("src")
  
  This method will get the pad named "src" from the given element.
  
  Alternatively, you can request a list of pads from the element. The following code example will print the names of all the pads of an element. 
  
    element.each_pad do |pad|
      puts "pad name: " + pad.name
    end
  
  == Dynamic Pads
  
  Some elements might not have their pads when they are created. This can happen, for example, with an MPEG2 system demultiplexer. The demultiplexer will create its pads at runtime when it detects the different elementary streams in the MPEG2 system stream.
  
  Running (({gst-inspect mpegdemux})) will show that the element has only one pad: a sink pad called 'sink'. The other pads are "dormant" as you can see in the padtemplates from the 'Exists: Sometimes' property. Depending on the type of MPEG2 file you play, the pads are created. We will see that this is very important when you are going to create dynamic pipelines later on in this manual.
  
  You can attach a signal to an element to inform you when the element has created a new pad from one of its padtemplates. The following piece of code is an example of how to do this: 
  
    # create the pipeline and do something useful
    pipeline = Gst::Pipeline.new
    ...
  
    mpeg2parser = Gst::ElementFactory.make("mpegdemux")
    mpeg2parser.signal_connect("new_pad") do |parser, pad|
        puts "a new pad #{pad.name} was created!"
        pipeline.pause
        if pad.name == "private_stream_1.0"
            # set up an AC3 decoder pipeline
            ...
  
            # link pad to the AC3 decoder pipeline
            ...
        end
    end
  
    # start the pipeline
    pipeline.play
    ...
  
  == Request Pads
  
  An element can also have request pads. These pads are not created automatically but are only created on demand. This is very useful for multiplexers, aggregators and tee elements.
  
  The tee element, for example, has one input pad and a request padtemplate for the output pads. Whenever an element wants to get an output pad from the tee element, it has to request the pad.
  
  The following piece of code can be used to get a pad from the tee element. After the pad has been requested, it can be used to link another element to it. 
  
    element = Gst::ElementFactory.make("tee")
    pad = element.request_pad("src%d")
    puts "new pad: " + pad.name
  
  The Gst::Element#request_pad method can be used to get a pad from the element based on the name_template of the padtemplate.
  
  It is also possible to request a pad that is compatible with another pad template. This is very useful if you want to link an element to a multiplexer element and you need to request a pad that is compatible. Gst::Element#get_compatible_pad is used to request a compatible pad, as is shown in the next example. 
  
    element = Gst::ElementFactory.make("tee")
    mad = Gst::ElementFactory.make("mad")
  
    templ = mad.get_pad_template_by_name("sink")
  
    pad = element.get_compatible_pad(templ)
    puts "new pad: " = pad.name





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