Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

callback.h 7.2KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* libFLAC - Free Lossless Audio Codec library
  2. * Copyright (C) 2004-2009 Josh Coalson
  3. * Copyright (C) 2011-2014 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. #ifndef FLAC__CALLBACK_H
  33. #define FLAC__CALLBACK_H
  34. #include "ordinals.h"
  35. #include <stdlib.h> /* for size_t */
  36. /** \file include/FLAC/callback.h
  37. *
  38. * \brief
  39. * This module defines the structures for describing I/O callbacks
  40. * to the other FLAC interfaces.
  41. *
  42. * See the detailed documentation for callbacks in the
  43. * \link flac_callbacks callbacks \endlink module.
  44. */
  45. /** \defgroup flac_callbacks FLAC/callback.h: I/O callback structures
  46. * \ingroup flac
  47. *
  48. * \brief
  49. * This module defines the structures for describing I/O callbacks
  50. * to the other FLAC interfaces.
  51. *
  52. * The purpose of the I/O callback functions is to create a common way
  53. * for the metadata interfaces to handle I/O.
  54. *
  55. * Originally the metadata interfaces required filenames as the way of
  56. * specifying FLAC files to operate on. This is problematic in some
  57. * environments so there is an additional option to specify a set of
  58. * callbacks for doing I/O on the FLAC file, instead of the filename.
  59. *
  60. * In addition to the callbacks, a FLAC__IOHandle type is defined as an
  61. * opaque structure for a data source.
  62. *
  63. * The callback function prototypes are similar (but not identical) to the
  64. * stdio functions fread, fwrite, fseek, ftell, feof, and fclose. If you use
  65. * stdio streams to implement the callbacks, you can pass fread, fwrite, and
  66. * fclose anywhere a FLAC__IOCallback_Read, FLAC__IOCallback_Write, or
  67. * FLAC__IOCallback_Close is required, and a FILE* anywhere a FLAC__IOHandle
  68. * is required. \warning You generally CANNOT directly use fseek or ftell
  69. * for FLAC__IOCallback_Seek or FLAC__IOCallback_Tell since on most systems
  70. * these use 32-bit offsets and FLAC requires 64-bit offsets to deal with
  71. * large files. You will have to find an equivalent function (e.g. ftello),
  72. * or write a wrapper. The same is true for feof() since this is usually
  73. * implemented as a macro, not as a function whose address can be taken.
  74. *
  75. * \{
  76. */
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif
  80. /** This is the opaque handle type used by the callbacks. Typically
  81. * this is a \c FILE* or address of a file descriptor.
  82. */
  83. typedef void* FLAC__IOHandle;
  84. /** Signature for the read callback.
  85. * The signature and semantics match POSIX fread() implementations
  86. * and can generally be used interchangeably.
  87. *
  88. * \param ptr The address of the read buffer.
  89. * \param size The size of the records to be read.
  90. * \param nmemb The number of records to be read.
  91. * \param handle The handle to the data source.
  92. * \retval size_t
  93. * The number of records read.
  94. */
  95. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  96. /** Signature for the write callback.
  97. * The signature and semantics match POSIX fwrite() implementations
  98. * and can generally be used interchangeably.
  99. *
  100. * \param ptr The address of the write buffer.
  101. * \param size The size of the records to be written.
  102. * \param nmemb The number of records to be written.
  103. * \param handle The handle to the data source.
  104. * \retval size_t
  105. * The number of records written.
  106. */
  107. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  108. /** Signature for the seek callback.
  109. * The signature and semantics mostly match POSIX fseek() WITH ONE IMPORTANT
  110. * EXCEPTION: the offset is a 64-bit type whereas fseek() is generally 'long'
  111. * and 32-bits wide.
  112. *
  113. * \param handle The handle to the data source.
  114. * \param offset The new position, relative to \a whence
  115. * \param whence \c SEEK_SET, \c SEEK_CUR, or \c SEEK_END
  116. * \retval int
  117. * \c 0 on success, \c -1 on error.
  118. */
  119. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  120. /** Signature for the tell callback.
  121. * The signature and semantics mostly match POSIX ftell() WITH ONE IMPORTANT
  122. * EXCEPTION: the offset is a 64-bit type whereas ftell() is generally 'long'
  123. * and 32-bits wide.
  124. *
  125. * \param handle The handle to the data source.
  126. * \retval FLAC__int64
  127. * The current position on success, \c -1 on error.
  128. */
  129. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  130. /** Signature for the EOF callback.
  131. * The signature and semantics mostly match POSIX feof() but WATCHOUT:
  132. * on many systems, feof() is a macro, so in this case a wrapper function
  133. * must be provided instead.
  134. *
  135. * \param handle The handle to the data source.
  136. * \retval int
  137. * \c 0 if not at end of file, nonzero if at end of file.
  138. */
  139. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  140. /** Signature for the close callback.
  141. * The signature and semantics match POSIX fclose() implementations
  142. * and can generally be used interchangeably.
  143. *
  144. * \param handle The handle to the data source.
  145. * \retval int
  146. * \c 0 on success, \c EOF on error.
  147. */
  148. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  149. /** A structure for holding a set of callbacks.
  150. * Each FLAC interface that requires a FLAC__IOCallbacks structure will
  151. * describe which of the callbacks are required. The ones that are not
  152. * required may be set to NULL.
  153. *
  154. * If the seek requirement for an interface is optional, you can signify that
  155. * a data sorce is not seekable by setting the \a seek field to \c NULL.
  156. */
  157. typedef struct {
  158. FLAC__IOCallback_Read read;
  159. FLAC__IOCallback_Write write;
  160. FLAC__IOCallback_Seek seek;
  161. FLAC__IOCallback_Tell tell;
  162. FLAC__IOCallback_Eof eof;
  163. FLAC__IOCallback_Close close;
  164. } FLAC__IOCallbacks;
  165. /* \} */
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif