1 /* 2 * Audio FIFO 3 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com> 4 * 5 * This file is part of FFmpeg. 6 * 7 * FFmpeg is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * FFmpeg is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with FFmpeg; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 /** 23 * @file 24 * Audio FIFO Buffer 25 */ 26 27 module ffmpeg.libavutil.audio_fifo; 28 29 import ffmpeg.libavutil.samplefmt; 30 31 extern (C): 32 import ffmpeg; @nogc nothrow: 33 34 /** 35 * @addtogroup lavu_audio 36 * @{ 37 * 38 * @defgroup lavu_audiofifo Audio FIFO Buffer 39 * @{ 40 */ 41 42 /** 43 * Context for an Audio FIFO Buffer. 44 * 45 * - Operates at the sample level rather than the byte level. 46 * - Supports multiple channels with either planar or packed sample format. 47 * - Automatic reallocation when writing to a full buffer. 48 */ 49 struct AVAudioFifo; 50 51 /** 52 * Free an AVAudioFifo. 53 * 54 * @param af AVAudioFifo to free 55 */ 56 void av_audio_fifo_free (AVAudioFifo* af); 57 58 /** 59 * Allocate an AVAudioFifo. 60 * 61 * @param sample_fmt sample format 62 * @param channels number of channels 63 * @param nb_samples initial allocation size, in samples 64 * @return newly allocated AVAudioFifo, or NULL on error 65 */ 66 AVAudioFifo* av_audio_fifo_alloc ( 67 AVSampleFormat sample_fmt, 68 int channels, 69 int nb_samples); 70 71 /** 72 * Reallocate an AVAudioFifo. 73 * 74 * @param af AVAudioFifo to reallocate 75 * @param nb_samples new allocation size, in samples 76 * @return 0 if OK, or negative AVERROR code on failure 77 */ 78 int av_audio_fifo_realloc (AVAudioFifo* af, int nb_samples); 79 80 /** 81 * Write data to an AVAudioFifo. 82 * 83 * The AVAudioFifo will be reallocated automatically if the available space 84 * is less than nb_samples. 85 * 86 * @see enum AVSampleFormat 87 * The documentation for AVSampleFormat describes the data layout. 88 * 89 * @param af AVAudioFifo to write to 90 * @param data audio data plane pointers 91 * @param nb_samples number of samples to write 92 * @return number of samples actually written, or negative AVERROR 93 * code on failure. If successful, the number of samples 94 * actually written will always be nb_samples. 95 */ 96 int av_audio_fifo_write (AVAudioFifo* af, void** data, int nb_samples); 97 98 /** 99 * Peek data from an AVAudioFifo. 100 * 101 * @see enum AVSampleFormat 102 * The documentation for AVSampleFormat describes the data layout. 103 * 104 * @param af AVAudioFifo to read from 105 * @param data audio data plane pointers 106 * @param nb_samples number of samples to peek 107 * @return number of samples actually peek, or negative AVERROR code 108 * on failure. The number of samples actually peek will not 109 * be greater than nb_samples, and will only be less than 110 * nb_samples if av_audio_fifo_size is less than nb_samples. 111 */ 112 int av_audio_fifo_peek (AVAudioFifo* af, void** data, int nb_samples); 113 114 /** 115 * Peek data from an AVAudioFifo. 116 * 117 * @see enum AVSampleFormat 118 * The documentation for AVSampleFormat describes the data layout. 119 * 120 * @param af AVAudioFifo to read from 121 * @param data audio data plane pointers 122 * @param nb_samples number of samples to peek 123 * @param offset offset from current read position 124 * @return number of samples actually peek, or negative AVERROR code 125 * on failure. The number of samples actually peek will not 126 * be greater than nb_samples, and will only be less than 127 * nb_samples if av_audio_fifo_size is less than nb_samples. 128 */ 129 int av_audio_fifo_peek_at (AVAudioFifo* af, void** data, int nb_samples, int offset); 130 131 /** 132 * Read data from an AVAudioFifo. 133 * 134 * @see enum AVSampleFormat 135 * The documentation for AVSampleFormat describes the data layout. 136 * 137 * @param af AVAudioFifo to read from 138 * @param data audio data plane pointers 139 * @param nb_samples number of samples to read 140 * @return number of samples actually read, or negative AVERROR code 141 * on failure. The number of samples actually read will not 142 * be greater than nb_samples, and will only be less than 143 * nb_samples if av_audio_fifo_size is less than nb_samples. 144 */ 145 int av_audio_fifo_read (AVAudioFifo* af, void** data, int nb_samples); 146 147 /** 148 * Drain data from an AVAudioFifo. 149 * 150 * Removes the data without reading it. 151 * 152 * @param af AVAudioFifo to drain 153 * @param nb_samples number of samples to drain 154 * @return 0 if OK, or negative AVERROR code on failure 155 */ 156 int av_audio_fifo_drain (AVAudioFifo* af, int nb_samples); 157 158 /** 159 * Reset the AVAudioFifo buffer. 160 * 161 * This empties all data in the buffer. 162 * 163 * @param af AVAudioFifo to reset 164 */ 165 void av_audio_fifo_reset (AVAudioFifo* af); 166 167 /** 168 * Get the current number of samples in the AVAudioFifo available for reading. 169 * 170 * @param af the AVAudioFifo to query 171 * @return number of samples available for reading 172 */ 173 int av_audio_fifo_size (AVAudioFifo* af); 174 175 /** 176 * Get the current number of samples in the AVAudioFifo available for writing. 177 * 178 * @param af the AVAudioFifo to query 179 * @return number of samples available for writing 180 */ 181 int av_audio_fifo_space (AVAudioFifo* af); 182 183 /** 184 * @} 185 * @} 186 */ 187 188 /* AVUTIL_AUDIO_FIFO_H */