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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #ifndef __GST_AUDIO_AUDIO_H__
25 #include <gst/audio/audio.h>
28 #ifndef _GST_AUDIO_DECODER_H_
29 #define _GST_AUDIO_DECODER_H_
32 #include <gst/base/gstadapter.h>
36 #define GST_TYPE_AUDIO_DECODER \
37 (gst_audio_decoder_get_type())
38 #define GST_AUDIO_DECODER(obj) \
39 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_DECODER,GstAudioDecoder))
40 #define GST_AUDIO_DECODER_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AUDIO_DECODER,GstAudioDecoderClass))
42 #define GST_AUDIO_DECODER_GET_CLASS(obj) \
43 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_AUDIO_DECODER,GstAudioDecoderClass))
44 #define GST_IS_AUDIO_DECODER(obj) \
45 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_DECODER))
46 #define GST_IS_AUDIO_DECODER_CLASS(obj) \
47 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AUDIO_DECODER))
48 #define GST_AUDIO_DECODER_CAST(obj) \
49 ((GstAudioDecoder *)(obj))
52 * GST_AUDIO_DECODER_SINK_NAME:
54 * The name of the templates for the sink pad.
56 #define GST_AUDIO_DECODER_SINK_NAME "sink"
58 * GST_AUDIO_DECODER_SRC_NAME:
60 * The name of the templates for the source pad.
62 #define GST_AUDIO_DECODER_SRC_NAME "src"
65 * GST_AUDIO_DECODER_SRC_PAD:
66 * @obj: base audio codec instance
68 * Gives the pointer to the source #GstPad object of the element.
70 #define GST_AUDIO_DECODER_SRC_PAD(obj) (((GstAudioDecoder *) (obj))->srcpad)
73 * GST_AUDIO_DECODER_SINK_PAD:
74 * @obj: base audio codec instance
76 * Gives the pointer to the sink #GstPad object of the element.
78 #define GST_AUDIO_DECODER_SINK_PAD(obj) (((GstAudioDecoder *) (obj))->sinkpad)
80 #define GST_AUDIO_DECODER_STREAM_LOCK(dec) g_rec_mutex_lock (&GST_AUDIO_DECODER (dec)->stream_lock)
81 #define GST_AUDIO_DECODER_STREAM_UNLOCK(dec) g_rec_mutex_unlock (&GST_AUDIO_DECODER (dec)->stream_lock)
84 * GST_AUDIO_DECODER_INPUT_SEGMENT:
85 * @obj: audio decoder instance
87 * Gives the input segment of the element.
89 #define GST_AUDIO_DECODER_INPUT_SEGMENT(obj) (GST_AUDIO_DECODER_CAST (obj)->input_segment)
92 * GST_AUDIO_DECODER_OUTPUT_SEGMENT:
93 * @obj: audio decoder instance
95 * Gives the output segment of the element.
97 #define GST_AUDIO_DECODER_OUTPUT_SEGMENT(obj) (GST_AUDIO_DECODER_CAST (obj)->output_segment)
99 typedef struct _GstAudioDecoder GstAudioDecoder;
100 typedef struct _GstAudioDecoderClass GstAudioDecoderClass;
102 typedef struct _GstAudioDecoderPrivate GstAudioDecoderPrivate;
104 /* do not use this one, use macro below */
107 GstFlowReturn _gst_audio_decoder_error (GstAudioDecoder *dec, gint weight,
108 GQuark domain, gint code,
109 gchar *txt, gchar *debug,
110 const gchar *file, const gchar *function,
114 * GST_AUDIO_DECODER_ERROR:
115 * @el: the base audio decoder element that generates the error
116 * @weight: element defined weight of the error, added to error count
117 * @domain: like CORE, LIBRARY, RESOURCE or STREAM (see #gstreamer-GstGError)
118 * @code: error code defined for that domain (see #gstreamer-GstGError)
119 * @text: the message to display (format string and args enclosed in
121 * @debug: debugging information for the message (format string and args
122 * enclosed in parentheses)
123 * @ret: variable to receive return value
125 * Utility function that audio decoder elements can use in case they encountered
126 * a data processing error that may be fatal for the current "data unit" but
127 * need not prevent subsequent decoding. Such errors are counted and if there
128 * are too many, as configured in the context's max_errors, the pipeline will
129 * post an error message and the application will be requested to stop further
130 * media processing. Otherwise, it is considered a "glitch" and only a warning
131 * is logged. In either case, @ret is set to the proper value to
132 * return to upstream/caller (indicating either GST_FLOW_ERROR or GST_FLOW_OK).
134 #define GST_AUDIO_DECODER_ERROR(el, weight, domain, code, text, debug, ret) \
136 gchar *__txt = _gst_element_error_printf text; \
137 gchar *__dbg = _gst_element_error_printf debug; \
138 GstAudioDecoder *__dec = GST_AUDIO_DECODER (el); \
139 ret = _gst_audio_decoder_error (__dec, weight, GST_ ## domain ## _ERROR, \
140 GST_ ## domain ## _ERROR_ ## code, __txt, __dbg, __FILE__, \
141 GST_FUNCTION, __LINE__); \
146 * GST_AUDIO_DECODER_MAX_ERRORS:
148 * Default maximum number of errors tolerated before signaling error.
150 #define GST_AUDIO_DECODER_MAX_ERRORS -1
155 * The opaque #GstAudioDecoder data structure.
157 struct _GstAudioDecoder
162 /* source and sink pads */
166 /* protects all data processing, i.e. is locked
167 * in the chain function, finish_frame and when
168 * processing serialized events */
169 GRecMutex stream_lock;
171 /* MT-protected (with STREAM_LOCK) */
172 GstSegment input_segment;
173 GstSegment output_segment;
176 GstAudioDecoderPrivate *priv;
178 gpointer _gst_reserved[GST_PADDING_LARGE];
182 * GstAudioDecoderClass:
183 * @element_class: The parent class structure
185 * Called when the element starts processing.
186 * Allows opening external resources.
188 * Called when the element stops processing.
189 * Allows closing external resources.
190 * @set_format: Notifies subclass of incoming data format (caps).
192 * Allows chopping incoming data into manageable units (frames)
193 * for subsequent decoding. This division is at subclass
194 * discretion and may or may not correspond to 1 (or more)
195 * frames as defined by audio format.
196 * @handle_frame: Provides input data (or NULL to clear any remaining data)
197 * to subclass. Input data ref management is performed by
198 * base class, subclass should not care or intervene,
199 * and input data is only valid until next call to base class,
200 * most notably a call to gst_audio_decoder_finish_frame().
202 * Instructs subclass to clear any codec caches and discard
203 * any pending samples and not yet returned decoded data.
204 * @hard indicates whether a FLUSH is being processed,
205 * or otherwise a DISCONT (or conceptually similar).
206 * @sink_event: Optional.
207 * Event handler on the sink pad. Subclasses should chain up to
208 * the parent implementation to invoke the default handler.
209 * @src_event: Optional.
210 * Event handler on the src pad. Subclasses should chain up to
211 * the parent implementation to invoke the default handler.
212 * @pre_push: Optional.
213 * Called just prior to pushing (encoded data) buffer downstream.
214 * Subclass has full discretionary access to buffer,
215 * and a not OK flow return will abort downstream pushing.
217 * Called when the element changes to GST_STATE_READY.
218 * Allows opening external resources.
220 * Called when the element changes to GST_STATE_NULL.
221 * Allows closing external resources.
222 * @negotiate: Optional.
223 * Negotiate with downstream and configure buffer pools, etc.
224 * Subclasses should chain up to the parent implementation to
225 * invoke the default handler.
226 * @decide_allocation: Optional.
227 * Setup the allocation parameters for allocating output
228 * buffers. The passed in query contains the result of the
229 * downstream allocation query.
230 * Subclasses should chain up to the parent implementation to
231 * invoke the default handler.
232 * @propose_allocation: Optional.
233 * Propose buffer allocation parameters for upstream elements.
234 * Subclasses should chain up to the parent implementation to
235 * invoke the default handler.
236 * @sink_query: Optional.
237 * Query handler on the sink pad. This function should
238 * return TRUE if the query could be performed. Subclasses
239 * should chain up to the parent implementation to invoke the
240 * default handler. Since: 1.6
241 * @src_query: Optional.
242 * Query handler on the source pad. This function should
243 * return TRUE if the query could be performed. Subclasses
244 * should chain up to the parent implementation to invoke the
245 * default handler. Since: 1.6
246 * @getcaps: Optional.
247 * Allows for a custom sink getcaps implementation.
248 * If not implemented,
249 * default returns gst_audio_decoder_proxy_getcaps
250 * applied to sink template caps.
251 * @transform_meta: Optional. Transform the metadata on the input buffer to the
252 * output buffer. By default this method copies all meta without
253 * tags and meta with only the "audio" tag. subclasses can
254 * implement this method and return %TRUE if the metadata is to be
257 * Subclasses can override any of the available virtual methods or not, as
258 * needed. At minimum @handle_frame (and likely @set_format) needs to be
261 struct _GstAudioDecoderClass
263 GstElementClass element_class;
266 /* virtual methods for subclasses */
268 gboolean (*start) (GstAudioDecoder *dec);
270 gboolean (*stop) (GstAudioDecoder *dec);
272 gboolean (*set_format) (GstAudioDecoder *dec,
276 * GstAudioDecoderClass::parse:
280 GstFlowReturn (*parse) (GstAudioDecoder *dec,
282 gint *offset, gint *length);
284 GstFlowReturn (*handle_frame) (GstAudioDecoder *dec,
287 void (*flush) (GstAudioDecoder *dec, gboolean hard);
289 GstFlowReturn (*pre_push) (GstAudioDecoder *dec,
292 gboolean (*sink_event) (GstAudioDecoder *dec,
294 gboolean (*src_event) (GstAudioDecoder *dec,
297 gboolean (*open) (GstAudioDecoder *dec);
299 gboolean (*close) (GstAudioDecoder *dec);
301 gboolean (*negotiate) (GstAudioDecoder *dec);
303 gboolean (*decide_allocation) (GstAudioDecoder *dec, GstQuery *query);
305 gboolean (*propose_allocation) (GstAudioDecoder *dec,
308 gboolean (*sink_query) (GstAudioDecoder *dec, GstQuery *query);
310 gboolean (*src_query) (GstAudioDecoder *dec, GstQuery *query);
312 GstCaps * (*getcaps) (GstAudioDecoder * dec,
315 gboolean (*transform_meta) (GstAudioDecoder *enc, GstBuffer *outbuf,
316 GstMeta *meta, GstBuffer *inbuf);
319 gpointer _gst_reserved[GST_PADDING_LARGE - 4];
323 GType gst_audio_decoder_get_type (void);
326 gboolean gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
327 const GstAudioInfo * info);
330 gboolean gst_audio_decoder_set_output_caps (GstAudioDecoder * dec,
333 GstCaps * gst_audio_decoder_proxy_getcaps (GstAudioDecoder * decoder,
338 gboolean gst_audio_decoder_negotiate (GstAudioDecoder * dec);
341 GstFlowReturn gst_audio_decoder_finish_subframe (GstAudioDecoder * dec,
345 GstFlowReturn gst_audio_decoder_finish_frame (GstAudioDecoder * dec,
346 GstBuffer * buf, gint frames);
349 GstBuffer * gst_audio_decoder_allocate_output_buffer (GstAudioDecoder * dec,
352 /* context parameters */
355 GstAudioInfo * gst_audio_decoder_get_audio_info (GstAudioDecoder * dec);
358 void gst_audio_decoder_set_plc_aware (GstAudioDecoder * dec,
362 gint gst_audio_decoder_get_plc_aware (GstAudioDecoder * dec);
365 void gst_audio_decoder_set_estimate_rate (GstAudioDecoder * dec,
369 gint gst_audio_decoder_get_estimate_rate (GstAudioDecoder * dec);
372 gint gst_audio_decoder_get_delay (GstAudioDecoder * dec);
375 void gst_audio_decoder_set_max_errors (GstAudioDecoder * dec,
379 gint gst_audio_decoder_get_max_errors (GstAudioDecoder * dec);
382 void gst_audio_decoder_set_latency (GstAudioDecoder * dec,
387 void gst_audio_decoder_get_latency (GstAudioDecoder * dec,
392 void gst_audio_decoder_get_parse_state (GstAudioDecoder * dec,
397 void gst_audio_decoder_set_allocation_caps (GstAudioDecoder * dec,
398 GstCaps * allocation_caps);
400 /* object properties */
403 void gst_audio_decoder_set_plc (GstAudioDecoder * dec,
407 gboolean gst_audio_decoder_get_plc (GstAudioDecoder * dec);
410 void gst_audio_decoder_set_min_latency (GstAudioDecoder * dec,
414 GstClockTime gst_audio_decoder_get_min_latency (GstAudioDecoder * dec);
417 void gst_audio_decoder_set_tolerance (GstAudioDecoder * dec,
418 GstClockTime tolerance);
421 GstClockTime gst_audio_decoder_get_tolerance (GstAudioDecoder * dec);
424 void gst_audio_decoder_set_drainable (GstAudioDecoder * dec,
428 gboolean gst_audio_decoder_get_drainable (GstAudioDecoder * dec);
431 void gst_audio_decoder_set_needs_format (GstAudioDecoder * dec,
435 gboolean gst_audio_decoder_get_needs_format (GstAudioDecoder * dec);
438 void gst_audio_decoder_get_allocator (GstAudioDecoder * dec,
439 GstAllocator ** allocator,
440 GstAllocationParams * params);
443 void gst_audio_decoder_merge_tags (GstAudioDecoder * dec,
444 const GstTagList * tags, GstTagMergeMode mode);
447 void gst_audio_decoder_set_use_default_pad_acceptcaps (GstAudioDecoder * decoder,
450 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstAudioDecoder, gst_object_unref)
454 #endif /* _GST_AUDIO_DECODER_H_ */