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>
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.
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.
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.
24 #ifndef _GST_BASE_AUDIO_DECODER_H_
25 #define _GST_BASE_AUDIO_DECODER_H_
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."
33 #include <gst/audio/audio.h>
34 #include <gst/base/gstadapter.h>
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))
52 * GST_BASE_AUDIO_DECODER_SINK_NAME:
54 * The name of the templates for the sink pad.
58 #define GST_BASE_AUDIO_DECODER_SINK_NAME "sink"
60 * GST_BASE_AUDIO_DECODER_SRC_NAME:
62 * The name of the templates for the source pad.
66 #define GST_BASE_AUDIO_DECODER_SRC_NAME "src"
69 * GST_BASE_AUDIO_DECODER_SRC_PAD:
70 * @obj: base audio codec instance
72 * Gives the pointer to the source #GstPad object of the element.
76 #define GST_BASE_AUDIO_DECODER_SRC_PAD(obj) (((GstBaseAudioDecoder *) (obj))->srcpad)
79 * GST_BASE_AUDIO_DECODER_SINK_PAD:
80 * @obj: base audio codec instance
82 * Gives the pointer to the sink #GstPad object of the element.
86 #define GST_BASE_AUDIO_DECODER_SINK_PAD(obj) (((GstBaseAudioDecoder *) (obj))->sinkpad)
88 typedef struct _GstBaseAudioDecoder GstBaseAudioDecoder;
89 typedef struct _GstBaseAudioDecoderClass GstBaseAudioDecoderClass;
91 typedef struct _GstBaseAudioDecoderPrivate GstBaseAudioDecoderPrivate;
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,
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
108 * @debug: debugging information for the message (format string and args
109 * enclosed in parentheses)
110 * @ret: variable to receive return value
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).
123 #define GST_BASE_AUDIO_DECODER_ERROR(el, w, domain, code, text, debug, ret) \
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__); \
134 * GstBaseAudioDecoder:
136 * The opaque #GstBaseAudioDecoder data structure.
140 struct _GstBaseAudioDecoder
145 /* source and sink pads */
149 /* MT-protected (with STREAM_LOCK) */
153 GstBaseAudioDecoderPrivate *priv;
154 gpointer _gst_reserved[GST_PADDING_LARGE];
158 * GstBaseAudioDecoderClass:
160 * Called when the element starts processing.
161 * Allows opening external resources.
163 * Called when the element stops processing.
164 * Allows closing external resources.
165 * @set_format: Notifies subclass of incoming data format (caps).
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.
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).
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.
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
194 struct _GstBaseAudioDecoderClass
196 GstElementClass parent_class;
199 /* virtual methods for subclasses */
201 gboolean (*start) (GstBaseAudioDecoder *dec);
203 gboolean (*stop) (GstBaseAudioDecoder *dec);
205 gboolean (*set_format) (GstBaseAudioDecoder *dec,
208 GstFlowReturn (*parse) (GstBaseAudioDecoder *dec,
210 gint *offset, gint *length);
212 GstFlowReturn (*handle_frame) (GstBaseAudioDecoder *dec,
215 void (*flush) (GstBaseAudioDecoder *dec, gboolean hard);
217 GstFlowReturn (*pre_push) (GstBaseAudioDecoder *dec,
220 gboolean (*event) (GstBaseAudioDecoder *dec,
224 gpointer _gst_reserved[GST_PADDING_LARGE];
227 GstFlowReturn gst_base_audio_decoder_finish_frame (GstBaseAudioDecoder * dec,
228 GstBuffer * buf, gint frames);
230 /* context parameters */
231 GstAudioInfo * gst_base_audio_decoder_get_audio_info (GstBaseAudioDecoder * dec);
233 void gst_base_audio_decoder_set_plc_aware (GstBaseAudioDecoder * dec,
235 gint gst_base_audio_decoder_get_plc_aware (GstBaseAudioDecoder * dec);
237 void gst_base_audio_decoder_set_byte_time (GstBaseAudioDecoder * dec,
239 gint gst_base_audio_decoder_get_byte_time (GstBaseAudioDecoder * dec);
241 gint gst_base_audio_decoder_get_delay (GstBaseAudioDecoder * dec);
243 void gst_base_audio_decoder_set_max_errors (GstBaseAudioDecoder * enc,
245 gint gst_base_audio_decoder_get_max_errors (GstBaseAudioDecoder * dec);
247 void gst_base_audio_decoder_set_latency (GstBaseAudioDecoder * dec,
248 GstClockTime min, GstClockTime max);
249 void gst_base_audio_decoder_get_latency (GstBaseAudioDecoder * dec,
250 GstClockTime * min, GstClockTime * max);
252 void gst_base_audio_decoder_get_parse_state (GstBaseAudioDecoder * dec,
253 gboolean * sync, gboolean * eos);
256 /* object properties */
257 void gst_base_audio_decoder_set_plc (GstBaseAudioDecoder * dec,
259 gboolean gst_base_audio_decoder_get_plc (GstBaseAudioDecoder * dec);
261 void gst_base_audio_decoder_set_min_latency (GstBaseAudioDecoder * dec,
263 gint64 gst_base_audio_decoder_get_min_latency (GstBaseAudioDecoder * dec);
265 void gst_base_audio_decoder_set_tolerance (GstBaseAudioDecoder * dec,
268 gint64 gst_base_audio_decoder_get_tolerance (GstBaseAudioDecoder * dec);
270 GType gst_base_audio_decoder_get_type (void);