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