annotate src/flac-1.2.1/include/FLAC/callback.h @ 1:05aa0afa9217

Bring in flac, ogg, vorbis
author Chris Cannam
date Tue, 19 Mar 2013 17:37:49 +0000
parents
children
rev   line source
Chris@1 1 /* libFLAC - Free Lossless Audio Codec library
Chris@1 2 * Copyright (C) 2004,2005,2006,2007 Josh Coalson
Chris@1 3 *
Chris@1 4 * Redistribution and use in source and binary forms, with or without
Chris@1 5 * modification, are permitted provided that the following conditions
Chris@1 6 * are met:
Chris@1 7 *
Chris@1 8 * - Redistributions of source code must retain the above copyright
Chris@1 9 * notice, this list of conditions and the following disclaimer.
Chris@1 10 *
Chris@1 11 * - Redistributions in binary form must reproduce the above copyright
Chris@1 12 * notice, this list of conditions and the following disclaimer in the
Chris@1 13 * documentation and/or other materials provided with the distribution.
Chris@1 14 *
Chris@1 15 * - Neither the name of the Xiph.org Foundation nor the names of its
Chris@1 16 * contributors may be used to endorse or promote products derived from
Chris@1 17 * this software without specific prior written permission.
Chris@1 18 *
Chris@1 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@1 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Chris@1 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Chris@1 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
Chris@1 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@1 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@1 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
Chris@1 26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
Chris@1 27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Chris@1 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Chris@1 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@1 30 */
Chris@1 31
Chris@1 32 #ifndef FLAC__CALLBACK_H
Chris@1 33 #define FLAC__CALLBACK_H
Chris@1 34
Chris@1 35 #include "ordinals.h"
Chris@1 36 #include <stdlib.h> /* for size_t */
Chris@1 37
Chris@1 38 /** \file include/FLAC/callback.h
Chris@1 39 *
Chris@1 40 * \brief
Chris@1 41 * This module defines the structures for describing I/O callbacks
Chris@1 42 * to the other FLAC interfaces.
Chris@1 43 *
Chris@1 44 * See the detailed documentation for callbacks in the
Chris@1 45 * \link flac_callbacks callbacks \endlink module.
Chris@1 46 */
Chris@1 47
Chris@1 48 /** \defgroup flac_callbacks FLAC/callback.h: I/O callback structures
Chris@1 49 * \ingroup flac
Chris@1 50 *
Chris@1 51 * \brief
Chris@1 52 * This module defines the structures for describing I/O callbacks
Chris@1 53 * to the other FLAC interfaces.
Chris@1 54 *
Chris@1 55 * The purpose of the I/O callback functions is to create a common way
Chris@1 56 * for the metadata interfaces to handle I/O.
Chris@1 57 *
Chris@1 58 * Originally the metadata interfaces required filenames as the way of
Chris@1 59 * specifying FLAC files to operate on. This is problematic in some
Chris@1 60 * environments so there is an additional option to specify a set of
Chris@1 61 * callbacks for doing I/O on the FLAC file, instead of the filename.
Chris@1 62 *
Chris@1 63 * In addition to the callbacks, a FLAC__IOHandle type is defined as an
Chris@1 64 * opaque structure for a data source.
Chris@1 65 *
Chris@1 66 * The callback function prototypes are similar (but not identical) to the
Chris@1 67 * stdio functions fread, fwrite, fseek, ftell, feof, and fclose. If you use
Chris@1 68 * stdio streams to implement the callbacks, you can pass fread, fwrite, and
Chris@1 69 * fclose anywhere a FLAC__IOCallback_Read, FLAC__IOCallback_Write, or
Chris@1 70 * FLAC__IOCallback_Close is required, and a FILE* anywhere a FLAC__IOHandle
Chris@1 71 * is required. \warning You generally CANNOT directly use fseek or ftell
Chris@1 72 * for FLAC__IOCallback_Seek or FLAC__IOCallback_Tell since on most systems
Chris@1 73 * these use 32-bit offsets and FLAC requires 64-bit offsets to deal with
Chris@1 74 * large files. You will have to find an equivalent function (e.g. ftello),
Chris@1 75 * or write a wrapper. The same is true for feof() since this is usually
Chris@1 76 * implemented as a macro, not as a function whose address can be taken.
Chris@1 77 *
Chris@1 78 * \{
Chris@1 79 */
Chris@1 80
Chris@1 81 #ifdef __cplusplus
Chris@1 82 extern "C" {
Chris@1 83 #endif
Chris@1 84
Chris@1 85 /** This is the opaque handle type used by the callbacks. Typically
Chris@1 86 * this is a \c FILE* or address of a file descriptor.
Chris@1 87 */
Chris@1 88 typedef void* FLAC__IOHandle;
Chris@1 89
Chris@1 90 /** Signature for the read callback.
Chris@1 91 * The signature and semantics match POSIX fread() implementations
Chris@1 92 * and can generally be used interchangeably.
Chris@1 93 *
Chris@1 94 * \param ptr The address of the read buffer.
Chris@1 95 * \param size The size of the records to be read.
Chris@1 96 * \param nmemb The number of records to be read.
Chris@1 97 * \param handle The handle to the data source.
Chris@1 98 * \retval size_t
Chris@1 99 * The number of records read.
Chris@1 100 */
Chris@1 101 typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
Chris@1 102
Chris@1 103 /** Signature for the write callback.
Chris@1 104 * The signature and semantics match POSIX fwrite() implementations
Chris@1 105 * and can generally be used interchangeably.
Chris@1 106 *
Chris@1 107 * \param ptr The address of the write buffer.
Chris@1 108 * \param size The size of the records to be written.
Chris@1 109 * \param nmemb The number of records to be written.
Chris@1 110 * \param handle The handle to the data source.
Chris@1 111 * \retval size_t
Chris@1 112 * The number of records written.
Chris@1 113 */
Chris@1 114 typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
Chris@1 115
Chris@1 116 /** Signature for the seek callback.
Chris@1 117 * The signature and semantics mostly match POSIX fseek() WITH ONE IMPORTANT
Chris@1 118 * EXCEPTION: the offset is a 64-bit type whereas fseek() is generally 'long'
Chris@1 119 * and 32-bits wide.
Chris@1 120 *
Chris@1 121 * \param handle The handle to the data source.
Chris@1 122 * \param offset The new position, relative to \a whence
Chris@1 123 * \param whence \c SEEK_SET, \c SEEK_CUR, or \c SEEK_END
Chris@1 124 * \retval int
Chris@1 125 * \c 0 on success, \c -1 on error.
Chris@1 126 */
Chris@1 127 typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
Chris@1 128
Chris@1 129 /** Signature for the tell callback.
Chris@1 130 * The signature and semantics mostly match POSIX ftell() WITH ONE IMPORTANT
Chris@1 131 * EXCEPTION: the offset is a 64-bit type whereas ftell() is generally 'long'
Chris@1 132 * and 32-bits wide.
Chris@1 133 *
Chris@1 134 * \param handle The handle to the data source.
Chris@1 135 * \retval FLAC__int64
Chris@1 136 * The current position on success, \c -1 on error.
Chris@1 137 */
Chris@1 138 typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
Chris@1 139
Chris@1 140 /** Signature for the EOF callback.
Chris@1 141 * The signature and semantics mostly match POSIX feof() but WATCHOUT:
Chris@1 142 * on many systems, feof() is a macro, so in this case a wrapper function
Chris@1 143 * must be provided instead.
Chris@1 144 *
Chris@1 145 * \param handle The handle to the data source.
Chris@1 146 * \retval int
Chris@1 147 * \c 0 if not at end of file, nonzero if at end of file.
Chris@1 148 */
Chris@1 149 typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
Chris@1 150
Chris@1 151 /** Signature for the close callback.
Chris@1 152 * The signature and semantics match POSIX fclose() implementations
Chris@1 153 * and can generally be used interchangeably.
Chris@1 154 *
Chris@1 155 * \param handle The handle to the data source.
Chris@1 156 * \retval int
Chris@1 157 * \c 0 on success, \c EOF on error.
Chris@1 158 */
Chris@1 159 typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
Chris@1 160
Chris@1 161 /** A structure for holding a set of callbacks.
Chris@1 162 * Each FLAC interface that requires a FLAC__IOCallbacks structure will
Chris@1 163 * describe which of the callbacks are required. The ones that are not
Chris@1 164 * required may be set to NULL.
Chris@1 165 *
Chris@1 166 * If the seek requirement for an interface is optional, you can signify that
Chris@1 167 * a data sorce is not seekable by setting the \a seek field to \c NULL.
Chris@1 168 */
Chris@1 169 typedef struct {
Chris@1 170 FLAC__IOCallback_Read read;
Chris@1 171 FLAC__IOCallback_Write write;
Chris@1 172 FLAC__IOCallback_Seek seek;
Chris@1 173 FLAC__IOCallback_Tell tell;
Chris@1 174 FLAC__IOCallback_Eof eof;
Chris@1 175 FLAC__IOCallback_Close close;
Chris@1 176 } FLAC__IOCallbacks;
Chris@1 177
Chris@1 178 /* \} */
Chris@1 179
Chris@1 180 #ifdef __cplusplus
Chris@1 181 }
Chris@1 182 #endif
Chris@1 183
Chris@1 184 #endif