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 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. If successful, the number of samples
89  * actually written will always be nb_samples.
90  */
91 int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
92 
93 /**
94  * Read data from an AVAudioFifo.
95  *
96  * @see enum AVSampleFormat
97  * The documentation for AVSampleFormat describes the data layout.
98  *
99  * @param af AVAudioFifo to read from
100  * @param data audio data plane pointers
101  * @param nb_samples number of samples to read
102  * @return number of samples actually read, or negative AVERROR code
103  * on failure. The number of samples actually read will not
104  * be greater than nb_samples, and will only be less than
105  * nb_samples if av_audio_fifo_size is less than nb_samples.
106  */
107 int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
108 
109 /**
110  * Drain data from an AVAudioFifo.
111  *
112  * Removes the data without reading it.
113  *
114  * @param af AVAudioFifo to drain
115  * @param nb_samples number of samples to drain
116  * @return 0 if OK, or negative AVERROR code on failure
117  */
119 
120 /**
121  * Reset the AVAudioFifo buffer.
122  *
123  * This empties all data in the buffer.
124  *
125  * @param af AVAudioFifo to reset
126  */
128 
129 /**
130  * Get the current number of samples in the AVAudioFifo available for reading.
131  *
132  * @param af the AVAudioFifo to query
133  * @return number of samples available for reading
134  */
136 
137 /**
138  * Get the current number of samples in the AVAudioFifo available for writing.
139  *
140  * @param af the AVAudioFifo to query
141  * @return number of samples available for writing
142  */
144 
145 /**
146  * @}
147  */
148 
149 #endif /* AVUTIL_AUDIO_FIFO_H */