af_format: prefer strtok_r() over strsep()

strsep() is not POSIX compliant, and thus not supported on some platform.
Fix compilation on Solaris.
This commit is contained in:
Stefano Sabatini 2011-08-16 02:02:44 +02:00
parent a719679561
commit 86ca51acb0
2 changed files with 41 additions and 17 deletions

1
configure vendored
View File

@ -1501,6 +1501,7 @@ tcp_protocol_deps="network"
udp_protocol_deps="network"
# filters
aformat_filter_deps="strtok_r"
blackframe_filter_deps="gpl"
boxblur_filter_deps="gpl"
cropdetect_filter_deps="gpl"

View File

@ -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);
}