From 27b53dcf5d90eba5f3e6bf398ed41d0bf64b2cfb Mon Sep 17 00:00:00 2001 From: Josh Coalson Date: Mon, 5 Aug 2002 06:49:45 +0000 Subject: [PATCH] initial import; still needs a lot of work --- include/OggFLAC/Makefile.am | 28 + include/OggFLAC/all.h | 41 ++ include/OggFLAC/file_decoder.h | 589 ++++++++++++++++ include/OggFLAC/file_encoder.h | 813 +++++++++++++++++++++ include/OggFLAC/seekable_stream_decoder.h | 786 +++++++++++++++++++++ include/OggFLAC/seekable_stream_encoder.h | 816 ++++++++++++++++++++++ include/OggFLAC/stream_decoder.h | 748 ++++++++++++++++++++ include/OggFLAC/stream_encoder.h | 377 ++++++++++ 8 files changed, 4198 insertions(+) create mode 100644 include/OggFLAC/Makefile.am create mode 100644 include/OggFLAC/all.h create mode 100644 include/OggFLAC/file_decoder.h create mode 100644 include/OggFLAC/file_encoder.h create mode 100644 include/OggFLAC/seekable_stream_decoder.h create mode 100644 include/OggFLAC/seekable_stream_encoder.h create mode 100644 include/OggFLAC/stream_decoder.h create mode 100644 include/OggFLAC/stream_encoder.h diff --git a/include/OggFLAC/Makefile.am b/include/OggFLAC/Makefile.am new file mode 100644 index 00000000..3067e2f2 --- /dev/null +++ b/include/OggFLAC/Makefile.am @@ -0,0 +1,28 @@ +# libOggFLAC - Free Lossless Audio Codec + Ogg library +# Copyright (C) 2002 Josh Coalson +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +includedir = ${prefix}/include/OggFLAC + +include_HEADERS = \ + all.h \ + file_encoder.h \ + file_decoder.h \ + seekable_stream_decoder.h \ + seekable_stream_encoder.h \ + stream_decoder.h \ + stream_encoder.h diff --git a/include/OggFLAC/all.h b/include/OggFLAC/all.h new file mode 100644 index 00000000..f21a261f --- /dev/null +++ b/include/OggFLAC/all.h @@ -0,0 +1,41 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__ALL_H +#define OggFLAC__ALL_H + +#include "assert.h" +#include "file_decoder.h" +#include "file_encoder.h" +#include "format.h" +#include "metadata.h" +#include "ordinals.h" +#include "seekable_stream_decoder.h" +#include "seekable_stream_encoder.h" +#include "stream_decoder.h" +#include "stream_encoder.h" + +/** \defgroup oggflac OggFLAC C API + * + * The OggFLAC C API is the interface to libOggFLAC, a set of encoders + * and decoders that wrap around the libFLAC API to provide encoding + * to and decoding from FLAC streams in an Ogg transport. + */ + +#endif diff --git a/include/OggFLAC/file_decoder.h b/include/OggFLAC/file_decoder.h new file mode 100644 index 00000000..147cfb43 --- /dev/null +++ b/include/OggFLAC/file_decoder.h @@ -0,0 +1,589 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__FILE_DECODER_H +#define OggFLAC__FILE_DECODER_H + +#include "FLAC/file_decoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file include/OggFLAC/file_decoder.h + * + * \brief + * This module contains the functions which implement the file + * decoder. + * + * See the detailed documentation in the + * \link oggflac_file_decoder file decoder \endlink module. + */ + +/** \defgroup oggflac_file_decoder OggFLAC/file_decoder.h: file decoder interface + * \ingroup oggflac_decoder + * + * \brief + * This module contains the functions which implement the file + * decoder. + * + * The basic usage of this decoder is as follows: + * - The program creates an instance of a decoder using + * OggFLAC__file_decoder_new(). + * - The program overrides the default settings and sets callbacks for + * writing, error reporting, and metadata reporting using + * OggFLAC__file_decoder_set_*() functions. + * - The program initializes the instance to validate the settings and + * prepare for decoding using OggFLAC__file_decoder_init(). + * - The program calls the OggFLAC__file_decoder_process_*() functions + * to decode data, which subsequently calls the callbacks. + * - The program finishes the decoding with OggFLAC__file_decoder_finish(), + * which flushes the input and output and resets the decoder to the + * uninitialized state. + * - The instance may be used again or deleted with + * OggFLAC__file_decoder_delete(). + * + * The file decoder is a trivial wrapper around the + * \link oggflac_seekable_stream_decoder seekable stream decoder \endlink + * meant to simplfy the process of decoding from a standard file. The + * file decoder supplies all but the Write/Metadata/Error callbacks. + * The user needs only to provide the path to the file and the file + * decoder handles the rest. + * + * Like the seekable stream decoder, seeking is exposed through the + * OggFLAC__file_decoder_seek_absolute() method. At any point after the file + * decoder has been initialized, the user can call this function to seek to + * an exact sample within the file. Subsequently, the first time the write + * callback is called it will be passed a (possibly partial) block starting + * at that sample. + * + * The file decoder also inherits MD5 signature checking from the seekable + * stream decoder. If this is turned on before initialization, + * OggFLAC__file_decoder_finish() will report when the decoded MD5 signature + * does not match the one stored in the STREAMINFO block. MD5 checking is + * automatically turned off if there is no signature in the STREAMINFO + * block or when a seek is attempted. + * + * Make sure to read the detailed descriptions of the + * \link oggflac_seekable_stream_decoder seekable stream decoder module \endlink + * and \link oggflac_stream_decoder stream decoder module \endlink + * since the file decoder inherits much of its behavior from them. + * + * \note + * The "set" functions may only be called when the decoder is in the + * state OggFLAC__FILE_DECODER_UNINITIALIZED, i.e. after + * OggFLAC__file_decoder_new() or OggFLAC__file_decoder_finish(), but + * before OggFLAC__file_decoder_init(). If this is the case they will + * return \c true, otherwise \c false. + * + * \note + * OggFLAC__file_decoder_finish() resets all settings to the constructor + * defaults, including the callbacks. + * + * \{ + */ + + +/** State values for a OggFLAC__FileDecoder + * + * The decoder's state can be obtained by calling OggFLAC__file_decoder_get_state(). + */ +typedef enum { + + OggFLAC__FILE_DECODER_OK = 0, + /**< The decoder is in the normal OK state. */ + + OggFLAC__FILE_DECODER_END_OF_FILE, + /**< The decoder has reached the end of the file. */ + + OggFLAC__FILE_DECODER_ERROR_OPENING_FILE, + /**< An error occurred opening the input file. */ + + OggFLAC__FILE_DECODER_MEMORY_ALLOCATION_ERROR, + /**< An error occurred allocating memory. */ + + OggFLAC__FILE_DECODER_SEEK_ERROR, + /**< An error occurred while seeking. */ + + OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR, + /**< An error occurred in the underlying seekable stream decoder. */ + + OggFLAC__FILE_DECODER_ALREADY_INITIALIZED, + /**< OggFLAC__file_decoder_init() was called when the decoder was already + * initialized, usually because OggFLAC__file_decoder_finish() was not + * called. + */ + + OggFLAC__FILE_DECODER_INVALID_CALLBACK, + /**< OggFLAC__file_decoder_init() was called without all callbacks + * being set. + */ + + OggFLAC__FILE_DECODER_UNINITIALIZED + /**< The decoder is in the uninitialized state. */ + +} OggFLAC__FileDecoderState; + +/** Maps a OggFLAC__FileDecoderState to a C string. + * + * Using a OggFLAC__FileDecoderState as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__FileDecoderStateString[]; + + +/*********************************************************************** + * + * class OggFLAC__FileDecoder : public OggFLAC__StreamDecoder + * + ***********************************************************************/ + +struct OggFLAC__FileDecoderProtected; +struct OggFLAC__FileDecoderPrivate; +/** The opaque structure definition for the file decoder type. See the + * \link oggflac_file_decoder file decoder module \endlink for a detailed + * description. + */ +typedef struct { + struct OggFLAC__FileDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */ + struct OggFLAC__FileDecoderPrivate *private_; /* avoid the C++ keyword 'private' */ +} OggFLAC__FileDecoder; + +/* @@@@ document */ +typedef OggFLAC__StreamDecoderWriteStatus (*OggFLAC__FileDecoderWriteCallback)(const OggFLAC__FileDecoder *decoder, const OggFLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); +typedef void (*OggFLAC__FileDecoderMetadataCallback)(const OggFLAC__FileDecoder *decoder, const OggFLAC__StreamMetadata *metadata, void *client_data); +typedef void (*OggFLAC__FileDecoderErrorCallback)(const OggFLAC__FileDecoder *decoder, OggFLAC__StreamDecoderErrorStatus status, void *client_data); + + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +/** Create a new file decoder instance. The instance is created with + * default settings; see the individual OggFLAC__file_decoder_set_*() + * functions for each setting's default. + * + * \retval OggFLAC__FileDecoder* + * \c NULL if there was an error allocating memory, else the new instance. + */ +OggFLAC__FileDecoder *OggFLAC__file_decoder_new(); + +/** Free a decoder instance. Deletes the object pointed to by \a decoder. + * + * \param decoder A pointer to an existing decoder. + * \assert + * \code decoder != NULL \endcode + */ +void OggFLAC__file_decoder_delete(OggFLAC__FileDecoder *decoder); + + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/** Set the "MD5 signature checking" flag. + * This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_md5_checking(). + * + * \default \c false + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_md5_checking(OggFLAC__FileDecoder *decoder, FLAC__bool value); + +/** Set the input file name to decode. + * + * \default \c "-" + * \param decoder A decoder instance to set. + * \param value The input file name, or "-" for \c stdin. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, or there was a memory + * allocation error, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_filename(OggFLAC__FileDecoder *decoder, const char *value); + +/** Set the write callback. + * This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_write_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_write_callback(OggFLAC__FileDecoder *decoder, OggFLAC__FileDecoderWriteCallback value); + +/** Set the metadata callback. + * This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_callback(OggFLAC__FileDecoder *decoder, OggFLAC__FileDecoderMetadataCallback value); + +/** Set the error callback. + * This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_error_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_error_callback(OggFLAC__FileDecoder *decoder, OggFLAC__FileDecoderErrorCallback value); + +/** Set the client data to be passed back to callbacks. + * This value will be supplied to callbacks in their \a client_data + * argument. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_client_data(OggFLAC__FileDecoder *decoder, void *value); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_respond(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param type See above. + * \assert + * \code decoder != NULL \endcode + * \a type is valid + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_respond(OggFLAC__FileDecoder *decoder, OggFLAC__MetadataType type); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_respond_application(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param id See above. + * \assert + * \code decoder != NULL \endcode + * \code id != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_respond_application(OggFLAC__FileDecoder *decoder, const FLAC__byte id[4]); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_respond_all(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_respond_all(OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_ignore(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param type See above. + * \assert + * \code decoder != NULL \endcode + * \a type is valid + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_ignore(OggFLAC__FileDecoder *decoder, OggFLAC__MetadataType type); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param id See above. + * \assert + * \code decoder != NULL \endcode + * \code id != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_ignore_application(OggFLAC__FileDecoder *decoder, const FLAC__byte id[4]); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_decoder_set_metadata_ignore_all(OggFLAC__FileDecoder *decoder); + +/** Get the current decoder state. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__FileDecoderState + * The current decoder state. + */ +OggFLAC__FileDecoderState OggFLAC__file_decoder_get_state(const OggFLAC__FileDecoder *decoder); + +/** Get the state of the underlying seekable stream decoder. + * Useful when the file decoder state is + * \c OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR. + * + * \param decoder An decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__SeekableStreamDecoderState + * The seekable stream decoder state. + */ +OggFLAC__SeekableStreamDecoderState OggFLAC__file_decoder_get_seekable_stream_decoder_state(const OggFLAC__FileDecoder *decoder); + +/** Get the state of the underlying stream decoder. + * Useful when the file decoder state is + * \c OggFLAC__FILE_DECODER_SEEKABLE_STREAM_DECODER_ERROR and the seekable stream + * decoder state is \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR. + * + * \param decoder An decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__SeekableStreamDecoderState + * The seekable stream decoder state. + */ +OggFLAC__StreamDecoderState OggFLAC__file_decoder_get_stream_decoder_state(const OggFLAC__FileDecoder *decoder); + +/** Get the "MD5 signature checking" flag. + * This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_get_md5_checking(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__file_decoder_get_md5_checking(const OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_get_channels(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__file_decoder_get_channels(const OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_get_channel_assignment(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__ChannelAssignment + * See above. + */ +OggFLAC__ChannelAssignment OggFLAC__file_decoder_get_channel_assignment(const OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_get_bits_per_sample(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__file_decoder_get_bits_per_sample(const OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_get_sample_rate(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__file_decoder_get_sample_rate(const OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_get_blocksize(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__file_decoder_get_blocksize(const OggFLAC__FileDecoder *decoder); + +/** Initialize the decoder instance. + * Should be called after OggFLAC__file_decoder_new() and + * OggFLAC__file_decoder_set_*() but before any of the + * OggFLAC__file_decoder_process_*() functions. Will set and return + * the decoder state, which will be OggFLAC__FILE_DECODER_OK if + * initialization succeeded. + * + * \param decoder An uninitialized decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__FileDecoderState + * \c OggFLAC__FILE_DECODER_OK if initialization was successful; see + * OggFLAC__FileDecoderState for the meanings of other return values. + */ +OggFLAC__FileDecoderState OggFLAC__file_decoder_init(OggFLAC__FileDecoder *decoder); + +/** Finish the decoding process. + * Flushes the decoding buffer, releases resources, resets the decoder + * settings to their defaults, and returns the decoder state to + * OggFLAC__FILE_DECODER_UNINITIALIZED. + * + * In the event of a prematurely-terminated decode, it is not strictly + * necessary to call this immediately before OggFLAC__file_decoder_delete() + * but it is good practice to match every OggFLAC__file_decoder_init() with + * a OggFLAC__file_decoder_finish(). + * + * \param decoder An uninitialized decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if MD5 checking is on AND a STREAMINFO block was available + * AND the MD5 signature in the STREAMINFO block was non-zero AND the + * signature does not match the one computed by the decoder; else + * \c true. + */ +FLAC__bool OggFLAC__file_decoder_finish(OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_process_single(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__file_decoder_process_single(OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__file_decoder_process_until_end_of_metadata(OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_process_until_end_of_stream(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__file_decoder_process_until_end_of_file(OggFLAC__FileDecoder *decoder); + +/** This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_process_remaining_frames(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__file_decoder_process_remaining_frames(OggFLAC__FileDecoder *decoder); + +/** Flush the input and seek to an absolute sample. + * This is inherited from OggFLAC__SeekableStreamDecoder; see + * OggFLAC__seekable_stream_decoder_seek_absolute(). + * + * \param decoder A decoder instance. + * \param sample The target sample number to seek to. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c true if successful, else \c false. + */ +FLAC__bool OggFLAC__file_decoder_seek_absolute(OggFLAC__FileDecoder *decoder, FLAC__uint64 sample); + +/* \} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/OggFLAC/file_encoder.h b/include/OggFLAC/file_encoder.h new file mode 100644 index 00000000..d75699a2 --- /dev/null +++ b/include/OggFLAC/file_encoder.h @@ -0,0 +1,813 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__FILE_ENCODER_H +#define OggFLAC__FILE_ENCODER_H + +#include "FLAC/file_encoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file include/OggFLAC/file_encoder.h + * + * \brief + * This module contains the functions which implement the file + * encoder. + * + * See the detailed documentation in the + * \link oggflac_file_encoder file encoder \endlink module. + */ + +/** \defgroup oggflac_file_encoder OggFLAC/file_encoder.h: file encoder interface + * \ingroup oggflac_encoder + * + * \brief + * This module contains the functions which implement the file + * encoder. + * + * The basic usage of this encoder is as follows: + * - The program creates an instance of an encoder using + * OggFLAC__file_encoder_new(). + * - The program overrides the default settings using + * OggFLAC__file_encoder_set_*() functions. + * - The program initializes the instance to validate the settings and + * prepare for encoding using OggFLAC__file_encoder_init(). + * - The program calls OggFLAC__file_encoder_process() or + * OggFLAC__file_encoder_process_interleaved() to encode data, which + * subsequently writes data to the output file. + * - The program finishes the encoding with OggFLAC__file_encoder_finish(), + * which causes the encoder to encode any data still in its input pipe, + * rewind and write the STREAMINFO metadata to file, and finally reset + * the encoder to the uninitialized state. + * - The instance may be used again or deleted with + * OggFLAC__file_encoder_delete(). + * + * The file encoder is a wrapper around the + * \link oggflac_seekable_stream_encoder seekable stream encoder \endlink which supplies all + * callbacks internally; the user need specify only the filename. + * + * Make sure to read the detailed description of the + * \link oggflac_seekable_stream_encoder seekable stream encoder module \endlink since the + * \link oggflac_stream_encoder stream encoder module \endlink since the + * file encoder inherits much of its behavior from them. + * + * \note + * The "set" functions may only be called when the encoder is in the + * state OggFLAC__FILE_ENCODER_UNINITIALIZED, i.e. after + * OggFLAC__file_encoder_new() or OggFLAC__file_encoder_finish(), but + * before OggFLAC__file_encoder_init(). If this is the case they will + * return \c true, otherwise \c false. + * + * \note + * OggFLAC__file_encoder_finish() resets all settings to the constructor + * defaults. + * + * \{ + */ + + +/** State values for a OggFLAC__FileEncoder + * + * The encoder's state can be obtained by calling OggFLAC__file_encoder_get_state(). + */ +typedef enum { + + OggFLAC__FILE_ENCODER_OK = 0, + /**< The encoder is in the normal OK state. */ + + OggFLAC__FILE_ENCODER_NO_FILENAME, + /**< OggFLAC__file_encoder_init() was called without first calling + * OggFLAC__file_encoder_set_filename(). + */ + + OggFLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR, + /**< An error occurred in the underlying seekable stream encoder; + * check OggFLAC__file_encoder_get_seekable_stream_encoder_state(). + */ + + OggFLAC__FILE_ENCODER_FATAL_ERROR_WHILE_WRITING, + /**< A fatal error occurred while writing to the encoded file. */ + + OggFLAC__FILE_ENCODER_ERROR_OPENING_FILE, + /**< An error occurred opening the output file for writing. */ + + OggFLAC__FILE_ENCODER_MEMORY_ALLOCATION_ERROR, + /**< Memory allocation failed. */ + + OggFLAC__FILE_ENCODER_ALREADY_INITIALIZED, + /**< OggFLAC__file_encoder_init() was called when the encoder was + * already initialized, usually because + * OggFLAC__file_encoder_finish() was not called. + */ + + OggFLAC__FILE_ENCODER_UNINITIALIZED + /**< The encoder is in the uninitialized state. */ + +} OggFLAC__FileEncoderState; + +/** Maps a OggFLAC__FileEncoderState to a C string. + * + * Using a OggFLAC__FileEncoderState as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +/* @@@@ double-check mapping */ +extern const char * const OggFLAC__FileEncoderStateString[]; + + +/*********************************************************************** + * + * class OggFLAC__FileEncoder + * + ***********************************************************************/ + +struct OggFLAC__FileEncoderProtected; +struct OggFLAC__FileEncoderPrivate; +/** The opaque structure definition for the file encoder type. + * See the \link oggflac_file_encoder file encoder module \endlink + * for a detailed description. + */ +typedef struct { + struct OggFLAC__FileEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */ + struct OggFLAC__FileEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ +} OggFLAC__FileEncoder; + +/*@@@ document: */ +typedef void (*OggFLAC__FileEncoderProgressCallback)(const OggFLAC__FileEncoder *encoder, unsigned current_frame, unsigned total_frames_estimate, void *client_data); + + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +/** Create a new file encoder instance. The instance is created with + * default settings; see the individual OggFLAC__file_encoder_set_*() + * functions for each setting's default. + * + * \retval OggFLAC__FileEncoder* + * \c NULL if there was an error allocating memory, else the new instance. + */ +OggFLAC__FileEncoder *OggFLAC__file_encoder_new(); + +/** Free an encoder instance. Deletes the object pointed to by \a encoder. + * + * \param encoder A pointer to an existing encoder. + * \assert + * \code encoder != NULL \endcode + */ +void OggFLAC__file_encoder_delete(OggFLAC__FileEncoder *encoder); + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_verify(). + * + * \default \c true + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_verify(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_streamable_subset(). + * + * \default \c true + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_streamable_subset(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_do_mid_side_stereo(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_loose_mid_side_stereo(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_channels(). + * + * \default \c 2 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_channels(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_bits_per_sample(). + * + * \warning + * Do not feed the encoder data that is wider than the value you + * set here or you will generate an invalid stream. + * + * \default \c 16 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_bits_per_sample(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_sample_rate(). + * + * \default \c 44100 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_sample_rate(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_blocksize(). + * + * \default \c 1152 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_blocksize(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_max_lpc_order(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_max_lpc_order(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(). + * + * \note + * In the current implementation, qlp_coeff_precision + bits_per_sample must + * be less than 32. + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_qlp_coeff_precision(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_do_qlp_coeff_prec_search(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_do_escape_coding(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_do_escape_coding(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_do_exhaustive_model_search(OggFLAC__FileEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_min_residual_partition_order(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_max_residual_partition_order(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_rice_parameter_search_dist(OggFLAC__FileEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_total_samples_estimate(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_total_samples_estimate(OggFLAC__FileEncoder *encoder, FLAC__uint64 value); + +/** This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_set_metadata(). + * + * \default \c NULL, 0 + * \param encoder An encoder instance to set. + * \param metadata See above. + * \param num_blocks See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_metadata(OggFLAC__FileEncoder *encoder, OggFLAC__StreamMetadata **metadata, unsigned num_blocks); + +/** Set the output file name encode to. + * + * \note + * The filename is mandatory and must be set before initialization. + * + * \note + * Unlike the OggFLAC__FileDecoder, the filename does not interpret "-" for + * \c stdout; writing to \c stdout is not relevant in the file encoder. + * + * \default \c NULL + * \param encoder A encoder instance to set. + * \param value The output file name. + * \assert + * \code encoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, or there was a memory + * allocation error, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_filename(OggFLAC__FileEncoder *encoder, const char *value); + +/** Set the progress callback. + * The supplied function will be called when the encoder has finished + * writing a frame. The \c total_frames_estimate argument to the callback + * will be based on the value from + * OggFLAC__file_encoder_set_total_samples_estimate(). + * + * \note + * Unlike most other callbacks, the progress callback is \b not mandatory + * and need not be set before initialization. + * + * \default \c NULL + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_progress_callback(OggFLAC__FileEncoder *encoder, OggFLAC__FileEncoderProgressCallback value); + +/** Set the client data to be passed back to callbacks. + * This value will be supplied to callbacks in their \a client_data + * argument. + * + * \default \c NULL + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__file_encoder_set_client_data(OggFLAC__FileEncoder *encoder, void *value); + +/** Get the current encoder state. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__FileEncoderState + * The current encoder state. + */ +OggFLAC__FileEncoderState OggFLAC__file_encoder_get_state(const OggFLAC__FileEncoder *encoder); + +/** Get the state of the underlying seekable stream encoder. + * Useful when the file encoder state is + * \c OggFLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__SeekableStreamEncoderState + * The seekable stream encoder state. + */ +OggFLAC__SeekableStreamEncoderState OggFLAC__file_encoder_get_seekable_stream_encoder_state(const OggFLAC__FileEncoder *encoder); + +/** Get the state of the underlying stream encoder. + * Useful when the file encoder state is + * \c OggFLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR and the seekable stream + * encoder state is \c OggFLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__SeekableStreamEncoderState + * The seekable stream encoder state. + */ +OggFLAC__StreamEncoderState OggFLAC__file_encoder_get_stream_encoder_state(const OggFLAC__FileEncoder *encoder); + +/** Get the state of the underlying stream encoder's verify decoder. + * Useful when the file encoder state is + * \c OggFLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR and the seekable stream + * encoder state is \c OggFLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR and + * the stream encoder state is \c OggFLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__StreamEncoderState + * The stream encoder state. + */ +OggFLAC__StreamDecoderState OggFLAC__file_encoder_get_verify_decoder_state(const OggFLAC__FileEncoder *encoder); + +/** Get the "verify" flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_verify(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_set_verify(). + */ +FLAC__bool OggFLAC__file_encoder_get_verify(const OggFLAC__FileEncoder *encoder); + +/** Get the "streamable subset" flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_streamable_subset(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_set_streamable_subset(). + */ +FLAC__bool OggFLAC__file_encoder_get_streamable_subset(const OggFLAC__FileEncoder *encoder); + +/** Get the "mid/side stereo coding" flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_get_do_mid_side_stereo(). + */ +FLAC__bool OggFLAC__file_encoder_get_do_mid_side_stereo(const OggFLAC__FileEncoder *encoder); + +/** Get the "adaptive mid/side switching" flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_set_loose_mid_side_stereo(). + */ +FLAC__bool OggFLAC__file_encoder_get_loose_mid_side_stereo(const OggFLAC__FileEncoder *encoder); + +/** Get the number of input channels being processed. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_channels(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_channels(). + */ +unsigned OggFLAC__file_encoder_get_channels(const OggFLAC__FileEncoder *encoder); + +/** Get the input sample resolution setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_bits_per_sample(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_bits_per_sample(). + */ +unsigned OggFLAC__file_encoder_get_bits_per_sample(const OggFLAC__FileEncoder *encoder); + +/** Get the input sample rate setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_sample_rate(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_sample_rate(). + */ +unsigned OggFLAC__file_encoder_get_sample_rate(const OggFLAC__FileEncoder *encoder); + +/** Get the blocksize setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_blocksize(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_blocksize(). + */ +unsigned OggFLAC__file_encoder_get_blocksize(const OggFLAC__FileEncoder *encoder); + +/** Get the maximum LPC order setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_max_lpc_order(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_max_lpc_order(). + */ +unsigned OggFLAC__file_encoder_get_max_lpc_order(const OggFLAC__FileEncoder *encoder); + +/** Get the quantized linear predictor coefficient precision setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_qlp_coeff_precision(). + */ +unsigned OggFLAC__file_encoder_get_qlp_coeff_precision(const OggFLAC__FileEncoder *encoder); + +/** Get the qlp coefficient precision search flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_set_do_qlp_coeff_prec_search(). + */ +FLAC__bool OggFLAC__file_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__FileEncoder *encoder); + +/** Get the "escape coding" flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_do_escape_coding(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_set_do_escape_coding(). + */ +FLAC__bool OggFLAC__file_encoder_get_do_escape_coding(const OggFLAC__FileEncoder *encoder); + +/** Get the exhaustive model search flag. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__file_encoder_set_do_exhaustive_model_search(). + */ +FLAC__bool OggFLAC__file_encoder_get_do_exhaustive_model_search(const OggFLAC__FileEncoder *encoder); + +/** Get the minimum residual partition order setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_min_residual_partition_order(). + */ +unsigned OggFLAC__file_encoder_get_min_residual_partition_order(const OggFLAC__FileEncoder *encoder); + +/** Get maximum residual partition order setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_max_residual_partition_order(). + */ +unsigned OggFLAC__file_encoder_get_max_residual_partition_order(const OggFLAC__FileEncoder *encoder); + +/** Get the Rice parameter search distance setting. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__file_encoder_set_rice_parameter_search_dist(). + */ +unsigned OggFLAC__file_encoder_get_rice_parameter_search_dist(const OggFLAC__FileEncoder *encoder); + +/** Get the previously set estimate of the total samples to be encoded. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_get_total_samples_estimate(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__uint64 + * See OggFLAC__file_encoder_set_total_samples_estimate(). + */ +FLAC__uint64 OggFLAC__file_encoder_get_total_samples_estimate(const OggFLAC__FileEncoder *encoder); + +/** Initialize the encoder instance. + * Should be called after OggFLAC__file_encoder_new() and + * OggFLAC__file_encoder_set_*() but before OggFLAC__file_encoder_process() + * or OggFLAC__file_encoder_process_interleaved(). Will set and return + * the encoder state, which will be OggFLAC__FILE_ENCODER_OK if + * initialization succeeded. + * + * \param encoder An uninitialized encoder instance. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__FileEncoderState + * \c OggFLAC__FILE_ENCODER_OK if initialization was successful; see + * OggFLAC__FileEncoderState for the meanings of other return values. + */ +OggFLAC__FileEncoderState OggFLAC__file_encoder_init(OggFLAC__FileEncoder *encoder); + +/** Finish the encoding process. + * Flushes the encoding buffer, releases resources, resets the encoder + * settings to their defaults, and returns the encoder state to + * OggFLAC__FILE_ENCODER_UNINITIALIZED. + * + * In the event of a prematurely-terminated encode, it is not strictly + * necessary to call this immediately before OggFLAC__file_encoder_delete() + * but it is good practice to match every OggFLAC__file_encoder_init() + * with a OggFLAC__file_encoder_finish(). + * + * \param encoder An uninitialized encoder instance. + * \assert + * \code encoder != NULL \endcode + */ +void OggFLAC__file_encoder_finish(OggFLAC__FileEncoder *encoder); + +/** Submit data for encoding. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_process(). + * + * \param encoder An initialized encoder instance in the OK state. + * \param buffer An array of pointers to each channel's signal. + * \param samples The number of samples in one channel. + * \assert + * \code encoder != NULL \endcode + * \code OggFLAC__file_encoder_get_state(encoder) == OggFLAC__FILE_ENCODER_OK \endcode + * \retval FLAC__bool + * \c true if successful, else \c false; in this case, check the + * encoder state with OggFLAC__file_encoder_get_state() to see what + * went wrong. + */ +FLAC__bool OggFLAC__file_encoder_process(OggFLAC__FileEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples); + +/** Submit data for encoding. + * This is inherited from OggFLAC__SeekableStreamEncoder; see + * OggFLAC__seekable_stream_encoder_process_interleaved(). + * + * \param encoder An initialized encoder instance in the OK state. + * \param buffer An array of channel-interleaved data (see above). + * \param samples The number of samples in one channel, the same as for + * OggFLAC__file_encoder_process(). For example, if + * encoding two channels, \c 1000 \a samples corresponds + * to a \a buffer of 2000 values. + * \assert + * \code encoder != NULL \endcode + * \code OggFLAC__file_encoder_get_state(encoder) == OggFLAC__FILE_ENCODER_OK \endcode + * \retval FLAC__bool + * \c true if successful, else \c false; in this case, check the + * encoder state with OggFLAC__file_encoder_get_state() to see what + * went wrong. + */ +FLAC__bool OggFLAC__file_encoder_process_interleaved(OggFLAC__FileEncoder *encoder, const FLAC__int32 buffer[], unsigned samples); + +/* \} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/OggFLAC/seekable_stream_decoder.h b/include/OggFLAC/seekable_stream_decoder.h new file mode 100644 index 00000000..d50b436c --- /dev/null +++ b/include/OggFLAC/seekable_stream_decoder.h @@ -0,0 +1,786 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__SEEKABLE_STREAM_DECODER_H +#define OggFLAC__SEEKABLE_STREAM_DECODER_H + +#include "FLAC/seekable_stream_decoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file include/OggFLAC/seekable_stream_decoder.h + * + * \brief + * This module contains the functions which implement the seekable stream + * decoder. + * + * See the detailed documentation in the + * \link oggflac_seekable_stream_decoder seekable stream decoder \endlink module. + */ + +/** \defgroup oggflac_seekable_stream_decoder OggFLAC/seekable_stream_decoder.h: seekable stream decoder interface + * \ingroup oggflac_decoder + * + * \brief + * This module contains the functions which implement the seekable stream + * decoder. + * + * The basic usage of this decoder is as follows: + * - The program creates an instance of a decoder using + * OggFLAC__seekable_stream_decoder_new(). + * - The program overrides the default settings and sets callbacks for + * reading, writing, seeking, error reporting, and metadata reporting + * using OggFLAC__seekable_stream_decoder_set_*() functions. + * - The program initializes the instance to validate the settings and + * prepare for decoding using OggFLAC__seekable_stream_decoder_init(). + * - The program calls the OggFLAC__seekable_stream_decoder_process_*() + * functions to decode data, which subsequently calls the callbacks. + * - The program finishes the decoding with + * OggFLAC__seekable_stream_decoder_finish(), which flushes the input and + * output and resets the decoder to the uninitialized state. + * - The instance may be used again or deleted with + * OggFLAC__seekable_stream_decoder_delete(). + * + * The seekable stream decoder is a wrapper around the + * \link oggflac_stream_decoder stream decoder \endlink which also provides + * seeking capability. In addition to the Read/Write/Metadata/Error + * callbacks of the stream decoder, the user must also provide the following: + * + * - Seek callback - This function will be called when the decoder wants to + * seek to an absolute position in the stream. + * - Tell callback - This function will be called when the decoder wants to + * know the current absolute position of the stream. + * - Length callback - This function will be called when the decoder wants + * to know length of the stream. The seeking algorithm currently requires + * that the overall stream length be known. + * - EOF callback - This function will be called when the decoder wants to + * know if it is at the end of the stream. This could be synthesized from + * the tell and length callbacks but it may be more expensive that way, so + * there is a separate callback for it. + * + * Seeking is exposed through the + * OggFLAC__seekable_stream_decoder_seek_absolute() method. At any point after + * the seekable stream decoder has been initialized, the user can call this + * function to seek to an exact sample within the stream. Subsequently, the + * first time the write callback is called it will be passed a (possibly + * partial) block starting at that sample. + * + * The seekable stream decoder also provides MD5 signature checking. If + * this is turned on before initialization, + * OggFLAC__seekable_stream_decoder_finish() will report when the decoded MD5 + * signature does not match the one stored in the STREAMINFO block. MD5 + * checking is automatically turned off (until the next + * OggFLAC__seekable_stream_decoder_reset()) if there is no signature in the + * STREAMINFO block or when a seek is attempted. + * + * Make sure to read the detailed description of the + * \link oggflac_stream_decoder stream decoder module \endlink since the + * seekable stream decoder inherits much of its behavior. + * + * \note + * The "set" functions may only be called when the decoder is in the + * state OggFLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED, i.e. after + * OggFLAC__seekable_stream_decoder_new() or + * OggFLAC__seekable_stream_decoder_finish(), but before + * OggFLAC__seekable_stream_decoder_init(). If this is the case they will + * return \c true, otherwise \c false. + * + * \note + * OggFLAC__stream_decoder_finish() resets all settings to the constructor + * defaults, including the callbacks. + * + * \{ + */ + + +/** State values for a OggFLAC__SeekableStreamDecoder + * + * The decoder's state can be obtained by calling OggFLAC__seekable_stream_decoder_get_state(). + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_DECODER_OK = 0, + /**< The decoder is in the normal OK state. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_SEEKING, + /**< The decoder is in the process of seeking. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM, + /**< The decoder has reached the end of the stream. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR, + /**< An error occurred allocating memory. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR, + /**< An error occurred in the underlying stream decoder. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_READ_ERROR, + /**< The read callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_ERROR, + /**< An error occurred while seeking or the seek or tell + * callback returned an error. + */ + + OggFLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED, + /**< OggFLAC__seekable_stream_decoder_init() was called when the + * decoder was already initialized, usually because + * OggFLAC__seekable_stream_decoder_finish() was not called. + */ + + OggFLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK, + /**< OggFLAC__seekable_stream_decoder_init() was called without all + * callbacks being set. + */ + + OggFLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED + /**< The decoder is in the uninitialized state. */ + +} OggFLAC__SeekableStreamDecoderState; + +/** Maps a OggFLAC__SeekableStreamDecoderState to a C string. + * + * Using a OggFLAC__SeekableStreamDecoderState as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__SeekableStreamDecoderStateString[]; + + +/** Return values for the OggFLAC__SeekableStreamDecoder read callback. + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_OK, + /**< The read was OK and decoding can continue. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_READ_STATUS_ERROR + /**< An unrecoverable error occurred. The decoder will return from the process call. */ + +} OggFLAC__SeekableStreamDecoderReadStatus; + +/** Maps a OggFLAC__SeekableStreamDecoderReadStatus to a C string. + * + * Using a OggFLAC__SeekableStreamDecoderReadStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__SeekableStreamDecoderReadStatusString[]; + + +/** Return values for the OggFLAC__SeekableStreamDecoder seek callback. + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_OK, + /**< The seek was OK and decoding can continue. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_SEEK_STATUS_ERROR + /**< An unrecoverable error occurred. The decoder will return from the process call. */ + +} OggFLAC__SeekableStreamDecoderSeekStatus; + +/** Maps a OggFLAC__SeekableStreamDecoderSeekStatus to a C string. + * + * Using a OggFLAC__SeekableStreamDecoderSeekStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__SeekableStreamDecoderSeekStatusString[]; + + +/** Return values for the OggFLAC__SeekableStreamDecoder tell callback. + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_OK, + /**< The tell was OK and decoding can continue. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_TELL_STATUS_ERROR + /**< An unrecoverable error occurred. The decoder will return from the process call. */ + +} OggFLAC__SeekableStreamDecoderTellStatus; + +/** Maps a OggFLAC__SeekableStreamDecoderTellStatus to a C string. + * + * Using a OggFLAC__SeekableStreamDecoderTellStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__SeekableStreamDecoderTellStatusString[]; + + +/** Return values for the OggFLAC__SeekableStreamDecoder length callback. + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_OK, + /**< The length call was OK and decoding can continue. */ + + OggFLAC__SEEKABLE_STREAM_DECODER_LENGTH_STATUS_ERROR + /**< An unrecoverable error occurred. The decoder will return from the process call. */ + +} OggFLAC__SeekableStreamDecoderLengthStatus; + +/** Maps a OggFLAC__SeekableStreamDecoderLengthStatus to a C string. + * + * Using a OggFLAC__SeekableStreamDecoderLengthStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__SeekableStreamDecoderLengthStatusString[]; + + +/*********************************************************************** + * + * class OggFLAC__SeekableStreamDecoder : public OggFLAC__StreamDecoder + * + ***********************************************************************/ + +struct OggFLAC__SeekableStreamDecoderProtected; +struct OggFLAC__SeekableStreamDecoderPrivate; +/** The opaque structure definition for the seekable stream decoder type. + * See the + * \link oggflac_seekable_stream_decoder seekable stream decoder module \endlink + * for a detailed description. + */ +typedef struct { + struct OggFLAC__SeekableStreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */ + struct OggFLAC__SeekableStreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */ +} OggFLAC__SeekableStreamDecoder; + +/*@@@ document */ +typedef OggFLAC__SeekableStreamDecoderReadStatus (*OggFLAC__SeekableStreamDecoderReadCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); +typedef OggFLAC__SeekableStreamDecoderSeekStatus (*OggFLAC__SeekableStreamDecoderSeekCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data); +typedef OggFLAC__SeekableStreamDecoderTellStatus (*OggFLAC__SeekableStreamDecoderTellCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data); +typedef OggFLAC__SeekableStreamDecoderLengthStatus (*OggFLAC__SeekableStreamDecoderLengthCallback)(const OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data); +typedef FLAC__bool (*OggFLAC__SeekableStreamDecoderEofCallback)(const OggFLAC__SeekableStreamDecoder *decoder, void *client_data); +typedef OggFLAC__StreamDecoderWriteStatus (*OggFLAC__SeekableStreamDecoderWriteCallback)(const OggFLAC__SeekableStreamDecoder *decoder, const OggFLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); +typedef void (*OggFLAC__SeekableStreamDecoderMetadataCallback)(const OggFLAC__SeekableStreamDecoder *decoder, const OggFLAC__StreamMetadata *metadata, void *client_data); +typedef void (*OggFLAC__SeekableStreamDecoderErrorCallback)(const OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__StreamDecoderErrorStatus status, void *client_data); + + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +/** Create a new seekable stream decoder instance. The instance is created + * with default settings; see the individual + * OggFLAC__seekable_stream_decoder_set_*() functions for each setting's + * default. + * + * \retval OggFLAC__SeekableStreamDecoder* + * \c NULL if there was an error allocating memory, else the new instance. + */ +OggFLAC__SeekableStreamDecoder *OggFLAC__seekable_stream_decoder_new(); + +/** Free a decoder instance. Deletes the object pointed to by \a decoder. + * + * \param decoder A pointer to an existing decoder. + * \assert + * \code decoder != NULL \endcode + */ +void OggFLAC__seekable_stream_decoder_delete(OggFLAC__SeekableStreamDecoder *decoder); + + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/** Set the "MD5 signature checking" flag. If \c true, the decoder will + * compute the MD5 signature of the unencoded audio data while decoding + * and compare it to the signature from the STREAMINFO block, if it + * exists, during OggFLAC__seekable_stream_decoder_finish(). + * + * MD5 signature checking will be turned off (until the next + * OggFLAC__seekable_stream_decoder_reset()) if there is no signature in + * the STREAMINFO block or when a seek is attempted. + * + * \default \c false + * \param decoder A decoder instance to set. + * \param value Flag value (see above). + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_md5_checking(OggFLAC__SeekableStreamDecoder *decoder, FLAC__bool value); + +/** Set the read callback. + * This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_read_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_read_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderReadCallback value); + +/** Set the seek callback. + * The supplied function will be called when the decoder needs to seek + * the input stream. The decoder will pass the absolute byte offset + * to seek to, 0 meaning the beginning of the stream. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_seek_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderSeekCallback value); + +/** Set the tell callback. + * The supplied function will be called when the decoder wants to know + * the current position of the stream. The callback should return the + * byte offset from the beginning of the stream. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_tell_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderTellCallback value); + +/** Set the length callback. + * The supplied function will be called when the decoder wants to know + * the total length of the stream in bytes. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_length_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderLengthCallback value); + +/** Set the eof callback. + * The supplied function will be called when the decoder needs to know + * if the end of the stream has been reached. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_eof_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderEofCallback value); + +/** Set the write callback. + * This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_write_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_write_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderWriteCallback value); + +/** Set the metadata callback. + * This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderMetadataCallback value); + +/** Set the error callback. + * This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_error_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder A decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_error_callback(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__SeekableStreamDecoderErrorCallback value); + +/** Set the client data to be passed back to callbacks. + * This value will be supplied to callbacks in their \a client_data + * argument. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_client_data(OggFLAC__SeekableStreamDecoder *decoder, void *value); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_respond(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param type See above. + * \assert + * \code decoder != NULL \endcode + * \a type is valid + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_respond(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__MetadataType type); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_respond_application(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param id See above. + * \assert + * \code decoder != NULL \endcode + * \code id != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_respond_application(OggFLAC__SeekableStreamDecoder *decoder, const FLAC__byte id[4]); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_respond_all(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_respond_all(OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_ignore(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param type See above. + * \assert + * \code decoder != NULL \endcode + * \a type is valid + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore(OggFLAC__SeekableStreamDecoder *decoder, OggFLAC__MetadataType type); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_ignore_application(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param id See above. + * \assert + * \code decoder != NULL \endcode + * \code id != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore_application(OggFLAC__SeekableStreamDecoder *decoder, const FLAC__byte id[4]); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_set_metadata_ignore_all(). + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_set_metadata_ignore_all(OggFLAC__SeekableStreamDecoder *decoder); + +/** Get the current decoder state. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__SeekableStreamDecoderState + * The current decoder state. + */ +OggFLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_get_state(const OggFLAC__SeekableStreamDecoder *decoder); + +/** Get the state of the underlying stream decoder. + * Useful when the seekable stream decoder state is + * \c OggFLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR. + * + * \param decoder An decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__StreamDecoderState + * The stream decoder state. + */ +OggFLAC__StreamDecoderState OggFLAC__seekable_stream_decoder_get_stream_decoder_state(const OggFLAC__SeekableStreamDecoder *decoder); + +/** Get the "MD5 signature checking" flag. + * This is the value of the setting, not whether or not the decoder is + * currently checking the MD5 (remember, it can be turned off automatically + * by a seek). When the decoder is reset the flag will be restored to the + * value returned by this function. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_get_md5_checking(const OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_get_channels(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__seekable_stream_decoder_get_channels(const OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_get_channel_assignment(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__ChannelAssignment + * See above. + */ +OggFLAC__ChannelAssignment OggFLAC__seekable_stream_decoder_get_channel_assignment(const OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_get_bits_per_sample(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__seekable_stream_decoder_get_bits_per_sample(const OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_get_sample_rate(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__seekable_stream_decoder_get_sample_rate(const OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_get_blocksize(). + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__seekable_stream_decoder_get_blocksize(const OggFLAC__SeekableStreamDecoder *decoder); + +/** Initialize the decoder instance. + * Should be called after OggFLAC__seekable_stream_decoder_new() and + * OggFLAC__seekable_stream_decoder_set_*() but before any of the + * OggFLAC__seekable_stream_decoder_process_*() functions. Will set and return + * the decoder state, which will be OggFLAC__SEEKABLE_STREAM_DECODER_OK + * if initialization succeeded. + * + * \param decoder An uninitialized decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__SeekableStreamDecoderState + * \c OggFLAC__SEEKABLE_STREAM_DECODER_OK if initialization was + * successful; see OggFLAC__SeekableStreamDecoderState for the meanings + * of other return values. + */ +OggFLAC__SeekableStreamDecoderState OggFLAC__seekable_stream_decoder_init(OggFLAC__SeekableStreamDecoder *decoder); + +/** Finish the decoding process. + * Flushes the decoding buffer, releases resources, resets the decoder + * settings to their defaults, and returns the decoder state to + * OggFLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED. + * + * In the event of a prematurely-terminated decode, it is not strictly + * necessary to call this immediately before + * OggFLAC__seekable_stream_decoder_delete() but it is good practice to match + * every OggFLAC__seekable_stream_decoder_init() with a + * OggFLAC__seekable_stream_decoder_finish(). + * + * \param decoder An uninitialized decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if MD5 checking is on AND a STREAMINFO block was available + * AND the MD5 signature in the STREAMINFO block was non-zero AND the + * signature does not match the one computed by the decoder; else + * \c true. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_finish(OggFLAC__SeekableStreamDecoder *decoder); + +/** Flush the stream input. + * The decoder's input buffer will be cleared and the state set to + * \c OggFLAC__SEEKABLE_STREAM_DECODER_OK. This will also turn off MD5 + * checking. + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c true if successful, else \c false if a memory allocation + * or stream decoder error occurs. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_flush(OggFLAC__SeekableStreamDecoder *decoder); + +/** Reset the decoding process. + * The decoder's input buffer will be cleared and the state set to + * \c OggFLAC__SEEKABLE_STREAM_DECODER_OK. This is similar to + * OggFLAC__seekable_stream_decoder_finish() except that the settings are + * preserved; there is no need to call OggFLAC__seekable_stream_decoder_init() + * before decoding again. MD5 checking will be restored to its original + * setting. + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c true if successful, else \c false if a memory allocation + * or stream decoder error occurs. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_reset(OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_process_single(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_process_single(OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_process_until_end_of_metadata(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_process_until_end_of_metadata(OggFLAC__SeekableStreamDecoder *decoder); + +/** This is inherited from OggFLAC__StreamDecoder; see + * OggFLAC__stream_decoder_process_until_end_of_stream(). + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * See above. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_process_until_end_of_stream(OggFLAC__SeekableStreamDecoder *decoder); + +/** Flush the input and seek to an absolute sample. + * Decoding will resume at the given sample. Note that because of + * this, the next write callback may contain a partial block. + * + * \param decoder A decoder instance. + * \param sample The target sample number to seek to. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c true if successful, else \c false. + */ +FLAC__bool OggFLAC__seekable_stream_decoder_seek_absolute(OggFLAC__SeekableStreamDecoder *decoder, FLAC__uint64 sample); + +/* \} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/OggFLAC/seekable_stream_encoder.h b/include/OggFLAC/seekable_stream_encoder.h new file mode 100644 index 00000000..55cf8cbd --- /dev/null +++ b/include/OggFLAC/seekable_stream_encoder.h @@ -0,0 +1,816 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__SEEKABLE_STREAM_ENCODER_H +#define OggFLAC__SEEKABLE_STREAM_ENCODER_H + +#include "FLAC/seekable_stream_encoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file include/OggFLAC/seekable_stream_encoder.h + * + * \brief + * This module contains the functions which implement the seekable stream + * encoder. + * + * See the detailed documentation in the + * \link oggflac_seekable_stream_encoder seekable stream encoder \endlink module. + */ + +/** \defgroup oggflac_seekable_stream_encoder OggFLAC/seekable_stream_encoder.h: seekable stream encoder interface + * \ingroup oggflac_encoder + * + * \brief + * This module contains the functions which implement the seekable stream + * encoder. + * + * XXX (import) + * + * The seekable stream encoder is a wrapper around the + * \link oggflac_stream_encoder stream encoder \endlink which (XXXimport) + * + * Make sure to read the detailed description of the + * \link oggflac_stream_encoder stream encoder module \endlink since the + * seekable stream encoder inherits much of its behavior. + * + * \note + * The "set" functions may only be called when the encoder is in the + * state OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED, i.e. after + * OggFLAC__seekable_stream_encoder_new() or OggFLAC__seekable_stream_encoder_finish(), but + * before OggFLAC__seekable_stream_encoder_init(). If this is the case they will + * return \c true, otherwise \c false. + * + * \note + * OggFLAC__seekable_stream_encoder_finish() resets all settings to the constructor + * defaults, including the callbacks. + * + * \{ + */ + + +/** State values for a OggFLAC__SeekableStreamEncoder + * + * The encoder's state can be obtained by calling OggFLAC__seekable_stream_encoder_get_state(). + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_ENCODER_OK = 0, + /**< The encoder is in the normal OK state. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR, + /**< An error occurred in the underlying stream encoder; + * check OggFLAC__seekable_stream_encoder_get_stream_encoder_state(). + */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_MEMORY_ALLOCATION_ERROR, + /**< Memory allocation failed. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_WRITE_ERROR, + /**< The write callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_READ_ERROR, + /**< The read callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_SEEK_ERROR, + /**< The seek callback returned an error. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_ALREADY_INITIALIZED, + /**< OggFLAC__seekable_stream_encoder_init() was called when the encoder was + * already initialized, usually because + * OggFLAC__seekable_stream_encoder_finish() was not called. + */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_CALLBACK, + /**< OggFLAC__seekable_stream_encoder_init() was called without all + * callbacks being set. + */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_INVALID_SEEKTABLE, + /**< An invalid seek table was passed is the metadata to + * OggFLAC__seekable_stream_encoder_set_metadata(). + */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED + /**< The encoder is in the uninitialized state. */ + +} OggFLAC__SeekableStreamEncoderState; + +/** Maps a OggFLAC__SeekableStreamEncoderState to a C string. + * + * Using a OggFLAC__SeekableStreamEncoderState as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +/* @@@@ double-check mapping */ +extern const char * const OggFLAC__SeekableStreamEncoderStateString[]; + + +/** Return values for the OggFLAC__SeekableStreamEncoder seek callback. + */ +typedef enum { + + OggFLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK, + /**< The seek was OK and encoding can continue. */ + + OggFLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_ERROR + /**< An unrecoverable error occurred. The encoder will return from the process call. */ + +} OggFLAC__SeekableStreamEncoderSeekStatus; + +/** Maps a OggFLAC__SeekableStreamEncoderSeekStatus to a C string. + * + * Using a OggFLAC__SeekableStreamEncoderSeekStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__SeekableStreamEncoderSeekStatusString[]; + + +/*********************************************************************** + * + * class OggFLAC__SeekableStreamEncoder + * + ***********************************************************************/ + +struct OggFLAC__SeekableStreamEncoderProtected; +struct OggFLAC__SeekableStreamEncoderPrivate; +/** The opaque structure definition for the seekable stream encoder type. + * See the \link oggflac_seekable_stream_encoder seekable stream encoder module \endlink + * for a detailed description. + */ +typedef struct { + struct OggFLAC__SeekableStreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */ + struct OggFLAC__SeekableStreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ +} OggFLAC__SeekableStreamEncoder; + +/*@@@ document: */ +typedef OggFLAC__SeekableStreamEncoderSeekStatus (*OggFLAC__SeekableStreamEncoderSeekCallback)(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data); +typedef OggFLAC__StreamEncoderWriteStatus (*OggFLAC__SeekableStreamEncoderWriteCallback)(const OggFLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); + + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +/** Create a new seekable stream encoder instance. The instance is created with + * default settings; see the individual OggFLAC__seekable_stream_encoder_set_*() + * functions for each setting's default. + * + * \retval OggFLAC__SeekableStreamEncoder* + * \c NULL if there was an error allocating memory, else the new instance. + */ +OggFLAC__SeekableStreamEncoder *OggFLAC__seekable_stream_encoder_new(); + +/** Free an encoder instance. Deletes the object pointed to by \a encoder. + * + * \param encoder A pointer to an existing encoder. + * \assert + * \code encoder != NULL \endcode + */ +void OggFLAC__seekable_stream_encoder_delete(OggFLAC__SeekableStreamEncoder *encoder); + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_verify(). + * + * \default \c true + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_verify(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_streamable_subset(). + * + * \default \c true + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_streamable_subset(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_do_mid_side_stereo(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_loose_mid_side_stereo(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_channels(). + * + * \default \c 2 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_channels(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_bits_per_sample(). + * + * \warning + * Do not feed the encoder data that is wider than the value you + * set here or you will generate an invalid stream. + * + * \default \c 16 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_bits_per_sample(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_sample_rate(). + * + * \default \c 44100 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_sample_rate(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_blocksize(). + * + * \default \c 1152 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_blocksize(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_max_lpc_order(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_max_lpc_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_qlp_coeff_precision(). + * + * \note + * In the current implementation, qlp_coeff_precision + bits_per_sample must + * be less than 32. + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_do_escape_coding(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_do_escape_coding(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_do_exhaustive_model_search(). + * + * \default \c false + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(OggFLAC__SeekableStreamEncoder *encoder, FLAC__bool value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_min_residual_partition_order(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_max_residual_partition_order(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_rice_parameter_search_dist(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(OggFLAC__SeekableStreamEncoder *encoder, unsigned value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_total_samples_estimate(). + * + * \default \c 0 + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_total_samples_estimate(OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 value); + +/** This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_metadata(). + * + * \note + * The decoder instance \b will modify the first \c SEEKTABLE block + * as it transforms the template to a valid seektable while encoding, + * but it is still up to the caller to free all metadata blocks after + * encoding. + * + * \default \c NULL, 0 + * \param encoder An encoder instance to set. + * \param metadata See above. + * \param num_blocks See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_metadata(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__StreamMetadata **metadata, unsigned num_blocks); + +/** Set the seek callback. + * The supplied function will be called when the encoder needs to seek + * the output stream. The encoder will pass the absolute byte offset + * to seek to, 0 meaning the beginning of the stream. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_seek_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderSeekCallback value); + +/** Set the write callback. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_set_write_callback(). + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_write_callback(OggFLAC__SeekableStreamEncoder *encoder, OggFLAC__SeekableStreamEncoderWriteCallback value); + +/** Set the client data to be passed back to callbacks. + * This value will be supplied to callbacks in their \a client_data + * argument. + * + * \default \c NULL + * \param encoder An encoder instance to set. + * \param value See above. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * \c false if the encoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_set_client_data(OggFLAC__SeekableStreamEncoder *encoder, void *value); + +/** Get the current encoder state. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__SeekableStreamEncoderState + * The current encoder state. + */ +OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_get_state(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the state of the underlying stream encoder. + * Useful when the seekable stream encoder state is + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__StreamEncoderState + * The stream encoder state. + */ +OggFLAC__StreamEncoderState OggFLAC__seekable_stream_encoder_get_stream_encoder_state(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the state of the underlying stream encoder's verify decoder. + * Useful when the seekable stream encoder state is + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR and the + * stream encoder state is \c OggFLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__StreamEncoderState + * The stream encoder state. + */ +OggFLAC__StreamDecoderState OggFLAC__seekable_stream_encoder_get_verify_decoder_state(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the "verify" flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_verify(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_set_verify(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_verify(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the "streamable subset" flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_streamable_subset(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_set_streamable_subset(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_streamable_subset(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the "mid/side stereo coding" flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_do_mid_side_stereo(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the "adaptive mid/side switching" flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_loose_mid_side_stereo(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the number of input channels being processed. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_channels(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_channels(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_channels(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the input sample resolution setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_bits_per_sample(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_bits_per_sample(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_bits_per_sample(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the input sample rate setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_sample_rate(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_sample_rate(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_sample_rate(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the blocksize setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_blocksize(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_blocksize(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_blocksize(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the maximum LPC order setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_max_lpc_order(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_max_lpc_order(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_max_lpc_order(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the quantized linear predictor coefficient precision setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_qlp_coeff_precision(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the qlp coefficient precision search flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the "escape coding" flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_do_escape_coding(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_set_do_escape_coding(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_do_escape_coding(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the exhaustive model search flag. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_do_exhaustive_model_search(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__bool + * See OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(). + */ +FLAC__bool OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the minimum residual partition order setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_min_residual_partition_order(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get maximum residual partition order setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_max_residual_partition_order(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the Rice parameter search distance setting. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_rice_parameter_search_dist(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval unsigned + * See OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(). + */ +unsigned OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Get the previously set estimate of the total samples to be encoded. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_get_total_samples_estimate(). + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__uint64 + * See OggFLAC__seekable_stream_encoder_set_total_samples_estimate(). + */ +FLAC__uint64 OggFLAC__seekable_stream_encoder_get_total_samples_estimate(const OggFLAC__SeekableStreamEncoder *encoder); + +/** Initialize the encoder instance. + * Should be called after OggFLAC__seekable_stream_encoder_new() and + * OggFLAC__seekable_stream_encoder_set_*() but before OggFLAC__seekable_stream_encoder_process() + * or OggFLAC__seekable_stream_encoder_process_interleaved(). Will set and return + * the encoder state, which will be OggFLAC__SEEKABLE_STREAM_ENCODER_OK if + * initialization succeeded. + * + * The call to OggFLAC__seekable_stream_encoder_init() currently will also immediately + * call the write callback with the \c fLaC signature and all the encoded + * metadata. + * + * \param encoder An uninitialized encoder instance. + * \assert + * \code encoder != NULL \endcode + * \retval OggFLAC__SeekableStreamEncoderState + * \c OggFLAC__SEEKABLE_STREAM_ENCODER_OK if initialization was successful; see + * OggFLAC__SeekableStreamEncoderState for the meanings of other return values. + */ +OggFLAC__SeekableStreamEncoderState OggFLAC__seekable_stream_encoder_init(OggFLAC__SeekableStreamEncoder *encoder); + +/** Finish the encoding process. + * Flushes the encoding buffer, releases resources, resets the encoder + * settings to their defaults, and returns the encoder state to + * OggFLAC__SEEKABLE_STREAM_ENCODER_UNINITIALIZED. + * + * In the event of a prematurely-terminated encode, it is not strictly + * necessary to call this immediately before OggFLAC__seekable_stream_encoder_delete() + * but it is good practice to match every OggFLAC__seekable_stream_encoder_init() + * with a OggFLAC__seekable_stream_encoder_finish(). + * + * \param encoder An uninitialized encoder instance. + * \assert + * \code encoder != NULL \endcode + */ +void OggFLAC__seekable_stream_encoder_finish(OggFLAC__SeekableStreamEncoder *encoder); + +/** Submit data for encoding. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_process(). + * + * \param encoder An initialized encoder instance in the OK state. + * \param buffer An array of pointers to each channel's signal. + * \param samples The number of samples in one channel. + * \assert + * \code encoder != NULL \endcode + * \code OggFLAC__seekable_stream_encoder_get_state(encoder) == OggFLAC__SEEKABLE_STREAM_ENCODER_OK \endcode + * \retval FLAC__bool + * \c true if successful, else \c false; in this case, check the + * encoder state with OggFLAC__seekable_stream_encoder_get_state() to see what + * went wrong. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_process(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples); + +/** Submit data for encoding. + * This is inherited from OggFLAC__StreamEncoder; see + * OggFLAC__stream_encoder_process_interleaved(). + * + * \param encoder An initialized encoder instance in the OK state. + * \param buffer An array of channel-interleaved data (see above). + * \param samples The number of samples in one channel, the same as for + * OggFLAC__seekable_stream_encoder_process(). For example, if + * encoding two channels, \c 1000 \a samples corresponds + * to a \a buffer of 2000 values. + * \assert + * \code encoder != NULL \endcode + * \code OggFLAC__seekable_stream_encoder_get_state(encoder) == OggFLAC__SEEKABLE_STREAM_ENCODER_OK \endcode + * \retval FLAC__bool + * \c true if successful, else \c false; in this case, check the + * encoder state with OggFLAC__seekable_stream_encoder_get_state() to see what + * went wrong. + */ +FLAC__bool OggFLAC__seekable_stream_encoder_process_interleaved(OggFLAC__SeekableStreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples); + +/* \} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/OggFLAC/stream_decoder.h b/include/OggFLAC/stream_decoder.h new file mode 100644 index 00000000..182000ec --- /dev/null +++ b/include/OggFLAC/stream_decoder.h @@ -0,0 +1,748 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__STREAM_DECODER_H +#define OggFLAC__STREAM_DECODER_H + +#include "FLAC/stream_decoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file include/OggFLAC/stream_decoder.h + * + * \brief + * This module contains the functions which implement the stream + * decoder. + * + * See the detailed documentation in the + * \link oggflac_stream_decoder stream decoder \endlink module. + */ + +/** \defgroup oggflac_decoder OggFLAC/ *_decoder.h: decoder interfaces + * \ingroup oggflac + * + * \brief + * This module describes the three decoder layers provided by libOggFLAC. + * + * For decoding OggFLAC streams, libOggFLAC provides three layers of access. The + * lowest layer is non-seekable stream-level decoding, the next is seekable + * stream-level decoding, and the highest layer is file-level decoding. The + * interfaces are described in the \link oggflac_stream_decoder stream decoder + * \endlink, \link oggflac_seekable_stream_decoder seekable stream decoder + * \endlink, and \link oggflac_file_decoder file decoder \endlink modules + * respectively. Typically you will choose the highest layer that your input + * source will support. + * + * The stream decoder relies on callbacks for all input and output and has no + * provisions for seeking. The seekable stream decoder wraps the stream + * decoder and exposes functions for seeking. However, you must provide + * extra callbacks for seek-related operations on your stream, like seek and + * tell. The file decoder wraps the seekable stream decoder and supplies + * most of the callbacks internally, simplifying the processing of standard + * files. + */ + +/** \defgroup oggflac_stream_decoder OggFLAC/stream_decoder.h: stream decoder interface + * \ingroup oggflac_decoder + * + * \brief + * This module contains the functions which implement the stream + * decoder. + * + * The basic usage of this decoder is as follows: + * - The program creates an instance of a decoder using + * OggFLAC__stream_decoder_new(). + * - The program overrides the default settings and sets callbacks for + * reading, writing, error reporting, and metadata reporting using + * OggFLAC__stream_decoder_set_*() functions. + * - The program initializes the instance to validate the settings and + * prepare for decoding using OggFLAC__stream_decoder_init(). + * - The program calls the OggFLAC__stream_decoder_process_*() functions + * to decode data, which subsequently calls the callbacks. + * - The program finishes the decoding with OggFLAC__stream_decoder_finish(), + * which flushes the input and output and resets the decoder to the + * uninitialized state. + * - The instance may be used again or deleted with + * OggFLAC__stream_decoder_delete(). + * + * In more detail, the program will create a new instance by calling + * OggFLAC__stream_decoder_new(), then call OggFLAC__stream_decoder_set_*() + * functions to set the callbacks and client data, and call + * OggFLAC__stream_decoder_init(). The required callbacks are: + * + * - Read callback - This function will be called when the decoder needs + * more input data. The address of the buffer to be filled is supplied, + * along with the number of bytes the buffer can hold. The callback may + * choose to supply less data and modify the byte count but must be careful + * not to overflow the buffer. The callback then returns a status code + * chosen from OggFLAC__StreamDecoderReadStatus. + * - Write callback - This function will be called when the decoder has + * decoded a single frame of data. The decoder will pass the frame + * metadata as well as an array of pointers (one for each channel) + * pointing to the decoded audio. + * - Metadata callback - This function will be called when the decoder has + * decoded a metadata block. There will always be one STREAMINFO block + * per stream, followed by zero or more other metadata blocks. These will + * be supplied by the decoder in the same order as they appear in the + * stream and always before the first audio frame (i.e. write callback). + * The metadata block that is passed in must not be modified, and it + * doesn't live beyond the callback, so you should make a copy of it with + * OggFLAC__metadata_object_clone() if you will need it elsewhere. Since + * metadata blocks can potentially be large, by default the decoder only + * calls the metadata callback for the STREAMINFO block; you can instruct + * the decoder to pass or filter other blocks with + * OggFLAC__stream_decoder_set_metadata_*() calls. + * - Error callback - This function will be called whenever an error occurs + * during decoding. + * + * Once the decoder is initialized, your program will call one of several + * functions to start the decoding process: + * + * - OggFLAC__stream_decoder_process_single() - Tells the decoder to process at + * most one metadata block or audio frame and return, calling either the + * metadata callback or write callback, respectively, once. If the decoder + * loses sync it will return with only the error callback being called. + * - OggFLAC__stream_decoder_process_until_end_of_metadata() - Tells the decoder + * to process the stream from the current location and stop upon reaching + * the first audio frame. The user will get one metadata, write, or error + * callback per metadata block, audio frame, or sync error, respectively. + * - OggFLAC__stream_decoder_process_until_end_of_stream() - Tells the decoder + * to process the stream from the current location until the read callback + * returns OggFLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM or + * OggFLAC__STREAM_DECODER_READ_STATUS_ABORT. The user will get one metadata, + * write, or error callback per metadata block, audio frame, or sync error, + * respectively. + * + * When the decoder has finished decoding (normally or through an abort), + * the instance is finished by calling OggFLAC__stream_decoder_finish(), which + * ensures the decoder is in the correct state and frees memory. Then the + * instance may be deleted with OggFLAC__stream_decoder_delete() or initialized + * again to decode another stream. + * + * Note that the stream decoder has no real concept of stream position, it + * just converts data. To seek within a stream the callbacks have only to + * flush the decoder using OggFLAC__stream_decoder_flush() and start feeding + * data from the new position through the read callback. The seekable + * stream decoder does just this. + * + * The OggFLAC__stream_decoder_set_metadata_*() functions deserve special + * attention. By default, the decoder only calls the metadata_callback for + * the STREAMINFO block. These functions allow you to tell the decoder + * explicitly which blocks to parse and return via the metadata_callback + * and/or which to skip. Use a OggFLAC__stream_decoder_respond_all(), + * OggFLAC__stream_decoder_ignore() ... or OggFLAC__stream_decoder_ignore_all(), + * OggFLAC__stream_decoder_respond() ... sequence to exactly specify which + * blocks to return. Remember that some metadata blocks can be big so + * filtering out the ones you don't use can reduce the memory requirements + * of the decoder. Also note the special forms + * OggFLAC__stream_decoder_respond_application(id) and + * OggFLAC__stream_decoder_ignore_application(id) for filtering APPLICATION + * blocks based on the application ID. + * + * STREAMINFO and SEEKTABLE blocks are always parsed and used internally, but + * they still can legally be filtered from the metadata_callback. + * + * \note + * The "set" functions may only be called when the decoder is in the + * state OggFLAC__STREAM_DECODER_UNINITIALIZED, i.e. after + * OggFLAC__stream_decoder_new() or OggFLAC__stream_decoder_finish(), but + * before OggFLAC__stream_decoder_init(). If this is the case they will + * return \c true, otherwise \c false. + * + * \note + * OggFLAC__stream_decoder_finish() resets all settings to the constructor + * defaults, including the callbacks. + * + * \{ + */ + + +/** State values for a OggFLAC__StreamDecoder + * + * The decoder's state can be obtained by calling OggFLAC__stream_decoder_get_state(). + */ +typedef enum { + + OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0, + /**< The decoder is ready to search for metadata. */ + + OggFLAC__STREAM_DECODER_READ_METADATA, + /**< The decoder is ready to or is in the process of reading metadata. */ + + OggFLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC, + /**< The decoder is ready to or is in the process of searching for the frame sync code. */ + + OggFLAC__STREAM_DECODER_READ_FRAME, + /**< The decoder is ready to or is in the process of reading a frame. */ + + OggFLAC__STREAM_DECODER_END_OF_STREAM, + /**< The decoder has reached the end of the stream. */ + + OggFLAC__STREAM_DECODER_ABORTED, + /**< The decoder was aborted by the read callback. */ + + OggFLAC__STREAM_DECODER_UNPARSEABLE_STREAM, + /**< The decoder encountered reserved fields in use in the stream. */ + + OggFLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR, + /**< An error occurred allocating memory. */ + + OggFLAC__STREAM_DECODER_ALREADY_INITIALIZED, + /**< OggFLAC__stream_decoder_init() was called when the decoder was + * already initialized, usually because + * OggFLAC__stream_decoder_finish() was not called. + */ + + OggFLAC__STREAM_DECODER_INVALID_CALLBACK, + /**< OggFLAC__stream_decoder_init() was called without all callbacks being set. */ + + OggFLAC__STREAM_DECODER_UNINITIALIZED + /**< The decoder is in the uninitialized state. */ + +} OggFLAC__StreamDecoderState; + +/** Maps a OggFLAC__StreamDecoderState to a C string. + * + * Using a OggFLAC__StreamDecoderState as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__StreamDecoderStateString[]; + + +/** Return values for the OggFLAC__StreamDecoder read callback. + */ +typedef enum { + + OggFLAC__STREAM_DECODER_READ_STATUS_CONTINUE, + /**< The read was OK and decoding can continue. */ + + OggFLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM, + /**< The read was attempted at the end of the stream. */ + + OggFLAC__STREAM_DECODER_READ_STATUS_ABORT + /**< An unrecoverable error occurred. The decoder will return from the process call. */ + +} OggFLAC__StreamDecoderReadStatus; + +/** Maps a OggFLAC__StreamDecoderReadStatus to a C string. + * + * Using a OggFLAC__StreamDecoderReadStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__StreamDecoderReadStatusString[]; + + +/** Return values for the OggFLAC__StreamDecoder write callback. + */ +typedef enum { + + OggFLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE, + /**< The write was OK and decoding can continue. */ + + OggFLAC__STREAM_DECODER_WRITE_STATUS_ABORT + /**< An unrecoverable error occurred. The decoder will return from the process call. */ + +} OggFLAC__StreamDecoderWriteStatus; + +/** Maps a OggFLAC__StreamDecoderWriteStatus to a C string. + * + * Using a OggFLAC__StreamDecoderWriteStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__StreamDecoderWriteStatusString[]; + + +/** Possible values passed in to the OggFLAC__StreamDecoder error callback. + */ +typedef enum { + + OggFLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC, + /**< An error in the stream caused the decoder to lose synchronization. */ + + OggFLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER, + /**< The decoder encountered a corrupted frame header. */ + + OggFLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH + /**< The frame's data did not match the CRC in the footer. */ + +} OggFLAC__StreamDecoderErrorStatus; + +/** Maps a OggFLAC__StreamDecoderErrorStatus to a C string. + * + * Using a OggFLAC__StreamDecoderErrorStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__StreamDecoderErrorStatusString[]; + + +/*********************************************************************** + * + * class OggFLAC__StreamDecoder + * + ***********************************************************************/ + +struct OggFLAC__StreamDecoderProtected; +struct OggFLAC__StreamDecoderPrivate; +/** The opaque structure definition for the stream decoder type. + * See the \link oggflac_stream_decoder stream decoder module \endlink + * for a detailed description. + */ +typedef struct { + struct OggFLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */ + struct OggFLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */ +} OggFLAC__StreamDecoder; + +typedef OggFLAC__StreamDecoderReadStatus (*OggFLAC__StreamDecoderReadCallback)(const OggFLAC__StreamDecoder *decoder, FLAC__byte buffer[], unsigned *bytes, void *client_data); +typedef OggFLAC__StreamDecoderWriteStatus (*OggFLAC__StreamDecoderWriteCallback)(const OggFLAC__StreamDecoder *decoder, const OggFLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); +typedef void (*OggFLAC__StreamDecoderMetadataCallback)(const OggFLAC__StreamDecoder *decoder, const OggFLAC__StreamMetadata *metadata, void *client_data); +typedef void (*OggFLAC__StreamDecoderErrorCallback)(const OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderErrorStatus status, void *client_data); + + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +/** Create a new stream decoder instance. The instance is created with + * default settings; see the individual OggFLAC__stream_decoder_set_*() + * functions for each setting's default. + * + * \retval OggFLAC__StreamDecoder* + * \c NULL if there was an error allocating memory, else the new instance. + */ +OggFLAC__StreamDecoder *OggFLAC__stream_decoder_new(); + +/** Free a decoder instance. Deletes the object pointed to by \a decoder. + * + * \param decoder A pointer to an existing decoder. + * \assert + * \code decoder != NULL \endcode + */ +void OggFLAC__stream_decoder_delete(OggFLAC__StreamDecoder *decoder); + + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/** Set the read callback. + * The supplied function will be called when the decoder needs more input + * data. The address of the buffer to be filled is supplied, along with + * the number of bytes the buffer can hold. The callback may choose to + * supply less data and modify the byte count but must be careful not to + * overflow the buffer. The callback then returns a status code chosen + * from OggFLAC__StreamDecoderReadStatus. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_read_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderReadCallback); + +/** Set the write callback. + * The supplied function will be called when the decoder has decoded a + * single frame of data. The decoder will pass the frame metadata as + * well as an array of pointers (one for each channel) pointing to the + * decoded audio. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_write_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderWriteCallback); + +/** Set the metadata callback. + * The supplied function will be called when the decoder has decoded a + * metadata block. There will always be one STREAMINFO block per stream, + * followed by zero or more other metadata blocks. These will be supplied + * by the decoder in the same order as they appear in the stream and always + * before the first audio frame (i.e. write callback). The metadata block + * that is passed in must not be modified, and it doesn't live beyond the + * callback, so you should make a copy of it with + * OggFLAC__metadata_object_clone() if you will need it elsewhere. Since + * metadata blocks can potentially be large, by default the decoder only + * calls the metadata callback for the STREAMINFO block; you can instruct + * the decoder to pass or filter other blocks with + * OggFLAC__stream_decoder_set_metadata_*() calls. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderMetadataCallback); + +/** Set the error callback. + * The supplied function will be called whenever an error occurs during + * decoding. + * + * \note + * The callback is mandatory and must be set before initialization. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \code value != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_error_callback(OggFLAC__StreamDecoder *decoder, OggFLAC__StreamDecoderErrorCallback); + +/** Set the client data to be passed back to callbacks. + * This value will be supplied to callbacks in their \a client_data + * argument. + * + * \default \c NULL + * \param decoder An decoder instance to set. + * \param value See above. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_client_data(OggFLAC__StreamDecoder *decoder, void *value); + +/** Direct the decoder to pass on all metadata blocks of type \a type. + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param type See above. + * \assert + * \code decoder != NULL \endcode + * \a type is valid + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_respond(OggFLAC__StreamDecoder *decoder, OggFLAC__MetadataType type); + +/** Direct the decoder to pass on all APPLICATION metadata blocks of the + * given \a id. + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param id See above. + * \assert + * \code decoder != NULL \endcode + * \code id != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]); + +/** Direct the decoder to pass on all metadata blocks of any type. + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_respond_all(OggFLAC__StreamDecoder *decoder); + +/** Direct the decoder to filter out all metadata blocks of type \a type. + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param type See above. + * \assert + * \code decoder != NULL \endcode + * \a type is valid + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore(OggFLAC__StreamDecoder *decoder, OggFLAC__MetadataType type); + +/** Direct the decoder to filter out all APPLICATION metadata blocks of + * the given \a id. + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \param id See above. + * \assert + * \code decoder != NULL \endcode + * \code id != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_application(OggFLAC__StreamDecoder *decoder, const FLAC__byte id[4]); + +/** Direct the decoder to filter out all metadata blocks of any type. + * + * \default By default, only the \c STREAMINFO block is returned via the + * metadata callback. + * \param decoder A decoder instance to set. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c false if the decoder is already initialized, else \c true. + */ +FLAC__bool OggFLAC__stream_decoder_set_metadata_ignore_all(OggFLAC__StreamDecoder *decoder); + +/** Get the current decoder state. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__StreamDecoderState + * The current decoder state. + */ +OggFLAC__StreamDecoderState OggFLAC__stream_decoder_get_state(const OggFLAC__StreamDecoder *decoder); + +/** Get the current number of channels in the stream being decoded. + * Will only be valid after decoding has started and will contain the + * value from the most recently decoded frame header. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__stream_decoder_get_channels(const OggFLAC__StreamDecoder *decoder); + +/** Get the current channel assignment in the stream being decoded. + * Will only be valid after decoding has started and will contain the + * value from the most recently decoded frame header. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__ChannelAssignment + * See above. + */ +OggFLAC__ChannelAssignment OggFLAC__stream_decoder_get_channel_assignment(const OggFLAC__StreamDecoder *decoder); + +/** Get the current sample resolution in the stream being decoded. + * Will only be valid after decoding has started and will contain the + * value from the most recently decoded frame header. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__stream_decoder_get_bits_per_sample(const OggFLAC__StreamDecoder *decoder); + +/** Get the current sample rate in Hz of the stream being decoded. + * Will only be valid after decoding has started and will contain the + * value from the most recently decoded frame header. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__stream_decoder_get_sample_rate(const OggFLAC__StreamDecoder *decoder); + +/** Get the current blocksize of the stream being decoded. + * Will only be valid after decoding has started and will contain the + * value from the most recently decoded frame header. + * + * \param decoder A decoder instance to query. + * \assert + * \code decoder != NULL \endcode + * \retval unsigned + * See above. + */ +unsigned OggFLAC__stream_decoder_get_blocksize(const OggFLAC__StreamDecoder *decoder); + +/** Initialize the decoder instance. + * Should be called after OggFLAC__stream_decoder_new() and + * OggFLAC__stream_decoder_set_*() but before any of the + * OggFLAC__stream_decoder_process_*() functions. Will set and return the + * decoder state, which will be OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA + * if initialization succeeded. + * + * \param decoder An uninitialized decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval OggFLAC__StreamDecoderState + * \c OggFLAC__STREAM_DECODER_SEARCH_FOR_MEATADATA if initialization was + * successful; see OggFLAC__StreamDecoderState for the meanings of other + * return values. + */ +OggFLAC__StreamDecoderState OggFLAC__stream_decoder_init(OggFLAC__StreamDecoder *decoder); + +/** Finish the decoding process. + * Flushes the decoding buffer, releases resources, resets the decoder + * settings to their defaults, and returns the decoder state to + * OggFLAC__STREAM_DECODER_UNINITIALIZED. + * + * In the event of a prematurely-terminated decode, it is not strictly + * necessary to call this immediately before OggFLAC__stream_decoder_delete() + * but it is good practice to match every OggFLAC__stream_decoder_init() + * with a OggFLAC__stream_decoder_finish(). + * + * \param decoder An uninitialized decoder instance. + * \assert + * \code decoder != NULL \endcode + */ +void OggFLAC__stream_decoder_finish(OggFLAC__StreamDecoder *decoder); + +/** Flush the stream input. + * The decoder's input buffer will be cleared and the state set to + * \c OggFLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC. + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c true if successful, else \c false if a memory allocation + * error occurs. + */ +FLAC__bool OggFLAC__stream_decoder_flush(OggFLAC__StreamDecoder *decoder); + +/** Reset the decoding process. + * The decoder's input buffer will be cleared and the state set to + * \c OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA. This is similar to + * OggFLAC__stream_decoder_finish() except that the settings are + * preserved; there is no need to call OggFLAC__stream_decoder_init() + * before decoding again. + * + * \param decoder A decoder instance. + * \assert + * \code decoder != NULL \endcode + * \retval FLAC__bool + * \c true if successful, else \c false if a memory allocation + * error occurs. + */ +FLAC__bool OggFLAC__stream_decoder_reset(OggFLAC__StreamDecoder *decoder); + +/** Decode one metadata block or audio frame. + * This version instructs the decoder to decode a either a single metadata + * block or a single frame and stop, unless the callbacks return a fatal + * error or the read callback returns + * \c OggFLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. + * + * As the decoder needs more input it will call the read callback. + * Depending on what was decoded, the metadata or write callback will be + * called with the decoded metadata block or audio frame, unless an error + * occurred. If the decoder loses sync it will call the error callback + * instead. + * + * \param decoder An initialized decoder instance in the state + * \c OggFLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC. + * \assert + * \code decoder != NULL \endcode + * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC \endcode + * \retval FLAC__bool + * \c false if any read or write error occurred (except + * \c OggFLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c false; + * in any case, check the decoder state with + * OggFLAC__stream_decoder_get_state() to see what went wrong or to + * check for lost synchronization (a sign of stream corruption). + */ +FLAC__bool OggFLAC__stream_decoder_process_single(OggFLAC__StreamDecoder *decoder); + +/** Decode until the end of the metadata. + * This version instructs the decoder to decode from the current position + * and continue until all the metadata has been read, or until the + * callbacks return a fatal error or the read callback returns + * \c OggFLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM. + * + * As the decoder needs more input it will call the read callback. + * As each metadata block is decoded, the metadata callback will be called + * with the decoded metadata. If the decoder loses sync it will call the + * error callback. + * + * \param decoder An initialized decoder instance in the state + * \c OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA. + * \assert + * \code decoder != NULL \endcode + * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA \endcode + * \retval FLAC__bool + * \c false if any read or write error occurred (except + * \c OggFLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c false; + * in any case, check the decoder state with + * OggFLAC__stream_decoder_get_state() to see what went wrong or to + * check for lost synchronization (a sign of stream corruption). + */ +FLAC__bool OggFLAC__stream_decoder_process_until_end_of_metadata(OggFLAC__StreamDecoder *decoder); + +/** Decode until the end of the stream. + * This version instructs the decoder to decode from the current position + * and continue until the end of stream (the read callback returns + * \c OggFLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM), or until the + * callbacks return a fatal error. + * + * As the decoder needs more input it will call the read callback. + * As each metadata block and frame is decoded, the metadata or write + * callback will be called with the decoded metadata or frame. If the + * decoder loses sync it will call the error callback. + * + * \param decoder An initialized decoder instance in the state + * \c OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA. + * \assert + * \code decoder != NULL \endcode + * \code OggFLAC__stream_decoder_get_state(decoder) == OggFLAC__STREAM_DECODER_SEARCH_FOR_METADATA \endcode + * \retval FLAC__bool + * \c false if any read or write error occurred (except + * \c OggFLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC), else \c false; + * in any case, check the decoder state with + * OggFLAC__stream_decoder_get_state() to see what went wrong or to + * check for lost synchronization (a sign of stream corruption). + */ +FLAC__bool OggFLAC__stream_decoder_process_until_end_of_stream(OggFLAC__StreamDecoder *decoder); + +/* \} */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/OggFLAC/stream_encoder.h b/include/OggFLAC/stream_encoder.h new file mode 100644 index 00000000..70f742fc --- /dev/null +++ b/include/OggFLAC/stream_encoder.h @@ -0,0 +1,377 @@ +/* libOggFLAC - Free Lossless Audio Codec + Ogg library + * Copyright (C) 2002 Josh Coalson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef OggFLAC__STREAM_ENCODER_H +#define OggFLAC__STREAM_ENCODER_H + +#include "FLAC/stream_encoder.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** \file include/OggFLAC/stream_encoder.h + * + * \brief + * This module contains the functions which implement the stream + * encoder. + * + * See the detailed documentation in the + * \link oggflac_stream_encoder stream encoder \endlink module. + */ + +/** \defgroup oggflac_encoder OggFLAC/ *_encoder.h: encoder interfaces + * \ingroup oggflac + * + * \brief + * This module describes the three encoder layers provided by libOggFLAC. + * + * libOggFLAC provides the same three layers of access as libFLAC and the + * interface is identical. See the \link flac_encoder FLAC encoder module + * \endlink for full documentation. + */ + +/** \defgroup oggflac_stream_encoder OggFLAC/stream_encoder.h: stream encoder interface + * \ingroup oggflac_encoder + * + * \brief + * This module contains the functions which implement the stream + * encoder. + * + * The interface here is identical to FLAC's stream encoder. See the + * defaults, including the callbacks. See the \link flac_stream_encoder + * FLAC stream encoder module \endlink for full documentation. + * \{ + */ + + +/** State values for a OggFLAC__StreamEncoder + * + * The encoder's state can be obtained by calling OggFLAC__stream_encoder_get_state(). + */ +typedef enum { + + OggFLAC__STREAM_ENCODER_OK = 0, + /**< The encoder is in the normal OK state. */ + + OggFLAC__STREAM_ENCODER_FLAC_ENCODER_ERROR, + /**< An error occurred in the underlying FLAC stream encoder; + * check OggFLAC__stream_encoder_get_FLAC_encoder_state(). + */ + + OggFLAC__STREAM_ENCODER_INVALID_CALLBACK, + /**< The encoder was initialized before setting all the required callbacks. */ + + OggFLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR, + /**< Memory allocation failed. */ + + OggFLAC__STREAM_ENCODER_ALREADY_INITIALIZED, + /**< OggFLAC__stream_encoder_init() was called when the encoder was + * already initialized, usually because + * OggFLAC__stream_encoder_finish() was not called. + */ + + OggFLAC__STREAM_ENCODER_UNINITIALIZED + /**< The encoder is in the uninitialized state. */ + +} OggFLAC__StreamEncoderState; + +/** Maps an OggFLAC__StreamEncoderState to a C string. + * + * Using a OggFLAC__StreamEncoderState as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__StreamEncoderStateString[]; + +/** Return values for the OggFLAC__StreamEncoder write callback. + */ +typedef enum { + + OggFLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0, + /**< The write was OK and encoding can continue. */ + + OggFLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR + /**< An unrecoverable error occurred. The encoder will return from the process call. */ + +} OggFLAC__StreamEncoderWriteStatus; + +/** Maps an OggFLAC__StreamEncoderWriteStatus to a C string. + * + * Using a OggFLAC__StreamEncoderWriteStatus as the index to this array + * will give the string equivalent. The contents should not be modified. + */ +extern const char * const OggFLAC__StreamEncoderWriteStatusString[]; + + +/*********************************************************************** + * + * class OggFLAC__StreamEncoder + * + ***********************************************************************/ + +struct OggFLAC__StreamEncoderProtected; +struct OggFLAC__StreamEncoderPrivate; +/** The opaque structure definition for the stream encoder type. + * See the \link oggflac_stream_encoder stream encoder module \endlink + * for a detailed description. + */ +typedef struct { + struct OggFLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */ + struct OggFLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */ +} OggFLAC__StreamEncoder; + +/*@@@@ document: */ +typedef OggFLAC__StreamEncoderWriteStatus (*OggFLAC__StreamEncoderWriteCallback)(const OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data); +typedef void (*OggFLAC__StreamEncoderMetadataCallback)(const OggFLAC__StreamEncoder *encoder, const OggFLAC__StreamMetadata *metadata, void *client_data); + + +/*********************************************************************** + * + * Class constructor/destructor + * + ***********************************************************************/ + +/** Create a new stream encoder instance. The instance is created with + * default settings; see the individual OggFLAC__stream_encoder_set_*() + * functions for each setting's default. + * + * \retval OggFLAC__StreamEncoder* + * \c NULL if there was an error allocating memory, else the new instance. + */ +OggFLAC__StreamEncoder *OggFLAC__stream_encoder_new(); + +/** Free an encoder instance. Deletes the object pointed to by \a encoder. + * + * \param encoder A pointer to an existing encoder. + * \assert + * \code encoder != NULL \endcode + */ +void OggFLAC__stream_encoder_delete(OggFLAC__StreamEncoder *encoder); + +/*********************************************************************** + * + * Public class method prototypes + * + ***********************************************************************/ + +/** Inherited from FLAC__stream_encoder_set_verify() + */ +FLAC__bool OggFLAC__stream_encoder_set_verify(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_streamable_subset() + */ +FLAC__bool OggFLAC__stream_encoder_set_streamable_subset(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_do_mid_side_stereo() + */ +FLAC__bool OggFLAC__stream_encoder_set_do_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_loose_mid_side_stereo() + */ +FLAC__bool OggFLAC__stream_encoder_set_loose_mid_side_stereo(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_channels() + */ +FLAC__bool OggFLAC__stream_encoder_set_channels(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_bits_per_sample() + */ +FLAC__bool OggFLAC__stream_encoder_set_bits_per_sample(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_sample_rate() + */ +FLAC__bool OggFLAC__stream_encoder_set_sample_rate(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_blocksize() + */ +FLAC__bool OggFLAC__stream_encoder_set_blocksize(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_max_lpc_order() + */ +FLAC__bool OggFLAC__stream_encoder_set_max_lpc_order(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_qlp_coeff_precision() + */ +FLAC__bool OggFLAC__stream_encoder_set_qlp_coeff_precision(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_do_qlp_coeff_prec_search() + */ +FLAC__bool OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_do_escape_coding() + */ +FLAC__bool OggFLAC__stream_encoder_set_do_escape_coding(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_do_exhaustive_model_search() + */ +FLAC__bool OggFLAC__stream_encoder_set_do_exhaustive_model_search(OggFLAC__StreamEncoder *encoder, FLAC__bool value); + +/** Inherited from FLAC__stream_encoder_set_min_residual_partition_order() + */ +FLAC__bool OggFLAC__stream_encoder_set_min_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_max_residual_partition_order() + */ +FLAC__bool OggFLAC__stream_encoder_set_max_residual_partition_order(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_rice_parameter_search_dist() + */ +FLAC__bool OggFLAC__stream_encoder_set_rice_parameter_search_dist(OggFLAC__StreamEncoder *encoder, unsigned value); + +/** Inherited from FLAC__stream_encoder_set_total_samples_estimate() + */ +FLAC__bool OggFLAC__stream_encoder_set_total_samples_estimate(OggFLAC__StreamEncoder *encoder, FLAC__uint64 value); + +/** Inherited from FLAC__stream_encoder_set_metadata() + */ +FLAC__bool OggFLAC__stream_encoder_set_metadata(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamMetadata **metadata, unsigned num_blocks); + +/** Inherited from FLAC__stream_encoder_set_write_callback() + */ +FLAC__bool OggFLAC__stream_encoder_set_write_callback(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamEncoderWriteCallback value); + +/** Inherited from FLAC__stream_encoder_set_metadata_callback() + */ +FLAC__bool OggFLAC__stream_encoder_set_metadata_callback(OggFLAC__StreamEncoder *encoder, OggFLAC__StreamEncoderMetadataCallback value); + +/** Inherited from FLAC__stream_encoder_set_client_data() + */ +FLAC__bool OggFLAC__stream_encoder_set_client_data(OggFLAC__StreamEncoder *encoder, void *value); + +/** Inherited from FLAC__stream_encoder_get_state() + */ +OggFLAC__StreamEncoderState OggFLAC__stream_encoder_get_state(const OggFLAC__StreamEncoder *encoder); + +/** Get the state of the underlying FLAC encoder. + * Useful when the stream encoder state is + * \c OggFLAC__STREAM_ENCODER_FLAC_ENCODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__StreamEncoderState + * The stream encoder state. + */ +FLAC__StreamEncoderState OggFLAC__stream_encoder_get_FLAC_encoder_state(const OggFLAC__StreamEncoder *encoder); + +/** Get the state of the FLAC encoder's verify decoder. + * Useful when the stream encoder state is + * \c OggFLAC__STREAM_ENCODER_FLAC_ENCODER_ERROR and the + * FLAC encoder state is \c OggFLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR. + * + * \param encoder An encoder instance to query. + * \assert + * \code encoder != NULL \endcode + * \retval FLAC__StreamDecoderState + * The stream encoder state. + */ +FLAC__StreamDecoderState OggFLAC__stream_encoder_get_verify_decoder_state(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_verify() + */ +FLAC__bool OggFLAC__stream_encoder_get_verify(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_streamable_subset() + */ +FLAC__bool OggFLAC__stream_encoder_get_streamable_subset(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_do_mid_side_stereo() + */ +FLAC__bool OggFLAC__stream_encoder_get_do_mid_side_stereo(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_loose_mid_side_stereo() + */ +FLAC__bool OggFLAC__stream_encoder_get_loose_mid_side_stereo(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_channels() + */ +unsigned OggFLAC__stream_encoder_get_channels(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_bits_per_sample() + */ +unsigned OggFLAC__stream_encoder_get_bits_per_sample(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_sample_rate() + */ +unsigned OggFLAC__stream_encoder_get_sample_rate(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_blocksize() + */ +unsigned OggFLAC__stream_encoder_get_blocksize(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_max_lpc_order() + */ +unsigned OggFLAC__stream_encoder_get_max_lpc_order(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_qlp_coeff_precision() + */ +unsigned OggFLAC__stream_encoder_get_qlp_coeff_precision(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_do_qlp_coeff_prec_search() + */ +FLAC__bool OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_do_escape_coding() + */ +FLAC__bool OggFLAC__stream_encoder_get_do_escape_coding(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_do_exhaustive_model_search() + */ +FLAC__bool OggFLAC__stream_encoder_get_do_exhaustive_model_search(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_min_residual_partition_order() + */ +unsigned OggFLAC__stream_encoder_get_min_residual_partition_order(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_max_residual_partition_order() + */ +unsigned OggFLAC__stream_encoder_get_max_residual_partition_order(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_rice_parameter_search_dist() + */ +unsigned OggFLAC__stream_encoder_get_rice_parameter_search_dist(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_get_total_samples_estimate() + */ +FLAC__uint64 OggFLAC__stream_encoder_get_total_samples_estimate(const OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_init() + */ +OggFLAC__StreamEncoderState OggFLAC__stream_encoder_init(OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_finish() + */ +void OggFLAC__stream_encoder_finish(OggFLAC__StreamEncoder *encoder); + +/** Inherited from FLAC__stream_encoder_process() + */ +FLAC__bool OggFLAC__stream_encoder_process(OggFLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples); + +/** Inherited from FLAC__stream_encoder_process_interleaved() + */ +FLAC__bool OggFLAC__stream_encoder_process_interleaved(OggFLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples); + +/* \} */ + +#ifdef __cplusplus +} +#endif + +#endif