Commit d79bd604 authored by Anton Khirnov's avatar Anton Khirnov

lavfi: factorize freeing a link

parent 1dd35611
...@@ -428,10 +428,28 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in ...@@ -428,10 +428,28 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in
} }
#endif #endif
static void free_link(AVFilterLink *link)
{
if (!link)
return;
if (link->src)
link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
if (link->dst)
link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
ff_formats_unref(&link->in_formats);
ff_formats_unref(&link->out_formats);
ff_formats_unref(&link->in_samplerates);
ff_formats_unref(&link->out_samplerates);
ff_channel_layouts_unref(&link->in_channel_layouts);
ff_channel_layouts_unref(&link->out_channel_layouts);
av_freep(&link);
}
void avfilter_free(AVFilterContext *filter) void avfilter_free(AVFilterContext *filter)
{ {
int i; int i;
AVFilterLink *link;
if (filter->graph) if (filter->graph)
ff_filter_graph_remove_filter(filter->graph, filter); ff_filter_graph_remove_filter(filter->graph, filter);
...@@ -440,30 +458,10 @@ void avfilter_free(AVFilterContext *filter) ...@@ -440,30 +458,10 @@ void avfilter_free(AVFilterContext *filter)
filter->filter->uninit(filter); filter->filter->uninit(filter);
for (i = 0; i < filter->nb_inputs; i++) { for (i = 0; i < filter->nb_inputs; i++) {
if ((link = filter->inputs[i])) { free_link(filter->inputs[i]);
if (link->src)
link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
ff_formats_unref(&link->in_formats);
ff_formats_unref(&link->out_formats);
ff_formats_unref(&link->in_samplerates);
ff_formats_unref(&link->out_samplerates);
ff_channel_layouts_unref(&link->in_channel_layouts);
ff_channel_layouts_unref(&link->out_channel_layouts);
}
av_freep(&link);
} }
for (i = 0; i < filter->nb_outputs; i++) { for (i = 0; i < filter->nb_outputs; i++) {
if ((link = filter->outputs[i])) { free_link(filter->outputs[i]);
if (link->dst)
link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
ff_formats_unref(&link->in_formats);
ff_formats_unref(&link->out_formats);
ff_formats_unref(&link->in_samplerates);
ff_formats_unref(&link->out_samplerates);
ff_channel_layouts_unref(&link->in_channel_layouts);
ff_channel_layouts_unref(&link->out_channel_layouts);
}
av_freep(&link);
} }
if (filter->filter->priv_class) if (filter->filter->priv_class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment