History

fftools/ffplay: stop using avfilter_graph_create_filter() incorrectly

This function creates AND initializes a filter, so setting any filter options after it is wrong. It happens to work when the filter's init function does not touch the options in question, but is forbidden by the API and is not guaranteed to remain functional. Instead, use avfilter_graph_alloc_filter(), followed by setting the options, and avfilter_init_dict().

Anton Khirnov committed 2 years ago

Commit 577708a1 parent f6f0e051 file · +35 −23Browse files

Unified · Split

fftools/ffplay.c+35−23
@@ -1861,7 +1861,6 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c · 1860 unmodified lines
18611861 {
18621862 enum AVPixelFormat pix_fmts[FF_ARRAY_ELEMS(sdl_texture_format_map)];
18631863 char sws_flags_str[512] = "";
1864− char buffersrc_args[256];
18651864 int ret;
18661865 AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;
18671866 AVCodecParameters *codecpar = is->video_st->codecpar;
@@ -1895,38 +1894,48 @@ static int configure_video_filters(AVFilterGraph *graph, VideoState *is, const c · 27 unmodified lines
18951894
18961895 graph->scale_sws_opts = av_strdup(sws_flags_str);
18971896
1898− snprintf(buffersrc_args, sizeof(buffersrc_args),
1899− "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d:"
1900− "colorspace=%d:range=%d",
1901− frame->width, frame->height, frame->format,
1902− is->video_st->time_base.num, is->video_st->time_base.den,
1903− codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1),
1904− frame->colorspace, frame->color_range);
1905− if (fr.num && fr.den)
1906− av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den);
1907−
1908− if ((ret = avfilter_graph_create_filter(&filt_src,
1909− avfilter_get_by_name("buffer"),
1910− "ffplay_buffer", buffersrc_args, NULL,
1911− graph)) < 0)
1897+
1898+ filt_src = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffer"),
1899+ "ffplay_buffer");
1900+ if (!filt_src) {
1901+ ret = AVERROR(ENOMEM);
19121902 goto fail;
1903+ }
1904+
1905+ par->format = frame->format;
1906+ par->time_base = is->video_st->time_base;
1907+ par->width = frame->width;
1908+ par->height = frame->height;
1909+ par->sample_aspect_ratio = codecpar->sample_aspect_ratio;
1910+ par->color_space = frame->colorspace;
1911+ par->color_range = frame->color_range;
1912+ par->frame_rate = fr;
19131913 par->hw_frames_ctx = frame->hw_frames_ctx;
19141914 ret = av_buffersrc_parameters_set(filt_src, par);
19151915 if (ret < 0)
19161916 goto fail;
19171917
1918− ret = avfilter_graph_create_filter(&filt_out,
1919− avfilter_get_by_name("buffersink"),
1920− "ffplay_buffersink", NULL, NULL, graph);
1918+ ret = avfilter_init_dict(filt_src, NULL);
19211919 if (ret < 0)
19221920 goto fail;
19231921
1922+ filt_out = avfilter_graph_alloc_filter(graph, avfilter_get_by_name("buffersink"),
1923+ "ffplay_buffersink");
1924+ if (!filt_out) {
1925+ ret = AVERROR(ENOMEM);
1926+ goto fail;
1927+ }
1928+
19241929 if ((ret = av_opt_set_int_list(filt_out, "pix_fmts", pix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)
19251930 goto fail;
19261931 if (!vk_renderer &&
19271932 (ret = av_opt_set_int_list(filt_out, "color_spaces", sdl_supported_color_spaces, AVCOL_SPC_UNSPECIFIED, AV_OPT_SEARCH_CHILDREN)) < 0)
19281933 goto fail;
19291934
1935+ ret = avfilter_init_dict(filt_out, NULL);
1936+ if (ret < 0)
1937+ goto fail;
1938+
19301939 last_filter = filt_out;
19311940
19321941 /* Note: this macro adds a filter before the lastly added filter, so the
@@ -2029,12 +2038,12 @@ static int configure_audio_filters(VideoState *is, const char *afilters, int for · 96 unmodified lines
20292038 if (ret < 0)
20302039 goto end;
20312040
2032−
2033− ret = avfilter_graph_create_filter(&filt_asink,
2034− avfilter_get_by_name("abuffersink"), "ffplay_abuffersink",
2035− NULL, NULL, is->agraph);
2036− if (ret < 0)
2041+ filt_asink = avfilter_graph_alloc_filter(is->agraph, avfilter_get_by_name("abuffersink"),
2042+ "ffplay_abuffersink");
2043+ if (!filt_asink) {
2044+ ret = AVERROR(ENOMEM);
20372045 goto end;
2046+ }
20382047
20392048 if ((ret = av_opt_set_int_list(filt_asink, "sample_fmts", sample_fmts, AV_SAMPLE_FMT_NONE, AV_OPT_SEARCH_CHILDREN)) < 0)
20402049 goto end;
@@ -2053,6 +2062,9 @@ static int configure_audio_filters(VideoState *is, const char *afilters, int for · 12 unmodified lines
20532062 goto end;
20542063 }
20552064
2065+ ret = avfilter_init_dict(filt_asink, NULL);
2066+ if (ret < 0)
2067+ goto end;
20562068
20572069 if ((ret = configure_filtergraph(is->agraph, afilters, filt_asrc, filt_asink)) < 0)
20582070 goto end;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t