Fix #333669, Add pad accessor defines for GstBaseTransform
[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) \
32         (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
33 #define GST_IS_BASE_TRANSFORM(obj)      (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_TRANSFORM))
34 #define GST_IS_BASE_TRANSFORM_CLASS(obj)(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_TRANSFORM))
35 /* since 0.10.4 */
36 #define GST_BASE_TRANSFORM_CAST(obj)    ((GstBaseTransform *)(obj))
37
38 /**
39  * GST_BASE_TRANSFORM_SINK_NAME:
40  *
41  * the name of the templates for the sink pad
42  */
43 #define GST_BASE_TRANSFORM_SINK_NAME    "sink"
44 /**
45  * GST_BASE_TRANSFORM_SRC_NAME:
46  *
47  * the name of the templates for the source pad
48  */
49 #define GST_BASE_TRANSFORM_SRC_NAME     "src"
50
51 /**
52  * GST_BASE_TRANSFORM_SRC_PAD:
53  * @obj: base transform instance
54  * 
55  * Gives the pointer to the source #GstPad object of the element.
56  *
57  * Since: 0.10.4
58  */
59 #define GST_BASE_TRANSFORM_SRC_PAD(obj)         (GST_BASE_TRANSFORM_CAST (obj)->srcpad)
60
61 /**
62  * GST_BASE_TRANSFORM_SINK_PAD:
63  * @obj: base transform instance
64  * 
65  * Gives the pointer to the sink #GstPad object of the element.
66  *
67  * Since: 0.10.4
68  */
69 #define GST_BASE_TRANSFORM_SINK_PAD(obj)        (GST_BASE_TRANSFORM_CAST (obj)->sinkpad)
70
71 typedef struct _GstBaseTransform GstBaseTransform;
72 typedef struct _GstBaseTransformClass GstBaseTransformClass;
73
74 /**
75  * GstBaseTransform:
76  * @element: the parent element.
77  *
78  * The opaque #GstBaseTransform data structure.
79  */
80 struct _GstBaseTransform {
81   GstElement     element;
82
83   /*< protected >*/
84   /* source and sink pads */
85   GstPad        *sinkpad;
86   GstPad        *srcpad;
87
88   /* Set by sub-class */
89   gboolean       passthrough;
90   gboolean       always_in_place;
91
92   GstCaps       *cache_caps1;
93   guint          cache_caps1_size;
94   GstCaps       *cache_caps2;
95   guint          cache_caps2_size;
96   gboolean       have_same_caps;
97
98   gboolean       delay_configure;
99   gboolean       pending_configure;
100   gboolean       negotiated;
101
102   gboolean       have_newsegment;
103
104   /* MT-protected (with STREAM_LOCK) */
105   GstSegment     segment;
106
107   GMutex        *transform_lock;
108
109   /*< private >*/
110   gpointer       _gst_reserved[GST_PADDING_LARGE];
111 };
112
113 /**
114  * GstBaseTransformClass::transform_caps:
115  * @direction: the pad direction
116  * @caps: the caps
117  *
118  * This method should answer the question "given this pad, and given these
119  * caps, what caps would you allow on the other pad inside your element ?"
120  */
121 struct _GstBaseTransformClass {
122   GstElementClass parent_class;
123
124   /*< public >*/
125   /* virtual methods for subclasses */
126
127   /* given the (non-)fixed simple caps on the pad in the given direction,
128    * what can I do on the other pad ? */
129   GstCaps*      (*transform_caps) (GstBaseTransform *trans,
130                                    GstPadDirection direction,
131                                    GstCaps *caps);
132
133   /* given caps on one pad, how would you fixate caps on the other pad ? */
134   void          (*fixate_caps)    (GstBaseTransform *trans,
135                                    GstPadDirection direction, GstCaps *caps,
136                                    GstCaps *othercaps);
137
138   /* given the size of a buffer in the given direction with the given caps,
139    * calculate the byte size of an buffer on the other side with the given
140    * other caps; the default
141    * implementation uses get_size and keeps the number of units the same */
142   gboolean      (*transform_size) (GstBaseTransform *trans,
143                                    GstPadDirection direction,
144                                    GstCaps *caps, guint size,
145                                    GstCaps *othercaps, guint *othersize);
146
147   /* get the byte size of one unit for a given caps.
148    * Always needs to be implemented if the transform is not in-place. */
149   gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
150                                    guint *size);
151
152   /* notify the subclass of new caps */
153   gboolean      (*set_caps)     (GstBaseTransform *trans, GstCaps *incaps,
154                                  GstCaps *outcaps);
155
156   /* start and stop processing, ideal for opening/closing the resource */
157   gboolean      (*start)        (GstBaseTransform *trans);
158   gboolean      (*stop)         (GstBaseTransform *trans);
159
160   gboolean      (*event)        (GstBaseTransform *trans, GstEvent *event);
161
162   /* transform one incoming buffer to one outgoing buffer.
163    * Always needs to be implemented unless always operating in-place.
164    * transform function is allowed to change size/timestamp/duration of
165    * the outgoing buffer. */
166   GstFlowReturn (*transform)    (GstBaseTransform *trans, GstBuffer *inbuf,
167                                  GstBuffer *outbuf);
168
169   /* transform a buffer inplace */
170   GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
171
172   /* FIXME: When adjusting the padding, move these to nicer places in the class */
173   /* Set by child classes to automatically do passthrough mode */
174   gboolean       passthrough_on_same_caps;
175
176   /* Subclasses can override this to do their own allocation of output buffers.
177    * Elements that only do analysis can return a subbuffer or even just
178    * increment the reference to the input buffer (if in passthrough mode)
179    */
180   GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
181      GstBuffer *input, gint size, GstCaps *caps, GstBuffer **buf);
182
183   /*< private >*/
184   gpointer       _gst_reserved[GST_PADDING_LARGE];
185 };
186
187 GType           gst_base_transform_get_type         (void);
188
189 void            gst_base_transform_set_passthrough  (GstBaseTransform *trans,
190                                                      gboolean passthrough);
191 gboolean        gst_base_transform_is_passthrough   (GstBaseTransform *trans);
192
193 void            gst_base_transform_set_in_place     (GstBaseTransform *trans,
194                                                      gboolean in_place);
195 gboolean        gst_base_transform_is_in_place      (GstBaseTransform *trans);
196
197
198 G_END_DECLS
199
200 #endif /* __GST_BASE_TRANSFORM_H__ */