2012-03-24 00:45:48 +03:00
|
|
|
/*
|
|
|
|
* Audio FIFO
|
|
|
|
* Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
|
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* This file is part of FFmpeg.
|
2012-03-24 00:45:48 +03:00
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2012-03-24 00:45:48 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2013-08-16 00:12:51 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2012-03-24 00:45:48 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2013-08-16 00:12:51 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2012-03-24 00:45:48 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Audio FIFO Buffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVUTIL_AUDIO_FIFO_H
|
|
|
|
#define AVUTIL_AUDIO_FIFO_H
|
|
|
|
|
|
|
|
#include "avutil.h"
|
|
|
|
#include "fifo.h"
|
|
|
|
#include "samplefmt.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup lavu_audio
|
|
|
|
* @{
|
2014-07-04 21:06:43 +03:00
|
|
|
*
|
2014-07-06 20:54:17 +03:00
|
|
|
* @defgroup lavu_audiofifo Audio FIFO Buffer
|
2014-07-04 21:06:43 +03:00
|
|
|
* @{
|
2012-03-24 00:45:48 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context for an Audio FIFO Buffer.
|
|
|
|
*
|
|
|
|
* - Operates at the sample level rather than the byte level.
|
|
|
|
* - Supports multiple channels with either planar or packed sample format.
|
|
|
|
* - Automatic reallocation when writing to a full buffer.
|
|
|
|
*/
|
|
|
|
typedef struct AVAudioFifo AVAudioFifo;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to free
|
|
|
|
*/
|
|
|
|
void av_audio_fifo_free(AVAudioFifo *af);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* @param sample_fmt sample format
|
|
|
|
* @param channels number of channels
|
|
|
|
* @param nb_samples initial allocation size, in samples
|
|
|
|
* @return newly allocated AVAudioFifo, or NULL on error
|
|
|
|
*/
|
|
|
|
AVAudioFifo *av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels,
|
|
|
|
int nb_samples);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reallocate an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to reallocate
|
|
|
|
* @param nb_samples new allocation size, in samples
|
|
|
|
* @return 0 if OK, or negative AVERROR code on failure
|
|
|
|
*/
|
|
|
|
int av_audio_fifo_realloc(AVAudioFifo *af, int nb_samples);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write data to an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* The AVAudioFifo will be reallocated automatically if the available space
|
|
|
|
* is less than nb_samples.
|
|
|
|
*
|
|
|
|
* @see enum AVSampleFormat
|
|
|
|
* The documentation for AVSampleFormat describes the data layout.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to write to
|
|
|
|
* @param data audio data plane pointers
|
|
|
|
* @param nb_samples number of samples to write
|
|
|
|
* @return number of samples actually written, or negative AVERROR
|
2013-03-09 08:48:43 +03:00
|
|
|
* code on failure. If successful, the number of samples
|
|
|
|
* actually written will always be nb_samples.
|
2012-03-24 00:45:48 +03:00
|
|
|
*/
|
|
|
|
int av_audio_fifo_write(AVAudioFifo *af, void **data, int nb_samples);
|
|
|
|
|
2015-08-04 14:41:35 +02:00
|
|
|
/**
|
|
|
|
* Peek data from an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* @see enum AVSampleFormat
|
|
|
|
* The documentation for AVSampleFormat describes the data layout.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to read from
|
|
|
|
* @param data audio data plane pointers
|
|
|
|
* @param nb_samples number of samples to peek
|
|
|
|
* @return number of samples actually peek, or negative AVERROR code
|
|
|
|
* on failure. The number of samples actually peek will not
|
|
|
|
* be greater than nb_samples, and will only be less than
|
|
|
|
* nb_samples if av_audio_fifo_size is less than nb_samples.
|
|
|
|
*/
|
|
|
|
int av_audio_fifo_peek(AVAudioFifo *af, void **data, int nb_samples);
|
|
|
|
|
2012-03-24 00:45:48 +03:00
|
|
|
/**
|
|
|
|
* Read data from an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* @see enum AVSampleFormat
|
|
|
|
* The documentation for AVSampleFormat describes the data layout.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to read from
|
|
|
|
* @param data audio data plane pointers
|
|
|
|
* @param nb_samples number of samples to read
|
|
|
|
* @return number of samples actually read, or negative AVERROR code
|
2013-03-09 08:48:43 +03:00
|
|
|
* on failure. The number of samples actually read will not
|
|
|
|
* be greater than nb_samples, and will only be less than
|
|
|
|
* nb_samples if av_audio_fifo_size is less than nb_samples.
|
2012-03-24 00:45:48 +03:00
|
|
|
*/
|
|
|
|
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drain data from an AVAudioFifo.
|
|
|
|
*
|
|
|
|
* Removes the data without reading it.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to drain
|
|
|
|
* @param nb_samples number of samples to drain
|
|
|
|
* @return 0 if OK, or negative AVERROR code on failure
|
|
|
|
*/
|
|
|
|
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the AVAudioFifo buffer.
|
|
|
|
*
|
|
|
|
* This empties all data in the buffer.
|
|
|
|
*
|
|
|
|
* @param af AVAudioFifo to reset
|
|
|
|
*/
|
|
|
|
void av_audio_fifo_reset(AVAudioFifo *af);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current number of samples in the AVAudioFifo available for reading.
|
|
|
|
*
|
|
|
|
* @param af the AVAudioFifo to query
|
|
|
|
* @return number of samples available for reading
|
|
|
|
*/
|
|
|
|
int av_audio_fifo_size(AVAudioFifo *af);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current number of samples in the AVAudioFifo available for writing.
|
|
|
|
*
|
|
|
|
* @param af the AVAudioFifo to query
|
|
|
|
* @return number of samples available for writing
|
|
|
|
*/
|
|
|
|
int av_audio_fifo_space(AVAudioFifo *af);
|
|
|
|
|
|
|
|
/**
|
2014-07-04 21:06:43 +03:00
|
|
|
* @}
|
2012-03-24 00:45:48 +03:00
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /* AVUTIL_AUDIO_FIFO_H */
|