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