]> git.sesse.net Git - ffmpeg/blob - libavutil/samplefmt.h
mips: intreadwrite: fix inline asm for gcc 4.8
[ffmpeg] / libavutil / samplefmt.h
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
19 #ifndef AVUTIL_SAMPLEFMT_H
20 #define AVUTIL_SAMPLEFMT_H
21
22 #include "avutil.h"
23
24 /**
25  * Audio Sample Formats
26  *
27  * @par
28  * The data described by the sample format is always in native-endian order.
29  * Sample values can be expressed by native C types, hence the lack of a signed
30  * 24-bit sample format even though it is a common raw audio data format.
31  *
32  * @par
33  * The floating-point formats are based on full volume being in the range
34  * [-1.0, 1.0]. Any values outside this range are beyond full volume level.
35  *
36  * @par
37  * The data layout as used in av_samples_fill_arrays() and elsewhere in Libav
38  * (such as AVFrame in libavcodec) is as follows:
39  *
40  * For planar sample formats, each audio channel is in a separate data plane,
41  * and linesize is the buffer size, in bytes, for a single plane. All data
42  * planes must be the same size. For packed sample formats, only the first data
43  * plane is used, and samples for each channel are interleaved. In this case,
44  * linesize is the buffer size, in bytes, for the 1 plane.
45  */
46 enum AVSampleFormat {
47     AV_SAMPLE_FMT_NONE = -1,
48     AV_SAMPLE_FMT_U8,          ///< unsigned 8 bits
49     AV_SAMPLE_FMT_S16,         ///< signed 16 bits
50     AV_SAMPLE_FMT_S32,         ///< signed 32 bits
51     AV_SAMPLE_FMT_FLT,         ///< float
52     AV_SAMPLE_FMT_DBL,         ///< double
53
54     AV_SAMPLE_FMT_U8P,         ///< unsigned 8 bits, planar
55     AV_SAMPLE_FMT_S16P,        ///< signed 16 bits, planar
56     AV_SAMPLE_FMT_S32P,        ///< signed 32 bits, planar
57     AV_SAMPLE_FMT_FLTP,        ///< float, planar
58     AV_SAMPLE_FMT_DBLP,        ///< double, planar
59
60     AV_SAMPLE_FMT_NB           ///< Number of sample formats. DO NOT USE if linking dynamically
61 };
62
63 /**
64  * Return the name of sample_fmt, or NULL if sample_fmt is not
65  * recognized.
66  */
67 const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
68
69 /**
70  * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
71  * on error.
72  */
73 enum AVSampleFormat av_get_sample_fmt(const char *name);
74
75 /**
76  * Get the packed alternative form of the given sample format.
77  *
78  * If the passed sample_fmt is already in packed format, the format returned is
79  * the same as the input.
80  *
81  * @return  the packed alternative form of the given sample format or
82             AV_SAMPLE_FMT_NONE on error.
83  */
84 enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
85
86 /**
87  * Get the planar alternative form of the given sample format.
88  *
89  * If the passed sample_fmt is already in planar format, the format returned is
90  * the same as the input.
91  *
92  * @return  the planar alternative form of the given sample format or
93             AV_SAMPLE_FMT_NONE on error.
94  */
95 enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
96
97 /**
98  * Generate a string corresponding to the sample format with
99  * sample_fmt, or a header if sample_fmt is negative.
100  *
101  * @param buf the buffer where to write the string
102  * @param buf_size the size of buf
103  * @param sample_fmt the number of the sample format to print the
104  * corresponding info string, or a negative value to print the
105  * corresponding header.
106  * @return the pointer to the filled buffer or NULL if sample_fmt is
107  * unknown or in case of other errors
108  */
109 char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
110
111 #if FF_API_GET_BITS_PER_SAMPLE_FMT
112 /**
113  * @deprecated Use av_get_bytes_per_sample() instead.
114  */
115 attribute_deprecated
116 int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
117 #endif
118
119 /**
120  * Return number of bytes per sample.
121  *
122  * @param sample_fmt the sample format
123  * @return number of bytes per sample or zero if unknown for the given
124  * sample format
125  */
126 int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
127
128 /**
129  * Check if the sample format is planar.
130  *
131  * @param sample_fmt the sample format to inspect
132  * @return 1 if the sample format is planar, 0 if it is interleaved
133  */
134 int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
135
136 /**
137  * Get the required buffer size for the given audio parameters.
138  *
139  * @param[out] linesize calculated linesize, may be NULL
140  * @param nb_channels   the number of channels
141  * @param nb_samples    the number of samples in a single channel
142  * @param sample_fmt    the sample format
143  * @param align         buffer size alignment (0 = default, 1 = no alignment)
144  * @return              required buffer size, or negative error code on failure
145  */
146 int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
147                                enum AVSampleFormat sample_fmt, int align);
148
149 /**
150  * Fill channel data pointers and linesize for samples with sample
151  * format sample_fmt.
152  *
153  * The pointers array is filled with the pointers to the samples data:
154  * for planar, set the start point of each channel's data within the buffer,
155  * for packed, set the start point of the entire buffer only.
156  *
157  * The linesize array is filled with the aligned size of each channel's data
158  * buffer for planar layout, or the aligned size of the buffer for all channels
159  * for packed layout.
160  *
161  * @see enum AVSampleFormat
162  * The documentation for AVSampleFormat describes the data layout.
163  *
164  * @param[out] audio_data  array to be filled with the pointer for each channel
165  * @param[out] linesize    calculated linesize, may be NULL
166  * @param buf              the pointer to a buffer containing the samples
167  * @param nb_channels      the number of channels
168  * @param nb_samples       the number of samples in a single channel
169  * @param sample_fmt       the sample format
170  * @param align            buffer size alignment (0 = default, 1 = no alignment)
171  * @return                 0 on success or a negative error code on failure
172  */
173 int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
174                            const uint8_t *buf,
175                            int nb_channels, int nb_samples,
176                            enum AVSampleFormat sample_fmt, int align);
177
178 /**
179  * Allocate a samples buffer for nb_samples samples, and fill data pointers and
180  * linesize accordingly.
181  * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
182  *
183  * @see enum AVSampleFormat
184  * The documentation for AVSampleFormat describes the data layout.
185  *
186  * @param[out] audio_data  array to be filled with the pointer for each channel
187  * @param[out] linesize    aligned size for audio buffer(s), may be NULL
188  * @param nb_channels      number of audio channels
189  * @param nb_samples       number of samples per channel
190  * @param align            buffer size alignment (0 = default, 1 = no alignment)
191  * @return                 0 on success or a negative error code on failure
192  * @see av_samples_fill_arrays()
193  */
194 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
195                      int nb_samples, enum AVSampleFormat sample_fmt, int align);
196
197 #endif /* AVUTIL_SAMPLEFMT_H */