## GstBaseTransform GstBaseTransform — Base class for simple transform filters |

## Synopsis

    #include <gst/base/gstbasetransform.h>

    struct              GstBaseTransform;
    struct              GstBaseTransformClass;
    gboolean            gst_base_transform_is_passthrough   (GstBaseTransform *trans);
    void                gst_base_transform_set_passthrough  (GstBaseTransform *trans,
                                                             gboolean passthrough);
    void                gst_base_transform_set_prefer_passthrough
                                                            (GstBaseTransform *trans,
                                                             gboolean prefer_passthrough);
    gboolean            gst_base_transform_is_in_place      (GstBaseTransform *trans);
    void                gst_base_transform_set_in_place     (GstBaseTransform *trans,
                                                             gboolean in_place);
    gboolean            gst_base_transform_is_qos_enabled   (GstBaseTransform *trans);
    void                gst_base_transform_set_qos_enabled  (GstBaseTransform *trans,
                                                             gboolean enabled);
    void                gst_base_transform_update_qos       (GstBaseTransform *trans,
                                                             gdouble proportion,
                                                             GstClockTimeDiff diff,
                                                             GstClockTime timestamp);
    void                gst_base_transform_set_gap_aware    (GstBaseTransform *trans,
                                                             gboolean gap_aware);
    void                gst_base_transform_get_allocator    (GstBaseTransform *trans,
                                                             GstAllocator **allocator,
                                                             GstAllocationParams *params);
    GstBufferPool *     gst_base_transform_get_buffer_pool  (GstBaseTransform *trans);
    #define             GST_BASE_TRANSFORM_SINK_NAME
    #define             GST_BASE_TRANSFORM_SRC_NAME
    #define             GST_BASE_TRANSFORM_SINK_PAD         (obj)
    #define             GST_BASE_TRANSFORM_SRC_PAD          (obj)
    #define             GST_BASE_TRANSFORM_FLOW_DROPPED

## Object Hierarchy

      GObject
       +----GInitiallyUnowned
             +----GstObject
                   +----GstElement
                         +----GstBaseTransform

## Properties

      "qos"                      gboolean              : Read / Write

## Description

This base class is for filter elements that process data.

It provides for:

- one sinkpad and one srcpad

- Possible formats on sink and source pad implemented with custom transform_caps function. By default uses same format on sink and source.

- Handles state changes

- Does flushing

- Push mode

- Pull mode if the sub-class transform can operate on arbitrary data

### Use Cases

1. Passthrough mode

   - Element has no interest in modifying the buffer. It may want to inspect it, in which case the element should have a transform_ip function. If there is no transform_ip function in passthrough mode, the buffer is pushed intact.

   - On the GstBaseTransformClass is the passthrough_on_same_caps variable which will automatically set/unset passthrough based on whether the element negotiates the same caps on both pads.

   - passthrough_on_same_caps on an element that doesn't implement a transform_caps function is useful for elements that only inspect data (such as level)

   Example elements

   - Level
   - Videoscale, audioconvert, videoconvert, audioresample in certain modes.

2. Modifications in-place - input buffer and output buffer are the same thing.

   - The element must implement a transform_ip function.

   - Output buffer size must <= input buffer size

   - If the always_in_place flag is set, non-writable buffers will be copied and passed to the transform_ip function, otherwise a new buffer will be created and the transform function called.

   - Incoming writable buffers will be passed to the transform_ip function immediately.

   - only implementing transform_ip and not transform implies always_in_place = TRUE

   Example elements

   - Volume
   - Audioconvert in certain modes (signed/unsigned conversion)
   - videoconvert in certain modes (endianness swapping)

3. Modifications only to the caps/metadata of a buffer

   - The element does not require writable data, but non-writable buffers should be subbuffered so that the meta-information can be replaced.

   - Elements wishing to operate in this mode should replace the prepare_output_buffer method to create subbuffers of the input buffer and set always_in_place to TRUE

   Example elements

   - Capsfilter when setting caps on outgoing buffers that have none.
   - identity when it is going to re-timestamp buffers by datarate.

4. Normal mode

   - always_in_place flag is not set, or there is no transform_ip function

   - Element will receive an input buffer and output buffer to operate on.

   - Output buffer is allocated by calling the prepare_output_buffer function.

   Example elements

   - Videoscale, videoconvert, audioconvert when doing scaling/conversions

