[FFmpeg-devel] [PATCH] Factorize code from video_thread() and put it in configure_video_filters().
Stefano Sabatini
stefano.sabatini-lala
Sat Jan 15 13:52:47 CET 2011
---
ffplay.c | 68 +++++++++++++++++++++++++++++++++++++------------------------
1 files changed, 41 insertions(+), 27 deletions(-)
diff --git a/ffplay.c b/ffplay.c
index 58f2942..6026d98 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -213,6 +213,7 @@ typedef struct VideoState {
#if CONFIG_AVFILTER
AVFilterContext *out_video_filter; ///<the last filter in the video chain
AVFilterContext *out_audio_filter; ///<the last filter in the audio chain
+ AVFilterGraph *vgraph;
AVFilterGraph *agraph;
#endif
@@ -1967,31 +1968,24 @@ fail:
#endif /* CONFIG_AVFILTER */
-static int video_thread(void *arg)
+static int configure_video_filters(VideoState *is, const char *vfilters)
{
- VideoState *is = arg;
- AVFrame *frame= avcodec_alloc_frame();
- int64_t pts_int;
- double pts;
- int ret;
-
-#if CONFIG_AVFILTER
- int64_t pos;
char sws_flags_str[128];
+ int ret;
FFSinkContext ffsink_ctx = { .pix_fmt = PIX_FMT_YUV420P };
AVFilterContext *filt_src = NULL, *filt_out = NULL;
- AVFilterGraph *graph = avfilter_graph_alloc();
+ is->vgraph = avfilter_graph_alloc();
snprintf(sws_flags_str, sizeof(sws_flags_str), "flags=%d", sws_flags);
- graph->scale_sws_opts = av_strdup(sws_flags_str);
+ is->vgraph->scale_sws_opts = av_strdup(sws_flags_str);
- if (avfilter_graph_create_filter(&filt_src, &input_filter, "src",
- NULL, is, graph) < 0)
- goto the_end;
- if (avfilter_graph_create_filter(&filt_out, &ffsink, "out",
- NULL, &ffsink_ctx, graph) < 0)
- goto the_end;
+ if ((ret = avfilter_graph_create_filter(&filt_src, &input_filter, "src",
+ NULL, is, is->vgraph)) < 0)
+ goto fail;
+ if ((ret = avfilter_graph_create_filter(&filt_out, &ffsink, "out",
+ NULL, &ffsink_ctx, is->vgraph)) < 0)
+ goto fail;
- if(vfilters) {
+ if (vfilters) {
AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut));
AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut));
@@ -2005,17 +1999,39 @@ static int video_thread(void *arg)
inputs->pad_idx = 0;
inputs->next = NULL;
- if (avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL) < 0)
- goto the_end;
+ if ((ret = avfilter_graph_parse(is->vgraph, vfilters, inputs, outputs, NULL)) < 0)
+ goto fail;
av_freep(&vfilters);
} else {
- if(avfilter_link(filt_src, 0, filt_out, 0) < 0) goto the_end;
+ if ((ret = avfilter_link(filt_src, 0, filt_out, 0)) < 0)
+ goto fail;
}
- if (avfilter_graph_config(graph, NULL) < 0)
- goto the_end;
+ if ((ret = avfilter_graph_config(is->vgraph, NULL)) < 0)
+ goto fail;
is->out_video_filter = filt_out;
+ return 0;
+fail:
+ avfilter_graph_free(is->vgraph);
+ av_freep(&is->vgraph);
+ return ret;
+}
+
+static int video_thread(void *arg)
+{
+ VideoState *is = arg;
+ AVFrame *frame= avcodec_alloc_frame();
+ int64_t pts_int;
+ double pts;
+ int ret;
+#if CONFIG_AVFILTER
+ AVFilterContext *filt_out = NULL;
+ int64_t pos;
+
+ if ((ret = configure_video_filters(is, vfilters)) < 0)
+ goto the_end;
+ filt_out = is->out_video_filter;
#endif
for(;;) {
@@ -2068,10 +2084,8 @@ static int video_thread(void *arg)
stream_pause(cur_stream);
}
the_end:
-#if CONFIG_AVFILTER
- avfilter_graph_free(graph);
- av_freep(&graph);
-#endif
+ avfilter_graph_free(is->vgraph);
+ av_freep(&is->vgraph);
av_free(frame);
return 0;
}
--
1.7.2.3
More information about the ffmpeg-devel
mailing list