FFmpeg
 All Data Structures 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 Libav.
6  *
7  * Libav 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  * Libav 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 Libav; 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 
39 /**
40  * Context for an Audio FIFO Buffer.
41  *
42  * - Operates at the sample level rather than the byte level.
43  * - Supports multiple channels with either planar or packed sample format.
44  * - Automatic reallocation when writing to a full buffer.
45  */
46 typedef struct AVAudioFifo AVAudioFifo;
47 
48 /**
49  * Free an AVAudioFifo.
50  *
51  * @param af AVAudioFifo to free
52  */
54 
55 /**
56  * Allocate an AVAudioFifo.
57  *
58  * @param sample_fmt sample format
59  * @param channels number of channels
60  * @param nb_samples initial allocation size, in samples
61  * @return newly allocated AVAudioFifo, or NULL on error
62  */
64  int nb_samples);
65 
66 /**
67  * Reallocate an AVAudioFifo.
68  *
69  * @param af AVAudioFifo to reallocate
70  * @param nb_samples new allocation size, in samples
71  * @return 0 if OK, or negative AVERROR code on failure
72  */
74 
75 /**
76  * Write data to an AVAudioFifo.
77  *
78  * The AVAudioFifo will be reallocated automatically if the available space
79  * is less than nb_samples.
80  *
81  * @see enum AVSampleFormat
82  * The documentation for AVSampleFormat describes the data layout.
83  *
84  * @param af AVAudioFifo to write to
85  * @param data audio data plane pointers
86  * @param nb_samples number of samples to write
87  * @return number of samples actually written, or negative AVERROR
88  * code on failure.
89  */
90 int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
91 
92 /**
93  * Read data from an AVAudioFifo.
94  *
95  * @see enum AVSampleFormat
96  * The documentation for AVSampleFormat describes the data layout.
97  *
98  * @param af AVAudioFifo to read from
99  * @param data audio data plane pointers
100  * @param nb_samples number of samples to read
101  * @return number of samples actually read, or negative AVERROR code
102  * on failure.
103  */
104 int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
105 
106 /**
107  * Drain data from an AVAudioFifo.
108  *
109  * Removes the data without reading it.
110  *
111  * @param af AVAudioFifo to drain
112  * @param nb_samples number of samples to drain
113  * @return 0 if OK, or negative AVERROR code on failure
114  */
116 
117 /**
118  * Reset the AVAudioFifo buffer.
119  *
120  * This empties all data in the buffer.
121  *
122  * @param af AVAudioFifo to reset
123  */
125 
126 /**
127  * Get the current number of samples in the AVAudioFifo available for reading.
128  *
129  * @param af the AVAudioFifo to query
130  * @return number of samples available for reading
131  */
133 
134 /**
135  * Get the current number of samples in the AVAudioFifo available for writing.
136  *
137  * @param af the AVAudioFifo to query
138  * @return number of samples available for writing
139  */
141 
142 /**
143  * @}
144  */
145 
146 #endif /* AVUTIL_AUDIO_FIFO_H */