samplefmt.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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. * all in native-endian format
  23. */
  24. enum AVSampleFormat {
  25. AV_SAMPLE_FMT_NONE = -1,
  26. AV_SAMPLE_FMT_U8, ///< unsigned 8 bits
  27. AV_SAMPLE_FMT_S16, ///< signed 16 bits
  28. AV_SAMPLE_FMT_S32, ///< signed 32 bits
  29. AV_SAMPLE_FMT_FLT, ///< float
  30. AV_SAMPLE_FMT_DBL, ///< double
  31. AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar
  32. AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar
  33. AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
  34. AV_SAMPLE_FMT_FLTP, ///< float, planar
  35. AV_SAMPLE_FMT_DBLP, ///< double, planar
  36. AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically
  37. };
  38. /**
  39. * Return the name of sample_fmt, or NULL if sample_fmt is not
  40. * recognized.
  41. */
  42. const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
  43. /**
  44. * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
  45. * on error.
  46. */
  47. enum AVSampleFormat av_get_sample_fmt(const char *name);
  48. /**
  49. * Return the planar<->packed alternative form of the given sample format, or
  50. * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the
  51. * requested planar/packed format, the format returned is the same as the
  52. * input.
  53. */
  54. enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar);
  55. /**
  56. * Generate a string corresponding to the sample format with
  57. * sample_fmt, or a header if sample_fmt is negative.
  58. *
  59. * @param buf the buffer where to write the string
  60. * @param buf_size the size of buf
  61. * @param sample_fmt the number of the sample format to print the
  62. * corresponding info string, or a negative value to print the
  63. * corresponding header.
  64. * @return the pointer to the filled buffer or NULL if sample_fmt is
  65. * unknown or in case of other errors
  66. */
  67. char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
  68. #if FF_API_GET_BITS_PER_SAMPLE_FMT
  69. /**
  70. * @deprecated Use av_get_bytes_per_sample() instead.
  71. */
  72. attribute_deprecated
  73. int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
  74. #endif
  75. /**
  76. * Return number of bytes per sample.
  77. *
  78. * @param sample_fmt the sample format
  79. * @return number of bytes per sample or zero if unknown for the given
  80. * sample format
  81. */
  82. int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
  83. /**
  84. * Check if the sample format is planar.
  85. *
  86. * @param sample_fmt the sample format to inspect
  87. * @return 1 if the sample format is planar, 0 if it is interleaved
  88. */
  89. int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
  90. /**
  91. * Get the required buffer size for the given audio parameters.
  92. *
  93. * @param[out] linesize calculated linesize, may be NULL
  94. * @param nb_channels the number of channels
  95. * @param nb_samples the number of samples in a single channel
  96. * @param sample_fmt the sample format
  97. * @return required buffer size, or negative error code on failure
  98. */
  99. int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
  100. enum AVSampleFormat sample_fmt, int align);
  101. /**
  102. * Fill channel data pointers and linesize for samples with sample
  103. * format sample_fmt.
  104. *
  105. * The pointers array is filled with the pointers to the samples data:
  106. * for planar, set the start point of each channel's data within the buffer,
  107. * for packed, set the start point of the entire buffer only.
  108. *
  109. * The linesize array is filled with the aligned size of each channel's data
  110. * buffer for planar layout, or the aligned size of the buffer for all channels
  111. * for packed layout.
  112. *
  113. * @param[out] audio_data array to be filled with the pointer for each channel
  114. * @param[out] linesize calculated linesize
  115. * @param buf the pointer to a buffer containing the samples
  116. * @param nb_channels the number of channels
  117. * @param nb_samples the number of samples in a single channel
  118. * @param sample_fmt the sample format
  119. * @param align buffer size alignment (1 = no alignment required)
  120. * @return 0 on success or a negative error code on failure
  121. */
  122. int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf,
  123. int nb_channels, int nb_samples,
  124. enum AVSampleFormat sample_fmt, int align);
  125. /**
  126. * Allocate a samples buffer for nb_samples samples, and fill data pointers and
  127. * linesize accordingly.
  128. * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
  129. *
  130. * @param[out] audio_data array to be filled with the pointer for each channel
  131. * @param[out] linesize aligned size for audio buffer(s)
  132. * @param nb_channels number of audio channels
  133. * @param nb_samples number of samples per channel
  134. * @param align buffer size alignment (1 = no alignment required)
  135. * @return 0 on success or a negative error code on failure
  136. * @see av_samples_fill_arrays()
  137. */
  138. int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
  139. int nb_samples, enum AVSampleFormat sample_fmt, int align);
  140. #endif /* AVUTIL_SAMPLEFMT_H */