16.4. Ghost pads

You can see from Figure 16-1 how a bin has no pads of its own. This is where "ghost pads" come into play.

Figure 16-1. Visualisation of a GstBin element without ghost pads

A ghost pad is a pad from some element in the bin that has been promoted to the bin. This way, the bin also has a pad. The bin becomes just another element with a pad and you can then use the bin just like any other element. This is a very important feature for creating custom bins.

Figure 16-2. Visualisation of a GstBin element with a ghost pad

Figure 16-2 is a representation of a ghost pad. The sink pad of element one is now also a pad of the bin.

Ghost pads can actually be added to all GstElements and not just GstBins. Use the following code example to add a ghost pad to a bin:


  GstElement *bin;
  GstElement *element;

  element = gst_element_factory_create ("mad", "decoder");
  bin = gst_bin_new ("mybin");

  gst_bin_add (GST_BIN (bin), element);

  gst_element_add_ghost_pad (bin, gst_element_get_pad (element, "sink"), "sink");
  
    

In the above example, the bin now also has a pad: the pad called 'sink' of the given element.

We can now, for example, link the source pad of a filesrc element to the bin with:


  GstElement *filesrc;

  filesrc = gst_element_factory_create ("filesrc", "disk_reader");
  
  gst_element_link_pads (filesrc, "src", bin, "sink");
    ...