stream_decoder.h 69 KB

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