cannam@86: /* libFLAC - Free Lossless Audio Codec library cannam@86: * Copyright (C) 2004,2005,2006,2007 Josh Coalson cannam@86: * cannam@86: * Redistribution and use in source and binary forms, with or without cannam@86: * modification, are permitted provided that the following conditions cannam@86: * are met: cannam@86: * cannam@86: * - Redistributions of source code must retain the above copyright cannam@86: * notice, this list of conditions and the following disclaimer. cannam@86: * cannam@86: * - Redistributions in binary form must reproduce the above copyright cannam@86: * notice, this list of conditions and the following disclaimer in the cannam@86: * documentation and/or other materials provided with the distribution. cannam@86: * cannam@86: * - Neither the name of the Xiph.org Foundation nor the names of its cannam@86: * contributors may be used to endorse or promote products derived from cannam@86: * this software without specific prior written permission. cannam@86: * cannam@86: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS cannam@86: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT cannam@86: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR cannam@86: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR cannam@86: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, cannam@86: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, cannam@86: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR cannam@86: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF cannam@86: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING cannam@86: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS cannam@86: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cannam@86: */ cannam@86: cannam@86: #ifndef FLAC__CALLBACK_H cannam@86: #define FLAC__CALLBACK_H cannam@86: cannam@86: #include "ordinals.h" cannam@86: #include /* for size_t */ cannam@86: cannam@86: /** \file include/FLAC/callback.h cannam@86: * cannam@86: * \brief cannam@86: * This module defines the structures for describing I/O callbacks cannam@86: * to the other FLAC interfaces. cannam@86: * cannam@86: * See the detailed documentation for callbacks in the cannam@86: * \link flac_callbacks callbacks \endlink module. cannam@86: */ cannam@86: cannam@86: /** \defgroup flac_callbacks FLAC/callback.h: I/O callback structures cannam@86: * \ingroup flac cannam@86: * cannam@86: * \brief cannam@86: * This module defines the structures for describing I/O callbacks cannam@86: * to the other FLAC interfaces. cannam@86: * cannam@86: * The purpose of the I/O callback functions is to create a common way cannam@86: * for the metadata interfaces to handle I/O. cannam@86: * cannam@86: * Originally the metadata interfaces required filenames as the way of cannam@86: * specifying FLAC files to operate on. This is problematic in some cannam@86: * environments so there is an additional option to specify a set of cannam@86: * callbacks for doing I/O on the FLAC file, instead of the filename. cannam@86: * cannam@86: * In addition to the callbacks, a FLAC__IOHandle type is defined as an cannam@86: * opaque structure for a data source. cannam@86: * cannam@86: * The callback function prototypes are similar (but not identical) to the cannam@86: * stdio functions fread, fwrite, fseek, ftell, feof, and fclose. If you use cannam@86: * stdio streams to implement the callbacks, you can pass fread, fwrite, and cannam@86: * fclose anywhere a FLAC__IOCallback_Read, FLAC__IOCallback_Write, or cannam@86: * FLAC__IOCallback_Close is required, and a FILE* anywhere a FLAC__IOHandle cannam@86: * is required. \warning You generally CANNOT directly use fseek or ftell cannam@86: * for FLAC__IOCallback_Seek or FLAC__IOCallback_Tell since on most systems cannam@86: * these use 32-bit offsets and FLAC requires 64-bit offsets to deal with cannam@86: * large files. You will have to find an equivalent function (e.g. ftello), cannam@86: * or write a wrapper. The same is true for feof() since this is usually cannam@86: * implemented as a macro, not as a function whose address can be taken. cannam@86: * cannam@86: * \{ cannam@86: */ cannam@86: cannam@86: #ifdef __cplusplus cannam@86: extern "C" { cannam@86: #endif cannam@86: cannam@86: /** This is the opaque handle type used by the callbacks. Typically cannam@86: * this is a \c FILE* or address of a file descriptor. cannam@86: */ cannam@86: typedef void* FLAC__IOHandle; cannam@86: cannam@86: /** Signature for the read callback. cannam@86: * The signature and semantics match POSIX fread() implementations cannam@86: * and can generally be used interchangeably. cannam@86: * cannam@86: * \param ptr The address of the read buffer. cannam@86: * \param size The size of the records to be read. cannam@86: * \param nmemb The number of records to be read. cannam@86: * \param handle The handle to the data source. cannam@86: * \retval size_t cannam@86: * The number of records read. cannam@86: */ cannam@86: typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle); cannam@86: cannam@86: /** Signature for the write callback. cannam@86: * The signature and semantics match POSIX fwrite() implementations cannam@86: * and can generally be used interchangeably. cannam@86: * cannam@86: * \param ptr The address of the write buffer. cannam@86: * \param size The size of the records to be written. cannam@86: * \param nmemb The number of records to be written. cannam@86: * \param handle The handle to the data source. cannam@86: * \retval size_t cannam@86: * The number of records written. cannam@86: */ cannam@86: typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle); cannam@86: cannam@86: /** Signature for the seek callback. cannam@86: * The signature and semantics mostly match POSIX fseek() WITH ONE IMPORTANT cannam@86: * EXCEPTION: the offset is a 64-bit type whereas fseek() is generally 'long' cannam@86: * and 32-bits wide. cannam@86: * cannam@86: * \param handle The handle to the data source. cannam@86: * \param offset The new position, relative to \a whence cannam@86: * \param whence \c SEEK_SET, \c SEEK_CUR, or \c SEEK_END cannam@86: * \retval int cannam@86: * \c 0 on success, \c -1 on error. cannam@86: */ cannam@86: typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence); cannam@86: cannam@86: /** Signature for the tell callback. cannam@86: * The signature and semantics mostly match POSIX ftell() WITH ONE IMPORTANT cannam@86: * EXCEPTION: the offset is a 64-bit type whereas ftell() is generally 'long' cannam@86: * and 32-bits wide. cannam@86: * cannam@86: * \param handle The handle to the data source. cannam@86: * \retval FLAC__int64 cannam@86: * The current position on success, \c -1 on error. cannam@86: */ cannam@86: typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle); cannam@86: cannam@86: /** Signature for the EOF callback. cannam@86: * The signature and semantics mostly match POSIX feof() but WATCHOUT: cannam@86: * on many systems, feof() is a macro, so in this case a wrapper function cannam@86: * must be provided instead. cannam@86: * cannam@86: * \param handle The handle to the data source. cannam@86: * \retval int cannam@86: * \c 0 if not at end of file, nonzero if at end of file. cannam@86: */ cannam@86: typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle); cannam@86: cannam@86: /** Signature for the close callback. cannam@86: * The signature and semantics match POSIX fclose() implementations cannam@86: * and can generally be used interchangeably. cannam@86: * cannam@86: * \param handle The handle to the data source. cannam@86: * \retval int cannam@86: * \c 0 on success, \c EOF on error. cannam@86: */ cannam@86: typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle); cannam@86: cannam@86: /** A structure for holding a set of callbacks. cannam@86: * Each FLAC interface that requires a FLAC__IOCallbacks structure will cannam@86: * describe which of the callbacks are required. The ones that are not cannam@86: * required may be set to NULL. cannam@86: * cannam@86: * If the seek requirement for an interface is optional, you can signify that cannam@86: * a data sorce is not seekable by setting the \a seek field to \c NULL. cannam@86: */ cannam@86: typedef struct { cannam@86: FLAC__IOCallback_Read read; cannam@86: FLAC__IOCallback_Write write; cannam@86: FLAC__IOCallback_Seek seek; cannam@86: FLAC__IOCallback_Tell tell; cannam@86: FLAC__IOCallback_Eof eof; cannam@86: FLAC__IOCallback_Close close; cannam@86: } FLAC__IOCallbacks; cannam@86: cannam@86: /* \} */ cannam@86: cannam@86: #ifdef __cplusplus cannam@86: } cannam@86: #endif cannam@86: cannam@86: #endif