2 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef AVRESAMPLE_AUDIO_DATA_H
22 #define AVRESAMPLE_AUDIO_DATA_H
26 #include "libavutil/audio_fifo.h"
27 #include "libavutil/log.h"
28 #include "libavutil/samplefmt.h"
29 #include "avresample.h"
32 int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int channels);
35 * Audio buffer used for intermediate storage between conversion phases.
38 const AVClass *class; /**< AVClass for logging */
39 uint8_t *data[AVRESAMPLE_MAX_CHANNELS]; /**< data plane pointers */
40 uint8_t *buffer; /**< data buffer */
41 unsigned int buffer_size; /**< allocated buffer size */
42 int allocated_samples; /**< number of samples the buffer can hold */
43 int nb_samples; /**< current number of samples */
44 enum AVSampleFormat sample_fmt; /**< sample format */
45 int channels; /**< channel count */
46 int allocated_channels; /**< allocated channel count */
47 int is_planar; /**< sample format is planar */
48 int planes; /**< number of data planes */
49 int sample_size; /**< bytes per sample */
50 int stride; /**< sample byte offset within a plane */
51 int read_only; /**< data is read-only */
52 int allow_realloc; /**< realloc is allowed */
53 int ptr_align; /**< minimum data pointer alignment */
54 int samples_align; /**< allocated samples alignment */
55 const char *name; /**< name for debug logging */
58 int ff_audio_data_set_channels(AudioData *a, int channels);
61 * Initialize AudioData using a given source.
63 * This does not allocate an internal buffer. It only sets the data pointers
64 * and audio parameters.
66 * @param a AudioData struct
67 * @param src source data pointers
68 * @param plane_size plane size, in bytes.
69 * This can be 0 if unknown, but that will lead to
70 * optimized functions not being used in many cases,
71 * which could slow down some conversions.
72 * @param channels channel count
73 * @param nb_samples number of samples in the source data
74 * @param sample_fmt sample format
75 * @param read_only indicates if buffer is read only or read/write
76 * @param name name for debug logging (can be NULL)
77 * @return 0 on success, negative AVERROR value on error
79 int ff_audio_data_init(AudioData *a, uint8_t * const *src, int plane_size,
80 int channels, int nb_samples,
81 enum AVSampleFormat sample_fmt, int read_only,
87 * This allocates an internal buffer and sets audio parameters.
89 * @param channels channel count
90 * @param nb_samples number of samples to allocate space for
91 * @param sample_fmt sample format
92 * @param name name for debug logging (can be NULL)
93 * @return newly allocated AudioData struct, or NULL on error
95 AudioData *ff_audio_data_alloc(int channels, int nb_samples,
96 enum AVSampleFormat sample_fmt,
100 * Reallocate AudioData.
102 * The AudioData must have been previously allocated with ff_audio_data_alloc().
104 * @param a AudioData struct
105 * @param nb_samples number of samples to allocate space for
106 * @return 0 on success, negative AVERROR value on error
108 int ff_audio_data_realloc(AudioData *a, int nb_samples);
113 * The AudioData must have been previously allocated with ff_audio_data_alloc().
115 * @param a AudioData struct
117 void ff_audio_data_free(AudioData **a);
120 * Copy data from one AudioData to another.
122 * @param out output AudioData
123 * @param in input AudioData
124 * @param map channel map, NULL if not remapping
125 * @return 0 on success, negative AVERROR value on error
127 int ff_audio_data_copy(AudioData *out, AudioData *in, ChannelMapInfo *map);
130 * Append data from one AudioData to the end of another.
132 * @param dst destination AudioData
133 * @param dst_offset offset, in samples, to start writing, relative to the
135 * @param src source AudioData
136 * @param src_offset offset, in samples, to start copying, relative to the
138 * @param nb_samples number of samples to copy
139 * @return 0 on success, negative AVERROR value on error
141 int ff_audio_data_combine(AudioData *dst, int dst_offset, AudioData *src,
142 int src_offset, int nb_samples);
145 * Drain samples from the start of the AudioData.
147 * Remaining samples are shifted to the start of the AudioData.
149 * @param a AudioData struct
150 * @param nb_samples number of samples to drain
152 void ff_audio_data_drain(AudioData *a, int nb_samples);
155 * Add samples in AudioData to an AVAudioFifo.
157 * @param af Audio FIFO Buffer
158 * @param a AudioData struct
159 * @param offset number of samples to skip from the start of the data
160 * @param nb_samples number of samples to add to the FIFO
161 * @return number of samples actually added to the FIFO, or
162 * negative AVERROR code on error
164 int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset,
168 * Read samples from an AVAudioFifo to AudioData.
170 * @param af Audio FIFO Buffer
171 * @param a AudioData struct
172 * @param nb_samples number of samples to read from the FIFO
173 * @return number of samples actually read from the FIFO, or
174 * negative AVERROR code on error
176 int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples);
178 #endif /* AVRESAMPLE_AUDIO_DATA_H */