FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
audio_fifo.h
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 Buffer
25  */
26 
27 #ifndef AVUTIL_AUDIO_FIFO_H
28 #define AVUTIL_AUDIO_FIFO_H
29 
30 #include "avutil.h"
31 #include "fifo.h"
32 #include "samplefmt.h"
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 typedef struct AVAudioFifo AVAudioFifo;
50 
51 /**
52  * Free an AVAudioFifo.
53  *
54  * @param af AVAudioFifo to free
55  */
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  */
67  int nb_samples);
68 
69 /**
70  * Reallocate an AVAudioFifo.
71  *
72  * @param af AVAudioFifo to reallocate
73  * @param nb_samples new allocation size, in samples
74  * @return 0 if OK, or negative AVERROR code on failure
75  */
78 
79 /**
80  * Write data to an AVAudioFifo.
81  *
82  * The AVAudioFifo will be reallocated automatically if the available space
83  * is less than nb_samples.
84  *
85  * @see enum AVSampleFormat
86  * The documentation for AVSampleFormat describes the data layout.
87  *
88  * @param af AVAudioFifo to write to
89  * @param data audio data plane pointers
90  * @param nb_samples number of samples to write
91  * @return number of samples actually written, or negative AVERROR
92  * code on failure. If successful, the number of samples
93  * actually written will always be nb_samples.
94  */
95 int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
96 
97 /**
98  * Peek data from an AVAudioFifo.
99  *
100  * @see enum AVSampleFormat
101  * The documentation for AVSampleFormat describes the data layout.
102  *
103  * @param af AVAudioFifo to read from
104  * @param data audio data plane pointers
105  * @param nb_samples number of samples to peek
106  * @return number of samples actually peek, or negative AVERROR code
107  * on failure. The number of samples actually peek will not
108  * be greater than nb_samples, and will only be less than
109  * nb_samples if av_audio_fifo_size is less than nb_samples.
110  */
111 int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples);
112 
113 /**
114  * Peek data from an AVAudioFifo.
115  *
116  * @see enum AVSampleFormat
117  * The documentation for AVSampleFormat describes the data layout.
118  *
119  * @param af AVAudioFifo to read from
120  * @param data audio data plane pointers
121  * @param nb_samples number of samples to peek
122  * @param offset offset from current read position
123  * @return number of samples actually peek, or negative AVERROR code
124  * on failure. The number of samples actually peek will not
125  * be greater than nb_samples, and will only be less than
126  * nb_samples if av_audio_fifo_size is less than nb_samples.
127  */
128 int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, 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 **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  */
156 
157 /**
158  * Reset the AVAudioFifo buffer.
159  *
160  * This empties all data in the buffer.
161  *
162  * @param af AVAudioFifo to reset
163  */
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  */
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  */
181 
182 /**
183  * @}
184  * @}
185  */
186 
187 #endif /* AVUTIL_AUDIO_FIFO_H */
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:59
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:181
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
channels
Definition: aptx.c:30
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
Convenience header that includes libavutil's core.
enum AVSampleFormat sample_fmt
sample format
Definition: audio_fifo.c:41
int av_audio_fifo_space(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for writing.
Definition: audio_fifo.c:233
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
Context for an Audio FIFO Buffer.
Definition: audio_fifo.c:34
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:228
av_warn_unused_result int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples)
Reallocate an AVAudioFifo.
Definition: audio_fifo.c:96
int nb_samples
number of samples currently in the FIFO
Definition: audio_fifo.c:37
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
a very simple circular buffer FIFO implementation
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples)
Write data to an AVAudioFifo.
Definition: audio_fifo.c:112
#define av_warn_unused_result
Definition: attributes.h:56
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:201
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples)
Peek data from an AVAudioFifo.
Definition: audio_fifo.c:138
int av_audio_fifo_peek_at(AVAudioFifo *af, void **data, int nb_samples, int offset)
Peek data from an AVAudioFifo.
Definition: audio_fifo.c:157
void av_audio_fifo_reset(AVAudioFifo *af)
Reset the AVAudioFifo buffer.
Definition: audio_fifo.c:218