int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char* blacklist, URLContext *parent) { AVDictionary *tmp_opts = NULL; AVDictionaryEntry *e; int ret = ffurl_alloc(puc, filename, flags, int_cb); if (ret < 0) return ret; if (parent) av_opt_copy(*puc, parent); if (options && (ret = av_opt_set_dict(*puc, options)) < 0) goto fail; if (options && (*puc)->prot->priv_data_class && (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0) goto fail; if (!options) options = &tmp_opts; av_assert0(!whitelist || !(e=av_dict_get(*options, "protocol_whitelist", NULL, 0)) || !strcmp(whitelist, e->value)); av_assert0(!blacklist || !(e=av_dict_get(*options, "protocol_blacklist", NULL, 0)) || !strcmp(blacklist, e->value)); if ((ret = av_dict_set(options, "protocol_whitelist", whitelist, 0)) < 0) goto fail; if ((ret = av_dict_set(options, "protocol_blacklist", blacklist, 0)) < 0) goto fail; if ((ret = av_opt_set_dict(*puc, options)) < 0) goto fail; ret = ffurl_connect(*puc, options); if (!ret) return 0; fail: ffurl_close(*puc); *puc = NULL; return ret; }
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { const AVCodec *orig_codec = dest->codec; uint8_t *orig_priv_data = dest->priv_data; if (avcodec_is_open(dest)) { // check that the dest context is uninitialized av_log(dest, AV_LOG_ERROR, "Tried to copy AVCodecContext %p into already-initialized %p\n", src, dest); return AVERROR(EINVAL); } av_opt_free(dest); av_freep(&dest->rc_override); av_freep(&dest->intra_matrix); av_freep(&dest->inter_matrix); av_freep(&dest->extradata); av_freep(&dest->subtitle_header); memcpy(dest, src, sizeof(*dest)); av_opt_copy(dest, src); dest->priv_data = orig_priv_data; dest->codec = orig_codec; if (orig_priv_data && src->codec && src->codec->priv_class && dest->codec && dest->codec->priv_class) av_opt_copy(orig_priv_data, src->priv_data); /* set values specific to opened codecs back to their default state */ dest->slice_offset = NULL; dest->hwaccel = NULL; dest->internal = NULL; #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS dest->coded_frame = NULL; FF_ENABLE_DEPRECATION_WARNINGS #endif /* reallocate values that should be allocated separately */ dest->extradata = NULL; dest->intra_matrix = NULL; dest->inter_matrix = NULL; dest->rc_override = NULL; dest->subtitle_header = NULL; dest->hw_frames_ctx = NULL; #define alloc_and_copy_or_fail(obj, size, pad) \ if (src->obj && size > 0) { \ dest->obj = av_malloc(size + pad); \ if (!dest->obj) \ goto fail; \ memcpy(dest->obj, src->obj, size); \ if (pad) \ memset(((uint8_t *) dest->obj) + size, 0, pad); \ } alloc_and_copy_or_fail(extradata, src->extradata_size, AV_INPUT_BUFFER_PADDING_SIZE); dest->extradata_size = src->extradata_size; alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0); alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0); alloc_and_copy_or_fail(rc_override, src->rc_override_count * sizeof(*src->rc_override), 0); alloc_and_copy_or_fail(subtitle_header, src->subtitle_header_size, 1); av_assert0(dest->subtitle_header_size == src->subtitle_header_size); #undef alloc_and_copy_or_fail if (src->hw_frames_ctx) { dest->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx); if (!dest->hw_frames_ctx) goto fail; } return 0; fail: av_freep(&dest->subtitle_header); av_freep(&dest->rc_override); av_freep(&dest->intra_matrix); av_freep(&dest->inter_matrix); av_freep(&dest->extradata); av_buffer_unref(&dest->hw_frames_ctx); dest->subtitle_header_size = 0; dest->extradata_size = 0; av_opt_free(dest); return AVERROR(ENOMEM); }
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { const AVCodec *orig_codec = dest->codec; uint8_t *orig_priv_data = dest->priv_data; if (avcodec_is_open(dest)) { // check that the dest context is uninitialized av_log(dest, AV_LOG_ERROR, "Tried to copy AVCodecContext %p into already-initialized %p\n", src, dest); return AVERROR(EINVAL); } av_opt_free(dest); memcpy(dest, src, sizeof(*dest)); dest->priv_data = orig_priv_data; if (orig_priv_data) av_opt_copy(orig_priv_data, src->priv_data); dest->codec = orig_codec; /* set values specific to opened codecs back to their default state */ dest->slice_offset = NULL; dest->hwaccel = NULL; dest->internal = NULL; /* reallocate values that should be allocated separately */ dest->rc_eq = NULL; dest->extradata = NULL; dest->intra_matrix = NULL; dest->inter_matrix = NULL; dest->rc_override = NULL; dest->subtitle_header = NULL; if (src->rc_eq) { dest->rc_eq = av_strdup(src->rc_eq); if (!dest->rc_eq) return AVERROR(ENOMEM); } #define alloc_and_copy_or_fail(obj, size, pad) \ if (src->obj && size > 0) { \ dest->obj = av_malloc(size + pad); \ if (!dest->obj) \ goto fail; \ memcpy(dest->obj, src->obj, size); \ if (pad) \ memset(((uint8_t *) dest->obj) + size, 0, pad); \ } alloc_and_copy_or_fail(extradata, src->extradata_size, FF_INPUT_BUFFER_PADDING_SIZE); alloc_and_copy_or_fail(intra_matrix, 64 * sizeof(int16_t), 0); alloc_and_copy_or_fail(inter_matrix, 64 * sizeof(int16_t), 0); alloc_and_copy_or_fail(rc_override, src->rc_override_count * sizeof(*src->rc_override), 0); alloc_and_copy_or_fail(subtitle_header, src->subtitle_header_size, 1); av_assert0(dest->subtitle_header_size == src->subtitle_header_size); #undef alloc_and_copy_or_fail return 0; fail: av_freep(&dest->rc_override); av_freep(&dest->intra_matrix); av_freep(&dest->inter_matrix); av_freep(&dest->extradata); av_freep(&dest->rc_eq); return AVERROR(ENOMEM); }