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;
86 * @element: the parent element.
88 * The opaque #GstBaseTransform data structure.
90 struct _GstBaseTransform {
94 /* source and sink pads */
98 /* Set by sub-class */
100 gboolean always_in_place;
102 GstCaps *cache_caps1;
103 guint cache_caps1_size;
104 GstCaps *cache_caps2;
105 guint cache_caps2_size;
106 gboolean have_same_caps;
108 gboolean delay_configure;
109 gboolean pending_configure;
112 gboolean have_newsegment;
114 /* MT-protected (with STREAM_LOCK) */
117 GMutex *transform_lock;
120 GstBaseTransformPrivate *priv;
122 gpointer _gst_reserved[GST_PADDING_LARGE - 1];
126 * GstBaseTransformClass:
127 * @transform_caps: Optional. given the pad in this direction and the given
128 * caps, what caps are allowed on the other pad in this
130 * @fixate_caps: Optional. Given the pad in this direction and the given
131 * caps, fixate the caps on the other pad.
132 * @transform_size: Optional. given the size of a buffer in the given direction
133 * with the given caps, calculate the size in bytes of a buffer
134 * on the other pad with the given other caps.
135 * The default implementation uses get_unit_size and keeps
136 * the number of units the same.
137 * @get_unit_size: Required if the transform is not in-place.
138 * get the size in bytes of one unit for the given caps.
139 * @set_caps: allows the subclass to be notified of the actual caps set.
141 * Called when the element starts processing.
142 * Allows opening external resources.
144 * Called when the element stops processing.
145 * Allows closing external resources.
146 * @transform: Required if the element does not operate in-place.
147 * Transforms one incoming buffer to one outgoing buffer.
148 * The function is allowed to change size/timestamp/duration
149 * of the outgoing buffer.
150 * @transform_ip: Required if the element operates in-place.
151 * Transform the incoming buffer in-place.
153 * Event handler on the sink pad.
154 * @src_event: Optional.
155 * Event handler on the source pad.
156 * @passthrough_on_same_caps: If set to TRUE, passthrough mode will be
157 * automatically enabled if the caps are the same.
158 * @prepare_output_buffer: Optional.
159 * Subclasses can override this to do their own
160 * allocation of output buffers. Elements that only do
161 * analysis can return a subbuffer or even just
162 * increment the reference to the input buffer (if in
165 * Subclasses can override any of the available virtual methods or not, as
166 * needed. At minimum either @transform or @transform_ip need to be overridden.
167 * If the element can overwrite the input data with the results (data is of the
168 * same type and quantity) it should provide @transform_ip.
170 struct _GstBaseTransformClass {
171 GstElementClass parent_class;
174 /* virtual methods for subclasses */
176 GstCaps* (*transform_caps) (GstBaseTransform *trans,
177 GstPadDirection direction,
180 void (*fixate_caps) (GstBaseTransform *trans,
181 GstPadDirection direction, GstCaps *caps,
184 gboolean (*transform_size) (GstBaseTransform *trans,
185 GstPadDirection direction,
186 GstCaps *caps, guint size,
187 GstCaps *othercaps, guint *othersize);
189 gboolean (*get_unit_size) (GstBaseTransform *trans, GstCaps *caps,
192 gboolean (*set_caps) (GstBaseTransform *trans, GstCaps *incaps,
195 gboolean (*start) (GstBaseTransform *trans);
196 gboolean (*stop) (GstBaseTransform *trans);
198 gboolean (*event) (GstBaseTransform *trans, GstEvent *event);
200 GstFlowReturn (*transform) (GstBaseTransform *trans, GstBuffer *inbuf,
202 GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
204 /* FIXME: When adjusting the padding, move these to nicer places in the class */
205 gboolean passthrough_on_same_caps;
207 GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
208 GstBuffer *input, gint size, GstCaps *caps, GstBuffer **buf);
211 gboolean (*src_event) (GstBaseTransform *trans, GstEvent *event);
214 gpointer _gst_reserved[GST_PADDING_LARGE - 1];
217 GType gst_base_transform_get_type (void);
219 void gst_base_transform_set_passthrough (GstBaseTransform *trans,
220 gboolean passthrough);
221 gboolean gst_base_transform_is_passthrough (GstBaseTransform *trans);
223 void gst_base_transform_set_in_place (GstBaseTransform *trans,
225 gboolean gst_base_transform_is_in_place (GstBaseTransform *trans);
227 void gst_base_transform_update_qos (GstBaseTransform *trans,
229 GstClockTimeDiff diff,
230 GstClockTime timestamp);
231 void gst_base_transform_set_qos_enabled (GstBaseTransform *trans,
233 gboolean gst_base_transform_is_qos_enabled (GstBaseTransform *trans);
237 #endif /* __GST_BASE_TRANSFORM_H__ */