1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001,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 FLAC__STREAM_DECODER_H
21 #define FLAC__STREAM_DECODER_H
30 /** \file include/FLAC/stream_decoder.h
33 * This module contains the functions which implement the stream
36 * See the detailed documentation in the
37 * \link flac_stream_decoder stream decoder \endlink module.
40 /** \defgroup flac_decoder FLAC/ *_decoder.h: decoder interfaces
44 * This module describes the three decoder layers provided by libFLAC.
46 * For decoding FLAC streams, libFLAC provides three layers of access. The
47 * lowest layer is non-seekable stream-level decoding, the next is seekable
48 * stream-level decoding, and the highest layer is file-level decoding. The
49 * interfaces are described in the \link flac_stream_decoder stream decoder
50 * \endlink, \link flac_seekable_stream_decoder seekable stream decoder
51 * \endlink, and \link flac_file_decoder file decoder \endlink modules
52 * respectively. Typically you will choose the highest layer that your input
53 * source will support.
55 * The stream decoder relies on callbacks for all input and output and has no
56 * provisions for seeking. The seekable stream decoder wraps the stream
57 * decoder and exposes functions for seeking. However, you must provide
58 * extra callbacks for seek-related operations on your stream, like seek and
59 * tell. The file decoder wraps the seekable stream decoder and supplies
60 * most of the callbacks internally, simplifying the processing of standard
64 /** \defgroup flac_stream_decoder FLAC/stream_decoder.h: stream decoder interface
65 * \ingroup flac_decoder
68 * This module contains the functions which implement the stream
71 * The basic usage of this decoder is as follows:
72 * - The program creates an instance of a decoder using
73 * FLAC__stream_decoder_new().
74 * - The program overrides the default settings and sets callbacks for
75 * reading, writing, error reporting, and metadata reporting using
76 * FLAC__stream_decoder_set_*() functions.
77 * - The program initializes the instance to validate the settings and
78 * prepare for decoding using FLAC__stream_decoder_init().
79 * - The program calls the FLAC__stream_decoder_process_*() functions
80 * to decode data, which subsequently calls the callbacks.
81 * - The program finishes the decoding with FLAC__stream_decoder_finish(),
82 * which flushes the input and output and resets the decoder to the
83 * uninitialized state.
84 * - The instance may be used again or deleted with
85 * FLAC__stream_decoder_delete().
87 * In more detail, the program will create a new instance by calling
88 * FLAC__stream_decoder_new(), then call FLAC__stream_decoder_set_*()
89 * functions to set the callbacks and client data, and call
90 * FLAC__stream_decoder_init(). The required callbacks are:
92 * - Read callback - This function will be called when the decoder needs
93 * more input data. The address of the buffer to be filled is supplied,
94 * along with the number of bytes the buffer can hold. The callback may
95 * choose to supply less data and modify the byte count but must be careful
96 * not to overflow the buffer. The callback then returns a status code
97 * chosen from FLAC__StreamDecoderReadStatus.
98 * - Write callback - This function will be called when the decoder has
99 * decoded a single frame of data. The decoder will pass the frame
100 * metadata as well as an array of pointers (one for each channel)
101 * pointing to the decoded audio.
102 * - Metadata callback - This function will be called when the decoder has
103 * decoded a metadata block. In a valid FLAC file there will always be
104 * one STREAMINFO block, followed by zero or more other metadata
105 * blocks. These will be supplied by the decoder in the same order as
106 * they appear in the stream and always before the first audio frame
107 * (i.e. write callback). The metadata block that is passed in must not
108 * be modified, and it doesn't live beyond the callback, so you should
109 * make a copy of it with FLAC__metadata_object_clone() if you will need
110 * it elsewhere. Since metadata blocks can potentially be large, by
111 * default the decoder only calls the metadata callback for the STREAMINFO
112 * block; you can instruct the decoder to pass or filter other blocks with
113 * FLAC__stream_decoder_set_metadata_*() calls.
114 * - Error callback - This function will be called whenever an error occurs
117 * Once the decoder is initialized, your program will call one of several
118 * functions to start the decoding process:
120 * - FLAC__stream_decoder_process_single() - Tells the decoder to process at
121 * most one metadata block or audio frame and return, calling either the
122 * metadata callback or write callback, respectively, once. If the decoder
123 * loses sync it will return with only the error callback being called.
124 * - FLAC__stream_decoder_process_until_end_of_metadata() - Tells the decoder
125 * to process the stream from the current location and stop upon reaching
126 * the first audio frame. The user will get one metadata, write, or error
127 * callback per metadata block, audio frame, or sync error, respectively.
128 * - FLAC__stream_decoder_process_until_end_of_stream() - Tells the decoder
129 * to process the stream from the current location until the read callback
130 * returns FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM or
131 * FLAC__STREAM_DECODER_READ_STATUS_ABORT. The user will get one metadata,
132 * write, or error callback per metadata block, audio frame, or sync error,
135 * When the decoder has finished decoding (normally or through an abort),
136 * the instance is finished by calling FLAC__stream_decoder_finish(), which
137 * ensures the decoder is in the correct state and frees memory. Then the
138 * instance may be deleted with FLAC__stream_decoder_delete() or initialized
139 * again to decode another stream.
141 * Note that the stream decoder has no real concept of stream position, it
142 * just converts data. To seek within a stream the callbacks have only to
143 * flush the decoder using FLAC__stream_decoder_flush() and start feeding
144 * data from the new position through the read callback. The seekable
145 * stream decoder does just this.
147 * The FLAC__stream_decoder_set_metadata_*() functions deserve special
148 * attention. By default, the decoder only calls the metadata_callback for
149 * the STREAMINFO block. These functions allow you to tell the decoder
150 * explicitly which blocks to parse and return via the metadata_callback
151 * and/or which to skip. Use a FLAC__stream_decoder_respond_all(),
152 * FLAC__stream_decoder_ignore() ... or FLAC__stream_decoder_ignore_all(),
153 * FLAC__stream_decoder_respond() ... sequence to exactly specify which
154 * blocks to return. Remember that some metadata blocks can be big so
155 * filtering out the ones you don't use can reduce the memory requirements
156 * of the decoder. Also note the special forms
157 * FLAC__stream_decoder_respond_application(id) and
158 * FLAC__stream_decoder_ignore_application(id) for filtering APPLICATION
159 * blocks based on the application ID.
161 * STREAMINFO and SEEKTABLE blocks are always parsed and used internally, but
162 * they still can legally be filtered from the metadata_callback.
165 * The "set" functions may only be called when the decoder is in the
166 * state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after
167 * FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but
168 * before FLAC__stream_decoder_init(). If this is the case they will
169 * return \c true, otherwise \c false.
172 * FLAC__stream_decoder_finish() resets all settings to the constructor
173 * defaults, including the callbacks.
179 /** State values for a FLAC__StreamDecoder
181 * The decoder's state can be obtained by calling FLAC__stream_decoder_get_state().
185 FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
186 /**< The decoder is ready to search for metadata. */
188 FLAC__STREAM_DECODER_READ_METADATA,
189 /**< The decoder is ready to or is in the process of reading metadata. */
191 FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
192 /**< The decoder is ready to or is in the process of searching for the frame sync code. */
194 FLAC__STREAM_DECODER_READ_FRAME,
195 /**< The decoder is ready to or is in the process of reading a frame. */
197 FLAC__STREAM_DECODER_END_OF_STREAM,
198 /**< The decoder has reached the end of the stream. */
200 FLAC__STREAM_DECODER_ABORTED,
201 /**< The decoder was aborted by the read callback. */
203 FLAC__STREAM_DECODER_UNPARSEABLE_STREAM,
204 /**< The decoder encountered reserved fields in use in the stream. */
206 FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
207 /**< An error occurred allocating memory. */
209 FLAC__STREAM_DECODER_ALREADY_INITIALIZED,
210 /**< FLAC__stream_decoder_init() was called when the decoder was
211 * already initialized, usually because
212 * FLAC__stream_decoder_finish() was not called.
215 FLAC__STREAM_DECODER_INVALID_CALLBACK,
216 /**< FLAC__stream_decoder_init() was called without all callbacks being set. */
218 FLAC__STREAM_DECODER_UNINITIALIZED
219 /**< The decoder is in the uninitialized state. */
221 } FLAC__StreamDecoderState;
223 /** Maps a FLAC__StreamDecoderState to a C string.
225 * Using a FLAC__StreamDecoderState as the index to this array
226 * will give the string equivalent. The contents should not be modified.
228 extern const char * const FLAC__StreamDecoderStateString[];
231 /** Return values for the FLAC__StreamDecoder read callback.
235 FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
236 /**< The read was OK and decoding can continue. */
238 FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
239 /**< The read was attempted at the end of the stream. */
241 FLAC__STREAM_DECODER_READ_STATUS_ABORT
242 /**< An unrecoverable error occurred. The decoder will return from the process call. */
244 } FLAC__StreamDecoderReadStatus;
246 /** Maps a FLAC__StreamDecoderReadStatus to a C string.
248 * Using a FLAC__StreamDecoderReadStatus as the index to this array
249 * will give the string equivalent. The contents should not be modified.
251 extern const char * const FLAC__StreamDecoderReadStatusString[];
254 /** Return values for the FLAC__StreamDecoder write callback.
258 FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
259 /**< The write was OK and decoding can continue. */
261 FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
262 /**< An unrecoverable error occurred. The decoder will return from the process call. */
264 } FLAC__StreamDecoderWriteStatus;
266 /** Maps a FLAC__StreamDecoderWriteStatus to a C string.
268 * Using a FLAC__StreamDecoderWriteStatus as the index to this array
269 * will give the string equivalent. The contents should not be modified.
271 extern const char * const FLAC__StreamDecoderWriteStatusString[];
274 /** Possible values passed in to the FLAC__StreamDecoder error callback.
278 FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
279 /**< An error in the stream caused the decoder to lose synchronization. */
281 FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
282 /**< The decoder encountered a corrupted frame header. */
284 FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH
285 /**< The frame's data did not match the CRC in the footer. */
287 } FLAC__StreamDecoderErrorStatus;
289 /** Maps a FLAC__StreamDecoderErrorStatus to a C string.
291 * Using a FLAC__StreamDecoderErrorStatus as the index to this array
292 * will give the string equivalent. The contents should not be modified.
294 extern const char * const FLAC__StreamDecoderErrorStatusString[];
297 /***********************************************************************
299 * class FLAC__StreamDecoder
301 ***********************************************************************/
303 struct FLAC__StreamDecoderProtected;
304 struct FLAC__StreamDecoderPrivate;
305 /** The opaque structure definition for the stream decoder type.
306 * See the \link flac_stream_decoder stream decoder module \endlink
307 * for a detailed description.
310 struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
311 struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
312 } FLAC__StreamDecoder;
314 /** Signature for the read callback.
315 * See FLAC__stream_decoder_set_read_callback() for more info.
317 * \param decoder The decoder instance calling the callback.
318 * \param buffer A pointer to a location for the callee to store
319 * data to be decoded.
320 * \param bytes A pointer to the size of the buffer. On entry
321 * to the callback, it contains the maximum number
322 * of bytes that may be stored in \a buffer. The
323 * callee must set it to the actual number of bytes
324 * stored before returning.
325 * \param client_data The callee's client data set through
326 * FLAC__stream_decoder_set_client_data().
327 * \retval FLAC__StreamDecoderReadStatus
328 * The callee's return status.
330 typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
332 /** Signature for the write callback.
333 * See FLAC__stream_decoder_set_write_callback() for more info.
335 * \param decoder The decoder instance calling the callback.
336 * \param frame The description of the decoded frame. See
338 * \param buffer An array of pointers to decoded channels of data.
339 * Each pointer will point to an array of signed
340 * samples of length \a frame->header.blocksize.
341 * Currently, the channel order has no meaning
342 * except for stereo streams; in this case channel
343 * 0 is left and 1 is right.
344 * \param client_data The callee's client data set through
345 * FLAC__stream_decoder_set_client_data().
346 * \retval FLAC__StreamDecoderWriteStatus
347 * The callee's return status.
349 typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
351 /** Signature for the metadata callback.
352 * See FLAC__stream_decoder_set_metadata_callback() for more info.
354 * \param decoder The decoder instance calling the callback.
355 * \param metadata The decoded metadata block.
356 * \param client_data The callee's client data set through
357 * FLAC__stream_decoder_set_client_data().
359 typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
361 /** Signature for the error callback.
362 * See FLAC__stream_decoder_set_error_callback() for more info.
364 * \param decoder The decoder instance calling the callback.
365 * \param status The error encountered by the decoder.
366 * \param client_data The callee's client data set through
367 * FLAC__stream_decoder_set_client_data().
369 typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
372 /***********************************************************************
374 * Class constructor/destructor
376 ***********************************************************************/
378 /** Create a new stream decoder instance. The instance is created with
379 * default settings; see the individual FLAC__stream_decoder_set_*()
380 * functions for each setting's default.
382 * \retval FLAC__StreamDecoder*
383 * \c NULL if there was an error allocating memory, else the new instance.
385 FLAC__StreamDecoder *FLAC__stream_decoder_new();
387 /** Free a decoder instance. Deletes the object pointed to by \a decoder.
389 * \param decoder A pointer to an existing decoder.
391 * \code decoder != NULL \endcode
393 void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
396 /***********************************************************************
398 * Public class method prototypes
400 ***********************************************************************/
402 /** Set the read callback.
403 * The supplied function will be called when the decoder needs more input
404 * data. The address of the buffer to be filled is supplied, along with
405 * the number of bytes the buffer can hold. The callback may choose to
406 * supply less data and modify the byte count but must be careful not to
407 * overflow the buffer. The callback then returns a status code chosen
408 * from FLAC__StreamDecoderReadStatus.
411 * The callback is mandatory and must be set before initialization.
414 * \param decoder A decoder instance to set.
415 * \param value See above.
417 * \code decoder != NULL \endcode
418 * \code value != NULL \endcode
420 * \c false if the decoder is already initialized, else \c true.
422 FLAC__bool FLAC__stream_decoder_set_read_callback(FLAC__StreamDecoder *decoder, FLAC__StreamDecoderReadCallback value);
424 /** Set the write callback.
425 * The supplied function will be called when the decoder has decoded a
426 * single frame of data. The decoder will pass the frame metadata as
427 * well as an array of pointers (one for each channel) pointing to the
431 * The callback is mandatory and must be set before initialization.
434 * \param decoder A decoder instance to set.
435 * \param value See above.
437 * \code decoder != NULL \endcode
438 * \code value != NULL \endcode
440 * \c false if the decoder is already initialized, else \c true.
442 FLAC__bool FLAC__stream_decoder_set_write_callback(FLAC__StreamDecoder *decoder, FLAC__StreamDecoderWriteCallback value);
444 /** Set the metadata callback.
445 * The supplied function will be called when the decoder has decoded a metadata
446 * block. In a valid FLAC file there will always be one STREAMINFO block,
447 * followed by zero or more other metadata blocks. These will be supplied
448 * by the decoder in the same order as they appear in the stream and always
449 * before the first audio frame (i.e. write callback). The metadata block
450 * that is passed in must not be modified, and it doesn't live beyond the
451 * callback, so you should make a copy of it with
452 * FLAC__metadata_object_clone() if you will need it elsewhere. Since
453 * metadata blocks can potentially be large, by default the decoder only
454 * calls the metadata callback for the STREAMINFO block; you can instruct
455 * the decoder to pass or filter other blocks with
456 * FLAC__stream_decoder_set_metadata_*() calls.
459 * The callback is mandatory and must be set before initialization.
462 * \param decoder A decoder instance to set.
463 * \param value See above.
465 * \code decoder != NULL \endcode
466 * \code value != NULL \endcode
468 * \c false if the decoder is already initialized, else \c true.
470 FLAC__bool FLAC__stream_decoder_set_metadata_callback(FLAC__StreamDecoder *decoder, FLAC__StreamDecoderMetadataCallback value);
472 /** Set the error callback.
473 * The supplied function will be called whenever an error occurs during
477 * The callback is mandatory and must be set before initialization.
480 * \param decoder A decoder instance to set.
481 * \param value See above.
483 * \code decoder != NULL \endcode
484 * \code value != NULL \endcode
486 * \c false if the decoder is already initialized, else \c true.
488 FLAC__bool FLAC__stream_decoder_set_error_callback(FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorCallback value);
490 /** Set the client data to be passed back to callbacks.
491 * This value will be supplied to callbacks in their \a client_data
495 * \param decoder A decoder instance to set.
496 * \param value See above.
498 * \code decoder != NULL \endcode
500 * \c false if the decoder is already initialized, else \c true.
502 FLAC__bool FLAC__stream_decoder_set_client_data(FLAC__StreamDecoder *decoder, void *value);
504 /** Direct the decoder to pass on all metadata blocks of type \a type.
506 * \default By default, only the \c STREAMINFO block is returned via the
508 * \param decoder A decoder instance to set.
509 * \param type See above.
511 * \code decoder != NULL \endcode
514 * \c false if the decoder is already initialized, else \c true.
516 FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
518 /** Direct the decoder to pass on all APPLICATION metadata blocks of the
521 * \default By default, only the \c STREAMINFO block is returned via the
523 * \param decoder A decoder instance to set.
524 * \param id See above.
526 * \code decoder != NULL \endcode
527 * \code id != NULL \endcode
529 * \c false if the decoder is already initialized, else \c true.
531 FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
533 /** Direct the decoder to pass on all metadata blocks of any type.
535 * \default By default, only the \c STREAMINFO block is returned via the
537 * \param decoder A decoder instance to set.
539 * \code decoder != NULL \endcode
541 * \c false if the decoder is already initialized, else \c true.
543 FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
545 /** Direct the decoder to filter out all metadata blocks of type \a type.
547 * \default By default, only the \c STREAMINFO block is returned via the
549 * \param decoder A decoder instance to set.
550 * \param type See above.
552 * \code decoder != NULL \endcode
555 * \c false if the decoder is already initialized, else \c true.
557 FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
559 /** Direct the decoder to filter out all APPLICATION metadata blocks of
562 * \default By default, only the \c STREAMINFO block is returned via the
564 * \param decoder A decoder instance to set.
565 * \param id See above.
567 * \code decoder != NULL \endcode
568 * \code id != NULL \endcode
570 * \c false if the decoder is already initialized, else \c true.
572 FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
574 /** Direct the decoder to filter out all metadata blocks of any type.
576 * \default By default, only the \c STREAMINFO block is returned via the
578 * \param decoder A decoder instance to set.
580 * \code decoder != NULL \endcode
582 * \c false if the decoder is already initialized, else \c true.
584 FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
586 /** Get the current decoder state.
588 * \param decoder A decoder instance to query.
590 * \code decoder != NULL \endcode
591 * \retval FLAC__StreamDecoderState
592 * The current decoder state.
594 FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
596 /** Get the current number of channels in the stream being decoded.
597 * Will only be valid after decoding has started and will contain the
598 * value from the most recently decoded frame header.
600 * \param decoder A decoder instance to query.
602 * \code decoder != NULL \endcode
606 unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
608 /** Get the current channel assignment in the stream being decoded.
609 * Will only be valid after decoding has started and will contain the
610 * value from the most recently decoded frame header.
612 * \param decoder A decoder instance to query.
614 * \code decoder != NULL \endcode
615 * \retval FLAC__ChannelAssignment
618 FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
620 /** Get the current sample resolution in the stream being decoded.
621 * Will only be valid after decoding has started and will contain the
622 * value from the most recently decoded frame header.
624 * \param decoder A decoder instance to query.
626 * \code decoder != NULL \endcode
630 unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
632 /** Get the current sample rate in Hz of the stream being decoded.
633 * Will only be valid after decoding has started and will contain the
634 * value from the most recently decoded frame header.
636 * \param decoder A decoder instance to query.
638 * \code decoder != NULL \endcode
642 unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
644 /** Get the current blocksize of the stream being decoded.
645 * Will only be valid after decoding has started and will contain the
646 * value from the most recently decoded frame header.
648 * \param decoder A decoder instance to query.
650 * \code decoder != NULL \endcode
654 unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
656 /** Initialize the decoder instance.
657 * Should be called after FLAC__stream_decoder_new() and
658 * FLAC__stream_decoder_set_*() but before any of the
659 * FLAC__stream_decoder_process_*() functions. Will set and return the
660 * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
661 * if initialization succeeded.
663 * \param decoder An uninitialized decoder instance.
665 * \code decoder != NULL \endcode
666 * \retval FLAC__StreamDecoderState
667 * \c FLAC__STREAM_DECODER_SEARCH_FOR_MEATADATA if initialization was
668 * successful; see FLAC__StreamDecoderState for the meanings of other
671 FLAC__StreamDecoderState FLAC__stream_decoder_init(FLAC__StreamDecoder *decoder);
673 /** Finish the decoding process.
674 * Flushes the decoding buffer, releases resources, resets the decoder
675 * settings to their defaults, and returns the decoder state to
676 * FLAC__STREAM_DECODER_UNINITIALIZED.
678 * In the event of a prematurely-terminated decode, it is not strictly
679 * necessary to call this immediately before FLAC__stream_decoder_delete()
680 * but it is good practice to match every FLAC__stream_decoder_init()
681 * with a FLAC__stream_decoder_finish().
683 * \param decoder An uninitialized decoder instance.
685 * \code decoder != NULL \endcode
687 void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
689 /** Flush the stream input.
690 * The decoder's input buffer will be cleared and the state set to
691 * \c FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC.
693 * \param decoder A decoder instance.
695 * \code decoder != NULL \endcode
697 * \c true if successful, else \c false if a memory allocation
700 FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
702 /** Reset the decoding process.
703 * The decoder's input buffer will be cleared and the state set to
704 * \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA. This is similar to
705 * FLAC__stream_decoder_finish() except that the settings are
706 * preserved; there is no need to call FLAC__stream_decoder_init()
707 * before decoding again.
709 * \param decoder A decoder instance.
711 * \code decoder != NULL \endcode
713 * \c true if successful, else \c false if a memory allocation
716 FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
718 /** Decode one metadata block or audio frame.
719 * This version instructs the decoder to decode a either a single metadata
720 * block or a single frame and stop, unless the callbacks return a fatal
721 * error or the read callback returns
722 * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM.
724 * As the decoder needs more input it will call the read callback.
725 * Depending on what was decoded, the metadata or write callback will be
726 * called with the decoded metadata block or audio frame, unless an error
727 * occurred. If the decoder loses sync it will call the error callback
730 * \param decoder An initialized decoder instance in the state
731 * \c FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC.
733 * \code decoder != NULL \endcode
734 * \code FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC \endcode
736 * \c false if any read or write error occurred (except
737 * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c true;
738 * in any case, check the decoder state with
739 * FLAC__stream_decoder_get_state() to see what went wrong or to
740 * check for lost synchronization (a sign of stream corruption).
742 FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
744 /** Decode until the end of the metadata.
745 * This version instructs the decoder to decode from the current position
746 * and continue until all the metadata has been read, or until the
747 * callbacks return a fatal error or the read callback returns
748 * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM.
750 * As the decoder needs more input it will call the read callback.
751 * As each metadata block is decoded, the metadata callback will be called
752 * with the decoded metadata. If the decoder loses sync it will call the
755 * \param decoder An initialized decoder instance in the state
756 * \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA.
758 * \code decoder != NULL \endcode
759 * \code FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA \endcode
761 * \c false if any read or write error occurred (except
762 * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c true;
763 * in any case, check the decoder state with
764 * FLAC__stream_decoder_get_state() to see what went wrong or to
765 * check for lost synchronization (a sign of stream corruption).
767 FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
769 /** Decode until the end of the stream.
770 * This version instructs the decoder to decode from the current position
771 * and continue until the end of stream (the read callback returns
772 * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM), or until the
773 * callbacks return a fatal error.
775 * As the decoder needs more input it will call the read callback.
776 * As each metadata block and frame is decoded, the metadata or write
777 * callback will be called with the decoded metadata or frame. If the
778 * decoder loses sync it will call the error callback.
780 * \param decoder An initialized decoder instance in the state
781 * \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA.
783 * \code decoder != NULL \endcode
784 * \code FLAC__stream_decoder_get_state(decoder) == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA \endcode
786 * \c false if any read or write error occurred (except
787 * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c true;
788 * in any case, check the decoder state with
789 * FLAC__stream_decoder_get_state() to see what went wrong or to
790 * check for lost synchronization (a sign of stream corruption).
792 FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);