annotate src/flac-1.2.1/include/FLAC/stream_decoder.h @ 93:5fcdb63f4cc6

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