yading@11: /* yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_SAMPLEFMT_H yading@11: #define AVUTIL_SAMPLEFMT_H yading@11: yading@11: #include yading@11: yading@11: #include "avutil.h" yading@11: #include "attributes.h" yading@11: yading@11: /** yading@11: * Audio Sample Formats yading@11: * yading@11: * @par yading@11: * The data described by the sample format is always in native-endian order. yading@11: * Sample values can be expressed by native C types, hence the lack of a signed yading@11: * 24-bit sample format even though it is a common raw audio data format. yading@11: * yading@11: * @par yading@11: * The floating-point formats are based on full volume being in the range yading@11: * [-1.0, 1.0]. Any values outside this range are beyond full volume level. yading@11: * yading@11: * @par yading@11: * The data layout as used in av_samples_fill_arrays() and elsewhere in FFmpeg yading@11: * (such as AVFrame in libavcodec) is as follows: yading@11: * yading@11: * For planar sample formats, each audio channel is in a separate data plane, yading@11: * and linesize is the buffer size, in bytes, for a single plane. All data yading@11: * planes must be the same size. For packed sample formats, only the first data yading@11: * plane is used, and samples for each channel are interleaved. In this case, yading@11: * linesize is the buffer size, in bytes, for the 1 plane. yading@11: */ yading@11: enum AVSampleFormat { yading@11: AV_SAMPLE_FMT_NONE = -1, yading@11: AV_SAMPLE_FMT_U8, ///< unsigned 8 bits yading@11: AV_SAMPLE_FMT_S16, ///< signed 16 bits yading@11: AV_SAMPLE_FMT_S32, ///< signed 32 bits yading@11: AV_SAMPLE_FMT_FLT, ///< float yading@11: AV_SAMPLE_FMT_DBL, ///< double yading@11: yading@11: AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar yading@11: AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar yading@11: AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar yading@11: AV_SAMPLE_FMT_FLTP, ///< float, planar yading@11: AV_SAMPLE_FMT_DBLP, ///< double, planar yading@11: yading@11: AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically yading@11: }; yading@11: yading@11: /** yading@11: * Return the name of sample_fmt, or NULL if sample_fmt is not yading@11: * recognized. yading@11: */ yading@11: const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt); yading@11: yading@11: /** yading@11: * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE yading@11: * on error. yading@11: */ yading@11: enum AVSampleFormat av_get_sample_fmt(const char *name); yading@11: yading@11: /** yading@11: * Return the planar<->packed alternative form of the given sample format, or yading@11: * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the yading@11: * requested planar/packed format, the format returned is the same as the yading@11: * input. yading@11: */ yading@11: enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar); yading@11: yading@11: /** yading@11: * Get the packed alternative form of the given sample format. yading@11: * yading@11: * If the passed sample_fmt is already in packed format, the format returned is yading@11: * the same as the input. yading@11: * yading@11: * @return the packed alternative form of the given sample format or yading@11: AV_SAMPLE_FMT_NONE on error. yading@11: */ yading@11: enum AVSampleFormat av_get_packed_sample_fmt(enum AVSampleFormat sample_fmt); yading@11: yading@11: /** yading@11: * Get the planar alternative form of the given sample format. yading@11: * yading@11: * If the passed sample_fmt is already in planar format, the format returned is yading@11: * the same as the input. yading@11: * yading@11: * @return the planar alternative form of the given sample format or yading@11: AV_SAMPLE_FMT_NONE on error. yading@11: */ yading@11: enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt); yading@11: yading@11: /** yading@11: * Generate a string corresponding to the sample format with yading@11: * sample_fmt, or a header if sample_fmt is negative. yading@11: * yading@11: * @param buf the buffer where to write the string yading@11: * @param buf_size the size of buf yading@11: * @param sample_fmt the number of the sample format to print the yading@11: * corresponding info string, or a negative value to print the yading@11: * corresponding header. yading@11: * @return the pointer to the filled buffer or NULL if sample_fmt is yading@11: * unknown or in case of other errors yading@11: */ yading@11: char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt); yading@11: yading@11: #if FF_API_GET_BITS_PER_SAMPLE_FMT yading@11: /** yading@11: * @deprecated Use av_get_bytes_per_sample() instead. yading@11: */ yading@11: attribute_deprecated yading@11: int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt); yading@11: #endif yading@11: yading@11: /** yading@11: * Return number of bytes per sample. yading@11: * yading@11: * @param sample_fmt the sample format yading@11: * @return number of bytes per sample or zero if unknown for the given yading@11: * sample format yading@11: */ yading@11: int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt); yading@11: yading@11: /** yading@11: * Check if the sample format is planar. yading@11: * yading@11: * @param sample_fmt the sample format to inspect yading@11: * @return 1 if the sample format is planar, 0 if it is interleaved yading@11: */ yading@11: int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt); yading@11: yading@11: /** yading@11: * Get the required buffer size for the given audio parameters. yading@11: * yading@11: * @param[out] linesize calculated linesize, may be NULL yading@11: * @param nb_channels the number of channels yading@11: * @param nb_samples the number of samples in a single channel yading@11: * @param sample_fmt the sample format yading@11: * @param align buffer size alignment (0 = default, 1 = no alignment) yading@11: * @return required buffer size, or negative error code on failure yading@11: */ yading@11: int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, yading@11: enum AVSampleFormat sample_fmt, int align); yading@11: yading@11: /** yading@11: * Fill plane data pointers and linesize for samples with sample yading@11: * format sample_fmt. yading@11: * yading@11: * The audio_data array is filled with the pointers to the samples data planes: yading@11: * for planar, set the start point of each channel's data within the buffer, yading@11: * for packed, set the start point of the entire buffer only. yading@11: * yading@11: * The value pointed to by linesize is set to the aligned size of each yading@11: * channel's data buffer for planar layout, or to the aligned size of the yading@11: * buffer for all channels for packed layout. yading@11: * yading@11: * The buffer in buf must be big enough to contain all the samples yading@11: * (use av_samples_get_buffer_size() to compute its minimum size), yading@11: * otherwise the audio_data pointers will point to invalid data. yading@11: * yading@11: * @see enum AVSampleFormat yading@11: * The documentation for AVSampleFormat describes the data layout. yading@11: * yading@11: * @param[out] audio_data array to be filled with the pointer for each channel yading@11: * @param[out] linesize calculated linesize, may be NULL yading@11: * @param buf the pointer to a buffer containing the samples yading@11: * @param nb_channels the number of channels yading@11: * @param nb_samples the number of samples in a single channel yading@11: * @param sample_fmt the sample format yading@11: * @param align buffer size alignment (0 = default, 1 = no alignment) yading@11: * @return >=0 on success or a negative error code on failure yading@11: * @todo return minimum size in bytes required for the buffer in case yading@11: * of success at the next bump yading@11: */ yading@11: int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, yading@11: const uint8_t *buf, yading@11: int nb_channels, int nb_samples, yading@11: enum AVSampleFormat sample_fmt, int align); yading@11: yading@11: /** yading@11: * Allocate a samples buffer for nb_samples samples, and fill data pointers and yading@11: * linesize accordingly. yading@11: * The allocated samples buffer can be freed by using av_freep(&audio_data[0]) yading@11: * Allocated data will be initialized to silence. yading@11: * yading@11: * @see enum AVSampleFormat yading@11: * The documentation for AVSampleFormat describes the data layout. yading@11: * yading@11: * @param[out] audio_data array to be filled with the pointer for each channel yading@11: * @param[out] linesize aligned size for audio buffer(s), may be NULL yading@11: * @param nb_channels number of audio channels yading@11: * @param nb_samples number of samples per channel yading@11: * @param align buffer size alignment (0 = default, 1 = no alignment) yading@11: * @return >=0 on success or a negative error code on failure yading@11: * @todo return the size of the allocated buffer in case of success at the next bump yading@11: * @see av_samples_fill_arrays() yading@11: * @see av_samples_alloc_array_and_samples() yading@11: */ yading@11: int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels, yading@11: int nb_samples, enum AVSampleFormat sample_fmt, int align); yading@11: yading@11: /** yading@11: * Allocate a data pointers array, samples buffer for nb_samples yading@11: * samples, and fill data pointers and linesize accordingly. yading@11: * yading@11: * This is the same as av_samples_alloc(), but also allocates the data yading@11: * pointers array. yading@11: * yading@11: * @see av_samples_alloc() yading@11: */ yading@11: int av_samples_alloc_array_and_samples(uint8_t ***audio_data, int *linesize, int nb_channels, yading@11: int nb_samples, enum AVSampleFormat sample_fmt, int align); yading@11: yading@11: /** yading@11: * Copy samples from src to dst. yading@11: * yading@11: * @param dst destination array of pointers to data planes yading@11: * @param src source array of pointers to data planes yading@11: * @param dst_offset offset in samples at which the data will be written to dst yading@11: * @param src_offset offset in samples at which the data will be read from src yading@11: * @param nb_samples number of samples to be copied yading@11: * @param nb_channels number of audio channels yading@11: * @param sample_fmt audio sample format yading@11: */ yading@11: int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset, yading@11: int src_offset, int nb_samples, int nb_channels, yading@11: enum AVSampleFormat sample_fmt); yading@11: yading@11: /** yading@11: * Fill an audio buffer with silence. yading@11: * yading@11: * @param audio_data array of pointers to data planes yading@11: * @param offset offset in samples at which to start filling yading@11: * @param nb_samples number of samples to fill yading@11: * @param nb_channels number of audio channels yading@11: * @param sample_fmt audio sample format yading@11: */ yading@11: int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, yading@11: int nb_channels, enum AVSampleFormat sample_fmt); yading@11: yading@11: #endif /* AVUTIL_SAMPLEFMT_H */