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