blob: ece15c64f14863b9d0b72abf797a2b97b5690985 [file] [log] [blame]
Josh Coalson26560dd2001-02-08 00:38:41 +00001/* libFLAC - Free Lossless Audio Codec library
Josh Coalson0395dac2006-04-25 06:59:33 +00002 * Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Josh Coalson
Josh Coalsonbb7f6b92000-12-10 04:09:52 +00003 *
Josh Coalsonafd81072003-01-31 23:34:56 +00004 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
Josh Coalsonbb7f6b92000-12-10 04:09:52 +00007 *
Josh Coalsonafd81072003-01-31 23:34:56 +00008 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
Josh Coalsonbb7f6b92000-12-10 04:09:52 +000010 *
Josh Coalsonafd81072003-01-31 23:34:56 +000011 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of the Xiph.org Foundation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Josh Coalsonbb7f6b92000-12-10 04:09:52 +000030 */
31
32#ifndef FLAC__ALL_H
33#define FLAC__ALL_H
34
Josh Coalson55bc5872002-10-16 22:18:32 +000035#include "export.h"
36
Josh Coalson1b689822001-05-31 20:11:02 +000037#include "assert.h"
Josh Coalsond8934e22004-07-10 00:37:02 +000038#include "callback.h"
Josh Coalsondc86ea92001-04-13 18:53:59 +000039#include "format.h"
Josh Coalson36432f42002-05-04 17:33:51 +000040#include "metadata.h"
Josh Coalsonbb7f6b92000-12-10 04:09:52 +000041#include "ordinals.h"
Josh Coalsonbb7f6b92000-12-10 04:09:52 +000042#include "stream_decoder.h"
Josh Coalson0a15c142001-06-13 17:59:57 +000043#include "stream_encoder.h"
Josh Coalsonbb7f6b92000-12-10 04:09:52 +000044
Josh Coalson0e252ba2002-07-12 05:42:04 +000045/** \mainpage
46 *
Josh Coalson5cc58df2002-07-24 06:15:56 +000047 * \section intro Introduction
Josh Coalson0e252ba2002-07-12 05:42:04 +000048 *
49 * This is the documentation for the FLAC C and C++ APIs. It is
50 * highly interconnected; this introduction should give you a top
51 * level idea of the structure and how to find the information you
52 * need. As a prerequisite you should have at least a basic
Josh Coalson0b9ebc32002-07-16 16:14:17 +000053 * knowledge of the FLAC format, documented
54 * <A HREF="../format.html">here</A>.
Josh Coalson0e252ba2002-07-12 05:42:04 +000055 *
Josh Coalson5cc58df2002-07-24 06:15:56 +000056 * \section c_api FLAC C API
57 *
Josh Coalson0e252ba2002-07-12 05:42:04 +000058 * The FLAC C API is the interface to libFLAC, a set of structures
59 * describing the components of FLAC streams, and functions for
60 * encoding and decoding streams, as well as manipulating FLAC
61 * metadata in files. The public include files will be installed
Josh Coalsonf31f5542002-07-15 05:26:50 +000062 * in your include area as <include>/FLAC/...
Josh Coalson0e252ba2002-07-12 05:42:04 +000063 *
Josh Coalson5cc58df2002-07-24 06:15:56 +000064 * By writing a little code and linking against libFLAC, it is
65 * relatively easy to add FLAC support to another program. The
Josh Coalsonffc4c632004-09-14 03:36:26 +000066 * library is licensed under <A HREF="../license.html">Xiph's BSD license</A>.
Josh Coalson5cc58df2002-07-24 06:15:56 +000067 * Complete source code of libFLAC as well as the command-line
68 * encoder and plugins is available and is a useful source of
69 * examples.
70 *
Josh Coalson03706dc2002-07-25 05:35:16 +000071 * Aside from encoders and decoders, libFLAC provides a powerful
72 * metadata interface for manipulating metadata in FLAC files. It
73 * allows the user to add, delete, and modify FLAC metadata blocks
74 * and it can automatically take advantage of PADDING blocks to avoid
75 * rewriting the entire FLAC file when changing the size of the
76 * metadata.
77 *
Josh Coalson5cc58df2002-07-24 06:15:56 +000078 * libFLAC usually only requires the standard C library and C math
79 * library. In particular, threading is not used so there is no
80 * dependency on a thread library. However, libFLAC does not use
81 * global variables and should be thread-safe.
82 *
Josh Coalsonedf672e2006-09-15 15:39:10 +000083 * There is also a libOggFLAC library which wraps around libFLAC
Josh Coalson87977ba2002-08-20 07:09:33 +000084 * to provide routines for encoding to and decoding from FLAC streams
85 * inside an Ogg container. The interfaces are very similar or identical
86 * to their counterparts in libFLAC. libOggFLAC is also licensed under
Josh Coalsonffc4c632004-09-14 03:36:26 +000087 * <A HREF="../license.html">Xiph's BSD license</A>.
Josh Coalson87977ba2002-08-20 07:09:33 +000088 *
Josh Coalson1ce20b62002-10-23 22:18:37 +000089 * \section cpp_api FLAC C++ API
Josh Coalson5cc58df2002-07-24 06:15:56 +000090 *
Josh Coalson0e252ba2002-07-12 05:42:04 +000091 * The FLAC C++ API is a set of classes that encapsulate the
92 * structures and functions in libFLAC. They provide slightly more
93 * functionality with respect to metadata but are otherwise
94 * equivalent. For the most part, they share the same usage as
95 * their counterparts in libFLAC, and the FLAC C API documentation
96 * can be used as a supplement. The public include files
97 * for the C++ API will be installed in your include area as
Josh Coalsonf31f5542002-07-15 05:26:50 +000098 * <include>/FLAC++/...
Josh Coalson0e252ba2002-07-12 05:42:04 +000099 *
Josh Coalsonedf672e2006-09-15 15:39:10 +0000100 * There is also a libOggFLAC++ library, which provides classes
Josh Coalson87977ba2002-08-20 07:09:33 +0000101 * for encoding to and decoding from FLAC streams in an Ogg container.
102 * The classes are very similar to their counterparts in libFLAC++.
103 *
Josh Coalsonffc4c632004-09-14 03:36:26 +0000104 * Both libFLAC++ libOggFLAC++ are also licensed under
105 * <A HREF="../license.html">Xiph's BSD license</A>.
Josh Coalson5cc58df2002-07-24 06:15:56 +0000106 *
107 * \section getting_started Getting Started
108 *
Josh Coalson0e252ba2002-07-12 05:42:04 +0000109 * A good starting point for learning the API is to browse through
Josh Coalson03706dc2002-07-25 05:35:16 +0000110 * the <A HREF="modules.html">modules</A>. Modules are logical
Josh Coalson0b9ebc32002-07-16 16:14:17 +0000111 * groupings of related functions or classes, which correspond roughly
112 * to header files or sections of header files. Each module includes a
113 * detailed description of the general usage of its functions or
114 * classes.
Josh Coalson0e252ba2002-07-12 05:42:04 +0000115 *
116 * From there you can go on to look at the documentation of
117 * individual functions. You can see different views of the individual
118 * functions through the links in top bar across this page.
Josh Coalsonf1eff452002-07-31 07:05:33 +0000119 *
Josh Coalson6b21f662006-09-13 01:42:27 +0000120 * \section porting_guide Porting Guide
121 *
122 * Starting with FLAC 1.1.3 a \link porting Porting Guide \endlink
123 * has been introduced which gives detailed instructions on how to
124 * port your code to newer versions of FLAC.
125 *
Josh Coalsonf1eff452002-07-31 07:05:33 +0000126 * \section embedded_developers Embedded Developers
127 *
128 * libFLAC has grown larger over time as more functionality has been
129 * included, but much of it may be unnecessary for a particular embedded
130 * implementation. Unused parts may be pruned by some simple editing of
131 * src/libFLAC/Makefile.am. In general, the decoders, encoders, and
132 * metadata interface are all independent from each other.
133 *
134 * It is easiest to just describe the dependencies:
135 *
136 * - All modules depend on the \link flac_format Format \endlink module.
137 * - The decoders and encoders are independent of each other.
138 * - The metadata interface requires the file decoder.
139 * - The decoder and encoder layers depend on the layers below them, but
140 * not above them; e.g. the seekable stream decoder depends on the stream
141 * decoder but not the file decoder
142 *
143 * For example, if your application only requires the stream decoder, no
144 * encoders, and no metadata interface, you can remove the seekable stream
145 * decoder, file decoder, all encoders, and the metadata interface, which
146 * will greatly reduce the size of the library.
Josh Coalson0e252ba2002-07-12 05:42:04 +0000147 */
148
Josh Coalson6b21f662006-09-13 01:42:27 +0000149/** \defgroup porting Porting Guide for New Versions
150 *
151 * This module describes differences in the library interfaces from
152 * version to version. It assists in the porting of code that uses
153 * the libraries to newer versions of FLAC.
154 */
155
156/** \defgroup porting_1_1_2_to_1_1_3 Porting from FLAC 1.1.2 to 1.1.3
157 * \ingroup porting
158 *
159 * \brief
160 * This module describes porting from FLAC 1.1.2 to FLAC 1.1.3.
161 *
162 * The main change between the APIs in 1.1.2 and 1.1.3 is that the three
163 * decoding layers and three encoding layers have been merged into a
164 * single stream decoder and stream encoder. That is, the functionality
165 * of FLAC__SeekableStreamDecoder and FLAC__FileDecoder has been merged
166 * into FLAC__StreamDecoder, and FLAC__SeekableStreamEncoder and
167 * FLAC__FileEncoder into FLAC__StreamEncoder. Only the
168 * FLAC__StreamDecoder and FLAC__StreamEncoder remain. This can
169 * simplify code that needs to process both seekable and non-seekable
170 * streams.
171 *
172 * Instead of creating an encoder or decoder of a certain layer, now the
173 * client will always create a FLAC__StreamEncoder or
174 * FLAC__StreamDecoder. The different layers are differentiated by the
175 * initialization function. For example, for the decoder,
176 * FLAC__stream_decoder_init() has been replaced by
177 * FLAC__stream_decoder_init_stream(). This init function takes
178 * callbacks for the I/O, and the seeking callbacks are optional. This
179 * allows the client to use the same object for seekable and
180 * non-seekable streams. For decoding a FLAC file directly, the client
181 * can use FLAC__stream_decoder_init_file() and pass just a filename
182 * and fewer callbacks; most of the other callbacks are supplied
183 * internally. For situations where fopen()ing by filename is not
184 * possible (e.g. Unicode filenames on Windows) the client can instead
185 * open the file itself and supply the FILE* to
186 * FLAC__stream_decoder_init_FILE(). The init functions now returns a
187 * FLAC__StreamDecoderInitStatus instead of FLAC__StreamDecoderState.
188 * Since the callbacks and client data are now passed to the init
189 * function, the FLAC__stream_decoder_set_*_callback() functions and
190 * FLAC__stream_decoder_set_client_data() are no longer needed. The
191 * rest of the calls to the decoder are the same as before.
192 *
193 * As an example, in FLAC 1.1.2 a seekable stream decoder would be set
194 * up like so:
Josh Coalson7f1b6422006-09-16 00:38:14 +0000195 *
Josh Coalson6b21f662006-09-13 01:42:27 +0000196 * \code
197 * FLAC__SeekableStreamDecoder *decoder = FLAC__seekable_stream_decoder_new();
Josh Coalsonedf672e2006-09-15 15:39:10 +0000198 * if(decoder == NULL) do_something;
Josh Coalson6b21f662006-09-13 01:42:27 +0000199 * FLAC__seekable_stream_decoder_set_md5_checking(decoder, true);
200 * [... other settings ...]
201 * FLAC__seekable_stream_decoder_set_read_callback(decoder, my_read_callback);
202 * FLAC__seekable_stream_decoder_set_seek_callback(decoder, my_seek_callback);
203 * FLAC__seekable_stream_decoder_set_tell_callback(decoder, my_tell_callback);
204 * FLAC__seekable_stream_decoder_set_length_callback(decoder, my_length_callback);
205 * FLAC__seekable_stream_decoder_set_eof_callback(decoder, my_eof_callback);
206 * FLAC__seekable_stream_decoder_set_write_callback(decoder, my_write_callback);
207 * FLAC__seekable_stream_decoder_set_metadata_callback(decoder, my_metadata_callback);
208 * FLAC__seekable_stream_decoder_set_error_callback(decoder, my_error_callback);
209 * FLAC__seekable_stream_decoder_set_client_data(decoder, my_client_data);
Josh Coalsonedf672e2006-09-15 15:39:10 +0000210 * if(FLAC__seekable_stream_decoder_init(decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK) do_something;
Josh Coalson6b21f662006-09-13 01:42:27 +0000211 * \endcode
212 *
213 * In FLAC 1.1.3 it is like this:
214 *
215 * \code
216 * FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new();
Josh Coalsonedf672e2006-09-15 15:39:10 +0000217 * if(decoder == NULL) do_something;
Josh Coalson6b21f662006-09-13 01:42:27 +0000218 * FLAC__stream_decoder_set_md5_checking(decoder, true);
219 * [... other settings ...]
220 * if(FLAC__stream_decoder_init_stream(
221 * decoder,
222 * my_read_callback,
223 * my_seek_callback, // or NULL
224 * my_tell_callback, // or NULL
225 * my_length_callback, // or NULL
226 * my_eof_callback, // or NULL
227 * my_write_callback,
228 * my_metadata_callback, // or NULL
229 * my_error_callback,
Josh Coalson7f1b6422006-09-16 00:38:14 +0000230 * my_client_data
Josh Coalsonedf672e2006-09-15 15:39:10 +0000231 * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
Josh Coalson6b21f662006-09-13 01:42:27 +0000232 * \endcode
233 *
234 * or you could do;
235 *
236 * \code
237 * [...]
238 * FILE *file = fopen("somefile.flac","rb");
Josh Coalsonedf672e2006-09-15 15:39:10 +0000239 * if(file == NULL) do_somthing;
Josh Coalson6b21f662006-09-13 01:42:27 +0000240 * if(FLAC__stream_decoder_init_FILE(
241 * decoder,
242 * file,
243 * my_write_callback,
244 * my_metadata_callback, // or NULL
245 * my_error_callback,
Josh Coalson7f1b6422006-09-16 00:38:14 +0000246 * my_client_data
Josh Coalsonedf672e2006-09-15 15:39:10 +0000247 * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
Josh Coalson6b21f662006-09-13 01:42:27 +0000248 * \endcode
249 *
250 * or just:
251 *
252 * \code
253 * [...]
Josh Coalson7f1b6422006-09-16 00:38:14 +0000254 * if(FLAC__stream_decoder_init_file(
Josh Coalson6b21f662006-09-13 01:42:27 +0000255 * decoder,
256 * "somefile.flac",
257 * my_write_callback,
258 * my_metadata_callback, // or NULL
259 * my_error_callback,
Josh Coalson7f1b6422006-09-16 00:38:14 +0000260 * my_client_data
Josh Coalsonedf672e2006-09-15 15:39:10 +0000261 * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
Josh Coalson6b21f662006-09-13 01:42:27 +0000262 * \endcode
263 *
264 * Another small change to the decoder is in how it handles unparseable
265 * streams. Before, when the decoder found an unparseable stream
266 * (reserved for when the decoder encounters a stream from a future
267 * encoder that it can't parse), it changed the state to
268 * \c FLAC__STREAM_DECODER_UNPARSEABLE_STREAM. Now the decoder instead
269 * drops sync and calls the error callback with a new error code
270 * \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM. This is
271 * more robust. If your error callback does not discriminate on the the
272 * error state, your code does not need to be changed.
273 *
274 * The encoder now has a new setting:
275 * FLAC__stream_encoder_set_apodization(). This is for setting the
276 * method used to window the data before LPC analysis. You only need to
277 * add a call to this function if the default is not There are also
278 * two new convenience functions that may be useful:
279 * FLAC__metadata_object_cuesheet_calculate_cddb_id() and
280 * FLAC__metadata_get_cuesheet().
Josh Coalson68acb042006-09-15 15:40:57 +0000281 *
282 * In libOggFLAC++, OggFLAC::Decoder::Stream now inherits from
283 * FLAC::Decoder::Stream and OggFLAC::Encoder::Stream now inherits from
284 * FLAC::Encoder::Stream, which means both OggFLAC and FLAC can be
285 * supported by using common code for everything after initialization.
Josh Coalson6b21f662006-09-13 01:42:27 +0000286 */
287
Josh Coalson889598d2002-07-10 07:14:49 +0000288/** \defgroup flac FLAC C API
Josh Coalson0e252ba2002-07-12 05:42:04 +0000289 *
290 * The FLAC C API is the interface to libFLAC, a set of structures
291 * describing the components of FLAC streams, and functions for
292 * encoding and decoding streams, as well as manipulating FLAC
293 * metadata in files.
294 *
Josh Coalson0b9ebc32002-07-16 16:14:17 +0000295 * You should start with the format components as all other modules
Josh Coalson0e252ba2002-07-12 05:42:04 +0000296 * are dependent on it.
Josh Coalson889598d2002-07-10 07:14:49 +0000297 */
298
Josh Coalsonbb7f6b92000-12-10 04:09:52 +0000299#endif