| 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 | #ifndef AVUTIL_AUDIO_FIFO_H |
| 28 | #define AVUTIL_AUDIO_FIFO_H |
| 29 |
| 30 | #include "attributes.h" |
| 31 | #include "samplefmt.h" |
| 32 |
| 33 | /** |
| 34 | * @addtogroup lavu_audio |
| 35 | * @{ |
| 36 | * |
| 37 | * @defgroup lavu_audiofifo Audio FIFO Buffer |
| 38 | * @{ |
| 39 | */ |
| 40 |
| 41 | /** |
| 42 | * Context for an Audio FIFO Buffer. |
| 43 | * |
| 44 | * - Operates at the sample level rather than the byte level. |
| 45 | * - Supports multiple channels with either planar or packed sample format. |
| 46 | * - Automatic reallocation when writing to a full buffer. |
| 47 | */ |
| 48 | typedef struct AVAudioFifo AVAudioFifo; |
| 49 |
| 50 | /** |
| 51 | * Free an AVAudioFifo. |
| 52 | * |
| 53 | * @param af AVAudioFifo to free |
| 54 | */ |
| 55 | void av_audio_fifo_free(AVAudioFifo *af); |
| 56 |
| 57 | /** |
| 58 | * Allocate an AVAudioFifo. |
| 59 | * |
| 60 | * @param sample_fmt sample format |
| 61 | * @param channels number of channels |
| 62 | * @param nb_samples initial allocation size, in samples |
| 63 | * @return newly allocated AVAudioFifo, or NULL on error |
| 64 | */ |
| 65 | AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, |
| 66 | int nb_samples); |
| 67 |
| 68 | /** |
| 69 | * Reallocate an AVAudioFifo. |
| 70 | * |
| 71 | * @param af AVAudioFifo to reallocate |
| 72 | * @param nb_samples new allocation size, in samples |
| 73 | * @return 0 if OK, or negative AVERROR code on failure |
| 74 | */ |
| 75 | av_warn_unused_result |
| 76 | int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples); |
| 77 |
| 78 | /** |
| 79 | * Write data to an AVAudioFifo. |
| 80 | * |
| 81 | * The AVAudioFifo will be reallocated automatically if the available space |
| 82 | * is less than nb_samples. |
| 83 | * |
| 84 | * @see enum AVSampleFormat |
| 85 | * The documentation for AVSampleFormat describes the data layout. |
| 86 | * |
| 87 | * @param af AVAudioFifo to write to |
| 88 | * @param data audio data plane pointers |
| 89 | * @param nb_samples number of samples to write |
| 90 | * @return number of samples actually written, or negative AVERROR |
| 91 | * code on failure. If successful, the number of samples |
| 92 | * actually written will always be nb_samples. |
| 93 | */ |
| 94 | int av_audio_fifo_write(AVAudioFifo *af, void * const *data, int nb_samples); |
| 95 |
| 96 | /** |
| 97 | * Peek data from an AVAudioFifo. |
| 98 | * |
| 99 | * @see enum AVSampleFormat |
| 100 | * The documentation for AVSampleFormat describes the data layout. |
| 101 | * |
| 102 | * @param af AVAudioFifo to read from |
| 103 | * @param data audio data plane pointers |
| 104 | * @param nb_samples number of samples to peek |
| 105 | * @return number of samples actually peek, or negative AVERROR code |
| 106 | * on failure. The number of samples actually peek will not |
| 107 | * be greater than nb_samples, and will only be less than |
| 108 | * nb_samples if av_audio_fifo_size is less than nb_samples. |
| 109 | */ |
| 110 | int av_audio_fifo_peek(const AVAudioFifo *af, void * const *data, int nb_samples); |
| 111 |
| 112 | /** |
| 113 | * Peek data from an AVAudioFifo. |
| 114 | * |
| 115 | * @see enum AVSampleFormat |
| 116 | * The documentation for AVSampleFormat describes the data layout. |
| 117 | * |
| 118 | * @param af AVAudioFifo to read from |
| 119 | * @param data audio data plane pointers |
| 120 | * @param nb_samples number of samples to peek |
| 121 | * @param offset offset from current read position |
| 122 | * @return number of samples actually peek, or negative AVERROR code |
| 123 | * on failure. The number of samples actually peek will not |
| 124 | * be greater than nb_samples, and will only be less than |
| 125 | * nb_samples if av_audio_fifo_size is less than nb_samples. |
| 126 | */ |
| 127 | int av_audio_fifo_peek_at(const AVAudioFifo *af, void * const *data, |
| 128 | int nb_samples, int offset); |
| 129 |
| 130 | /** |
| 131 | * Read data from an AVAudioFifo. |
| 132 | * |
| 133 | * @see enum AVSampleFormat |
| 134 | * The documentation for AVSampleFormat describes the data layout. |
| 135 | * |
| 136 | * @param af AVAudioFifo to read from |
| 137 | * @param data audio data plane pointers |
| 138 | * @param nb_samples number of samples to read |
| 139 | * @return number of samples actually read, or negative AVERROR code |
| 140 | * on failure. The number of samples actually read will not |
| 141 | * be greater than nb_samples, and will only be less than |
| 142 | * nb_samples if av_audio_fifo_size is less than nb_samples. |
| 143 | */ |
| 144 | int av_audio_fifo_read(AVAudioFifo *af, void * const *data, int nb_samples); |
| 145 |
| 146 | /** |
| 147 | * Drain data from an AVAudioFifo. |
| 148 | * |
| 149 | * Removes the data without reading it. |
| 150 | * |
| 151 | * @param af AVAudioFifo to drain |
| 152 | * @param nb_samples number of samples to drain |
| 153 | * @return 0 if OK, or negative AVERROR code on failure |
| 154 | */ |
| 155 | int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples); |
| 156 |
| 157 | /** |
| 158 | * Reset the AVAudioFifo buffer. |
| 159 | * |
| 160 | * This empties all data in the buffer. |
| 161 | * |
| 162 | * @param af AVAudioFifo to reset |
| 163 | */ |
| 164 | void av_audio_fifo_reset(AVAudioFifo *af); |
| 165 |
| 166 | /** |
| 167 | * Get the current number of samples in the AVAudioFifo available for reading. |
| 168 | * |
| 169 | * @param af the AVAudioFifo to query |
| 170 | * @return number of samples available for reading |
| 171 | */ |
| 172 | int av_audio_fifo_size(AVAudioFifo *af); |
| 173 |
| 174 | /** |
| 175 | * Get the current number of samples in the AVAudioFifo available for writing. |
| 176 | * |
| 177 | * @param af the AVAudioFifo to query |
| 178 | * @return number of samples available for writing |
| 179 | */ |
| 180 | int av_audio_fifo_space(AVAudioFifo *af); |
| 181 |
| 182 | /** |
| 183 | * @} |
| 184 | * @} |
| 185 | */ |
| 186 |
| 187 | #endif /* AVUTIL_AUDIO_FIFO_H */ |
| 188 |