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 module ffmpeg.libavutil.samplefmt;
19 extern (C) @nogc nothrow:
20 
21 /**
22  * @addtogroup lavu_audio
23  * @{
24  *
25  * @defgroup lavu_sampfmts Audio sample formats
26  *
27  * Audio sample format enumeration and related convenience functions.
28  * @{
29  */
30 
31 /**
32  * Audio sample formats
33  *
34  * - The data described by the sample format is always in native-endian order.
35  *   Sample values can be expressed by native C types, hence the lack of a signed
36  *   24-bit sample format even though it is a common raw audio data format.
37  *
38  * - The floating-point formats are based on full volume being in the range
39  *   [-1.0, 1.0]. Any values outside this range are beyond full volume level.
40  *
41  * - The data layout as used in av_samples_fill_arrays() and elsewhere in FFmpeg
42  *   (such as AVFrame in libavcodec) is as follows:
43  *
44  * @par
45  * For planar sample formats, each audio channel is in a separate data plane,
46  * and linesize is the buffer size, in bytes, for a single plane. All data
47  * planes must be the same size. For packed sample formats, only the first data
48  * plane is used, and samples for each channel are interleaved. In this case,
49  * linesize is the buffer size, in bytes, for the 1 plane.
50  *
51  */
52 enum AVSampleFormat
53 {
54     AV_SAMPLE_FMT_NONE = -1,
55     AV_SAMPLE_FMT_U8 = 0, ///< unsigned 8 bits
56     AV_SAMPLE_FMT_S16 = 1, ///< signed 16 bits
57     AV_SAMPLE_FMT_S32 = 2, ///< signed 32 bits
58     AV_SAMPLE_FMT_FLT = 3, ///< float
59     AV_SAMPLE_FMT_DBL = 4, ///< double
60 
61     AV_SAMPLE_FMT_U8P = 5, ///< unsigned 8 bits, planar
62     AV_SAMPLE_FMT_S16P = 6, ///< signed 16 bits, planar
63     AV_SAMPLE_FMT_S32P = 7, ///< signed 32 bits, planar
64     AV_SAMPLE_FMT_FLTP = 8, ///< float, planar
65     AV_SAMPLE_FMT_DBLP = 9, ///< double, planar
66     AV_SAMPLE_FMT_S64 = 10, ///< signed 64 bits
67     AV_SAMPLE_FMT_S64P = 11, ///< signed 64 bits, planar
68 
69     AV_SAMPLE_FMT_NB = 12 ///< Number of sample formats. DO NOT USE if linking dynamically
70 }
71 
72 /**
73  * Return the name of sample_fmt, or NULL if sample_fmt is not
74  * recognized.
75  */
76 const(char)* av_get_sample_fmt_name (AVSampleFormat sample_fmt);
77 
78 /**
79  * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
80  * on error.
81  */
82 AVSampleFormat av_get_sample_fmt (const(char)* name);
83 
84 /**
85  * Return the planar<->packed alternative form of the given sample format, or
86  * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the
87  * requested planar/packed format, the format returned is the same as the
88  * input.
89  */
90 AVSampleFormat av_get_alt_sample_fmt (AVSampleFormat sample_fmt, int planar);
91 
92 /**
93  * Get the packed alternative form of the given sample format.
94  *
95  * If the passed sample_fmt is already in packed format, the format returned is
96  * the same as the input.
97  *
98  * @return  the packed alternative form of the given sample format or
99             AV_SAMPLE_FMT_NONE on error.
100  */
101 AVSampleFormat av_get_packed_sample_fmt (AVSampleFormat sample_fmt);
102 
103 /**
104  * Get the planar alternative form of the given sample format.
105  *
106  * If the passed sample_fmt is already in planar format, the format returned is
107  * the same as the input.
108  *
109  * @return  the planar alternative form of the given sample format or
110             AV_SAMPLE_FMT_NONE on error.
111  */
112 AVSampleFormat av_get_planar_sample_fmt (AVSampleFormat sample_fmt);
113 
114 /**
115  * Generate a string corresponding to the sample format with
116  * sample_fmt, or a header if sample_fmt is negative.
117  *
118  * @param buf the buffer where to write the string
119  * @param buf_size the size of buf
120  * @param sample_fmt the number of the sample format to print the
121  * corresponding info string, or a negative value to print the
122  * corresponding header.
123  * @return the pointer to the filled buffer or NULL if sample_fmt is
124  * unknown or in case of other errors
125  */
126 char* av_get_sample_fmt_string (char* buf, int buf_size, AVSampleFormat sample_fmt);
127 
128 /**
129  * Return number of bytes per sample.
130  *
131  * @param sample_fmt the sample format
132  * @return number of bytes per sample or zero if unknown for the given
133  * sample format
134  */
135 int av_get_bytes_per_sample (AVSampleFormat sample_fmt);
136 
137 /**
138  * Check if the sample format is planar.
139  *
140  * @param sample_fmt the sample format to inspect
141  * @return 1 if the sample format is planar, 0 if it is interleaved
142  */
143 int av_sample_fmt_is_planar (AVSampleFormat sample_fmt);
144 
145 /**
146  * Get the required buffer size for the given audio parameters.
147  *
148  * @param[out] linesize calculated linesize, may be NULL
149  * @param nb_channels   the number of channels
150  * @param nb_samples    the number of samples in a single channel
151  * @param sample_fmt    the sample format
152  * @param align         buffer size alignment (0 = default, 1 = no alignment)
153  * @return              required buffer size, or negative error code on failure
154  */
155 int av_samples_get_buffer_size (
156     int* linesize,
157     int nb_channels,
158     int nb_samples,
159     AVSampleFormat sample_fmt,
160     int align_);
161 
162 /**
163  * @}
164  *
165  * @defgroup lavu_sampmanip Samples manipulation
166  *
167  * Functions that manipulate audio samples
168  * @{
169  */
170 
171 /**
172  * Fill plane data pointers and linesize for samples with sample
173  * format sample_fmt.
174  *
175  * The audio_data array is filled with the pointers to the samples data planes:
176  * for planar, set the start point of each channel's data within the buffer,
177  * for packed, set the start point of the entire buffer only.
178  *
179  * The value pointed to by linesize is set to the aligned size of each
180  * channel's data buffer for planar layout, or to the aligned size of the
181  * buffer for all channels for packed layout.
182  *
183  * The buffer in buf must be big enough to contain all the samples
184  * (use av_samples_get_buffer_size() to compute its minimum size),
185  * otherwise the audio_data pointers will point to invalid data.
186  *
187  * @see enum AVSampleFormat
188  * The documentation for AVSampleFormat describes the data layout.
189  *
190  * @param[out] audio_data  array to be filled with the pointer for each channel
191  * @param[out] linesize    calculated linesize, may be NULL
192  * @param buf              the pointer to a buffer containing the samples
193  * @param nb_channels      the number of channels
194  * @param nb_samples       the number of samples in a single channel
195  * @param sample_fmt       the sample format
196  * @param align            buffer size alignment (0 = default, 1 = no alignment)
197  * @return                 >=0 on success or a negative error code on failure
198  * @todo return minimum size in bytes required for the buffer in case
199  * of success at the next bump
200  */
201 int av_samples_fill_arrays (
202     ubyte** audio_data,
203     int* linesize,
204     const(ubyte)* buf,
205     int nb_channels,
206     int nb_samples,
207     AVSampleFormat sample_fmt,
208     int align_);
209 
210 /**
211  * Allocate a samples buffer for nb_samples samples, and fill data pointers and
212  * linesize accordingly.
213  * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
214  * Allocated data will be initialized to silence.
215  *
216  * @see enum AVSampleFormat
217  * The documentation for AVSampleFormat describes the data layout.
218  *
219  * @param[out] audio_data  array to be filled with the pointer for each channel
220  * @param[out] linesize    aligned size for audio buffer(s), may be NULL
221  * @param nb_channels      number of audio channels
222  * @param nb_samples       number of samples per channel
223  * @param align            buffer size alignment (0 = default, 1 = no alignment)
224  * @return                 >=0 on success or a negative error code on failure
225  * @todo return the size of the allocated buffer in case of success at the next bump
226  * @see av_samples_fill_arrays()
227  * @see av_samples_alloc_array_and_samples()
228  */
229 int av_samples_alloc (
230     ubyte** audio_data,
231     int* linesize,
232     int nb_channels,
233     int nb_samples,
234     AVSampleFormat sample_fmt,
235     int align_);
236 
237 /**
238  * Allocate a data pointers array, samples buffer for nb_samples
239  * samples, and fill data pointers and linesize accordingly.
240  *
241  * This is the same as av_samples_alloc(), but also allocates the data
242  * pointers array.
243  *
244  * @see av_samples_alloc()
245  */
246 int av_samples_alloc_array_and_samples (
247     ubyte*** audio_data,
248     int* linesize,
249     int nb_channels,
250     int nb_samples,
251     AVSampleFormat sample_fmt,
252     int align_);
253 
254 /**
255  * Copy samples from src to dst.
256  *
257  * @param dst destination array of pointers to data planes
258  * @param src source array of pointers to data planes
259  * @param dst_offset offset in samples at which the data will be written to dst
260  * @param src_offset offset in samples at which the data will be read from src
261  * @param nb_samples number of samples to be copied
262  * @param nb_channels number of audio channels
263  * @param sample_fmt audio sample format
264  */
265 int av_samples_copy (
266     ubyte** dst,
267     ubyte** src,
268     int dst_offset,
269     int src_offset,
270     int nb_samples,
271     int nb_channels,
272     AVSampleFormat sample_fmt);
273 
274 /**
275  * Fill an audio buffer with silence.
276  *
277  * @param audio_data  array of pointers to data planes
278  * @param offset      offset in samples at which to start filling
279  * @param nb_samples  number of samples to fill
280  * @param nb_channels number of audio channels
281  * @param sample_fmt  audio sample format
282  */
283 int av_samples_set_silence (
284     ubyte** audio_data,
285     int offset,
286     int nb_samples,
287     int nb_channels,
288     AVSampleFormat sample_fmt);
289 
290 /**
291  * @}
292  * @}
293  */
294 /* AVUTIL_SAMPLEFMT_H */