annotate ffmpeg/libavutil/samplefmt.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents f445c3017523
children
rev   line source
yading@11 1 /*
yading@11 2 * This file is part of FFmpeg.
yading@11 3 *
yading@11 4 * FFmpeg is free software; you can redistribute it and/or
yading@11 5 * modify it under the terms of the GNU Lesser General Public
yading@11 6 * License as published by the Free Software Foundation; either
yading@11 7 * version 2.1 of the License, or (at your option) any later version.
yading@11 8 *
yading@11 9 * FFmpeg is distributed in the hope that it will be useful,
yading@11 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@11 12 * Lesser General Public License for more details.
yading@11 13 *
yading@11 14 * You should have received a copy of the GNU Lesser General Public
yading@11 15 * License along with FFmpeg; if not, write to the Free Software
yading@11 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@11 17 */
yading@11 18
yading@11 19 #ifndef AVUTIL_SAMPLEFMT_H
yading@11 20 #define AVUTIL_SAMPLEFMT_H
yading@11 21
yading@11 22 #include <stdint.h>
yading@11 23
yading@11 24 #include "avutil.h"
yading@11 25 #include "attributes.h"
yading@11 26
yading@11 27 /**
yading@11 28 * Audio Sample Formats
yading@11 29 *
yading@11 30 * @par
yading@11 31 * The data described by the sample format is always in native-endian order.
yading@11 32 * Sample values can be expressed by native C types, hence the lack of a signed
yading@11 33 * 24-bit sample format even though it is a common raw audio data format.
yading@11 34 *
yading@11 35 * @par
yading@11 36 * The floating-point formats are based on full volume being in the range
yading@11 37 * [-1.0, 1.0]. Any values outside this range are beyond full volume level.
yading@11 38 *
yading@11 39 * @par
yading@11 40 * The data layout as used in av_samples_fill_arrays() and elsewhere in FFmpeg
yading@11 41 * (such as AVFrame in libavcodec) is as follows:
yading@11 42 *
yading@11 43 * For planar sample formats, each audio channel is in a separate data plane,
yading@11 44 * and linesize is the buffer size, in bytes, for a single plane. All data
yading@11 45 * planes must be the same size. For packed sample formats, only the first data
yading@11 46 * plane is used, and samples for each channel are interleaved. In this case,
yading@11 47 * linesize is the buffer size, in bytes, for the 1 plane.
yading@11 48 */
yading@11 49 enum AVSampleFormat {
yading@11 50 AV_SAMPLE_FMT_NONE = -1,
yading@11 51 AV_SAMPLE_FMT_U8, ///< unsigned 8 bits
yading@11 52 AV_SAMPLE_FMT_S16, ///< signed 16 bits
yading@11 53 AV_SAMPLE_FMT_S32, ///< signed 32 bits
yading@11 54 AV_SAMPLE_FMT_FLT, ///< float
yading@11 55 AV_SAMPLE_FMT_DBL, ///< double
yading@11 56
yading@11 57 AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar
yading@11 58 AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar
yading@11 59 AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar
yading@11 60 AV_SAMPLE_FMT_FLTP, ///< float, planar
yading@11 61 AV_SAMPLE_FMT_DBLP, ///< double, planar
yading@11 62
yading@11 63 AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically
yading@11 64 };
yading@11 65
yading@11 66 /**
yading@11 67 * Return the name of sample_fmt, or NULL if sample_fmt is not
yading@11 68 * recognized.
yading@11 69 */
yading@11 70 const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt);
yading@11 71
yading@11 72 /**
yading@11 73 * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE
yading@11 74 * on error.
yading@11 75 */
yading@11 76 enum AVSampleFormat av_get_sample_fmt(const char *name);
yading@11 77
yading@11 78 /**
yading@11 79 * Return the planar<->packed alternative form of the given sample format, or
yading@11 80 * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the
yading@11 81 * requested planar/packed format, the format returned is the same as the
yading@11 82 * input.
yading@11 83 */
yading@11 84 enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar);
yading@11 85
yading@11 86 /**
yading@11 87 * Get the packed alternative form of the given sample format.
yading@11 88 *
yading@11 89 * If the passed sample_fmt is already in packed format, the format returned is
yading@11 90 * the same as the input.
yading@11 91 *
yading@11 92 * @return the packed alternative form of the given sample format or
yading@11 93 AV_SAMPLE_FMT_NONE on error.
yading@11 94 */
yading@11 95 enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt);
yading@11 96
yading@11 97 /**
yading@11 98 * Get the planar alternative form of the given sample format.
yading@11 99 *
yading@11 100 * If the passed sample_fmt is already in planar format, the format returned is
yading@11 101 * the same as the input.
yading@11 102 *
yading@11 103 * @return the planar alternative form of the given sample format or
yading@11 104 AV_SAMPLE_FMT_NONE on error.
yading@11 105 */
yading@11 106 enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt);
yading@11 107
yading@11 108 /**
yading@11 109 * Generate a string corresponding to the sample format with
yading@11 110 * sample_fmt, or a header if sample_fmt is negative.
yading@11 111 *
yading@11 112 * @param buf the buffer where to write the string
yading@11 113 * @param buf_size the size of buf
yading@11 114 * @param sample_fmt the number of the sample format to print the
yading@11 115 * corresponding info string, or a negative value to print the
yading@11 116 * corresponding header.
yading@11 117 * @return the pointer to the filled buffer or NULL if sample_fmt is
yading@11 118 * unknown or in case of other errors
yading@11 119 */
yading@11 120 char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt);
yading@11 121
yading@11 122 #if FF_API_GET_BITS_PER_SAMPLE_FMT
yading@11 123 /**
yading@11 124 * @deprecated Use av_get_bytes_per_sample() instead.
yading@11 125 */
yading@11 126 attribute_deprecated
yading@11 127 int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt);
yading@11 128 #endif
yading@11 129
yading@11 130 /**
yading@11 131 * Return number of bytes per sample.
yading@11 132 *
yading@11 133 * @param sample_fmt the sample format
yading@11 134 * @return number of bytes per sample or zero if unknown for the given
yading@11 135 * sample format
yading@11 136 */
yading@11 137 int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt);
yading@11 138
yading@11 139 /**
yading@11 140 * Check if the sample format is planar.
yading@11 141 *
yading@11 142 * @param sample_fmt the sample format to inspect
yading@11 143 * @return 1 if the sample format is planar, 0 if it is interleaved
yading@11 144 */
yading@11 145 int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt);
yading@11 146
yading@11 147 /**
yading@11 148 * Get the required buffer size for the given audio parameters.
yading@11 149 *
yading@11 150 * @param[out] linesize calculated linesize, may be NULL
yading@11 151 * @param nb_channels the number of channels
yading@11 152 * @param nb_samples the number of samples in a single channel
yading@11 153 * @param sample_fmt the sample format
yading@11 154 * @param align buffer size alignment (0 = default, 1 = no alignment)
yading@11 155 * @return required buffer size, or negative error code on failure
yading@11 156 */
yading@11 157 int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples,
yading@11 158 enum AVSampleFormat sample_fmt, int align);
yading@11 159
yading@11 160 /**
yading@11 161 * Fill plane data pointers and linesize for samples with sample
yading@11 162 * format sample_fmt.
yading@11 163 *
yading@11 164 * The audio_data array is filled with the pointers to the samples data planes:
yading@11 165 * for planar, set the start point of each channel's data within the buffer,
yading@11 166 * for packed, set the start point of the entire buffer only.
yading@11 167 *
yading@11 168 * The value pointed to by linesize is set to the aligned size of each
yading@11 169 * channel's data buffer for planar layout, or to the aligned size of the
yading@11 170 * buffer for all channels for packed layout.
yading@11 171 *
yading@11 172 * The buffer in buf must be big enough to contain all the samples
yading@11 173 * (use av_samples_get_buffer_size() to compute its minimum size),
yading@11 174 * otherwise the audio_data pointers will point to invalid data.
yading@11 175 *
yading@11 176 * @see enum AVSampleFormat
yading@11 177 * The documentation for AVSampleFormat describes the data layout.
yading@11 178 *
yading@11 179 * @param[out] audio_data array to be filled with the pointer for each channel
yading@11 180 * @param[out] linesize calculated linesize, may be NULL
yading@11 181 * @param buf the pointer to a buffer containing the samples
yading@11 182 * @param nb_channels the number of channels
yading@11 183 * @param nb_samples the number of samples in a single channel
yading@11 184 * @param sample_fmt the sample format
yading@11 185 * @param align buffer size alignment (0 = default, 1 = no alignment)
yading@11 186 * @return >=0 on success or a negative error code on failure
yading@11 187 * @todo return minimum size in bytes required for the buffer in case
yading@11 188 * of success at the next bump
yading@11 189 */
yading@11 190 int av_samples_fill_arrays(uint8_t **audio_data, int *linesize,
yading@11 191 const uint8_t *buf,
yading@11 192 int nb_channels, int nb_samples,
yading@11 193 enum AVSampleFormat sample_fmt, int align);
yading@11 194
yading@11 195 /**
yading@11 196 * Allocate a samples buffer for nb_samples samples, and fill data pointers and
yading@11 197 * linesize accordingly.
yading@11 198 * The allocated samples buffer can be freed by using av_freep(&audio_data[0])
yading@11 199 * Allocated data will be initialized to silence.
yading@11 200 *
yading@11 201 * @see enum AVSampleFormat
yading@11 202 * The documentation for AVSampleFormat describes the data layout.
yading@11 203 *
yading@11 204 * @param[out] audio_data array to be filled with the pointer for each channel
yading@11 205 * @param[out] linesize aligned size for audio buffer(s), may be NULL
yading@11 206 * @param nb_channels number of audio channels
yading@11 207 * @param nb_samples number of samples per channel
yading@11 208 * @param align buffer size alignment (0 = default, 1 = no alignment)
yading@11 209 * @return >=0 on success or a negative error code on failure
yading@11 210 * @todo return the size of the allocated buffer in case of success at the next bump
yading@11 211 * @see av_samples_fill_arrays()
yading@11 212 * @see av_samples_alloc_array_and_samples()
yading@11 213 */
yading@11 214 int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
yading@11 215 int nb_samples, enum AVSampleFormat sample_fmt, int align);
yading@11 216
yading@11 217 /**
yading@11 218 * Allocate a data pointers array, samples buffer for nb_samples
yading@11 219 * samples, and fill data pointers and linesize accordingly.
yading@11 220 *
yading@11 221 * This is the same as av_samples_alloc(), but also allocates the data
yading@11 222 * pointers array.
yading@11 223 *
yading@11 224 * @see av_samples_alloc()
yading@11 225 */
yading@11 226 int av_samples_alloc_array_and_samples(uint8_t ***audio_data, int *linesize, int nb_channels,
yading@11 227 int nb_samples, enum AVSampleFormat sample_fmt, int align);
yading@11 228
yading@11 229 /**
yading@11 230 * Copy samples from src to dst.
yading@11 231 *
yading@11 232 * @param dst destination array of pointers to data planes
yading@11 233 * @param src source array of pointers to data planes
yading@11 234 * @param dst_offset offset in samples at which the data will be written to dst
yading@11 235 * @param src_offset offset in samples at which the data will be read from src
yading@11 236 * @param nb_samples number of samples to be copied
yading@11 237 * @param nb_channels number of audio channels
yading@11 238 * @param sample_fmt audio sample format
yading@11 239 */
yading@11 240 int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
yading@11 241 int src_offset, int nb_samples, int nb_channels,
yading@11 242 enum AVSampleFormat sample_fmt);
yading@11 243
yading@11 244 /**
yading@11 245 * Fill an audio buffer with silence.
yading@11 246 *
yading@11 247 * @param audio_data array of pointers to data planes
yading@11 248 * @param offset offset in samples at which to start filling
yading@11 249 * @param nb_samples number of samples to fill
yading@11 250 * @param nb_channels number of audio channels
yading@11 251 * @param sample_fmt audio sample format
yading@11 252 */
yading@11 253 int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples,
yading@11 254 int nb_channels, enum AVSampleFormat sample_fmt);
yading@11 255
yading@11 256 #endif /* AVUTIL_SAMPLEFMT_H */