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
81 * GST_BASE_TRANSFORM_LOCK:
82 * @obj: base transform instance
84 * Obtain a lock to protect the transform function from concurrent access.
88 #define GST_BASE_TRANSFORM_LOCK(obj) g_mutex_lock (GST_BASE_TRANSFORM_CAST (obj)->transform_lock)
91 * GST_BASE_TRANSFORM_UNLOCK:
92 * @obj: base transform instance
94 * Release the lock that protects the transform function from concurrent access.
98 #define GST_BASE_TRANSFORM_UNLOCK(obj) g_mutex_unlock (GST_BASE_TRANSFORM_CAST (obj)->transform_lock)
100 typedef struct _GstBaseTransform GstBaseTransform;
101 typedef struct _GstBaseTransformClass GstBaseTransformClass;
102 typedef struct _GstBaseTransformPrivate GstBaseTransformPrivate;
106 * @element: the parent element.
108 * The opaque #GstBaseTransform data structure.
110 struct _GstBaseTransform {
114 /* source and sink pads */
118 /* Set by sub-class */
119 gboolean passthrough;
120 gboolean always_in_place;
122 GstCaps *cache_caps1;
123 guint cache_caps1_size;
124 GstCaps *cache_caps2;
125 guint cache_caps2_size;
126 gboolean have_same_caps;
128 gboolean delay_configure;
129 gboolean pending_configure;
132 gboolean have_newsegment;
134 /* MT-protected (with STREAM_LOCK) */
137 GMutex *transform_lock;
140 GstBaseTransformPrivate *priv;
142 gpointer _gst_reserved[GST_PADDING_LARGE - 1];
146 * GstBaseTransformClass:
147 * @transform_caps: Optional. Given the pad in this direction and the given
148 * caps, what caps are allowed on the other pad in this
150 * @fixate_caps: Optional. Given the pad in this direction and the given
151 * caps, fixate the caps on the other pad.
152 * @transform_size: Optional. Given the size of a buffer in the given direction
153 * with the given caps, calculate the size in bytes of a buffer
154 * on the other pad with the given other caps.
155 * The default implementation uses get_unit_size and keeps
156 * the number of units the same.
157 * @get_unit_size: Required if the transform is not in-place.
158 * get the size in bytes of one unit for the given caps.
159 * @set_caps: allows the subclass to be notified of the actual caps set.
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 * @transform: Required if the element does not operate in-place.
167 * Transforms one incoming buffer to one outgoing buffer.
168 * The function is allowed to change size/timestamp/duration
169 * of the outgoing buffer.
170 * @transform_ip: Required if the element operates in-place.
171 * Transform the incoming buffer in-place.
173 * Event handler on the sink pad. This function should return
174 * TRUE if the base class should forward the event.
175 * @src_event: Optional.
176 * Event handler on the source pad.
177 * @passthrough_on_same_caps: If set to TRUE, passthrough mode will be
178 * automatically enabled if the caps are the same.
179 * @prepare_output_buffer: Optional.
180 * Subclasses can override this to do their own
181 * allocation of output buffers. Elements that only do
182 * analysis can return a subbuffer or even just
183 * increment the reference to the input buffer (if in
186 * Subclasses can override any of the available virtual methods or not, as
187 * needed. At minimum either @transform or @transform_ip need to be overridden.
188 * If the element can overwrite the input data with the results (data is of the
189 * same type and quantity) it should provide @transform_ip.
191 struct _GstBaseTransformClass {
192 GstElementClass parent_class;
195 /* virtual methods for subclasses */
197 GstCaps* (*transform_caps) (GstBaseTransform *trans,
198 GstPadDirection direction,
201 void (*fixate_caps) (GstBaseTransform *trans,
202 GstPadDirection direction, GstCaps *caps,
205 gboolean (*transform_size) (GstBaseTransform *trans,
206 GstPadDirection direction,
207 GstCaps *caps, guint size,
208 GstCaps *othercaps, guint *othersize);
210 gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps,
213 gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,
216 gboolean (*start) (GstBaseTransform *trans);
217 gboolean (*stop) (GstBaseTransform *trans);
219 gboolean (*event) (GstBaseTransform *trans, GstEvent *event);
221 GstFlowReturn (*transform) (GstBaseTransform *trans, GstBuffer *inbuf,
223 GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
225 /* FIXME: When adjusting the padding, move these to nicer places in the class */
226 gboolean passthrough_on_same_caps;
228 GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
229 GstBuffer *input, gint size, GstCaps *caps, GstBuffer **buf);
232 gboolean (*src_event) (GstBaseTransform *trans, GstEvent *event);
235 gpointer _gst_reserved[GST_PADDING_LARGE - 1];
238 GType gst_base_transform_get_type (void);
240 void gst_base_transform_set_passthrough (GstBaseTransform *trans,
241 gboolean passthrough);
242 gboolean gst_base_transform_is_passthrough (GstBaseTransform *trans);
244 void gst_base_transform_set_in_place (GstBaseTransform *trans,
246 gboolean gst_base_transform_is_in_place (GstBaseTransform *trans);
248 void gst_base_transform_update_qos (GstBaseTransform *trans,
250 GstClockTimeDiff diff,
251 GstClockTime timestamp);
252 void gst_base_transform_set_qos_enabled (GstBaseTransform *trans,
254 gboolean gst_base_transform_is_qos_enabled (GstBaseTransform *trans);
256 void gst_base_transform_set_gap_aware (GstBaseTransform *trans,
259 void gst_base_transform_suggest (GstBaseTransform *trans,
260 GstCaps *caps, guint size);
263 #endif /* __GST_BASE_TRANSFORM_H__ */