samplefmt.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_NB ///< Number of sample formats. DO NOT USE if linking dynamically
  32. };
  33. /**
  34. * Return the name of sample_fmt, or NULL if sample_fmt is not
  35. * recognized.
  36. */
  37. const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
  38. /**
  39. * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
  40. * on error.
  41. */
  42. enum AVSampleFormat av_get_sample_fmt(const char *name);
  43. /**
  44. * Generate a string corresponding to the sample format with
  45. * sample_fmt, or a header if sample_fmt is negative.
  46. *
  47. * @param buf the buffer where to write the string
  48. * @param buf_size the size of buf
  49. * @param sample_fmt the number of the sample format to print the
  50. * corresponding info string, or a negative value to print the
  51. * corresponding header.
  52. * @return the pointer to the filled buffer or NULL if sample_fmt is
  53. * unknown or in case of other errors
  54. */
  55. char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
  56. #if FF_API_GET_BITS_PER_SAMPLE_FMT
  57. /**
  58. * @deprecated Use av_get_bytes_per_sample() instead.
  59. */
  60. attribute_deprecated
  61. int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
  62. #endif
  63. /**
  64. * Return number of bytes per sample.
  65. *
  66. * @param sample_fmt the sample format
  67. * @return number of bytes per sample or zero if unknown for the given
  68. * sample format
  69. */
  70. int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
  71. /**
  72. * Fill channel data pointers and linesizes for samples with sample
  73. * format sample_fmt.
  74. *
  75. * The pointers array is filled with the pointers to the samples data:
  76. * for planar, set the start point of each plane's data within the buffer,
  77. * for packed, set the start point of the entire buffer only.
  78. *
  79. * The linesize array is filled with the aligned size of each samples
  80. * plane, that is linesize[i] will contain the linesize of the plane i,
  81. * and will be zero for all the unused planes. All linesize values are
  82. * equal.
  83. *
  84. * @param pointers array to be filled with the pointer for each plane, may be NULL
  85. * @param linesizes array to be filled with the linesize, may be NULL
  86. * @param buf the pointer to a buffer containing the samples
  87. * @param nb_samples the number of samples in a single channel
  88. * @param planar 1 if the samples layout is planar, 0 if it is packed
  89. * @param nb_channels the number of channels
  90. * @return the total size of the buffer, a negative
  91. * error code in case of failure
  92. */
  93. int av_samples_fill_arrays(uint8_t *pointers[8], int linesizes[8],
  94. uint8_t *buf, int nb_channels, int nb_samples,
  95. enum AVSampleFormat sample_fmt, int planar, int align);
  96. /**
  97. * Allocate a samples buffer for nb_samples samples, and
  98. * fill pointers and linesizes accordingly.
  99. * The allocated samples buffer has to be freed by using
  100. * av_freep(&pointers[0]).
  101. *
  102. * @param nb_channels number of audio channels
  103. * @param nb_samples number of samples per channel
  104. * @param planar 1 if the samples layout is planar, 0 if packed,
  105. * @param align the value to use for buffer size alignment
  106. * @return the size in bytes required for the samples buffer, a negative
  107. * error code in case of failure
  108. * @see av_samples_fill_arrays()
  109. */
  110. int av_samples_alloc(uint8_t *pointers[8], int linesizes[8],
  111. int nb_channels, int nb_samples,
  112. enum AVSampleFormat sample_fmt, int planar,
  113. int align);
  114. #endif /* AVCORE_SAMPLEFMT_H */