34 #define MAX_CHILD_ARGS 64
39 int log_level,
int *errors,
const char *
fmt,
42 int log_level,
int *errors,
const char *
fmt,
45 #define ERROR(...) report_config_error(config->filename, config->line_num,\
46 AV_LOG_ERROR, &config->errors, __VA_ARGS__)
47 #define WARNING(...) report_config_error(config->filename, config->line_num,\
48 AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
52 static int resolve_host(
struct in_addr *sin_addr,
const char *hostname)
65 for (cur = ai; cur; cur = cur->
ai_next) {
67 *sin_addr = ((
struct sockaddr_in *)cur->
ai_addr)->sin_addr;
76 hp = gethostbyname(hostname);
79 memcpy(sin_addr, hp->h_addr_list[0],
sizeof(
struct in_addr));
96 if (*p ==
'\"' || *p ==
'\'')
100 if (quote && *p == quote || !quote &&
av_isspace(*p))
102 if ((q - buf) < buf_size - 1)
108 if (quote && *p == quote)
115 const char *p,
const char *filename,
int line_num)
128 fprintf(stderr,
"%s:%d: ACL action '%s' should be ALLOW or DENY.\n",
129 filename, line_num, arg);
137 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
138 filename, line_num, arg);
149 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
150 filename, line_num, arg);
162 naclp = &stream->
acl;
168 fprintf(stderr,
"%s:%d: ACL found not in <Stream> or <Feed>\n",
173 naclp = &(*naclp)->
next;
203 "Something is wrong, %d options are not set!\n",
212 "audio bit rate is not set\n");
216 "audio sample rate is not set\n");
222 "video size is not set\n");
238 WARNING(
"Setting default value for audio bit rate = %d. "
239 "Use NoDefaults to disable it.\n",
245 WARNING(
"Setting default value for audio sample rate = %d. "
246 "Use NoDefaults to disable it.\n",
252 WARNING(
"Setting default value for audio channel count = %d. "
253 "Use NoDefaults to disable it.\n",
261 WARNING(
"Setting default value for video bit rate = %d. "
262 "Use NoDefaults to disable it.\n",
269 WARNING(
"Setting default value for video frame rate = %d. "
270 "Use NoDefaults to disable it.\n",
276 av_dict_set(&recommended,
"video_size",
"160x128", 0);
277 WARNING(
"Setting default value for video size = %dx%d. "
278 "Use NoDefaults to disable it.\n",
286 WARNING(
"Setting default value for video bit rate tolerance = %d. "
287 "Use NoDefaults to disable it.\n",
293 av_dict_set(&recommended,
"rc_eq",
"tex^qComp", 0);
294 WARNING(
"Setting default value for video rate control equation = "
295 "%s. Use NoDefaults to disable it.\n",
301 WARNING(
"Setting default value for video max rate = %d. "
302 "Use NoDefaults to disable it.\n",
309 WARNING(
"Setting default value for video buffer size = %d. "
310 "Use NoDefaults to disable it.\n",
337 "Invalid codec name: '%s'\n", codec_name);
348 "Inconsistent configuration: trying to set '%s' "
349 "codec option, but '%s' codec is used previously\n",
357 char filename[1000],
tmp[1000], tmp2[1000],
line[1000];
381 int e= fscanf(f,
"%999[^\n]\n", line) - 1;
382 if(line[0] ==
'#' && !e)
384 e|= sscanf(line,
"%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
396 }
else if (!strcmp(tmp,
"scodec")) {
410 const char *filename,
411 const char *mime_type)
417 char stream_format_name[64];
419 snprintf(stream_format_name,
sizeof(stream_format_name),
"%s_stream",
431 int log_level,
int *errors,
const char *
fmt,
434 av_log(
NULL, log_level,
"%s:%d: ", filename, line_num);
441 int log_level,
int *errors,
442 const char *
fmt, ...)
452 const char *error_msg, ...)
456 if (!value || !value[0])
459 tmp = strtol(value, &tailp, 0);
460 if (tmp < min || tmp > max)
463 if (tmp == INT_MIN ||
FFABS(tmp) > INT_MAX /
FFABS(factor))
467 if (tailp[0] || errno)
475 va_start(vl, error_msg);
477 &config->
errors, error_msg, vl);
486 const char *error_msg, ...)
490 if (!value || !value[0])
493 tmp =
strtod(value, &tailp);
494 if (tmp < min || tmp > max)
498 if (tailp[0] || errno)
506 va_start(vl, error_msg);
508 &config->
errors, error_msg, vl);
517 static int hinted = 0;
522 const char *codec_name =
NULL;
545 if (strchr(opt,
':')) {
547 snprintf(buff,
sizeof(buff),
"%s", opt);
549 if(!(option = strchr(buff,
':'))){
552 "Syntax error. Unmatched ':'\n");
556 buff[option - buff] =
'\0';
569 (!strcmp(option,
"time_base") || !strcmp(option,
"pixel_format") ||
570 !strcmp(option,
"video_size") || !strcmp(option,
"codec_tag")))
574 &config->
errors,
"Option not found: '%s'\n", opt);
579 "option, then prefix it with codec name, for "
580 "example '%s:%s %s' or define codec earlier.\n",
586 &config->
errors,
"Invalid value for option %s (%s): %s\n", opt,
590 (arg[0] ==
'+' || arg[0] ==
'-'))
593 &config->
errors,
"Redeclaring value of option '%s'."
594 "Previous value was: '%s'.\n", opt, e->
value);
595 }
else if (
av_dict_set(dict, option, arg, 0) < 0) {
605 snprintf(buf,
sizeof(buf),
"%"PRId64, arg);
616 WARNING(
"Port option is deprecated. Use HTTPPort instead.\n");
619 "Invalid port: %s\n", arg);
621 WARNING(
"Trying to use IETF assigned system port: '%d'\n", val);
626 WARNING(
"BindAddress option is deprecated. Use HTTPBindAddress "
630 ERROR(
"Invalid host/IP address: '%s'\n", arg);
632 WARNING(
"NoDaemon option has no effect. You should remove it.\n");
636 "Invalid port: %s\n", arg);
641 ERROR(
"Invalid host/IP address: %s\n", arg);
645 "Invalid MaxHTTPConnections: %s\n", arg);
648 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
655 "Invalid MaxClients: '%s'\n", arg);
658 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
667 llval = strtoll(arg, &tailp, 10);
668 if (llval < 10 || llval > 10000000 || tailp[0] || errno)
669 ERROR(
"Invalid MaxBandwidth: '%s'\n", arg);
673 if (!config->
debug) {
678 ERROR(
"Loadable modules are no longer supported\n");
684 ERROR(
"Incorrect keyword: '%s'\n", cmd);
740 (config->
http_addr.sin_addr.s_addr == INADDR_ANY) ?
741 "127.0.0.1" : inet_ntoa(config->
http_addr.sin_addr),
758 WARNING(
"Truncate N syntax in configuration file is deprecated. "
759 "Use Truncate alone with no arguments.\n");
774 fsize *= 1024 * 1024;
777 fsize *= 1024 * 1024 * 1024;
780 ERROR(
"Invalid file size: '%s'\n", arg);
785 ERROR(
"Feed max file size is too small. Must be at least %d.\n",
791 ERROR(
"Invalid entry '%s' inside <Feed></Feed>\n", cmd);
800 char arg[1024], arg2[1024];
856 ERROR(
"Feed with name '%s' for stream '%s' is not defined\n", arg,
859 stream->
feed = sfeed;
862 if (!strcmp(arg,
"status")) {
868 if (!strcmp(arg,
"jpeg")) {
869 strcpy(arg,
"singlejpeg");
874 ERROR(
"Unknown Format: '%s'\n", arg);
884 ERROR(
"Unknown input format: '%s'\n", arg);
890 ERROR(
"FaviconURL only permitted for status streams\n");
898 for (i = 0; i < strlen(cmd); i++)
901 WARNING(
"Deprecated '%s' option in configuration file. Use "
902 "'Metadata %s VALUE' instead.\n", cmd, key);
923 stream->
max_time = atof(arg) * 1000;
928 "Invalid %s: '%s'\n", cmd, arg);
941 int minrate, maxrate;
944 dash = strchr(arg,
'-');
955 ERROR(
"Incorrect format for VideoBitRateRange. It should be "
956 "<min>-<max>: '%s'.\n", arg);
970 "Invalid %s: '%s'", cmd, arg);
976 "Invalid %s: '%s'", cmd, arg);
982 "Invalid %s: '%s'", cmd, arg);
990 ERROR(
"Invalid video size '%s'\n", arg);
993 WARNING(
"Image size is not a multiple of 2\n");
999 arg[0] =
'1'; arg[1] =
'/';
1007 ERROR(
"Unknown pixel format: '%s'\n", arg);
1046 if (strlen(arg) == 4 &&
1048 MKTAG(arg[0], arg[1], arg[2], arg[3]),
1063 "Invalid Qscale: '%s'\n", arg);
1104 ERROR(
"Invalid host/IP address: '%s'\n", arg);
1110 "Invalid MulticastPort: '%s'\n", arg);
1115 "Invalid MulticastTTL: '%s'\n", arg);
1121 if (stream->
feed && stream->
fmt && strcmp(stream->
fmt->
name,
"ffm")) {
1150 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1154 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1157 ERROR(
"Invalid entry '%s' inside <Stream></Stream>\n", cmd);
1170 const char *cmd,
const char **p,
1175 redirect = *predirect;
1184 q = strrchr(redirect->
filename,
'>');
1188 *predirect = redirect;
1197 ERROR(
"No URL found for <Redirect>\n");
1200 ERROR(
"Invalid entry '%s' inside <Redirect></Redirect>\n", cmd);
1217 f = fopen(filename,
"r");
1221 "Could not open the configuration file '%s'\n", filename);
1233 while (fgets(line,
sizeof(line), f) !=
NULL) {
1238 if (*p ==
'\0' || *p ==
'#')
1245 if (opening && (stream || feed || redirect)) {
1246 ERROR(
"Already in a tag\n");
1253 *last_stream = feed;
1255 last_stream = &feed->
next;
1261 if (opening && (stream || feed || redirect)) {
1262 ERROR(
"Already in a tag\n");
1269 *last_stream = stream;
1270 last_stream = &stream->
next;
1275 if (opening && (stream || feed || redirect))
1276 ERROR(
"Already in a tag\n");
1284 *last_stream = redirect;
1285 last_stream = &redirect->
next;
1292 if (stream || feed || redirect)
1293 ERROR(
"Missing closing </%s> tag\n",
1294 stream ?
"Stream" : (feed ?
"Feed" :
"Redirect"));
1314 args = *(
char ***)argsp;
const struct AVCodec * codec
int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
const char const char void * val
static enum AVPixelFormat pix_fmt
struct sockaddr_in http_addr
static void add_codec(FFServerStream *stream, AVCodecContext *av, FFServerConfig *config)
static void report_config_error(const char *filename, int line_num, int log_level, int *errors, const char *fmt,...)
AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
FFServerIPAddressACL * acl
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
static int ffserver_set_float_param(float *dest, const char *value, float factor, float min, float max, FFServerConfig *config, const char *error_msg,...)
unsigned int nb_max_connections
#define AV_LOG_WARNING
Something somehow does not look correct.
int64_t bit_rate
the average bitrate
static FFServerConfig config
#define AV_OPT_FLAG_AUDIO_PARAM
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int av_dict_get_string(const AVDictionary *m, char **buffer, const char key_val_sep, const char pairs_sep)
Get dictionary entries as a string.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
AVCodecContext * dummy_vctx
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
AVCodecContext * dummy_actx
struct FFServerStream * next
void ffserver_free_child_args(void *argsp)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int bit_rate_tolerance
number of bits the bitstream is allowed to diverge from the reference.
enum AVCodecID guessed_video_codec_id
attribute_deprecated const char * rc_eq
enum AVCodecID guessed_audio_codec_id
double strtod(const char *, char **)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
AVStream * streams[FFSERVER_MAX_STREAMS]
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
static av_const int av_tolower(int c)
Locale-independent conversion of ASCII characters to lowercase.
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
enum FFServerStreamType stream_type
static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFServerConfig *config)
simple assert() macros that are a bit more flexible than ISO C assert().
static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, const char **p, FFServerStream **pfeed)
const char * name
Name of the codec implementation.
int rc_buffer_size
decoder bitstream buffer size
char * av_asprintf(const char *fmt,...)
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd, const char **p)
struct FFServerStream * next_feed
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
int ff_inet_aton(const char *str, struct in_addr *add)
int width
picture width / height.
static int resolve_host(struct in_addr *sin_addr, const char *hostname)
GLsizei GLboolean const GLfloat * value
void ffserver_get_arg(char *buf, int buf_size, const char **pp)
struct FFServerIPAddressACL * next
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
AVDictionary * video_opts
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_DICT_APPEND
If the entry already exists, append to it.
static int ffserver_save_avoption_int(const char *opt, int64_t arg, int type, FFServerConfig *config)
AVOutputFormat * av_guess_format(const char *short_name, const char *filename, const char *mime_type)
Return the output format in the list of registered output formats which best matches the provided par...
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
#define FF_ARRAY_ELEMS(a)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
enum AVMediaType codec_type
static void vreport_config_error(const char *filename, int line_num, int log_level, int *errors, const char *fmt, va_list vl)
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer...
char * av_strdup(const char *s)
Duplicate the string s.
int sample_rate
samples per second
#define AV_OPT_FLAG_VIDEO_PARAM
main external API structure.
AVDictionary * audio_opts
struct sockaddr_in rtsp_addr
static int ffserver_opt_preset(const char *arg, int type, FFServerConfig *config)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
FILE * get_preset_file(char *filename, size_t filename_size, const char *preset_name, int is_path, const char *codec_name)
Get a file corresponding to a preset file.
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static const int factor[16]
FFServerStream * first_feed
static int ffserver_parse_config_redirect(FFServerConfig *config, const char *cmd, const char **p, FFServerStream **predirect)
static int ffserver_set_int_param(int *dest, const char *value, int factor, int min, int max, FFServerConfig *config, const char *error_msg,...)
struct FFServerStream * feed
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set that converts the value to a string and stores it...
struct addrinfo * ai_next
void ffserver_parse_acl_row(FFServerStream *stream, FFServerStream *feed, FFServerIPAddressACL *ext_acl, const char *p, const char *filename, int line_num)
static AVOutputFormat * ffserver_guess_format(const char *short_name, const char *filename, const char *mime_type)
int avcodec_get_context_defaults3(AVCodecContext *s, const AVCodec *codec)
int channels
number of audio channels
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
static int ffserver_save_avoption(const char *opt, const char *arg, int type, FFServerConfig *config)
static void * av_mallocz_array(size_t nmemb, size_t size)
struct in_addr multicast_ip
static int64_t fsize(FILE *f)
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
FFServerStream * first_stream
#define MKTAG(a, b, c, d)
struct sockaddr * ai_addr
AVPixelFormat
Pixel format.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
unsigned int nb_max_http_connections
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
enum FFServerIPAddressAction action
int64_t rc_max_rate
maximum bitrate
static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, const char **p, FFServerStream **pstream)