5. Special output buffer allocations

   - Elements which need to do special allocation of their output buffers beyond allocating output buffers via the negotiated allocator or buffer pool should implement the prepare_output_buffer method.

   Example elements

   - efence

### Sub-class settable flags on GstBaseTransform

- passthrough

  - Implies that in the current configuration, the sub-class is not interested in modifying the buffers.

  - Elements which are always in passthrough mode whenever the same caps has been negotiated on both pads can set the class variable passthrough_on_same_caps to have this behaviour automatically.

- always_in_place

  - Determines whether a non-writable buffer will be copied before passing to the transform_ip function.

  - Implied TRUE if no transform function is implemented.

  - Implied FALSE if ONLY transform function is implemented.

## Details

### struct GstBaseTransform

    struct GstBaseTransform;

The opaque GstBaseTransform data structure.

### struct GstBaseTransformClass

    struct GstBaseTransformClass {
      GstElementClass parent_class;

      gboolean       passthrough_on_same_caps;
      gboolean       transform_ip_on_passthrough;

      /* virtual methods for subclasses */
      GstCaps* (*transform_caps) (GstBaseTransform *trans,
                                       GstPadDirection direction,
                                       GstCaps *caps, GstCaps *filter);
      GstCaps* (*fixate_caps)	  (GstBaseTransform *trans,
                                       GstPadDirection direction, GstCaps *caps,
                                       GstCaps *othercaps);
      gboolean      (*accept_caps)    (GstBaseTransform *trans, GstPadDirection direction,
                                       GstCaps *caps);
      gboolean      (*set_caps)       (GstBaseTransform *trans, GstCaps *incaps,
                                       GstCaps *outcaps);
      gboolean      (*query)          (GstBaseTransform *trans, GstPadDirection direction,
                                       GstQuery *query);

      /* decide allocation query for output buffers */
      gboolean      (*decide_allocation)  (GstBaseTransform *trans, GstQuery *query);
      gboolean      (*filter_meta)        (GstBaseTransform *trans, GstQuery *query,
                                           GType api, const GstStructure *params);

      /* propose allocation query parameters for input buffers */
      gboolean      (*propose_allocation) (GstBaseTransform *trans, GstQuery *decide_query,
                                           GstQuery *query);

      /* transform size */
      gboolean      (*transform_size) (GstBaseTransform *trans,
                                       GstPadDirection direction,
                                       GstCaps *caps, gsize size,
                                       GstCaps *othercaps, gsize *othersize);

      gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
                                       gsize *size);

      /* states */
      gboolean      (*start)        (GstBaseTransform *trans);
      gboolean      (*stop)         (GstBaseTransform *trans);

      /* sink and src pad event handlers */
      gboolean      (*sink_event)   (GstBaseTransform *trans, GstEvent *event);
      gboolean      (*src_event)    (GstBaseTransform *trans, GstEvent *event);

      GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
                                              GstBuffer *input, GstBuffer **outbuf);

      /* metadata */
      gboolean      (*copy_metadata)     (GstBaseTransform *trans, GstBuffer *input,
                                          GstBuffer *outbuf);
      gboolean      (*transform_meta)    (GstBaseTransform *trans, GstBuffer *outbuf,
                                          GstMeta *meta, GstBuffer *inbuf);

      void          (*before_transform)  (GstBaseTransform *trans, GstBuffer *buffer);

      /* transform */
      GstFlowReturn (*transform)    (GstBaseTransform *trans, GstBuffer *inbuf,
                                     GstBuffer *outbuf);
      GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
    };

Subclasses can override any of the available virtual methods or not, as needed. At minimum either `transform` or `transform_ip` need to be overridden. If the element can overwrite the input data with the results (data is of the same type and quantity) it should provide `transform_ip`.

