1 /* libOggFLAC - Free Lossless Audio Codec + Ogg library
2 * Copyright (C) 2002 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifndef OggFLAC__SEEKABLE_STREAM_DECODER_H
21 #define OggFLAC__SEEKABLE_STREAM_DECODER_H
23 #include "FLAC/seekable_stream_decoder.h"
30 /** \file include/OggFLAC/seekable_stream_decoder.h
33 * This module contains the functions which implement the seekable stream
36 * See the detailed documentation in the
37 * \link oggflac_seekable_stream_decoder seekable stream decoder \endlink module.
40 /** \defgroup oggflac_seekable_stream_decoder OggFLAC/seekable_stream_decoder.h: seekable stream decoder interface
41 * \ingroup oggflac_decoder
44 * This module contains the functions which implement the seekable stream
47 * The interface here is identical to FLAC's seekable stream decoder. See the
48 * defaults, including the callbacks. See the \link flac_seekable_stream_decoder
49 * FLAC seekable stream decoder module \endlink for full documentation.
55 /** State values for an OggFLAC__SeekableStreamDecoder
57 * The decoder's state can be obtained by calling OggFLAC__seekable_stream_decoder_get_state().
61 OggFLAC__SEEKABLE_STREAM_DECODER_OK = 0,
62 /**< The decoder is in the normal OK state. */
64 OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR,
65 /**< An error occurred in the underlying FLAC seekable stream decoder;
66 * check OggFLAC__seekable_stream_decoder_get_FLAC_seekable_stream_decoder_state().
69 OggFLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK,
70 /**< The decoder was initialized before setting all the required callbacks. */
72 OggFLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
73 /**< Memory allocation failed. */
75 OggFLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED,
76 /**< OggFLAC__seekable_stream_decoder_init() was called when the decoder was
77 * already initialized, usually because
78 * OggFLAC__seekable_stream_decoder_finish() was not called.
81 OggFLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED
82 /**< The decoder is in the uninitialized state. */
84 } OggFLAC__SeekableStreamDecoderState;
86 /** Maps an OggFLAC__SeekableStreamDecoderState to a C string.
88 * Using an OggFLAC__SeekableStreamDecoderState as the index to this array
89 * will give the string equivalent. The contents should not be modified.
91 extern const char * const OggFLAC__SeekableStreamDecoderStateString[];
94 /***********************************************************************
96 * class OggFLAC__SeekableStreamDecoder : public FLAC__StreamDecoder
98 ***********************************************************************/
100 struct OggFLAC__SeekableStreamDecoderProtected;
101 struct OggFLAC__SeekableStreamDecoderPrivate;
102 /** The opaque structure definition for the seekable stream decoder type.
104 * \link oggflac_seekable_stream_decoder seekable stream decoder module \endlink
105 * for a detailed description.
108 struct OggFLAC__SeekableStreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
109 struct OggFLAC__SeekableStreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
110 } OggFLAC__SeekableStreamDecoder;
113 typedef FLAC__SeekableStreamDecoderReadStatus (*OggFLAC__SeekableStreamDecoderReadCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data);
114 typedef FLAC__SeekableStreamDecoderSeekStatus (*OggFLAC__SeekableStreamDecoderSeekCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
115 typedef FLAC__SeekableStreamDecoderTellStatus (*OggFLAC__SeekableStreamDecoderTellCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
116 typedef FLAC__SeekableStreamDecoderLengthStatus (*OggFLAC__SeekableStreamDecoderLengthCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
117 typedef FLAC__bool (*OggFLAC__SeekableStreamDecoderEofCallback)(const OggFLAC__SeekableStreamDecoder *decoder, void *client_data);
118 typedef FLAC__StreamDecoderWriteStatus (*OggFLAC__SeekableStreamDecoderWriteCallback)(const OggFLAC__SeekableStreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
119 typedef void (*OggFLAC__SeekableStreamDecoderMetadataCallback)(const OggFLAC__SeekableStreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
120 typedef void (*OggFLAC__SeekableStreamDecoderErrorCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
123 /***********************************************************************
125 * Class constructor/destructor
127 ***********************************************************************/
129 /** Create a new seekable stream decoder instance. The instance is created
130 * with default settings; see the individual
131 * OggFLAC__seekable_stream_decoder_set_*() functions for each setting's
134 * \retval OggFLAC__SeekableStreamDecoder*
135 * \c NULL if there was an error allocating memory, else the new instance.
137 OggFLAC__SeekableStreamDecoder *OggFLAC__seekable_stream_decoder_new();
139 /** Free a decoder instance. Deletes the object pointed to by \a decoder.
141 * \param decoder A pointer to an existing decoder.
143 * \code decoder != NULL \endcode
145 void OggFLAC__seekable_stream_decoder_delete(OggFLAC__SeekableStreamDecoder *decoder);
148 /***********************************************************************
150 * Public class method prototypes
152 ***********************************************************************/
154 /*@@@inherit set_serial_number*/
156 /** Set the "MD5 signature checking" flag.
157 * This is inherited from FLAC__SeekableStreamDecoder; see
158 * FLAC__seekable_stream_decoder_set_md5_checking().
161 * \param decoder A decoder instance to set.
162 * \param value Flag value (see above).
164 * \code decoder != NULL \endcode
166 * \c false if the decoder is already initialized, else \c true.
168 FLAC__bool OggFLAC__seekable_stream_decoder_set_md5_checking(OggFLAC__SeekableStreamDecoder *decoder, FLAC__bool value);
170 /** Set the read callback.
171 * This is inherited from FLAC__SeekableStreamDecoder; see
172 * FLAC__seekable_stream_decoder_set_read_callback().
175 * The callback is mandatory and must be set before initialization.
178 * \param decoder A decoder instance to set.
179 * \param value See above.
181 * \code decoder != NULL \endcode
182 * \code value != NULL \endcode
184 * \c false if the decoder is already initialized, else \c true.
186 FLAC__bool OggFLAC__seekable_stream_decoder_set_read_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderReadCallback value);
188 /** Set the seek callback.
189 * This is inherited from FLAC__SeekableStreamDecoder; see
190 * FLAC__seekable_stream_decoder_set_seek_callback().
193 * The callback is mandatory and must be set before initialization.
196 * \param decoder A decoder instance to set.
197 * \param value See above.
199 * \code decoder != NULL \endcode
200 * \code value != NULL \endcode
202 * \c false if the decoder is already initialized, else \c true.
204 FLAC__bool OggFLAC__seekable_stream_decoder_set_seek_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderSeekCallback value);
206 /** Set the tell callback.
207 * This is inherited from FLAC__SeekableStreamDecoder; see
208 * FLAC__seekable_stream_decoder_set_tell_callback().
211 * The callback is mandatory and must be set before initialization.
214 * \param decoder A decoder instance to set.
215 * \param value See above.
217 * \code decoder != NULL \endcode
218 * \code value != NULL \endcode
220 * \c false if the decoder is already initialized, else \c true.
222 FLAC__bool OggFLAC__seekable_stream_decoder_set_tell_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderTellCallback value);
224 /** Set the length callback.
225 * This is inherited from FLAC__SeekableStreamDecoder; see
226 * FLAC__seekable_stream_decoder_set_length_callback().
229 * The callback is mandatory and must be set before initialization.
232 * \param decoder A decoder instance to set.
233 * \param value See above.
235 * \code decoder != NULL \endcode
236 * \code value != NULL \endcode
238 * \c false if the decoder is already initialized, else \c true.
240 FLAC__bool OggFLAC__seekable_stream_decoder_set_length_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderLengthCallback value);
242 /** Set the eof callback.
243 * This is inherited from FLAC__SeekableStreamDecoder; see
244 * FLAC__seekable_stream_decoder_set_eof_callback().
247 * The callback is mandatory and must be set before initialization.
250 * \param decoder A decoder instance to set.
251 * \param value See above.
253 * \code decoder != NULL \endcode
254 * \code value != NULL \endcode
256 * \c false if the decoder is already initialized, else \c true.
258 FLAC__bool OggFLAC__seekable_stream_decoder_set_eof_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderEofCallback value);
260 /** Set the write callback.
261 * This is inherited from FLAC__SeekableStreamDecoder; see
262 * FLAC__seekable_stream_decoder_set_write_callback().
265 * The callback is mandatory and must be set before initialization.
268 * \param decoder A decoder instance to set.
269 * \param value See above.
271 * \code decoder != NULL \endcode
272 * \code value != NULL \endcode
274 * \c false if the decoder is already initialized, else \c true.
276 FLAC__bool OggFLAC__seekable_stream_decoder_set_write_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderWriteCallback value);
278 /** Set the metadata callback.
279 * This is inherited from FLAC__SeekableStreamDecoder; see
280 * FLAC__seekable_stream_decoder_set_metadata_callback().
283 * The callback is mandatory and must be set before initialization.
286 * \param decoder A decoder instance to set.
287 * \param value See above.
289 * \code decoder != NULL \endcode
290 * \code value != NULL \endcode
292 * \c false if the decoder is already initialized, else \c true.
294 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderMetadataCallback value);
296 /** Set the error callback.
297 * This is inherited from FLAC__SeekableStreamDecoder; see
298 * FLAC__seekable_stream_decoder_set_error_callback().
301 * The callback is mandatory and must be set before initialization.
304 * \param decoder A decoder instance to set.
305 * \param value See above.
307 * \code decoder != NULL \endcode
308 * \code value != NULL \endcode
310 * \c false if the decoder is already initialized, else \c true.
312 FLAC__bool OggFLAC__seekable_stream_decoder_set_error_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderErrorCallback value);
314 /** Set the client data to be passed back to callbacks.
315 * This value will be supplied to callbacks in their \a client_data
319 * \param decoder A decoder instance to set.
320 * \param value See above.
322 * \code decoder != NULL \endcode
324 * \c false if the decoder is already initialized, else \c true.
326 FLAC__bool OggFLAC__seekable_stream_decoder_set_client_data(OggFLAC__SeekableStreamDecoder *decoder, void *value);
328 /** This is inherited from FLAC__SeekableStreamDecoder; see
329 * FLAC__seekable_stream_decoder_set_metadata_respond().
331 * \default By default, only the \c STREAMINFO block is returned via the
333 * \param decoder A decoder instance to set.
334 * \param type See above.
336 * \code decoder != NULL \endcode
339 * \c false if the decoder is already initialized, else \c true.
341 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_respond(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__MetadataType type);
343 /** This is inherited from FLAC__SeekableStreamDecoder; see
344 * FLAC__seekable_stream_decoder_set_metadata_respond_application().
346 * \default By default, only the \c STREAMINFO block is returned via the
348 * \param decoder A decoder instance to set.
349 * \param id See above.
351 * \code decoder != NULL \endcode
352 * \code id != NULL \endcode
354 * \c false if the decoder is already initialized, else \c true.
356 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_respond_application(OggFLAC__SeekableStreamDecoder *decoder, const FLAC__byte id[4]);
358 /** This is inherited from FLAC__SeekableStreamDecoder; see
359 * FLAC__seekable_stream_decoder_set_metadata_respond_all().
361 * \default By default, only the \c STREAMINFO block is returned via the
363 * \param decoder A decoder instance to set.
365 * \code decoder != NULL \endcode
367 * \c false if the decoder is already initialized, else \c true.
369 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_respond_all(OggFLAC__SeekableStreamDecoder *decoder);
371 /** This is inherited from FLAC__SeekableStreamDecoder; see
372 * FLAC__seekable_stream_decoder_set_metadata_ignore().
374 * \default By default, only the \c STREAMINFO block is returned via the
376 * \param decoder A decoder instance to set.
377 * \param type See above.
379 * \code decoder != NULL \endcode
382 * \c false if the decoder is already initialized, else \c true.
384 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__MetadataType type);
386 /** This is inherited from FLAC__SeekableStreamDecoder; see
387 * FLAC__seekable_stream_decoder_set_metadata_ignore_application().
389 * \default By default, only the \c STREAMINFO block is returned via the
391 * \param decoder A decoder instance to set.
392 * \param id See above.
394 * \code decoder != NULL \endcode
395 * \code id != NULL \endcode
397 * \c false if the decoder is already initialized, else \c true.
399 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(OggFLAC__SeekableStreamDecoder *decoder, const FLAC__byte id[4]);
401 /** This is inherited from FLAC__SeekableStreamDecoder; see
402 * FLAC__seekable_stream_decoder_set_metadata_ignore_all().
404 * \default By default, only the \c STREAMINFO block is returned via the
406 * \param decoder A decoder instance to set.
408 * \code decoder != NULL \endcode
410 * \c false if the decoder is already initialized, else \c true.
412 FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(OggFLAC__SeekableStreamDecoder *decoder);
414 /** Get the current decoder state.
416 * \param decoder A decoder instance to query.
418 * \code decoder != NULL \endcode
419 * \retval OggFLAC__SeekableStreamDecoderState
420 * The current decoder state.
422 OggFLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_get_state(const OggFLAC__SeekableStreamDecoder *decoder);
424 /** Get the state of the underlying FLAC seekable stream decoder.
425 * Useful when the seekable stream decoder state is
426 * \c OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR.
428 * \param decoder A decoder instance to query.
430 * \code decoder != NULL \endcode
431 * \retval FLAC__SeekableStreamDecoderState
432 * The FLAC seekable stream decoder state.
434 FLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_get_FLAC_seekable_stream_decoder_state(const OggFLAC__SeekableStreamDecoder *decoder);
436 /** Get the state of the underlying FLAC seekable stream decoder's stream decoder.
437 * Useful when the seekable stream decoder state is
438 * \c OggFLAC__SEEKABLE_STREAM_DECODER_FLAC_SEEKABLE_STREAM_DECODER_ERROR and the
439 * FLAC seekable stream decoder state is \c FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR
441 * \param decoder A decoder instance to query.
443 * \code decoder != NULL \endcode
444 * \retval FLAC__StreamDecoderState
445 * The FLAC stream decoder state.
447 FLAC__StreamDecoderState OggFLAC__seekable_stream_decoder_get_FLAC_stream_decoder_state(const OggFLAC__SeekableStreamDecoder *decoder);
449 /** This is inherited from FLAC__SeekableStreamDecoder; see
450 * FLAC__seekable_stream_decoder_get_md5_checking().
452 * \param decoder A decoder instance to query.
454 * \code decoder != NULL \endcode
458 FLAC__bool OggFLAC__seekable_stream_decoder_get_md5_checking(const OggFLAC__SeekableStreamDecoder *decoder);
460 /** This is inherited from FLAC__SeekableStreamDecoder; see
461 * FLAC__seekable_stream_decoder_get_channels().
463 * \param decoder A decoder instance to query.
465 * \code decoder != NULL \endcode
469 unsigned OggFLAC__seekable_stream_decoder_get_channels(const OggFLAC__SeekableStreamDecoder *decoder);
471 /** This is inherited from FLAC__SeekableStreamDecoder; see
472 * FLAC__seekable_stream_decoder_get_channel_assignment().
474 * \param decoder A decoder instance to query.
476 * \code decoder != NULL \endcode
477 * \retval OggFLAC__ChannelAssignment
480 OggFLAC__ChannelAssignment OggFLAC__seekable_stream_decoder_get_channel_assignment(const OggFLAC__SeekableStreamDecoder *decoder);
482 /** This is inherited from FLAC__SeekableStreamDecoder; see
483 * FLAC__seekable_stream_decoder_get_bits_per_sample().
485 * \param decoder A decoder instance to query.
487 * \code decoder != NULL \endcode
491 unsigned OggFLAC__seekable_stream_decoder_get_bits_per_sample(const OggFLAC__SeekableStreamDecoder *decoder);
493 /** This is inherited from FLAC__SeekableStreamDecoder; see
494 * FLAC__seekable_stream_decoder_get_sample_rate().
496 * \param decoder A decoder instance to query.
498 * \code decoder != NULL \endcode
502 unsigned OggFLAC__seekable_stream_decoder_get_sample_rate(const OggFLAC__SeekableStreamDecoder *decoder);
504 /** This is inherited from FLAC__SeekableStreamDecoder; see
505 * FLAC__seekable_stream_decoder_get_blocksize().
507 * \param decoder A decoder instance to query.
509 * \code decoder != NULL \endcode
513 unsigned OggFLAC__seekable_stream_decoder_get_blocksize(const OggFLAC__SeekableStreamDecoder *decoder);
515 /** Initialize the decoder instance.
516 * Should be called after OggFLAC__seekable_stream_decoder_new() and
517 * OggFLAC__seekable_stream_decoder_set_*() but before any of the
518 * OggFLAC__seekable_stream_decoder_process_*() functions. Will set and return
519 * the decoder state, which will be OggFLAC__SEEKABLE_STREAM_DECODER_OK
520 * if initialization succeeded.
522 * \param decoder An uninitialized decoder instance.
524 * \code decoder != NULL \endcode
525 * \retval OggFLAC__SeekableStreamDecoderState
526 * \c OggFLAC__SEEKABLE_STREAM_DECODER_OK if initialization was
527 * successful; see OggFLAC__SeekableStreamDecoderState for the meanings
528 * of other return values.
530 OggFLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_init(OggFLAC__SeekableStreamDecoder *decoder);
532 /** Finish the decoding process.
533 * Flushes the decoding buffer, releases resources, resets the decoder
534 * settings to their defaults, and returns the decoder state to
535 * OggFLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED.
537 * In the event of a prematurely-terminated decode, it is not strictly
538 * necessary to call this immediately before
539 * OggFLAC__seekable_stream_decoder_delete() but it is good practice to match
540 * every OggFLAC__seekable_stream_decoder_init() with a
541 * OggFLAC__seekable_stream_decoder_finish().
543 * \param decoder An uninitialized decoder instance.
545 * \code decoder != NULL \endcode
547 * \c false if MD5 checking is on AND a STREAMINFO block was available
548 * AND the MD5 signature in the STREAMINFO block was non-zero AND the
549 * signature does not match the one computed by the decoder; else
552 FLAC__bool OggFLAC__seekable_stream_decoder_finish(OggFLAC__SeekableStreamDecoder *decoder);
554 /** This is inherited from FLAC__SeekableStreamDecoder; see
555 * FLAC__seekable_stream_decoder_flush().
557 * \param decoder A decoder instance.
559 * \code decoder != NULL \endcode
561 * \c true if successful, else \c false if a memory allocation
562 * or stream decoder error occurs.
564 FLAC__bool OggFLAC__seekable_stream_decoder_flush(OggFLAC__SeekableStreamDecoder *decoder);
566 /** This is inherited from FLAC__SeekableStreamDecoder; see
567 * FLAC__seekable_stream_decoder_reset().
569 * \param decoder A decoder instance.
571 * \code decoder != NULL \endcode
573 * \c true if successful, else \c false if a memory allocation
574 * or stream decoder error occurs.
576 FLAC__bool OggFLAC__seekable_stream_decoder_reset(OggFLAC__SeekableStreamDecoder *decoder);
578 /** This is inherited from FLAC__SeekableStreamDecoder; see
579 * FLAC__seekable_stream_decoder_process_single().
581 * \param decoder A decoder instance.
583 * \code decoder != NULL \endcode
587 FLAC__bool OggFLAC__seekable_stream_decoder_process_single(OggFLAC__SeekableStreamDecoder *decoder);
589 /** This is inherited from FLAC__SeekableStreamDecoder; see
590 * FLAC__seekable_stream_decoder_process_until_end_of_metadata().
592 * \param decoder A decoder instance.
594 * \code decoder != NULL \endcode
598 FLAC__bool OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(OggFLAC__SeekableStreamDecoder *decoder);
600 /** This is inherited from FLAC__SeekableStreamDecoder; see
601 * FLAC__seekable_stream_decoder_process_until_end_of_stream().
603 * \param decoder A decoder instance.
605 * \code decoder != NULL \endcode
609 FLAC__bool OggFLAC__seekable_stream_decoder_process_until_end_of_stream(OggFLAC__SeekableStreamDecoder *decoder);
611 /** This is inherited from FLAC__SeekableStreamDecoder; see
612 * FLAC__seekable_stream_decoder_seek_absolute().
614 * \param decoder A decoder instance.
615 * \param sample The target sample number to seek to.
617 * \code decoder != NULL \endcode
619 * \c true if successful, else \c false.
621 FLAC__bool OggFLAC__seekable_stream_decoder_seek_absolute(OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 sample);