all.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2000-2009 Josh Coalson
  3. * Copyright (C) 2011-2014 Xiph.Org Foundation
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. *
  12. * - Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * - Neither the name of the Xiph.org Foundation nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
  24. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef FLAC__ALL_H
  33. #define FLAC__ALL_H
  34. #include "export.h"
  35. #include "callback.h"
  36. #include "flac_assert.h"
  37. #include "format.h"
  38. #include "metadata.h"
  39. #include "ordinals.h"
  40. #include "stream_decoder.h"
  41. #include "stream_encoder.h"
  42. /** \mainpage
  43. *
  44. * \section intro Introduction
  45. *
  46. * This is the documentation for the FLAC C and C++ APIs. It is
  47. * highly interconnected; this introduction should give you a top
  48. * level idea of the structure and how to find the information you
  49. * need. As a prerequisite you should have at least a basic
  50. * knowledge of the FLAC format, documented
  51. * <A HREF="../format.html">here</A>.
  52. *
  53. * \section c_api FLAC C API
  54. *
  55. * The FLAC C API is the interface to libFLAC, a set of structures
  56. * describing the components of FLAC streams, and functions for
  57. * encoding and decoding streams, as well as manipulating FLAC
  58. * metadata in files. The public include files will be installed
  59. * in your include area (for example /usr/include/FLAC/...).
  60. *
  61. * By writing a little code and linking against libFLAC, it is
  62. * relatively easy to add FLAC support to another program. The
  63. * library is licensed under <A HREF="../license.html">Xiph's BSD license</A>.
  64. * Complete source code of libFLAC as well as the command-line
  65. * encoder and plugins is available and is a useful source of
  66. * examples.
  67. *
  68. * Aside from encoders and decoders, libFLAC provides a powerful
  69. * metadata interface for manipulating metadata in FLAC files. It
  70. * allows the user to add, delete, and modify FLAC metadata blocks
  71. * and it can automatically take advantage of PADDING blocks to avoid
  72. * rewriting the entire FLAC file when changing the size of the
  73. * metadata.
  74. *
  75. * libFLAC usually only requires the standard C library and C math
  76. * library. In particular, threading is not used so there is no
  77. * dependency on a thread library. However, libFLAC does not use
  78. * global variables and should be thread-safe.
  79. *
  80. * libFLAC also supports encoding to and decoding from Ogg FLAC.
  81. * However the metadata editing interfaces currently have limited
  82. * read-only support for Ogg FLAC files.
  83. *
  84. * \section cpp_api FLAC C++ API
  85. *
  86. * The FLAC C++ API is a set of classes that encapsulate the
  87. * structures and functions in libFLAC. They provide slightly more
  88. * functionality with respect to metadata but are otherwise
  89. * equivalent. For the most part, they share the same usage as
  90. * their counterparts in libFLAC, and the FLAC C API documentation
  91. * can be used as a supplement. The public include files
  92. * for the C++ API will be installed in your include area (for
  93. * example /usr/include/FLAC++/...).
  94. *
  95. * libFLAC++ is also licensed under
  96. * <A HREF="../license.html">Xiph's BSD license</A>.
  97. *
  98. * \section getting_started Getting Started
  99. *
  100. * A good starting point for learning the API is to browse through
  101. * the <A HREF="modules.html">modules</A>. Modules are logical
  102. * groupings of related functions or classes, which correspond roughly
  103. * to header files or sections of header files. Each module includes a
  104. * detailed description of the general usage of its functions or
  105. * classes.
  106. *
  107. * From there you can go on to look at the documentation of
  108. * individual functions. You can see different views of the individual
  109. * functions through the links in top bar across this page.
  110. *
  111. * If you prefer a more hands-on approach, you can jump right to some
  112. * <A HREF="../documentation_example_code.html">example code</A>.
  113. *
  114. * \section porting_guide Porting Guide
  115. *
  116. * Starting with FLAC 1.1.3 a \link porting Porting Guide \endlink
  117. * has been introduced which gives detailed instructions on how to
  118. * port your code to newer versions of FLAC.
  119. *
  120. * \section embedded_developers Embedded Developers
  121. *
  122. * libFLAC has grown larger over time as more functionality has been
  123. * included, but much of it may be unnecessary for a particular embedded
  124. * implementation. Unused parts may be pruned by some simple editing of
  125. * src/libFLAC/Makefile.am. In general, the decoders, encoders, and
  126. * metadata interface are all independent from each other.
  127. *
  128. * It is easiest to just describe the dependencies:
  129. *
  130. * - All modules depend on the \link flac_format Format \endlink module.
  131. * - The decoders and encoders depend on the bitbuffer.
  132. * - The decoder is independent of the encoder. The encoder uses the
  133. * decoder because of the verify feature, but this can be removed if
  134. * not needed.
  135. * - Parts of the metadata interface require the stream decoder (but not
  136. * the encoder).
  137. * - Ogg support is selectable through the compile time macro
  138. * \c FLAC__HAS_OGG.
  139. *
  140. * For example, if your application only requires the stream decoder, no
  141. * encoder, and no metadata interface, you can remove the stream encoder
  142. * and the metadata interface, which will greatly reduce the size of the
  143. * library.
  144. *
  145. * Also, there are several places in the libFLAC code with comments marked
  146. * with "OPT:" where a #define can be changed to enable code that might be
  147. * faster on a specific platform. Experimenting with these can yield faster
  148. * binaries.
  149. */
  150. /** \defgroup porting Porting Guide for New Versions
  151. *
  152. * This module describes differences in the library interfaces from
  153. * version to version. It assists in the porting of code that uses
  154. * the libraries to newer versions of FLAC.
  155. *
  156. * One simple facility for making porting easier that has been added
  157. * in FLAC 1.1.3 is a set of \c #defines in \c export.h of each
  158. * library's includes (e.g. \c include/FLAC/export.h). The
  159. * \c #defines mirror the libraries'
  160. * <A HREF="http://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning">libtool version numbers</A>,
  161. * e.g. in libFLAC there are \c FLAC_API_VERSION_CURRENT,
  162. * \c FLAC_API_VERSION_REVISION, and \c FLAC_API_VERSION_AGE.
  163. * These can be used to support multiple versions of an API during the
  164. * transition phase, e.g.
  165. *
  166. * \code
  167. * #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
  168. * legacy code
  169. * #else
  170. * new code
  171. * #endif
  172. * \endcode
  173. *
  174. * The the source will work for multiple versions and the legacy code can
  175. * easily be removed when the transition is complete.
  176. *
  177. * Another available symbol is FLAC_API_SUPPORTS_OGG_FLAC (defined in
  178. * include/FLAC/export.h), which can be used to determine whether or not
  179. * the library has been compiled with support for Ogg FLAC. This is
  180. * simpler than trying to call an Ogg init function and catching the
  181. * error.
  182. */
  183. /** \defgroup porting_1_1_2_to_1_1_3 Porting from FLAC 1.1.2 to 1.1.3
  184. * \ingroup porting
  185. *
  186. * \brief
  187. * This module describes porting from FLAC 1.1.2 to FLAC 1.1.3.
  188. *
  189. * The main change between the APIs in 1.1.2 and 1.1.3 is that they have
  190. * been simplified. First, libOggFLAC has been merged into libFLAC and
  191. * libOggFLAC++ has been merged into libFLAC++. Second, both the three
  192. * decoding layers and three encoding layers have been merged into a
  193. * single stream decoder and stream encoder. That is, the functionality
  194. * of FLAC__SeekableStreamDecoder and FLAC__FileDecoder has been merged
  195. * into FLAC__StreamDecoder, and FLAC__SeekableStreamEncoder and
  196. * FLAC__FileEncoder into FLAC__StreamEncoder. Only the
  197. * FLAC__StreamDecoder and FLAC__StreamEncoder remain. What this means
  198. * is there is now a single API that can be used to encode or decode
  199. * streams to/from native FLAC or Ogg FLAC and the single API can work
  200. * on both seekable and non-seekable streams.
  201. *
  202. * Instead of creating an encoder or decoder of a certain layer, now the
  203. * client will always create a FLAC__StreamEncoder or
  204. * FLAC__StreamDecoder. The old layers are now differentiated by the
  205. * initialization function. For example, for the decoder,
  206. * FLAC__stream_decoder_init() has been replaced by
  207. * FLAC__stream_decoder_init_stream(). This init function takes
  208. * callbacks for the I/O, and the seeking callbacks are optional. This
  209. * allows the client to use the same object for seekable and
  210. * non-seekable streams. For decoding a FLAC file directly, the client
  211. * can use FLAC__stream_decoder_init_file() and pass just a filename
  212. * and fewer callbacks; most of the other callbacks are supplied
  213. * internally. For situations where fopen()ing by filename is not
  214. * possible (e.g. Unicode filenames on Windows) the client can instead
  215. * open the file itself and supply the FILE* to
  216. * FLAC__stream_decoder_init_FILE(). The init functions now returns a
  217. * FLAC__StreamDecoderInitStatus instead of FLAC__StreamDecoderState.
  218. * Since the callbacks and client data are now passed to the init
  219. * function, the FLAC__stream_decoder_set_*_callback() functions and
  220. * FLAC__stream_decoder_set_client_data() are no longer needed. The
  221. * rest of the calls to the decoder are the same as before.
  222. *
  223. * There are counterpart init functions for Ogg FLAC, e.g.
  224. * FLAC__stream_decoder_init_ogg_stream(). All the rest of the calls
  225. * and callbacks are the same as for native FLAC.
  226. *
  227. * As an example, in FLAC 1.1.2 a seekable stream decoder would have
  228. * been set up like so:
  229. *
  230. * \code
  231. * FLAC__SeekableStreamDecoder *decoder = FLAC__seekable_stream_decoder_new();
  232. * if(decoder == NULL) do_something;
  233. * FLAC__seekable_stream_decoder_set_md5_checking(decoder, true);
  234. * [... other settings ...]
  235. * FLAC__seekable_stream_decoder_set_read_callback(decoder, my_read_callback);
  236. * FLAC__seekable_stream_decoder_set_seek_callback(decoder, my_seek_callback);
  237. * FLAC__seekable_stream_decoder_set_tell_callback(decoder, my_tell_callback);
  238. * FLAC__seekable_stream_decoder_set_length_callback(decoder, my_length_callback);
  239. * FLAC__seekable_stream_decoder_set_eof_callback(decoder, my_eof_callback);
  240. * FLAC__seekable_stream_decoder_set_write_callback(decoder, my_write_callback);
  241. * FLAC__seekable_stream_decoder_set_metadata_callback(decoder, my_metadata_callback);
  242. * FLAC__seekable_stream_decoder_set_error_callback(decoder, my_error_callback);
  243. * FLAC__seekable_stream_decoder_set_client_data(decoder, my_client_data);
  244. * if(FLAC__seekable_stream_decoder_init(decoder) != FLAC__SEEKABLE_STREAM_DECODER_OK) do_something;
  245. * \endcode
  246. *
  247. * In FLAC 1.1.3 it is like this:
  248. *
  249. * \code
  250. * FLAC__StreamDecoder *decoder = FLAC__stream_decoder_new();
  251. * if(decoder == NULL) do_something;
  252. * FLAC__stream_decoder_set_md5_checking(decoder, true);
  253. * [... other settings ...]
  254. * if(FLAC__stream_decoder_init_stream(
  255. * decoder,
  256. * my_read_callback,
  257. * my_seek_callback, // or NULL
  258. * my_tell_callback, // or NULL
  259. * my_length_callback, // or NULL
  260. * my_eof_callback, // or NULL
  261. * my_write_callback,
  262. * my_metadata_callback, // or NULL
  263. * my_error_callback,
  264. * my_client_data
  265. * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
  266. * \endcode
  267. *
  268. * or you could do;
  269. *
  270. * \code
  271. * [...]
  272. * FILE *file = fopen("somefile.flac","rb");
  273. * if(file == NULL) do_somthing;
  274. * if(FLAC__stream_decoder_init_FILE(
  275. * decoder,
  276. * file,
  277. * my_write_callback,
  278. * my_metadata_callback, // or NULL
  279. * my_error_callback,
  280. * my_client_data
  281. * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
  282. * \endcode
  283. *
  284. * or just:
  285. *
  286. * \code
  287. * [...]
  288. * if(FLAC__stream_decoder_init_file(
  289. * decoder,
  290. * "somefile.flac",
  291. * my_write_callback,
  292. * my_metadata_callback, // or NULL
  293. * my_error_callback,
  294. * my_client_data
  295. * ) != FLAC__STREAM_DECODER_INIT_STATUS_OK) do_something;
  296. * \endcode
  297. *
  298. * Another small change to the decoder is in how it handles unparseable
  299. * streams. Before, when the decoder found an unparseable stream
  300. * (reserved for when the decoder encounters a stream from a future
  301. * encoder that it can't parse), it changed the state to
  302. * \c FLAC__STREAM_DECODER_UNPARSEABLE_STREAM. Now the decoder instead
  303. * drops sync and calls the error callback with a new error code
  304. * \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM. This is
  305. * more robust. If your error callback does not discriminate on the the
  306. * error state, your code does not need to be changed.
  307. *
  308. * The encoder now has a new setting:
  309. * FLAC__stream_encoder_set_apodization(). This is for setting the
  310. * method used to window the data before LPC analysis. You only need to
  311. * add a call to this function if the default is not suitable. There
  312. * are also two new convenience functions that may be useful:
  313. * FLAC__metadata_object_cuesheet_calculate_cddb_id() and
  314. * FLAC__metadata_get_cuesheet().
  315. *
  316. * The \a bytes parameter to FLAC__StreamDecoderReadCallback,
  317. * FLAC__StreamEncoderReadCallback, and FLAC__StreamEncoderWriteCallback
  318. * is now \c size_t instead of \c unsigned.
  319. */
  320. /** \defgroup porting_1_1_3_to_1_1_4 Porting from FLAC 1.1.3 to 1.1.4
  321. * \ingroup porting
  322. *
  323. * \brief
  324. * This module describes porting from FLAC 1.1.3 to FLAC 1.1.4.
  325. *
  326. * There were no changes to any of the interfaces from 1.1.3 to 1.1.4.
  327. * There was a slight change in the implementation of
  328. * FLAC__stream_encoder_set_metadata(); the function now makes a copy
  329. * of the \a metadata array of pointers so the client no longer needs
  330. * to maintain it after the call. The objects themselves that are
  331. * pointed to by the array are still not copied though and must be
  332. * maintained until the call to FLAC__stream_encoder_finish().
  333. */
  334. /** \defgroup porting_1_1_4_to_1_2_0 Porting from FLAC 1.1.4 to 1.2.0
  335. * \ingroup porting
  336. *
  337. * \brief
  338. * This module describes porting from FLAC 1.1.4 to FLAC 1.2.0.
  339. *
  340. * There were only very minor changes to the interfaces from 1.1.4 to 1.2.0.
  341. * In libFLAC, \c FLAC__format_sample_rate_is_subset() was added.
  342. * In libFLAC++, \c FLAC::Decoder::Stream::get_decode_position() was added.
  343. *
  344. * Finally, value of the constant \c FLAC__FRAME_HEADER_RESERVED_LEN
  345. * has changed to reflect the conversion of one of the reserved bits
  346. * into active use. It used to be \c 2 and now is \c 1. However the
  347. * FLAC frame header length has not changed, so to skip the proper
  348. * number of bits, use \c FLAC__FRAME_HEADER_RESERVED_LEN +
  349. * \c FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN
  350. */
  351. /** \defgroup flac FLAC C API
  352. *
  353. * The FLAC C API is the interface to libFLAC, a set of structures
  354. * describing the components of FLAC streams, and functions for
  355. * encoding and decoding streams, as well as manipulating FLAC
  356. * metadata in files.
  357. *
  358. * You should start with the format components as all other modules
  359. * are dependent on it.
  360. */
  361. #endif