MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / avcodec_copy_context

Function avcodec_copy_context

libavcodec/options.c:474–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472}
473
474int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
475{
476 if (dest->codec) { // check that the dest context is uninitialized
477 av_log(dest, AV_LOG_ERROR,
478 "Tried to copy AVCodecContext %p into already-initialized %p\n",
479 src, dest);
480 return AVERROR(EINVAL);
481 }
482 memcpy(dest, src, sizeof(*dest));
483
484 /* set values specific to opened codecs back to their default state */
485 dest->priv_data = NULL;
486 dest->codec = NULL;
487 dest->palctrl = NULL;
488 dest->slice_offset = NULL;
489 dest->internal_buffer = NULL;
490 dest->hwaccel = NULL;
491 dest->thread_opaque = NULL;
492
493 /* reallocate values that should be allocated separately */
494 dest->rc_eq = NULL;
495 dest->extradata = NULL;
496 dest->intra_matrix = NULL;
497 dest->inter_matrix = NULL;
498 dest->rc_override = NULL;
499 if (src->rc_eq) {
500 dest->rc_eq = av_strdup(src->rc_eq);
501 if (!dest->rc_eq)
502 return AVERROR(ENOMEM);
503 }
504
505#define alloc_and_copy_or_fail(obj, size, pad) \
506 if (src->obj && size > 0) { \
507 dest->obj = av_malloc(size + pad); \
508 if (!dest->obj) \
509 goto fail; \
510 memcpy(dest->obj, src->obj, size); \
511 if (pad) \
512 memset(((uint8_t *) dest->obj) + size, 0, pad); \
513 }
514 alloc_and_copy_or_fail(extradata, src->extradata_size,
515 FF_INPUT_BUFFER_PADDING_SIZE);
516 alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0);
517 alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0);
518 alloc_and_copy_or_fail(rc_override, src->rc_override_count * sizeof(*src->rc_override), 0);
519#undef alloc_and_copy_or_fail
520
521 return 0;
522
523fail:
524 av_freep(&dest->rc_override);
525 av_freep(&dest->intra_matrix);
526 av_freep(&dest->inter_matrix);
527 av_freep(&dest->extradata);
528 av_freep(&dest->rc_eq);
529 return AVERROR(ENOMEM);
530}

Callers 1

read_ffserver_streamsFunction · 0.85

Calls 3

av_logFunction · 0.85
av_strdupFunction · 0.85
av_freepFunction · 0.85

Tested by

no test coverage detected