]> git.sesse.net Git - ffmpeg/blob - libavutil/samplefmt.h
Merge commit '3b266da3d35f3f7a61258b78384dfe920d875d29'
[ffmpeg] / libavutil / samplefmt.h
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
19 #ifndef AVUTIL_SAMPLEFMT_H
20 #define AVUTIL_SAMPLEFMT_H
21
22 #include "avutil.h"
23
24 /**
25  * all in native-endian format
26  */
27 enum AVSampleFormat {
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
34
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
40
41     AV_SAMPLE_FMT_NB           ///< Number of sample formats. DO NOT USE if linking dynamically
42 };
43
44 /**
45  * Return the name of sample_fmt, or NULL if sample_fmt is not
46  * recognized.
47  */
48 const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
49
50 /**
51  * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
52  * on error.
53  */
54 enum AVSampleFormat av_get_sample_fmt(const char *name);
55
56 /**
57  * Return the planar<->packed alternative form of the given sample format, or
58  * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the
59  * requested planar/packed format, the format returned is the same as the
60  * input.
61  */
62 enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar);
63
64 /**
65  * Get the packed alternative form of the given sample format.
66  *
67  * If the passed sample_fmt is already in packed format, the format returned is
68  * the same as the input.
69  *
70  * @return  the packed alternative form of the given sample format or
71             AV_SAMPLE_FMT_NONE on error.
72  */
73 enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
74
75 /**
76  * Get the planar alternative form of the given sample format.
77  *
78  * If the passed sample_fmt is already in planar format, the format returned is
79  * the same as the input.
80  *
81  * @return  the planar alternative form of the given sample format or
82             AV_SAMPLE_FMT_NONE on error.
83  */
84 enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
85
86 /**
87  * Generate a string corresponding to the sample format with
88  * sample_fmt, or a header if sample_fmt is negative.
89  *
90  * @param buf the buffer where to write the string
91  * @param buf_size the size of buf
92  * @param sample_fmt the number of the sample format to print the
93  * corresponding info string, or a negative value to print the
94  * corresponding header.
95  * @return the pointer to the filled buffer or NULL if sample_fmt is
96  * unknown or in case of other errors
97  */
98 char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
99
100 #if FF_API_GET_BITS_PER_SAMPLE_FMT
101 /**
102  * @deprecated Use av_get_bytes_per_sample() instead.
103  */
104 attribute_deprecated
105 int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
106 #endif
107
108 /**
109  * Return number of bytes per sample.
110  *
111  * @param sample_fmt the sample format
112  * @return number of bytes per sample or zero if unknown for the given
113  * sample format
114  */
115 int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
116
117 /**
118  * Check if the sample format is planar.
119  *
120  * @param sample_fmt the sample format to inspect
121  * @return 1 if the sample format is planar, 0 if it is interleaved
122  */
123 int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
124
125 /**
126  * Get the required buffer size for the given audio parameters.
127  *
128  * @param[out] linesize calculated linesize, may be NULL
129  * @param nb_channels   the number of channels
130  * @param nb_samples    the number of samples in a single channel
131  * @param sample_fmt    the sample format
132  * @param align         buffer size alignment (0 = default, 1 = no alignment)
133  * @return              required buffer size, or negative error code on failure
134  */
135 int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
136                                enum AVSampleFormat sample_fmt, int align);
137
138 /**
139  * Fill channel data pointers and linesize for samples with sample
140  * format sample_fmt.
141  *
142  * The pointers array is filled with the pointers to the samples data:
143  * for planar, set the start point of each channel's data within the buffer,
144  * for packed, set the start point of the entire buffer only.
145  *
146  * The linesize array is filled with the aligned size of each channel's data
147  * buffer for planar layout, or the aligned size of the buffer for all channels
148  * for packed layout.
149  *
150  * @param[out] audio_data  array to be filled with the pointer for each channel
151  * @param[out] linesize    calculated linesize, may be NULL
152  * @param buf              the pointer to a buffer containing the samples
153  * @param nb_channels      the number of channels
154  * @param nb_samples       the number of samples in a single channel
155  * @param sample_fmt       the sample format
156  * @param align            buffer size alignment (0 = default, 1 = no alignment)
157  * @return                 0 on success or a negative error code on failure
158  */
159 int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf,
160                            int nb_channels, int nb_samples,
161                            enum AVSampleFormat sample_fmt, int align);
162
163 /**
164  * Allocate a samples buffer for nb_samples samples, and fill data pointers and
165  * linesize accordingly.
166  * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
167  *
168  * @param[out] audio_data  array to be filled with the pointer for each channel
169  * @param[out] linesize    aligned size for audio buffer(s), may be NULL
170  * @param nb_channels      number of audio channels
171  * @param nb_samples       number of samples per channel
172  * @param align            buffer size alignment (0 = default, 1 = no alignment)
173  * @return                 0 on success or a negative error code on failure
174  * @see av_samples_fill_arrays()
175  */
176 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
177                      int nb_samples, enum AVSampleFormat sample_fmt, int align);
178
179 #endif /* AVUTIL_SAMPLEFMT_H */