gstbasetransform.h 12.4 KB
Newer Older
Wim Taymans's avatar
Wim Taymans committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2005 Wim Taymans <wim@fluendo.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#ifndef __GST_BASE_TRANSFORM_H__
#define __GST_BASE_TRANSFORM_H__

#include <gst/gst.h>

G_BEGIN_DECLS

Stefan Kost's avatar
Stefan Kost committed
28 29 30 31 32 33
#define GST_TYPE_BASE_TRANSFORM		   (gst_base_transform_get_type())
#define GST_BASE_TRANSFORM(obj)		   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransform))
#define GST_BASE_TRANSFORM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
#define GST_BASE_TRANSFORM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_TRANSFORM,GstBaseTransformClass))
#define GST_IS_BASE_TRANSFORM(obj)	   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_TRANSFORM))
#define GST_IS_BASE_TRANSFORM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_TRANSFORM))
34 35
/* since 0.10.4 */
#define GST_BASE_TRANSFORM_CAST(obj)	((GstBaseTransform *)(obj))
Wim Taymans's avatar
Wim Taymans committed
36

Stefan Kost's avatar
Stefan Kost committed
37 38 39
/**
 * GST_BASE_TRANSFORM_SINK_NAME:
 *
40
 * The name of the templates for the sink pad.
Stefan Kost's avatar
Stefan Kost committed
41
 */
Wim Taymans's avatar
Wim Taymans committed
42
#define GST_BASE_TRANSFORM_SINK_NAME	"sink"
Stefan Kost's avatar
Stefan Kost committed
43 44 45
/**
 * GST_BASE_TRANSFORM_SRC_NAME:
 *
46
 * The name of the templates for the source pad.
Stefan Kost's avatar
Stefan Kost committed
47
 */
Wim Taymans's avatar
Wim Taymans committed
48 49
#define GST_BASE_TRANSFORM_SRC_NAME	"src"

50 51 52
/**
 * GST_BASE_TRANSFORM_SRC_PAD:
 * @obj: base transform instance
53
 *
54 55 56 57 58 59 60 61 62
 * Gives the pointer to the source #GstPad object of the element.
 *
 * Since: 0.10.4
 */
#define GST_BASE_TRANSFORM_SRC_PAD(obj)		(GST_BASE_TRANSFORM_CAST (obj)->srcpad)

/**
 * GST_BASE_TRANSFORM_SINK_PAD:
 * @obj: base transform instance
63
 *
64 65 66 67 68 69
 * Gives the pointer to the sink #GstPad object of the element.
 *
 * Since: 0.10.4
 */
#define GST_BASE_TRANSFORM_SINK_PAD(obj)	(GST_BASE_TRANSFORM_CAST (obj)->sinkpad)

70 71 72 73 74 75 76 77 78 79
/**
 * GST_BASE_TRANSFORM_FLOW_DROPPED:
 *
 * A #GstFlowReturn that can be returned from transform and transform_ip to
 * indicate that no output buffer was generated.
 *
 * Since: 0.10.13
 */
#define GST_BASE_TRANSFORM_FLOW_DROPPED   GST_FLOW_CUSTOM_SUCCESS

80 81 82 83 84 85 86 87
/**
 * GST_BASE_TRANSFORM_LOCK:
 * @obj: base transform instance
 *
 * Obtain a lock to protect the transform function from concurrent access.
 *
 * Since: 0.10.13
 */
88
#define GST_BASE_TRANSFORM_LOCK(obj)   g_mutex_lock (GST_BASE_TRANSFORM_CAST (obj)->transform_lock)
89 90 91 92 93 94 95 96 97

/**
 * GST_BASE_TRANSFORM_UNLOCK:
 * @obj: base transform instance
 *
 * Release the lock that protects the transform function from concurrent access.
 *
 * Since: 0.10.13
 */
98
#define GST_BASE_TRANSFORM_UNLOCK(obj) g_mutex_unlock (GST_BASE_TRANSFORM_CAST (obj)->transform_lock)
99

Wim Taymans's avatar
Wim Taymans committed
100 101
typedef struct _GstBaseTransform GstBaseTransform;
typedef struct _GstBaseTransformClass GstBaseTransformClass;
102 103
typedef struct _GstBaseTransformPrivate GstBaseTransformPrivate;

Wim Taymans's avatar
Wim Taymans committed
104 105 106 107 108
/**
 * GstBaseTransform:
 *
 * The opaque #GstBaseTransform data structure.
 */
Wim Taymans's avatar
Wim Taymans committed
109
struct _GstBaseTransform {
110
  GstElement	 element;
Wim Taymans's avatar
Wim Taymans committed
111

Wim Taymans's avatar
Wim Taymans committed
112
  /*< protected >*/
Wim Taymans's avatar
Wim Taymans committed
113
  /* source and sink pads */
114 115
  GstPad	*sinkpad;
  GstPad	*srcpad;
116

117
  /* Set by sub-class */
118
  gboolean	 passthrough;
119
  gboolean	 always_in_place;
120

121
  GstCaps	*cache_caps1;
122
  gsize		 cache_caps1_size;
123
  GstCaps	*cache_caps2;
124
  gsize		 cache_caps2_size;
125
  gboolean	 have_same_caps;
126

127
  gboolean	 negotiated;
128

Wim Taymans's avatar
Wim Taymans committed
129
  gboolean       have_segment;
130

131
  /* MT-protected (with STREAM_LOCK) */
132 133 134 135 136
  GstSegment     segment;

