[FFmpeg-devel] [PATCH] lavfi/format: fix crash in case no format is specified
Stefano Sabatini
stefasab at gmail.com
Mon Dec 9 15:45:56 CET 2013
Also extend logic so that if no format is specified then all formats are
accepted. This is probably silly but is consitent with the (undocumented)
behavior of aformat.
Fix trac ticket #3210.
Todo: bump micro.
---
libavfilter/vf_format.c | 29 +++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)
diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c
index 2e9ff27..5ecef44 100644
--- a/libavfilter/vf_format.c
+++ b/libavfilter/vf_format.c
@@ -78,21 +78,35 @@ static av_cold int init(AVFilterContext *ctx)
return 0;
}
-static AVFilterFormats *make_format_list(FormatContext *s, int flag)
+static int make_format_list(AVFilterFormats **formatsp, FormatContext *s, int flag)
{
AVFilterFormats *formats = NULL;
enum AVPixelFormat pix_fmt;
+ int ret, count = 0;
for (pix_fmt = 0; pix_fmt < AV_PIX_FMT_NB; pix_fmt++)
if (s->listed_pix_fmt_flags[pix_fmt] == flag) {
- int ret = ff_add_format(&formats, pix_fmt);
+ count++;
+ ret = ff_add_format(&formats, pix_fmt);
if (ret < 0) {
ff_formats_unref(&formats);
- return NULL;
+ return ret;
}
}
- return formats;
+ *formatsp = formats;
+ return count;
+}
+
+static int query_formats_common(AVFilterContext *ctx, int flag)
+{
+ AVFilterFormats *formats = NULL;
+ int ret;
+
+ if ((ret = make_format_list(&formats, ctx->priv, flag)) < 0)
+ return ret;
+ ff_set_common_formats(ctx, formats ? formats : ff_all_formats(AVMEDIA_TYPE_VIDEO));
+ return 0;
}
#define OFFSET(x) offsetof(FormatContext, x)
@@ -104,8 +118,7 @@ static const AVOption options[] = {
#if CONFIG_FORMAT_FILTER
static int query_formats_format(AVFilterContext *ctx)
{
- ff_set_common_formats(ctx, make_format_list(ctx->priv, 1));
- return 0;
+ return query_formats_common(ctx, 1);
}
#define format_options options
@@ -141,10 +154,10 @@ AVFilter ff_vf_format = {
#endif /* CONFIG_FORMAT_FILTER */
#if CONFIG_NOFORMAT_FILTER
+
static int query_formats_noformat(AVFilterContext *ctx)
{
- ff_set_common_formats(ctx, make_format_list(ctx->priv, 0));
- return 0;
+ return query_formats_common(ctx, 0);
}
#define noformat_options options
--
1.8.1.2
More information about the ffmpeg-devel
mailing list