annotate DEPENDENCIES/mingw32/include/FLAC/stream_decoder.h @ 133:4acb5d8d80b6 tip

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