31 #define MAX_CHILD_ARGS 64
36 int log_level,
int *errors,
const char *
fmt,
39 int log_level,
int *errors,
const char *
fmt,
42 #define ERROR(...) report_config_error(config->filename, config->line_num,\
43 AV_LOG_ERROR, &config->errors, __VA_ARGS__)
44 #define WARNING(...) report_config_error(config->filename, config->line_num,\
45 AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
49 static int resolve_host(
struct in_addr *sin_addr,
const char *hostname)
62 for (cur = ai; cur; cur = cur->
ai_next) {
64 *sin_addr = ((
struct sockaddr_in *)cur->
ai_addr)->sin_addr;
73 hp = gethostbyname(hostname);
76 memcpy(sin_addr, hp->h_addr_list[0],
sizeof(
struct in_addr));
93 if (*p ==
'\"' || *p ==
'\'')
97 if (quote && *p == quote || !quote &&
av_isspace(*p))
99 if ((q - buf) < buf_size - 1)
105 if (quote && *p == quote)
112 const char *p,
const char *filename,
int line_num)
125 fprintf(stderr,
"%s:%d: ACL action '%s' should be ALLOW or DENY.\n",
126 filename, line_num, arg);
134 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
135 filename, line_num, arg);
146 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
147 filename, line_num, arg);
154 fprintf(stderr,
"Failed to allocate FFServerIPAddressACL\n");
164 naclp = &stream->
acl;
170 fprintf(stderr,
"%s:%d: ACL found not in <Stream> or <Feed>\n",
175 naclp = &(*naclp)->
next;
205 "Something is wrong, %d options are not set!\n",
214 "audio bit rate is not set\n");
218 "audio sample rate is not set\n");
224 "video size is not set\n");
240 WARNING(
"Setting default value for audio bit rate = %d. "
241 "Use NoDefaults to disable it.\n",
247 WARNING(
"Setting default value for audio sample rate = %d. "
248 "Use NoDefaults to disable it.\n",
254 WARNING(
"Setting default value for audio channel count = %d. "
255 "Use NoDefaults to disable it.\n",
263 WARNING(
"Setting default value for video bit rate = %d. "
264 "Use NoDefaults to disable it.\n",
271 WARNING(
"Setting default value for video frame rate = %d. "
272 "Use NoDefaults to disable it.\n",
278 av_dict_set(&recommended,
"video_size",
"160x128", 0);
279 WARNING(
"Setting default value for video size = %dx%d. "
280 "Use NoDefaults to disable it.\n",
288 WARNING(
"Setting default value for video bit rate tolerance = %d. "
289 "Use NoDefaults to disable it.\n",
294 av_dict_set(&recommended,
"rc_eq",
"tex^qComp", 0);
295 WARNING(
"Setting default value for video rate control equation = "
296 "tex^qComp. 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",
339 "Invalid codec name: '%s'\n", codec_name);
350 "Inconsistent configuration: trying to set '%s' "
351 "codec option, but '%s' codec is used previously\n",
359 char filename[1000],
tmp[1000], tmp2[1000],
line[1000];
383 int e= fscanf(f,
"%999[^\n]\n", line) - 1;
384 if(line[0] ==
'#' && !e)
386 e|= sscanf(line,
"%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
398 }
else if (!strcmp(tmp,
"scodec")) {
412 const char *filename,
413 const char *mime_type)
419 char stream_format_name[64];
421 snprintf(stream_format_name,
sizeof(stream_format_name),
"%s_stream",
433 int log_level,
int *errors,
const char *
fmt,
436 av_log(
NULL, log_level,
"%s:%d: ", filename, line_num);
443 int log_level,
int *errors,
444 const char *
fmt, ...)
454 const char *error_msg, ...)
458 if (!value || !value[0])
461 tmp = strtol(value, &tailp, 0);
462 if (tmp < min || tmp > max)
465 if (tmp == INT_MIN ||
FFABS(tmp) > INT_MAX /
FFABS(factor))
469 if (tailp[0] || errno)
477 va_start(vl, error_msg);
479 &config->
errors, error_msg, vl);
488 const char *error_msg, ...)
492 if (!value || !value[0])
495 tmp =
strtod(value, &tailp);
496 if (tmp < min || tmp > max)
500 if (tailp[0] || errno)
508 va_start(vl, error_msg);
510 &config->
errors, error_msg, vl);
519 static int hinted = 0;
524 const char *codec_name =
NULL;
547 if (strchr(opt,
':')) {
549 snprintf(buff,
sizeof(buff),
"%s", opt);
551 if(!(option = strchr(buff,
':'))){
554 "Syntax error. Unmatched ':'\n");
558 buff[option - buff] =
'\0';
571 (!strcmp(option,
"time_base") || !strcmp(option,
"pixel_format") ||
572 !strcmp(option,
"video_size") || !strcmp(option,
"codec_tag")))
576 &config->
errors,
"Option not found: '%s'\n", opt);
581 "option, then prefix it with codec name, for "
582 "example '%s:%s %s' or define codec earlier.\n",
588 &config->
errors,
"Invalid value for option %s (%s): %s\n", opt,
592 (arg[0] ==
'+' || arg[0] ==
'-'))
595 &config->
errors,
"Redeclaring value of option '%s'."
596 "Previous value was: '%s'.\n", opt, e->
value);
597 }
else if (
av_dict_set(dict, option, arg, 0) < 0) {
607 snprintf(buf,
sizeof(buf),
"%"PRId64, arg);
618 WARNING(
"Port option is deprecated. Use HTTPPort instead.\n");
621 "Invalid port: %s\n", arg);
623 WARNING(
"Trying to use IETF assigned system port: '%d'\n", val);
628 WARNING(
"BindAddress option is deprecated. Use HTTPBindAddress "
632 ERROR(
"Invalid host/IP address: '%s'\n", arg);
634 WARNING(
"NoDaemon option has no effect. You should remove it.\n");
638 "Invalid port: %s\n", arg);
643 ERROR(
"Invalid host/IP address: %s\n", arg);
647 "Invalid MaxHTTPConnections: %s\n", arg);
650 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
657 "Invalid MaxClients: '%s'\n", arg);
660 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
669 llval = strtoll(arg, &tailp, 10);
670 if (llval < 10 || llval > 10000000 || tailp[0] || errno)
671 ERROR(
"Invalid MaxBandwidth: '%s'\n", arg);
675 if (!config->
debug) {
680 ERROR(
"Loadable modules are no longer supported\n");
686 ERROR(
"Incorrect keyword: '%s'\n", cmd);
742 (config->
http_addr.sin_addr.s_addr == INADDR_ANY) ?
743 "127.0.0.1" : inet_ntoa(config->
http_addr.sin_addr),
760 WARNING(
"Truncate N syntax in configuration file is deprecated. "
761 "Use Truncate alone with no arguments.\n");
776 fsize *= 1024 * 1024;
779 fsize *= 1024 * 1024 * 1024;
782 ERROR(
"Invalid file size: '%s'\n", arg);
787 ERROR(
"Feed max file size is too small. Must be at least %d.\n",
793 ERROR(
"Invalid entry '%s' inside <Feed></Feed>\n", cmd);
802 char arg[1024], arg2[1024];
858 ERROR(
"Feed with name '%s' for stream '%s' is not defined\n", arg,
861 stream->
feed = sfeed;
864 if (!strcmp(arg,
"status")) {
870 if (!strcmp(arg,
"jpeg")) {
871 strcpy(arg,
"singlejpeg");
876 ERROR(
"Unknown Format: '%s'\n", arg);
886 ERROR(
"Unknown input format: '%s'\n", arg);
892 ERROR(
"FaviconURL only permitted for status streams\n");
900 for (i = 0; i < strlen(cmd); i++)
903 WARNING(
"Deprecated '%s' option in configuration file. Use "
904 "'Metadata %s VALUE' instead.\n", cmd, key);
925 stream->
max_time = atof(arg) * 1000;
930 "Invalid %s: '%s'\n", cmd, arg);
943 int minrate, maxrate;
946 dash = strchr(arg,
'-');
957 ERROR(
"Incorrect format for VideoBitRateRange. It should be "
958 "<min>-<max>: '%s'.\n", arg);
972 "Invalid %s: '%s'", cmd, arg);
978 "Invalid %s: '%s'", cmd, arg);
984 "Invalid %s: '%s'", cmd, arg);
992 ERROR(
"Invalid video size '%s'\n", arg);
995 WARNING(
"Image size is not a multiple of 2\n");
1001 arg[0] =
'1'; arg[1] =
'/';
1009 ERROR(
"Unknown pixel format: '%s'\n", arg);
1048 if (strlen(arg) == 4 &&
1050 MKTAG(arg[0], arg[1], arg[2], arg[3]),
1066 "Invalid Qscale: '%s'\n", arg);
1107 ERROR(
"Invalid host/IP address: '%s'\n", arg);
1113 "Invalid MulticastPort: '%s'\n", arg);
1118 "Invalid MulticastTTL: '%s'\n", arg);
1124 if (stream->
feed && stream->
fmt && strcmp(stream->
fmt->
name,
"ffm")) {
1153 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1157 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1160 ERROR(
"Invalid entry '%s' inside <Stream></Stream>\n", cmd);
1173 const char *cmd,
const char **p,
1178 redirect = *predirect;
1187 q = strrchr(redirect->
filename,
'>');
1191 *predirect = redirect;
1200 ERROR(
"No URL found for <Redirect>\n");
1203 ERROR(
"Invalid entry '%s' inside <Redirect></Redirect>\n", cmd);
1220 f = fopen(filename,
"r");
1224 "Could not open the configuration file '%s'\n", filename);
1236 while (fgets(line,
sizeof(line), f) !=
NULL) {
1241 if (*p ==
'\0' || *p ==
'#')
1248 if (opening && (stream || feed || redirect)) {
1249 ERROR(
"Already in a tag\n");
1256 *last_stream = feed;
1258 last_stream = &feed->
next;
1264 if (opening && (stream || feed || redirect)) {
1265 ERROR(
"Already in a tag\n");
1272 *last_stream = stream;
1273 last_stream = &stream->
next;
1278 if (opening && (stream || feed || redirect))
1279 ERROR(
"Already in a tag\n");
1287 *last_stream = redirect;
1288 last_stream = &redirect->
next;
1295 if (stream || feed || redirect)
1296 ERROR(
"Missing closing </%s> tag\n",
1297 stream ?
"Stream" : (feed ?
"Feed" :
"Redirect"));
1317 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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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
enum AVCodecID guessed_audio_codec_id
AVCodecParameters * codecpar
AVCodecParameters * avcodec_parameters_alloc(void)
Allocate a new AVCodecParameters and set its fields to default values (unknown/invalid/0).
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.
#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.
static void error(const char *err)
#define FF_ARRAY_ELEMS(a)
const char * avcodec_get_name(enum AVCodecID id)
Get the name of a codec.
char * av_strdup(const char *s)
Duplicate a string.
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...
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.
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
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...
This holds the stream parameters for an AVStream, it cannot be a AVStream because AVStreams cannot be...
LayeredAVStream * streams[FFSERVER_MAX_STREAMS]
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)
char * recommended_encoder_configuration
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)
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
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)
void * av_mallocz_array(size_t nmemb, size_t size)