Path: blob/master/dep/ffmpeg/include/libavutil/audio_fifo.h
4216 views
/*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 "attributes.h"30#include "samplefmt.h"3132/**33* @addtogroup lavu_audio34* @{35*36* @defgroup lavu_audiofifo Audio FIFO Buffer37* @{38*/3940/**41* Context for an Audio FIFO Buffer.42*43* - Operates at the sample level rather than the byte level.44* - Supports multiple channels with either planar or packed sample format.45* - Automatic reallocation when writing to a full buffer.46*/47typedef struct AVAudioFifo AVAudioFifo;4849/**50* Free an AVAudioFifo.51*52* @param af AVAudioFifo to free53*/54void av_audio_fifo_free(AVAudioFifo *af);5556/**57* Allocate an AVAudioFifo.58*59* @param sample_fmt sample format60* @param channels number of channels61* @param nb_samples initial allocation size, in samples62* @return newly allocated AVAudioFifo, or NULL on error63*/64AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,65int nb_samples);6667/**68* Reallocate an AVAudioFifo.69*70* @param af AVAudioFifo to reallocate71* @param nb_samples new allocation size, in samples72* @return 0 if OK, or negative AVERROR code on failure73*/74av_warn_unused_result75int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);7677/**78* Write data to an AVAudioFifo.79*80* The AVAudioFifo will be reallocated automatically if the available space81* is less than nb_samples.82*83* @see enum AVSampleFormat84* The documentation for AVSampleFormat describes the data layout.85*86* @param af AVAudioFifo to write to87* @param data audio data plane pointers88* @param nb_samples number of samples to write89* @return number of samples actually written, or negative AVERROR90* code on failure. If successful, the number of samples91* actually written will always be nb_samples.92*/93int av_audio_fifo_write(AVAudioFifo *af, void * const *data, int nb_samples);9495/**96* Peek data from an AVAudioFifo.97*98* @see enum AVSampleFormat99* The documentation for AVSampleFormat describes the data layout.100*101* @param af AVAudioFifo to read from102* @param data audio data plane pointers103* @param nb_samples number of samples to peek104* @return number of samples actually peek, or negative AVERROR code105* on failure. The number of samples actually peek will not106* be greater than nb_samples, and will only be less than107* nb_samples if av_audio_fifo_size is less than nb_samples.108*/109int av_audio_fifo_peek(const AVAudioFifo *af, void * const *data, int nb_samples);110111/**112* Peek data from an AVAudioFifo.113*114* @see enum AVSampleFormat115* The documentation for AVSampleFormat describes the data layout.116*117* @param af AVAudioFifo to read from118* @param data audio data plane pointers119* @param nb_samples number of samples to peek120* @param offset offset from current read position121* @return number of samples actually peek, or negative AVERROR code122* on failure. The number of samples actually peek 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_peek_at(const AVAudioFifo *af, void * const *data,127int nb_samples, int offset);128129/**130* Read data from an AVAudioFifo.131*132* @see enum AVSampleFormat133* The documentation for AVSampleFormat describes the data layout.134*135* @param af AVAudioFifo to read from136* @param data audio data plane pointers137* @param nb_samples number of samples to read138* @return number of samples actually read, or negative AVERROR code139* on failure. The number of samples actually read will not140* be greater than nb_samples, and will only be less than141* nb_samples if av_audio_fifo_size is less than nb_samples.142*/143int av_audio_fifo_read(AVAudioFifo *af, void * const *data, int nb_samples);144145/**146* Drain data from an AVAudioFifo.147*148* Removes the data without reading it.149*150* @param af AVAudioFifo to drain151* @param nb_samples number of samples to drain152* @return 0 if OK, or negative AVERROR code on failure153*/154int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);155156/**157* Reset the AVAudioFifo buffer.158*159* This empties all data in the buffer.160*161* @param af AVAudioFifo to reset162*/163void av_audio_fifo_reset(AVAudioFifo *af);164165/**166* Get the current number of samples in the AVAudioFifo available for reading.167*168* @param af the AVAudioFifo to query169* @return number of samples available for reading170*/171int av_audio_fifo_size(AVAudioFifo *af);172173/**174* Get the current number of samples in the AVAudioFifo available for writing.175*176* @param af the AVAudioFifo to query177* @return number of samples available for writing178*/179int av_audio_fifo_space(AVAudioFifo *af);180181/**182* @}183* @}184*/185186#endif /* AVUTIL_AUDIO_FIFO_H */187188189