annotate win64-mingw/include/FLAC/stream_decoder.h @ 122:62723f530572

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