FFmpeg: libavutil/audio_fifo.c Source File
Go to the documentation of this file. 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
25 */
26
28 #include <stddef.h>
29
36
38 AVFifo **
buf;
/**< single buffer for interleaved, per-channel buffers for planar */
40 int nb_samples;
/**< number of samples currently in the FIFO */
42
45 int sample_size;
/**< size, in bytes, of one sample in a buffer */
46 };
47
49 {
50 if (af) {
55 }
57 }
59 }
60 }
61
63 int nb_samples)
64 {
67
68 /* get channel buffer size (also validates parameters) */
71
73 if (!af)
75
80
84
89 }
91
92 return af;
93
97 }
98
100 {
103 int i,
ret, buf_size;
104
108
109 if (buf_size > cur_size) {
113 }
114 }
116 return 0;
117 }
118
120 {
122
123 /* automatically reallocate buffers if needed */
126 /* check for integer overflow in new size calculation */
127 if (INT_MAX / 2 - current_size < nb_samples)
129 /* reallocate buffers */
132 }
133
139 }
141
142 return nb_samples;
143 }
144
146 {
148 }
149
151 int nb_samples,
int offset)
152 {
154
157 if (nb_samples < 0)
160 if (!nb_samples)
161 return 0;
164
170 }
171
172 return nb_samples;
173 }
174
176 {
178
179 if (nb_samples < 0)
182 if (!nb_samples)
183 return 0;
184
189 }
191
192 return nb_samples;
193 }
194
196 {
198
199 if (nb_samples < 0)
202
203 if (nb_samples) {
208 }
209 return 0;
210 }
211
213 {
215
218
220 }
221
223 {
225 }
226
228 {
230 }
static void error(const char *err)
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
size_t av_fifo_can_write(const AVFifo *f)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)
Reallocate an AVAudioFifo.
int av_fifo_peek(const AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
int nb_samples
number of samples currently in the FIFO
Context for an Audio FIFO Buffer.
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
int av_fifo_grow2(AVFifo *f, size_t inc)
Enlarge an AVFifo.
int channels
number of channels
int sample_size
size, in bytes, of one sample in a buffer
int av_fifo_read(AVFifo *f, void *buf, size_t nb_elems)
Read data from a FIFO.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
AVFifo ** buf
single buffer for interleaved, per-channel buffers for planar
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
size_t av_fifo_can_read(const AVFifo *f)
void av_fifo_reset2(AVFifo *f)
int av_audio_fifo_read(AVAudioFifo *af, void *const *data, int nb_samples)
Read data from an AVAudioFifo.
int av_audio_fifo_peek(const AVAudioFifo *af, void *const *data, int nb_samples)
Peek data from an AVAudioFifo.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
#define i(width, name, range_min, range_max)
AVSampleFormat
Audio sample formats.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
void * av_calloc(size_t nmemb, size_t size)
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
enum AVSampleFormat sample_fmt
sample format
int allocated_samples
current allocated size, in samples
int nb_buffers
number of buffers
int av_audio_fifo_space(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for writing.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
void av_audio_fifo_reset(AVAudioFifo *af)
Reset the AVAudioFifo buffer.
int av_audio_fifo_peek_at(const AVAudioFifo *af, void *const *data, int nb_samples, int offset)
Peek data from an AVAudioFifo.
Generated on Fri Aug 22 2025 13:59:38 for FFmpeg by
doxygen
1.8.17