summaryrefslogtreecommitdiff
path: root/fftools
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-04-18 19:41:48 +0200
committerAnton Khirnov <anton@khirnov.net>2023-04-24 16:56:06 +0200
commitcc7a8ddf56468a2d96c284a5737fd85a05811a3e (patch)
tree0078f8e82d2b75b8c3c3d91c43639b662eb36963 /fftools
parenteb9ce9de3ba4422d781c79fb53c9f86cfddcc58b (diff)
downloadffmpeg-cc7a8ddf56468a2d96c284a5737fd85a05811a3e.tar.gz
fftools/ffmpeg: move freeing a filtergraph into a separate function
Diffstat (limited to 'fftools')
-rw-r--r--fftools/ffmpeg.c42
-rw-r--r--fftools/ffmpeg.h2
-rw-r--r--fftools/ffmpeg_filter.c44
3 files changed, 49 insertions, 39 deletions
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 5bcb76ac55..15fe839914 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -487,51 +487,15 @@ const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
static void ffmpeg_cleanup(int ret)
{
- int i, j;
+ int i;
if (do_benchmark) {
int maxrss = getmaxrss() / 1024;
av_log(NULL, AV_LOG_INFO, "bench: maxrss=%ikB\n", maxrss);
}
- for (i = 0; i < nb_filtergraphs; i++) {
- FilterGraph *fg = filtergraphs[i];
- avfilter_graph_free(&fg->graph);
- for (j = 0; j < fg->nb_inputs; j++) {
- InputFilter *ifilter = fg->inputs[j];
- struct InputStream *ist = ifilter->ist;
-
- if (ifilter->frame_queue) {
- AVFrame *frame;
- while (av_fifo_read(ifilter->frame_queue, &frame, 1) >= 0)
- av_frame_free(&frame);
- av_fifo_freep2(&ifilter->frame_queue);
- }
- av_freep(&ifilter->displaymatrix);
- if (ist->sub2video.sub_queue) {
- AVSubtitle sub;
- while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0)
- avsubtitle_free(&sub);
- av_fifo_freep2(&ist->sub2video.sub_queue);
- }
- av_buffer_unref(&ifilter->hw_frames_ctx);
- av_freep(&ifilter->name);
- av_freep(&fg->inputs[j]);
- }
- av_freep(&fg->inputs);
- for (j = 0; j < fg->nb_outputs; j++) {
- OutputFilter *ofilter = fg->outputs[j];
-
- avfilter_inout_free(&ofilter->out_tmp);
- av_freep(&ofilter->name);
- av_channel_layout_uninit(&ofilter->ch_layout);
- av_freep(&fg->outputs[j]);
- }
- av_freep(&fg->outputs);
- av_freep(&fg->graph_desc);
-
- av_freep(&filtergraphs[i]);
- }
+ for (i = 0; i < nb_filtergraphs; i++)
+ fg_free(&filtergraphs[i]);
av_freep(&filtergraphs);
/* close files */
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 07c1fc7ed6..95591f4bba 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -814,6 +814,8 @@ int ifilter_has_all_input_formats(FilterGraph *fg);
*/
FilterGraph *fg_create(char *graph_desc);
+void fg_free(FilterGraph **pfg);
+
/**
* Perform a step of transcoding for the specified filter graph.
*
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index c39cf43774..cfd93a0f9d 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -189,6 +189,50 @@ static OutputFilter *ofilter_alloc(FilterGraph *fg)
return ofilter;
}
+void fg_free(FilterGraph **pfg)
+{
+ FilterGraph *fg = *pfg;
+
+ if (!fg)
+ return;
+
+ avfilter_graph_free(&fg->graph);
+ for (int j = 0; j < fg->nb_inputs; j++) {
+ InputFilter *ifilter = fg->inputs[j];
+ struct InputStream *ist = ifilter->ist;
+
+ if (ifilter->frame_queue) {
+ AVFrame *frame;
+ while (av_fifo_read(ifilter->frame_queue, &frame, 1) >= 0)
+ av_frame_free(&frame);
+ av_fifo_freep2(&ifilter->frame_queue);
+ }
+ av_freep(&ifilter->displaymatrix);
+ if (ist->sub2video.sub_queue) {
+ AVSubtitle sub;
+ while (av_fifo_read(ist->sub2video.sub_queue, &sub, 1) >= 0)
+ avsubtitle_free(&sub);
+ av_fifo_freep2(&ist->sub2video.sub_queue);
+ }
+ av_buffer_unref(&ifilter->hw_frames_ctx);
+ av_freep(&ifilter->name);
+ av_freep(&fg->inputs[j]);
+ }
+ av_freep(&fg->inputs);
+ for (int j = 0; j < fg->nb_outputs; j++) {
+ OutputFilter *ofilter = fg->outputs[j];
+
+ avfilter_inout_free(&ofilter->out_tmp);
+ av_freep(&ofilter->name);
+ av_channel_layout_uninit(&ofilter->ch_layout);
+ av_freep(&fg->outputs[j]);
+ }
+ av_freep(&fg->outputs);
+ av_freep(&fg->graph_desc);
+
+ av_freep(pfg);
+}
+
FilterGraph *fg_create(char *graph_desc)
{
FilterGraph *fg;