1 /*
2 * Copyright (c) 2001 Fabrice Bellard
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Options definition for AVCodecContext.
25 */
26
33 #include <float.h> /* FLT_MIN, FLT_MAX */
34 #include <string.h>
35
37
40
43 else
44 return "NULL";
45 }
46
48 {
53 }
54
56 {
58
59 /* find the codec that corresponds to prev */
62 break;
63
64 /* find next codec with priv options */
69 }
70
72 {
76 }
77
83 .log_level_offset_offset = offsetof(
AVCodecContext, log_level_offset),
88 };
89
91 {
94
96
98 if (codec) {
101 }
102
110
121
128 }
129 }
133 }
134 }
141 d++;
142 }
143 }
144 return 0;
145 }
146
148 {
150
151 if (!avctx)
153
157 }
158
159 return avctx;
160 }
161
163 {
165
166 if (!avctx)
167 return;
168
170
176
178 }
179
181 {
184
185 if (
avcodec_is_open(dest)) {
// check that the dest context is uninitialized
187 "Tried to copy AVCodecContext %p into already-initialized %p\n",
188 src, dest);
190 }
191
198
199 memcpy(dest, src, sizeof(*dest));
201
203 dest->
codec = orig_codec;
204
208
209
210 /* set values specific to opened codecs back to their default state */
215
216 /* reallocate values that should be allocated separately */
222
223 #define alloc_and_copy_or_fail(obj, size, pad) \
224 if (src->obj && size > 0) { \
225 dest->obj = av_malloc(size + pad); \
226 if (!dest->obj) \
227 goto fail; \
228 memcpy(dest->obj, src->obj, size); \
229 if (pad) \
230 memset(((uint8_t *) dest->obj) + size, 0, pad); \
231 }
240 #undef alloc_and_copy_or_fail
241
242 return 0;
243
244 fail:
254 }
255
257 {
259 }
260
261 #define FOFFSET(x) offsetof(AVFrame,x)
262
274 };
275
281 };
282
284 {
286 }
287
288 #define SROFFSET(x) offsetof(AVSubtitleRect,x)
289
299 };
300
306 };
307
309 {
311 }
312
313 #ifdef TEST
315 {
316 //TODO: this code should set every possible pointer that could be set by codec and is not an option;
320 return 0;
321 }
322
324 {
328 return 0;
329 }
330
332 {
334 }
335
336 typedef struct Dummy12Context {
338 int num;
339 char* str;
340 } Dummy12Context;
341
342 typedef struct Dummy3Context {
343 void *fake_av_class;
344 int num;
345 char* str;
346 } Dummy3Context;
347
348 #define OFFSET(x) offsetof(Dummy12Context, x)
349 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
350 static const AVOption dummy_options[] = {
354 };
355
356 static const AVClass dummy_v1_class = {
359 .option = dummy_options,
361 };
362
363 static const AVClass dummy_v2_class = {
366 .option = dummy_options,
368 };
369
370 /* codec with options */
372 .
name =
"dummy_v1_codec",
375 .encode2 = dummy_encode,
376 .init = dummy_init,
377 .close = dummy_close,
378 .priv_class = &dummy_v1_class,
379 .priv_data_size = sizeof(Dummy12Context),
380 };
381
382 /* codec with options, different class */
384 .
name =
"dummy_v2_codec",
387 .encode2 = dummy_encode,
388 .init = dummy_init,
389 .close = dummy_close,
390 .priv_class = &dummy_v2_class,
391 .priv_data_size = sizeof(Dummy12Context),
392 };
393
394 /* codec with priv data, but no class */
396 .
name =
"dummy_v3_codec",
399 .encode2 = dummy_encode,
400 .init = dummy_init,
401 .close = dummy_close,
402 .priv_data_size = sizeof(Dummy3Context),
403 };
404
405 /* codec without priv data */
407 .
name =
"dummy_v4_codec",
410 .encode2 = dummy_encode,
411 .init = dummy_init,
412 .close = dummy_close,
413 };
414
416 {
417 printf("%-14s: %dx%d prv: %s",
422 int64_t i64;
426 printf(" opts: %"PRId64" %s", i64, str);
428 }
429 printf("\n");
430 }
431
433 {
435 printf(
"%s -> %s\nclosed:\n", c1 ? c1->
name :
"NULL", c2 ? c2->
name :
"NULL");
442 }
444 test_copy_print_codec(ctx1);
445 test_copy_print_codec(ctx2);
447 printf("opened:\n");
452 }
454 test_copy_print_codec(ctx1);
455 test_copy_print_codec(ctx2);
457 }
460 }
461
463 {
465 &dummy_v1_encoder,
466 &dummy_v2_encoder,
467 &dummy_v3_encoder,
468 &dummy_v4_encoder,
470 };
471 int i, j;
472
473 for (i = 0; dummy_codec[i]; i++)
475
476 printf("testing avcodec_copy_context()\n");
479 test_copy(dummy_codec[i], dummy_codec[j]);
480 return 0;
481 }
482 #endif