libs/gst/base/gstbasetransform.*: Add support for dropping buffers with custom GstFlo...
[platform/upstream/gstreamer.git] / libs / gst / base / gstbasetransform.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2005 Wim Taymans <wim@fluendo.com>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #ifndef __GST_BASE_TRANSFORM_H__
22 #define __GST_BASE_TRANSFORM_H__
23
24 #include <gst/gst.h>
25
26 G_BEGIN_DECLS
27
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))
34 /* since 0.10.4 */
35 #define GST_BASE_TRANSFORM_CAST(obj)    ((GstBaseTransform *)(obj))
36
37 /**
38  * GST_BASE_TRANSFORM_SINK_NAME:
39  *
40  * the name of the templates for the sink pad
41  */
42 #define GST_BASE_TRANSFORM_SINK_NAME    "sink"
43 /**
44  * GST_BASE_TRANSFORM_SRC_NAME:
45  *
46  * the name of the templates for the source pad
47  */
48 #define GST_BASE_TRANSFORM_SRC_NAME     "src"
49
50 /**
51  * GST_BASE_TRANSFORM_SRC_PAD:
52  * @obj: base transform instance
53  *
54  * Gives the pointer to the source #GstPad object of the element.
55  *
56  * Since: 0.10.4
57  */
58 #define GST_BASE_TRANSFORM_SRC_PAD(obj)         (GST_BASE_TRANSFORM_CAST (obj)->srcpad)
59
60 /**
61  * GST_BASE_TRANSFORM_SINK_PAD:
62  * @obj: base transform instance
63  *
64  * Gives the pointer to the sink #GstPad object of the element.
65  *
66  * Since: 0.10.4
67  */
68 #define GST_BASE_TRANSFORM_SINK_PAD(obj)        (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)
69
70 /**
71  * GST_BASE_TRANSFORM_FLOW_DROPPED:
72  *
73  * A #GstFlowReturn that can be returned from transform and transform_ip to
74  * indicate that no output buffer was generated.
75  *
76  * Since: 0.10.13
77  */
78 #define GST_BASE_TRANSFORM_FLOW_DROPPED   GST_FLOW_CUSTOM_SUCCESS
79
80 typedef struct _GstBaseTransform GstBaseTransform;
81 typedef struct _GstBaseTransformClass GstBaseTransformClass;
82 typedef struct _GstBaseTransformPrivate GstBaseTransformPrivate;
83
84 /**
85  * GstBaseTransform:
86  * @element: the parent element.
87  *
88  * The opaque #GstBaseTransform data structure.
89  */
90 struct _GstBaseTransform {
91   GstElement     element;
92
93   /*< protected >*/
94   /* source and sink pads */
95   GstPad        *sinkpad;
96   GstPad        *srcpad;
97
98   /* Set by sub-class */
99   gboolean       passthrough;
100   gboolean       always_in_place;
101
102   GstCaps       *cache_caps1;
103   guint          cache_caps1_size;
104   GstCaps       *cache_caps2;
105   guint          cache_caps2_size;
106   gboolean       have_same_caps;
107
108   gboolean       delay_configure;
109   gboolean       pending_configure;
110   gboolean       negotiated;
111
112   gboolean       have_newsegment;
113
114   /* MT-protected (with STREAM_LOCK) */
115   GstSegment     segment;
116
117   GMutex        *transform_lock;
118
119   /*< private >*/
120   GstBaseTransformPrivate *priv;
121
122   gpointer       _gst_reserved[GST_PADDING_LARGE - 1];
123 };
124
125 /**
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
129  *                  element ?
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.
140  * @start:          Optional.
141  *                  Called when the element starts processing.
142  *                  Allows opening external resources.
143  * @stop:           Optional.
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.
152  * @event:          Optional.
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
163  *                         passthrough mode)
164  *
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.
169  */
170 struct _GstBaseTransformClass {
171   GstElementClass parent_class;
172
173   /*< public >*/
174   /* virtual methods for subclasses */
175
176   GstCaps*      (*transform_caps) (GstBaseTransform *trans,
177                                    GstPadDirection direction,
178                                    GstCaps *caps);
179
180   void          (*fixate_caps)    (GstBaseTransform *trans,
181                                    GstPadDirection direction, GstCaps *caps,
182                                    GstCaps *othercaps);
183
184   gboolean      (*transform_size) (GstBaseTransform *trans,
185                                    GstPadDirection direction,
186                                    GstCaps *caps, guint size,
187                                    GstCaps *othercaps, guint *othersize);
188
189   gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
190                                    guint *size);
191
192   gboolean      (*set_caps)     (GstBaseTransform *trans, GstCaps *incaps,
193                                  GstCaps *outcaps);
194
195   gboolean      (*start)        (GstBaseTransform *trans);
196   gboolean      (*stop)         (GstBaseTransform *trans);
197
198   gboolean      (*event)        (GstBaseTransform *trans, GstEvent *event);
199
200   GstFlowReturn (*transform)    (GstBaseTransform *trans, GstBuffer *inbuf,
201                                  GstBuffer *outbuf);
202   GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
203
204   /* FIXME: When adjusting the padding, move these to nicer places in the class */
205   gboolean       passthrough_on_same_caps;
206
207   GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
208      GstBuffer *input, gint size, GstCaps *caps, GstBuffer **buf);
209
210   /* src event */
211   gboolean      (*src_event)      (GstBaseTransform *trans, GstEvent *event);
212
213   /*< private >*/
214   gpointer       _gst_reserved[GST_PADDING_LARGE - 1];
215 };
216
217 GType           gst_base_transform_get_type         (void);
218
219 void            gst_base_transform_set_passthrough  (GstBaseTransform *trans,
220                                                      gboolean passthrough);
221 gboolean        gst_base_transform_is_passthrough   (GstBaseTransform *trans);
222
223 void            gst_base_transform_set_in_place     (GstBaseTransform *trans,
224                                                      gboolean in_place);
225 gboolean        gst_base_transform_is_in_place      (GstBaseTransform *trans);
226
227 void            gst_base_transform_update_qos       (GstBaseTransform *trans,
228                                                      gdouble proportion,
229                                                      GstClockTimeDiff diff,
230                                                      GstClockTime timestamp);
231 void            gst_base_transform_set_qos_enabled  (GstBaseTransform *trans,
232                                                      gboolean enabled);
233 gboolean        gst_base_transform_is_qos_enabled   (GstBaseTransform *trans);
234
235 G_END_DECLS
236
237 #endif /* __GST_BASE_TRANSFORM_H__ */