GstElementClass `parent_class`; | Element parent class
gboolean `passthrough_on_same_caps`; | If set to `TRUE`, passthrough mode will be automatically enabled if the caps are the same. Set to `FALSE` by default.
gboolean `transform_ip_on_passthrough`; | If set to `TRUE`, `transform_ip` will be called in passthrough mode. The passed buffer might not be writable. When `FALSE`, neither `transform` nor `transform_ip` will be called in passthrough mode. Set to `TRUE` by default.
`transform_caps` () | Optional. Given the pad in this direction and the given caps, what caps are allowed on the other pad in this element ?
`fixate_caps` () | Optional. Given the pad in this direction and the given caps, fixate the caps on the other pad. The function takes ownership of `othercaps` and returns a fixated version of `othercaps`. `othercaps` is not guaranteed to be writable.
`accept_caps` () | Optional. Subclasses can override this method to check if `caps` can be handled by the element. The default implementation might not be the most optimal way to check this in all cases.
`set_caps` () | allows the subclass to be notified of the actual caps set.
`query` () | Optional. Handle a requested query. Subclasses that implement this should must chain up to the parent if they didn't handle the query
`decide_allocation` () | Setup the allocation parameters for allocating output buffers. The passed in query contains the result of the downstream allocation query. This function is only called when not operating in passthrough mode. The default implementation will remove all memory dependent metadata. If there is ia `filter_meta` method implementation, it will be called for all metadata API in the downstream query, otherwise the metadata API is removed.
`filter_meta` () | Return TRUE if the metadata API should be proposed in the upstream allocation query. The default implementation is NULL and will cause all metadata to be removed.
`propose_allocation` () | Propose buffer allocation parameters for upstream elements. This function must be implemented if the element reads or writes the buffer content. The query that was passed to the decide_allocation is passed in this method (or NULL when the element is in passthrough mode). The default implementation will pass the query downstream when in passthrough mode and will copy all the filtered metadata API in non-passthrough mode.
`transform_size` () | Optional. Given the size of a buffer in the given direction with the given caps, calculate the size in bytes of a buffer on the other pad with the given other caps. The default implementation uses get_unit_size and keeps the number of units the same.
`get_unit_size` () | Required if the transform is not in-place. get the size in bytes of one unit for the given caps.
`start` () | Optional. Called when the element starts processing. Allows opening external resources.
`stop` () | Optional. Called when the element stops processing. Allows closing external resources.
`sink_event` () | Optional. Event handler on the sink pad. The default implementation handles the event and forwards it downstream.
`src_event` () | Optional. Event handler on the source pad. The default implementation handles the event and forwards it upstream.
`prepare_output_buffer` () | Optional. Subclasses can override this to do their own allocation of output buffers. Elements that only do analysis can return a subbuffer or even just return a reference to the input buffer (if in passthrough mode). The default implementation will use the negotiated allocator or bufferpool and transform_size to allocate an output buffer or it will return the input buffer in passthrough mode.
`copy_metadata` () | Optional. Copy the metadata from the input buffer to the output buffer. The default implementation will copy the flags, timestamps and offsets of the buffer.
`transform_meta` () | Optional. Transform the metadata on the input buffer to the output buffer. By default this method is NULL and no metadata is copied. subclasses can implement this method and return TRUE if the metadata is to be copied.
`before_transform` () | Optional. This method is called right before the base class will start processing. Dynamic properties or other delayed configuration could be performed in this method.
`transform` () | Required if the element does not operate in-place. Transforms one incoming buffer to one outgoing buffer. The function is allowed to change size/timestamp/duration of the outgoing buffer.
`transform_ip` () | Required if the element operates in-place. Transform the incoming buffer in-place.

### gst_base_transform_is_passthrough ()

    gboolean            gst_base_transform_is_passthrough   (GstBaseTransform *trans);

See if `trans` is configured as a passthrough transform.

`trans` : | the GstBaseTransform to query
Returns : | TRUE is the transform is configured in passthrough mode. MT safe.

### gst_base_transform_set_passthrough ()

    void                gst_base_transform_set_passthrough  (GstBaseTransform *trans,
                                                             gboolean passthrough);

Set passthrough mode for this filter by default. This is mostly useful for filters that do not care about negotiation.

Always TRUE for filters which don't implement either a transform or transform_ip method.

MT safe.

`trans` : | the GstBaseTransform to set
`passthrough` : | boolean indicating passthrough mode.

### gst_base_transform_set_prefer_passthrough ()

    void                gst_base_transform_set_prefer_passthrough
                                                            (GstBaseTransform *trans,
                                                             gboolean prefer_passthrough);

If `prefer_passthrough` is `TRUE` (the default), `trans` will check and prefer passthrough caps from the list of caps returned by the transform_caps vmethod.

If set to `FALSE`, the element must order the caps returned from the transform_caps function in such a way that the prefered format is first in the list. This can be interesting for transforms that can do passthrough transforms but prefer to do something else, like a capsfilter.

MT safe.

`trans` : | a GstBaseTransform
`prefer_passthrough` : | New state

Since 1.0.1

### gst_base_transform_is_in_place ()

    gboolean            gst_base_transform_is_in_place      (GstBaseTransform *trans);