  GMutex	*transform_lock;

  /*< private >*/
137 138
  GstBaseTransformPrivate *priv;

Wim Taymans's avatar
Wim Taymans committed
139
  gpointer       _gst_reserved[GST_PADDING_LARGE];
Wim Taymans's avatar
Wim Taymans committed
140 141
};

142
/**
143
 * GstBaseTransformClass:
Stefan Kost's avatar
Stefan Kost committed
144
 * @parent_class:   Element parent class
145 146
 * @passthrough_on_same_caps: If set to TRUE, passthrough mode will be
 *                            automatically enabled if the caps are the same.
147
 * @transform_caps: Optional.  Given the pad in this direction and the given
148 149 150 151
 *                  caps, what caps are allowed on the other pad in this
 *                  element ?
 * @fixate_caps:    Optional. Given the pad in this direction and the given
 *                  caps, fixate the caps on the other pad.
152 153 154 155 156
 * @accept_caps:    Optional. Since 0.10.30
 *                  Subclasses can override this method to check if @caps can be
 *                  handled by the element. The default implementation might not be
 *                  the most optimal way to check this in all cases.
 * @set_caps:       allows the subclass to be notified of the actual caps set.
Wim Taymans's avatar
Wim Taymans committed
157 158 159 160
 * @query:          Optional Since 0.10.36
 *                  Handle a requested query. Subclasses that implement this
 *                  should must chain up to the parent if they didn't handle the
 *                  query
Wim Taymans's avatar
Wim Taymans committed
161
 * @propose_allocation: Propose buffer allocation parameters for upstream elements.
162 163
 *                      This function must be implemented if the element reads or
 *                      writes the buffer content. The default implementation is NULL.
Wim Taymans's avatar
Wim Taymans committed
164
 * @decide_allocation: Setup the allocation parameters for allocating output
165 166
 *                    buffers. The passed in query contains the result of the
 *                    downstream allocation query. This function is only called
167 168
 *                    when not operating in passthrough mode. The default
 *                    implementation is NULL.
169
 * @transform_size: Optional. Given the size of a buffer in the given direction
170 171 172 173 174 175 176 177 178 179 180 181
 *                  with the given caps, calculate the size in bytes of a buffer
 *                  on the other pad with the given other caps.
 *                  The default implementation uses get_unit_size and keeps
 *                  the number of units the same.
 * @get_unit_size:  Required if the transform is not in-place.
 *                  get the size in bytes of one unit for the given caps.
 * @start:          Optional.
 *                  Called when the element starts processing.
 *                  Allows opening external resources.
 * @stop:           Optional.
 *                  Called when the element stops processing.
 *                  Allows closing external resources.
182 183 184
 * @sink_event:     Optional.
 *                  Event handler on the sink pad. The default implementation
 *                  handles the event and forwards it downstream.
185
 * @src_event:      Optional.
186 187
 *                  Event handler on the source pad. The default implementation
 *                  handles the event and forwards it upstream.
188 189 190 191
 * @prepare_output_buffer: Optional.
 *                         Subclasses can override this to do their own
 *                         allocation of output buffers.  Elements that only do
 *                         analysis can return a subbuffer or even just
192
 *                         return a reference to the input buffer (if in
193 194
 *                         passthrough mode). The default implementation will
 *                         use the negotiated allocator or bufferpool and
195 196
 *                         transform_size to allocate an output buffer or it
 *                         will return the input buffer in passthrough mode.
197 198 199 200
 * @copy_metadata: Optional.
 *                 Copy the metadata from the input buffer to the output buffer.
 *                 The default implementation will copy the flags, timestamps and
 *                 offsets of the buffer.
201 202 203 204
 * @before_transform: Optional. Since 0.10.22
 *                    This method is called right before the base class will
 *                    start processing. Dynamic properties or other delayed
 *                    configuration could be performed in this method.
205 206 207 208 209 210
 * @transform:      Required if the element does not operate in-place.
 *                  Transforms one incoming buffer to one outgoing buffer.
 *                  The function is allowed to change size/timestamp/duration
 *                  of the outgoing buffer.
 * @transform_ip:   Required if the element operates in-place.
 *                  Transform the incoming buffer in-place.
211 212 213 214 215
 *
 * Subclasses can override any of the available virtual methods or not, as
 * needed. At minimum either @transform or @transform_ip need to be overridden.
 * If the element can overwrite the input data with the results (data is of the
 * same type and quantity) it should provide @transform_ip.
216
 */
