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