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)
127 fprintf(stderr,
"%s:%d: ACL action '%s' should be ALLOW or DENY.\n",
128 filename, line_num, arg);
136 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
137 filename, line_num, arg);
147 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
148 filename, line_num, arg);
161 naclp = &stream->
acl;
167 fprintf(stderr,
"%s:%d: ACL found not in <Stream> or <Feed>\n",
174 naclp = &(*naclp)->
next;
201 "Something is wrong, %d options are not set!\n",
210 "audio bit rate is not set\n");
214 "audio sample rate is not set\n");
220 "video size is not set\n");
236 WARNING(
"Setting default value for audio bit rate = %d. "
237 "Use NoDefaults to disable it.\n",
243 WARNING(
"Setting default value for audio sample rate = %d. "
244 "Use NoDefaults to disable it.\n",
250 WARNING(
"Setting default value for audio channel count = %d. "
251 "Use NoDefaults to disable it.\n",
259 WARNING(
"Setting default value for video bit rate = %d. "
260 "Use NoDefaults to disable it.\n",
267 WARNING(
"Setting default value for video frame rate = %d. "
268 "Use NoDefaults to disable it.\n",
274 av_dict_set(&recommended,
"video_size",
"160x128", 0);
275 WARNING(
"Setting default value for video size = %dx%d. "
276 "Use NoDefaults to disable it.\n",
284 WARNING(
"Setting default value for video bit rate tolerance = %d. "
285 "Use NoDefaults to disable it.\n",
291 av_dict_set(&recommended,
"rc_eq",
"tex^qComp", 0);
292 WARNING(
"Setting default value for video rate control equation = "
293 "%s. Use NoDefaults to disable it.\n",
299 WARNING(
"Setting default value for video max rate = %d. "
300 "Use NoDefaults to disable it.\n",
307 WARNING(
"Setting default value for video buffer size = %d. "
308 "Use NoDefaults to disable it.\n",
335 "Invalid codec name: '%s'\n", codec_name);
346 "Inconsistent configuration: trying to set '%s' "
347 "codec option, but '%s' codec is used previously\n",
355 char filename[1000], tmp[1000], tmp2[1000],
line[1000];
379 int e= fscanf(f,
"%999[^\n]\n", line) - 1;
380 if(line[0] ==
'#' && !e)
382 e|= sscanf(line,
"%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
394 }
else if (!strcmp(tmp,
"scodec")) {
408 const char *filename,
409 const char *mime_type)
415 char stream_format_name[64];
417 snprintf(stream_format_name,
sizeof(stream_format_name),
"%s_stream",
429 int log_level,
int *errors,
const char *
fmt,
432 av_log(
NULL, log_level,
"%s:%d: ", filename, line_num);
439 int log_level,
int *errors,
440 const char *
fmt, ...)
450 const char *error_msg, ...)
454 if (!value || !value[0])
457 tmp = strtol(value, &tailp, 0);
458 if (tmp < min || tmp > max)
465 if (tailp[0] || errno)
473 va_start(vl, error_msg);
475 &config->
errors, error_msg, vl);
484 const char *error_msg, ...)
488 if (!value || !value[0])
491 tmp =
strtod(value, &tailp);
492 if (tmp < min || tmp > max)
496 if (tailp[0] || errno)
504 va_start(vl, error_msg);
506 &config->
errors, error_msg, vl);
515 static int hinted = 0;
520 const char *codec_name =
NULL;
543 if (strchr(opt,
':')) {
545 snprintf(buff,
sizeof(buff),
"%s", opt);
547 if(!(option = strchr(buff,
':'))){
550 "Syntax error. Unmatched ':'\n");
554 buff[option - buff] =
'\0';
567 (!strcmp(option,
"time_base") || !strcmp(option,
"pixel_format") ||
568 !strcmp(option,
"video_size") || !strcmp(option,
"codec_tag")))
572 &config->
errors,
"Option not found: '%s'\n", opt);
577 "option, then prefix it with codec name, for "
578 "example '%s:%s %s' or define codec earlier.\n",
584 &config->
errors,
"Invalid value for option %s (%s): %s\n", opt,
588 (arg[0] ==
'+' || arg[0] ==
'-'))
591 &config->
errors,
"Redeclaring value of option '%s'."
592 "Previous value was: '%s'.\n", opt, e->
value);
593 }
else if (
av_dict_set(dict, option, arg, 0) < 0) {
603 snprintf(buf,
sizeof(buf),
"%"PRId64, arg);
614 WARNING(
"Port option is deprecated. Use HTTPPort instead.\n");
617 "Invalid port: %s\n", arg);
619 WARNING(
"Trying to use IETF assigned system port: '%d'\n", val);
624 WARNING(
"BindAddress option is deprecated. Use HTTPBindAddress "
628 ERROR(
"Invalid host/IP address: '%s'\n", arg);
630 WARNING(
"NoDaemon option has no effect. You should remove it.\n");
634 "Invalid port: %s\n", arg);
639 ERROR(
"Invalid host/IP address: %s\n", arg);
643 "Invalid MaxHTTPConnections: %s\n", arg);
646 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
653 "Invalid MaxClients: '%s'\n", arg);
656 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
665 llval = strtoll(arg, &tailp, 10);
666 if (llval < 10 || llval > 10000000 || tailp[0] || errno)
667 ERROR(
"Invalid MaxBandwidth: '%s'\n", arg);
671 if (!config->
debug) {
676 ERROR(
"Loadable modules are no longer supported\n");
682 ERROR(
"Incorrect keyword: '%s'\n", cmd);
738 (config->
http_addr.sin_addr.s_addr == INADDR_ANY) ?
739 "127.0.0.1" : inet_ntoa(config->
http_addr.sin_addr),
756 WARNING(
"Truncate N syntax in configuration file is deprecated. "
757 "Use Truncate alone with no arguments.\n");
772 fsize *= 1024 * 1024;
775 fsize *= 1024 * 1024 * 1024;
778 ERROR(
"Invalid file size: '%s'\n", arg);
783 ERROR(
"Feed max file size is too small. Must be at least %d.\n",
789 ERROR(
"Invalid entry '%s' inside <Feed></Feed>\n", cmd);
797 char arg[1024], arg2[1024];
853 ERROR(
"Feed with name '%s' for stream '%s' is not defined\n", arg,
856 stream->
feed = sfeed;
859 if (!strcmp(arg,
"status")) {
865 if (!strcmp(arg,
"jpeg")) {
866 strcpy(arg,
"singlejpeg");
871 ERROR(
"Unknown Format: '%s'\n", arg);
881 ERROR(
"Unknown input format: '%s'\n", arg);
887 ERROR(
"FaviconURL only permitted for status streams\n");
895 for (i = 0; i < strlen(cmd); i++)
898 WARNING(
"Deprecated '%s' option in configuration file. Use "
899 "'Metadata %s VALUE' instead.\n", cmd, key);
920 stream->
max_time = atof(arg) * 1000;
925 "Invalid %s: '%s'\n", cmd, arg);
938 int minrate, maxrate;
941 dash = strchr(arg,
'-');
952 ERROR(
"Incorrect format for VideoBitRateRange. It should be "
953 "<min>-<max>: '%s'.\n", arg);
967 "Invalid %s: '%s'", cmd, arg);
973 "Invalid %s: '%s'", cmd, arg);
979 "Invalid %s: '%s'", cmd, arg);
987 ERROR(
"Invalid video size '%s'\n", arg);
990 WARNING(
"Image size is not a multiple of 2\n");
996 arg[0] =
'1'; arg[1] =
'/';
1004 ERROR(
"Unknown pixel format: '%s'\n", arg);
1043 if (strlen(arg) == 4 &&
1045 MKTAG(arg[0], arg[1], arg[2], arg[3]),
1060 "Invalid Qscale: '%s'\n", arg);
1101 ERROR(
"Invalid host/IP address: '%s'\n", arg);
1107 "Invalid MulticastPort: '%s'\n", arg);
1112 "Invalid MulticastTTL: '%s'\n", arg);
1118 if (stream->
feed && stream->
fmt && strcmp(stream->
fmt->
name,
"ffm")) {
1145 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1149 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1152 ERROR(
"Invalid entry '%s' inside <Stream></Stream>\n", cmd);
1165 const char *cmd,
const char **p,
1170 redirect = *predirect;
1179 q = strrchr(redirect->
filename,
'>');
1183 *predirect = redirect;
1192 ERROR(
"No URL found for <Redirect>\n");
1195 ERROR(
"Invalid entry '%s' inside <Redirect></Redirect>\n", cmd);
1212 f = fopen(filename,
"r");
1216 "Could not open the configuration file '%s'\n", filename);
1228 while (fgets(line,
sizeof(line), f) !=
NULL) {
1233 if (*p ==
'\0' || *p ==
'#')
1240 if (opening && (stream || feed || redirect)) {
1241 ERROR(
"Already in a tag\n");
1248 *last_stream = feed;
1250 last_stream = &feed->
next;
1256 if (opening && (stream || feed || redirect)) {
1257 ERROR(
"Already in a tag\n");
1264 *last_stream = stream;
1265 last_stream = &stream->
next;
1270 if (opening && (stream || feed || redirect))
1271 ERROR(
"Already in a tag\n");
1279 *last_stream = redirect;
1280 last_stream = &redirect->
next;
1287 if (stream || feed || redirect)
1288 ERROR(
"Missing closing </%s> tag\n",
1289 stream ?
"Stream" : (feed ?
"Feed" :
"Redirect"));
1309 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.
static FFServerConfig config
#define AV_OPT_FLAG_AUDIO_PARAM
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
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.
#define FF_ARRAY_ELEMS(a)
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
int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
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.
void av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
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
int rc_max_rate
maximum bitrate
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.
AVCodecContext * codec
Codec context associated with this stream.
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)
int bit_rate
the average bitrate
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 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.
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)
Set the fields of the given AVCodecContext to default values corresponding to the given codec (defaul...
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
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
static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, const char **p, FFServerStream **pstream)