Class CollectPads

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class CollectPads extends GstObject

Manages a set of pads that operate in collect mode. This means that control is given to the manager of this object when all pads have data.

  • Collectpads are created with gst_collect_pads_new(). A callback should then be installed with gst_collect_pads_set_function ().

  • Pads are added to the collection with gst_collect_pads_add_pad()/ gst_collect_pads_remove_pad(). The pad has to be a sinkpad. When added, the chain, event and query functions of the pad are overridden. The element_private of the pad is used to store private information for the collectpads.

  • For each pad, data is queued in the _chain function or by performing a pull_range.

  • When data is queued on all pads in waiting mode, the callback function is called.

  • Data can be dequeued from the pad with the gst_collect_pads_pop() method. One can peek at the data with the gst_collect_pads_peek() function. These functions will return null if the pad received an EOS event. When all pads return null from a gst_collect_pads_peek(), the element can emit an EOS event itself.

  • Data can also be dequeued in byte units using the gst_collect_pads_available(), gst_collect_pads_read_buffer() and gst_collect_pads_flush() calls.

  • Elements should call gst_collect_pads_start() and gst_collect_pads_stop() in their state change functions to start and stop the processing of the collectpads. The gst_collect_pads_stop() call should be called before calling the parent element state change function in the PAUSED_TO_READY state change to ensure no pad is blocked and the element can finish streaming.

  • gst_collect_pads_set_waiting() sets a pad to waiting or non-waiting mode. CollectPads element is not waiting for data to be collected on non-waiting pads. Thus these pads may but need not have data when the callback is called. All pads are in waiting mode by default.

  • Constructor Details

    • CollectPads

      public CollectPads(MemorySegment address)
      Create a CollectPads instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • CollectPads

      public CollectPads()
      Create a new CollectPads.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the CollectPads class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected CollectPads asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class GstObject
      Returns:
      the instance as if it were its parent type
    • addPad

      public @Nullable CollectData addPad(Pad pad, int size, @Nullable CollectDataDestroyNotify destroyNotify, boolean lock)

      Add a pad to the collection of collect pads. The pad has to be a sinkpad. The refcount of the pad is incremented. Use gst_collect_pads_remove_pad() to remove the pad from the collection again.

      You specify a size for the returned GstCollectData structure so that you can use it to store additional information.

      You can also specify a GstCollectDataDestroyNotify that will be called just before the GstCollectData structure is freed. It is passed the pointer to the structure and should free any custom memory and resources allocated for it.

      Keeping a pad locked in waiting state is only relevant when using the default collection algorithm (providing the oldest buffer). It ensures a buffer must be available on this pad for a collection to take place. This is of typical use to a muxer element where non-subtitle streams should always be in waiting state, e.g. to assure that caps information is available on all these streams when initial headers have to be written.

      The pad will be automatically activated in push mode when this CollectPads is started.

      MT safe.

      Parameters:
      pad - the pad to add
      size - the size of the returned GstCollectData structure
      destroyNotify - function to be called before the returned GstCollectData structure is freed
      lock - whether to lock this pad in usual waiting state
      Returns:
      a new GstCollectData to identify the new pad. Or null if wrong parameters are supplied.
    • available

      public int available()

      Query how much bytes can be read from each queued buffer. This means that the result of this call is the maximum number of bytes that can be read from each of the pads.

      This function should be called with this CollectPads STREAM_LOCK held, such as in the callback.

      MT safe.

      Returns:
      The maximum number of bytes queued on all pads. This function returns 0 if a pad has no queued buffer.
    • clipRunningTime

      public FlowReturn clipRunningTime(CollectData cdata, Buffer buf, @Nullable Out<Buffer> outbuf, @Nullable MemorySegment userData)

      Convenience clipping function that converts incoming buffer's timestamp to running time, or clips the buffer if outside configured segment.

      Since 1.6, this clipping function also sets the DTS parameter of the GstCollectData structure. This version of the running time DTS can be negative. G_MININT64 is used to indicate invalid value.

      Parameters:
      cdata - collect data of corresponding pad
      buf - buffer being clipped
      outbuf - output buffer with running time, or NULL if clipped
      userData - user data (unused)
    • eventDefault

      public boolean eventDefault(CollectData data, Event event, boolean discard)
      Default GstCollectPads event handling that elements should always chain up to to ensure proper operation. Element might however indicate event should not be forwarded downstream.
      Parameters:
      data - collect data of corresponding pad
      event - event being processed
      discard - process but do not send event downstream
    • flush

      public int flush(CollectData data, int size)

      Flush size bytes from the pad data.

      This function should be called with this CollectPads STREAM_LOCK held, such as in the callback.

      MT safe.

      Parameters:
      data - the data to use
      size - the number of bytes to flush
      Returns:
      The number of bytes flushed This can be less than size and is 0 if the pad was end-of-stream.
    • peek

      public @Nullable Buffer peek(CollectData data)

      Peek at the buffer currently queued in data. This function should be called with the this CollectPads STREAM_LOCK held, such as in the callback handler.

      MT safe.

      Parameters:
      data - the data to use
      Returns:
      The buffer in data or null if no buffer is queued. should unref the buffer after usage.
    • pop

      public @Nullable Buffer pop(CollectData data)

      Pop the buffer currently queued in data. This function should be called with the this CollectPads STREAM_LOCK held, such as in the callback handler.

      MT safe.

      Parameters:
      data - the data to use
      Returns:
      The buffer in data or null if no buffer was queued. You should unref the buffer after usage.
    • queryDefault

      public boolean queryDefault(CollectData data, Query query, boolean discard)
      Default GstCollectPads query handling that elements should always chain up to to ensure proper operation. Element might however indicate query should not be forwarded downstream.
      Parameters:
      data - collect data of corresponding pad
      query - query being processed
      discard - process but do not send event downstream
    • readBuffer

      public @Nullable Buffer readBuffer(CollectData data, int size)

      Get a subbuffer of size bytes from the given pad data.

      This function should be called with this CollectPads STREAM_LOCK held, such as in the callback.

      MT safe.

      Parameters:
      data - the data to use
      size - the number of bytes to read
      Returns:
      A sub buffer. The size of the buffer can be less that requested. A return of null signals that the pad is end-of-stream. Unref the buffer after use.
    • removePad

      public boolean removePad(Pad pad)

      Remove a pad from the collection of collect pads. This function will also free the GstCollectData and all the resources that were allocated with gst_collect_pads_add_pad().

      The pad will be deactivated automatically when this CollectPads is stopped.

      MT safe.

      Parameters:
      pad - the pad to remove
      Returns:
      true if the pad could be removed.
    • setBufferFunction

      public void setBufferFunction(@Nullable CollectPadsBufferFunction func)

      Set the callback function and user data that will be called with the oldest buffer when all pads have been collected, or null on EOS. If a buffer is passed, the callback owns a reference and must unref it.

      MT safe.

      Parameters:
      func - the function to set
    • setClipFunction

      public void setClipFunction(@Nullable CollectPadsClipFunction clipfunc)
      Install a clipping function that is called right after a buffer is received on a pad managed by pads. See GstCollectPadsClipFunction for more info.
      Parameters:
      clipfunc - clip function to install
    • setCompareFunction

      public void setCompareFunction(@Nullable CollectPadsCompareFunction func)

      Set the timestamp comparison function.

      MT safe.

      Parameters:
      func - the function to set
    • setEventFunction

      public void setEventFunction(@Nullable CollectPadsEventFunction func)

      Set the event callback function and user data that will be called when collectpads has received an event originating from one of the collected pads. If the event being processed is a serialized one, this callback is called with this CollectPads STREAM_LOCK held, otherwise not. As this lock should be held when calling a number of CollectPads functions, it should be acquired if so (unusually) needed.

      MT safe.

      Parameters:
      func - the function to set
    • setFlushFunction

      public void setFlushFunction(@Nullable CollectPadsFlushFunction func)
      Install a flush function that is called when the internal state of all pads should be flushed as part of flushing seek handling. See GstCollectPadsFlushFunction for more info.
      Parameters:
      func - flush function to install
      Since:
      1.4
    • setFlushing

      public void setFlushing(boolean flushing)

      Change the flushing state of all the pads in the collection. No pad is able to accept anymore data when flushing is true. Calling this function with flushing false makes this CollectPads accept data again. Caller must ensure that downstream streaming (thread) is not blocked, e.g. by sending a FLUSH_START downstream.

      MT safe.

      Parameters:
      flushing - desired state of the pads
    • setFunction

      public void setFunction(@Nullable CollectPadsFunction func)

      CollectPads provides a default collection algorithm that will determine the oldest buffer available on all of its pads, and then delegate to a configured callback. However, if circumstances are more complicated and/or more control is desired, this sets a callback that will be invoked instead when all the pads added to the collection have buffers queued. Evidently, this callback is not compatible with gst_collect_pads_set_buffer_function() callback. If this callback is set, the former will be unset.

      MT safe.

      Parameters:
      func - the function to set
    • setQueryFunction

      public void setQueryFunction(@Nullable CollectPadsQueryFunction func)

      Set the query callback function and user data that will be called after collectpads has received a query originating from one of the collected pads. If the query being processed is a serialized one, this callback is called with this CollectPads STREAM_LOCK held, otherwise not. As this lock should be held when calling a number of CollectPads functions, it should be acquired if so (unusually) needed.

      MT safe.

      Parameters:
      func - the function to set
    • setWaiting

      public void setWaiting(CollectData data, boolean waiting)

      Sets a pad to waiting or non-waiting mode, if at least this pad has not been created with locked waiting state, in which case nothing happens.

      This function should be called with this CollectPads STREAM_LOCK held, such as in the callback.

      MT safe.

      Parameters:
      data - the data to use
      waiting - boolean indicating whether this pad should operate in waiting or non-waiting mode
    • srcEventDefault

      public boolean srcEventDefault(Pad pad, Event event)
      Default GstCollectPads event handling for the src pad of elements. Elements can chain up to this to let flushing seek event handling be done by GstCollectPads.
      Parameters:
      pad - src GstPad that received the event
      event - event being processed
      Since:
      1.4
    • start

      public void start()

      Starts the processing of data in the collect_pads.

      MT safe.

    • stop

      public void stop()

      Stops the processing of data in the collect_pads. this function will also unblock any blocking operations.

      MT safe.

    • takeBuffer

      public @Nullable Buffer takeBuffer(CollectData data, int size)

      Get a subbuffer of size bytes from the given pad data. Flushes the amount of read bytes.

      This function should be called with this CollectPads STREAM_LOCK held, such as in the callback.

      MT safe.

      Parameters:
      data - the data to use
      size - the number of bytes to read
      Returns:
      A sub buffer. The size of the buffer can be less that requested. A return of null signals that the pad is end-of-stream. Unref the buffer after use.
    • builder

      public static CollectPads.Builder<? extends CollectPads.Builder> builder()
      A CollectPads.Builder object constructs a CollectPads with the specified properties. Use the various set...() methods to set properties, and finish construction with CollectPads.Builder.build().
      Returns:
      the builder object