cannam@90: /* libFLAC - Free Lossless Audio Codec library cannam@90: * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson cannam@90: * cannam@90: * Redistribution and use in source and binary forms, with or without cannam@90: * modification, are permitted provided that the following conditions cannam@90: * are met: cannam@90: * cannam@90: * - Redistributions of source code must retain the above copyright cannam@90: * notice, this list of conditions and the following disclaimer. cannam@90: * cannam@90: * - Redistributions in binary form must reproduce the above copyright cannam@90: * notice, this list of conditions and the following disclaimer in the cannam@90: * documentation and/or other materials provided with the distribution. cannam@90: * cannam@90: * - Neither the name of the Xiph.org Foundation nor the names of its cannam@90: * contributors may be used to endorse or promote products derived from cannam@90: * this software without specific prior written permission. cannam@90: * cannam@90: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@90: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT cannam@90: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR cannam@90: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR cannam@90: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@90: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@90: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR cannam@90: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF cannam@90: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING cannam@90: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS cannam@90: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@90: */ cannam@90: cannam@90: #ifndef FLAC__STREAM_DECODER_H cannam@90: #define FLAC__STREAM_DECODER_H cannam@90: cannam@90: #include /* for FILE */ cannam@90: #include "export.h" cannam@90: #include "format.h" cannam@90: cannam@90: #ifdef __cplusplus cannam@90: extern "C" { cannam@90: #endif cannam@90: cannam@90: cannam@90: /** \file include/FLAC/stream_decoder.h cannam@90: * cannam@90: * \brief cannam@90: * This module contains the functions which implement the stream cannam@90: * decoder. cannam@90: * cannam@90: * See the detailed documentation in the cannam@90: * \link flac_stream_decoder stream decoder \endlink module. cannam@90: */ cannam@90: cannam@90: /** \defgroup flac_decoder FLAC/ \*_decoder.h: decoder interfaces cannam@90: * \ingroup flac cannam@90: * cannam@90: * \brief cannam@90: * This module describes the decoder layers provided by libFLAC. cannam@90: * cannam@90: * The stream decoder can be used to decode complete streams either from cannam@90: * the client via callbacks, or directly from a file, depending on how cannam@90: * it is initialized. When decoding via callbacks, the client provides cannam@90: * callbacks for reading FLAC data and writing decoded samples, and cannam@90: * handling metadata and errors. If the client also supplies seek-related cannam@90: * callback, the decoder function for sample-accurate seeking within the cannam@90: * FLAC input is also available. When decoding from a file, the client cannam@90: * needs only supply a filename or open \c FILE* and write/metadata/error cannam@90: * callbacks; the rest of the callbacks are supplied internally. For more cannam@90: * info see the \link flac_stream_decoder stream decoder \endlink module. cannam@90: */ cannam@90: cannam@90: /** \defgroup flac_stream_decoder FLAC/stream_decoder.h: stream decoder interface cannam@90: * \ingroup flac_decoder cannam@90: * cannam@90: * \brief cannam@90: * This module contains the functions which implement the stream cannam@90: * decoder. cannam@90: * cannam@90: * The stream decoder can decode native FLAC, and optionally Ogg FLAC cannam@90: * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files. cannam@90: * cannam@90: * The basic usage of this decoder is as follows: cannam@90: * - The program creates an instance of a decoder using cannam@90: * FLAC__stream_decoder_new(). cannam@90: * - The program overrides the default settings using cannam@90: * FLAC__stream_decoder_set_*() functions. cannam@90: * - The program initializes the instance to validate the settings and cannam@90: * prepare for decoding using cannam@90: * - FLAC__stream_decoder_init_stream() or FLAC__stream_decoder_init_FILE() cannam@90: * or FLAC__stream_decoder_init_file() for native FLAC, cannam@90: * - FLAC__stream_decoder_init_ogg_stream() or FLAC__stream_decoder_init_ogg_FILE() cannam@90: * or FLAC__stream_decoder_init_ogg_file() for Ogg FLAC cannam@90: * - The program calls the FLAC__stream_decoder_process_*() functions cannam@90: * to decode data, which subsequently calls the callbacks. cannam@90: * - The program finishes the decoding with FLAC__stream_decoder_finish(), cannam@90: * which flushes the input and output and resets the decoder to the cannam@90: * uninitialized state. cannam@90: * - The instance may be used again or deleted with cannam@90: * FLAC__stream_decoder_delete(). cannam@90: * cannam@90: * In more detail, the program will create a new instance by calling cannam@90: * FLAC__stream_decoder_new(), then call FLAC__stream_decoder_set_*() cannam@90: * functions to override the default decoder options, and call cannam@90: * one of the FLAC__stream_decoder_init_*() functions. cannam@90: * cannam@90: * There are three initialization functions for native FLAC, one for cannam@90: * setting up the decoder to decode FLAC data from the client via cannam@90: * callbacks, and two for decoding directly from a FLAC file. cannam@90: * cannam@90: * For decoding via callbacks, use FLAC__stream_decoder_init_stream(). cannam@90: * You must also supply several callbacks for handling I/O. Some (like cannam@90: * seeking) are optional, depending on the capabilities of the input. cannam@90: * cannam@90: * For decoding directly from a file, use FLAC__stream_decoder_init_FILE() cannam@90: * or FLAC__stream_decoder_init_file(). Then you must only supply an open cannam@90: * \c FILE* or filename and fewer callbacks; the decoder will handle cannam@90: * the other callbacks internally. cannam@90: * cannam@90: * There are three similarly-named init functions for decoding from Ogg cannam@90: * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the cannam@90: * library has been built with Ogg support. cannam@90: * cannam@90: * Once the decoder is initialized, your program will call one of several cannam@90: * functions to start the decoding process: cannam@90: * cannam@90: * - FLAC__stream_decoder_process_single() - Tells the decoder to process at cannam@90: * most one metadata block or audio frame and return, calling either the cannam@90: * metadata callback or write callback, respectively, once. If the decoder cannam@90: * loses sync it will return with only the error callback being called. cannam@90: * - FLAC__stream_decoder_process_until_end_of_metadata() - Tells the decoder cannam@90: * to process the stream from the current location and stop upon reaching cannam@90: * the first audio frame. The client will get one metadata, write, or error cannam@90: * callback per metadata block, audio frame, or sync error, respectively. cannam@90: * - FLAC__stream_decoder_process_until_end_of_stream() - Tells the decoder cannam@90: * to process the stream from the current location until the read callback cannam@90: * returns FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM or cannam@90: * FLAC__STREAM_DECODER_READ_STATUS_ABORT. The client will get one metadata, cannam@90: * write, or error callback per metadata block, audio frame, or sync error, cannam@90: * respectively. cannam@90: * cannam@90: * When the decoder has finished decoding (normally or through an abort), cannam@90: * the instance is finished by calling FLAC__stream_decoder_finish(), which cannam@90: * ensures the decoder is in the correct state and frees memory. Then the cannam@90: * instance may be deleted with FLAC__stream_decoder_delete() or initialized cannam@90: * again to decode another stream. cannam@90: * cannam@90: * Seeking is exposed through the FLAC__stream_decoder_seek_absolute() method. cannam@90: * At any point after the stream decoder has been initialized, the client can cannam@90: * call this function to seek to an exact sample within the stream. cannam@90: * Subsequently, the first time the write callback is called it will be cannam@90: * passed a (possibly partial) block starting at that sample. cannam@90: * cannam@90: * If the client cannot seek via the callback interface provided, but still cannam@90: * has another way of seeking, it can flush the decoder using cannam@90: * FLAC__stream_decoder_flush() and start feeding data from the new position cannam@90: * through the read callback. cannam@90: * cannam@90: * The stream decoder also provides MD5 signature checking. If this is cannam@90: * turned on before initialization, FLAC__stream_decoder_finish() will cannam@90: * report when the decoded MD5 signature does not match the one stored cannam@90: * in the STREAMINFO block. MD5 checking is automatically turned off cannam@90: * (until the next FLAC__stream_decoder_reset()) if there is no signature cannam@90: * in the STREAMINFO block or when a seek is attempted. cannam@90: * cannam@90: * The FLAC__stream_decoder_set_metadata_*() functions deserve special cannam@90: * attention. By default, the decoder only calls the metadata_callback for cannam@90: * the STREAMINFO block. These functions allow you to tell the decoder cannam@90: * explicitly which blocks to parse and return via the metadata_callback cannam@90: * and/or which to skip. Use a FLAC__stream_decoder_set_metadata_respond_all(), cannam@90: * FLAC__stream_decoder_set_metadata_ignore() ... or FLAC__stream_decoder_set_metadata_ignore_all(), cannam@90: * FLAC__stream_decoder_set_metadata_respond() ... sequence to exactly specify cannam@90: * which blocks to return. Remember that metadata blocks can potentially cannam@90: * be big (for example, cover art) so filtering out the ones you don't cannam@90: * use can reduce the memory requirements of the decoder. Also note the cannam@90: * special forms FLAC__stream_decoder_set_metadata_respond_application(id) cannam@90: * and FLAC__stream_decoder_set_metadata_ignore_application(id) for cannam@90: * filtering APPLICATION blocks based on the application ID. cannam@90: * cannam@90: * STREAMINFO and SEEKTABLE blocks are always parsed and used internally, but cannam@90: * they still can legally be filtered from the metadata_callback. cannam@90: * cannam@90: * \note cannam@90: * The "set" functions may only be called when the decoder is in the cannam@90: * state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after cannam@90: * FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but cannam@90: * before FLAC__stream_decoder_init_*(). If this is the case they will cannam@90: * return \c true, otherwise \c false. cannam@90: * cannam@90: * \note cannam@90: * FLAC__stream_decoder_finish() resets all settings to the constructor cannam@90: * defaults, including the callbacks. cannam@90: * cannam@90: * \{ cannam@90: */ cannam@90: cannam@90: cannam@90: /** State values for a FLAC__StreamDecoder cannam@90: * cannam@90: * The decoder's state can be obtained by calling FLAC__stream_decoder_get_state(). cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0, cannam@90: /**< The decoder is ready to search for metadata. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_READ_METADATA, cannam@90: /**< The decoder is ready to or is in the process of reading metadata. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC, cannam@90: /**< The decoder is ready to or is in the process of searching for the cannam@90: * frame sync code. cannam@90: */ cannam@90: cannam@90: FLAC__STREAM_DECODER_READ_FRAME, cannam@90: /**< The decoder is ready to or is in the process of reading a frame. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_END_OF_STREAM, cannam@90: /**< The decoder has reached the end of the stream. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_OGG_ERROR, cannam@90: /**< An error occurred in the underlying Ogg layer. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_SEEK_ERROR, cannam@90: /**< An error occurred while seeking. The decoder must be flushed cannam@90: * with FLAC__stream_decoder_flush() or reset with cannam@90: * FLAC__stream_decoder_reset() before decoding can continue. cannam@90: */ cannam@90: cannam@90: FLAC__STREAM_DECODER_ABORTED, cannam@90: /**< The decoder was aborted by the read callback. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR, cannam@90: /**< An error occurred allocating memory. The decoder is in an invalid cannam@90: * state and can no longer be used. cannam@90: */ cannam@90: cannam@90: FLAC__STREAM_DECODER_UNINITIALIZED cannam@90: /**< The decoder is in the uninitialized state; one of the cannam@90: * FLAC__stream_decoder_init_*() functions must be called before samples cannam@90: * can be processed. cannam@90: */ cannam@90: cannam@90: } FLAC__StreamDecoderState; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderState to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderState as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderStateString[]; cannam@90: cannam@90: cannam@90: /** Possible return values for the FLAC__stream_decoder_init_*() functions. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_INIT_STATUS_OK = 0, cannam@90: /**< Initialization was successful. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER, cannam@90: /**< The library was not compiled with support for the given container cannam@90: * format. cannam@90: */ cannam@90: cannam@90: FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS, cannam@90: /**< A required callback was not supplied. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR, cannam@90: /**< An error occurred allocating memory. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE, cannam@90: /**< fopen() failed in FLAC__stream_decoder_init_file() or cannam@90: * FLAC__stream_decoder_init_ogg_file(). */ cannam@90: cannam@90: FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED cannam@90: /**< FLAC__stream_decoder_init_*() was called when the decoder was cannam@90: * already initialized, usually because cannam@90: * FLAC__stream_decoder_finish() was not called. cannam@90: */ cannam@90: cannam@90: } FLAC__StreamDecoderInitStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderInitStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderInitStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[]; cannam@90: cannam@90: cannam@90: /** Return values for the FLAC__StreamDecoder read callback. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_READ_STATUS_CONTINUE, cannam@90: /**< The read was OK and decoding can continue. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM, cannam@90: /**< The read was attempted while at the end of the stream. Note that cannam@90: * the client must only return this value when the read callback was cannam@90: * called when already at the end of the stream. Otherwise, if the read cannam@90: * itself moves to the end of the stream, the client should still return cannam@90: * the data and \c FLAC__STREAM_DECODER_READ_STATUS_CONTINUE, and then on cannam@90: * the next read callback it should return cannam@90: * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM with a byte count cannam@90: * of \c 0. cannam@90: */ cannam@90: cannam@90: FLAC__STREAM_DECODER_READ_STATUS_ABORT cannam@90: /**< An unrecoverable error occurred. The decoder will return from the process call. */ cannam@90: cannam@90: } FLAC__StreamDecoderReadStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderReadStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderReadStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[]; cannam@90: cannam@90: cannam@90: /** Return values for the FLAC__StreamDecoder seek callback. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_SEEK_STATUS_OK, cannam@90: /**< The seek was OK and decoding can continue. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_SEEK_STATUS_ERROR, cannam@90: /**< An unrecoverable error occurred. The decoder will return from the process call. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED cannam@90: /**< Client does not support seeking. */ cannam@90: cannam@90: } FLAC__StreamDecoderSeekStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderSeekStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderSeekStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[]; cannam@90: cannam@90: cannam@90: /** Return values for the FLAC__StreamDecoder tell callback. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_TELL_STATUS_OK, cannam@90: /**< The tell was OK and decoding can continue. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_TELL_STATUS_ERROR, cannam@90: /**< An unrecoverable error occurred. The decoder will return from the process call. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED cannam@90: /**< Client does not support telling the position. */ cannam@90: cannam@90: } FLAC__StreamDecoderTellStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderTellStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderTellStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[]; cannam@90: cannam@90: cannam@90: /** Return values for the FLAC__StreamDecoder length callback. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_LENGTH_STATUS_OK, cannam@90: /**< The length call was OK and decoding can continue. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR, cannam@90: /**< An unrecoverable error occurred. The decoder will return from the process call. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED cannam@90: /**< Client does not support reporting the length. */ cannam@90: cannam@90: } FLAC__StreamDecoderLengthStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderLengthStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderLengthStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[]; cannam@90: cannam@90: cannam@90: /** Return values for the FLAC__StreamDecoder write callback. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE, cannam@90: /**< The write was OK and decoding can continue. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_WRITE_STATUS_ABORT cannam@90: /**< An unrecoverable error occurred. The decoder will return from the process call. */ cannam@90: cannam@90: } FLAC__StreamDecoderWriteStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderWriteStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderWriteStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[]; cannam@90: cannam@90: cannam@90: /** Possible values passed back to the FLAC__StreamDecoder error callback. cannam@90: * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC is the generic catch- cannam@90: * all. The rest could be caused by bad sync (false synchronization on cannam@90: * data that is not the start of a frame) or corrupted data. The error cannam@90: * itself is the decoder's best guess at what happened assuming a correct cannam@90: * sync. For example \c FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER cannam@90: * could be caused by a correct sync on the start of a frame, but some cannam@90: * data in the frame header was corrupted. Or it could be the result of cannam@90: * syncing on a point the stream that looked like the starting of a frame cannam@90: * but was not. \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM cannam@90: * could be because the decoder encountered a valid frame made by a future cannam@90: * version of the encoder which it cannot parse, or because of a false cannam@90: * sync making it appear as though an encountered frame was generated by cannam@90: * a future encoder. cannam@90: */ cannam@90: typedef enum { cannam@90: cannam@90: FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC, cannam@90: /**< An error in the stream caused the decoder to lose synchronization. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER, cannam@90: /**< The decoder encountered a corrupted frame header. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH, cannam@90: /**< The frame's data did not match the CRC in the footer. */ cannam@90: cannam@90: FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM cannam@90: /**< The decoder encountered reserved fields in use in the stream. */ cannam@90: cannam@90: } FLAC__StreamDecoderErrorStatus; cannam@90: cannam@90: /** Maps a FLAC__StreamDecoderErrorStatus to a C string. cannam@90: * cannam@90: * Using a FLAC__StreamDecoderErrorStatus as the index to this array cannam@90: * will give the string equivalent. The contents should not be modified. cannam@90: */ cannam@90: extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[]; cannam@90: cannam@90: cannam@90: /*********************************************************************** cannam@90: * cannam@90: * class FLAC__StreamDecoder cannam@90: * cannam@90: ***********************************************************************/ cannam@90: cannam@90: struct FLAC__StreamDecoderProtected; cannam@90: struct FLAC__StreamDecoderPrivate; cannam@90: /** The opaque structure definition for the stream decoder type. cannam@90: * See the \link flac_stream_decoder stream decoder module \endlink cannam@90: * for a detailed description. cannam@90: */ cannam@90: typedef struct { cannam@90: struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */ cannam@90: struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */ cannam@90: } FLAC__StreamDecoder; cannam@90: cannam@90: /** Signature for the read callback. cannam@90: * cannam@90: * A function pointer matching this signature must be passed to cannam@90: * FLAC__stream_decoder_init*_stream(). The supplied function will be cannam@90: * called when the decoder needs more input data. The address of the cannam@90: * buffer to be filled is supplied, along with the number of bytes the cannam@90: * buffer can hold. The callback may choose to supply less data and cannam@90: * modify the byte count but must be careful not to overflow the buffer. cannam@90: * The callback then returns a status code chosen from cannam@90: * FLAC__StreamDecoderReadStatus. cannam@90: * cannam@90: * Here is an example of a read callback for stdio streams: cannam@90: * \code cannam@90: * FLAC__StreamDecoderReadStatus read_cb(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data) cannam@90: * { cannam@90: * FILE *file = ((MyClientData*)client_data)->file; cannam@90: * if(*bytes > 0) { cannam@90: * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file); cannam@90: * if(ferror(file)) cannam@90: * return FLAC__STREAM_DECODER_READ_STATUS_ABORT; cannam@90: * else if(*bytes == 0) cannam@90: * return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM; cannam@90: * else cannam@90: * return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE; cannam@90: * } cannam@90: * else cannam@90: * return FLAC__STREAM_DECODER_READ_STATUS_ABORT; cannam@90: * } cannam@90: * \endcode cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param buffer A pointer to a location for the callee to store cannam@90: * data to be decoded. cannam@90: * \param bytes A pointer to the size of the buffer. On entry cannam@90: * to the callback, it contains the maximum number cannam@90: * of bytes that may be stored in \a buffer. The cannam@90: * callee must set it to the actual number of bytes cannam@90: * stored (0 in case of error or end-of-stream) before cannam@90: * returning. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: * \retval FLAC__StreamDecoderReadStatus cannam@90: * The callee's return status. Note that the callback should return cannam@90: * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM if and only if cannam@90: * zero bytes were read and there is no more data to be read. cannam@90: */ cannam@90: typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data); cannam@90: cannam@90: /** Signature for the seek callback. cannam@90: * cannam@90: * A function pointer matching this signature may be passed to cannam@90: * FLAC__stream_decoder_init*_stream(). The supplied function will be cannam@90: * called when the decoder needs to seek the input stream. The decoder cannam@90: * will pass the absolute byte offset to seek to, 0 meaning the cannam@90: * beginning of the stream. cannam@90: * cannam@90: * Here is an example of a seek callback for stdio streams: cannam@90: * \code cannam@90: * FLAC__StreamDecoderSeekStatus seek_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data) cannam@90: * { cannam@90: * FILE *file = ((MyClientData*)client_data)->file; cannam@90: * if(file == stdin) cannam@90: * return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED; cannam@90: * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0) cannam@90: * return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR; cannam@90: * else cannam@90: * return FLAC__STREAM_DECODER_SEEK_STATUS_OK; cannam@90: * } cannam@90: * \endcode cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param absolute_byte_offset The offset from the beginning of the stream cannam@90: * to seek to. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: * \retval FLAC__StreamDecoderSeekStatus cannam@90: * The callee's return status. cannam@90: */ cannam@90: typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); cannam@90: cannam@90: /** Signature for the tell callback. cannam@90: * cannam@90: * A function pointer matching this signature may be passed to cannam@90: * FLAC__stream_decoder_init*_stream(). The supplied function will be cannam@90: * called when the decoder wants to know the current position of the cannam@90: * stream. The callback should return the byte offset from the cannam@90: * beginning of the stream. cannam@90: * cannam@90: * Here is an example of a tell callback for stdio streams: cannam@90: * \code cannam@90: * FLAC__StreamDecoderTellStatus tell_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data) cannam@90: * { cannam@90: * FILE *file = ((MyClientData*)client_data)->file; cannam@90: * off_t pos; cannam@90: * if(file == stdin) cannam@90: * return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED; cannam@90: * else if((pos = ftello(file)) < 0) cannam@90: * return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; cannam@90: * else { cannam@90: * *absolute_byte_offset = (FLAC__uint64)pos; cannam@90: * return FLAC__STREAM_DECODER_TELL_STATUS_OK; cannam@90: * } cannam@90: * } cannam@90: * \endcode cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param absolute_byte_offset A pointer to storage for the current offset cannam@90: * from the beginning of the stream. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: * \retval FLAC__StreamDecoderTellStatus cannam@90: * The callee's return status. cannam@90: */ cannam@90: typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); cannam@90: cannam@90: /** Signature for the length callback. cannam@90: * cannam@90: * A function pointer matching this signature may be passed to cannam@90: * FLAC__stream_decoder_init*_stream(). The supplied function will be cannam@90: * called when the decoder wants to know the total length of the stream cannam@90: * in bytes. cannam@90: * cannam@90: * Here is an example of a length callback for stdio streams: cannam@90: * \code cannam@90: * FLAC__StreamDecoderLengthStatus length_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data) cannam@90: * { cannam@90: * FILE *file = ((MyClientData*)client_data)->file; cannam@90: * struct stat filestats; cannam@90: * cannam@90: * if(file == stdin) cannam@90: * return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED; cannam@90: * else if(fstat(fileno(file), &filestats) != 0) cannam@90: * return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; cannam@90: * else { cannam@90: * *stream_length = (FLAC__uint64)filestats.st_size; cannam@90: * return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; cannam@90: * } cannam@90: * } cannam@90: * \endcode cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param stream_length A pointer to storage for the length of the stream cannam@90: * in bytes. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: * \retval FLAC__StreamDecoderLengthStatus cannam@90: * The callee's return status. cannam@90: */ cannam@90: typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); cannam@90: cannam@90: /** Signature for the EOF callback. cannam@90: * cannam@90: * A function pointer matching this signature may be passed to cannam@90: * FLAC__stream_decoder_init*_stream(). The supplied function will be cannam@90: * called when the decoder needs to know if the end of the stream has cannam@90: * been reached. cannam@90: * cannam@90: * Here is an example of a EOF callback for stdio streams: cannam@90: * FLAC__bool eof_cb(const FLAC__StreamDecoder *decoder, void *client_data) cannam@90: * \code cannam@90: * { cannam@90: * FILE *file = ((MyClientData*)client_data)->file; cannam@90: * return feof(file)? true : false; cannam@90: * } cannam@90: * \endcode cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: * \retval FLAC__bool cannam@90: * \c true if the currently at the end of the stream, else \c false. cannam@90: */ cannam@90: typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data); cannam@90: cannam@90: /** Signature for the write callback. cannam@90: * cannam@90: * A function pointer matching this signature must be passed to one of cannam@90: * the FLAC__stream_decoder_init_*() functions. cannam@90: * The supplied function will be called when the decoder has decoded a cannam@90: * single audio frame. The decoder will pass the frame metadata as well cannam@90: * as an array of pointers (one for each channel) pointing to the cannam@90: * decoded audio. cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param frame The description of the decoded frame. See cannam@90: * FLAC__Frame. cannam@90: * \param buffer An array of pointers to decoded channels of data. cannam@90: * Each pointer will point to an array of signed cannam@90: * samples of length \a frame->header.blocksize. cannam@90: * Channels will be ordered according to the FLAC cannam@90: * specification; see the documentation for the cannam@90: * frame header. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: * \retval FLAC__StreamDecoderWriteStatus cannam@90: * The callee's return status. cannam@90: */ cannam@90: typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); cannam@90: cannam@90: /** Signature for the metadata callback. cannam@90: * cannam@90: * A function pointer matching this signature must be passed to one of cannam@90: * the FLAC__stream_decoder_init_*() functions. cannam@90: * The supplied function will be called when the decoder has decoded a cannam@90: * metadata block. In a valid FLAC file there will always be one cannam@90: * \c STREAMINFO block, followed by zero or more other metadata blocks. cannam@90: * These will be supplied by the decoder in the same order as they cannam@90: * appear in the stream and always before the first audio frame (i.e. cannam@90: * write callback). The metadata block that is passed in must not be cannam@90: * modified, and it doesn't live beyond the callback, so you should make cannam@90: * a copy of it with FLAC__metadata_object_clone() if you will need it cannam@90: * elsewhere. Since metadata blocks can potentially be large, by cannam@90: * default the decoder only calls the metadata callback for the cannam@90: * \c STREAMINFO block; you can instruct the decoder to pass or filter cannam@90: * other blocks with FLAC__stream_decoder_set_metadata_*() calls. cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param metadata The decoded metadata block. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: */ cannam@90: typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); cannam@90: cannam@90: /** Signature for the error callback. cannam@90: * cannam@90: * A function pointer matching this signature must be passed to one of cannam@90: * the FLAC__stream_decoder_init_*() functions. cannam@90: * The supplied function will be called whenever an error occurs during cannam@90: * decoding. cannam@90: * cannam@90: * \note In general, FLAC__StreamDecoder functions which change the cannam@90: * state should not be called on the \a decoder while in the callback. cannam@90: * cannam@90: * \param decoder The decoder instance calling the callback. cannam@90: * \param status The error encountered by the decoder. cannam@90: * \param client_data The callee's client data set through cannam@90: * FLAC__stream_decoder_init_*(). cannam@90: */ cannam@90: typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); cannam@90: cannam@90: cannam@90: /*********************************************************************** cannam@90: * cannam@90: * Class constructor/destructor cannam@90: * cannam@90: ***********************************************************************/ cannam@90: cannam@90: /** Create a new stream decoder instance. The instance is created with cannam@90: * default settings; see the individual FLAC__stream_decoder_set_*() cannam@90: * functions for each setting's default. cannam@90: * cannam@90: * \retval FLAC__StreamDecoder* cannam@90: * \c NULL if there was an error allocating memory, else the new instance. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void); cannam@90: cannam@90: /** Free a decoder instance. Deletes the object pointed to by \a decoder. cannam@90: * cannam@90: * \param decoder A pointer to an existing decoder. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: */ cannam@90: FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: cannam@90: /*********************************************************************** cannam@90: * cannam@90: * Public class method prototypes cannam@90: * cannam@90: ***********************************************************************/ cannam@90: cannam@90: /** Set the serial number for the FLAC stream within the Ogg container. cannam@90: * The default behavior is to use the serial number of the first Ogg cannam@90: * page. Setting a serial number here will explicitly specify which cannam@90: * stream is to be decoded. cannam@90: * cannam@90: * \note cannam@90: * This does not need to be set for native FLAC decoding. cannam@90: * cannam@90: * \default \c use serial number of first page cannam@90: * \param decoder A decoder instance to set. cannam@90: * \param serial_number See above. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number); cannam@90: cannam@90: /** Set the "MD5 signature checking" flag. If \c true, the decoder will cannam@90: * compute the MD5 signature of the unencoded audio data while decoding cannam@90: * and compare it to the signature from the STREAMINFO block, if it cannam@90: * exists, during FLAC__stream_decoder_finish(). cannam@90: * cannam@90: * MD5 signature checking will be turned off (until the next cannam@90: * FLAC__stream_decoder_reset()) if there is no signature in the cannam@90: * STREAMINFO block or when a seek is attempted. cannam@90: * cannam@90: * Clients that do not use the MD5 check should leave this off to speed cannam@90: * up decoding. cannam@90: * cannam@90: * \default \c false cannam@90: * \param decoder A decoder instance to set. cannam@90: * \param value Flag value (see above). cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value); cannam@90: cannam@90: /** Direct the decoder to pass on all metadata blocks of type \a type. cannam@90: * cannam@90: * \default By default, only the \c STREAMINFO block is returned via the cannam@90: * metadata callback. cannam@90: * \param decoder A decoder instance to set. cannam@90: * \param type See above. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \a type is valid cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type); cannam@90: cannam@90: /** Direct the decoder to pass on all APPLICATION metadata blocks of the cannam@90: * given \a id. cannam@90: * cannam@90: * \default By default, only the \c STREAMINFO block is returned via the cannam@90: * metadata callback. cannam@90: * \param decoder A decoder instance to set. cannam@90: * \param id See above. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \code id != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]); cannam@90: cannam@90: /** Direct the decoder to pass on all metadata blocks of any type. cannam@90: * cannam@90: * \default By default, only the \c STREAMINFO block is returned via the cannam@90: * metadata callback. cannam@90: * \param decoder A decoder instance to set. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Direct the decoder to filter out all metadata blocks of type \a type. cannam@90: * cannam@90: * \default By default, only the \c STREAMINFO block is returned via the cannam@90: * metadata callback. cannam@90: * \param decoder A decoder instance to set. cannam@90: * \param type See above. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \a type is valid cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type); cannam@90: cannam@90: /** Direct the decoder to filter out all APPLICATION metadata blocks of cannam@90: * the given \a id. cannam@90: * cannam@90: * \default By default, only the \c STREAMINFO block is returned via the cannam@90: * metadata callback. cannam@90: * \param decoder A decoder instance to set. cannam@90: * \param id See above. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \code id != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]); cannam@90: cannam@90: /** Direct the decoder to filter out all metadata blocks of any type. cannam@90: * cannam@90: * \default By default, only the \c STREAMINFO block is returned via the cannam@90: * metadata callback. cannam@90: * \param decoder A decoder instance to set. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if the decoder is already initialized, else \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current decoder state. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderState cannam@90: * The current decoder state. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current decoder state as a C string. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval const char * cannam@90: * The decoder state as a C string. Do not modify the contents. cannam@90: */ cannam@90: FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the "MD5 signature checking" flag. cannam@90: * This is the value of the setting, not whether or not the decoder is cannam@90: * currently checking the MD5 (remember, it can be turned off automatically cannam@90: * by a seek). When the decoder is reset the flag will be restored to the cannam@90: * value returned by this function. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the total number of samples in the stream being decoded. cannam@90: * Will only be valid after decoding has started and will contain the cannam@90: * value from the \c STREAMINFO block. A value of \c 0 means "unknown". cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval unsigned cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current number of channels in the stream being decoded. cannam@90: * Will only be valid after decoding has started and will contain the cannam@90: * value from the most recently decoded frame header. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval unsigned cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current channel assignment in the stream being decoded. cannam@90: * Will only be valid after decoding has started and will contain the cannam@90: * value from the most recently decoded frame header. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__ChannelAssignment cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current sample resolution in the stream being decoded. cannam@90: * Will only be valid after decoding has started and will contain the cannam@90: * value from the most recently decoded frame header. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval unsigned cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current sample rate in Hz of the stream being decoded. cannam@90: * Will only be valid after decoding has started and will contain the cannam@90: * value from the most recently decoded frame header. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval unsigned cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Get the current blocksize of the stream being decoded. cannam@90: * Will only be valid after decoding has started and will contain the cannam@90: * value from the most recently decoded frame header. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval unsigned cannam@90: * See above. cannam@90: */ cannam@90: FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Returns the decoder's current read position within the stream. cannam@90: * The position is the byte offset from the start of the stream. cannam@90: * Bytes before this position have been fully decoded. Note that cannam@90: * there may still be undecoded bytes in the decoder's read FIFO. cannam@90: * The returned position is correct even after a seek. cannam@90: * cannam@90: * \warning This function currently only works for native FLAC, cannam@90: * not Ogg FLAC streams. cannam@90: * cannam@90: * \param decoder A decoder instance to query. cannam@90: * \param position Address at which to return the desired position. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \code position != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c true if successful, \c false if the stream is not native FLAC, cannam@90: * or there was an error from the 'tell' callback or it returned cannam@90: * \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position); cannam@90: cannam@90: /** Initialize the decoder instance to decode native FLAC streams. cannam@90: * cannam@90: * This flavor of initialization sets up the decoder to decode from a cannam@90: * native FLAC stream. I/O is performed via callbacks to the client. cannam@90: * For decoding from a plain file via filename or open FILE*, cannam@90: * FLAC__stream_decoder_init_file() and FLAC__stream_decoder_init_FILE() cannam@90: * provide a simpler interface. cannam@90: * cannam@90: * This function should be called after FLAC__stream_decoder_new() and cannam@90: * FLAC__stream_decoder_set_*() but before any of the cannam@90: * FLAC__stream_decoder_process_*() functions. Will set and return the cannam@90: * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA cannam@90: * if initialization succeeded. cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \param read_callback See FLAC__StreamDecoderReadCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param seek_callback See FLAC__StreamDecoderSeekCallback. This cannam@90: * pointer may be \c NULL if seeking is not cannam@90: * supported. If \a seek_callback is not \c NULL then a cannam@90: * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied. cannam@90: * Alternatively, a dummy seek callback that just cannam@90: * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param tell_callback See FLAC__StreamDecoderTellCallback. This cannam@90: * pointer may be \c NULL if not supported by the client. If cannam@90: * \a seek_callback is not \c NULL then a cannam@90: * \a tell_callback must also be supplied. cannam@90: * Alternatively, a dummy tell callback that just cannam@90: * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param length_callback See FLAC__StreamDecoderLengthCallback. This cannam@90: * pointer may be \c NULL if not supported by the client. If cannam@90: * \a seek_callback is not \c NULL then a cannam@90: * \a length_callback must also be supplied. cannam@90: * Alternatively, a dummy length callback that just cannam@90: * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param eof_callback See FLAC__StreamDecoderEofCallback. This cannam@90: * pointer may be \c NULL if not supported by the client. If cannam@90: * \a seek_callback is not \c NULL then a cannam@90: * \a eof_callback must also be supplied. cannam@90: * Alternatively, a dummy length callback that just cannam@90: * returns \c false cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param write_callback See FLAC__StreamDecoderWriteCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This cannam@90: * pointer may be \c NULL if the callback is not cannam@90: * desired. cannam@90: * \param error_callback See FLAC__StreamDecoderErrorCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param client_data This value will be supplied to callbacks in their cannam@90: * \a client_data argument. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderInitStatus cannam@90: * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; cannam@90: * see FLAC__StreamDecoderInitStatus for the meanings of other return values. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream( cannam@90: FLAC__StreamDecoder *decoder, cannam@90: FLAC__StreamDecoderReadCallback read_callback, cannam@90: FLAC__StreamDecoderSeekCallback seek_callback, cannam@90: FLAC__StreamDecoderTellCallback tell_callback, cannam@90: FLAC__StreamDecoderLengthCallback length_callback, cannam@90: FLAC__StreamDecoderEofCallback eof_callback, cannam@90: FLAC__StreamDecoderWriteCallback write_callback, cannam@90: FLAC__StreamDecoderMetadataCallback metadata_callback, cannam@90: FLAC__StreamDecoderErrorCallback error_callback, cannam@90: void *client_data cannam@90: ); cannam@90: cannam@90: /** Initialize the decoder instance to decode Ogg FLAC streams. cannam@90: * cannam@90: * This flavor of initialization sets up the decoder to decode from a cannam@90: * FLAC stream in an Ogg container. I/O is performed via callbacks to the cannam@90: * client. For decoding from a plain file via filename or open FILE*, cannam@90: * FLAC__stream_decoder_init_ogg_file() and FLAC__stream_decoder_init_ogg_FILE() cannam@90: * provide a simpler interface. cannam@90: * cannam@90: * This function should be called after FLAC__stream_decoder_new() and cannam@90: * FLAC__stream_decoder_set_*() but before any of the cannam@90: * FLAC__stream_decoder_process_*() functions. Will set and return the cannam@90: * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA cannam@90: * if initialization succeeded. cannam@90: * cannam@90: * \note Support for Ogg FLAC in the library is optional. If this cannam@90: * library has been built without support for Ogg FLAC, this function cannam@90: * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \param read_callback See FLAC__StreamDecoderReadCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param seek_callback See FLAC__StreamDecoderSeekCallback. This cannam@90: * pointer may be \c NULL if seeking is not cannam@90: * supported. If \a seek_callback is not \c NULL then a cannam@90: * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied. cannam@90: * Alternatively, a dummy seek callback that just cannam@90: * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param tell_callback See FLAC__StreamDecoderTellCallback. This cannam@90: * pointer may be \c NULL if not supported by the client. If cannam@90: * \a seek_callback is not \c NULL then a cannam@90: * \a tell_callback must also be supplied. cannam@90: * Alternatively, a dummy tell callback that just cannam@90: * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param length_callback See FLAC__StreamDecoderLengthCallback. This cannam@90: * pointer may be \c NULL if not supported by the client. If cannam@90: * \a seek_callback is not \c NULL then a cannam@90: * \a length_callback must also be supplied. cannam@90: * Alternatively, a dummy length callback that just cannam@90: * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param eof_callback See FLAC__StreamDecoderEofCallback. This cannam@90: * pointer may be \c NULL if not supported by the client. If cannam@90: * \a seek_callback is not \c NULL then a cannam@90: * \a eof_callback must also be supplied. cannam@90: * Alternatively, a dummy length callback that just cannam@90: * returns \c false cannam@90: * may also be supplied, all though this is slightly cannam@90: * less efficient for the decoder. cannam@90: * \param write_callback See FLAC__StreamDecoderWriteCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This cannam@90: * pointer may be \c NULL if the callback is not cannam@90: * desired. cannam@90: * \param error_callback See FLAC__StreamDecoderErrorCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param client_data This value will be supplied to callbacks in their cannam@90: * \a client_data argument. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderInitStatus cannam@90: * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; cannam@90: * see FLAC__StreamDecoderInitStatus for the meanings of other return values. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream( cannam@90: FLAC__StreamDecoder *decoder, cannam@90: FLAC__StreamDecoderReadCallback read_callback, cannam@90: FLAC__StreamDecoderSeekCallback seek_callback, cannam@90: FLAC__StreamDecoderTellCallback tell_callback, cannam@90: FLAC__StreamDecoderLengthCallback length_callback, cannam@90: FLAC__StreamDecoderEofCallback eof_callback, cannam@90: FLAC__StreamDecoderWriteCallback write_callback, cannam@90: FLAC__StreamDecoderMetadataCallback metadata_callback, cannam@90: FLAC__StreamDecoderErrorCallback error_callback, cannam@90: void *client_data cannam@90: ); cannam@90: cannam@90: /** Initialize the decoder instance to decode native FLAC files. cannam@90: * cannam@90: * This flavor of initialization sets up the decoder to decode from a cannam@90: * plain native FLAC file. For non-stdio streams, you must use cannam@90: * FLAC__stream_decoder_init_stream() and provide callbacks for the I/O. cannam@90: * cannam@90: * This function should be called after FLAC__stream_decoder_new() and cannam@90: * FLAC__stream_decoder_set_*() but before any of the cannam@90: * FLAC__stream_decoder_process_*() functions. Will set and return the cannam@90: * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA cannam@90: * if initialization succeeded. cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \param file An open FLAC file. The file should have been cannam@90: * opened with mode \c "rb" and rewound. The file cannam@90: * becomes owned by the decoder and should not be cannam@90: * manipulated by the client while decoding. cannam@90: * Unless \a file is \c stdin, it will be closed cannam@90: * when FLAC__stream_decoder_finish() is called. cannam@90: * Note however that seeking will not work when cannam@90: * decoding from \c stdout since it is not seekable. cannam@90: * \param write_callback See FLAC__StreamDecoderWriteCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This cannam@90: * pointer may be \c NULL if the callback is not cannam@90: * desired. cannam@90: * \param error_callback See FLAC__StreamDecoderErrorCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param client_data This value will be supplied to callbacks in their cannam@90: * \a client_data argument. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \code file != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderInitStatus cannam@90: * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; cannam@90: * see FLAC__StreamDecoderInitStatus for the meanings of other return values. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE( cannam@90: FLAC__StreamDecoder *decoder, cannam@90: FILE *file, cannam@90: FLAC__StreamDecoderWriteCallback write_callback, cannam@90: FLAC__StreamDecoderMetadataCallback metadata_callback, cannam@90: FLAC__StreamDecoderErrorCallback error_callback, cannam@90: void *client_data cannam@90: ); cannam@90: cannam@90: /** Initialize the decoder instance to decode Ogg FLAC files. cannam@90: * cannam@90: * This flavor of initialization sets up the decoder to decode from a cannam@90: * plain Ogg FLAC file. For non-stdio streams, you must use cannam@90: * FLAC__stream_decoder_init_ogg_stream() and provide callbacks for the I/O. cannam@90: * cannam@90: * This function should be called after FLAC__stream_decoder_new() and cannam@90: * FLAC__stream_decoder_set_*() but before any of the cannam@90: * FLAC__stream_decoder_process_*() functions. Will set and return the cannam@90: * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA cannam@90: * if initialization succeeded. cannam@90: * cannam@90: * \note Support for Ogg FLAC in the library is optional. If this cannam@90: * library has been built without support for Ogg FLAC, this function cannam@90: * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \param file An open FLAC file. The file should have been cannam@90: * opened with mode \c "rb" and rewound. The file cannam@90: * becomes owned by the decoder and should not be cannam@90: * manipulated by the client while decoding. cannam@90: * Unless \a file is \c stdin, it will be closed cannam@90: * when FLAC__stream_decoder_finish() is called. cannam@90: * Note however that seeking will not work when cannam@90: * decoding from \c stdout since it is not seekable. cannam@90: * \param write_callback See FLAC__StreamDecoderWriteCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This cannam@90: * pointer may be \c NULL if the callback is not cannam@90: * desired. cannam@90: * \param error_callback See FLAC__StreamDecoderErrorCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param client_data This value will be supplied to callbacks in their cannam@90: * \a client_data argument. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \code file != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderInitStatus cannam@90: * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; cannam@90: * see FLAC__StreamDecoderInitStatus for the meanings of other return values. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE( cannam@90: FLAC__StreamDecoder *decoder, cannam@90: FILE *file, cannam@90: FLAC__StreamDecoderWriteCallback write_callback, cannam@90: FLAC__StreamDecoderMetadataCallback metadata_callback, cannam@90: FLAC__StreamDecoderErrorCallback error_callback, cannam@90: void *client_data cannam@90: ); cannam@90: cannam@90: /** Initialize the decoder instance to decode native FLAC files. cannam@90: * cannam@90: * This flavor of initialization sets up the decoder to decode from a plain cannam@90: * native FLAC file. If POSIX fopen() semantics are not sufficient, (for cannam@90: * example, with Unicode filenames on Windows), you must use cannam@90: * FLAC__stream_decoder_init_FILE(), or FLAC__stream_decoder_init_stream() cannam@90: * and provide callbacks for the I/O. cannam@90: * cannam@90: * This function should be called after FLAC__stream_decoder_new() and cannam@90: * FLAC__stream_decoder_set_*() but before any of the cannam@90: * FLAC__stream_decoder_process_*() functions. Will set and return the cannam@90: * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA cannam@90: * if initialization succeeded. cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \param filename The name of the file to decode from. The file will cannam@90: * be opened with fopen(). Use \c NULL to decode from cannam@90: * \c stdin. Note that \c stdin is not seekable. cannam@90: * \param write_callback See FLAC__StreamDecoderWriteCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This cannam@90: * pointer may be \c NULL if the callback is not cannam@90: * desired. cannam@90: * \param error_callback See FLAC__StreamDecoderErrorCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param client_data This value will be supplied to callbacks in their cannam@90: * \a client_data argument. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderInitStatus cannam@90: * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; cannam@90: * see FLAC__StreamDecoderInitStatus for the meanings of other return values. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file( cannam@90: FLAC__StreamDecoder *decoder, cannam@90: const char *filename, cannam@90: FLAC__StreamDecoderWriteCallback write_callback, cannam@90: FLAC__StreamDecoderMetadataCallback metadata_callback, cannam@90: FLAC__StreamDecoderErrorCallback error_callback, cannam@90: void *client_data cannam@90: ); cannam@90: cannam@90: /** Initialize the decoder instance to decode Ogg FLAC files. cannam@90: * cannam@90: * This flavor of initialization sets up the decoder to decode from a plain cannam@90: * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, (for cannam@90: * example, with Unicode filenames on Windows), you must use cannam@90: * FLAC__stream_decoder_init_ogg_FILE(), or FLAC__stream_decoder_init_ogg_stream() cannam@90: * and provide callbacks for the I/O. cannam@90: * cannam@90: * This function should be called after FLAC__stream_decoder_new() and cannam@90: * FLAC__stream_decoder_set_*() but before any of the cannam@90: * FLAC__stream_decoder_process_*() functions. Will set and return the cannam@90: * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA cannam@90: * if initialization succeeded. cannam@90: * cannam@90: * \note Support for Ogg FLAC in the library is optional. If this cannam@90: * library has been built without support for Ogg FLAC, this function cannam@90: * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER. cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \param filename The name of the file to decode from. The file will cannam@90: * be opened with fopen(). Use \c NULL to decode from cannam@90: * \c stdin. Note that \c stdin is not seekable. cannam@90: * \param write_callback See FLAC__StreamDecoderWriteCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This cannam@90: * pointer may be \c NULL if the callback is not cannam@90: * desired. cannam@90: * \param error_callback See FLAC__StreamDecoderErrorCallback. This cannam@90: * pointer must not be \c NULL. cannam@90: * \param client_data This value will be supplied to callbacks in their cannam@90: * \a client_data argument. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__StreamDecoderInitStatus cannam@90: * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful; cannam@90: * see FLAC__StreamDecoderInitStatus for the meanings of other return values. cannam@90: */ cannam@90: FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file( cannam@90: FLAC__StreamDecoder *decoder, cannam@90: const char *filename, cannam@90: FLAC__StreamDecoderWriteCallback write_callback, cannam@90: FLAC__StreamDecoderMetadataCallback metadata_callback, cannam@90: FLAC__StreamDecoderErrorCallback error_callback, cannam@90: void *client_data cannam@90: ); cannam@90: cannam@90: /** Finish the decoding process. cannam@90: * Flushes the decoding buffer, releases resources, resets the decoder cannam@90: * settings to their defaults, and returns the decoder state to cannam@90: * FLAC__STREAM_DECODER_UNINITIALIZED. cannam@90: * cannam@90: * In the event of a prematurely-terminated decode, it is not strictly cannam@90: * necessary to call this immediately before FLAC__stream_decoder_delete() cannam@90: * but it is good practice to match every FLAC__stream_decoder_init_*() cannam@90: * with a FLAC__stream_decoder_finish(). cannam@90: * cannam@90: * \param decoder An uninitialized decoder instance. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if MD5 checking is on AND a STREAMINFO block was available cannam@90: * AND the MD5 signature in the STREAMINFO block was non-zero AND the cannam@90: * signature does not match the one computed by the decoder; else cannam@90: * \c true. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Flush the stream input. cannam@90: * The decoder's input buffer will be cleared and the state set to cannam@90: * \c FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC. This will also turn cannam@90: * off MD5 checking. cannam@90: * cannam@90: * \param decoder A decoder instance. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c true if successful, else \c false if a memory allocation cannam@90: * error occurs (in which case the state will be set to cannam@90: * \c FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR). cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Reset the decoding process. cannam@90: * The decoder's input buffer will be cleared and the state set to cannam@90: * \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA. This is similar to cannam@90: * FLAC__stream_decoder_finish() except that the settings are cannam@90: * preserved; there is no need to call FLAC__stream_decoder_init_*() cannam@90: * before decoding again. MD5 checking will be restored to its original cannam@90: * setting. cannam@90: * cannam@90: * If the decoder is seekable, or was initialized with cannam@90: * FLAC__stream_decoder_init*_FILE() or FLAC__stream_decoder_init*_file(), cannam@90: * the decoder will also attempt to seek to the beginning of the file. cannam@90: * If this rewind fails, this function will return \c false. It follows cannam@90: * that FLAC__stream_decoder_reset() cannot be used when decoding from cannam@90: * \c stdin. cannam@90: * cannam@90: * If the decoder was initialized with FLAC__stream_encoder_init*_stream() cannam@90: * and is not seekable (i.e. no seek callback was provided or the seek cannam@90: * callback returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED), it cannam@90: * is the duty of the client to start feeding data from the beginning of cannam@90: * the stream on the next FLAC__stream_decoder_process() or cannam@90: * FLAC__stream_decoder_process_interleaved() call. cannam@90: * cannam@90: * \param decoder A decoder instance. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c true if successful, else \c false if a memory allocation occurs cannam@90: * (in which case the state will be set to cannam@90: * \c FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) or a seek error cannam@90: * occurs (the state will be unchanged). cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Decode one metadata block or audio frame. cannam@90: * This version instructs the decoder to decode a either a single metadata cannam@90: * block or a single frame and stop, unless the callbacks return a fatal cannam@90: * error or the read callback returns cannam@90: * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. cannam@90: * cannam@90: * As the decoder needs more input it will call the read callback. cannam@90: * Depending on what was decoded, the metadata or write callback will be cannam@90: * called with the decoded metadata block or audio frame. cannam@90: * cannam@90: * Unless there is a fatal read error or end of stream, this function cannam@90: * will return once one whole frame is decoded. In other words, if the cannam@90: * stream is not synchronized or points to a corrupt frame header, the cannam@90: * decoder will continue to try and resync until it gets to a valid cannam@90: * frame, then decode one frame, then return. If the decoder points to cannam@90: * a frame whose frame CRC in the frame footer does not match the cannam@90: * computed frame CRC, this function will issue a cannam@90: * FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH error to the cannam@90: * error callback, and return, having decoded one complete, although cannam@90: * corrupt, frame. (Such corrupted frames are sent as silence of the cannam@90: * correct length to the write callback.) cannam@90: * cannam@90: * \param decoder An initialized decoder instance. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if any fatal read, write, or memory allocation error cannam@90: * occurred (meaning decoding must stop), else \c true; for more cannam@90: * information about the decoder, check the decoder state with cannam@90: * FLAC__stream_decoder_get_state(). cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Decode until the end of the metadata. cannam@90: * This version instructs the decoder to decode from the current position cannam@90: * and continue until all the metadata has been read, or until the cannam@90: * callbacks return a fatal error or the read callback returns cannam@90: * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. cannam@90: * cannam@90: * As the decoder needs more input it will call the read callback. cannam@90: * As each metadata block is decoded, the metadata callback will be called cannam@90: * with the decoded metadata. cannam@90: * cannam@90: * \param decoder An initialized decoder instance. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if any fatal read, write, or memory allocation error cannam@90: * occurred (meaning decoding must stop), else \c true; for more cannam@90: * information about the decoder, check the decoder state with cannam@90: * FLAC__stream_decoder_get_state(). cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Decode until the end of the stream. cannam@90: * This version instructs the decoder to decode from the current position cannam@90: * and continue until the end of stream (the read callback returns cannam@90: * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM), or until the cannam@90: * callbacks return a fatal error. cannam@90: * cannam@90: * As the decoder needs more input it will call the read callback. cannam@90: * As each metadata block and frame is decoded, the metadata or write cannam@90: * callback will be called with the decoded metadata or frame. cannam@90: * cannam@90: * \param decoder An initialized decoder instance. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if any fatal read, write, or memory allocation error cannam@90: * occurred (meaning decoding must stop), else \c true; for more cannam@90: * information about the decoder, check the decoder state with cannam@90: * FLAC__stream_decoder_get_state(). cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Skip one audio frame. cannam@90: * This version instructs the decoder to 'skip' a single frame and stop, cannam@90: * unless the callbacks return a fatal error or the read callback returns cannam@90: * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. cannam@90: * cannam@90: * The decoding flow is the same as what occurs when cannam@90: * FLAC__stream_decoder_process_single() is called to process an audio cannam@90: * frame, except that this function does not decode the parsed data into cannam@90: * PCM or call the write callback. The integrity of the frame is still cannam@90: * checked the same way as in the other process functions. cannam@90: * cannam@90: * This function will return once one whole frame is skipped, in the cannam@90: * same way that FLAC__stream_decoder_process_single() will return once cannam@90: * one whole frame is decoded. cannam@90: * cannam@90: * This function can be used in more quickly determining FLAC frame cannam@90: * boundaries when decoding of the actual data is not needed, for cannam@90: * example when an application is separating a FLAC stream into frames cannam@90: * for editing or storing in a container. To do this, the application cannam@90: * can use FLAC__stream_decoder_skip_single_frame() to quickly advance cannam@90: * to the next frame, then use cannam@90: * FLAC__stream_decoder_get_decode_position() to find the new frame cannam@90: * boundary. cannam@90: * cannam@90: * This function should only be called when the stream has advanced cannam@90: * past all the metadata, otherwise it will return \c false. cannam@90: * cannam@90: * \param decoder An initialized decoder instance not in a metadata cannam@90: * state. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c false if any fatal read, write, or memory allocation error cannam@90: * occurred (meaning decoding must stop), or if the decoder cannam@90: * is in the FLAC__STREAM_DECODER_SEARCH_FOR_METADATA or cannam@90: * FLAC__STREAM_DECODER_READ_METADATA state, else \c true; for more cannam@90: * information about the decoder, check the decoder state with cannam@90: * FLAC__stream_decoder_get_state(). cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder); cannam@90: cannam@90: /** Flush the input and seek to an absolute sample. cannam@90: * Decoding will resume at the given sample. Note that because of cannam@90: * this, the next write callback may contain a partial block. The cannam@90: * client must support seeking the input or this function will fail cannam@90: * and return \c false. Furthermore, if the decoder state is cannam@90: * \c FLAC__STREAM_DECODER_SEEK_ERROR, then the decoder must be flushed cannam@90: * with FLAC__stream_decoder_flush() or reset with cannam@90: * FLAC__stream_decoder_reset() before decoding can continue. cannam@90: * cannam@90: * \param decoder A decoder instance. cannam@90: * \param sample The target sample number to seek to. cannam@90: * \assert cannam@90: * \code decoder != NULL \endcode cannam@90: * \retval FLAC__bool cannam@90: * \c true if successful, else \c false. cannam@90: */ cannam@90: FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample); cannam@90: cannam@90: /* \} */ cannam@90: cannam@90: #ifdef __cplusplus cannam@90: } cannam@90: #endif cannam@90: cannam@90: #endif