/*1* Copyright (c) 2012 Justin Ruggles <[email protected]>2*3* This file is part of FFmpeg.4*5* FFmpeg is free software; you can redistribute it and/or6* modify it under the terms of the GNU Lesser General Public7* License as published by the Free Software Foundation; either8* version 2.1 of the License, or (at your option) any later version.9*10* FFmpeg is distributed in the hope that it will be useful,11* but WITHOUT ANY WARRANTY; without even the implied warranty of12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU13* Lesser General Public License for more details.14*15* You should have received a copy of the GNU Lesser General Public16* License along with FFmpeg; if not, write to the Free Software17* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA18*/1920#ifndef AVRESAMPLE_AUDIO_DATA_H21#define AVRESAMPLE_AUDIO_DATA_H2223#include <stdint.h>2425#include "libavutil/audio_fifo.h"26#include "libavutil/log.h"27#include "libavutil/samplefmt.h"28#include "avresample.h"29#include "internal.h"3031int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int channels);3233/**34* Audio buffer used for intermediate storage between conversion phases.35*/36struct AudioData {37const AVClass *class; /**< AVClass for logging */38uint8_t *data[AVRESAMPLE_MAX_CHANNELS]; /**< data plane pointers */39uint8_t *buffer; /**< data buffer */40unsigned int buffer_size; /**< allocated buffer size */41int allocated_samples; /**< number of samples the buffer can hold */42int nb_samples; /**< current number of samples */43enum AVSampleFormat sample_fmt; /**< sample format */44int channels; /**< channel count */45int allocated_channels; /**< allocated channel count */46int is_planar; /**< sample format is planar */47int planes; /**< number of data planes */48int sample_size; /**< bytes per sample */49int stride; /**< sample byte offset within a plane */50int read_only; /**< data is read-only */51int allow_realloc; /**< realloc is allowed */52int ptr_align; /**< minimum data pointer alignment */53int samples_align; /**< allocated samples alignment */54const char *name; /**< name for debug logging */55};5657int ff_audio_data_set_channels(AudioData *a, int channels);5859/**60* Initialize AudioData using a given source.61*62* This does not allocate an internal buffer. It only sets the data pointers63* and audio parameters.64*65* @param a AudioData struct66* @param src source data pointers67* @param plane_size plane size, in bytes.68* This can be 0 if unknown, but that will lead to69* optimized functions not being used in many cases,70* which could slow down some conversions.71* @param channels channel count72* @param nb_samples number of samples in the source data73* @param sample_fmt sample format74* @param read_only indicates if buffer is read only or read/write75* @param name name for debug logging (can be NULL)76* @return 0 on success, negative AVERROR value on error77*/78int ff_audio_data_init(AudioData *a, uint8_t * const *src, int plane_size,79int channels, int nb_samples,80enum AVSampleFormat sample_fmt, int read_only,81const char *name);8283/**84* Allocate AudioData.85*86* This allocates an internal buffer and sets audio parameters.87*88* @param channels channel count89* @param nb_samples number of samples to allocate space for90* @param sample_fmt sample format91* @param name name for debug logging (can be NULL)92* @return newly allocated AudioData struct, or NULL on error93*/94AudioData *ff_audio_data_alloc(int channels, int nb_samples,95enum AVSampleFormat sample_fmt,96const char *name);9798/**99* Reallocate AudioData.100*101* The AudioData must have been previously allocated with ff_audio_data_alloc().102*103* @param a AudioData struct104* @param nb_samples number of samples to allocate space for105* @return 0 on success, negative AVERROR value on error106*/107int ff_audio_data_realloc(AudioData *a, int nb_samples);108109/**110* Free AudioData.111*112* The AudioData must have been previously allocated with ff_audio_data_alloc().113*114* @param a AudioData struct115*/116void ff_audio_data_free(AudioData **a);117118/**119* Copy data from one AudioData to another.120*121* @param out output AudioData122* @param in input AudioData123* @param map channel map, NULL if not remapping124* @return 0 on success, negative AVERROR value on error125*/126int ff_audio_data_copy(AudioData *out, AudioData *in, ChannelMapInfo *map);127128/**129* Append data from one AudioData to the end of another.130*131* @param dst destination AudioData132* @param dst_offset offset, in samples, to start writing, relative to the133* start of dst134* @param src source AudioData135* @param src_offset offset, in samples, to start copying, relative to the136* start of the src137* @param nb_samples number of samples to copy138* @return 0 on success, negative AVERROR value on error139*/140int ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src,141int src_offset, int nb_samples);142143/**144* Drain samples from the start of the AudioData.145*146* Remaining samples are shifted to the start of the AudioData.147*148* @param a AudioData struct149* @param nb_samples number of samples to drain150*/151void ff_audio_data_drain(AudioData *a, int nb_samples);152153/**154* Add samples in AudioData to an AVAudioFifo.155*156* @param af Audio FIFO Buffer157* @param a AudioData struct158* @param offset number of samples to skip from the start of the data159* @param nb_samples number of samples to add to the FIFO160* @return number of samples actually added to the FIFO, or161* negative AVERROR code on error162*/163int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset,164int nb_samples);165166/**167* Read samples from an AVAudioFifo to AudioData.168*169* @param af Audio FIFO Buffer170* @param a AudioData struct171* @param nb_samples number of samples to read from the FIFO172* @return number of samples actually read from the FIFO, or173* negative AVERROR code on error174*/175int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples);176177#endif /* AVRESAMPLE_AUDIO_DATA_H */178179180