2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2005 Wim Taymans <wim@fluendo.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __GST_BASE_TRANSFORM_H__
22 #define __GST_BASE_TRANSFORM_H__
28 #define GST_TYPE_BASE_TRANSFORM (gst_base_transform_get_type())
29 #define GST_BASE_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransform))
30 #define GST_BASE_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
31 #define GST_BASE_TRANSFORM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
32 #define GST_IS_BASE_TRANSFORM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_TRANSFORM))
33 #define GST_IS_BASE_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_TRANSFORM))
35 #define GST_BASE_TRANSFORM_CAST(obj) ((GstBaseTransform *)(obj))
38 * GST_BASE_TRANSFORM_SINK_NAME:
40 * The name of the templates for the sink pad.
42 #define GST_BASE_TRANSFORM_SINK_NAME "sink"
44 * GST_BASE_TRANSFORM_SRC_NAME:
46 * The name of the templates for the source pad.
48 #define GST_BASE_TRANSFORM_SRC_NAME "src"
51 * GST_BASE_TRANSFORM_SRC_PAD:
52 * @obj: base transform instance
54 * Gives the pointer to the source #GstPad object of the element.
58 #define GST_BASE_TRANSFORM_SRC_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->srcpad)
61 * GST_BASE_TRANSFORM_SINK_PAD:
62 * @obj: base transform instance
64 * Gives the pointer to the sink #GstPad object of the element.
68 #define GST_BASE_TRANSFORM_SINK_PAD(obj) (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)
71 * GST_BASE_TRANSFORM_FLOW_DROPPED:
73 * A #GstFlowReturn that can be returned from transform and transform_ip to
74 * indicate that no output buffer was generated.
78 #define GST_BASE_TRANSFORM_FLOW_DROPPED GST_FLOW_CUSTOM_SUCCESS
80 typedef struct _GstBaseTransform GstBaseTransform;
81 typedef struct _GstBaseTransformClass GstBaseTransformClass;
82 typedef struct _GstBaseTransformPrivate GstBaseTransformPrivate;
87 * The opaque #GstBaseTransform data structure.
89 struct _GstBaseTransform {
93 /* source and sink pads */
97 /* MT-protected (with STREAM_LOCK) */
98 gboolean have_segment;
102 GstBaseTransformPrivate *priv;
104 gpointer _gst_reserved[GST_PADDING_LARGE];
108 * GstBaseTransformClass:
109 * @parent_class: Element parent class
110 * @passthrough_on_same_caps: If set to %TRUE, passthrough mode will be
111 * automatically enabled if the caps are the same.
112 * Set to %FALSE by default.
113 * @transform_ip_on_passthrough: If set to %TRUE, @transform_ip will be called in
114 * passthrough mode. The passed buffer might not be
115 * writable. When %FALSE, neither @transform nor
116 * @transform_ip will be called in passthrough mode.
117 * Set to %TRUE by default.
118 * @transform_caps: Optional. Given the pad in this direction and the given
119 * caps, what caps are allowed on the other pad in this
121 * @fixate_caps: Optional. Given the pad in this direction and the given
122 * caps, fixate the caps on the other pad. The function takes
123 * ownership of @othercaps and returns a fixated version of
124 * @othercaps. @othercaps is not guaranteed to be writable.
125 * @accept_caps: Optional. Since 0.10.30
126 * Subclasses can override this method to check if @caps can be
127 * handled by the element. The default implementation might not be
128 * the most optimal way to check this in all cases.
129 * @set_caps: allows the subclass to be notified of the actual caps set.
130 * @query: Optional Since 0.10.36
131 * Handle a requested query. Subclasses that implement this
132 * should must chain up to the parent if they didn't handle the
134 * @decide_allocation: Setup the allocation parameters for allocating output
135 * buffers. The passed in query contains the result of the
136 * downstream allocation query. This function is only called
137 * when not operating in passthrough mode. The default
138 * implementation will remove all memory dependent metadata.
139 * If there is ia @filter_meta method implementation, it will
140 * be called for all metadata API in the downstream query,
141 * otherwise the metadata API is removed.
142 * @filter_meta: Return TRUE if the metadata API should be proposed in the
143 * upstream allocation query. The default implementation is NULL
144 * and will cause all metadata to be removed.
145 * @propose_allocation: Propose buffer allocation parameters for upstream elements.
146 * This function must be implemented if the element reads or
147 * writes the buffer content. The query that was passed to
148 * the decide_allocation is passed in this method (or NULL
149 * when the element is in passthrough mode). The default
150 * implementation will pass the query downstream when in
151 * passthrough mode and will copy all the filtered metadata
152 * API in non-passthrough mode.
153 * @transform_size: Optional. Given the size of a buffer in the given direction
154 * with the given caps, calculate the size in bytes of a buffer
155 * on the other pad with the given other caps.
156 * The default implementation uses get_unit_size and keeps
157 * the number of units the same.
158 * @get_unit_size: Required if the transform is not in-place.
159 * get the size in bytes of one unit for the given caps.
161 * Called when the element starts processing.
162 * Allows opening external resources.
164 * Called when the element stops processing.
165 * Allows closing external resources.
166 * @sink_event: Optional.
167 * Event handler on the sink pad. The default implementation
168 * handles the event and forwards it downstream.
169 * @src_event: Optional.
170 * Event handler on the source pad. The default implementation
171 * handles the event and forwards it upstream.
172 * @prepare_output_buffer: Optional.
173 * Subclasses can override this to do their own
174 * allocation of output buffers. Elements that only do
175 * analysis can return a subbuffer or even just
176 * return a reference to the input buffer (if in
177 * passthrough mode). The default implementation will
178 * use the negotiated allocator or bufferpool and
179 * transform_size to allocate an output buffer or it
180 * will return the input buffer in passthrough mode.
181 * @copy_metadata: Optional.
182 * Copy the metadata from the input buffer to the output buffer.
183 * The default implementation will copy the flags, timestamps and
184 * offsets of the buffer.
185 * @transform_meta: Optional. Transform the metadata on the input buffer to the
186 * output buffer. By default this method is NULL and no
187 * metadata is copied. subclasses can implement this method and
188 * return TRUE if the metadata is to be copied.
189 * @before_transform: Optional. Since 0.10.22
190 * This method is called right before the base class will
191 * start processing. Dynamic properties or other delayed
192 * configuration could be performed in this method.
193 * @transform: Required if the element does not operate in-place.
194 * Transforms one incoming buffer to one outgoing buffer.
195 * The function is allowed to change size/timestamp/duration
196 * of the outgoing buffer.
197 * @transform_ip: Required if the element operates in-place.
198 * Transform the incoming buffer in-place.
200 * Subclasses can override any of the available virtual methods or not, as
201 * needed. At minimum either @transform or @transform_ip need to be overridden.
202 * If the element can overwrite the input data with the results (data is of the
203 * same type and quantity) it should provide @transform_ip.
205 struct _GstBaseTransformClass {
206 GstElementClass parent_class;
209 gboolean passthrough_on_same_caps;
210 gboolean transform_ip_on_passthrough;
212 /* virtual methods for subclasses */
213 GstCaps* (*transform_caps) (GstBaseTransform *trans,
214 GstPadDirection direction,
215 GstCaps *caps, GstCaps *filter);
216 GstCaps* (*fixate_caps) (GstBaseTransform *trans,
217 GstPadDirection direction, GstCaps *caps,
219 gboolean (*accept_caps) (GstBaseTransform *trans, GstPadDirection direction,
221 gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,
223 gboolean (*query) (GstBaseTransform *trans, GstPadDirection direction,
226 /* decide allocation query for output buffers */
227 gboolean (*decide_allocation) (GstBaseTransform *trans, GstQuery *query);
228 gboolean (*filter_meta) (GstBaseTransform *trans, GstQuery *query, GType api);
230 /* propose allocation query parameters for input buffers */
231 gboolean (*propose_allocation) (GstBaseTransform *trans, GstQuery *decide_query,
235 gboolean (*transform_size) (GstBaseTransform *trans,
236 GstPadDirection direction,
237 GstCaps *caps, gsize size,
238 GstCaps *othercaps, gsize *othersize);
240 gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps,
244 gboolean (*start) (GstBaseTransform *trans);
245 gboolean (*stop) (GstBaseTransform *trans);
247 /* sink and src pad event handlers */
248 gboolean (*sink_event) (GstBaseTransform *trans, GstEvent *event);
249 gboolean (*src_event) (GstBaseTransform *trans, GstEvent *event);
251 GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
252 GstBuffer *input, GstBuffer **outbuf);
255 gboolean (*copy_metadata) (GstBaseTransform *trans, GstBuffer *input,
257 gboolean (*transform_meta) (GstBaseTransform *trans, GstBuffer *outbuf,
258 GstMeta *meta, GstBuffer *inbuf);
260 void (*before_transform) (GstBaseTransform *trans, GstBuffer *buffer);
263 GstFlowReturn (*transform) (GstBaseTransform *trans, GstBuffer *inbuf,
265 GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
268 gpointer _gst_reserved[GST_PADDING_LARGE];
271 GType gst_base_transform_get_type (void);
273 void gst_base_transform_set_passthrough (GstBaseTransform *trans,
274 gboolean passthrough);
275 gboolean gst_base_transform_is_passthrough (GstBaseTransform *trans);
277 void gst_base_transform_set_in_place (GstBaseTransform *trans,
279 gboolean gst_base_transform_is_in_place (GstBaseTransform *trans);
281 void gst_base_transform_update_qos (GstBaseTransform *trans,
283 GstClockTimeDiff diff,
284 GstClockTime timestamp);
285 void gst_base_transform_set_qos_enabled (GstBaseTransform *trans,
287 gboolean gst_base_transform_is_qos_enabled (GstBaseTransform *trans);
289 void gst_base_transform_set_gap_aware (GstBaseTransform *trans,
292 void gst_base_transform_reconfigure_sink (GstBaseTransform *trans);
293 void gst_base_transform_reconfigure_src (GstBaseTransform *trans);
296 #endif /* __GST_BASE_TRANSFORM_H__ */