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