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",
295 av_dict_set(&recommended,
"rc_eq",
"tex^qComp", 0);
296 WARNING(
"Setting default value for video rate control equation = "
297 "%s. Use NoDefaults to disable it.\n",
303 WARNING(
"Setting default value for video max rate = %d. "
304 "Use NoDefaults to disable it.\n",
311 WARNING(
"Setting default value for video buffer size = %d. "
312 "Use NoDefaults to disable it.\n",
341 "Invalid codec name: '%s'\n", codec_name);
352 "Inconsistent configuration: trying to set '%s' "
353 "codec option, but '%s' codec is used previously\n",
361 char filename[1000],
tmp[1000], tmp2[1000],
line[1000];
385 int e= fscanf(f,
"%999[^\n]\n", line) - 1;
386 if(line[0] ==
'#' && !e)
388 e|= sscanf(line,
"%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
400 }
else if (!strcmp(tmp,
"scodec")) {
414 const char *filename,
415 const char *mime_type)
421 char stream_format_name[64];
423 snprintf(stream_format_name,
sizeof(stream_format_name),
"%s_stream",
435 int log_level,
int *errors,
const char *
fmt,
438 av_log(
NULL, log_level,
"%s:%d: ", filename, line_num);
445 int log_level,
int *errors,
446 const char *
fmt, ...)
456 const char *error_msg, ...)
460 if (!value || !value[0])
463 tmp = strtol(value, &tailp, 0);
464 if (tmp < min || tmp > max)
467 if (tmp == INT_MIN ||
FFABS(tmp) > INT_MAX /
FFABS(factor))
471 if (tailp[0] || errno)
479 va_start(vl, error_msg);
481 &config->
errors, error_msg, vl);
490 const char *error_msg, ...)
494 if (!value || !value[0])
497 tmp =
strtod(value, &tailp);
498 if (tmp < min || tmp > max)
502 if (tailp[0] || errno)
510 va_start(vl, error_msg);
512 &config->
errors, error_msg, vl);
521 static int hinted = 0;
526 const char *codec_name =
NULL;
549 if (strchr(opt,
':')) {
551 snprintf(buff,
sizeof(buff),
"%s", opt);
553 if(!(option = strchr(buff,
':'))){
556 "Syntax error. Unmatched ':'\n");
560 buff[option - buff] =
'\0';
573 (!strcmp(option,
"time_base") || !strcmp(option,
"pixel_format") ||
574 !strcmp(option,
"video_size") || !strcmp(option,
"codec_tag")))
578 &config->
errors,
"Option not found: '%s'\n", opt);
583 "option, then prefix it with codec name, for "
584 "example '%s:%s %s' or define codec earlier.\n",
590 &config->
errors,
"Invalid value for option %s (%s): %s\n", opt,
594 (arg[0] ==
'+' || arg[0] ==
'-'))
597 &config->
errors,
"Redeclaring value of option '%s'."
598 "Previous value was: '%s'.\n", opt, e->
value);
599 }
else if (
av_dict_set(dict, option, arg, 0) < 0) {
609 snprintf(buf,
sizeof(buf),
"%"PRId64, arg);
620 WARNING(
"Port option is deprecated. Use HTTPPort instead.\n");
623 "Invalid port: %s\n", arg);
625 WARNING(
"Trying to use IETF assigned system port: '%d'\n", val);
630 WARNING(
"BindAddress option is deprecated. Use HTTPBindAddress "
634 ERROR(
"Invalid host/IP address: '%s'\n", arg);
636 WARNING(
"NoDaemon option has no effect. You should remove it.\n");
640 "Invalid port: %s\n", arg);
645 ERROR(
"Invalid host/IP address: %s\n", arg);
649 "Invalid MaxHTTPConnections: %s\n", arg);
652 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
659 "Invalid MaxClients: '%s'\n", arg);
662 ERROR(
"Inconsistent configuration: MaxClients(%d) > "
671 llval = strtoll(arg, &tailp, 10);
672 if (llval < 10 || llval > 10000000 || tailp[0] || errno)
673 ERROR(
"Invalid MaxBandwidth: '%s'\n", arg);
677 if (!config->
debug) {
682 ERROR(
"Loadable modules are no longer supported\n");
688 ERROR(
"Incorrect keyword: '%s'\n", cmd);
744 (config->
http_addr.sin_addr.s_addr == INADDR_ANY) ?
745 "127.0.0.1" : inet_ntoa(config->
http_addr.sin_addr),
762 WARNING(
"Truncate N syntax in configuration file is deprecated. "
763 "Use Truncate alone with no arguments.\n");
778 fsize *= 1024 * 1024;
781 fsize *= 1024 * 1024 * 1024;
784 ERROR(
"Invalid file size: '%s'\n", arg);
789 ERROR(
"Feed max file size is too small. Must be at least %d.\n",
795 ERROR(
"Invalid entry '%s' inside <Feed></Feed>\n", cmd);
804 char arg[1024], arg2[1024];
860 ERROR(
"Feed with name '%s' for stream '%s' is not defined\n", arg,
863 stream->
feed = sfeed;
866 if (!strcmp(arg,
"status")) {
872 if (!strcmp(arg,
"jpeg")) {
873 strcpy(arg,
"singlejpeg");
878 ERROR(
"Unknown Format: '%s'\n", arg);
888 ERROR(
"Unknown input format: '%s'\n", arg);
894 ERROR(
"FaviconURL only permitted for status streams\n");
902 for (i = 0; i < strlen(cmd); i++)
905 WARNING(
"Deprecated '%s' option in configuration file. Use "
906 "'Metadata %s VALUE' instead.\n", cmd, key);
927 stream->
max_time = atof(arg) * 1000;
932 "Invalid %s: '%s'\n", cmd, arg);
945 int minrate, maxrate;
948 dash = strchr(arg,
'-');
959 ERROR(
"Incorrect format for VideoBitRateRange. It should be "
960 "<min>-<max>: '%s'.\n", arg);
974 "Invalid %s: '%s'", cmd, arg);
980 "Invalid %s: '%s'", cmd, arg);
986 "Invalid %s: '%s'", cmd, arg);
994 ERROR(
"Invalid video size '%s'\n", arg);
997 WARNING(
"Image size is not a multiple of 2\n");
1003 arg[0] =
'1'; arg[1] =
'/';
1011 ERROR(
"Unknown pixel format: '%s'\n", arg);
1050 if (strlen(arg) == 4 &&
1052 MKTAG(arg[0], arg[1], arg[2], arg[3]),
1068 "Invalid Qscale: '%s'\n", arg);
1109 ERROR(
"Invalid host/IP address: '%s'\n", arg);
1115 "Invalid MulticastPort: '%s'\n", arg);
1120 "Invalid MulticastTTL: '%s'\n", arg);
1126 if (stream->
feed && stream->
fmt && strcmp(stream->
fmt->
name,
"ffm")) {
1155 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1159 WARNING(
"Multiple UseDefaults/NoDefaults entries.\n");
1162 ERROR(
"Invalid entry '%s' inside <Stream></Stream>\n", cmd);
1175 const char *cmd,
const char **p,
1180 redirect = *predirect;
1189 q = strrchr(redirect->
filename,
'>');
1193 *predirect = redirect;
1202 ERROR(
"No URL found for <Redirect>\n");
1205 ERROR(
"Invalid entry '%s' inside <Redirect></Redirect>\n", cmd);
1222 f = fopen(filename,
"r");
1226 "Could not open the configuration file '%s'\n", filename);
1238 while (fgets(line,
sizeof(line), f) !=
NULL) {
1243 if (*p ==
'\0' || *p ==
'#')
1250 if (opening && (stream || feed || redirect)) {
1251 ERROR(
"Already in a tag\n");
1258 *last_stream = feed;
1260 last_stream = &feed->
next;
1266 if (opening && (stream || feed || redirect)) {
1267 ERROR(
"Already in a tag\n");
1274 *last_stream = stream;
1275 last_stream = &stream->
next;
1280 if (opening && (stream || feed || redirect))
1281 ERROR(
"Already in a tag\n");
1289 *last_stream = redirect;
1290 last_stream = &redirect->
next;
1297 if (stream || feed || redirect)
1298 ERROR(
"Missing closing </%s> tag\n",
1299 stream ?
"Stream" : (feed ?
"Feed" :
"Redirect"));
1319 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
attribute_deprecated const char * rc_eq
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.
static void * av_mallocz_array(size_t nmemb, size_t size)
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)