Top |
struct | GstBaseTransform |
struct | GstBaseTransformClass |
#define | GST_BASE_TRANSFORM_SINK_NAME |
#define | GST_BASE_TRANSFORM_SRC_NAME |
#define | GST_BASE_TRANSFORM_FLOW_DROPPED |
This base class is for filter elements that process data. Elements that are suitable for implementation using GstBaseTransform are ones where the size and caps of the output is known entirely from the input caps and buffer sizes. These include elements that directly transform one buffer into another, modify the contents of a buffer in-place, as well as elements that collate multiple input buffers into one output buffer, or that expand one input buffer into multiple output buffers. See below for more concrete use cases.
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
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.
The GstBaseTransformClass.passthrough_on_same_caps variable will automatically set/unset passthrough based on whether the element negotiates the same caps on both pads.
GstBaseTransformClass.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.
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)
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.
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
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
gboolean
gst_base_transform_is_passthrough (GstBaseTransform *trans
);
See if trans
is configured as a passthrough transform.
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.
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 preferred 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.
Since: 1.0.1
gboolean
gst_base_transform_is_in_place (GstBaseTransform *trans
);
See if trans
is configured as a in_place transform.
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.
MT safe.
trans |
the GstBaseTransform to modify |
|
in_place |
Boolean value indicating that we would like to operate on in_place buffers. |
gboolean
gst_base_transform_is_qos_enabled (GstBaseTransform *trans
);
Queries if the transform will handle QoS.
void gst_base_transform_set_qos_enabled (GstBaseTransform *trans
,gboolean enabled
);
Enable or disable QoS handling in the transform.
MT safe.
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.
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.
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 |
||
allocator |
the GstAllocator used. |
[out][allow-none][transfer full] |
params |
the
GstAllocationParams of |
[out][allow-none][transfer full] |
GstBufferPool *
gst_base_transform_get_buffer_pool (GstBaseTransform *trans
);
void
gst_base_transform_reconfigure_sink (GstBaseTransform *trans
);
Instructs trans
to request renegotiation upstream. This function is
typically called after properties on the transform were set that
influence the input format.
void
gst_base_transform_reconfigure_src (GstBaseTransform *trans
);
Instructs trans
to renegotiate a new downstream transform on the next
buffer. This function is typically called after properties on the transform
were set that influence the output format.
gboolean gst_base_transform_update_src_caps (GstBaseTransform *trans
,GstCaps *updated_caps
);
Updates the srcpad caps and send the caps downstream. This function can be used by subclasses when they have already negotiated their caps but found a change in them (or computed new informations). This way, they can notify downstream about that change without loosing any buffer.
Since: 1.6
#define GST_BASE_TRANSFORM_SINK_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)
Gives the pointer to the sink GstPad object of the element.
#define GST_BASE_TRANSFORM_SRC_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->srcpad)
Gives the pointer to the source GstPad object of the element.
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); /** * GstBaseTransformClass::transform_size: * @othersize: (out): */ gboolean (*transform_size) (GstBaseTransform *trans, GstPadDirection direction, GstCaps *caps, gsize size, GstCaps *othercaps, gsize *othersize); /** * GstBaseTransformClass::get_unit_size: * @size: (out): */ 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); /** * GstBaseTransformClass::prepare_output_buffer: * @outbuf: (out): */ 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); GstFlowReturn (*submit_input_buffer) (GstBaseTransform *trans, gboolean is_discont, GstBuffer *input); /** * GstBaseTransformClass::generate_output: * @outbuf: (out): */ GstFlowReturn (*generate_output) (GstBaseTransform *trans, GstBuffer **outbuf); };
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
.
gboolean |
If set to |
|
gboolean |
If set to |
|
Optional. Given the pad in this direction and the given caps, what caps are allowed on the other pad in this element ? |
||
Optional. Given the pad in this direction and the given
caps, fixate the caps on the other pad. The function takes
ownership of |
||
Optional.
Subclasses can override this method to check if |
||
allows the subclass to be notified of the actual caps set. |
||
Optional. Handle a requested query. Subclasses that implement this should must chain up to the parent if they didn't handle the query |
||
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 a |
||
Return |
||
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 |
||
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. |
||
Required if the transform is not in-place. get the size in bytes of one unit for the given caps. |
||
Optional. Called when the element starts processing. Allows opening external resources. |
||
Optional. Called when the element stops processing. Allows closing external resources. |
||
Optional. Event handler on the sink pad. The default implementation handles the event and forwards it downstream. |
||
Optional. Event handler on the source pad. The default implementation handles the event and forwards it upstream. |
||
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. |
||
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. |
||
Optional. Transform the metadata on the input buffer to the
output buffer. By default this method copies all meta without
tags. subclasses can implement this method and return |
||
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. |
||
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. |
||
Required if the element operates in-place. Transform the incoming buffer in-place. |
||
Function which accepts a new input buffer and pre-processes it.
The default implementation performs caps (re)negotiation, then
QoS if needed, and places the input buffer into the |
||
Called after each new input buffer is submitted repeatedly
until it either generates an error or fails to generate an output
buffer. The default implementation takes the contents of the
|
#define GST_BASE_TRANSFORM_SINK_NAME "sink"
The name of the templates for the sink pad.
#define GST_BASE_TRANSFORM_SRC_NAME "src"
The name of the templates for the source pad.
#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.
“qos”
property“qos” gboolean
Handle Quality-of-Service events.
Flags: Read / Write
Default value: FALSE