1 /*
2 * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
3 *
4 * This file is part of Libav.
5 *
6 * Libav 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.
10 *
11 * Libav 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.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with Libav; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <stdint.h>
22 #include <string.h>
23
26
31 };
32
33 /*
34 * Calculate alignment for data pointers.
35 */
37 {
38 int p;
39 int min_align = 128;
40
41 for (p = 0; p < a->
planes; p++) {
42 int cur_align = 128;
43 while ((intptr_t)a->
data[p] % cur_align)
44 cur_align >>= 1;
45 if (cur_align < min_align)
46 min_align = cur_align;
47 }
49 }
50
52 {
56
59
61
62 return 0;
63 }
64
67 int read_only,
const char *
name)
68 {
69 int p;
70
71 memset(a, 0, sizeof(*a));
73
77 }
78
83 }
87
88 for (p = 0; p < (a->
is_planar ? channels : 1); p++) {
89 if (!src[p]) {
92 }
94 }
102 a->
name = name ? name :
"{no name}";
103
106
107 return 0;
108 }
109
112 {
115
117 return NULL;
118
120 if (!a)
121 return NULL;
122
126 return NULL;
127 }
131
138 a->
name = name ? name :
"{no name}";
139
140 if (nb_samples > 0) {
142 if (ret < 0) {
144 return NULL;
145 }
147 } else {
150 }
151 }
152
154 {
155 int ret, new_buf_size, plane_size, p;
156
157 /* check if buffer is already large enough */
159 return 0;
160
161 /* validate that the output is not read-only and realloc is allowed */
164
168 if (new_buf_size < 0)
169 return new_buf_size;
170
171 /* if there is already data in the buffer and the sample format is planar,
172 allocate a new buffer and copy the data, otherwise just realloc the
173 internal buffer and set new data pointers */
176
179 if (ret < 0)
181
182 for (p = 0; p < a->
planes; p++)
184
186 memcpy(a->
data, new_data,
sizeof(new_data));
188 } else {
196 if (ret < 0)
198 }
201
204
205 return 0;
206 }
207
209 {
210 if (!*a)
211 return;
214 }
215
217 {
219
220 /* validate input/output compatibility */
223
227 }
228
229 /* if the input is empty, just empty the output */
232 return 0;
233 }
234
235 /* reallocate output if necessary */
237 if (ret < 0)
239
240 /* copy data */
241 if (map) {
243 for (p = 0; p < src->
planes; p++) {
247 }
248 }
250 for (p = 0; p < src->
planes; p++) {
257 }
258 }
259 } else {
260 for (p = 0; p < src->
planes; p++)
262 }
263
265
266 return 0;
267 }
268
270 int src_offset, int nb_samples)
271 {
272 int ret, p, dst_offset2, dst_move_size;
273
274 /* validate input/output compatibility */
278 }
279
280 /* validate offsets are within the buffer bounds */
281 if (dst_offset < 0 || dst_offset > dst->
nb_samples ||
282 src_offset < 0 || src_offset > src->
nb_samples) {
284 src_offset, dst_offset);
286 }
287
288 /* check offsets and sizes to see if we can just do nothing and return */
289 if (nb_samples > src->
nb_samples - src_offset)
291 if (nb_samples <= 0)
292 return 0;
293
294 /* validate that the output is not read-only */
298 }
299
300 /* reallocate output if necessary */
302 if (ret < 0) {
305 }
306
307 dst_offset2 = dst_offset + nb_samples;
309
310 for (p = 0; p < src->
planes; p++) {
311 if (dst_move_size > 0) {
312 memmove(dst->
data[p] + dst_offset2 * dst->
stride,
314 dst_move_size * dst->
stride);
315 }
316 memcpy(dst->
data[p] + dst_offset * dst->
stride,
318 nb_samples * src->
stride);
319 }
321
322 return 0;
323 }
324
326 {
328 /* drain the whole buffer */
330 } else {
331 int p;
332 int move_offset = a->
stride * nb_samples;
334
335 for (p = 0; p < a->
planes; p++)
336 memmove(a->
data[p], a->
data[p] + move_offset, move_size);
337
339 }
340 }
341
343 int nb_samples)
344 {
346 int offset_size, p;
347
349 return 0;
350 offset_size = offset * a->
stride;
351 for (p = 0; p < a->
planes; p++)
352 offset_data[p] = a->
data[p] + offset_size;
353
355 }
356
358 {
360
363
365 if (ret < 0)
367
369 if (ret >= 0)
372 }