/*1* Audio FIFO2* Copyright (c) 2012 Justin Ruggles <[email protected]>3*4* This file is part of FFmpeg.5*6* FFmpeg is free software; you can redistribute it and/or7* modify it under the terms of the GNU Lesser General Public8* License as published by the Free Software Foundation; either9* version 2.1 of the License, or (at your option) any later version.10*11* FFmpeg is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14* Lesser General Public License for more details.15*16* You should have received a copy of the GNU Lesser General Public17* License along with FFmpeg; if not, write to the Free Software18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19*/2021/**22* @file23* Audio FIFO Buffer24*/2526#ifndef AVUTIL_AUDIO_FIFO_H27#define AVUTIL_AUDIO_FIFO_H2829#include "avutil.h"30#include "fifo.h"31#include "samplefmt.h"3233/**34* @addtogroup lavu_audio35* @{36*37* @defgroup lavu_audiofifo Audio FIFO Buffer38* @{39*/4041/**42* Context for an Audio FIFO Buffer.43*44* - Operates at the sample level rather than the byte level.45* - Supports multiple channels with either planar or packed sample format.46* - Automatic reallocation when writing to a full buffer.47*/48typedef struct AVAudioFifo AVAudioFifo;4950/**51* Free an AVAudioFifo.52*53* @param af AVAudioFifo to free54*/55void av_audio_fifo_free(AVAudioFifo *af);5657/**58* Allocate an AVAudioFifo.59*60* @param sample_fmt sample format61* @param channels number of channels62* @param nb_samples initial allocation size, in samples63* @return newly allocated AVAudioFifo, or NULL on error64*/65AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,66int nb_samples);6768/**69* Reallocate an AVAudioFifo.70*71* @param af AVAudioFifo to reallocate72* @param nb_samples new allocation size, in samples73* @return 0 if OK, or negative AVERROR code on failure74*/75av_warn_unused_result76int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);7778/**79* Write data to an AVAudioFifo.80*81* The AVAudioFifo will be reallocated automatically if the available space82* is less than nb_samples.83*84* @see enum AVSampleFormat85* The documentation for AVSampleFormat describes the data layout.86*87* @param af AVAudioFifo to write to88* @param data audio data plane pointers89* @param nb_samples number of samples to write90* @return number of samples actually written, or negative AVERROR91* code on failure. If successful, the number of samples92* actually written will always be nb_samples.93*/94int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);9596/**97* Peek data from an AVAudioFifo.98*99* @see enum AVSampleFormat100* The documentation for AVSampleFormat describes the data layout.101*102* @param af AVAudioFifo to read from103* @param data audio data plane pointers104* @param nb_samples number of samples to peek105* @return number of samples actually peek, or negative AVERROR code106* on failure. The number of samples actually peek will not107* be greater than nb_samples, and will only be less than108* nb_samples if av_audio_fifo_size is less than nb_samples.109*/110int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples);111112/**113* Read data from an AVAudioFifo.114*115* @see enum AVSampleFormat116* The documentation for AVSampleFormat describes the data layout.117*118* @param af AVAudioFifo to read from119* @param data audio data plane pointers120* @param nb_samples number of samples to read121* @return number of samples actually read, or negative AVERROR code122* on failure. The number of samples actually read will not123* be greater than nb_samples, and will only be less than124* nb_samples if av_audio_fifo_size is less than nb_samples.125*/126int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);127128/**129* Drain data from an AVAudioFifo.130*131* Removes the data without reading it.132*133* @param af AVAudioFifo to drain134* @param nb_samples number of samples to drain135* @return 0 if OK, or negative AVERROR code on failure136*/137int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);138139/**140* Reset the AVAudioFifo buffer.141*142* This empties all data in the buffer.143*144* @param af AVAudioFifo to reset145*/146void av_audio_fifo_reset(AVAudioFifo *af);147148/**149* Get the current number of samples in the AVAudioFifo available for reading.150*151* @param af the AVAudioFifo to query152* @return number of samples available for reading153*/154int av_audio_fifo_size(AVAudioFifo *af);155156/**157* Get the current number of samples in the AVAudioFifo available for writing.158*159* @param af the AVAudioFifo to query160* @return number of samples available for writing161*/162int av_audio_fifo_space(AVAudioFifo *af);163164/**165* @}166* @}167*/168169#endif /* AVUTIL_AUDIO_FIFO_H */170171172