2 * This file is part of Libav.
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.
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.
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
19 #ifndef AVUTIL_SAMPLEFMT_H
20 #define AVUTIL_SAMPLEFMT_H
25 * all in native-endian format
28 AV_SAMPLE_FMT_NONE = -1,
29 AV_SAMPLE_FMT_U8, ///< unsigned 8 bits
30 AV_SAMPLE_FMT_S16, ///< signed 16 bits
31 AV_SAMPLE_FMT_S32, ///< signed 32 bits
32 AV_SAMPLE_FMT_FLT, ///< float
33 AV_SAMPLE_FMT_DBL, ///< double
35 AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar
36 AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar
37 AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
38 AV_SAMPLE_FMT_FLTP, ///< float, planar
39 AV_SAMPLE_FMT_DBLP, ///< double, planar
41 AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically
45 * Return the name of sample_fmt, or NULL if sample_fmt is not
48 const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
51 * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
54 enum AVSampleFormat av_get_sample_fmt(const char *name);
57 * Get the packed alternative form of the given sample format.
59 * If the passed sample_fmt is already in packed format, the format returned is
60 * the same as the input.
62 * @return the packed alternative form of the given sample format or
63 AV_SAMPLE_FMT_NONE on error.
65 enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
68 * Get the planar alternative form of the given sample format.
70 * If the passed sample_fmt is already in planar format, the format returned is
71 * the same as the input.
73 * @return the planar alternative form of the given sample format or
74 AV_SAMPLE_FMT_NONE on error.
76 enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
79 * Generate a string corresponding to the sample format with
80 * sample_fmt, or a header if sample_fmt is negative.
82 * @param buf the buffer where to write the string
83 * @param buf_size the size of buf
84 * @param sample_fmt the number of the sample format to print the
85 * corresponding info string, or a negative value to print the
86 * corresponding header.
87 * @return the pointer to the filled buffer or NULL if sample_fmt is
88 * unknown or in case of other errors
90 char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
92 #if FF_API_GET_BITS_PER_SAMPLE_FMT
94 * @deprecated Use av_get_bytes_per_sample() instead.
97 int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
101 * Return number of bytes per sample.
103 * @param sample_fmt the sample format
104 * @return number of bytes per sample or zero if unknown for the given
107 int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
110 * Check if the sample format is planar.
112 * @param sample_fmt the sample format to inspect
113 * @return 1 if the sample format is planar, 0 if it is interleaved
115 int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
118 * Get the required buffer size for the given audio parameters.
120 * @param[out] linesize calculated linesize, may be NULL
121 * @param nb_channels the number of channels
122 * @param nb_samples the number of samples in a single channel
123 * @param sample_fmt the sample format
124 * @return required buffer size, or negative error code on failure
126 int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
127 enum AVSampleFormat sample_fmt, int align);
130 * Fill channel data pointers and linesize for samples with sample
133 * The pointers array is filled with the pointers to the samples data:
134 * for planar, set the start point of each channel's data within the buffer,
135 * for packed, set the start point of the entire buffer only.
137 * The linesize array is filled with the aligned size of each channel's data
138 * buffer for planar layout, or the aligned size of the buffer for all channels
141 * @param[out] audio_data array to be filled with the pointer for each channel
142 * @param[out] linesize calculated linesize
143 * @param buf the pointer to a buffer containing the samples
144 * @param nb_channels the number of channels
145 * @param nb_samples the number of samples in a single channel
146 * @param sample_fmt the sample format
147 * @param align buffer size alignment (1 = no alignment required)
148 * @return 0 on success or a negative error code on failure
150 int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf,
151 int nb_channels, int nb_samples,
152 enum AVSampleFormat sample_fmt, int align);
155 * Allocate a samples buffer for nb_samples samples, and fill data pointers and
156 * linesize accordingly.
157 * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
159 * @param[out] audio_data array to be filled with the pointer for each channel
160 * @param[out] linesize aligned size for audio buffer(s)
161 * @param nb_channels number of audio channels
162 * @param nb_samples number of samples per channel
163 * @param align buffer size alignment (1 = no alignment required)
164 * @return 0 on success or a negative error code on failure
165 * @see av_samples_fill_arrays()
167 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
168 int nb_samples, enum AVSampleFormat sample_fmt, int align);
170 #endif /* AVUTIL_SAMPLEFMT_H */