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 {
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
101 return buf;
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 align = 1;
139 nb_samples =
FFALIGN(nb_samples, 32);
140 }
141
142 /* check for integer overflow */
143 if (nb_channels > INT_MAX / align ||
144 (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size)
146
147 line_size = planar ?
FFALIGN(nb_samples * sample_size, align) :
148 FFALIGN(nb_samples * sample_size * nb_channels, align);
149 if (linesize)
150 *linesize = line_size;
151
152 return planar ? line_size * nb_channels : line_size;
153 }
154
158 {
159 int ch, planar, buf_size, line_size;
160
163 sample_fmt, align);
164 if (buf_size < 0)
165 return buf_size;
166
167 audio_data[0] = (
uint8_t *)buf;
169 audio_data[ch] = audio_data[ch-1] + line_size;
170
171 if (linesize)
172 *linesize = line_size;
173
174 #if FF_API_SAMPLES_UTILS_RETURN_ZERO
175 return 0;
176 #else
177 return buf_size;
178 #endif
179 }
180
183 {
186 sample_fmt, align);
187 if (size < 0)
189
191 if (!buf)
193
195 nb_samples, sample_fmt, align);
196 if (size < 0) {
199 }
200
202
203 #if FF_API_SAMPLES_UTILS_RETURN_ZERO
204 return 0;
205 #else
207 #endif
208 }
209
213 {
215 int planes = planar ? nb_channels : 1;
217 int data_size = nb_samples * block_align;
218 int i;
219
220 dst_offset *= block_align;
221 src_offset *= block_align;
222
223 if((dst[0] < src[0] ? src[0] - dst[0] : dst[0] - src[0]) >= data_size) {
224 for (i = 0; i < planes; i++)
225 memcpy(dst[i] + dst_offset, src[i] + src_offset, data_size);
226 } else {
227 for (i = 0; i < planes; i++)
228 memmove(dst[i] + dst_offset, src[i] + src_offset, data_size);
229 }
230
231 return 0;
232 }
233
236 {
238 int planes = planar ? nb_channels : 1;
240 int data_size = nb_samples * block_align;
243 int i;
244
245 offset *= block_align;
246
247 for (i = 0; i < planes; i++)
248 memset(audio_data[i] + offset, fill_char, data_size);
249
250 return 0;
251 }