Loop-based elements

As opposed to chain-based elements, Loop-based elements enter an infinite loop that looks like this:
  GstBuffer *buffer, *outbuffer;
 
  while (1) {
    buffer = gst_pad_pull (sinkpad);
    ...
    // process buffer, create outbuffer
    while (!done) {
      ....
      // optionally request another buffer
      buffer = gst_pad_pull (sinkpad);
      ....
    }
    ...
    gst_pad_push (srcpad, outbuffer);
  }
    
The loop-based elements request a buffer whenever they need one.

When the request for a buffer cannot immedialty satisfied, the control will be given to the source element of the loop-based element until it performs a push on its source pad. At that time the control is handed back to the loop-based element, etc... The the execution trace can get fairly complex using cothreads when there are multiple input/output pads for the loop-based element.

Loop based elements are mainly used for the more complex elements that need a specific amount of data before they can start to produce output. An example of such an element is the mpeg video decoder. the element will pull a buffer, performs some decoding on it and optionally requests more buffers to decode, when a complete video frame has been decoded, a buffer is send out.

There is no problem in putting cothreaded elements into a GstThread to create even more complex pipelines with both user and kernel space threads.