annotate osx/include/FLAC/stream_decoder.h @ 134:41e769c91eca

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