diff options
author | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2011-08-16 04:02:44 +0400 |
---|---|---|
committer | Stefano Sabatini <stefano.sabatini-lala@poste.it> | 2011-08-16 19:00:57 +0400 |
commit | 86ca51acb089e74d9b86dfbb25dce2c6b3568047 (patch) | |
tree | c5b17157a35688064eec8dc46dccffb8440bb32c /libavfilter/af_aformat.c | |
parent | a7196795613f2cd416cf2c51c767a1125e27b057 (diff) |
af_format: prefer strtok_r() over strsep()
strsep() is not POSIX compliant, and thus not supported on some platform.
Fix compilation on Solaris.
Diffstat (limited to 'libavfilter/af_aformat.c')
-rw-r--r-- | libavfilter/af_aformat.c | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index 59a2d5aa09..c753ea7b60 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -23,8 +23,8 @@ * format audio filter */ -#define _BSD_SOURCE #include "libavutil/audioconvert.h" +#include "libavutil/avstring.h" #include "avfilter.h" #include "internal.h" @@ -35,51 +35,74 @@ typedef struct { static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) { AFormatContext * const aformat = ctx->priv; - char *arg, *fmt_str; + char *fmts_str = NULL, *fmt_str, *ptr = NULL; int64_t fmt; int ret; - arg = strsep(&args, ":"); - if (!arg) goto arg_fail; - if (!strcmp(arg, "all")) { + if (!args) + goto arg_fail; + + fmts_str = av_get_token(&args, ":"); + if (!fmts_str || !*fmts_str) + goto arg_fail; + if (!strcmp(fmts_str, "all")) { aformat->formats = avfilter_all_formats(AVMEDIA_TYPE_AUDIO); } else { - while (fmt_str = strsep(&arg, ",")) { - if ((ret = ff_parse_sample_format((int*)&fmt, fmt_str, ctx)) < 0) + for (fmt_str = fmts_str; + fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) { + if ((ret = ff_parse_sample_format((int*)&fmt, fmt_str, ctx)) < 0) { + av_freep(&fmts_str); return ret; + } avfilter_add_format(&aformat->formats, fmt); } } + av_freep(&fmts_str); - arg = strsep(&args, ":"); - if (!arg) goto arg_fail; - if (!strcmp(arg, "all")) { + if (*args) + args++; + fmts_str = av_get_token(&args, ":"); + if (!fmts_str || !*fmts_str) + goto arg_fail; + if (!strcmp(fmts_str, "all")) { aformat->chlayouts = avfilter_all_channel_layouts(); } else { - while (fmt_str = strsep(&arg, ",")) { - if ((ret = ff_parse_channel_layout(&fmt, fmt_str, ctx)) < 0) + for (fmt_str = fmts_str; + fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) { + if ((ret = ff_parse_channel_layout(&fmt, fmt_str, ctx)) < 0) { + av_freep(&fmts_str); return ret; + } avfilter_add_format(&aformat->chlayouts, fmt); } } + av_freep(&fmts_str); - arg = strsep(&args, ":"); - if (!arg) goto arg_fail; - if (!strcmp(arg, "all")) { + if (*args) + args++; + fmts_str = av_get_token(&args, ":"); + if (!fmts_str || !*fmts_str) + goto arg_fail; + if (!strcmp(fmts_str, "all")) { aformat->packing = avfilter_all_packing_formats(); } else { - while (fmt_str = strsep(&arg, ",")) { - if ((ret = ff_parse_packing_format((int*)&fmt, fmt_str, ctx)) < 0) + for (fmt_str = fmts_str; + fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) { + if ((ret = ff_parse_packing_format((int*)&fmt, fmt_str, ctx)) < 0) { + av_freep(&fmts_str); return ret; + } avfilter_add_format(&aformat->packing, fmt); } } + av_freep(&fmts_str); return 0; arg_fail: av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form " "sample_fmts:channel_layouts:packing_fmts\n"); + av_freep(&fmts_str); return AVERROR(EINVAL); } |