base: use correct syntax in documentation more consistently
[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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, 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 #define GST_BASE_TRANSFORM_CAST(obj)    ((GstBaseTransform *)(obj))
35
36 /**
37  * GST_BASE_TRANSFORM_SINK_NAME:
38  *
39  * The name of the templates for the sink pad.
40  */
41 #define GST_BASE_TRANSFORM_SINK_NAME    "sink"
42 /**
43  * GST_BASE_TRANSFORM_SRC_NAME:
44  *
45  * The name of the templates for the source pad.
46  */
47 #define GST_BASE_TRANSFORM_SRC_NAME     "src"
48
49 /**
50  * GST_BASE_TRANSFORM_SRC_PAD:
51  * @obj: base transform instance
52  *
53  * Gives the pointer to the source #GstPad object of the element.
54  */
55 #define GST_BASE_TRANSFORM_SRC_PAD(obj)         (GST_BASE_TRANSFORM_CAST (obj)->srcpad)
56
57 /**
58  * GST_BASE_TRANSFORM_SINK_PAD:
59  * @obj: base transform instance
60  *
61  * Gives the pointer to the sink #GstPad object of the element.
62  */
63 #define GST_BASE_TRANSFORM_SINK_PAD(obj)        (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)
64
65 /**
66  * GST_BASE_TRANSFORM_FLOW_DROPPED:
67  *
68  * A #GstFlowReturn that can be returned from transform and transform_ip to
69  * indicate that no output buffer was generated.
70  */
71 #define GST_BASE_TRANSFORM_FLOW_DROPPED   GST_FLOW_CUSTOM_SUCCESS
72
73 typedef struct _GstBaseTransform GstBaseTransform;
74 typedef struct _GstBaseTransformClass GstBaseTransformClass;
75 typedef struct _GstBaseTransformPrivate GstBaseTransformPrivate;
76
77 /**
78  * GstBaseTransform:
79  *
80  * The opaque #GstBaseTransform data structure.
81  */
82 struct _GstBaseTransform {
83   GstElement     element;
84
85   /*< protected >*/
86   /* source and sink pads */
87   GstPad        *sinkpad;
88   GstPad        *srcpad;
89
90   /* MT-protected (with STREAM_LOCK) */
91   gboolean       have_segment;
92   GstSegment     segment;
93
94   /*< private >*/
95   GstBaseTransformPrivate *priv;
96
97   gpointer       _gst_reserved[GST_PADDING_LARGE];
98 };
99
100 /**
101  * GstBaseTransformClass:
102  * @parent_class:   Element parent class
103  * @passthrough_on_same_caps: If set to %TRUE, passthrough mode will be
104  *                            automatically enabled if the caps are the same.
105  *                            Set to %FALSE by default.
106  * @transform_ip_on_passthrough: If set to %TRUE, @transform_ip will be called in
107  *                           passthrough mode. The passed buffer might not be
108  *                           writable. When %FALSE, neither @transform nor
109  *                           @transform_ip will be called in passthrough mode.
110  *                           Set to %TRUE by default.
111  * @transform_caps: Optional.  Given the pad in this direction and the given
112  *                  caps, what caps are allowed on the other pad in this
113  *                  element ?
114  * @fixate_caps:    Optional. Given the pad in this direction and the given
115  *                  caps, fixate the caps on the other pad. The function takes
116  *                  ownership of @othercaps and returns a fixated version of
117  *                  @othercaps. @othercaps is not guaranteed to be writable.
118  * @accept_caps:    Optional.
119  *                  Subclasses can override this method to check if @caps can be
120  *                  handled by the element. The default implementation might not be
121  *                  the most optimal way to check this in all cases.
122  * @set_caps:       allows the subclass to be notified of the actual caps set.
123  * @query:          Optional.
124  *                  Handle a requested query. Subclasses that implement this
125  *                  should must chain up to the parent if they didn't handle the
126  *                  query
127  * @decide_allocation: Setup the allocation parameters for allocating output
128  *                    buffers. The passed in query contains the result of the
129  *                    downstream allocation query. This function is only called
130  *                    when not operating in passthrough mode. The default
131  *                    implementation will remove all memory dependent metadata.
132  *                    If there is a @filter_meta method implementation, it will
133  *                    be called for all metadata API in the downstream query,
134  *                    otherwise the metadata API is removed.
135  * @filter_meta: Return %TRUE if the metadata API should be proposed in the
136  *               upstream allocation query. The default implementation is %NULL
137  *               and will cause all metadata to be removed.
138  * @propose_allocation: Propose buffer allocation parameters for upstream elements.
139  *                      This function must be implemented if the element reads or
140  *                      writes the buffer content. The query that was passed to
141  *                      the decide_allocation is passed in this method (or %NULL
142  *                      when the element is in passthrough mode). The default
143  *                      implementation will pass the query downstream when in
144  *                      passthrough mode and will copy all the filtered metadata
145  *                      API in non-passthrough mode.
146  * @transform_size: Optional. Given the size of a buffer in the given direction
147  *                  with the given caps, calculate the size in bytes of a buffer
148  *                  on the other pad with the given other caps.
149  *                  The default implementation uses get_unit_size and keeps
150  *                  the number of units the same.
151  * @get_unit_size:  Required if the transform is not in-place.
152  *                  get the size in bytes of one unit for the given caps.
153  * @start:          Optional.
154  *                  Called when the element starts processing.
155  *                  Allows opening external resources.
156  * @stop:           Optional.
157  *                  Called when the element stops processing.
158  *                  Allows closing external resources.
159  * @sink_event:     Optional.
160  *                  Event handler on the sink pad. The default implementation
161  *                  handles the event and forwards it downstream.
162  * @src_event:      Optional.
163  *                  Event handler on the source pad. The default implementation
164  *                  handles the event and forwards it upstream.
165  * @prepare_output_buffer: Optional.
166  *                         Subclasses can override this to do their own
167  *                         allocation of output buffers.  Elements that only do
168  *                         analysis can return a subbuffer or even just
169  *                         return a reference to the input buffer (if in
170  *                         passthrough mode). The default implementation will
171  *                         use the negotiated allocator or bufferpool and
172  *                         transform_size to allocate an output buffer or it
173  *                         will return the input buffer in passthrough mode.
174  * @copy_metadata: Optional.
175  *                 Copy the metadata from the input buffer to the output buffer.
176  *                 The default implementation will copy the flags, timestamps and
177  *                 offsets of the buffer.
178  * @transform_meta: Optional. Transform the metadata on the input buffer to the
179  *                  output buffer. By default this method is %NULL and no
180  *                  metadata is copied. subclasses can implement this method and
181  *                  return %TRUE if the metadata is to be copied.
182  * @before_transform: Optional.
183  *                    This method is called right before the base class will
184  *                    start processing. Dynamic properties or other delayed
185  *                    configuration could be performed in this method.
186  * @transform:      Required if the element does not operate in-place.
187  *                  Transforms one incoming buffer to one outgoing buffer.
188  *                  The function is allowed to change size/timestamp/duration
189  *                  of the outgoing buffer.
190  * @transform_ip:   Required if the element operates in-place.
191  *                  Transform the incoming buffer in-place.
192  *
193  * Subclasses can override any of the available virtual methods or not, as
194  * needed. At minimum either @transform or @transform_ip need to be overridden.
195  * If the element can overwrite the input data with the results (data is of the
196  * same type and quantity) it should provide @transform_ip.
197  */
198 struct _GstBaseTransformClass {
199   GstElementClass parent_class;
200
201   /*< public >*/
202   gboolean       passthrough_on_same_caps;
203   gboolean       transform_ip_on_passthrough;
204
205   /* virtual methods for subclasses */
206   GstCaps*      (*transform_caps) (GstBaseTransform *trans,
207                                    GstPadDirection direction,
208                                    GstCaps *caps, GstCaps *filter);
209   GstCaps*      (*fixate_caps)    (GstBaseTransform *trans,
210                                    GstPadDirection direction, GstCaps *caps,
211                                    GstCaps *othercaps);
212   gboolean      (*accept_caps)    (GstBaseTransform *trans, GstPadDirection direction,
213                                    GstCaps *caps);
214   gboolean      (*set_caps)       (GstBaseTransform *trans, GstCaps *incaps,
215                                    GstCaps *outcaps);
216   gboolean      (*query)          (GstBaseTransform *trans, GstPadDirection direction,
217                                    GstQuery *query);
218
219   /* decide allocation query for output buffers */
220   gboolean      (*decide_allocation)  (GstBaseTransform *trans, GstQuery *query);
221   gboolean      (*filter_meta)        (GstBaseTransform *trans, GstQuery *query,
222                                        GType api, const GstStructure *params);
223
224   /* propose allocation query parameters for input buffers */
225   gboolean      (*propose_allocation) (GstBaseTransform *trans, GstQuery *decide_query,
226                                        GstQuery *query);
227
228   /* transform size */
229   gboolean      (*transform_size) (GstBaseTransform *trans,
230                                    GstPadDirection direction,
231                                    GstCaps *caps, gsize size,
232                                    GstCaps *othercaps, gsize *othersize);
233
234   gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
235                                    gsize *size);
236
237   /* states */
238   gboolean      (*start)        (GstBaseTransform *trans);
239   gboolean      (*stop)         (GstBaseTransform *trans);
240
241   /* sink and src pad event handlers */
242   gboolean      (*sink_event)   (GstBaseTransform *trans, GstEvent *event);
243   gboolean      (*src_event)    (GstBaseTransform *trans, GstEvent *event);
244
245   GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
246                                           GstBuffer *input, GstBuffer **outbuf);
247
248   /* metadata */
249   gboolean      (*copy_metadata)     (GstBaseTransform *trans, GstBuffer *input,
250                                       GstBuffer *outbuf);
251   gboolean      (*transform_meta)    (GstBaseTransform *trans, GstBuffer *outbuf,
252                                       GstMeta *meta, GstBuffer *inbuf);
253
254   void          (*before_transform)  (GstBaseTransform *trans, GstBuffer *buffer);
255
256   /* transform */
257   GstFlowReturn (*transform)    (GstBaseTransform *trans, GstBuffer *inbuf,
258                                  GstBuffer *outbuf);
259   GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
260
261   /*< private >*/
262   gpointer       _gst_reserved[GST_PADDING_LARGE];
263 };
264
265 GType           gst_base_transform_get_type         (void);
266
267 void            gst_base_transform_set_passthrough  (GstBaseTransform *trans,
268                                                      gboolean passthrough);
269 gboolean        gst_base_transform_is_passthrough   (GstBaseTransform *trans);
270
271 void            gst_base_transform_set_in_place     (GstBaseTransform *trans,
272                                                      gboolean in_place);
273 gboolean        gst_base_transform_is_in_place      (GstBaseTransform *trans);
274
275 void            gst_base_transform_update_qos       (GstBaseTransform *trans,
276                                                      gdouble proportion,
277                                                      GstClockTimeDiff diff,
278                                                      GstClockTime timestamp);
279 void            gst_base_transform_set_qos_enabled  (GstBaseTransform *trans,
280                                                      gboolean enabled);
281 gboolean        gst_base_transform_is_qos_enabled   (GstBaseTransform *trans);
282
283 void            gst_base_transform_set_gap_aware    (GstBaseTransform *trans,
284                                                      gboolean gap_aware);
285
286 void            gst_base_transform_set_prefer_passthrough (GstBaseTransform *trans,
287                                                            gboolean prefer_passthrough);
288
289 GstBufferPool * gst_base_transform_get_buffer_pool  (GstBaseTransform *trans);
290 void            gst_base_transform_get_allocator    (GstBaseTransform *trans,
291                                                      GstAllocator **allocator,
292                                                      GstAllocationParams *params);
293
294 void            gst_base_transform_reconfigure_sink (GstBaseTransform *trans);
295 void            gst_base_transform_reconfigure_src  (GstBaseTransform *trans);
296 G_END_DECLS
297
298 #endif /* __GST_BASE_TRANSFORM_H__ */