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.

225 lines
8.5KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_SAMPLEFMT_H
  19. #define AVUTIL_SAMPLEFMT_H
  20. #include "avutil.h"
  21. /**
  22. * Audio Sample Formats
  23. *
  24. * @par
  25. * The data described by the sample format is always in native-endian order.
  26. * Sample values can be expressed by native C types, hence the lack of a signed
  27. * 24-bit sample format even though it is a common raw audio data format.
  28. *
  29. * @par
  30. * The floating-point formats are based on full volume being in the range
  31. * [-1.0, 1.0]. Any values outside this range are beyond full volume level.
  32. *
  33. * @par
  34. * The data layout as used in av_samples_fill_arrays() and elsewhere in Libav
  35. * (such as AVFrame in libavcodec) is as follows:
  36. *
  37. * For planar sample formats, each audio channel is in a separate data plane,
  38. * and linesize is the buffer size, in bytes, for a single plane. All data
  39. * planes must be the same size. For packed sample formats, only the first data
  40. * plane is used, and samples for each channel are interleaved. In this case,
  41. * linesize is the buffer size, in bytes, for the 1 plane.
  42. */
  43. enum AVSampleFormat {
  44. AV_SAMPLE_FMT_NONE = -1,
  45. AV_SAMPLE_FMT_U8, ///< unsigned 8 bits
  46. AV_SAMPLE_FMT_S16, ///< signed 16 bits
  47. AV_SAMPLE_FMT_S32, ///< signed 32 bits
  48. AV_SAMPLE_FMT_FLT, ///< float
  49. AV_SAMPLE_FMT_DBL, ///< double
  50. AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar
  51. AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar
  52. AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
  53. AV_SAMPLE_FMT_FLTP, ///< float, planar
  54. AV_SAMPLE_FMT_DBLP, ///< double, planar
  55. AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically
  56. };
  57. /**
  58. * Return the name of sample_fmt, or NULL if sample_fmt is not
  59. * recognized.
  60. */
  61. const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
  62. /**
  63. * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
  64. * on error.
  65. */
  66. enum AVSampleFormat av_get_sample_fmt(const char *name);
  67. /**
  68. * Get the packed alternative form of the given sample format.
  69. *
  70. * If the passed sample_fmt is already in packed format, the format returned is
  71. * the same as the input.
  72. *
  73. * @return the packed alternative form of the given sample format or
  74. AV_SAMPLE_FMT_NONE on error.
  75. */
  76. enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
  77. /**
  78. * Get the planar alternative form of the given sample format.
  79. *
  80. * If the passed sample_fmt is already in planar format, the format returned is
  81. * the same as the input.
  82. *
  83. * @return the planar alternative form of the given sample format or
  84. AV_SAMPLE_FMT_NONE on error.
  85. */
  86. enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
  87. /**
  88. * Generate a string corresponding to the sample format with
  89. * sample_fmt, or a header if sample_fmt is negative.
  90. *
  91. * @param buf the buffer where to write the string
  92. * @param buf_size the size of buf
  93. * @param sample_fmt the number of the sample format to print the
  94. * corresponding info string, or a negative value to print the
  95. * corresponding header.
  96. * @return the pointer to the filled buffer or NULL if sample_fmt is
  97. * unknown or in case of other errors
  98. */
  99. char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
  100. #if FF_API_GET_BITS_PER_SAMPLE_FMT
  101. /**
  102. * @deprecated Use av_get_bytes_per_sample() instead.
  103. */
  104. attribute_deprecated
  105. int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
  106. #endif
  107. /**
  108. * Return number of bytes per sample.
  109. *
  110. * @param sample_fmt the sample format
  111. * @return number of bytes per sample or zero if unknown for the given
  112. * sample format
  113. */
  114. int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
  115. /**
  116. * Check if the sample format is planar.
  117. *
  118. * @param sample_fmt the sample format to inspect
  119. * @return 1 if the sample format is planar, 0 if it is interleaved
  120. */
  121. int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
  122. /**
  123. * Get the required buffer size for the given audio parameters.
  124. *
  125. * @param[out] linesize calculated linesize, may be NULL
  126. * @param nb_channels the number of channels
  127. * @param nb_samples the number of samples in a single channel
  128. * @param sample_fmt the sample format
  129. * @param align buffer size alignment (0 = default, 1 = no alignment)
  130. * @return required buffer size, or negative error code on failure
  131. */
  132. int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
  133. enum AVSampleFormat sample_fmt, int align);
  134. /**
  135. * Fill channel data pointers and linesize for samples with sample
  136. * format sample_fmt.
  137. *
  138. * The pointers array is filled with the pointers to the samples data:
  139. * for planar, set the start point of each channel's data within the buffer,
  140. * for packed, set the start point of the entire buffer only.
  141. *
  142. * The linesize array is filled with the aligned size of each channel's data
  143. * buffer for planar layout, or the aligned size of the buffer for all channels
  144. * for packed layout.
  145. *
  146. * @see enum AVSampleFormat
  147. * The documentation for AVSampleFormat describes the data layout.
  148. *
  149. * @param[out] audio_data array to be filled with the pointer for each channel
  150. * @param[out] linesize calculated linesize, may be NULL
  151. * @param buf the pointer to a buffer containing the samples
  152. * @param nb_channels the number of channels
  153. * @param nb_samples the number of samples in a single channel
  154. * @param sample_fmt the sample format
  155. * @param align buffer size alignment (0 = default, 1 = no alignment)
  156. * @return 0 on success or a negative error code on failure
  157. */
  158. int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
  159. const uint8_t *buf,
  160. int nb_channels, int nb_samples,
  161. enum AVSampleFormat sample_fmt, int align);
  162. /**
  163. * Allocate a samples buffer for nb_samples samples, and fill data pointers and
  164. * linesize accordingly.
  165. * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
  166. *
  167. * @see enum AVSampleFormat
  168. * The documentation for AVSampleFormat describes the data layout.
  169. *
  170. * @param[out] audio_data array to be filled with the pointer for each channel
  171. * @param[out] linesize aligned size for audio buffer(s), may be NULL
  172. * @param nb_channels number of audio channels
  173. * @param nb_samples number of samples per channel
  174. * @param align buffer size alignment (0 = default, 1 = no alignment)
  175. * @return 0 on success or a negative error code on failure
  176. * @see av_samples_fill_arrays()
  177. */
  178. int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
  179. int nb_samples, enum AVSampleFormat sample_fmt, int align);
  180. /**
  181. * Copy samples from src to dst.
  182. *
  183. * @param dst destination array of pointers to data planes
  184. * @param src source array of pointers to data planes
  185. * @param dst_offset offset in samples at which the data will be written to dst
  186. * @param src_offset offset in samples at which the data will be read from src
  187. * @param nb_samples number of samples to be copied
  188. * @param nb_channels number of audio channels
  189. * @param sample_fmt audio sample format
  190. */
  191. int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
  192. int src_offset, int nb_samples, int nb_channels,
  193. enum AVSampleFormat sample_fmt);
  194. /**
  195. * Fill an audio buffer with silence.
  196. *
  197. * @param audio_data array of pointers to data planes
  198. * @param offset offset in samples at which to start filling
  199. * @param nb_samples number of samples to fill
  200. * @param nb_channels number of audio channels
  201. * @param sample_fmt audio sample format
  202. */
  203. int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples,
  204. int nb_channels, enum AVSampleFormat sample_fmt);
  205. #endif /* AVUTIL_SAMPLEFMT_H */