fixing examples fixing docs typos changing log priority in error situations
[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
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 typedef struct _GstBaseTransform GstBaseTransform;
50 typedef struct _GstBaseTransformClass GstBaseTransformClass;
51
52 struct _GstBaseTransform {
53   GstElement     element;
54
55   /* source and sink pads */
56   GstPad        *sinkpad;
57   GstPad        *srcpad;
58
59   /*< public >*/
60   /* Set by sub-class */
61   gboolean       passthrough;
62   gboolean       always_in_place;
63
64   GstCaps       *cache_caps1;
65   guint          cache_caps1_size;
66   GstCaps       *cache_caps2;
67   guint          cache_caps2_size;
68
69   gboolean       delay_configure;
70   gboolean       pending_configure;
71   gboolean       negotiated;
72
73   gboolean       have_newsegment;
74
75   /* MT-protected (with STREAM_LOCK) */
76   gdouble        segment_rate;
77   gint64         segment_start;
78   gint64         segment_stop;
79   gint64         segment_base;
80
81   /* FIXME: When adjusting the padding, move this to a nice place in the structure */
82   /* Set if caps on each pad are equal */
83   gboolean       have_same_caps;
84
85   /*< private >*/
86   gpointer       _gst_reserved[GST_PADDING - 1];
87 };
88
89 /**
90  * GstBaseTransformClass::transform_caps:
91  * @direction: the pad direction
92  * @caps: the caps
93  *
94  * This method should answer the question "given this pad, and given these
95  * caps, what caps would you allow on the other pad inside your element ?"
96  */
97 struct _GstBaseTransformClass {
98   GstElementClass parent_class;
99
100   /*< public >*/
101   /* virtual methods for subclasses */
102
103   /* given the (non-)fixed simple caps on the pad in the given direction,
104    * what can I do on the other pad ? */
105   GstCaps*      (*transform_caps) (GstBaseTransform *trans,
106                                    GstPadDirection direction,
107                                    GstCaps *caps);
108
109   /* given caps on one pad, how would you fixate caps on the other pad ? */
110   void          (*fixate_caps)    (GstBaseTransform *trans,
111                                    GstPadDirection direction, GstCaps *caps,
112                                    GstCaps *othercaps);
113
114   /* given the size of a buffer in the given direction with the given caps,
115    * calculate the byte size of an buffer on the other side with the given
116    * other caps; the default
117    * implementation uses get_size and keeps the number of units the same */
118   gboolean      (*transform_size) (GstBaseTransform *trans,
119                                    GstPadDirection direction,
120                                    GstCaps *caps, guint size,
121                                    GstCaps *othercaps, guint *othersize);
122
123   /* get the byte size of one unit for a given caps.
124    * Always needs to be implemented if the transform is not in-place. */
125   gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
126                                    guint *size);
127
128   /* notify the subclass of new caps */
129   gboolean      (*set_caps)     (GstBaseTransform *trans, GstCaps *incaps,
130                                  GstCaps *outcaps);
131
132   /* start and stop processing, ideal for opening/closing the resource */
133   gboolean      (*start)        (GstBaseTransform *trans);
134   gboolean      (*stop)         (GstBaseTransform *trans);
135
136   gboolean      (*event)        (GstBaseTransform *trans, GstEvent *event);
137
138   /* transform one incoming buffer to one outgoing buffer.
139    * Always needs to be implemented unless always operating in-place.
140    * transform function is allowed to change size/timestamp/duration of
141    * the outgoing buffer. */
142   GstFlowReturn (*transform)    (GstBaseTransform *trans, GstBuffer *inbuf,
143                                  GstBuffer *outbuf);
144
145   /* transform a buffer inplace */
146   GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
147
148   /* FIXME: When adjusting the padding, more these to nicer places in the class */
149   /* Set by child classes to automatically do passthrough mode */
150   gboolean       passthrough_on_same_caps;
151
152   /* Subclasses can override this to do their own allocation of output buffers.
153    * Elements that only do analysis can return a subbuffer or even just
154    * increment the reference to the input buffer (if in passthrough mode)
155    */
156   GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
157      GstBuffer *input, gint size, GstCaps *caps, GstBuffer **buf);
158
159   /*< private >*/
160   gpointer       _gst_reserved[GST_PADDING - 2];
161 };
162
163 void            gst_base_transform_set_passthrough (GstBaseTransform *trans,
164                     gboolean passthrough);
165 gboolean        gst_base_transform_is_passthrough (GstBaseTransform *trans);
166
167 void            gst_base_transform_set_in_place (GstBaseTransform *trans,
168                     gboolean in_place);
169 gboolean        gst_base_transform_is_in_place (GstBaseTransform *trans);
170
171 GType gst_base_transform_get_type (void);
172
173 G_END_DECLS
174
175 #endif /* __GST_BASE_TRANSFORM_H__ */