Chris@2: /* libFLAC - Free Lossless Audio Codec library Chris@2: * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson Chris@2: * Chris@2: * Redistribution and use in source and binary forms, with or without Chris@2: * modification, are permitted provided that the following conditions Chris@2: * are met: Chris@2: * Chris@2: * - Redistributions of source code must retain the above copyright Chris@2: * notice, this list of conditions and the following disclaimer. Chris@2: * Chris@2: * - Redistributions in binary form must reproduce the above copyright Chris@2: * notice, this list of conditions and the following disclaimer in the Chris@2: * documentation and/or other materials provided with the distribution. Chris@2: * Chris@2: * - Neither the name of the Xiph.org Foundation nor the names of its Chris@2: * contributors may be used to endorse or promote products derived from Chris@2: * this software without specific prior written permission. Chris@2: * Chris@2: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS Chris@2: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT Chris@2: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR Chris@2: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR Chris@2: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, Chris@2: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, Chris@2: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR Chris@2: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF Chris@2: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING Chris@2: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS Chris@2: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Chris@2: */ Chris@2: Chris@2: #ifndef FLAC__ALL_H Chris@2: #define FLAC__ALL_H Chris@2: Chris@2: #include "export.h" Chris@2: Chris@2: #include "assert.h" Chris@2: #include "callback.h" Chris@2: #include "format.h" Chris@2: #include "metadata.h" Chris@2: #include "ordinals.h" Chris@2: #include "stream_decoder.h" Chris@2: #include "stream_encoder.h" Chris@2: Chris@2: /** \mainpage Chris@2: * Chris@2: * \section intro Introduction Chris@2: * Chris@2: * This is the documentation for the FLAC C and C++ APIs. It is Chris@2: * highly interconnected; this introduction should give you a top Chris@2: * level idea of the structure and how to find the information you Chris@2: * need. As a prerequisite you should have at least a basic Chris@2: * knowledge of the FLAC format, documented Chris@2: * here. Chris@2: * Chris@2: * \section c_api FLAC C API Chris@2: * Chris@2: * The FLAC C API is the interface to libFLAC, a set of structures Chris@2: * describing the components of FLAC streams, and functions for Chris@2: * encoding and decoding streams, as well as manipulating FLAC Chris@2: * metadata in files. The public include files will be installed Chris@2: * in your include area (for example /usr/include/FLAC/...). Chris@2: * Chris@2: * By writing a little code and linking against libFLAC, it is Chris@2: * relatively easy to add FLAC support to another program. The Chris@2: * library is licensed under Xiph's BSD license. Chris@2: * Complete source code of libFLAC as well as the command-line Chris@2: * encoder and plugins is available and is a useful source of Chris@2: * examples. Chris@2: * Chris@2: * Aside from encoders and decoders, libFLAC provides a powerful Chris@2: * metadata interface for manipulating metadata in FLAC files. It Chris@2: * allows the user to add, delete, and modify FLAC metadata blocks Chris@2: * and it can automatically take advantage of PADDING blocks to avoid Chris@2: * rewriting the entire FLAC file when changing the size of the Chris@2: * metadata. Chris@2: * Chris@2: * libFLAC usually only requires the standard C library and C math Chris@2: * library. In particular, threading is not used so there is no Chris@2: * dependency on a thread library. However, libFLAC does not use Chris@2: * global variables and should be thread-safe. Chris@2: * Chris@2: * libFLAC also supports encoding to and decoding from Ogg FLAC. Chris@2: * However the metadata editing interfaces currently have limited Chris@2: * read-only support for Ogg FLAC files. Chris@2: * Chris@2: * \section cpp_api FLAC C++ API Chris@2: * Chris@2: * The FLAC C++ API is a set of classes that encapsulate the Chris@2: * structures and functions in libFLAC. They provide slightly more Chris@2: * functionality with respect to metadata but are otherwise Chris@2: * equivalent. For the most part, they share the same usage as Chris@2: * their counterparts in libFLAC, and the FLAC C API documentation Chris@2: * can be used as a supplement. The public include files Chris@2: * for the C++ API will be installed in your include area (for Chris@2: * example /usr/include/FLAC++/...). Chris@2: * Chris@2: * libFLAC++ is also licensed under Chris@2: * Xiph's BSD license. Chris@2: * Chris@2: * \section getting_started Getting Started Chris@2: * Chris@2: * A good starting point for learning the API is to browse through Chris@2: * the modules. Modules are logical Chris@2: * groupings of related functions or classes, which correspond roughly Chris@2: * to header files or sections of header files. Each module includes a Chris@2: * detailed description of the general usage of its functions or Chris@2: * classes. Chris@2: * Chris@2: * From there you can go on to look at the documentation of Chris@2: * individual functions. You can see different views of the individual Chris@2: * functions through the links in top bar across this page. Chris@2: * Chris@2: * If you prefer a more hands-on approach, you can jump right to some Chris@2: * example code. Chris@2: * Chris@2: * \section porting_guide Porting Guide Chris@2: * Chris@2: * Starting with FLAC 1.1.3 a \link porting Porting Guide \endlink Chris@2: * has been introduced which gives detailed instructions on how to Chris@2: * port your code to newer versions of FLAC. Chris@2: * Chris@2: * \section embedded_developers Embedded Developers Chris@2: * Chris@2: * libFLAC has grown larger over time as more functionality has been Chris@2: * included, but much of it may be unnecessary for a particular embedded Chris@2: * implementation. Unused parts may be pruned by some simple editing of Chris@2: * src/libFLAC/Makefile.am. In general, the decoders, encoders, and Chris@2: * metadata interface are all independent from each other. Chris@2: * Chris@2: * It is easiest to just describe the dependencies: Chris@2: * Chris@2: * - All modules depend on the \link flac_format Format \endlink module. Chris@2: * - The decoders and encoders depend on the bitbuffer. Chris@2: * - The decoder is independent of the encoder. The encoder uses the Chris@2: * decoder because of the verify feature, but this can be removed if Chris@2: * not needed. Chris@2: * - Parts of the metadata interface require the stream decoder (but not Chris@2: * the encoder). Chris@2: * - Ogg support is selectable through the compile time macro Chris@2: * \c FLAC__HAS_OGG. Chris@2: * Chris@2: * For example, if your application only requires the stream decoder, no Chris@2: * encoder, and no metadata interface, you can remove the stream encoder Chris@2: * and the metadata interface, which will greatly reduce the size of the Chris@2: * library. Chris@2: * Chris@2: * Also, there are several places in the libFLAC code with comments marked Chris@2: * with "OPT:" where a #define can be changed to enable code that might be Chris@2: * faster on a specific platform. Experimenting with these can yield faster Chris@2: * binaries. Chris@2: */ Chris@2: Chris@2: /** \defgroup porting Porting Guide for New Versions Chris@2: * Chris@2: * This module describes differences in the library interfaces from Chris@2: * version to version. It assists in the porting of code that uses Chris@2: * the libraries to newer versions of FLAC. Chris@2: * Chris@2: * One simple facility for making porting easier that has been added Chris@2: * in FLAC 1.1.3 is a set of \c #defines in \c export.h of each Chris@2: * library's includes (e.g. \c include/FLAC/export.h). The Chris@2: * \c #defines mirror the libraries' Chris@2: * libtool version numbers, Chris@2: * e.g. in libFLAC there are \c FLAC_API_VERSION_CURRENT, Chris@2: * \c FLAC_API_VERSION_REVISION, and \c FLAC_API_VERSION_AGE. Chris@2: * These can be used to support multiple versions of an API during the Chris@2: * transition phase, e.g. Chris@2: * Chris@2: * \code Chris@2: * #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7 Chris@2: * legacy code Chris@2: * #else Chris@2: * new code Chris@2: * #endif Chris@2: * \endcode Chris@2: * Chris@2: * The the source will work for multiple versions and the legacy code can Chris@2: * easily be removed when the transition is complete. Chris@2: * Chris@2: * Another available symbol is FLAC_API_SUPPORTS_OGG_FLAC (defined in Chris@2: * include/FLAC/export.h), which can be used to determine whether or not Chris@2: * the library has been compiled with support for Ogg FLAC. This is Chris@2: * simpler than trying to call an Ogg init function and catching the Chris@2: * error. Chris@2: */ Chris@2: Chris@2: /** \defgroup porting_1_1_2_to_1_1_3 Porting from FLAC 1.1.2 to 1.1.3 Chris@2: * \ingroup porting Chris@2: * Chris@2: * \brief Chris@2: * This module describes porting from FLAC 1.1.2 to FLAC 1.1.3. Chris@2: * Chris@2: * The main change between the APIs in 1.1.2 and 1.1.3 is that they have Chris@2: * been simplified. First, libOggFLAC has been merged into libFLAC and Chris@2: * libOggFLAC++ has been merged into libFLAC++. Second, both the three Chris@2: * decoding layers and three encoding layers have been merged into a Chris@2: * single stream decoder and stream encoder. That is, the functionality Chris@2: * of FLAC__SeekableStreamDecoder and FLAC__FileDecoder has been merged Chris@2: * into FLAC__StreamDecoder, and FLAC__SeekableStreamEncoder and Chris@2: * FLAC__FileEncoder into FLAC__StreamEncoder. Only the Chris@2: * FLAC__StreamDecoder and FLAC__StreamEncoder remain. What this means Chris@2: * is there is now a single API that can be used to encode or decode Chris@2: * streams to/from native FLAC or Ogg FLAC and the single API can work Chris@2: * on both seekable and non-seekable streams. Chris@2: * Chris@2: * Instead of creating an encoder or decoder of a certain layer, now the Chris@2: * client will always create a FLAC__StreamEncoder or Chris@2: * FLAC__StreamDecoder. The old layers are now differentiated by the Chris@2: * initialization function. For example, for the decoder, Chris@2: * FLAC__stream_decoder_init() has been replaced by Chris@2: * FLAC__stream_decoder_init_stream(). This init function takes Chris@2: * callbacks for the I/O, and the seeking callbacks are optional. This Chris@2: * allows the client to use the same object for seekable and Chris@2: * non-seekable streams. For decoding a FLAC file directly, the client Chris@2: * can use FLAC__stream_decoder_init_file() and pass just a filename Chris@2: * and fewer callbacks; most of the other callbacks are supplied Chris@2: * internally. For situations where fopen()ing by filename is not Chris@2: * possible (e.g. Unicode filenames on Windows) the client can instead Chris@2: * open the file itself and supply the FILE* to Chris@2: * FLAC__stream_decoder_init_FILE(). The init functions now returns a Chris@2: * FLAC__StreamDecoderInitStatus instead of FLAC__StreamDecoderState. Chris@2: * Since the callbacks and client data are now passed to the init Chris@2: * function, the FLAC__stream_decoder_set_*_callback() functions and Chris@2: * FLAC__stream_decoder_set_client_data() are no longer needed. The Chris@2: * rest of the calls to the decoder are the same as before. Chris@2: * Chris@2: * There are counterpart init functions for Ogg FLAC, e.g. Chris@2: * FLAC__stream_decoder_init_ogg_stream(). All the rest of the calls Chris@2: * and callbacks are the same as for native FLAC. Chris@2: * Chris@2: * As an example, in FLAC 1.1.2 a seekable stream decoder would have Chris@2: * been set up like so: Chris@2: * Chris@2: * \code Chris@2: * FLAC__SeekableStreamDecoder *decoder = FLAC__seekable_stream_decoder_new(); Chris@2: * if(decoder == NULL) do_something; Chris@2: * FLAC__seekable_stream_decoder_set_md5_checking(decoder, true); Chris@2: * [... other settings ...] Chris@2: * FLAC__seekable_stream_decoder_set_read_callback(decoder, my_read_callback); Chris@2: * FLAC__seekable_stream_decoder_set_seek_callback(decoder, my_seek_callback); Chris@2: * FLAC__seekable_stream_decoder_set_tell_callback(decoder, my_tell_callback); Chris@2: * FLAC__seekable_stream_decoder_set_length_callback(decoder, my_length_callback); Chris@2: * FLAC__seekable_stream_decoder_set_eof_callback(decoder, my_eof_callback); Chris@2: * FLAC__seekable_stream_decoder_set_write_callback(decoder, my_write_callback); Chris@2: * FLAC__seekable_stream_decoder_set_metadata_callback(decoder, my_metadata_callback); Chris@2: * FLAC__seekable_stream_decoder_set_error_callback(decoder, my_error_callback); Chris@2: * FLAC__seekable_stream_decoder_set_client_data(decoder, my_client_data); Chris@2: * if(FLAC__seekable_stream_decoder_init(decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK) do_something; Chris@2: * \endcode Chris@2: * Chris@2: * In FLAC 1.1.3 it is like this: Chris@2: * Chris@2: * \code Chris@2: * FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new(); Chris@2: * if(decoder == NULL) do_something; Chris@2: * FLAC__stream_decoder_set_md5_checking(decoder, true); Chris@2: * [... other settings ...] Chris@2: * if(FLAC__stream_decoder_init_stream( Chris@2: * decoder, Chris@2: * my_read_callback, Chris@2: * my_seek_callback, // or NULL Chris@2: * my_tell_callback, // or NULL Chris@2: * my_length_callback, // or NULL Chris@2: * my_eof_callback, // or NULL Chris@2: * my_write_callback, Chris@2: * my_metadata_callback, // or NULL Chris@2: * my_error_callback, Chris@2: * my_client_data Chris@2: * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something; Chris@2: * \endcode Chris@2: * Chris@2: * or you could do; Chris@2: * Chris@2: * \code Chris@2: * [...] Chris@2: * FILE *file = fopen("somefile.flac","rb"); Chris@2: * if(file == NULL) do_somthing; Chris@2: * if(FLAC__stream_decoder_init_FILE( Chris@2: * decoder, Chris@2: * file, Chris@2: * my_write_callback, Chris@2: * my_metadata_callback, // or NULL Chris@2: * my_error_callback, Chris@2: * my_client_data Chris@2: * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something; Chris@2: * \endcode Chris@2: * Chris@2: * or just: Chris@2: * Chris@2: * \code Chris@2: * [...] Chris@2: * if(FLAC__stream_decoder_init_file( Chris@2: * decoder, Chris@2: * "somefile.flac", Chris@2: * my_write_callback, Chris@2: * my_metadata_callback, // or NULL Chris@2: * my_error_callback, Chris@2: * my_client_data Chris@2: * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something; Chris@2: * \endcode Chris@2: * Chris@2: * Another small change to the decoder is in how it handles unparseable Chris@2: * streams. Before, when the decoder found an unparseable stream Chris@2: * (reserved for when the decoder encounters a stream from a future Chris@2: * encoder that it can't parse), it changed the state to Chris@2: * \c FLAC__STREAM_DECODER_UNPARSEABLE_STREAM. Now the decoder instead Chris@2: * drops sync and calls the error callback with a new error code Chris@2: * \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM. This is Chris@2: * more robust. If your error callback does not discriminate on the the Chris@2: * error state, your code does not need to be changed. Chris@2: * Chris@2: * The encoder now has a new setting: Chris@2: * FLAC__stream_encoder_set_apodization(). This is for setting the Chris@2: * method used to window the data before LPC analysis. You only need to Chris@2: * add a call to this function if the default is not suitable. There Chris@2: * are also two new convenience functions that may be useful: Chris@2: * FLAC__metadata_object_cuesheet_calculate_cddb_id() and Chris@2: * FLAC__metadata_get_cuesheet(). Chris@2: * Chris@2: * The \a bytes parameter to FLAC__StreamDecoderReadCallback, Chris@2: * FLAC__StreamEncoderReadCallback, and FLAC__StreamEncoderWriteCallback Chris@2: * is now \c size_t instead of \c unsigned. Chris@2: */ Chris@2: Chris@2: /** \defgroup porting_1_1_3_to_1_1_4 Porting from FLAC 1.1.3 to 1.1.4 Chris@2: * \ingroup porting Chris@2: * Chris@2: * \brief Chris@2: * This module describes porting from FLAC 1.1.3 to FLAC 1.1.4. Chris@2: * Chris@2: * There were no changes to any of the interfaces from 1.1.3 to 1.1.4. Chris@2: * There was a slight change in the implementation of Chris@2: * FLAC__stream_encoder_set_metadata(); the function now makes a copy Chris@2: * of the \a metadata array of pointers so the client no longer needs Chris@2: * to maintain it after the call. The objects themselves that are Chris@2: * pointed to by the array are still not copied though and must be Chris@2: * maintained until the call to FLAC__stream_encoder_finish(). Chris@2: */ Chris@2: Chris@2: /** \defgroup porting_1_1_4_to_1_2_0 Porting from FLAC 1.1.4 to 1.2.0 Chris@2: * \ingroup porting Chris@2: * Chris@2: * \brief Chris@2: * This module describes porting from FLAC 1.1.4 to FLAC 1.2.0. Chris@2: * Chris@2: * There were only very minor changes to the interfaces from 1.1.4 to 1.2.0. Chris@2: * In libFLAC, \c FLAC__format_sample_rate_is_subset() was added. Chris@2: * In libFLAC++, \c FLAC::Decoder::Stream::get_decode_position() was added. Chris@2: * Chris@2: * Finally, value of the constant \c FLAC__FRAME_HEADER_RESERVED_LEN Chris@2: * has changed to reflect the conversion of one of the reserved bits Chris@2: * into active use. It used to be \c 2 and now is \c 1. However the Chris@2: * FLAC frame header length has not changed, so to skip the proper Chris@2: * number of bits, use \c FLAC__FRAME_HEADER_RESERVED_LEN + Chris@2: * \c FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN Chris@2: */ Chris@2: Chris@2: /** \defgroup flac FLAC C API Chris@2: * Chris@2: * The FLAC C API is the interface to libFLAC, a set of structures Chris@2: * describing the components of FLAC streams, and functions for Chris@2: * encoding and decoding streams, as well as manipulating FLAC Chris@2: * metadata in files. Chris@2: * Chris@2: * You should start with the format components as all other modules Chris@2: * are dependent on it. Chris@2: */ Chris@2: Chris@2: #endif