h264: on reference overflow, reset the reference count to 0, not 1.
[FFMpeg-mirror/mplayer-patches.git] / libavutil / audio_fifo.h
blob8c76388255bfbdf18d41cc6076cd7336ee12a1cf
1 /*
2 * Audio FIFO
3 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
5 * This file is part of Libav.
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.
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.
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
22 /**
23 * @file
24 * Audio FIFO Buffer
27 #ifndef AVUTIL_AUDIO_FIFO_H
28 #define AVUTIL_AUDIO_FIFO_H
30 #include "avutil.h"
31 #include "fifo.h"
32 #include "samplefmt.h"
34 /**
35 * @addtogroup lavu_audio
36 * @{
39 /**
40 * Context for an Audio FIFO Buffer.
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.
46 typedef struct AVAudioFifo AVAudioFifo;
48 /**
49 * Free an AVAudioFifo.
51 * @param af AVAudioFifo to free
53 void av_audio_fifo_free(AVAudioFifo *af);
55 /**
56 * Allocate an AVAudioFifo.
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
63 AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
64 int nb_samples);
66 /**
67 * Reallocate an AVAudioFifo.
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
73 int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);
75 /**
76 * Write data to an AVAudioFifo.
78 * The AVAudioFifo will be reallocated automatically if the available space
79 * is less than nb_samples.
81 * @see enum AVSampleFormat
82 * The documentation for AVSampleFormat describes the data layout.
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.
90 int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
92 /**
93 * Read data from an AVAudioFifo.
95 * @see enum AVSampleFormat
96 * The documentation for AVSampleFormat describes the data layout.
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.
104 int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
107 * Drain data from an AVAudioFifo.
109 * Removes the data without reading it.
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
115 int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);
118 * Reset the AVAudioFifo buffer.
120 * This empties all data in the buffer.
122 * @param af AVAudioFifo to reset
124 void av_audio_fifo_reset(AVAudioFifo *af);
127 * Get the current number of samples in the AVAudioFifo available for reading.
129 * @param af the AVAudioFifo to query
130 * @return number of samples available for reading
132 int av_audio_fifo_size(AVAudioFifo *af);
135 * Get the current number of samples in the AVAudioFifo available for writing.
137 * @param af the AVAudioFifo to query
138 * @return number of samples available for writing
140 int av_audio_fifo_space(AVAudioFifo *af);
143 * @}
146 #endif /* AVUTIL_AUDIO_FIFO_H */