Wim Taymans's avatar
Wim Taymans committed
217 218 219
struct _GstBaseTransformClass {
  GstElementClass parent_class;

220
  /*< public >*/
Wim Taymans's avatar
Wim Taymans committed
221
  gboolean       passthrough_on_same_caps;
222

Wim Taymans's avatar
Wim Taymans committed
223
  /* virtual methods for subclasses */
224 225
  GstCaps*	(*transform_caps) (GstBaseTransform *trans,
                                   GstPadDirection direction,
226
                                   GstCaps *caps, GstCaps *filter);
227 228 229
  void		(*fixate_caps)	  (GstBaseTransform *trans,
                                   GstPadDirection direction, GstCaps *caps,
                                   GstCaps *othercaps);
Wim Taymans's avatar
Wim Taymans committed
230 231 232 233
  gboolean      (*accept_caps)    (GstBaseTransform *trans, GstPadDirection direction,
                                   GstCaps *caps);
  gboolean      (*set_caps)       (GstBaseTransform *trans, GstCaps *incaps,
                                   GstCaps *outcaps);
234
  gboolean      (*query)          (GstBaseTransform *trans, GstPadDirection direction,
Wim Taymans's avatar
Wim Taymans committed
235
                                   GstQuery *query);
Wim Taymans's avatar
Wim Taymans committed
236

Wim Taymans's avatar
Wim Taymans committed
237 238 239
  /* propose allocation query parameters for input buffers */
  gboolean      (*propose_allocation) (GstBaseTransform *trans, GstQuery *query);
  /* decide allocation query for output buffers */
240
  gboolean      (*decide_allocation) (GstBaseTransform *trans, GstQuery *query);
241

242
  /* transform size */
243
  gboolean      (*transform_size) (GstBaseTransform *trans,
244
                                   GstPadDirection direction,
245 246
                                   GstCaps *caps, gsize size,
                                   GstCaps *othercaps, gsize *othersize);
247

248
  gboolean      (*get_unit_size)  (GstBaseTransform *trans, GstCaps *caps,
249
                                   gsize *size);
250

251
  /* states */
252 253 254
  gboolean      (*start)        (GstBaseTransform *trans);
  gboolean      (*stop)         (GstBaseTransform *trans);

255 256
  /* sink and src pad event handlers */
  gboolean      (*sink_event)   (GstBaseTransform *trans, GstEvent *event);
Wim Taymans's avatar
Wim Taymans committed
257
  gboolean      (*src_event)    (GstBaseTransform *trans, GstEvent *event);
258

Thomas Vander Stichele's avatar
Thomas Vander Stichele committed
259
  GstFlowReturn (*prepare_output_buffer) (GstBaseTransform * trans,
Wim Taymans's avatar
Wim Taymans committed
260
                                          GstBuffer *input, GstBuffer **outbuf);
261

Wim Taymans's avatar
Wim Taymans committed
262 263
  gboolean      (*copy_metadata)     (GstBaseTransform * trans, GstBuffer *input,
                                      GstBuffer *outbuf);
264

265 266
  void          (*before_transform)  (GstBaseTransform *trans, GstBuffer *buffer);

267
  /* transform */
Wim Taymans's avatar
Wim Taymans committed
268 269 270
  GstFlowReturn (*transform)    (GstBaseTransform *trans, GstBuffer *inbuf,
                                 GstBuffer *outbuf);
  GstFlowReturn (*transform_ip) (GstBaseTransform *trans, GstBuffer *buf);
271

272
  /*< private >*/
Wim Taymans's avatar
Wim Taymans committed
273
  gpointer       _gst_reserved[GST_PADDING_LARGE];
Wim Taymans's avatar
Wim Taymans committed
274 275
};

276 277 278 279 280
GType           gst_base_transform_get_type         (void);

void		gst_base_transform_set_passthrough  (GstBaseTransform *trans,
	                                             gboolean passthrough);
gboolean	gst_base_transform_is_passthrough   (GstBaseTransform *trans);
281

282 283 284
void		gst_base_transform_set_in_place     (GstBaseTransform *trans,
	                                             gboolean in_place);
gboolean	gst_base_transform_is_in_place      (GstBaseTransform *trans);
285

286 287 288
void		gst_base_transform_update_qos       (GstBaseTransform *trans,
						     gdouble proportion,
						     GstClockTimeDiff diff,
289
						     GstClockTime timestamp);
290
void		gst_base_transform_set_qos_enabled  (GstBaseTransform *trans,
291 292
		                                     gboolean enabled);
gboolean	gst_base_transform_is_qos_enabled   (GstBaseTransform *trans);
Wim Taymans's avatar
Wim Taymans committed
293

294 295 296
void            gst_base_transform_set_gap_aware    (GstBaseTransform *trans,
                                                     gboolean gap_aware);

297
void		gst_base_transform_suggest          (GstBaseTransform *trans,
298
	                                             GstCaps *caps, gsize size);
299
void		gst_base_transform_reconfigure      (GstBaseTransform *trans);
Wim Taymans's avatar
Wim Taymans committed
300 301 302
G_END_DECLS

#endif /* __GST_BASE_TRANSFORM_H__ */