yading@11: /* 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: #ifndef AVRESAMPLE_AUDIO_DATA_H yading@11: #define AVRESAMPLE_AUDIO_DATA_H yading@11: yading@11: #include yading@11: yading@11: #include "libavutil/audio_fifo.h" yading@11: #include "libavutil/log.h" yading@11: #include "libavutil/samplefmt.h" yading@11: #include "avresample.h" yading@11: #include "internal.h" yading@11: yading@11: /** yading@11: * Audio buffer used for intermediate storage between conversion phases. yading@11: */ yading@11: struct AudioData { yading@11: const AVClass *class; /**< AVClass for logging */ yading@11: uint8_t *data[AVRESAMPLE_MAX_CHANNELS]; /**< data plane pointers */ yading@11: uint8_t *buffer; /**< data buffer */ yading@11: unsigned int buffer_size; /**< allocated buffer size */ yading@11: int allocated_samples; /**< number of samples the buffer can hold */ yading@11: int nb_samples; /**< current number of samples */ yading@11: enum AVSampleFormat sample_fmt; /**< sample format */ yading@11: int channels; /**< channel count */ yading@11: int allocated_channels; /**< allocated channel count */ yading@11: int is_planar; /**< sample format is planar */ yading@11: int planes; /**< number of data planes */ yading@11: int sample_size; /**< bytes per sample */ yading@11: int stride; /**< sample byte offset within a plane */ yading@11: int read_only; /**< data is read-only */ yading@11: int allow_realloc; /**< realloc is allowed */ yading@11: int ptr_align; /**< minimum data pointer alignment */ yading@11: int samples_align; /**< allocated samples alignment */ yading@11: const char *name; /**< name for debug logging */ yading@11: }; yading@11: yading@11: int ff_audio_data_set_channels(AudioData *a, int channels); yading@11: yading@11: /** yading@11: * Initialize AudioData using a given source. yading@11: * yading@11: * This does not allocate an internal buffer. It only sets the data pointers yading@11: * and audio parameters. yading@11: * yading@11: * @param a AudioData struct yading@11: * @param src source data pointers yading@11: * @param plane_size plane size, in bytes. yading@11: * This can be 0 if unknown, but that will lead to yading@11: * optimized functions not being used in many cases, yading@11: * which could slow down some conversions. yading@11: * @param channels channel count yading@11: * @param nb_samples number of samples in the source data yading@11: * @param sample_fmt sample format yading@11: * @param read_only indicates if buffer is read only or read/write yading@11: * @param name name for debug logging (can be NULL) yading@11: * @return 0 on success, negative AVERROR value on error yading@11: */ yading@11: int ff_audio_data_init(AudioData *a, uint8_t **src, int plane_size, int channels, yading@11: int nb_samples, enum AVSampleFormat sample_fmt, yading@11: int read_only, const char *name); yading@11: yading@11: /** yading@11: * Allocate AudioData. yading@11: * yading@11: * This allocates an internal buffer and sets audio parameters. yading@11: * yading@11: * @param channels channel count yading@11: * @param nb_samples number of samples to allocate space for yading@11: * @param sample_fmt sample format yading@11: * @param name name for debug logging (can be NULL) yading@11: * @return newly allocated AudioData struct, or NULL on error yading@11: */ yading@11: AudioData *ff_audio_data_alloc(int channels, int nb_samples, yading@11: enum AVSampleFormat sample_fmt, yading@11: const char *name); yading@11: yading@11: /** yading@11: * Reallocate AudioData. yading@11: * yading@11: * The AudioData must have been previously allocated with ff_audio_data_alloc(). yading@11: * yading@11: * @param a AudioData struct yading@11: * @param nb_samples number of samples to allocate space for yading@11: * @return 0 on success, negative AVERROR value on error yading@11: */ yading@11: int ff_audio_data_realloc(AudioData *a, int nb_samples); yading@11: yading@11: /** yading@11: * Free AudioData. yading@11: * yading@11: * The AudioData must have been previously allocated with ff_audio_data_alloc(). yading@11: * yading@11: * @param a AudioData struct yading@11: */ yading@11: void ff_audio_data_free(AudioData **a); yading@11: yading@11: /** yading@11: * Copy data from one AudioData to another. yading@11: * yading@11: * @param out output AudioData yading@11: * @param in input AudioData yading@11: * @param map channel map, NULL if not remapping yading@11: * @return 0 on success, negative AVERROR value on error yading@11: */ yading@11: int ff_audio_data_copy(AudioData *out, AudioData *in, ChannelMapInfo *map); yading@11: yading@11: /** yading@11: * Append data from one AudioData to the end of another. yading@11: * yading@11: * @param dst destination AudioData yading@11: * @param dst_offset offset, in samples, to start writing, relative to the yading@11: * start of dst yading@11: * @param src source AudioData yading@11: * @param src_offset offset, in samples, to start copying, relative to the yading@11: * start of the src yading@11: * @param nb_samples number of samples to copy yading@11: * @return 0 on success, negative AVERROR value on error yading@11: */ yading@11: int ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src, yading@11: int src_offset, int nb_samples); yading@11: yading@11: /** yading@11: * Drain samples from the start of the AudioData. yading@11: * yading@11: * Remaining samples are shifted to the start of the AudioData. yading@11: * yading@11: * @param a AudioData struct yading@11: * @param nb_samples number of samples to drain yading@11: */ yading@11: void ff_audio_data_drain(AudioData *a, int nb_samples); yading@11: yading@11: /** yading@11: * Add samples in AudioData to an AVAudioFifo. yading@11: * yading@11: * @param af Audio FIFO Buffer yading@11: * @param a AudioData struct yading@11: * @param offset number of samples to skip from the start of the data yading@11: * @param nb_samples number of samples to add to the FIFO yading@11: * @return number of samples actually added to the FIFO, or yading@11: * negative AVERROR code on error yading@11: */ yading@11: int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset, yading@11: int nb_samples); yading@11: yading@11: /** yading@11: * Read samples from an AVAudioFifo to AudioData. yading@11: * yading@11: * @param af Audio FIFO Buffer yading@11: * @param a AudioData struct yading@11: * @param nb_samples number of samples to read from the FIFO yading@11: * @return number of samples actually read from the FIFO, or yading@11: * negative AVERROR code on error yading@11: */ yading@11: int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples); yading@11: yading@11: #endif /* AVRESAMPLE_AUDIO_DATA_H */