flac_FLAC_callback.h 7.0 KB

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