1 /* libOggFLAC - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef OggFLAC__STREAM_DECODER_H
21 #define OggFLAC__STREAM_DECODER_H
25 #include "FLAC/stream_decoder.h"
32 /** \file include/OggFLAC/stream_decoder.h
35 * This module contains the functions which implement the stream
38 * See the detailed documentation in the
39 * \link oggflac_stream_decoder stream decoder \endlink module.
42 /** \defgroup oggflac_decoder OggFLAC/ *_decoder.h: decoder interfaces
46 * This module describes the decoder layers provided by libOggFLAC.
48 * libOggFLAC currently provides the same stream layer access as libFLAC;
49 * the interface is identical. See the \link flac_decoder FLAC
50 * decoder module \endlink for full documentation.
53 /** \defgroup oggflac_stream_decoder OggFLAC/stream_decoder.h: stream decoder interface
54 * \ingroup oggflac_decoder
57 * This module contains the functions which implement the stream
60 * The interface here is identical to FLAC's stream decoder,
61 * including the callbacks. See the \link flac_stream_decoder
62 * FLAC stream decoder module \endlink for full documentation.
68 /** State values for an OggFLAC__StreamDecoder
70 * The decoder's state can be obtained by calling OggFLAC__stream_decoder_get_state().
74 OggFLAC__STREAM_DECODER_OK = 0,
75 /**< The decoder is in the normal OK state. */
77 OggFLAC__STREAM_DECODER_OGG_ERROR,
78 /**< An error occurred in the underlying Ogg layer. */
80 OggFLAC__STREAM_DECODER_READ_ERROR,
81 /**< The read callback returned an error. */
83 OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR,
84 /**< An error occurred in the underlying FLAC stream decoder;
85 * check OggFLAC__stream_decoder_get_FLAC_stream_decoder_state().
88 OggFLAC__STREAM_DECODER_INVALID_CALLBACK,
89 /**< The decoder was initialized before setting all the required callbacks. */
91 OggFLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
92 /**< Memory allocation failed. */
94 OggFLAC__STREAM_DECODER_ALREADY_INITIALIZED,
95 /**< OggFLAC__stream_decoder_init() was called when the decoder was
96 * already initialized, usually because
97 * OggFLAC__stream_decoder_finish() was not called.
100 OggFLAC__STREAM_DECODER_UNINITIALIZED
101 /**< The decoder is in the uninitialized state. */
103 } OggFLAC__StreamDecoderState;
105 /** Maps an OggFLAC__StreamDecoderState to a C string.
107 * Using an OggFLAC__StreamDecoderState as the index to this array
108 * will give the string equivalent. The contents should not be modified.
110 extern OggFLAC_API const char * const OggFLAC__StreamDecoderStateString[];
113 /***********************************************************************
115 * class OggFLAC__StreamDecoder
117 ***********************************************************************/
119 struct OggFLAC__StreamDecoderProtected;
120 struct OggFLAC__StreamDecoderPrivate;
121 /** The opaque structure definition for the stream decoder type.
122 * See the \link oggflac_stream_decoder stream decoder module \endlink
123 * for a detailed description.
126 struct OggFLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
127 struct OggFLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
128 } OggFLAC__StreamDecoder;
130 /** Signature for the read callback.
131 * See OggFLAC__stream_decoder_set_read_callback()
132 * and FLAC__StreamDecoderReadCallback for more info.
134 * \param decoder The decoder instance calling the callback.
135 * \param buffer A pointer to a location for the callee to store
136 * data to be decoded.
137 * \param bytes A pointer to the size of the buffer.
138 * \param client_data The callee's client data set through
139 * OggFLAC__stream_decoder_set_client_data().
140 * \retval FLAC__StreamDecoderReadStatus
141 * The callee's return status.
143 typedef FLAC__StreamDecoderReadStatus (*OggFLAC__StreamDecoderReadCallback)(const OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
145 /** Signature for the write callback.
146 * See OggFLAC__stream_decoder_set_write_callback()
147 * and FLAC__StreamDecoderWriteCallback for more info.
149 * \param decoder The decoder instance calling the callback.
150 * \param frame The description of the decoded frame.
151 * \param buffer An array of pointers to decoded channels of data.
152 * \param client_data The callee's client data set through
153 * OggFLAC__stream_decoder_set_client_data().
154 * \retval FLAC__StreamDecoderWriteStatus
155 * The callee's return status.
157 typedef FLAC__StreamDecoderWriteStatus (*OggFLAC__StreamDecoderWriteCallback)(const OggFLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
159 /** Signature for the metadata callback.
160 * See OggFLAC__stream_decoder_set_metadata_callback()
161 * and FLAC__StreamDecoderMetadataCallback for more info.
163 * \param decoder The decoder instance calling the callback.
164 * \param metadata The decoded metadata block.
165 * \param client_data The callee's client data set through
166 * OggFLAC__stream_decoder_set_client_data().
168 typedef void (*OggFLAC__StreamDecoderMetadataCallback)(const OggFLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
170 /** Signature for the error callback.
171 * See OggFLAC__stream_decoder_set_error_callback()
172 * and FLAC__StreamDecoderErrorCallback for more info.
174 * \param decoder The decoder instance calling the callback.
175 * \param status The error encountered by the decoder.
176 * \param client_data The callee's client data set through
177 * OggFLAC__stream_decoder_set_client_data().
179 typedef void (*OggFLAC__StreamDecoderErrorCallback)(const OggFLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
182 /***********************************************************************
184 * Class constructor/destructor
186 ***********************************************************************/
188 /** Create a new stream decoder instance. The instance is created with
189 * default settings; see the individual OggFLAC__stream_decoder_set_*()
190 * functions for each setting's default.
192 * \retval OggFLAC__StreamDecoder*
193 * \c NULL if there was an error allocating memory, else the new instance.
195 OggFLAC_API OggFLAC__StreamDecoder *OggFLAC__stream_decoder_new();
197 /** Free a decoder instance. Deletes the object pointed to by \a decoder.
199 * \param decoder A pointer to an existing decoder.
201 * \code decoder != NULL \endcode
203 OggFLAC_API void OggFLAC__stream_decoder_delete(OggFLAC__StreamDecoder *decoder);
206 /***********************************************************************
208 * Public class method prototypes
210 ***********************************************************************/
212 /** Set the read callback.
213 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_read_callback()
216 * The callback is mandatory and must be set before initialization.
219 * \param decoder A decoder instance to set.
220 * \param value See above.
222 * \code decoder != NULL \endcode
223 * \code value != NULL \endcode
225 * \c false if the decoder is already initialized, else \c true.
227 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_read_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderReadCallback value);
229 /** Set the write callback.
230 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_write_callback()
233 * The callback is mandatory and must be set before initialization.
236 * \param decoder A decoder instance to set.
237 * \param value See above.
239 * \code decoder != NULL \endcode
240 * \code value != NULL \endcode
242 * \c false if the decoder is already initialized, else \c true.
244 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_write_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderWriteCallback value);
246 /** Set the metadata callback.
247 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_callback()
250 * The callback is mandatory and must be set before initialization.
253 * \param decoder A decoder instance to set.
254 * \param value See above.
256 * \code decoder != NULL \endcode
257 * \code value != NULL \endcode
259 * \c false if the decoder is already initialized, else \c true.
261 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderMetadataCallback value);
263 /** Set the error callback.
264 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_error_callback()
267 * The callback is mandatory and must be set before initialization.
270 * \param decoder A decoder instance to set.
271 * \param value See above.
273 * \code decoder != NULL \endcode
274 * \code value != NULL \endcode
276 * \c false if the decoder is already initialized, else \c true.
278 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_error_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderErrorCallback value);
280 /** Set the client data to be passed back to callbacks.
281 * This value will be supplied to callbacks in their \a client_data
285 * \param decoder A decoder instance to set.
286 * \param value See above.
288 * \code decoder != NULL \endcode
290 * \c false if the decoder is already initialized, else \c true.
292 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_client_data(OggFLAC__StreamDecoder *decoder, void *value);
294 /** Set the serial number for the Ogg stream.
295 * The default behavior is to use the serial number of the first Ogg
296 * page. Setting a serial number here will explicitly define which
297 * stream is to be decoded.
299 * \default \c use serial number of first page
300 * \param decoder A decoder instance to set.
301 * \param serial_number See above.
303 * \code decoder != NULL \endcode
305 * \c false if the decoder is already initialized, else \c true.
307 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_serial_number(OggFLAC__StreamDecoder *decoder, long serial_number);
309 /** Direct the decoder to pass on all metadata blocks of type \a type.
310 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_respond()
312 * \default By default, only the \c STREAMINFO block is returned via the
314 * \param decoder A decoder instance to set.
315 * \param type See above.
317 * \code decoder != NULL \endcode
320 * \c false if the decoder is already initialized, else \c true.
322 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond(OggFLAC__StreamDecoder *decoder, FLAC__MetadataType type);
324 /** Direct the decoder to pass on all APPLICATION metadata blocks of the
326 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_respond_application()
328 * \default By default, only the \c STREAMINFO block is returned via the
330 * \param decoder A decoder instance to set.
331 * \param id See above.
333 * \code decoder != NULL \endcode
334 * \code id != NULL \endcode
336 * \c false if the decoder is already initialized, else \c true.
338 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
340 /** Direct the decoder to pass on all metadata blocks of any type.
341 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_respond_all()
343 * \default By default, only the \c STREAMINFO block is returned via the
345 * \param decoder A decoder instance to set.
347 * \code decoder != NULL \endcode
349 * \c false if the decoder is already initialized, else \c true.
351 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_all(OggFLAC__StreamDecoder *decoder);
353 /** Direct the decoder to filter out all metadata blocks of type \a type.
354 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_ignore()
356 * \default By default, only the \c STREAMINFO block is returned via the
358 * \param decoder A decoder instance to set.
359 * \param type See above.
361 * \code decoder != NULL \endcode
364 * \c false if the decoder is already initialized, else \c true.
366 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore(OggFLAC__StreamDecoder *decoder, FLAC__MetadataType type);
368 /** Direct the decoder to filter out all APPLICATION metadata blocks of
370 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_ignore_application()
372 * \default By default, only the \c STREAMINFO block is returned via the
374 * \param decoder A decoder instance to set.
375 * \param id See above.
377 * \code decoder != NULL \endcode
378 * \code id != NULL \endcode
380 * \c false if the decoder is already initialized, else \c true.
382 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
384 /** Direct the decoder to filter out all metadata blocks of any type.
385 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_set_metadata_ignore_all()
387 * \default By default, only the \c STREAMINFO block is returned via the
389 * \param decoder A decoder instance to set.
391 * \code decoder != NULL \endcode
393 * \c false if the decoder is already initialized, else \c true.
395 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_all(OggFLAC__StreamDecoder *decoder);
397 /** Get the current decoder state.
399 * \param decoder A decoder instance to query.
401 * \code decoder != NULL \endcode
402 * \retval OggFLAC__StreamDecoderState
403 * The current decoder state.
405 OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__stream_decoder_get_state(const OggFLAC__StreamDecoder *decoder);
407 /** Get the state of the underlying FLAC stream decoder.
408 * Useful when the stream decoder state is
409 * \c OggFLAC__STREAM_DECODER_FLAC_STREAM_DECODER_ERROR.
411 * \param decoder A decoder instance to query.
413 * \code decoder != NULL \endcode
414 * \retval FLAC__StreamDecoderState
415 * The FLAC stream decoder state.
417 OggFLAC_API FLAC__StreamDecoderState OggFLAC__stream_decoder_get_FLAC_stream_decoder_state(const OggFLAC__StreamDecoder *decoder);
419 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_channels()
421 * \param decoder A decoder instance to query.
423 * \code decoder != NULL \endcode
427 OggFLAC_API unsigned OggFLAC__stream_decoder_get_channels(const OggFLAC__StreamDecoder *decoder);
429 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_channel_assignment()
431 * \param decoder A decoder instance to query.
433 * \code decoder != NULL \endcode
434 * \retval OggFLAC__ChannelAssignment
437 OggFLAC_API FLAC__ChannelAssignment OggFLAC__stream_decoder_get_channel_assignment(const OggFLAC__StreamDecoder *decoder);
439 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_bits_per_sample()
441 * \param decoder A decoder instance to query.
443 * \code decoder != NULL \endcode
447 OggFLAC_API unsigned OggFLAC__stream_decoder_get_bits_per_sample(const OggFLAC__StreamDecoder *decoder);
449 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_sample_rate()
451 * \param decoder A decoder instance to query.
453 * \code decoder != NULL \endcode
457 OggFLAC_API unsigned OggFLAC__stream_decoder_get_sample_rate(const OggFLAC__StreamDecoder *decoder);
459 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_get_blocksize()
461 * \param decoder A decoder instance to query.
463 * \code decoder != NULL \endcode
467 OggFLAC_API unsigned OggFLAC__stream_decoder_get_blocksize(const OggFLAC__StreamDecoder *decoder);
469 /** Initialize the decoder instance.
470 * Should be called after OggFLAC__stream_decoder_new() and
471 * OggFLAC__stream_decoder_set_*() but before any of the
472 * OggFLAC__stream_decoder_process_*() functions. Will set and return the
473 * decoder state, which will be OggFLAC__STREAM_DECODER_OK
474 * if initialization succeeded.
476 * \param decoder An uninitialized decoder instance.
478 * \code decoder != NULL \endcode
479 * \retval OggFLAC__StreamDecoderState
480 * \c OggFLAC__STREAM_DECODER_OK if initialization was
481 * successful; see OggFLAC__StreamDecoderState for the meanings of other
484 OggFLAC_API OggFLAC__StreamDecoderState OggFLAC__stream_decoder_init(OggFLAC__StreamDecoder *decoder);
486 /** Finish the decoding process.
487 * Flushes the decoding buffer, releases resources, resets the decoder
488 * settings to their defaults, and returns the decoder state to
489 * OggFLAC__STREAM_DECODER_UNINITIALIZED.
491 * In the event of a prematurely-terminated decode, it is not strictly
492 * necessary to call this immediately before OggFLAC__stream_decoder_delete()
493 * but it is good practice to match every OggFLAC__stream_decoder_init()
494 * with an OggFLAC__stream_decoder_finish().
496 * \param decoder An uninitialized decoder instance.
498 * \code decoder != NULL \endcode
500 OggFLAC_API void OggFLAC__stream_decoder_finish(OggFLAC__StreamDecoder *decoder);
502 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_flush()
504 * \param decoder A decoder instance.
506 * \code decoder != NULL \endcode
508 * \c true if successful, else \c false if a memory allocation
511 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_flush(OggFLAC__StreamDecoder *decoder);
513 /** This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_reset()
515 * \param decoder A decoder instance.
517 * \code decoder != NULL \endcode
519 * \c true if successful, else \c false if a memory allocation
522 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_reset(OggFLAC__StreamDecoder *decoder);
524 /** Decode one metadata block or audio frame.
525 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_process_single()
527 * \param decoder An initialized decoder instance in the state
528 * \c OggFLAC__STREAM_DECODER_OK.
530 * \code decoder != NULL \endcode
531 * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_OK \endcode
533 * \c false if any read or write error occurred (except
534 * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c true;
535 * in any case, check the decoder state with
536 * OggFLAC__stream_decoder_get_state() to see what went wrong or to
537 * check for lost synchronization (a sign of stream corruption).
539 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_single(OggFLAC__StreamDecoder *decoder);
541 /** Decode until the end of the metadata.
542 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_process_until_end_of_metadata()
544 * \param decoder An initialized decoder instance in the state
545 * \c OggFLAC__STREAM_DECODER_OK.
547 * \code decoder != NULL \endcode
548 * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_OK \endcode
550 * \c false if any read or write error occurred (except
551 * \c OggFLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c true;
552 * in any case, check the decoder state with
553 * OggFLAC__stream_decoder_get_state() to see what went wrong or to
554 * check for lost synchronization (a sign of stream corruption).
556 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_metadata(OggFLAC__StreamDecoder *decoder);
558 /** Decode until the end of the stream.
559 * This is inherited from FLAC__StreamDecoder; see FLAC__stream_decoder_process_until_end_of_stream()
561 * \param decoder An initialized decoder instance in the state
562 * \c OggFLAC__STREAM_DECODER_OK.
564 * \code decoder != NULL \endcode
565 * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_OK \endcode
567 * \c false if any read or write error occurred (except
568 * \c OggFLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c true;
569 * in any case, check the decoder state with
570 * OggFLAC__stream_decoder_get_state() to see what went wrong or to
571 * check for lost synchronization (a sign of stream corruption).
573 OggFLAC_API FLAC__bool OggFLAC__stream_decoder_process_until_end_of_stream(OggFLAC__StreamDecoder *decoder);