tizen 2.3 release
[framework/multimedia/gst-plugins-base0.10.git] / gst-libs / gst / audio / gstaudiodecoder.h
1 /* GStreamer
2  * Copyright (C) 2009 Igalia S.L.
3  * Author: Iago Toral Quiroga <itoral@igalia.com>
4  * Copyright (C) 2011 Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>.
5  * Copyright (C) 2011 Nokia Corporation. All rights reserved.
6  *   Contact: Stefan Kost <stefan.kost@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 #ifndef _GST_AUDIO_DECODER_H_
24 #define _GST_AUDIO_DECODER_H_
25
26 #include <gst/gst.h>
27 #include <gst/audio/audio.h>
28 #include <gst/base/gstadapter.h>
29
30 G_BEGIN_DECLS
31
32 #define GST_TYPE_AUDIO_DECODER \
33   (gst_audio_decoder_get_type())
34 #define GST_AUDIO_DECODER(obj) \
35   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_DECODER,GstAudioDecoder))
36 #define GST_AUDIO_DECODER_CLASS(klass) \
37   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_DECODER,GstAudioDecoderClass))
38 #define GST_AUDIO_DECODER_GET_CLASS(obj) \
39   (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_AUDIO_DECODER,GstAudioDecoderClass))
40 #define GST_IS_AUDIO_DECODER(obj) \
41   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_DECODER))
42 #define GST_IS_AUDIO_DECODER_CLASS(obj) \
43   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_DECODER))
44
45 /**
46  * GST_AUDIO_DECODER_SINK_NAME:
47  *
48  * The name of the templates for the sink pad.
49  *
50  * Since: 0.10.36
51  */
52 #define GST_AUDIO_DECODER_SINK_NAME    "sink"
53 /**
54  * GST_AUDIO_DECODER_SRC_NAME:
55  *
56  * The name of the templates for the source pad.
57  *
58  * Since: 0.10.36
59  */
60 #define GST_AUDIO_DECODER_SRC_NAME     "src"
61
62 /**
63  * GST_AUDIO_DECODER_SRC_PAD:
64  * @obj: base audio codec instance
65  *
66  * Gives the pointer to the source #GstPad object of the element.
67  *
68  * Since: 0.10.36
69  */
70 #define GST_AUDIO_DECODER_SRC_PAD(obj)         (((GstAudioDecoder *) (obj))->srcpad)
71
72 /**
73  * GST_AUDIO_DECODER_SINK_PAD:
74  * @obj: base audio codec instance
75  *
76  * Gives the pointer to the sink #GstPad object of the element.
77  *
78  * Since: 0.10.36
79  */
80 #define GST_AUDIO_DECODER_SINK_PAD(obj)        (((GstAudioDecoder *) (obj))->sinkpad)
81
82 #define GST_AUDIO_DECODER_STREAM_LOCK(dec) g_static_rec_mutex_lock (&GST_AUDIO_DECODER (dec)->stream_lock)
83 #define GST_AUDIO_DECODER_STREAM_UNLOCK(dec) g_static_rec_mutex_unlock (&GST_AUDIO_DECODER (dec)->stream_lock)
84
85 typedef struct _GstAudioDecoder GstAudioDecoder;
86 typedef struct _GstAudioDecoderClass GstAudioDecoderClass;
87
88 typedef struct _GstAudioDecoderPrivate GstAudioDecoderPrivate;
89
90 /* do not use this one, use macro below */
91 GstFlowReturn _gst_audio_decoder_error (GstAudioDecoder *dec, gint weight,
92                                         GQuark domain, gint code,
93                                         gchar *txt, gchar *debug,
94                                         const gchar *file, const gchar *function,
95                                         gint line);
96
97 /**
98  * GST_AUDIO_DECODER_ERROR:
99  * @el:     the base audio decoder element that generates the error
100  * @weight: element defined weight of the error, added to error count
101  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
102  * @code:   error code defined for that domain (see #gstreamer-GstGError)
103  * @text:   the message to display (format string and args enclosed in
104  *          parentheses)
105  * @debug:  debugging information for the message (format string and args
106  *          enclosed in parentheses)
107  * @ret:    variable to receive return value
108  *
109  * Utility function that audio decoder elements can use in case they encountered
110  * a data processing error that may be fatal for the current "data unit" but
111  * need not prevent subsequent decoding.  Such errors are counted and if there
112  * are too many, as configured in the context's max_errors, the pipeline will
113  * post an error message and the application will be requested to stop further
114  * media processing.  Otherwise, it is considered a "glitch" and only a warning
115  * is logged. In either case, @ret is set to the proper value to
116  * return to upstream/caller (indicating either GST_FLOW_ERROR or GST_FLOW_OK).
117  *
118  * Since: 0.10.36
119  */
120 #define GST_AUDIO_DECODER_ERROR(el, weight, domain, code, text, debug, ret) \
121 G_STMT_START {                                                              \
122   gchar *__txt = _gst_element_error_printf text;                            \
123   gchar *__dbg = _gst_element_error_printf debug;                           \
124   GstAudioDecoder *dec = GST_AUDIO_DECODER (el);                   \
125   ret = _gst_audio_decoder_error (dec, weight, GST_ ## domain ## _ERROR,    \
126       GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,            \
127       GST_FUNCTION, __LINE__);                                              \
128 } G_STMT_END
129
130
131 /**
132  * GST_AUDIO_DECODER_MAX_ERRORS:
133  *
134  * Default maximum number of errors tolerated before signaling error.
135  *
136  * Since: 0.10.36
137  */
138 #define GST_AUDIO_DECODER_MAX_ERRORS     10
139
140 /**
141  * GstAudioDecoder:
142  *
143  * The opaque #GstAudioDecoder data structure.
144  *
145  * Since: 0.10.36
146  */
147 struct _GstAudioDecoder
148 {
149   GstElement element;
150
151   /*< protected >*/
152   /* source and sink pads */
153   GstPad         *sinkpad;
154   GstPad         *srcpad;
155
156   /* protects all data processing, i.e. is locked
157    * in the chain function, finish_frame and when
158    * processing serialized events */
159   GStaticRecMutex stream_lock;
160
161   /* MT-protected (with STREAM_LOCK) */
162   GstSegment      segment;
163
164   /*< private >*/
165   GstAudioDecoderPrivate *priv;
166   gpointer       _gst_reserved[GST_PADDING_LARGE];
167 };
168
169 /**
170  * GstAudioDecoderClass:
171  * @element_class:  The parent class structure
172  * @start:          Optional.
173  *                  Called when the element starts processing.
174  *                  Allows opening external resources.
175  * @stop:           Optional.
176  *                  Called when the element stops processing.
177  *                  Allows closing external resources.
178  * @set_format:     Notifies subclass of incoming data format (caps).
179  * @parse:          Optional.
180  *                  Allows chopping incoming data into manageable units (frames)
181  *                  for subsequent decoding.  This division is at subclass
182  *                  discretion and may or may not correspond to 1 (or more)
183  *                  frames as defined by audio format.
184  * @handle_frame:   Provides input data (or NULL to clear any remaining data)
185  *                  to subclass.  Input data ref management is performed by
186  *                  base class, subclass should not care or intervene,
187  *                  and input data is only valid until next call to base class,
188  *                  most notably a call to gst_audio_decoder_finish_frame().
189  * @flush:          Optional.
190  *                  Instructs subclass to clear any codec caches and discard
191  *                  any pending samples and not yet returned decoded data.
192  *                  @hard indicates whether a FLUSH is being processed,
193  *                  or otherwise a DISCONT (or conceptually similar).
194  * @event:          Optional.
195  *                  Event handler on the sink pad. This function should return
196  *                  TRUE if the event was handled and should be discarded
197  *                  (i.e. not unref'ed).
198  * @pre_push:       Optional.
199  *                  Called just prior to pushing (encoded data) buffer downstream.
200  *                  Subclass has full discretionary access to buffer,
201  *                  and a not OK flow return will abort downstream pushing.
202  *
203  * Subclasses can override any of the available virtual methods or not, as
204  * needed. At minimum @handle_frame (and likely @set_format) needs to be
205  * overridden.
206  *
207  * Since: 0.10.36
208  */
209 struct _GstAudioDecoderClass
210 {
211   GstElementClass element_class;
212
213   /*< public >*/
214   /* virtual methods for subclasses */
215
216   gboolean      (*start)              (GstAudioDecoder *dec);
217
218   gboolean      (*stop)               (GstAudioDecoder *dec);
219
220   gboolean      (*set_format)         (GstAudioDecoder *dec,
221                                        GstCaps *caps);
222
223   GstFlowReturn (*parse)              (GstAudioDecoder *dec,
224                                        GstAdapter *adapter,
225                                        gint *offset, gint *length);
226
227   GstFlowReturn (*handle_frame)       (GstAudioDecoder *dec,
228                                        GstBuffer *buffer);
229
230   void          (*flush)              (GstAudioDecoder *dec, gboolean hard);
231
232   GstFlowReturn (*pre_push)           (GstAudioDecoder *dec,
233                                        GstBuffer **buffer);
234
235   gboolean      (*event)              (GstAudioDecoder *dec,
236                                        GstEvent *event);
237
238   /*< private >*/
239   gpointer       _gst_reserved[GST_PADDING_LARGE];
240 };
241
242 GType             gst_audio_decoder_get_type (void);
243
244 GstFlowReturn     gst_audio_decoder_finish_frame (GstAudioDecoder * dec,
245                                                        GstBuffer * buf, gint frames);
246
247 /* context parameters */
248 GstAudioInfo    * gst_audio_decoder_get_audio_info (GstAudioDecoder * dec);
249
250 void              gst_audio_decoder_set_plc_aware  (GstAudioDecoder * dec,
251                                                     gboolean          plc);
252
253 gint              gst_audio_decoder_get_plc_aware  (GstAudioDecoder * dec);
254
255 void              gst_audio_decoder_set_byte_time  (GstAudioDecoder * dec,
256                                                     gboolean          enabled);
257
258 gint              gst_audio_decoder_get_byte_time  (GstAudioDecoder * dec);
259
260 gint              gst_audio_decoder_get_delay      (GstAudioDecoder * dec);
261
262 void              gst_audio_decoder_set_max_errors (GstAudioDecoder * dec,
263                                                    gint               num);
264
265 gint              gst_audio_decoder_get_max_errors (GstAudioDecoder * dec);
266
267 void              gst_audio_decoder_set_latency (GstAudioDecoder * dec,
268                                                  GstClockTime      min,
269                                                  GstClockTime      max);
270
271 void              gst_audio_decoder_get_latency (GstAudioDecoder * dec,
272                                                  GstClockTime    * min,
273                                                  GstClockTime    * max);
274
275 void              gst_audio_decoder_get_parse_state (GstAudioDecoder * dec,
276                                                      gboolean        * sync,
277                                                      gboolean        * eos);
278
279
280 /* object properties */
281 void              gst_audio_decoder_set_plc (GstAudioDecoder * dec,
282                                              gboolean          enabled);
283
284 gboolean          gst_audio_decoder_get_plc (GstAudioDecoder * dec);
285
286 void              gst_audio_decoder_set_min_latency (GstAudioDecoder * dec,
287                                                      gint64            num);
288
289 gint64            gst_audio_decoder_get_min_latency (GstAudioDecoder * dec);
290
291 void              gst_audio_decoder_set_tolerance   (GstAudioDecoder * dec,
292                                                      gint64            tolerance);
293
294 gint64            gst_audio_decoder_get_tolerance   (GstAudioDecoder * dec);
295
296 void              gst_audio_decoder_set_drainable (GstAudioDecoder * dec,
297                                                    gboolean enabled);
298
299 gboolean          gst_audio_decoder_get_drainable (GstAudioDecoder * dec);
300
301 void              gst_audio_decoder_set_needs_format (GstAudioDecoder * dec,
302                                                       gboolean enabled);
303
304 gboolean          gst_audio_decoder_get_needs_format (GstAudioDecoder * dec);
305
306 G_END_DECLS
307
308 #endif /* _GST_AUDIO_DECODER_H_ */