[FFmpeg-devel] [PATCH 1/6] avformat/format: add av_demuxer_find_by_ext
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Fri Jan 31 19:11:00 EET 2020
Gyan Doshi:
> Allows selecting demuxer by extension which are more widely recognized
> by users.
>
> Conditional cast added since this function will usually be called after
> av_find_input_format, and so matches its return type.
That's not a good point. av_demuxer_find_by_ext() already always
returns const AVInputFormat *, so you casting the const away when
returning is pointless. Furthermore, any caller that wants to use this
new function can simply use a pointer to const AVInputFormat to work
with both av_find_input_format() and av_demuxer_find_by_ext(). And
after all, adding const makes the code more future-proof
(av_find_input_format() will return const AVInputFormat * after the
next major bump).
> ---
> libavformat/avformat.h | 5 +++++
> libavformat/format.c | 15 +++++++++++++++
> libavformat/version.h | 2 +-
> 3 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 9b9b634ec3..9172ddbc8a 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -2237,6 +2237,11 @@ int avformat_alloc_output_context2(AVFormatContext **ctx, ff_const59 AVOutputFor
> */
> ff_const59 AVInputFormat *av_find_input_format(const char *short_name);
>
> +/**
> + * Find AVInputFormat based on an extension.
> + */
> +const AVInputFormat *av_demuxer_find_by_ext(const char *extension);
> +
> /**
> * Guess the file format.
> *
> diff --git a/libavformat/format.c b/libavformat/format.c
> index c47490c8eb..9dda6df676 100644
> --- a/libavformat/format.c
> +++ b/libavformat/format.c
> @@ -125,6 +125,21 @@ ff_const59 AVInputFormat *av_find_input_format(const char *short_name)
> return NULL;
> }
>
> +const AVInputFormat *av_demuxer_find_by_ext(const char *extension)
> +{
> + const AVInputFormat *fmt = NULL;
> + void *i = 0;
Use NULL, it's a pointer after all (yes, I know that
av_demuxer_iterate() treats it as a uintptr_t internally).
> + while ((fmt = av_demuxer_iterate(&i)))
> + if (fmt->extensions && av_match_name(extension, fmt->extensions))
> +#if FF_API_AVIOFORMAT
> + return (AVInputFormat*)fmt;
> +#else
> + return fmt;
> +#endif
As has been said: The first branch of the #if should be deleted (as
the #if, of course).
- Andreas
More information about the ffmpeg-devel
mailing list