flac_FLAC_stream_decoder.h 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2000,2001,2002,2003,2004,2005,2006,2007 Josh Coalson
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * - Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  11. * - 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.
  30. */
  31. #ifndef FLAC__STREAM_DECODER_H
  32. #define FLAC__STREAM_DECODER_H
  33. #include <stdio.h> /* for FILE */
  34. #include "flac_FLAC_export.h"
  35. #include "flac_FLAC_format.h"
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /** \file include/FLAC/stream_decoder.h
  40. *
  41. * \brief
  42. * This module contains the functions which implement the stream
  43. * decoder.
  44. *
  45. * See the detailed documentation in the
  46. * \link flac_stream_decoder stream decoder \endlink module.
  47. */
  48. /** \defgroup flac_decoder FLAC/ \*_decoder.h: decoder interfaces
  49. * \ingroup flac
  50. *
  51. * \brief
  52. * This module describes the decoder layers provided by libFLAC.
  53. *
  54. * The stream decoder can be used to decode complete streams either from
  55. * the client via callbacks, or directly from a file, depending on how
  56. * it is initialized. When decoding via callbacks, the client provides
  57. * callbacks for reading FLAC data and writing decoded samples, and
  58. * handling metadata and errors. If the client also supplies seek-related
  59. * callback, the decoder function for sample-accurate seeking within the
  60. * FLAC input is also available. When decoding from a file, the client
  61. * needs only supply a filename or open \c FILE* and write/metadata/error
  62. * callbacks; the rest of the callbacks are supplied internally. For more
  63. * info see the \link flac_stream_decoder stream decoder \endlink module.
  64. */
  65. /** \defgroup flac_stream_decoder FLAC/stream_decoder.h: stream decoder interface
  66. * \ingroup flac_decoder
  67. *
  68. * \brief
  69. * This module contains the functions which implement the stream
  70. * decoder.
  71. *
  72. * The stream decoder can decode native FLAC, and optionally Ogg FLAC
  73. * (check FLAC_API_SUPPORTS_OGG_FLAC) streams and files.
  74. *
  75. * The basic usage of this decoder is as follows:
  76. * - The program creates an instance of a decoder using
  77. * FLAC__stream_decoder_new().
  78. * - The program overrides the default settings using
  79. * FLAC__stream_decoder_set_*() functions.
  80. * - The program initializes the instance to validate the settings and
  81. * prepare for decoding using
  82. * - FLAC__stream_decoder_init_stream() or FLAC__stream_decoder_init_FILE()
  83. * or FLAC__stream_decoder_init_file() for native FLAC,
  84. * - FLAC__stream_decoder_init_ogg_stream() or FLAC__stream_decoder_init_ogg_FILE()
  85. * or FLAC__stream_decoder_init_ogg_file() for Ogg FLAC
  86. * - The program calls the FLAC__stream_decoder_process_*() functions
  87. * to decode data, which subsequently calls the callbacks.
  88. * - The program finishes the decoding with FLAC__stream_decoder_finish(),
  89. * which flushes the input and output and resets the decoder to the
  90. * uninitialized state.
  91. * - The instance may be used again or deleted with
  92. * FLAC__stream_decoder_delete().
  93. *
  94. * In more detail, the program will create a new instance by calling
  95. * FLAC__stream_decoder_new(), then call FLAC__stream_decoder_set_*()
  96. * functions to override the default decoder options, and call
  97. * one of the FLAC__stream_decoder_init_*() functions.
  98. *
  99. * There are three initialization functions for native FLAC, one for
  100. * setting up the decoder to decode FLAC data from the client via
  101. * callbacks, and two for decoding directly from a FLAC file.
  102. *
  103. * For decoding via callbacks, use FLAC__stream_decoder_init_stream().
  104. * You must also supply several callbacks for handling I/O. Some (like
  105. * seeking) are optional, depending on the capabilities of the input.
  106. *
  107. * For decoding directly from a file, use FLAC__stream_decoder_init_FILE()
  108. * or FLAC__stream_decoder_init_file(). Then you must only supply an open
  109. * \c FILE* or filename and fewer callbacks; the decoder will handle
  110. * the other callbacks internally.
  111. *
  112. * There are three similarly-named init functions for decoding from Ogg
  113. * FLAC streams. Check \c FLAC_API_SUPPORTS_OGG_FLAC to find out if the
  114. * library has been built with Ogg support.
  115. *
  116. * Once the decoder is initialized, your program will call one of several
  117. * functions to start the decoding process:
  118. *
  119. * - FLAC__stream_decoder_process_single() - Tells the decoder to process at
  120. * most one metadata block or audio frame and return, calling either the
  121. * metadata callback or write callback, respectively, once. If the decoder
  122. * loses sync it will return with only the error callback being called.
  123. * - FLAC__stream_decoder_process_until_end_of_metadata() - Tells the decoder
  124. * to process the stream from the current location and stop upon reaching
  125. * the first audio frame. The client will get one metadata, write, or error
  126. * callback per metadata block, audio frame, or sync error, respectively.
  127. * - FLAC__stream_decoder_process_until_end_of_stream() - Tells the decoder
  128. * to process the stream from the current location until the read callback
  129. * returns FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM or
  130. * FLAC__STREAM_DECODER_READ_STATUS_ABORT. The client will get one metadata,
  131. * write, or error callback per metadata block, audio frame, or sync error,
  132. * respectively.
  133. *
  134. * When the decoder has finished decoding (normally or through an abort),
  135. * the instance is finished by calling FLAC__stream_decoder_finish(), which
  136. * ensures the decoder is in the correct state and frees memory. Then the
  137. * instance may be deleted with FLAC__stream_decoder_delete() or initialized
  138. * again to decode another stream.
  139. *
  140. * Seeking is exposed through the FLAC__stream_decoder_seek_absolute() method.
  141. * At any point after the stream decoder has been initialized, the client can
  142. * call this function to seek to an exact sample within the stream.
  143. * Subsequently, the first time the write callback is called it will be
  144. * passed a (possibly partial) block starting at that sample.
  145. *
  146. * If the client cannot seek via the callback interface provided, but still
  147. * has another way of seeking, it can flush the decoder using
  148. * FLAC__stream_decoder_flush() and start feeding data from the new position
  149. * through the read callback.
  150. *
  151. * The stream decoder also provides MD5 signature checking. If this is
  152. * turned on before initialization, FLAC__stream_decoder_finish() will
  153. * report when the decoded MD5 signature does not match the one stored
  154. * in the STREAMINFO block. MD5 checking is automatically turned off
  155. * (until the next FLAC__stream_decoder_reset()) if there is no signature
  156. * in the STREAMINFO block or when a seek is attempted.
  157. *
  158. * The FLAC__stream_decoder_set_metadata_*() functions deserve special
  159. * attention. By default, the decoder only calls the metadata_callback for
  160. * the STREAMINFO block. These functions allow you to tell the decoder
  161. * explicitly which blocks to parse and return via the metadata_callback
  162. * and/or which to skip. Use a FLAC__stream_decoder_set_metadata_respond_all(),
  163. * FLAC__stream_decoder_set_metadata_ignore() ... or FLAC__stream_decoder_set_metadata_ignore_all(),
  164. * FLAC__stream_decoder_set_metadata_respond() ... sequence to exactly specify
  165. * which blocks to return. Remember that metadata blocks can potentially
  166. * be big (for example, cover art) so filtering out the ones you don't
  167. * use can reduce the memory requirements of the decoder. Also note the
  168. * special forms FLAC__stream_decoder_set_metadata_respond_application(id)
  169. * and FLAC__stream_decoder_set_metadata_ignore_application(id) for
  170. * filtering APPLICATION blocks based on the application ID.
  171. *
  172. * STREAMINFO and SEEKTABLE blocks are always parsed and used internally, but
  173. * they still can legally be filtered from the metadata_callback.
  174. *
  175. * \note
  176. * The "set" functions may only be called when the decoder is in the
  177. * state FLAC__STREAM_DECODER_UNINITIALIZED, i.e. after
  178. * FLAC__stream_decoder_new() or FLAC__stream_decoder_finish(), but
  179. * before FLAC__stream_decoder_init_*(). If this is the case they will
  180. * return \c true, otherwise \c false.
  181. *
  182. * \note
  183. * FLAC__stream_decoder_finish() resets all settings to the constructor
  184. * defaults, including the callbacks.
  185. *
  186. * \{
  187. */
  188. /** State values for a FLAC__StreamDecoder
  189. *
  190. * The decoder's state can be obtained by calling FLAC__stream_decoder_get_state().
  191. */
  192. typedef enum {
  193. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  194. /**< The decoder is ready to search for metadata. */
  195. FLAC__STREAM_DECODER_READ_METADATA,
  196. /**< The decoder is ready to or is in the process of reading metadata. */
  197. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  198. /**< The decoder is ready to or is in the process of searching for the
  199. * frame sync code.
  200. */
  201. FLAC__STREAM_DECODER_READ_FRAME,
  202. /**< The decoder is ready to or is in the process of reading a frame. */
  203. FLAC__STREAM_DECODER_END_OF_STREAM,
  204. /**< The decoder has reached the end of the stream. */
  205. FLAC__STREAM_DECODER_OGG_ERROR,
  206. /**< An error occurred in the underlying Ogg layer. */
  207. FLAC__STREAM_DECODER_SEEK_ERROR,
  208. /**< An error occurred while seeking. The decoder must be flushed
  209. * with FLAC__stream_decoder_flush() or reset with
  210. * FLAC__stream_decoder_reset() before decoding can continue.
  211. */
  212. FLAC__STREAM_DECODER_ABORTED,
  213. /**< The decoder was aborted by the read callback. */
  214. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  215. /**< An error occurred allocating memory. The decoder is in an invalid
  216. * state and can no longer be used.
  217. */
  218. FLAC__STREAM_DECODER_UNINITIALIZED
  219. /**< The decoder is in the uninitialized state; one of the
  220. * FLAC__stream_decoder_init_*() functions must be called before samples
  221. * can be processed.
  222. */
  223. } FLAC__StreamDecoderState;
  224. /** Maps a FLAC__StreamDecoderState to a C string.
  225. *
  226. * Using a FLAC__StreamDecoderState as the index to this array
  227. * will give the string equivalent. The contents should not be modified.
  228. */
  229. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  230. /** Possible return values for the FLAC__stream_decoder_init_*() functions.
  231. */
  232. typedef enum {
  233. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  234. /**< Initialization was successful. */
  235. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  236. /**< The library was not compiled with support for the given container
  237. * format.
  238. */
  239. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  240. /**< A required callback was not supplied. */
  241. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  242. /**< An error occurred allocating memory. */
  243. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  244. /**< fopen() failed in FLAC__stream_decoder_init_file() or
  245. * FLAC__stream_decoder_init_ogg_file(). */
  246. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  247. /**< FLAC__stream_decoder_init_*() was called when the decoder was
  248. * already initialized, usually because
  249. * FLAC__stream_decoder_finish() was not called.
  250. */
  251. } FLAC__StreamDecoderInitStatus;
  252. /** Maps a FLAC__StreamDecoderInitStatus to a C string.
  253. *
  254. * Using a FLAC__StreamDecoderInitStatus as the index to this array
  255. * will give the string equivalent. The contents should not be modified.
  256. */
  257. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  258. /** Return values for the FLAC__StreamDecoder read callback.
  259. */
  260. typedef enum {
  261. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  262. /**< The read was OK and decoding can continue. */
  263. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  264. /**< The read was attempted while at the end of the stream. Note that
  265. * the client must only return this value when the read callback was
  266. * called when already at the end of the stream. Otherwise, if the read
  267. * itself moves to the end of the stream, the client should still return
  268. * the data and \c FLAC__STREAM_DECODER_READ_STATUS_CONTINUE, and then on
  269. * the next read callback it should return
  270. * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM with a byte count
  271. * of \c 0.
  272. */
  273. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  274. /**< An unrecoverable error occurred. The decoder will return from the process call. */
  275. } FLAC__StreamDecoderReadStatus;
  276. /** Maps a FLAC__StreamDecoderReadStatus to a C string.
  277. *
  278. * Using a FLAC__StreamDecoderReadStatus as the index to this array
  279. * will give the string equivalent. The contents should not be modified.
  280. */
  281. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  282. /** Return values for the FLAC__StreamDecoder seek callback.
  283. */
  284. typedef enum {
  285. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  286. /**< The seek was OK and decoding can continue. */
  287. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  288. /**< An unrecoverable error occurred. The decoder will return from the process call. */
  289. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  290. /**< Client does not support seeking. */
  291. } FLAC__StreamDecoderSeekStatus;
  292. /** Maps a FLAC__StreamDecoderSeekStatus to a C string.
  293. *
  294. * Using a FLAC__StreamDecoderSeekStatus as the index to this array
  295. * will give the string equivalent. The contents should not be modified.
  296. */
  297. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  298. /** Return values for the FLAC__StreamDecoder tell callback.
  299. */
  300. typedef enum {
  301. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  302. /**< The tell was OK and decoding can continue. */
  303. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  304. /**< An unrecoverable error occurred. The decoder will return from the process call. */
  305. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  306. /**< Client does not support telling the position. */
  307. } FLAC__StreamDecoderTellStatus;
  308. /** Maps a FLAC__StreamDecoderTellStatus to a C string.
  309. *
  310. * Using a FLAC__StreamDecoderTellStatus as the index to this array
  311. * will give the string equivalent. The contents should not be modified.
  312. */
  313. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  314. /** Return values for the FLAC__StreamDecoder length callback.
  315. */
  316. typedef enum {
  317. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  318. /**< The length call was OK and decoding can continue. */
  319. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  320. /**< An unrecoverable error occurred. The decoder will return from the process call. */
  321. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  322. /**< Client does not support reporting the length. */
  323. } FLAC__StreamDecoderLengthStatus;
  324. /** Maps a FLAC__StreamDecoderLengthStatus to a C string.
  325. *
  326. * Using a FLAC__StreamDecoderLengthStatus as the index to this array
  327. * will give the string equivalent. The contents should not be modified.
  328. */
  329. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  330. /** Return values for the FLAC__StreamDecoder write callback.
  331. */
  332. typedef enum {
  333. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  334. /**< The write was OK and decoding can continue. */
  335. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  336. /**< An unrecoverable error occurred. The decoder will return from the process call. */
  337. } FLAC__StreamDecoderWriteStatus;
  338. /** Maps a FLAC__StreamDecoderWriteStatus to a C string.
  339. *
  340. * Using a FLAC__StreamDecoderWriteStatus as the index to this array
  341. * will give the string equivalent. The contents should not be modified.
  342. */
  343. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  344. /** Possible values passed back to the FLAC__StreamDecoder error callback.
  345. * \c FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC is the generic catch-
  346. * all. The rest could be caused by bad sync (false synchronization on
  347. * data that is not the start of a frame) or corrupted data. The error
  348. * itself is the decoder's best guess at what happened assuming a correct
  349. * sync. For example \c FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER
  350. * could be caused by a correct sync on the start of a frame, but some
  351. * data in the frame header was corrupted. Or it could be the result of
  352. * syncing on a point the stream that looked like the starting of a frame
  353. * but was not. \c FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  354. * could be because the decoder encountered a valid frame made by a future
  355. * version of the encoder which it cannot parse, or because of a false
  356. * sync making it appear as though an encountered frame was generated by
  357. * a future encoder.
  358. */
  359. typedef enum {
  360. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  361. /**< An error in the stream caused the decoder to lose synchronization. */
  362. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  363. /**< The decoder encountered a corrupted frame header. */
  364. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  365. /**< The frame's data did not match the CRC in the footer. */
  366. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  367. /**< The decoder encountered reserved fields in use in the stream. */
  368. } FLAC__StreamDecoderErrorStatus;
  369. /** Maps a FLAC__StreamDecoderErrorStatus to a C string.
  370. *
  371. * Using a FLAC__StreamDecoderErrorStatus as the index to this array
  372. * will give the string equivalent. The contents should not be modified.
  373. */
  374. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  375. /***********************************************************************
  376. *
  377. * class FLAC__StreamDecoder
  378. *
  379. ***********************************************************************/
  380. struct FLAC__StreamDecoderProtected;
  381. struct FLAC__StreamDecoderPrivate;
  382. /** The opaque structure definition for the stream decoder type.
  383. * See the \link flac_stream_decoder stream decoder module \endlink
  384. * for a detailed description.
  385. */
  386. typedef struct FLAC__StreamDecoder { // ppgb 20071120
  387. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  388. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  389. } FLAC__StreamDecoder;
  390. /** Signature for the read callback.
  391. *
  392. * A function pointer matching this signature must be passed to
  393. * FLAC__stream_decoder_init*_stream(). The supplied function will be
  394. * called when the decoder needs more input data. The address of the
  395. * buffer to be filled is supplied, along with the number of bytes the
  396. * buffer can hold. The callback may choose to supply less data and
  397. * modify the byte count but must be careful not to overflow the buffer.
  398. * The callback then returns a status code chosen from
  399. * FLAC__StreamDecoderReadStatus.
  400. *
  401. * Here is an example of a read callback for stdio streams:
  402. * \code
  403. * FLAC__StreamDecoderReadStatus read_cb(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  404. * {
  405. * FILE *file = ((MyClientData*)client_data)->file;
  406. * if(*bytes > 0) {
  407. * *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, file);
  408. * if(ferror(file))
  409. * return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  410. * else if(*bytes == 0)
  411. * return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  412. * else
  413. * return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  414. * }
  415. * else
  416. * return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  417. * }
  418. * \endcode
  419. *
  420. * \note In general, FLAC__StreamDecoder functions which change the
  421. * state should not be called on the \a decoder while in the callback.
  422. *
  423. * \param decoder The decoder instance calling the callback.
  424. * \param buffer A pointer to a location for the callee to store
  425. * data to be decoded.
  426. * \param bytes A pointer to the size of the buffer. On entry
  427. * to the callback, it contains the maximum number
  428. * of bytes that may be stored in \a buffer. The
  429. * callee must set it to the actual number of bytes
  430. * stored (0 in case of error or end-of-stream) before
  431. * returning.
  432. * \param client_data The callee's client data set through
  433. * FLAC__stream_decoder_init_*().
  434. * \retval FLAC__StreamDecoderReadStatus
  435. * The callee's return status. Note that the callback should return
  436. * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM if and only if
  437. * zero bytes were read and there is no more data to be read.
  438. */
  439. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  440. /** Signature for the seek callback.
  441. *
  442. * A function pointer matching this signature may be passed to
  443. * FLAC__stream_decoder_init*_stream(). The supplied function will be
  444. * called when the decoder needs to seek the input stream. The decoder
  445. * will pass the absolute byte offset to seek to, 0 meaning the
  446. * beginning of the stream.
  447. *
  448. * Here is an example of a seek callback for stdio streams:
  449. * \code
  450. * FLAC__StreamDecoderSeekStatus seek_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  451. * {
  452. * FILE *file = ((MyClientData*)client_data)->file;
  453. * if(file == stdin)
  454. * return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  455. * else if(fseeko(file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  456. * return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  457. * else
  458. * return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  459. * }
  460. * \endcode
  461. *
  462. * \note In general, FLAC__StreamDecoder functions which change the
  463. * state should not be called on the \a decoder while in the callback.
  464. *
  465. * \param decoder The decoder instance calling the callback.
  466. * \param absolute_byte_offset The offset from the beginning of the stream
  467. * to seek to.
  468. * \param client_data The callee's client data set through
  469. * FLAC__stream_decoder_init_*().
  470. * \retval FLAC__StreamDecoderSeekStatus
  471. * The callee's return status.
  472. */
  473. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  474. /** Signature for the tell callback.
  475. *
  476. * A function pointer matching this signature may be passed to
  477. * FLAC__stream_decoder_init*_stream(). The supplied function will be
  478. * called when the decoder wants to know the current position of the
  479. * stream. The callback should return the byte offset from the
  480. * beginning of the stream.
  481. *
  482. * Here is an example of a tell callback for stdio streams:
  483. * \code
  484. * FLAC__StreamDecoderTellStatus tell_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  485. * {
  486. * FILE *file = ((MyClientData*)client_data)->file;
  487. * off_t pos;
  488. * if(file == stdin)
  489. * return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  490. * else if((pos = ftello(file)) < 0)
  491. * return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  492. * else {
  493. * *absolute_byte_offset = (FLAC__uint64)pos;
  494. * return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  495. * }
  496. * }
  497. * \endcode
  498. *
  499. * \note In general, FLAC__StreamDecoder functions which change the
  500. * state should not be called on the \a decoder while in the callback.
  501. *
  502. * \param decoder The decoder instance calling the callback.
  503. * \param absolute_byte_offset A pointer to storage for the current offset
  504. * from the beginning of the stream.
  505. * \param client_data The callee's client data set through
  506. * FLAC__stream_decoder_init_*().
  507. * \retval FLAC__StreamDecoderTellStatus
  508. * The callee's return status.
  509. */
  510. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  511. /** Signature for the length callback.
  512. *
  513. * A function pointer matching this signature may be passed to
  514. * FLAC__stream_decoder_init*_stream(). The supplied function will be
  515. * called when the decoder wants to know the total length of the stream
  516. * in bytes.
  517. *
  518. * Here is an example of a length callback for stdio streams:
  519. * \code
  520. * FLAC__StreamDecoderLengthStatus length_cb(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  521. * {
  522. * FILE *file = ((MyClientData*)client_data)->file;
  523. * struct stat filestats;
  524. *
  525. * if(file == stdin)
  526. * return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  527. * else if(fstat(fileno(file), &filestats) != 0)
  528. * return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  529. * else {
  530. * *stream_length = (FLAC__uint64)filestats.st_size;
  531. * return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  532. * }
  533. * }
  534. * \endcode
  535. *
  536. * \note In general, FLAC__StreamDecoder functions which change the
  537. * state should not be called on the \a decoder while in the callback.
  538. *
  539. * \param decoder The decoder instance calling the callback.
  540. * \param stream_length A pointer to storage for the length of the stream
  541. * in bytes.
  542. * \param client_data The callee's client data set through
  543. * FLAC__stream_decoder_init_*().
  544. * \retval FLAC__StreamDecoderLengthStatus
  545. * The callee's return status.
  546. */
  547. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  548. /** Signature for the EOF callback.
  549. *
  550. * A function pointer matching this signature may be passed to
  551. * FLAC__stream_decoder_init*_stream(). The supplied function will be
  552. * called when the decoder needs to know if the end of the stream has
  553. * been reached.
  554. *
  555. * Here is an example of a EOF callback for stdio streams:
  556. * FLAC__bool eof_cb(const FLAC__StreamDecoder *decoder, void *client_data)
  557. * \code
  558. * {
  559. * FILE *file = ((MyClientData*)client_data)->file;
  560. * return feof(file)? true : false;
  561. * }
  562. * \endcode
  563. *
  564. * \note In general, FLAC__StreamDecoder functions which change the
  565. * state should not be called on the \a decoder while in the callback.
  566. *
  567. * \param decoder The decoder instance calling the callback.
  568. * \param client_data The callee's client data set through
  569. * FLAC__stream_decoder_init_*().
  570. * \retval FLAC__bool
  571. * \c true if the currently at the end of the stream, else \c false.
  572. */
  573. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  574. /** Signature for the write callback.
  575. *
  576. * A function pointer matching this signature must be passed to one of
  577. * the FLAC__stream_decoder_init_*() functions.
  578. * The supplied function will be called when the decoder has decoded a
  579. * single audio frame. The decoder will pass the frame metadata as well
  580. * as an array of pointers (one for each channel) pointing to the
  581. * decoded audio.
  582. *
  583. * \note In general, FLAC__StreamDecoder functions which change the
  584. * state should not be called on the \a decoder while in the callback.
  585. *
  586. * \param decoder The decoder instance calling the callback.
  587. * \param frame The description of the decoded frame. See
  588. * FLAC__Frame.
  589. * \param buffer An array of pointers to decoded channels of data.
  590. * Each pointer will point to an array of signed
  591. * samples of length \a frame->header.blocksize.
  592. * Channels will be ordered according to the FLAC
  593. * specification; see the documentation for the
  594. * <A HREF="../format.html#frame_header">frame header</A>.
  595. * \param client_data The callee's client data set through
  596. * FLAC__stream_decoder_init_*().
  597. * \retval FLAC__StreamDecoderWriteStatus
  598. * The callee's return status.
  599. */
  600. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  601. /** Signature for the metadata callback.
  602. *
  603. * A function pointer matching this signature must be passed to one of
  604. * the FLAC__stream_decoder_init_*() functions.
  605. * The supplied function will be called when the decoder has decoded a
  606. * metadata block. In a valid FLAC file there will always be one
  607. * \c STREAMINFO block, followed by zero or more other metadata blocks.
  608. * These will be supplied by the decoder in the same order as they
  609. * appear in the stream and always before the first audio frame (i.e.
  610. * write callback). The metadata block that is passed in must not be
  611. * modified, and it doesn't live beyond the callback, so you should make
  612. * a copy of it with FLAC__metadata_object_clone() if you will need it
  613. * elsewhere. Since metadata blocks can potentially be large, by
  614. * default the decoder only calls the metadata callback for the
  615. * \c STREAMINFO block; you can instruct the decoder to pass or filter
  616. * other blocks with FLAC__stream_decoder_set_metadata_*() calls.
  617. *
  618. * \note In general, FLAC__StreamDecoder functions which change the
  619. * state should not be called on the \a decoder while in the callback.
  620. *
  621. * \param decoder The decoder instance calling the callback.
  622. * \param metadata The decoded metadata block.
  623. * \param client_data The callee's client data set through
  624. * FLAC__stream_decoder_init_*().
  625. */
  626. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  627. /** Signature for the error callback.
  628. *
  629. * A function pointer matching this signature must be passed to one of
  630. * the FLAC__stream_decoder_init_*() functions.
  631. * The supplied function will be called whenever an error occurs during
  632. * decoding.
  633. *
  634. * \note In general, FLAC__StreamDecoder functions which change the
  635. * state should not be called on the \a decoder while in the callback.
  636. *
  637. * \param decoder The decoder instance calling the callback.
  638. * \param status The error encountered by the decoder.
  639. * \param client_data The callee's client data set through
  640. * FLAC__stream_decoder_init_*().
  641. */
  642. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  643. /***********************************************************************
  644. *
  645. * Class constructor/destructor
  646. *
  647. ***********************************************************************/
  648. /** Create a new stream decoder instance. The instance is created with
  649. * default settings; see the individual FLAC__stream_decoder_set_*()
  650. * functions for each setting's default.
  651. *
  652. * \retval FLAC__StreamDecoder*
  653. * \c NULL if there was an error allocating memory, else the new instance.
  654. */
  655. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  656. /** Free a decoder instance. Deletes the object pointed to by \a decoder.
  657. *
  658. * \param decoder A pointer to an existing decoder.
  659. * \assert
  660. * \code decoder != NULL \endcode
  661. */
  662. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  663. /***********************************************************************
  664. *
  665. * Public class method prototypes
  666. *
  667. ***********************************************************************/
  668. /** Set the serial number for the FLAC stream within the Ogg container.
  669. * The default behavior is to use the serial number of the first Ogg
  670. * page. Setting a serial number here will explicitly specify which
  671. * stream is to be decoded.
  672. *
  673. * \note
  674. * This does not need to be set for native FLAC decoding.
  675. *
  676. * \default \c use serial number of first page
  677. * \param decoder A decoder instance to set.
  678. * \param serial_number See above.
  679. * \assert
  680. * \code decoder != NULL \endcode
  681. * \retval FLAC__bool
  682. * \c false if the decoder is already initialized, else \c true.
  683. */
  684. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  685. /** Set the "MD5 signature checking" flag. If \c true, the decoder will
  686. * compute the MD5 signature of the unencoded audio data while decoding
  687. * and compare it to the signature from the STREAMINFO block, if it
  688. * exists, during FLAC__stream_decoder_finish().
  689. *
  690. * MD5 signature checking will be turned off (until the next
  691. * FLAC__stream_decoder_reset()) if there is no signature in the
  692. * STREAMINFO block or when a seek is attempted.
  693. *
  694. * Clients that do not use the MD5 check should leave this off to speed
  695. * up decoding.
  696. *
  697. * \default \c false
  698. * \param decoder A decoder instance to set.
  699. * \param value Flag value (see above).
  700. * \assert
  701. * \code decoder != NULL \endcode
  702. * \retval FLAC__bool
  703. * \c false if the decoder is already initialized, else \c true.
  704. */
  705. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  706. /** Direct the decoder to pass on all metadata blocks of type \a type.
  707. *
  708. * \default By default, only the \c STREAMINFO block is returned via the
  709. * metadata callback.
  710. * \param decoder A decoder instance to set.
  711. * \param type See above.
  712. * \assert
  713. * \code decoder != NULL \endcode
  714. * \a type is valid
  715. * \retval FLAC__bool
  716. * \c false if the decoder is already initialized, else \c true.
  717. */
  718. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  719. /** Direct the decoder to pass on all APPLICATION metadata blocks of the
  720. * given \a id.
  721. *
  722. * \default By default, only the \c STREAMINFO block is returned via the
  723. * metadata callback.
  724. * \param decoder A decoder instance to set.
  725. * \param id See above.
  726. * \assert
  727. * \code decoder != NULL \endcode
  728. * \code id != NULL \endcode
  729. * \retval FLAC__bool
  730. * \c false if the decoder is already initialized, else \c true.
  731. */
  732. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  733. /** Direct the decoder to pass on all metadata blocks of any type.
  734. *
  735. * \default By default, only the \c STREAMINFO block is returned via the
  736. * metadata callback.
  737. * \param decoder A decoder instance to set.
  738. * \assert
  739. * \code decoder != NULL \endcode
  740. * \retval FLAC__bool
  741. * \c false if the decoder is already initialized, else \c true.
  742. */
  743. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  744. /** Direct the decoder to filter out all metadata blocks of type \a type.
  745. *
  746. * \default By default, only the \c STREAMINFO block is returned via the
  747. * metadata callback.
  748. * \param decoder A decoder instance to set.
  749. * \param type See above.
  750. * \assert
  751. * \code decoder != NULL \endcode
  752. * \a type is valid
  753. * \retval FLAC__bool
  754. * \c false if the decoder is already initialized, else \c true.
  755. */
  756. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  757. /** Direct the decoder to filter out all APPLICATION metadata blocks of
  758. * the given \a id.
  759. *
  760. * \default By default, only the \c STREAMINFO block is returned via the
  761. * metadata callback.
  762. * \param decoder A decoder instance to set.
  763. * \param id See above.
  764. * \assert
  765. * \code decoder != NULL \endcode
  766. * \code id != NULL \endcode
  767. * \retval FLAC__bool
  768. * \c false if the decoder is already initialized, else \c true.
  769. */
  770. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  771. /** Direct the decoder to filter out all metadata blocks of any type.
  772. *
  773. * \default By default, only the \c STREAMINFO block is returned via the
  774. * metadata callback.
  775. * \param decoder A decoder instance to set.
  776. * \assert
  777. * \code decoder != NULL \endcode
  778. * \retval FLAC__bool
  779. * \c false if the decoder is already initialized, else \c true.
  780. */
  781. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  782. /** Get the current decoder state.
  783. *
  784. * \param decoder A decoder instance to query.
  785. * \assert
  786. * \code decoder != NULL \endcode
  787. * \retval FLAC__StreamDecoderState
  788. * The current decoder state.
  789. */
  790. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  791. /** Get the current decoder state as a C string.
  792. *
  793. * \param decoder A decoder instance to query.
  794. * \assert
  795. * \code decoder != NULL \endcode
  796. * \retval const char *
  797. * The decoder state as a C string. Do not modify the contents.
  798. */
  799. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  800. /** Get the "MD5 signature checking" flag.
  801. * This is the value of the setting, not whether or not the decoder is
  802. * currently checking the MD5 (remember, it can be turned off automatically
  803. * by a seek). When the decoder is reset the flag will be restored to the
  804. * value returned by this function.
  805. *
  806. * \param decoder A decoder instance to query.
  807. * \assert
  808. * \code decoder != NULL \endcode
  809. * \retval FLAC__bool
  810. * See above.
  811. */
  812. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  813. /** Get the total number of samples in the stream being decoded.
  814. * Will only be valid after decoding has started and will contain the
  815. * value from the \c STREAMINFO block. A value of \c 0 means "unknown".
  816. *
  817. * \param decoder A decoder instance to query.
  818. * \assert
  819. * \code decoder != NULL \endcode
  820. * \retval unsigned
  821. * See above.
  822. */
  823. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  824. /** Get the current number of channels in the stream being decoded.
  825. * Will only be valid after decoding has started and will contain the
  826. * value from the most recently decoded frame header.
  827. *
  828. * \param decoder A decoder instance to query.
  829. * \assert
  830. * \code decoder != NULL \endcode
  831. * \retval unsigned
  832. * See above.
  833. */
  834. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  835. /** Get the current channel assignment in the stream being decoded.
  836. * Will only be valid after decoding has started and will contain the
  837. * value from the most recently decoded frame header.
  838. *
  839. * \param decoder A decoder instance to query.
  840. * \assert
  841. * \code decoder != NULL \endcode
  842. * \retval FLAC__ChannelAssignment
  843. * See above.
  844. */
  845. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  846. /** Get the current sample resolution in the stream being decoded.
  847. * Will only be valid after decoding has started and will contain the
  848. * value from the most recently decoded frame header.
  849. *
  850. * \param decoder A decoder instance to query.
  851. * \assert
  852. * \code decoder != NULL \endcode
  853. * \retval unsigned
  854. * See above.
  855. */
  856. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  857. /** Get the current sample rate in Hz of the stream being decoded.
  858. * Will only be valid after decoding has started and will contain the
  859. * value from the most recently decoded frame header.
  860. *
  861. * \param decoder A decoder instance to query.
  862. * \assert
  863. * \code decoder != NULL \endcode
  864. * \retval unsigned
  865. * See above.
  866. */
  867. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  868. /** Get the current blocksize of the stream being decoded.
  869. * Will only be valid after decoding has started and will contain the
  870. * value from the most recently decoded frame header.
  871. *
  872. * \param decoder A decoder instance to query.
  873. * \assert
  874. * \code decoder != NULL \endcode
  875. * \retval unsigned
  876. * See above.
  877. */
  878. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  879. /** Returns the decoder's current read position within the stream.
  880. * The position is the byte offset from the start of the stream.
  881. * Bytes before this position have been fully decoded. Note that
  882. * there may still be undecoded bytes in the decoder's read FIFO.
  883. * The returned position is correct even after a seek.
  884. *
  885. * \warning This function currently only works for native FLAC,
  886. * not Ogg FLAC streams.
  887. *
  888. * \param decoder A decoder instance to query.
  889. * \param position Address at which to return the desired position.
  890. * \assert
  891. * \code decoder != NULL \endcode
  892. * \code position != NULL \endcode
  893. * \retval FLAC__bool
  894. * \c true if successful, \c false if the stream is not native FLAC,
  895. * or there was an error from the 'tell' callback or it returned
  896. * \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED.
  897. */
  898. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  899. /** Initialize the decoder instance to decode native FLAC streams.
  900. *
  901. * This flavor of initialization sets up the decoder to decode from a
  902. * native FLAC stream. I/O is performed via callbacks to the client.
  903. * For decoding from a plain file via filename or open FILE*,
  904. * FLAC__stream_decoder_init_file() and FLAC__stream_decoder_init_FILE()
  905. * provide a simpler interface.
  906. *
  907. * This function should be called after FLAC__stream_decoder_new() and
  908. * FLAC__stream_decoder_set_*() but before any of the
  909. * FLAC__stream_decoder_process_*() functions. Will set and return the
  910. * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
  911. * if initialization succeeded.
  912. *
  913. * \param decoder An uninitialized decoder instance.
  914. * \param read_callback See FLAC__StreamDecoderReadCallback. This
  915. * pointer must not be \c NULL.
  916. * \param seek_callback See FLAC__StreamDecoderSeekCallback. This
  917. * pointer may be \c NULL if seeking is not
  918. * supported. If \a seek_callback is not \c NULL then a
  919. * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied.
  920. * Alternatively, a dummy seek callback that just
  921. * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  922. * may also be supplied, all though this is slightly
  923. * less efficient for the decoder.
  924. * \param tell_callback See FLAC__StreamDecoderTellCallback. This
  925. * pointer may be \c NULL if not supported by the client. If
  926. * \a seek_callback is not \c NULL then a
  927. * \a tell_callback must also be supplied.
  928. * Alternatively, a dummy tell callback that just
  929. * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  930. * may also be supplied, all though this is slightly
  931. * less efficient for the decoder.
  932. * \param length_callback See FLAC__StreamDecoderLengthCallback. This
  933. * pointer may be \c NULL if not supported by the client. If
  934. * \a seek_callback is not \c NULL then a
  935. * \a length_callback must also be supplied.
  936. * Alternatively, a dummy length callback that just
  937. * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  938. * may also be supplied, all though this is slightly
  939. * less efficient for the decoder.
  940. * \param eof_callback See FLAC__StreamDecoderEofCallback. This
  941. * pointer may be \c NULL if not supported by the client. If
  942. * \a seek_callback is not \c NULL then a
  943. * \a eof_callback must also be supplied.
  944. * Alternatively, a dummy length callback that just
  945. * returns \c false
  946. * may also be supplied, all though this is slightly
  947. * less efficient for the decoder.
  948. * \param write_callback See FLAC__StreamDecoderWriteCallback. This
  949. * pointer must not be \c NULL.
  950. * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
  951. * pointer may be \c NULL if the callback is not
  952. * desired.
  953. * \param error_callback See FLAC__StreamDecoderErrorCallback. This
  954. * pointer must not be \c NULL.
  955. * \param client_data This value will be supplied to callbacks in their
  956. * \a client_data argument.
  957. * \assert
  958. * \code decoder != NULL \endcode
  959. * \retval FLAC__StreamDecoderInitStatus
  960. * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful;
  961. * see FLAC__StreamDecoderInitStatus for the meanings of other return values.
  962. */
  963. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  964. FLAC__StreamDecoder *decoder,
  965. FLAC__StreamDecoderReadCallback read_callback,
  966. FLAC__StreamDecoderSeekCallback seek_callback,
  967. FLAC__StreamDecoderTellCallback tell_callback,
  968. FLAC__StreamDecoderLengthCallback length_callback,
  969. FLAC__StreamDecoderEofCallback eof_callback,
  970. FLAC__StreamDecoderWriteCallback write_callback,
  971. FLAC__StreamDecoderMetadataCallback metadata_callback,
  972. FLAC__StreamDecoderErrorCallback error_callback,
  973. void *client_data
  974. );
  975. /** Initialize the decoder instance to decode Ogg FLAC streams.
  976. *
  977. * This flavor of initialization sets up the decoder to decode from a
  978. * FLAC stream in an Ogg container. I/O is performed via callbacks to the
  979. * client. For decoding from a plain file via filename or open FILE*,
  980. * FLAC__stream_decoder_init_ogg_file() and FLAC__stream_decoder_init_ogg_FILE()
  981. * provide a simpler interface.
  982. *
  983. * This function should be called after FLAC__stream_decoder_new() and
  984. * FLAC__stream_decoder_set_*() but before any of the
  985. * FLAC__stream_decoder_process_*() functions. Will set and return the
  986. * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
  987. * if initialization succeeded.
  988. *
  989. * \note Support for Ogg FLAC in the library is optional. If this
  990. * library has been built without support for Ogg FLAC, this function
  991. * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER.
  992. *
  993. * \param decoder An uninitialized decoder instance.
  994. * \param read_callback See FLAC__StreamDecoderReadCallback. This
  995. * pointer must not be \c NULL.
  996. * \param seek_callback See FLAC__StreamDecoderSeekCallback. This
  997. * pointer may be \c NULL if seeking is not
  998. * supported. If \a seek_callback is not \c NULL then a
  999. * \a tell_callback, \a length_callback, and \a eof_callback must also be supplied.
  1000. * Alternatively, a dummy seek callback that just
  1001. * returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  1002. * may also be supplied, all though this is slightly
  1003. * less efficient for the decoder.
  1004. * \param tell_callback See FLAC__StreamDecoderTellCallback. This
  1005. * pointer may be \c NULL if not supported by the client. If
  1006. * \a seek_callback is not \c NULL then a
  1007. * \a tell_callback must also be supplied.
  1008. * Alternatively, a dummy tell callback that just
  1009. * returns \c FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  1010. * may also be supplied, all though this is slightly
  1011. * less efficient for the decoder.
  1012. * \param length_callback See FLAC__StreamDecoderLengthCallback. This
  1013. * pointer may be \c NULL if not supported by the client. If
  1014. * \a seek_callback is not \c NULL then a
  1015. * \a length_callback must also be supplied.
  1016. * Alternatively, a dummy length callback that just
  1017. * returns \c FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  1018. * may also be supplied, all though this is slightly
  1019. * less efficient for the decoder.
  1020. * \param eof_callback See FLAC__StreamDecoderEofCallback. This
  1021. * pointer may be \c NULL if not supported by the client. If
  1022. * \a seek_callback is not \c NULL then a
  1023. * \a eof_callback must also be supplied.
  1024. * Alternatively, a dummy length callback that just
  1025. * returns \c false
  1026. * may also be supplied, all though this is slightly
  1027. * less efficient for the decoder.
  1028. * \param write_callback See FLAC__StreamDecoderWriteCallback. This
  1029. * pointer must not be \c NULL.
  1030. * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
  1031. * pointer may be \c NULL if the callback is not
  1032. * desired.
  1033. * \param error_callback See FLAC__StreamDecoderErrorCallback. This
  1034. * pointer must not be \c NULL.
  1035. * \param client_data This value will be supplied to callbacks in their
  1036. * \a client_data argument.
  1037. * \assert
  1038. * \code decoder != NULL \endcode
  1039. * \retval FLAC__StreamDecoderInitStatus
  1040. * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful;
  1041. * see FLAC__StreamDecoderInitStatus for the meanings of other return values.
  1042. */
  1043. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  1044. FLAC__StreamDecoder *decoder,
  1045. FLAC__StreamDecoderReadCallback read_callback,
  1046. FLAC__StreamDecoderSeekCallback seek_callback,
  1047. FLAC__StreamDecoderTellCallback tell_callback,
  1048. FLAC__StreamDecoderLengthCallback length_callback,
  1049. FLAC__StreamDecoderEofCallback eof_callback,
  1050. FLAC__StreamDecoderWriteCallback write_callback,
  1051. FLAC__StreamDecoderMetadataCallback metadata_callback,
  1052. FLAC__StreamDecoderErrorCallback error_callback,
  1053. void *client_data
  1054. );
  1055. /** Initialize the decoder instance to decode native FLAC files.
  1056. *
  1057. * This flavor of initialization sets up the decoder to decode from a
  1058. * plain native FLAC file. For non-stdio streams, you must use
  1059. * FLAC__stream_decoder_init_stream() and provide callbacks for the I/O.
  1060. *
  1061. * This function should be called after FLAC__stream_decoder_new() and
  1062. * FLAC__stream_decoder_set_*() but before any of the
  1063. * FLAC__stream_decoder_process_*() functions. Will set and return the
  1064. * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
  1065. * if initialization succeeded.
  1066. *
  1067. * \param decoder An uninitialized decoder instance.
  1068. * \param file An open FLAC file. The file should have been
  1069. * opened with mode \c "rb" and rewound. The file
  1070. * becomes owned by the decoder and should not be
  1071. * manipulated by the client while decoding.
  1072. * Unless \a file is \c stdin, it will be closed
  1073. * when FLAC__stream_decoder_finish() is called.
  1074. * Note however that seeking will not work when
  1075. * decoding from \c stdout since it is not seekable.
  1076. * \param write_callback See FLAC__StreamDecoderWriteCallback. This
  1077. * pointer must not be \c NULL.
  1078. * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
  1079. * pointer may be \c NULL if the callback is not
  1080. * desired.
  1081. * \param error_callback See FLAC__StreamDecoderErrorCallback. This
  1082. * pointer must not be \c NULL.
  1083. * \param client_data This value will be supplied to callbacks in their
  1084. * \a client_data argument.
  1085. * \assert
  1086. * \code decoder != NULL \endcode
  1087. * \code file != NULL \endcode
  1088. * \retval FLAC__StreamDecoderInitStatus
  1089. * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful;
  1090. * see FLAC__StreamDecoderInitStatus for the meanings of other return values.
  1091. */
  1092. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  1093. FLAC__StreamDecoder *decoder,
  1094. FILE *file,
  1095. FLAC__StreamDecoderWriteCallback write_callback,
  1096. FLAC__StreamDecoderMetadataCallback metadata_callback,
  1097. FLAC__StreamDecoderErrorCallback error_callback,
  1098. void *client_data
  1099. );
  1100. /** Initialize the decoder instance to decode Ogg FLAC files.
  1101. *
  1102. * This flavor of initialization sets up the decoder to decode from a
  1103. * plain Ogg FLAC file. For non-stdio streams, you must use
  1104. * FLAC__stream_decoder_init_ogg_stream() and provide callbacks for the I/O.
  1105. *
  1106. * This function should be called after FLAC__stream_decoder_new() and
  1107. * FLAC__stream_decoder_set_*() but before any of the
  1108. * FLAC__stream_decoder_process_*() functions. Will set and return the
  1109. * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
  1110. * if initialization succeeded.
  1111. *
  1112. * \note Support for Ogg FLAC in the library is optional. If this
  1113. * library has been built without support for Ogg FLAC, this function
  1114. * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER.
  1115. *
  1116. * \param decoder An uninitialized decoder instance.
  1117. * \param file An open FLAC file. The file should have been
  1118. * opened with mode \c "rb" and rewound. The file
  1119. * becomes owned by the decoder and should not be
  1120. * manipulated by the client while decoding.
  1121. * Unless \a file is \c stdin, it will be closed
  1122. * when FLAC__stream_decoder_finish() is called.
  1123. * Note however that seeking will not work when
  1124. * decoding from \c stdout since it is not seekable.
  1125. * \param write_callback See FLAC__StreamDecoderWriteCallback. This
  1126. * pointer must not be \c NULL.
  1127. * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
  1128. * pointer may be \c NULL if the callback is not
  1129. * desired.
  1130. * \param error_callback See FLAC__StreamDecoderErrorCallback. This
  1131. * pointer must not be \c NULL.
  1132. * \param client_data This value will be supplied to callbacks in their
  1133. * \a client_data argument.
  1134. * \assert
  1135. * \code decoder != NULL \endcode
  1136. * \code file != NULL \endcode
  1137. * \retval FLAC__StreamDecoderInitStatus
  1138. * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful;
  1139. * see FLAC__StreamDecoderInitStatus for the meanings of other return values.
  1140. */
  1141. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  1142. FLAC__StreamDecoder *decoder,
  1143. FILE *file,
  1144. FLAC__StreamDecoderWriteCallback write_callback,
  1145. FLAC__StreamDecoderMetadataCallback metadata_callback,
  1146. FLAC__StreamDecoderErrorCallback error_callback,
  1147. void *client_data
  1148. );
  1149. /** Initialize the decoder instance to decode native FLAC files.
  1150. *
  1151. * This flavor of initialization sets up the decoder to decode from a plain
  1152. * native FLAC file. If POSIX fopen() semantics are not sufficient, (for
  1153. * example, with Unicode filenames on Windows), you must use
  1154. * FLAC__stream_decoder_init_FILE(), or FLAC__stream_decoder_init_stream()
  1155. * and provide callbacks for the I/O.
  1156. *
  1157. * This function should be called after FLAC__stream_decoder_new() and
  1158. * FLAC__stream_decoder_set_*() but before any of the
  1159. * FLAC__stream_decoder_process_*() functions. Will set and return the
  1160. * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
  1161. * if initialization succeeded.
  1162. *
  1163. * \param decoder An uninitialized decoder instance.
  1164. * \param filename The name of the file to decode from. The file will
  1165. * be opened with fopen(). Use \c NULL to decode from
  1166. * \c stdin. Note that \c stdin is not seekable.
  1167. * \param write_callback See FLAC__StreamDecoderWriteCallback. This
  1168. * pointer must not be \c NULL.
  1169. * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
  1170. * pointer may be \c NULL if the callback is not
  1171. * desired.
  1172. * \param error_callback See FLAC__StreamDecoderErrorCallback. This
  1173. * pointer must not be \c NULL.
  1174. * \param client_data This value will be supplied to callbacks in their
  1175. * \a client_data argument.
  1176. * \assert
  1177. * \code decoder != NULL \endcode
  1178. * \retval FLAC__StreamDecoderInitStatus
  1179. * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful;
  1180. * see FLAC__StreamDecoderInitStatus for the meanings of other return values.
  1181. */
  1182. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  1183. FLAC__StreamDecoder *decoder,
  1184. const char *filename,
  1185. FLAC__StreamDecoderWriteCallback write_callback,
  1186. FLAC__StreamDecoderMetadataCallback metadata_callback,
  1187. FLAC__StreamDecoderErrorCallback error_callback,
  1188. void *client_data
  1189. );
  1190. /** Initialize the decoder instance to decode Ogg FLAC files.
  1191. *
  1192. * This flavor of initialization sets up the decoder to decode from a plain
  1193. * Ogg FLAC file. If POSIX fopen() semantics are not sufficient, (for
  1194. * example, with Unicode filenames on Windows), you must use
  1195. * FLAC__stream_decoder_init_ogg_FILE(), or FLAC__stream_decoder_init_ogg_stream()
  1196. * and provide callbacks for the I/O.
  1197. *
  1198. * This function should be called after FLAC__stream_decoder_new() and
  1199. * FLAC__stream_decoder_set_*() but before any of the
  1200. * FLAC__stream_decoder_process_*() functions. Will set and return the
  1201. * decoder state, which will be FLAC__STREAM_DECODER_SEARCH_FOR_METADATA
  1202. * if initialization succeeded.
  1203. *
  1204. * \note Support for Ogg FLAC in the library is optional. If this
  1205. * library has been built without support for Ogg FLAC, this function
  1206. * will return \c FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER.
  1207. *
  1208. * \param decoder An uninitialized decoder instance.
  1209. * \param filename The name of the file to decode from. The file will
  1210. * be opened with fopen(). Use \c NULL to decode from
  1211. * \c stdin. Note that \c stdin is not seekable.
  1212. * \param write_callback See FLAC__StreamDecoderWriteCallback. This
  1213. * pointer must not be \c NULL.
  1214. * \param metadata_callback See FLAC__StreamDecoderMetadataCallback. This
  1215. * pointer may be \c NULL if the callback is not
  1216. * desired.
  1217. * \param error_callback See FLAC__StreamDecoderErrorCallback. This
  1218. * pointer must not be \c NULL.
  1219. * \param client_data This value will be supplied to callbacks in their
  1220. * \a client_data argument.
  1221. * \assert
  1222. * \code decoder != NULL \endcode
  1223. * \retval FLAC__StreamDecoderInitStatus
  1224. * \c FLAC__STREAM_DECODER_INIT_STATUS_OK if initialization was successful;
  1225. * see FLAC__StreamDecoderInitStatus for the meanings of other return values.
  1226. */
  1227. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  1228. FLAC__StreamDecoder *decoder,
  1229. const char *filename,
  1230. FLAC__StreamDecoderWriteCallback write_callback,
  1231. FLAC__StreamDecoderMetadataCallback metadata_callback,
  1232. FLAC__StreamDecoderErrorCallback error_callback,
  1233. void *client_data
  1234. );
  1235. /** Finish the decoding process.
  1236. * Flushes the decoding buffer, releases resources, resets the decoder
  1237. * settings to their defaults, and returns the decoder state to
  1238. * FLAC__STREAM_DECODER_UNINITIALIZED.
  1239. *
  1240. * In the event of a prematurely-terminated decode, it is not strictly
  1241. * necessary to call this immediately before FLAC__stream_decoder_delete()
  1242. * but it is good practice to match every FLAC__stream_decoder_init_*()
  1243. * with a FLAC__stream_decoder_finish().
  1244. *
  1245. * \param decoder An uninitialized decoder instance.
  1246. * \assert
  1247. * \code decoder != NULL \endcode
  1248. * \retval FLAC__bool
  1249. * \c false if MD5 checking is on AND a STREAMINFO block was available
  1250. * AND the MD5 signature in the STREAMINFO block was non-zero AND the
  1251. * signature does not match the one computed by the decoder; else
  1252. * \c true.
  1253. */
  1254. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  1255. /** Flush the stream input.
  1256. * The decoder's input buffer will be cleared and the state set to
  1257. * \c FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC. This will also turn
  1258. * off MD5 checking.
  1259. *
  1260. * \param decoder A decoder instance.
  1261. * \assert
  1262. * \code decoder != NULL \endcode
  1263. * \retval FLAC__bool
  1264. * \c true if successful, else \c false if a memory allocation
  1265. * error occurs (in which case the state will be set to
  1266. * \c FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR).
  1267. */
  1268. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  1269. /** Reset the decoding process.
  1270. * The decoder's input buffer will be cleared and the state set to
  1271. * \c FLAC__STREAM_DECODER_SEARCH_FOR_METADATA. This is similar to
  1272. * FLAC__stream_decoder_finish() except that the settings are
  1273. * preserved; there is no need to call FLAC__stream_decoder_init_*()
  1274. * before decoding again. MD5 checking will be restored to its original
  1275. * setting.
  1276. *
  1277. * If the decoder is seekable, or was initialized with
  1278. * FLAC__stream_decoder_init*_FILE() or FLAC__stream_decoder_init*_file(),
  1279. * the decoder will also attempt to seek to the beginning of the file.
  1280. * If this rewind fails, this function will return \c false. It follows
  1281. * that FLAC__stream_decoder_reset() cannot be used when decoding from
  1282. * \c stdin.
  1283. *
  1284. * If the decoder was initialized with FLAC__stream_encoder_init*_stream()
  1285. * and is not seekable (i.e. no seek callback was provided or the seek
  1286. * callback returns \c FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED), it
  1287. * is the duty of the client to start feeding data from the beginning of
  1288. * the stream on the next FLAC__stream_decoder_process() or
  1289. * FLAC__stream_decoder_process_interleaved() call.
  1290. *
  1291. * \param decoder A decoder instance.
  1292. * \assert
  1293. * \code decoder != NULL \endcode
  1294. * \retval FLAC__bool
  1295. * \c true if successful, else \c false if a memory allocation occurs
  1296. * (in which case the state will be set to
  1297. * \c FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR) or a seek error
  1298. * occurs (the state will be unchanged).
  1299. */
  1300. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  1301. /** Decode one metadata block or audio frame.
  1302. * This version instructs the decoder to decode a either a single metadata
  1303. * block or a single frame and stop, unless the callbacks return a fatal
  1304. * error or the read callback returns
  1305. * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM.
  1306. *
  1307. * As the decoder needs more input it will call the read callback.
  1308. * Depending on what was decoded, the metadata or write callback will be
  1309. * called with the decoded metadata block or audio frame.
  1310. *
  1311. * Unless there is a fatal read error or end of stream, this function
  1312. * will return once one whole frame is decoded. In other words, if the
  1313. * stream is not synchronized or points to a corrupt frame header, the
  1314. * decoder will continue to try and resync until it gets to a valid
  1315. * frame, then decode one frame, then return. If the decoder points to
  1316. * a frame whose frame CRC in the frame footer does not match the
  1317. * computed frame CRC, this function will issue a
  1318. * FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH error to the
  1319. * error callback, and return, having decoded one complete, although
  1320. * corrupt, frame. (Such corrupted frames are sent as silence of the
  1321. * correct length to the write callback.)
  1322. *
  1323. * \param decoder An initialized decoder instance.
  1324. * \assert
  1325. * \code decoder != NULL \endcode
  1326. * \retval FLAC__bool
  1327. * \c false if any fatal read, write, or memory allocation error
  1328. * occurred (meaning decoding must stop), else \c true; for more
  1329. * information about the decoder, check the decoder state with
  1330. * FLAC__stream_decoder_get_state().
  1331. */
  1332. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  1333. /** Decode until the end of the metadata.
  1334. * This version instructs the decoder to decode from the current position
  1335. * and continue until all the metadata has been read, or until the
  1336. * callbacks return a fatal error or the read callback returns
  1337. * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM.
  1338. *
  1339. * As the decoder needs more input it will call the read callback.
  1340. * As each metadata block is decoded, the metadata callback will be called
  1341. * with the decoded metadata.
  1342. *
  1343. * \param decoder An initialized decoder instance.
  1344. * \assert
  1345. * \code decoder != NULL \endcode
  1346. * \retval FLAC__bool
  1347. * \c false if any fatal read, write, or memory allocation error
  1348. * occurred (meaning decoding must stop), else \c true; for more
  1349. * information about the decoder, check the decoder state with
  1350. * FLAC__stream_decoder_get_state().
  1351. */
  1352. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  1353. /** Decode until the end of the stream.
  1354. * This version instructs the decoder to decode from the current position
  1355. * and continue until the end of stream (the read callback returns
  1356. * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM), or until the
  1357. * callbacks return a fatal error.
  1358. *
  1359. * As the decoder needs more input it will call the read callback.
  1360. * As each metadata block and frame is decoded, the metadata or write
  1361. * callback will be called with the decoded metadata or frame.
  1362. *
  1363. * \param decoder An initialized decoder instance.
  1364. * \assert
  1365. * \code decoder != NULL \endcode
  1366. * \retval FLAC__bool
  1367. * \c false if any fatal read, write, or memory allocation error
  1368. * occurred (meaning decoding must stop), else \c true; for more
  1369. * information about the decoder, check the decoder state with
  1370. * FLAC__stream_decoder_get_state().
  1371. */
  1372. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  1373. /** Skip one audio frame.
  1374. * This version instructs the decoder to 'skip' a single frame and stop,
  1375. * unless the callbacks return a fatal error or the read callback returns
  1376. * \c FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM.
  1377. *
  1378. * The decoding flow is the same as what occurs when
  1379. * FLAC__stream_decoder_process_single() is called to process an audio
  1380. * frame, except that this function does not decode the parsed data into
  1381. * PCM or call the write callback. The integrity of the frame is still
  1382. * checked the same way as in the other process functions.
  1383. *
  1384. * This function will return once one whole frame is skipped, in the
  1385. * same way that FLAC__stream_decoder_process_single() will return once
  1386. * one whole frame is decoded.
  1387. *
  1388. * This function can be used in more quickly determining FLAC frame
  1389. * boundaries when decoding of the actual data is not needed, for
  1390. * example when an application is separating a FLAC stream into frames
  1391. * for editing or storing in a container. To do this, the application
  1392. * can use FLAC__stream_decoder_skip_single_frame() to quickly advance
  1393. * to the next frame, then use
  1394. * FLAC__stream_decoder_get_decode_position() to find the new frame
  1395. * boundary.
  1396. *
  1397. * This function should only be called when the stream has advanced
  1398. * past all the metadata, otherwise it will return \c false.
  1399. *
  1400. * \param decoder An initialized decoder instance not in a metadata
  1401. * state.
  1402. * \assert
  1403. * \code decoder != NULL \endcode
  1404. * \retval FLAC__bool
  1405. * \c false if any fatal read, write, or memory allocation error
  1406. * occurred (meaning decoding must stop), or if the decoder
  1407. * is in the FLAC__STREAM_DECODER_SEARCH_FOR_METADATA or
  1408. * FLAC__STREAM_DECODER_READ_METADATA state, else \c true; for more
  1409. * information about the decoder, check the decoder state with
  1410. * FLAC__stream_decoder_get_state().
  1411. */
  1412. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  1413. /** Flush the input and seek to an absolute sample.
  1414. * Decoding will resume at the given sample. Note that because of
  1415. * this, the next write callback may contain a partial block. The
  1416. * client must support seeking the input or this function will fail
  1417. * and return \c false. Furthermore, if the decoder state is
  1418. * \c FLAC__STREAM_DECODER_SEEK_ERROR, then the decoder must be flushed
  1419. * with FLAC__stream_decoder_flush() or reset with
  1420. * FLAC__stream_decoder_reset() before decoding can continue.
  1421. *
  1422. * \param decoder A decoder instance.
  1423. * \param sample The target sample number to seek to.
  1424. * \assert
  1425. * \code decoder != NULL \endcode
  1426. * \retval FLAC__bool
  1427. * \c true if successful, else \c false.
  1428. */
  1429. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  1430. /* \} */
  1431. #ifdef __cplusplus
  1432. }
  1433. #endif
  1434. #endif