See if `trans` is configured as a in_place transform.

`trans` : | the GstBaseTransform to query
Returns : | TRUE is the transform is configured in in_place mode. MT safe.

### gst_base_transform_set_in_place ()

    void                gst_base_transform_set_in_place     (GstBaseTransform *trans,
                                                             gboolean in_place);

Determines whether a non-writable buffer will be copied before passing to the transform_ip function.

- Always TRUE if no transform function is implemented.
- Always FALSE if ONLY transform function is implemented.

MT safe.

`trans` : | the GstBaseTransform to modify
`in_place` : | Boolean value indicating that we would like to operate on in_place buffers.

### gst_base_transform_is_qos_enabled ()

    gboolean            gst_base_transform_is_qos_enabled   (GstBaseTransform *trans);

Queries if the transform will handle QoS.

`trans` : | a GstBaseTransform
Returns : | TRUE if QoS is enabled. MT safe.

### gst_base_transform_set_qos_enabled ()

    void                gst_base_transform_set_qos_enabled  (GstBaseTransform *trans,
                                                             gboolean enabled);

Enable or disable QoS handling in the transform.

MT safe.

`trans` : | a GstBaseTransform
`enabled` : | new state

### gst_base_transform_update_qos ()

    void                gst_base_transform_update_qos       (GstBaseTransform *trans,
                                                             gdouble proportion,
                                                             GstClockTimeDiff diff,
                                                             GstClockTime timestamp);

Set the QoS parameters in the transform. This function is called internally when a QOS event is received but subclasses can provide custom information when needed.

MT safe.

`trans` : | a GstBaseTransform
`proportion` : | the proportion
`diff` : | the diff against the clock
`timestamp` : | the timestamp of the buffer generating the QoS expressed in running_time.

### gst_base_transform_set_gap_aware ()

    void                gst_base_transform_set_gap_aware    (GstBaseTransform *trans,
                                                             gboolean gap_aware);

If `gap_aware` is `FALSE` (the default), output buffers will have the `GST_BUFFER_FLAG_GAP` flag unset.

If set to `TRUE`, the element must handle output buffers with this flag set correctly, i.e. it can assume that the buffer contains neutral data but must unset the flag if the output is no neutral data.

MT safe.

`trans` : | a GstBaseTransform
`gap_aware` : | New state

### gst_base_transform_get_allocator ()

    void                gst_base_transform_get_allocator    (GstBaseTransform *trans,
                                                             GstAllocator **allocator,
                                                             GstAllocationParams *params);

Lets GstBaseTransform sub-classes to know the memory `allocator` used by the base class and its `params`.

Unref the `allocator` after use it.

`trans` : | a GstBaseTransform
`allocator` : | the GstAllocator used. [out][allow-none][transfer full]
`params` : | the GstAllocatorParams of `allocator`. [out][allow-none][transfer full]

### gst_base_transform_get_buffer_pool ()

    GstBufferPool *     gst_base_transform_get_buffer_pool  (GstBaseTransform *trans);

`trans` : | a GstBaseTransform
Returns : | the instance of the GstBufferPool used by `trans`; free it after use it. [transfer full]

### GST_BASE_TRANSFORM_SINK_NAME

    #define GST_BASE_TRANSFORM_SINK_NAME "sink"

The name of the templates for the sink pad.

### GST_BASE_TRANSFORM_SRC_NAME

    #define GST_BASE_TRANSFORM_SRC_NAME "src"

The name of the templates for the source pad.

### GST_BASE_TRANSFORM_SINK_PAD()

    #define GST_BASE_TRANSFORM_SINK_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)

Gives the pointer to the sink GstPad object of the element.

`obj` : | base transform instance

### GST_BASE_TRANSFORM_SRC_PAD()

    #define GST_BASE_TRANSFORM_SRC_PAD(obj)		(GST_BASE_TRANSFORM_CAST (obj)->srcpad)

Gives the pointer to the source GstPad object of the element.

`obj` : | base transform instance

### GST_BASE_TRANSFORM_FLOW_DROPPED

    #define GST_BASE_TRANSFORM_FLOW_DROPPED   GST_FLOW_CUSTOM_SUCCESS

A GstFlowReturn that can be returned from transform and transform_ip to indicate that no output buffer was generated.

## Property Details

### The `"qos"` property

      "qos"                      gboolean              : Read / Write

Handle Quality-of-Service events.

Default value: FALSE

## See Also

GstBaseSrc, GstBaseSink