static av_cold void uninit(AVFilterContext *ctx) { VolumeContext *vol = ctx->priv; av_expr_free(vol->volume_pexpr); av_opt_free(vol); av_freep(&vol->fdsp); }
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) { 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_free(dest->priv_data); memcpy(dest, src, sizeof(*dest)); /* set values specific to opened codecs back to their default state */ dest->priv_data = NULL; dest->codec = NULL; 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; 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); #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); }
void avfilter_free(AVFilterContext *filter) { int i; if (filter->graph) ff_filter_graph_remove_filter(filter->graph, filter); if (filter->filter->uninit) filter->filter->uninit(filter); for (i = 0; i < filter->nb_inputs; i++) { free_link(filter->inputs[i]); } for (i = 0; i < filter->nb_outputs; i++) { free_link(filter->outputs[i]); } if (filter->filter->priv_class) av_opt_free(filter->priv); av_buffer_unref(&filter->hw_device_ctx); av_freep(&filter->name); av_freep(&filter->input_pads); av_freep(&filter->output_pads); av_freep(&filter->inputs); av_freep(&filter->outputs); av_freep(&filter->priv); av_freep(&filter->internal); av_free(filter); }
void avresample_free(AVAudioResampleContext **avr) { if (!*avr) return; avresample_close(*avr); av_opt_free(*avr); av_freep(avr); }
static av_cold void uninit(AVFilterContext *ctx) { InterlaceContext *s = ctx->priv; av_frame_free(&s->cur); av_frame_free(&s->next); av_opt_free(s); }
void bv_device_free_context(BVDeviceContext ** devctx) { if (!**devctx) return; BVDeviceContext *s = *devctx; if (!s) return; av_opt_free(s); if (s->device && s->device->priv_class && s->priv_data) av_opt_free(s->priv_data); av_freep(&s->priv_data); av_free(s); devctx = NULL; return; }
void avfilter_free(AVFilterContext *filter) { int i; if (!filter) return; if (filter->graph) ff_filter_graph_remove_filter(filter->graph, filter); if (filter->filter->uninit) filter->filter->uninit(filter); for (i = 0; i < filter->nb_inputs; i++) { free_link(filter->inputs[i]); } for (i = 0; i < filter->nb_outputs; i++) { free_link(filter->outputs[i]); } if (filter->filter->priv_class) av_opt_free(filter->priv); av_buffer_unref(&filter->hw_device_ctx); av_freep(&filter->name); av_freep(&filter->input_pads); av_freep(&filter->output_pads); av_freep(&filter->inputs); av_freep(&filter->outputs); av_freep(&filter->priv); while(filter->command_queue){ ff_command_queue_pop(filter); } av_opt_free(filter); av_expr_free(filter->enable); filter->enable = NULL; av_freep(&filter->var_values); av_freep(&filter->internal); av_free(filter); }
int ffurl_closep(URLContext **hh) { URLContext *h= *hh; int ret = 0; if (!h) return 0; /* can happen when ffurl_open fails */ if (h->is_connected && h->prot->url_close) ret = h->prot->url_close(h); #if CONFIG_NETWORK if (h->prot->flags & URL_PROTOCOL_FLAG_NETWORK) ff_network_close(); #endif if (h->prot->priv_data_size) { if (h->prot->priv_data_class) av_opt_free(h->priv_data); av_freep(&h->priv_data); } av_opt_free(h); av_freep(hh); return ret; }
static void app_free(App *app) { if (!app) return; ffva_renderer_freep(&app->renderer); va_destroy_surface(app->va_display, &app->filter_surface.id); ffva_filter_freep(&app->filter); ffva_decoder_freep(&app->decoder); ffva_display_freep(&app->display); av_opt_free(app); free(app); }
void av_bsf_free(AVBSFContext **pctx) { AVBSFContext *ctx; if (!pctx || !*pctx) return; ctx = *pctx; if (ctx->filter->close) ctx->filter->close(ctx); if (ctx->filter->priv_class && ctx->priv_data) av_opt_free(ctx->priv_data); av_opt_free(ctx); av_packet_free(&ctx->internal->buffer_pkt); av_freep(&ctx->internal); av_freep(&ctx->priv_data); avcodec_parameters_free(&ctx->par_in); avcodec_parameters_free(&ctx->par_out); av_freep(pctx); }
int av_write_trailer(AVFormatContext *s) { int ret, i; for (;; ) { AVPacket pkt; ret = interleave_packet(s, &pkt, NULL, 1); if (ret < 0) //FIXME cleanup needed for ret<0 ? goto fail; if (!ret) break; ret = write_packet(s, &pkt); if (ret >= 0) s->streams[pkt.stream_index]->nb_frames++; av_packet_unref(&pkt); if (ret < 0) goto fail; } if (s->oformat->write_trailer) ret = s->oformat->write_trailer(s); if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) avio_flush(s->pb); fail: for (i = 0; i < s->nb_streams; i++) { av_freep(&s->streams[i]->priv_data); av_freep(&s->streams[i]->index_entries); } if (s->oformat->priv_class) av_opt_free(s->priv_data); av_freep(&s->priv_data); return ret; }
static void copy_context_reset(AVCodecContext *avctx) { int i; av_opt_free(avctx); #if FF_API_CODED_FRAME FF_DISABLE_DEPRECATION_WARNINGS av_frame_free(&avctx->coded_frame); FF_ENABLE_DEPRECATION_WARNINGS #endif av_freep(&avctx->rc_override); av_freep(&avctx->intra_matrix); av_freep(&avctx->inter_matrix); av_freep(&avctx->extradata); av_freep(&avctx->subtitle_header); av_buffer_unref(&avctx->hw_frames_ctx); av_buffer_unref(&avctx->hw_device_ctx); for (i = 0; i < avctx->nb_coded_side_data; i++) av_freep(&avctx->coded_side_data[i].data); av_freep(&avctx->coded_side_data); avctx->subtitle_header_size = 0; avctx->nb_coded_side_data = 0; avctx->extradata_size = 0; }
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); }