1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
32
33 /** this table gives more information about formats */
45 };
46
48 {
50 return NULL;
51 return sample_fmt_info[sample_fmt].
name;
52 }
53
55 {
56 int i;
57
59 if (!strcmp(sample_fmt_info[i].name, name))
60 return i;
62 }
63
65 {
68 if (sample_fmt_info[sample_fmt].planar == planar)
69 return sample_fmt;
70 return sample_fmt_info[sample_fmt].
altform;
71 }
72
74 {
77 if (sample_fmt_info[sample_fmt].planar)
78 return sample_fmt_info[sample_fmt].
altform;
79 return sample_fmt;
80 }
81
83 {
86 if (sample_fmt_info[sample_fmt].planar)
87 return sample_fmt;
88 return sample_fmt_info[sample_fmt].
altform;
89 }
90
92 {
93 /* print header */
94 if (sample_fmt < 0)
95 snprintf(buf, buf_size,
"name " " depth");
99 }
100
102 }
103
105 {
107 0 : sample_fmt_info[sample_fmt].
bits >> 3;
108 }
109
110 #if FF_API_GET_BITS_PER_SAMPLE_FMT
112 {
114 0 : sample_fmt_info[sample_fmt].
bits;
115 }
116 #endif
117
119 {
121 return 0;
122 return sample_fmt_info[sample_fmt].
planar;
123 }
124
127 {
128 int line_size;
131
132 /* validate parameter ranges */
133 if (!sample_size || nb_samples <= 0 || nb_channels <= 0)
135
136 /* auto-select alignment if not specified */
137 if (!align) {
138 if (nb_samples > INT_MAX - 31)
140 align = 1;
141 nb_samples =
FFALIGN(nb_samples, 32);
142 }
143
144 /* check for integer overflow */
145 if (nb_channels > INT_MAX / align ||
146 (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)
148
149 line_size = planar ?
FFALIGN(nb_samples * sample_size, align) :
150 FFALIGN(nb_samples * sample_size * nb_channels, align);
151 if (linesize)
152 *linesize = line_size;
153
154 return planar ? line_size * nb_channels : line_size;
155 }
156
160 {
161 int ch, planar, buf_size, line_size;
162
165 sample_fmt, align);
166 if (buf_size < 0)
167 return buf_size;
168
169 audio_data[0] = (
uint8_t *)buf;
171 audio_data[ch] = audio_data[ch-1] + line_size;
172
173 if (linesize)
174 *linesize = line_size;
175
176 #if FF_API_SAMPLES_UTILS_RETURN_ZERO
177 return 0;
178 #else
179 return buf_size;
180 #endif
181 }
182
185 {
188 sample_fmt, align);
189 if (size < 0)
191
193 if (!buf)
195
197 nb_samples, sample_fmt, align);
198 if (size < 0) {
201 }
202
204
205 #if FF_API_SAMPLES_UTILS_RETURN_ZERO
206 return 0;
207 #else
209 #endif
210 }
211
214 {
216
217 *audio_data =
av_calloc(nb_planes,
sizeof(**audio_data));
218 if (!*audio_data)
221 nb_samples, sample_fmt, align);
222 if (ret < 0)
225 }
226
230 {
232 int planes = planar ? nb_channels : 1;
234 int data_size = nb_samples * block_align;
235 int i;
236
237 dst_offset *= block_align;
238 src_offset *= block_align;
239
240 if((dst[0] < src[0] ? src[0] - dst[0] : dst[0] - src[0]) >=
data_size) {
241 for (i = 0; i < planes; i++)
242 memcpy(dst[i] + dst_offset, src[i] + src_offset, data_size);
243 } else {
244 for (i = 0; i < planes; i++)
245 memmove(dst[i] + dst_offset, src[i] + src_offset, data_size);
246 }
247
248 return 0;
249 }
250
253 {
255 int planes = planar ? nb_channels : 1;
257 int data_size = nb_samples * block_align;
260 int i;
261
262 offset *= block_align;
263
264 for (i = 0; i < planes; i++)
265 memset(audio_data[i] + offset, fill_char, data_size);
266
267 return 0;
268 }