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