base: port to 0.11
[platform/upstream/gstreamer.git] / gst-libs / gst / audio / gstbaseaudiodecoder.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
24 #ifndef _GST_BASE_AUDIO_DECODER_H_
25 #define _GST_BASE_AUDIO_DECODER_H_
26
27 #ifndef GST_USE_UNSTABLE_API
28 #warning "GstBaseAudioDecoder is unstable API and may change in future."
29 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
30 #endif
31
32 #include <gst/gst.h>
33 #include <gst/audio/audio.h>
34 #include <gst/base/gstadapter.h>
35
36 G_BEGIN_DECLS
37
38 #define GST_TYPE_BASE_AUDIO_DECODER \
39   (gst_base_audio_decoder_get_type())
40 #define GST_BASE_AUDIO_DECODER(obj) \
41   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_AUDIO_DECODER,GstBaseAudioDecoder))
42 #define GST_BASE_AUDIO_DECODER_CLASS(klass) \
43   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_AUDIO_DECODER,GstBaseAudioDecoderClass))
44 #define GST_BASE_AUDIO_DECODER_GET_CLASS(obj) \
45   (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_BASE_AUDIO_DECODER,GstBaseAudioDecoderClass))
46 #define GST_IS_BASE_AUDIO_DECODER(obj) \
47   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_AUDIO_DECODER))
48 #define GST_IS_BASE_AUDIO_DECODER_CLASS(obj) \
49   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_AUDIO_DECODER))
50
51 /**
52  * GST_BASE_AUDIO_DECODER_SINK_NAME:
53  *
54  * The name of the templates for the sink pad.
55  *
56  * Since: 0.10.36
57  */
58 #define GST_BASE_AUDIO_DECODER_SINK_NAME    "sink"
59 /**
60  * GST_BASE_AUDIO_DECODER_SRC_NAME:
61  *
62  * The name of the templates for the source pad.
63  *
64  * Since: 0.10.36
65  */
66 #define GST_BASE_AUDIO_DECODER_SRC_NAME     "src"
67
68 /**
69  * GST_BASE_AUDIO_DECODER_SRC_PAD:
70  * @obj: base audio codec instance
71  *
72  * Gives the pointer to the source #GstPad object of the element.
73  *
74  * Since: 0.10.36
75  */
76 #define GST_BASE_AUDIO_DECODER_SRC_PAD(obj)         (((GstBaseAudioDecoder *) (obj))->srcpad)
77
78 /**
79  * GST_BASE_AUDIO_DECODER_SINK_PAD:
80  * @obj: base audio codec instance
81  *
82  * Gives the pointer to the sink #GstPad object of the element.
83  *
84  * Since: 0.10.36
85  */
86 #define GST_BASE_AUDIO_DECODER_SINK_PAD(obj)        (((GstBaseAudioDecoder *) (obj))->sinkpad)
87
88 typedef struct _GstBaseAudioDecoder GstBaseAudioDecoder;
89 typedef struct _GstBaseAudioDecoderClass GstBaseAudioDecoderClass;
90
91 typedef struct _GstBaseAudioDecoderPrivate GstBaseAudioDecoderPrivate;
92
93 /* do not use this one, use macro below */
94 GstFlowReturn _gst_base_audio_decoder_error (GstBaseAudioDecoder *dec, gint weight,
95                                             GQuark domain, gint code,
96                                             gchar *txt, gchar *debug,
97                                             const gchar *file, const gchar *function,
98                                             gint line);
99
100 /**
101  * GST_BASE_AUDIO_DECODER_ERROR:
102  * @el:     the base audio decoder element that generates the error
103  * @weight: element defined weight of the error, added to error count
104  * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
105  * @code:   error code defined for that domain (see #gstreamer-GstGError)
106  * @text:   the message to display (format string and args enclosed in
107  *          parentheses)
108  * @debug:  debugging information for the message (format string and args
109  *          enclosed in parentheses)
110  * @ret:    variable to receive return value
111  *
112  * Utility function that audio decoder elements can use in case they encountered
113  * a data processing error that may be fatal for the current "data unit" but
114  * need not prevent subsequent decoding.  Such errors are counted and if there
115  * are too many, as configured in the context's max_errors, the pipeline will
116  * post an error message and the application will be requested to stop further
117  * media processing.  Otherwise, it is considered a "glitch" and only a warning
118  * is logged. In either case, @ret is set to the proper value to
119  * return to upstream/caller (indicating either GST_FLOW_ERROR or GST_FLOW_OK).
120  *
121  * Since: 0.10.36
122  */
123 #define GST_BASE_AUDIO_DECODER_ERROR(el, w, domain, code, text, debug, ret) \
124 G_STMT_START {                                                              \
125   gchar *__txt = _gst_element_error_printf text;                            \
126   gchar *__dbg = _gst_element_error_printf debug;                           \
127   GstBaseAudioDecoder *dec = GST_BASE_AUDIO_DECODER (el);                   \
128   ret = _gst_base_audio_decoder_error (dec, w, GST_ ## domain ## _ERROR,    \
129       GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__,            \
130       GST_FUNCTION, __LINE__);                                              \
131 } G_STMT_END
132
133 /**
134  * GstBaseAudioDecoder:
135  *
136  * The opaque #GstBaseAudioDecoder data structure.
137  *
138  * Since: 0.10.36
139  */
140 struct _GstBaseAudioDecoder
141 {
142   GstElement element;
143
144   /*< protected >*/
145   /* source and sink pads */
146   GstPad         *sinkpad;
147   GstPad         *srcpad;
148
149   /* MT-protected (with STREAM_LOCK) */
150   GstSegment      segment;
151
152   /*< private >*/
153   GstBaseAudioDecoderPrivate *priv;
154   gpointer       _gst_reserved[GST_PADDING_LARGE];
155 };
156
157 /**
158  * GstBaseAudioDecoderClass:
159  * @start:          Optional.
160  *                  Called when the element starts processing.
161  *                  Allows opening external resources.
162  * @stop:           Optional.
163  *                  Called when the element stops processing.
164  *                  Allows closing external resources.
165  * @set_format:     Notifies subclass of incoming data format (caps).
166  * @parse:          Optional.
167  *                  Allows chopping incoming data into manageable units (frames)
168  *                  for subsequent decoding.  This division is at subclass
169  *                  discretion and may or may not correspond to 1 (or more)
170  *                  frames as defined by audio format.
171  * @handle_frame:   Provides input data (or NULL to clear any remaining data)
172  *                  to subclass.  Input data ref management is performed by
173  *                  base class, subclass should not care or intervene.
174  * @flush:          Optional.
175  *                  Instructs subclass to clear any codec caches and discard
176  *                  any pending samples and not yet returned encoded data.
177  *                  @hard indicates whether a FLUSH is being processed,
178  *                  or otherwise a DISCONT (or conceptually similar).
179  * @event:          Optional.
180  *                  Event handler on the sink pad. This function should return
181  *                  TRUE if the event was handled and should be discarded
182  *                  (i.e. not unref'ed).
183  * @pre_push:       Optional.
184  *                  Called just prior to pushing (encoded data) buffer downstream.
185  *                  Subclass has full discretionary access to buffer,
186  *                  and a not OK flow return will abort downstream pushing.
187  *
188  * Subclasses can override any of the available virtual methods or not, as
189  * needed. At minimum @handle_frame (and likely @set_format) needs to be
190  * overridden.
191  *
192  * Since: 0.10.36
193  */
194 struct _GstBaseAudioDecoderClass
195 {
196   GstElementClass parent_class;
197
198   /*< public >*/
199   /* virtual methods for subclasses */
200
201   gboolean      (*start)              (GstBaseAudioDecoder *dec);
202
203   gboolean      (*stop)               (GstBaseAudioDecoder *dec);
204
205   gboolean      (*set_format)         (GstBaseAudioDecoder *dec,
206                                        GstCaps *caps);
207
208   GstFlowReturn (*parse)              (GstBaseAudioDecoder *dec,
209                                        GstAdapter *adapter,
210                                        gint *offset, gint *length);
211
212   GstFlowReturn (*handle_frame)       (GstBaseAudioDecoder *dec,
213                                        GstBuffer *buffer);
214
215   void          (*flush)              (GstBaseAudioDecoder *dec, gboolean hard);
216
217   GstFlowReturn (*pre_push)           (GstBaseAudioDecoder *dec,
218                                        GstBuffer **buffer);
219
220   gboolean      (*event)              (GstBaseAudioDecoder *dec,
221                                        GstEvent *event);
222
223   /*< private >*/
224   gpointer       _gst_reserved[GST_PADDING_LARGE];
225 };
226
227 gboolean          gst_base_audio_decoder_src_setcaps  (GstBaseAudioDecoder * dec,
228                                                        GstCaps * caps);
229 GstFlowReturn     gst_base_audio_decoder_finish_frame (GstBaseAudioDecoder * dec,
230                                                        GstBuffer * buf, gint frames);
231
232 /* context parameters */
233 GstAudioInfo    * gst_base_audio_decoder_get_audio_info (GstBaseAudioDecoder * dec);
234
235 void              gst_base_audio_decoder_set_plc_aware (GstBaseAudioDecoder * dec,
236                                                         gboolean plc);
237 gint              gst_base_audio_decoder_get_plc_aware (GstBaseAudioDecoder * dec);
238
239 void              gst_base_audio_decoder_set_byte_time (GstBaseAudioDecoder * dec,
240                                                         gboolean enabled);
241 gint              gst_base_audio_decoder_get_byte_time (GstBaseAudioDecoder * dec);
242
243 gint              gst_base_audio_decoder_get_delay (GstBaseAudioDecoder * dec);
244
245 void              gst_base_audio_decoder_set_max_errors (GstBaseAudioDecoder * enc,
246                                                          gint num);
247 gint              gst_base_audio_decoder_get_max_errors (GstBaseAudioDecoder * dec);
248
249 void              gst_base_audio_decoder_set_latency (GstBaseAudioDecoder * dec,
250                                                       GstClockTime min, GstClockTime max);
251 void              gst_base_audio_decoder_get_latency (GstBaseAudioDecoder * dec,
252                                                       GstClockTime * min, GstClockTime * max);
253
254 void              gst_base_audio_decoder_get_parse_state (GstBaseAudioDecoder * dec,
255                                                           gboolean * sync, gboolean * eos);
256
257
258 /* object properties */
259 void              gst_base_audio_decoder_set_plc (GstBaseAudioDecoder * dec,
260                                                   gboolean enabled);
261 gboolean          gst_base_audio_decoder_get_plc (GstBaseAudioDecoder * dec);
262
263 void              gst_base_audio_decoder_set_min_latency (GstBaseAudioDecoder * dec,
264                                                           gint64 num);
265 gint64            gst_base_audio_decoder_get_min_latency (GstBaseAudioDecoder * dec);
266
267 void              gst_base_audio_decoder_set_tolerance (GstBaseAudioDecoder * dec,
268                                                         gint64 tolerance);
269
270 gint64            gst_base_audio_decoder_get_tolerance (GstBaseAudioDecoder * dec);
271
272 GType gst_base_audio_decoder_get_type (void);
273
274 G_END_DECLS
275
276 #endif
277