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
33
35 AVFifoBuffer **
buf;
/**< single buffer for interleaved, per-channel buffers for planar */
37 int nb_samples;
/**< number of samples currently in the FIFO */
39
42 int sample_size;
/**< size, in bytes, of one sample in a buffer */
43 };
44
46 {
47 if (af) {
52 }
54 }
56 }
57 }
58
60 int nb_samples)
61 {
64
65 /* get channel buffer size (also validates parameters) */
68
70 if (!af)
72
77
81
86 }
88
89 return af;
90
94 }
95
97 {
99
103
107 }
109 return 0;
110 }
111
113 {
115
116 /* automatically reallocate buffers if needed */
119 /* check for integer overflow in new size calculation */
120 if (INT_MAX / 2 - current_size < nb_samples)
122 /* reallocate buffers */
125 }
126
132 }
134
135 return nb_samples;
136 }
137
139 {
141
142 if (nb_samples < 0)
145 if (!nb_samples)
146 return 0;
147
152 }
153
154 return nb_samples;
155 }
156
158 {
160
163 if (nb_samples < 0)
166 if (!nb_samples)
167 return 0;
170
176 }
177
178 return nb_samples;
179 }
180
182 {
184
185 if (nb_samples < 0)
188 if (!nb_samples)
189 return 0;
190
195 }
197
198 return nb_samples;
199 }
200
202 {
204
205 if (nb_samples < 0)
208
209 if (nb_samples) {
214 }
215 return 0;
216 }
217
219 {
221
224
226 }
227
229 {
231 }
232
234 {
236 }
static void error(const char *err)
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
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_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer.
int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)
Reallocate an AVAudioFifo.
int av_fifo_generic_peek(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback.
void av_fifo_reset(AVFifoBuffer *f)
Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied.
void av_fifo_drain(AVFifoBuffer *f, int size)
Discard data from the FIFO.
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 channels
number of channels
int sample_size
size, in bytes, of one sample in a buffer
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size)
Resize an AVFifoBuffer.
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int offset)
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.
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
#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)
enum AVSampleFormat sample_fmt
sample format
int allocated_samples
current allocated size, in samples
int nb_buffers
number of buffers
int av_fifo_generic_peek_at(AVFifoBuffer *f, void *dest, int offset, int buf_size, void(*func)(void *, void *, int))
Feed data at specific position from an AVFifoBuffer to a user-supplied callback.
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL.
int av_audio_fifo_space(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for writing.
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_audio_fifo_reset(AVAudioFifo *af)
Reset the AVAudioFifo buffer.
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
AVFifoBuffer ** buf
single buffer for interleaved, per-channel buffers for planar
Generated on Wed Aug 24 2022 21:38:28 for FFmpeg by
doxygen
1.8.17