[FFmpeg-devel] [PATCH 1/4] lavfi: parsing helper for unknown channel layouts.
Stefano Sabatini
stefasab at gmail.com
Fri Oct 25 18:58:49 CEST 2013
On date Friday 2013-10-25 16:20:55 +0200, Nicolas George encoded:
> Make ff_parse_channel_layout() accept unknown layouts too.
>
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
> libavfilter/af_aconvert.c | 2 +-
> libavfilter/af_pan.c | 2 +-
> libavfilter/asrc_aevalsrc.c | 2 +-
> libavfilter/asrc_anullsrc.c | 2 +-
> libavfilter/formats.c | 17 +++++++++++++++--
> libavfilter/internal.h | 5 ++++-
> 6 files changed, 23 insertions(+), 7 deletions(-)
>
>
> At some point, some cleanup will probably be necessary amongst these various
> functions that do almost the same thing.
> Unfortunately, I believe there are plans to break everything on the fork.
>
>
> diff --git a/libavfilter/af_aconvert.c b/libavfilter/af_aconvert.c
> index a198d2b..43158f0 100644
> --- a/libavfilter/af_aconvert.c
> +++ b/libavfilter/af_aconvert.c
> @@ -66,7 +66,7 @@ static av_cold int init(AVFilterContext *ctx)
> (ret = ff_parse_sample_format(&aconvert->out_sample_fmt, aconvert->format_str, ctx)) < 0)
> return ret;
> if (aconvert->channel_layout_str && strcmp(aconvert->channel_layout_str, "auto"))
> - return ff_parse_channel_layout(&aconvert->out_chlayout, aconvert->channel_layout_str, ctx);
> + return ff_parse_channel_layout(&aconvert->out_chlayout, NULL, aconvert->channel_layout_str, ctx);
> return ret;
> }
>
> diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c
> index 9cee9d9..e742d9e 100644
> --- a/libavfilter/af_pan.c
> +++ b/libavfilter/af_pan.c
> @@ -116,7 +116,7 @@ static av_cold int init(AVFilterContext *ctx)
> if (!args)
> return AVERROR(ENOMEM);
> arg = av_strtok(args, "|", &tokenizer);
> - ret = ff_parse_channel_layout(&pan->out_channel_layout, arg, ctx);
> + ret = ff_parse_channel_layout(&pan->out_channel_layout, NULL, arg, ctx);
> if (ret < 0)
> goto fail;
> pan->nb_output_channels = av_get_channel_layout_nb_channels(pan->out_channel_layout);
> diff --git a/libavfilter/asrc_aevalsrc.c b/libavfilter/asrc_aevalsrc.c
> index 3f71ac3..79fb4b2 100644
> --- a/libavfilter/asrc_aevalsrc.c
> +++ b/libavfilter/asrc_aevalsrc.c
> @@ -109,7 +109,7 @@ static av_cold int init(AVFilterContext *ctx)
>
> if (eval->chlayout_str) {
> int n;
> - ret = ff_parse_channel_layout(&eval->chlayout, eval->chlayout_str, ctx);
> + ret = ff_parse_channel_layout(&eval->chlayout, NULL, eval->chlayout_str, ctx);
> if (ret < 0)
> goto end;
>
> diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c
> index 4f76759..a4bf013 100644
> --- a/libavfilter/asrc_anullsrc.c
> +++ b/libavfilter/asrc_anullsrc.c
> @@ -68,7 +68,7 @@ static av_cold int init(AVFilterContext *ctx)
> null->sample_rate_str, ctx)) < 0)
> return ret;
>
> - if ((ret = ff_parse_channel_layout(&null->channel_layout,
> + if ((ret = ff_parse_channel_layout(&null->channel_layout, NULL,
> null->channel_layout_str, ctx)) < 0)
> return ret;
>
> diff --git a/libavfilter/formats.c b/libavfilter/formats.c
> index d51bf3c..5816032 100644
> --- a/libavfilter/formats.c
> +++ b/libavfilter/formats.c
> @@ -615,10 +615,21 @@ int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
> return 0;
> }
>
> -int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx)
> +int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
> + void *log_ctx)
> {
> char *tail;
> - int64_t chlayout = av_get_channel_layout(arg);
> + int64_t chlayout, count;
> +
> + if (nret) {
> + count = strtol(arg, &tail, 10);
> + if (*tail == 'c' && !tail[1] && count > 0 && count < 63) {
> + *nret = count;
> + *ret = 0;
> + return 0;
> + }
> + }
> + chlayout = av_get_channel_layout(arg);
what about another variant of av_get_channel_layout()?
> if (chlayout == 0) {
> chlayout = strtol(arg, &tail, 10);
> if (*tail || chlayout == 0) {
> @@ -627,6 +638,8 @@ int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx)
> }
> }
> *ret = chlayout;
> + if (nret)
> + *nret = av_get_channel_layout_nb_channels(chlayout);
> return 0;
> }
>
> diff --git a/libavfilter/internal.h b/libavfilter/internal.h
> index f8d0cce..0cb3c35 100644
> --- a/libavfilter/internal.h
> +++ b/libavfilter/internal.h
> @@ -207,11 +207,14 @@ int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx);
> * Parse a channel layout or a corresponding integer representation.
> *
> * @param ret 64bit integer pointer to where the value should be written.
> + * @param ret integer pointer to the number of channels;
nret
> + * if not NULL, then unknown channel layouts are accepted
> * @param arg string to parse
> * @param log_ctx log context
> * @return >= 0 in case of success, a negative AVERROR code on error
> */
> -int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx);
> +int ff_parse_channel_layout(int64_t *ret, int *nret, const char *arg,
> + void *log_ctx);
>
> void ff_update_link_current_pts(AVFilterLink *link, int64_t pts);
LGTM otherwise if useful for the following patches (which I still need
to read).
--
FFmpeg = Fanciful Fast Meaningless Purposeless Entertaining Gargoyle
More information about the ffmpeg-devel
mailing list