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