[FFmpeg-devel] [PATCH] cmdutils: make parse_options() accept a parse_arg_function with generic signature
Stefano Sabatini
stefasab at gmail.com
Thu Jan 12 18:25:27 CET 2012
Make parse_options() accept a parse_arg_function with signature:
int (* parse_arg_function)(void *optctx, const char *, const char*)
rather than:
int (* parse_arg_function)(void *optctx, const char*)
This is required as this function may be used for other options as well,
as in the case of the ffplay and ffprobe -i options.
In particular, fix ffprobe -i FILE behavior.
---
avconv.c | 3 ++-
cmdutils.c | 4 ++--
cmdutils.h | 2 +-
ffmpeg.c | 3 ++-
ffplay.c | 9 ++++-----
ffprobe.c | 7 ++++---
6 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/avconv.c b/avconv.c
index 5f0422c..8209bee 100644
--- a/avconv.c
+++ b/avconv.c
@@ -3896,7 +3896,7 @@ static int copy_chapters(InputFile *ifile, OutputFile *ofile, int copy_metadata)
return 0;
}
-static void opt_output_file(void *optctx, const char *filename)
+static int opt_output_file(void *optctx, const char *opt, const char *filename)
{
OptionsContext *o = optctx;
AVFormatContext *oc;
@@ -4156,6 +4156,7 @@ static void opt_output_file(void *optctx, const char *filename)
}
reset_options(o);
+ return 0;
}
/* same option as mencoder */
diff --git a/cmdutils.c b/cmdutils.c
index 344e506..729c51c 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -312,7 +312,7 @@ unknown_opt:
}
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
- void (*parse_arg_function)(void *, const char*))
+ int (*parse_arg_function)(void *, const char *, const char *))
{
const char *opt;
int optindex, handleoptions = 1, ret;
@@ -337,7 +337,7 @@ void parse_options(void *optctx, int argc, char **argv, const OptionDef *options
optindex += ret;
} else {
if (parse_arg_function)
- parse_arg_function(optctx, opt);
+ parse_arg_function(optctx, NULL, opt);
}
}
}
diff --git a/cmdutils.h b/cmdutils.h
index 61d0788..16274ba 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -186,7 +186,7 @@ void show_help_children(const AVClass *class, int flags);
* not have to be processed.
*/
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options,
- void (* parse_arg_function)(void *optctx, const char*));
+ int (* parse_arg_function)(void *optctx, const char *, const char *));
/**
* Parse one given option.
diff --git a/ffmpeg.c b/ffmpeg.c
index 884abde..9815345 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -4239,7 +4239,7 @@ static int read_ffserver_streams(OptionsContext *o, AVFormatContext *s, const ch
return 0;
}
-static void opt_output_file(void *optctx, const char *filename)
+static int opt_output_file(void *optctx, const char *opt, const char *filename)
{
OptionsContext *o = optctx;
AVFormatContext *oc;
@@ -4541,6 +4541,7 @@ static void opt_output_file(void *optctx, const char *filename)
}
reset_options(o, 0);
+ return 0;
}
/* same option as mencoder */
diff --git a/ffplay.c b/ffplay.c
index bd7374a..85f9b67 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -3038,16 +3038,17 @@ static int opt_show_mode(const char *opt, const char *arg)
return 0;
}
-static void opt_input_file(void *optctx, const char *filename)
+static int opt_input_file(void *optctx, const char *opt, const char *filename)
{
if (input_filename) {
fprintf(stderr, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
filename, input_filename);
- exit_program(1);
+ return AVERROR(EINVAL);
}
if (!strcmp(filename, "-"))
filename = "pipe:";
input_filename = filename;
+ return 0;
}
static int opt_codec(void *o, const char *opt, const char *arg)
@@ -3060,8 +3061,6 @@ static int opt_codec(void *o, const char *opt, const char *arg)
return 0;
}
-static int dummy;
-
static const OptionDef options[] = {
#include "cmdutils_common_opts.h"
{ "x", HAS_ARG, { (void*)opt_width }, "force displayed width", "width" },
@@ -3104,7 +3103,7 @@ static const OptionDef options[] = {
{ "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, { (void*)&rdftspeed }, "rdft speed", "msecs" },
{ "showmode", HAS_ARG, {(void*)opt_show_mode}, "select show mode (0 = video, 1 = waves, 2 = RDFT)", "mode" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, { (void*)opt_default }, "generic catch all option", "" },
- { "i", OPT_BOOL, {(void *)&dummy}, "read specified file", "input_file"},
+ { "i", HAS_ARG | OPT_FUNC2, {(void *)opt_input_file}, "read specified file", "input_file"},
{ "codec", HAS_ARG | OPT_FUNC2, {(void*)opt_codec}, "force decoder", "decoder" },
{ NULL, },
};
diff --git a/ffprobe.c b/ffprobe.c
index 954a829..14640e6 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -1696,16 +1696,17 @@ static int opt_format(const char *opt, const char *arg)
return 0;
}
-static void opt_input_file(void *optctx, const char *arg)
+static int opt_input_file(void *optctx, const char *opt, const char *arg)
{
if (input_filename) {
av_log(NULL, AV_LOG_ERROR, "Argument '%s' provided as input filename, but '%s' was already specified.\n",
arg, input_filename);
- exit(1);
+ return AVERROR(EINVAL);
}
if (!strcmp(arg, "-"))
arg = "pipe:";
input_filename = arg;
+ return 0;
}
static int opt_help(const char *opt, const char *arg)
@@ -1760,7 +1761,7 @@ static const OptionDef options[] = {
{ "show_private_data", OPT_BOOL, {(void*)&show_private_data}, "show private data" },
{ "private", OPT_BOOL, {(void*)&show_private_data}, "same as show_private_data" },
{ "default", HAS_ARG | OPT_AUDIO | OPT_VIDEO | OPT_EXPERT, {(void*)opt_default}, "generic catch all option", "" },
- { "i", HAS_ARG, {(void *)opt_input_file}, "read specified file", "input_file"},
+ { "i", HAS_ARG | OPT_FUNC2, {(void *)opt_input_file}, "read specified file", "input_file"},
{ NULL, },
};
--
1.7.5.4
More information about the ffmpeg-devel
mailing list