Skip to content
Snippets Groups Projects
Commit d57a6d20 authored by Lukasz Marek's avatar Lukasz Marek
Browse files

ffserver_config: cosmetic: move line_num into FFServerConfig

Moving line_num into FFServerConfig as parser state,
saves many passes of it aside of FFServerConfig pointer.
parent e98aced6
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "ffserver_config.h" #include "ffserver_config.h"
static int ffserver_save_avoption(const char *opt, const char *arg, int type, static int ffserver_save_avoption(const char *opt, const char *arg, int type,
FFServerConfig *config, int line_num); FFServerConfig *config);
static void vreport_config_error(const char *filename, int line_num, int log_level, static void vreport_config_error(const char *filename, int line_num, int log_level,
int *errors, const char *fmt, va_list vl); int *errors, const char *fmt, va_list vl);
static void report_config_error(const char *filename, int line_num, int log_level, static void report_config_error(const char *filename, int line_num, int log_level,
...@@ -253,12 +253,12 @@ static void add_codec(FFServerStream *stream, AVCodecContext *av) ...@@ -253,12 +253,12 @@ static void add_codec(FFServerStream *stream, AVCodecContext *av)
stream->streams[stream->nb_streams++] = st; stream->streams[stream->nb_streams++] = st;
} }
static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFServerConfig *config, int line_num) static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFServerConfig *config)
{ {
int ret; int ret;
AVCodec *codec = avcodec_find_encoder_by_name(codec_name); AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
if (!codec || codec->type != ctx->codec_type) { if (!codec || codec->type != ctx->codec_type) {
report_config_error(config->filename, line_num, AV_LOG_ERROR, report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
&config->errors, "Invalid codec name: %s\n", codec_name); &config->errors, "Invalid codec name: %s\n", codec_name);
return 0; return 0;
} }
...@@ -268,13 +268,13 @@ static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFSer ...@@ -268,13 +268,13 @@ static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFSer
ctx->codec = codec; ctx->codec = codec;
} }
if (ctx->codec_id != codec->id) if (ctx->codec_id != codec->id)
report_config_error(config->filename, line_num, AV_LOG_ERROR, &config->errors, report_config_error(config->filename, config->line_num, AV_LOG_ERROR, &config->errors,
"Inconsistent configuration: trying to set %s codec option, but %s codec is used previously\n", "Inconsistent configuration: trying to set %s codec option, but %s codec is used previously\n",
codec_name, avcodec_get_name(ctx->codec_id)); codec_name, avcodec_get_name(ctx->codec_id));
return 0; return 0;
} }
static int ffserver_opt_preset(const char *arg, int type, FFServerConfig *config, int line_num) static int ffserver_opt_preset(const char *arg, int type, FFServerConfig *config)
{ {
FILE *f=NULL; FILE *f=NULL;
char filename[1000], tmp[1000], tmp2[1000], line[1000]; char filename[1000], tmp[1000], tmp2[1000], line[1000];
...@@ -313,13 +313,13 @@ static int ffserver_opt_preset(const char *arg, int type, FFServerConfig *config ...@@ -313,13 +313,13 @@ static int ffserver_opt_preset(const char *arg, int type, FFServerConfig *config
if ((!strcmp(tmp, "acodec") && avctx->codec_type == AVMEDIA_TYPE_AUDIO) || if ((!strcmp(tmp, "acodec") && avctx->codec_type == AVMEDIA_TYPE_AUDIO) ||
!strcmp(tmp, "vcodec") && avctx->codec_type == AVMEDIA_TYPE_VIDEO) !strcmp(tmp, "vcodec") && avctx->codec_type == AVMEDIA_TYPE_VIDEO)
{ {
if (ffserver_set_codec(avctx, tmp2, config, line_num) < 0) if (ffserver_set_codec(avctx, tmp2, config) < 0)
break; break;
} else if (!strcmp(tmp, "scodec")) { } else if (!strcmp(tmp, "scodec")) {
av_log(NULL, AV_LOG_ERROR, "Subtitles preset found.\n"); av_log(NULL, AV_LOG_ERROR, "Subtitles preset found.\n");
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
break; break;
} else if (ffserver_save_avoption(tmp, tmp2, type, config, line_num) < 0) } else if (ffserver_save_avoption(tmp, tmp2, type, config) < 0)
break; break;
} }
...@@ -364,7 +364,7 @@ static void report_config_error(const char *filename, int line_num, int log_leve ...@@ -364,7 +364,7 @@ static void report_config_error(const char *filename, int line_num, int log_leve
} }
static int ffserver_set_int_param(int *dest, const char *value, int factor, int min, int max, static int ffserver_set_int_param(int *dest, const char *value, int factor, int min, int max,
FFServerConfig *config, int line_num, const char *error_msg, ...) FFServerConfig *config, const char *error_msg, ...)
{ {
int tmp; int tmp;
char *tailp; char *tailp;
...@@ -388,7 +388,7 @@ static int ffserver_set_int_param(int *dest, const char *value, int factor, int ...@@ -388,7 +388,7 @@ static int ffserver_set_int_param(int *dest, const char *value, int factor, int
if (config) { if (config) {
va_list vl; va_list vl;
va_start(vl, error_msg); va_start(vl, error_msg);
vreport_config_error(config->filename, line_num, AV_LOG_ERROR, vreport_config_error(config->filename, config->line_num, AV_LOG_ERROR,
&config->errors, error_msg, vl); &config->errors, error_msg, vl);
va_end(vl); va_end(vl);
} }
...@@ -396,7 +396,7 @@ static int ffserver_set_int_param(int *dest, const char *value, int factor, int ...@@ -396,7 +396,7 @@ static int ffserver_set_int_param(int *dest, const char *value, int factor, int
} }
static int ffserver_set_float_param(float *dest, const char *value, float factor, float min, float max, static int ffserver_set_float_param(float *dest, const char *value, float factor, float min, float max,
FFServerConfig *config, int line_num, const char *error_msg, ...) FFServerConfig *config, const char *error_msg, ...)
{ {
double tmp; double tmp;
char *tailp; char *tailp;
...@@ -417,14 +417,14 @@ static int ffserver_set_float_param(float *dest, const char *value, float factor ...@@ -417,14 +417,14 @@ static int ffserver_set_float_param(float *dest, const char *value, float factor
if (config) { if (config) {
va_list vl; va_list vl;
va_start(vl, error_msg); va_start(vl, error_msg);
vreport_config_error(config->filename, line_num, AV_LOG_ERROR, vreport_config_error(config->filename, config->line_num, AV_LOG_ERROR,
&config->errors, error_msg, vl); &config->errors, error_msg, vl);
va_end(vl); va_end(vl);
} }
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
static int ffserver_save_avoption(const char *opt, const char *arg, int type, FFServerConfig *config, int line_num) static int ffserver_save_avoption(const char *opt, const char *arg, int type, FFServerConfig *config)
{ {
static int hinted = 0; static int hinted = 0;
int ret = 0; int ret = 0;
...@@ -461,7 +461,7 @@ static int ffserver_save_avoption(const char *opt, const char *arg, int type, FF ...@@ -461,7 +461,7 @@ static int ffserver_save_avoption(const char *opt, const char *arg, int type, FF
option = strchr(buff, ':'); option = strchr(buff, ':');
buff[option - buff] = '\0'; buff[option - buff] = '\0';
option++; option++;
if ((ret = ffserver_set_codec(ctx, codec_name, config, line_num)) < 0) if ((ret = ffserver_set_codec(ctx, codec_name, config)) < 0)
return ret; return ret;
if (!ctx->codec || !ctx->priv_data) if (!ctx->codec || !ctx->priv_data)
return -1; return -1;
...@@ -471,23 +471,23 @@ static int ffserver_save_avoption(const char *opt, const char *arg, int type, FF ...@@ -471,23 +471,23 @@ static int ffserver_save_avoption(const char *opt, const char *arg, int type, FF
o = av_opt_find(ctx, option, NULL, type | AV_OPT_FLAG_ENCODING_PARAM, AV_OPT_SEARCH_CHILDREN); o = av_opt_find(ctx, option, NULL, type | AV_OPT_FLAG_ENCODING_PARAM, AV_OPT_SEARCH_CHILDREN);
if (!o) { if (!o) {
report_config_error(config->filename, line_num, AV_LOG_ERROR, report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
&config->errors, "Option not found: %s\n", opt); &config->errors, "Option not found: %s\n", opt);
if (!hinted && ctx->codec_id == AV_CODEC_ID_NONE) { if (!hinted && ctx->codec_id == AV_CODEC_ID_NONE) {
hinted = 1; hinted = 1;
report_config_error(config->filename, line_num, AV_LOG_ERROR, NULL, report_config_error(config->filename, config->line_num, AV_LOG_ERROR, NULL,
"If '%s' is a codec private option, then prefix it with codec name, " "If '%s' is a codec private option, then prefix it with codec name, "
"for example '%s:%s %s' or define codec earlier.\n", "for example '%s:%s %s' or define codec earlier.\n",
opt, avcodec_get_name(guessed_codec_id) ,opt, arg); opt, avcodec_get_name(guessed_codec_id) ,opt, arg);
} }
} else if ((ret = av_opt_set(ctx, option, arg, AV_OPT_SEARCH_CHILDREN)) < 0) { } else if ((ret = av_opt_set(ctx, option, arg, AV_OPT_SEARCH_CHILDREN)) < 0) {
report_config_error(config->filename, line_num, AV_LOG_ERROR, report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
&config->errors, "Invalid value for option %s (%s): %s\n", opt, &config->errors, "Invalid value for option %s (%s): %s\n", opt,
arg, av_err2str(ret)); arg, av_err2str(ret));
} else if ((e = av_dict_get(*dict, option, NULL, 0))) { } else if ((e = av_dict_get(*dict, option, NULL, 0))) {
if ((o->type == AV_OPT_TYPE_FLAGS) && arg && (arg[0] == '+' || arg[0] == '-')) if ((o->type == AV_OPT_TYPE_FLAGS) && arg && (arg[0] == '+' || arg[0] == '-'))
return av_dict_set(dict, option, arg, AV_DICT_APPEND); return av_dict_set(dict, option, arg, AV_DICT_APPEND);
report_config_error(config->filename, line_num, AV_LOG_ERROR, report_config_error(config->filename, config->line_num, AV_LOG_ERROR,
&config->errors, &config->errors,
"Redeclaring value of the option %s, previous value: %s\n", "Redeclaring value of the option %s, previous value: %s\n",
opt, e->value); opt, e->value);
...@@ -497,11 +497,11 @@ static int ffserver_save_avoption(const char *opt, const char *arg, int type, FF ...@@ -497,11 +497,11 @@ static int ffserver_save_avoption(const char *opt, const char *arg, int type, FF
return 0; return 0;
} }
#define ERROR(...) report_config_error(config->filename, line_num, AV_LOG_ERROR, &config->errors, __VA_ARGS__) #define ERROR(...) report_config_error(config->filename, config->line_num, AV_LOG_ERROR, &config->errors, __VA_ARGS__)
#define WARNING(...) report_config_error(config->filename, line_num, AV_LOG_WARNING, &config->warnings, __VA_ARGS__) #define WARNING(...) report_config_error(config->filename, config->line_num, AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
const char **p, int line_num) const char **p)
{ {
int val; int val;
char arg[1024]; char arg[1024];
...@@ -509,7 +509,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, ...@@ -509,7 +509,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
if (!av_strcasecmp(cmd, "Port")) if (!av_strcasecmp(cmd, "Port"))
WARNING("Port option is deprecated, use HTTPPort instead\n"); WARNING("Port option is deprecated, use HTTPPort instead\n");
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num, ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
"Invalid port: %s\n", arg); "Invalid port: %s\n", arg);
if (val < 1024) if (val < 1024)
WARNING("Trying to use IETF assigned system port: %d\n", val); WARNING("Trying to use IETF assigned system port: %d\n", val);
...@@ -524,7 +524,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, ...@@ -524,7 +524,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
WARNING("NoDaemon option has no effect, you should remove it\n"); WARNING("NoDaemon option has no effect, you should remove it\n");
} else if (!av_strcasecmp(cmd, "RTSPPort")) { } else if (!av_strcasecmp(cmd, "RTSPPort")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num, ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
"Invalid port: %s\n", arg); "Invalid port: %s\n", arg);
config->rtsp_addr.sin_port = htons(val); config->rtsp_addr.sin_port = htons(val);
} else if (!av_strcasecmp(cmd, "RTSPBindAddress")) { } else if (!av_strcasecmp(cmd, "RTSPBindAddress")) {
...@@ -533,7 +533,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, ...@@ -533,7 +533,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
ERROR("Invalid host/IP address: %s\n", arg); ERROR("Invalid host/IP address: %s\n", arg);
} else if (!av_strcasecmp(cmd, "MaxHTTPConnections")) { } else if (!av_strcasecmp(cmd, "MaxHTTPConnections")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num, ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
"Invalid MaxHTTPConnections: %s\n", arg); "Invalid MaxHTTPConnections: %s\n", arg);
config->nb_max_http_connections = val; config->nb_max_http_connections = val;
if (config->nb_max_connections > config->nb_max_http_connections) if (config->nb_max_connections > config->nb_max_http_connections)
...@@ -541,7 +541,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, ...@@ -541,7 +541,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
config->nb_max_connections, config->nb_max_http_connections); config->nb_max_connections, config->nb_max_http_connections);
} else if (!av_strcasecmp(cmd, "MaxClients")) { } else if (!av_strcasecmp(cmd, "MaxClients")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num, ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
"Invalid MaxClients: %s\n", arg); "Invalid MaxClients: %s\n", arg);
config->nb_max_connections = val; config->nb_max_connections = val;
if (config->nb_max_connections > config->nb_max_http_connections) if (config->nb_max_connections > config->nb_max_http_connections)
...@@ -568,7 +568,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, ...@@ -568,7 +568,7 @@ static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
} }
static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, const char **p, static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, const char **p,
int line_num, FFServerStream **pfeed) FFServerStream **pfeed)
{ {
FFServerStream *feed; FFServerStream *feed;
char arg[1024]; char arg[1024];
...@@ -626,7 +626,7 @@ static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, c ...@@ -626,7 +626,7 @@ static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, c
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} else if (!av_strcasecmp(cmd, "ACL")) { } else if (!av_strcasecmp(cmd, "ACL")) {
ffserver_parse_acl_row(NULL, feed, NULL, *p, config->filename, ffserver_parse_acl_row(NULL, feed, NULL, *p, config->filename,
line_num); config->line_num);
} else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) { } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
ffserver_get_arg(feed->feed_filename, sizeof(feed->feed_filename), p); ffserver_get_arg(feed->feed_filename, sizeof(feed->feed_filename), p);
feed->readonly = !av_strcasecmp(cmd, "ReadOnlyFile"); feed->readonly = !av_strcasecmp(cmd, "ReadOnlyFile");
...@@ -777,7 +777,7 @@ static void ffserver_apply_stream_config(AVCodecContext *enc, const AVDictionary ...@@ -777,7 +777,7 @@ static void ffserver_apply_stream_config(AVCodecContext *enc, const AVDictionary
} }
static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, const char **p, static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, const char **p,
int line_num, FFServerStream **pstream) FFServerStream **pstream)
{ {
char arg[1024], arg2[1024]; char arg[1024], arg2[1024];
FFServerStream *stream; FFServerStream *stream;
...@@ -893,29 +893,29 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -893,29 +893,29 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
stream->send_on_key = 1; stream->send_on_key = 1;
} else if (!av_strcasecmp(cmd, "AudioCodec")) { } else if (!av_strcasecmp(cmd, "AudioCodec")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_codec(config->dummy_actx, arg, config, line_num); ffserver_set_codec(config->dummy_actx, arg, config);
} else if (!av_strcasecmp(cmd, "VideoCodec")) { } else if (!av_strcasecmp(cmd, "VideoCodec")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_codec(config->dummy_vctx, arg, config, line_num); ffserver_set_codec(config->dummy_vctx, arg, config);
} else if (!av_strcasecmp(cmd, "MaxTime")) { } else if (!av_strcasecmp(cmd, "MaxTime")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
stream->max_time = atof(arg) * 1000; stream->max_time = atof(arg) * 1000;
} else if (!av_strcasecmp(cmd, "AudioBitRate")) { } else if (!av_strcasecmp(cmd, "AudioBitRate")) {
float f; float f;
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_float_param(&f, arg, 1000, 0, FLT_MAX, config, line_num, ffserver_set_float_param(&f, arg, 1000, 0, FLT_MAX, config,
"Invalid %s: %s\n", cmd, arg); "Invalid %s: %s\n", cmd, arg);
if (av_dict_set_int(&config->audio_conf, cmd, lrintf(f), 0) < 0) if (av_dict_set_int(&config->audio_conf, cmd, lrintf(f), 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "AudioChannels")) { } else if (!av_strcasecmp(cmd, "AudioChannels")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 8, config, line_num, ffserver_set_int_param(NULL, arg, 0, 1, 8, config,
"Invalid %s: %s, valid range is 1-8.", cmd, arg); "Invalid %s: %s, valid range is 1-8.", cmd, arg);
if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "AudioSampleRate")) { } else if (!av_strcasecmp(cmd, "AudioSampleRate")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 0, INT_MAX, config, line_num, ffserver_set_int_param(NULL, arg, 0, 0, INT_MAX, config,
"Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
...@@ -931,31 +931,31 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -931,31 +931,31 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
"<min>-<max>: %s\n", arg); "<min>-<max>: %s\n", arg);
} else if (!av_strcasecmp(cmd, "Debug")) { } else if (!av_strcasecmp(cmd, "Debug")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num, ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config,
"Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "Strict")) { } else if (!av_strcasecmp(cmd, "Strict")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num, ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config,
"Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBufferSize")) { } else if (!av_strcasecmp(cmd, "VideoBufferSize")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 8*1024, 0, INT_MAX, config, line_num, ffserver_set_int_param(NULL, arg, 8*1024, 0, INT_MAX, config,
"Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBitRateTolerance")) { } else if (!av_strcasecmp(cmd, "VideoBitRateTolerance")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 1000, INT_MIN, INT_MAX, config, ffserver_set_int_param(NULL, arg, 1000, INT_MIN, INT_MAX, config,
line_num, "Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoBitRate")) { } else if (!av_strcasecmp(cmd, "VideoBitRate")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 1000, 0, INT_MAX, config, line_num, ffserver_set_int_param(NULL, arg, 1000, 0, INT_MAX, config,
"Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
...@@ -990,7 +990,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -990,7 +990,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoGopSize")) { } else if (!av_strcasecmp(cmd, "VideoGopSize")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num, ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config,
"Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
...@@ -1009,18 +1009,18 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -1009,18 +1009,18 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_get_arg(arg2, sizeof(arg2), p); ffserver_get_arg(arg2, sizeof(arg2), p);
if (!av_strcasecmp(cmd, "AVOptionVideo")) if (!av_strcasecmp(cmd, "AVOptionVideo"))
ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_VIDEO_PARAM, config, line_num); ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_VIDEO_PARAM, config);
else else
ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_AUDIO_PARAM, config, line_num); ret = ffserver_save_avoption(arg, arg2, AV_OPT_FLAG_AUDIO_PARAM, config);
if (ret < 0) if (ret < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "AVPresetVideo") || } else if (!av_strcasecmp(cmd, "AVPresetVideo") ||
!av_strcasecmp(cmd, "AVPresetAudio")) { !av_strcasecmp(cmd, "AVPresetAudio")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
if (!av_strcasecmp(cmd, "AVPresetVideo")) if (!av_strcasecmp(cmd, "AVPresetVideo"))
ffserver_opt_preset(arg, AV_OPT_FLAG_VIDEO_PARAM, config, line_num); ffserver_opt_preset(arg, AV_OPT_FLAG_VIDEO_PARAM, config);
else else
ffserver_opt_preset(arg, AV_OPT_FLAG_AUDIO_PARAM, config, line_num); ffserver_opt_preset(arg, AV_OPT_FLAG_AUDIO_PARAM, config);
} else if (!av_strcasecmp(cmd, "VideoTag")) { } else if (!av_strcasecmp(cmd, "VideoTag")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
if (strlen(arg) == 4) { if (strlen(arg) == 4) {
...@@ -1042,32 +1042,32 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -1042,32 +1042,32 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoQDiff")) { } else if (!av_strcasecmp(cmd, "VideoQDiff")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num, ffserver_set_int_param(NULL, arg, 0, 1, 31, config,
"%s out of range\n", cmd); "%s out of range\n", cmd);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoQMax")) { } else if (!av_strcasecmp(cmd, "VideoQMax")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num, ffserver_set_int_param(NULL, arg, 0, 1, 31, config,
"%s out of range\n", cmd); "%s out of range\n", cmd);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "VideoQMin")) { } else if (!av_strcasecmp(cmd, "VideoQMin")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num, ffserver_set_int_param(NULL, arg, 0, 1, 31, config,
"%s out of range\n", cmd); "%s out of range\n", cmd);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "LumiMask")) { } else if (!av_strcasecmp(cmd, "LumiMask")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config, ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config,
line_num, "Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "DarkMask")) { } else if (!av_strcasecmp(cmd, "DarkMask")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config, ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config,
line_num, "Invalid %s: %s", cmd, arg); "Invalid %s: %s", cmd, arg);
if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0) if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
goto nomem; goto nomem;
} else if (!av_strcasecmp(cmd, "NoVideo")) { } else if (!av_strcasecmp(cmd, "NoVideo")) {
...@@ -1076,7 +1076,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -1076,7 +1076,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
config->no_audio = 1; config->no_audio = 1;
} else if (!av_strcasecmp(cmd, "ACL")) { } else if (!av_strcasecmp(cmd, "ACL")) {
ffserver_parse_acl_row(stream, NULL, NULL, *p, config->filename, ffserver_parse_acl_row(stream, NULL, NULL, *p, config->filename,
line_num); config->line_num);
} else if (!av_strcasecmp(cmd, "DynamicACL")) { } else if (!av_strcasecmp(cmd, "DynamicACL")) {
ffserver_get_arg(stream->dynamic_acl, sizeof(stream->dynamic_acl), p); ffserver_get_arg(stream->dynamic_acl, sizeof(stream->dynamic_acl), p);
} else if (!av_strcasecmp(cmd, "RTSPOption")) { } else if (!av_strcasecmp(cmd, "RTSPOption")) {
...@@ -1091,13 +1091,13 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -1091,13 +1091,13 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
stream->loop = 1; /* default is looping */ stream->loop = 1; /* default is looping */
} else if (!av_strcasecmp(cmd, "MulticastPort")) { } else if (!av_strcasecmp(cmd, "MulticastPort")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num, ffserver_set_int_param(&val, arg, 0, 1, 65535, config,
"Invalid MulticastPort: %s\n", arg); "Invalid MulticastPort: %s\n", arg);
stream->multicast_port = val; stream->multicast_port = val;
} else if (!av_strcasecmp(cmd, "MulticastTTL")) { } else if (!av_strcasecmp(cmd, "MulticastTTL")) {
ffserver_get_arg(arg, sizeof(arg), p); ffserver_get_arg(arg, sizeof(arg), p);
ffserver_set_int_param(&val, arg, 0, INT_MIN, INT_MAX, config, ffserver_set_int_param(&val, arg, 0, INT_MIN, INT_MAX, config,
line_num, "Invalid MulticastTTL: %s\n", arg); "Invalid MulticastTTL: %s\n", arg);
stream->multicast_ttl = val; stream->multicast_ttl = val;
} else if (!av_strcasecmp(cmd, "NoLoop")) { } else if (!av_strcasecmp(cmd, "NoLoop")) {
stream->loop = 0; stream->loop = 0;
...@@ -1144,7 +1144,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, ...@@ -1144,7 +1144,7 @@ static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd,
} }
static int ffserver_parse_config_redirect(FFServerConfig *config, const char *cmd, const char **p, static int ffserver_parse_config_redirect(FFServerConfig *config, const char *cmd, const char **p,
int line_num, FFServerStream **predirect) FFServerStream **predirect)
{ {
FFServerStream *redirect; FFServerStream *redirect;
av_assert0(predirect); av_assert0(predirect);
...@@ -1184,13 +1184,13 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config) ...@@ -1184,13 +1184,13 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
char line[1024]; char line[1024];
char cmd[64]; char cmd[64];
const char *p; const char *p;
int line_num = 0;
FFServerStream **last_stream, *stream = NULL, *redirect = NULL; FFServerStream **last_stream, *stream = NULL, *redirect = NULL;
FFServerStream **last_feed, *feed = NULL; FFServerStream **last_feed, *feed = NULL;
int ret = 0; int ret = 0;
av_assert0(config); av_assert0(config);
config->line_num = 0;
f = fopen(filename, "r"); f = fopen(filename, "r");
if (!f) { if (!f) {
ret = AVERROR(errno); ret = AVERROR(errno);
...@@ -1208,7 +1208,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config) ...@@ -1208,7 +1208,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
for(;;) { for(;;) {
if (fgets(line, sizeof(line), f) == NULL) if (fgets(line, sizeof(line), f) == NULL)
break; break;
line_num++; config->line_num++;
p = line; p = line;
while (av_isspace(*p)) while (av_isspace(*p))
p++; p++;
...@@ -1222,7 +1222,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config) ...@@ -1222,7 +1222,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
if (opening && (stream || feed || redirect)) { if (opening && (stream || feed || redirect)) {
ERROR("Already in a tag\n"); ERROR("Already in a tag\n");
} else { } else {
if ((ret = ffserver_parse_config_feed(config, cmd, &p, line_num, &feed)) < 0) if ((ret = ffserver_parse_config_feed(config, cmd, &p, &feed)) < 0)
break; break;
if (opening) { if (opening) {
/* add in stream list */ /* add in stream list */
...@@ -1238,7 +1238,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config) ...@@ -1238,7 +1238,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
if (opening && (stream || feed || redirect)) { if (opening && (stream || feed || redirect)) {
ERROR("Already in a tag\n"); ERROR("Already in a tag\n");
} else { } else {
if ((ret = ffserver_parse_config_stream(config, cmd, &p, line_num, &stream)) < 0) if ((ret = ffserver_parse_config_stream(config, cmd, &p, &stream)) < 0)
break; break;
if (opening) { if (opening) {
/* add in stream list */ /* add in stream list */
...@@ -1251,7 +1251,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config) ...@@ -1251,7 +1251,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
if (opening && (stream || feed || redirect)) if (opening && (stream || feed || redirect))
ERROR("Already in a tag\n"); ERROR("Already in a tag\n");
else { else {
if ((ret = ffserver_parse_config_redirect(config, cmd, &p, line_num, &redirect)) < 0) if ((ret = ffserver_parse_config_redirect(config, cmd, &p, &redirect)) < 0)
break; break;
if (opening) { if (opening) {
/* add in stream list */ /* add in stream list */
...@@ -1260,7 +1260,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config) ...@@ -1260,7 +1260,7 @@ int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
} }
} }
} else { } else {
ffserver_parse_config_global(config, cmd, &p, line_num); ffserver_parse_config_global(config, cmd, &p);
} }
} }
if (stream || feed || redirect) if (stream || feed || redirect)
......
...@@ -117,6 +117,7 @@ typedef struct FFServerConfig { ...@@ -117,6 +117,7 @@ typedef struct FFServerConfig {
AVCodecContext *dummy_vctx; /* Used internally to test video AVOptions. */ AVCodecContext *dummy_vctx; /* Used internally to test video AVOptions. */
int no_audio; int no_audio;
int no_video; int no_video;
int line_num;
} FFServerConfig; } FFServerConfig;
void ffserver_get_arg(char *buf, int buf_size, const char **pp); void ffserver_get_arg(char *buf, int buf_size, const char **pp);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment