2 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "libavutil/opt.h"
23 #include "libavutil/parseutils.h"
24 #include "libavutil/avstring.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/avassert.h"
28 // FIXME those are internal headers, ffserver _really_ shouldn't use them
29 #include "libavformat/ffm.h"
32 #include "ffserver_config.h"
34 static int ffserver_save_avoption(AVCodecContext *ctx, const char *opt, const char *arg,
35 AVDictionary **dict, int type, FFServerConfig *config, int line_num);
36 static void vreport_config_error(const char *filename, int line_num, int log_level,
37 int *errors, const char *fmt, va_list vl);
38 static void report_config_error(const char *filename, int line_num, int log_level,
39 int *errors, const char *fmt, ...);
41 /* FIXME: make ffserver work with IPv6 */
42 /* resolve host with also IP address parsing */
43 static int resolve_host(struct in_addr *sin_addr, const char *hostname)
46 if (!ff_inet_aton(hostname, sin_addr)) {
48 struct addrinfo *ai, *cur;
49 struct addrinfo hints = { 0 };
50 hints.ai_family = AF_INET;
51 if (getaddrinfo(hostname, NULL, &hints, &ai))
53 /* getaddrinfo returns a linked list of addrinfo structs.
54 * Even if we set ai_family = AF_INET above, make sure
55 * that the returned one actually is of the correct type. */
56 for (cur = ai; cur; cur = cur->ai_next) {
57 if (cur->ai_family == AF_INET) {
58 *sin_addr = ((struct sockaddr_in *)cur->ai_addr)->sin_addr;
67 hp = gethostbyname(hostname);
70 memcpy(sin_addr, hp->h_addr_list[0], sizeof(struct in_addr));
76 void ffserver_get_arg(char *buf, int buf_size, const char **pp)
83 while (av_isspace(*p)) p++;
86 if (*p == '\"' || *p == '\'')
98 if ((q - buf) < buf_size - 1)
103 if (quote && *p == quote)
108 void ffserver_parse_acl_row(FFServerStream *stream, FFServerStream* feed,
109 FFServerIPAddressACL *ext_acl,
110 const char *p, const char *filename, int line_num)
113 FFServerIPAddressACL acl;
116 ffserver_get_arg(arg, sizeof(arg), &p);
117 if (av_strcasecmp(arg, "allow") == 0)
118 acl.action = IP_ALLOW;
119 else if (av_strcasecmp(arg, "deny") == 0)
120 acl.action = IP_DENY;
122 fprintf(stderr, "%s:%d: ACL action '%s' is not ALLOW or DENY\n",
123 filename, line_num, arg);
127 ffserver_get_arg(arg, sizeof(arg), &p);
129 if (resolve_host(&acl.first, arg)) {
130 fprintf(stderr, "%s:%d: ACL refers to invalid host or IP address '%s'\n",
131 filename, line_num, arg);
134 acl.last = acl.first;
136 ffserver_get_arg(arg, sizeof(arg), &p);
139 if (resolve_host(&acl.last, arg)) {
141 "%s:%d: ACL refers to invalid host or IP address '%s'\n",
142 filename, line_num, arg);
148 FFServerIPAddressACL *nacl = av_mallocz(sizeof(*nacl));
149 FFServerIPAddressACL **naclp = 0;
155 naclp = &stream->acl;
161 fprintf(stderr, "%s:%d: ACL found not in <stream> or <feed>\n",
168 naclp = &(*naclp)->next;
176 /* add a codec and set the default parameters */
177 static void add_codec(FFServerStream *stream, AVCodecContext *av)
181 if(stream->nb_streams >= FF_ARRAY_ELEMS(stream->streams))
184 /* compute default parameters */
185 switch(av->codec_type) {
186 case AVMEDIA_TYPE_AUDIO:
187 if (av->bit_rate == 0)
188 av->bit_rate = 64000;
189 if (av->sample_rate == 0)
190 av->sample_rate = 22050;
191 if (av->channels == 0)
194 case AVMEDIA_TYPE_VIDEO:
195 if (av->bit_rate == 0)
196 av->bit_rate = 64000;
197 if (av->time_base.num == 0){
198 av->time_base.den = 5;
199 av->time_base.num = 1;
201 if (av->width == 0 || av->height == 0) {
205 /* Bitrate tolerance is less for streaming */
206 if (av->bit_rate_tolerance == 0)
207 av->bit_rate_tolerance = FFMAX(av->bit_rate / 4,
208 (int64_t)av->bit_rate*av->time_base.num/av->time_base.den);
213 if (av->max_qdiff == 0)
218 if (!av->nsse_weight)
221 av->frame_skip_cmp = FF_CMP_DCTMAX;
223 av->me_method = ME_EPZS;
225 /* FIXME: rc_buffer_aggressivity and rc_eq are deprecated */
226 av->rc_buffer_aggressivity = 1.0;
229 av->rc_eq = av_strdup("tex^qComp");
230 if (!av->i_quant_factor)
231 av->i_quant_factor = -0.8;
232 if (!av->b_quant_factor)
233 av->b_quant_factor = 1.25;
234 if (!av->b_quant_offset)
235 av->b_quant_offset = 1.25;
236 if (!av->rc_max_rate)
237 av->rc_max_rate = av->bit_rate * 2;
239 if (av->rc_max_rate && !av->rc_buffer_size) {
240 av->rc_buffer_size = av->rc_max_rate;
249 st = av_mallocz(sizeof(AVStream));
253 stream->streams[stream->nb_streams++] = st;
256 static int ffserver_set_codec(AVCodecContext *ctx, const char *codec_name, FFServerConfig *config, int line_num)
259 AVCodec *codec = avcodec_find_encoder_by_name(codec_name);
260 if (!codec || codec->type != ctx->codec_type) {
261 report_config_error(config->filename, line_num, AV_LOG_ERROR,
262 &config->errors, "Invalid codec name: %s\n", codec_name);
265 if (ctx->codec_id == AV_CODEC_ID_NONE && !ctx->priv_data) {
266 if ((ret = avcodec_get_context_defaults3(ctx, codec)) < 0)
270 if (ctx->codec_id != codec->id)
271 report_config_error(config->filename, line_num, AV_LOG_ERROR, &config->errors,
272 "Inconsistent configuration: trying to set %s codec option, but %s codec is used previously\n",
273 codec_name, avcodec_get_name(ctx->codec_id));
277 static int ffserver_opt_preset(const char *arg, AVCodecContext *avctx, FFServerConfig *config, int line_num)
280 char filename[1000], tmp[1000], tmp2[1000], line[1000];
282 AVCodec *codec = avcodec_find_encoder(avctx->codec_id);
284 if (!(f = get_preset_file(filename, sizeof(filename), arg, 0,
285 codec ? codec->name : NULL))) {
286 av_log(NULL, AV_LOG_ERROR, "File for preset '%s' not found\n", arg);
287 return AVERROR(EINVAL);
291 int e= fscanf(f, "%999[^\n]\n", line) - 1;
292 if(line[0] == '#' && !e)
294 e|= sscanf(line, "%999[^=]=%999[^\n]\n", tmp, tmp2) - 2;
296 av_log(NULL, AV_LOG_ERROR, "%s: Invalid syntax: '%s'\n", filename, line);
297 ret = AVERROR(EINVAL);
300 if ((!strcmp(tmp, "acodec") && avctx->codec_type == AVMEDIA_TYPE_AUDIO) ||
301 !strcmp(tmp, "vcodec") && avctx->codec_type == AVMEDIA_TYPE_VIDEO)
303 if (ffserver_set_codec(avctx, tmp2, config, line_num) < 0)
305 } else if (!strcmp(tmp, "scodec")) {
306 av_log(NULL, AV_LOG_ERROR, "Subtitles preset found.\n");
307 ret = AVERROR(EINVAL);
313 switch(avctx->codec_type) {
314 case AVMEDIA_TYPE_AUDIO:
315 type = AV_OPT_FLAG_AUDIO_PARAM;
316 opts = &config->audio_opts;
318 case AVMEDIA_TYPE_VIDEO:
319 type = AV_OPT_FLAG_VIDEO_PARAM;
320 opts = &config->video_opts;
323 ret = AVERROR(EINVAL);
326 if (ffserver_save_avoption(avctx, tmp, tmp2, opts, type, config, line_num) < 0)
337 static AVOutputFormat *ffserver_guess_format(const char *short_name, const char *filename, const char *mime_type)
339 AVOutputFormat *fmt = av_guess_format(short_name, filename, mime_type);
342 AVOutputFormat *stream_fmt;
343 char stream_format_name[64];
345 snprintf(stream_format_name, sizeof(stream_format_name), "%s_stream",
347 stream_fmt = av_guess_format(stream_format_name, NULL, NULL);
356 static void vreport_config_error(const char *filename, int line_num, int log_level, int *errors, const char *fmt, va_list vl)
358 av_log(NULL, log_level, "%s:%d: ", filename, line_num);
359 av_vlog(NULL, log_level, fmt, vl);
364 static void report_config_error(const char *filename, int line_num, int log_level, int *errors, const char *fmt, ...)
368 vreport_config_error(filename, line_num, log_level, errors, fmt, vl);
372 static int ffserver_set_int_param(int *dest, const char *value, int factor, int min, int max,
373 FFServerConfig *config, int line_num, const char *error_msg, ...)
377 if (!value || !value[0])
380 tmp = strtol(value, &tailp, 0);
381 if (tmp < min || tmp > max)
384 if (FFABS(tmp) > INT_MAX / FFABS(factor))
388 if (tailp[0] || errno)
396 va_start(vl, error_msg);
397 vreport_config_error(config->filename, line_num, AV_LOG_ERROR,
398 &config->errors, error_msg, vl);
401 return AVERROR(EINVAL);
404 static int ffserver_set_float_param(float *dest, const char *value, float factor, float min, float max,
405 FFServerConfig *config, int line_num, const char *error_msg, ...)
409 if (!value || !value[0])
412 tmp = strtod(value, &tailp);
413 if (tmp < min || tmp > max)
417 if (tailp[0] || errno)
425 va_start(vl, error_msg);
426 vreport_config_error(config->filename, line_num, AV_LOG_ERROR,
427 &config->errors, error_msg, vl);
430 return AVERROR(EINVAL);
433 static int ffserver_save_avoption(AVCodecContext *ctx, const char *opt, const char *arg, AVDictionary **dict,
434 int type, FFServerConfig *config, int line_num)
436 static int hinted = 0;
438 AVDictionaryEntry *e;
439 const AVOption *o = NULL;
440 const char *option = NULL;
441 const char *codec_name = NULL;
444 if (strchr(opt, ':')) {
445 //explicit private option
446 snprintf(buff, sizeof(buff), "%s", opt);
448 option = strchr(buff, ':');
449 buff[option - buff] = '\0';
451 if ((ret = ffserver_set_codec(ctx, codec_name, config, line_num)) < 0)
453 if (!ctx->codec || !ctx->priv_data)
459 o = av_opt_find(ctx, option, NULL, type | AV_OPT_FLAG_ENCODING_PARAM, AV_OPT_SEARCH_CHILDREN);
461 report_config_error(config->filename, line_num, AV_LOG_ERROR,
462 &config->errors, "Option not found: %s\n", opt);
463 if (!hinted && ctx->codec_id == AV_CODEC_ID_NONE) {
466 switch(ctx->codec_type) {
467 case AVMEDIA_TYPE_AUDIO:
468 id = config->guessed_audio_codec_id != AV_CODEC_ID_NONE ? config->guessed_audio_codec_id : AV_CODEC_ID_AAC;
470 case AVMEDIA_TYPE_VIDEO:
471 id = config->guessed_video_codec_id != AV_CODEC_ID_NONE ? config->guessed_video_codec_id : AV_CODEC_ID_H264;
476 report_config_error(config->filename, line_num, AV_LOG_ERROR, NULL,
477 "If '%s' is a codec private option, then prefix it with codec name, "
478 "for example '%s:%s %s' or define codec earlier.\n",
479 opt, avcodec_get_name(id) ,opt, arg);
482 } else if ((ret = av_opt_set(ctx, option, arg, AV_OPT_SEARCH_CHILDREN)) < 0) {
483 report_config_error(config->filename, line_num, AV_LOG_ERROR,
484 &config->errors, "Invalid value for option %s (%s): %s\n", opt,
485 arg, av_err2str(ret));
486 } else if ((e = av_dict_get(*dict, option, NULL, 0))) {
487 if ((o->type == AV_OPT_TYPE_FLAGS) && arg && (arg[0] == '+' || arg[0] == '-'))
488 return av_dict_set(dict, option, arg, AV_DICT_APPEND);
489 report_config_error(config->filename, line_num, AV_LOG_ERROR,
491 "Redeclaring value of the option %s, previous value: %s\n",
493 } else if (av_dict_set(dict, option, arg, 0) < 0) {
494 return AVERROR(ENOMEM);
499 #define ERROR(...) report_config_error(config->filename, line_num, AV_LOG_ERROR, &config->errors, __VA_ARGS__)
500 #define WARNING(...) report_config_error(config->filename, line_num, AV_LOG_WARNING, &config->warnings, __VA_ARGS__)
502 static int ffserver_parse_config_global(FFServerConfig *config, const char *cmd,
503 const char **p, int line_num)
507 if (!av_strcasecmp(cmd, "Port") || !av_strcasecmp(cmd, "HTTPPort")) {
508 if (!av_strcasecmp(cmd, "Port"))
509 WARNING("Port option is deprecated, use HTTPPort instead\n");
510 ffserver_get_arg(arg, sizeof(arg), p);
511 ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num,
512 "Invalid port: %s\n", arg);
514 WARNING("Trying to use IETF assigned system port: %d\n", val);
515 config->http_addr.sin_port = htons(val);
516 } else if (!av_strcasecmp(cmd, "HTTPBindAddress") || !av_strcasecmp(cmd, "BindAddress")) {
517 if (!av_strcasecmp(cmd, "BindAddress"))
518 WARNING("BindAddress option is deprecated, use HTTPBindAddress instead\n");
519 ffserver_get_arg(arg, sizeof(arg), p);
520 if (resolve_host(&config->http_addr.sin_addr, arg))
521 ERROR("Invalid host/IP address: %s\n", arg);
522 } else if (!av_strcasecmp(cmd, "NoDaemon")) {
523 WARNING("NoDaemon option has no effect, you should remove it\n");
524 } else if (!av_strcasecmp(cmd, "RTSPPort")) {
525 ffserver_get_arg(arg, sizeof(arg), p);
526 ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num,
527 "Invalid port: %s\n", arg);
528 config->rtsp_addr.sin_port = htons(val);
529 } else if (!av_strcasecmp(cmd, "RTSPBindAddress")) {
530 ffserver_get_arg(arg, sizeof(arg), p);
531 if (resolve_host(&config->rtsp_addr.sin_addr, arg))
532 ERROR("Invalid host/IP address: %s\n", arg);
533 } else if (!av_strcasecmp(cmd, "MaxHTTPConnections")) {
534 ffserver_get_arg(arg, sizeof(arg), p);
535 ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num,
536 "Invalid MaxHTTPConnections: %s\n", arg);
537 config->nb_max_http_connections = val;
538 if (config->nb_max_connections > config->nb_max_http_connections)
539 ERROR("Inconsistent configuration: MaxClients(%d) > MaxHTTPConnections(%d)\n",
540 config->nb_max_connections, config->nb_max_http_connections);
541 } else if (!av_strcasecmp(cmd, "MaxClients")) {
542 ffserver_get_arg(arg, sizeof(arg), p);
543 ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num,
544 "Invalid MaxClients: %s\n", arg);
545 config->nb_max_connections = val;
546 if (config->nb_max_connections > config->nb_max_http_connections)
547 ERROR("Inconsistent configuration: MaxClients(%d) > MaxHTTPConnections(%d)\n",
548 config->nb_max_connections, config->nb_max_http_connections);
549 } else if (!av_strcasecmp(cmd, "MaxBandwidth")) {
552 ffserver_get_arg(arg, sizeof(arg), p);
554 llval = strtoll(arg, &tailp, 10);
555 if (llval < 10 || llval > 10000000 || tailp[0] || errno)
556 ERROR("Invalid MaxBandwidth: %s\n", arg);
558 config->max_bandwidth = llval;
559 } else if (!av_strcasecmp(cmd, "CustomLog")) {
561 ffserver_get_arg(config->logfilename, sizeof(config->logfilename), p);
562 } else if (!av_strcasecmp(cmd, "LoadModule")) {
563 ERROR("Loadable modules are no longer supported\n");
565 ERROR("Incorrect keyword: '%s'\n", cmd);
569 static int ffserver_parse_config_feed(FFServerConfig *config, const char *cmd, const char **p,
570 int line_num, FFServerStream **pfeed)
572 FFServerStream *feed;
576 if (!av_strcasecmp(cmd, "<Feed")) {
579 feed = av_mallocz(sizeof(FFServerStream));
581 return AVERROR(ENOMEM);
582 ffserver_get_arg(feed->filename, sizeof(feed->filename), p);
583 q = strrchr(feed->filename, '>');
587 for (s = config->first_feed; s; s = s->next) {
588 if (!strcmp(feed->filename, s->filename))
589 ERROR("Feed '%s' already registered\n", s->filename);
592 feed->fmt = av_guess_format("ffm", NULL, NULL);
593 /* default feed file */
594 snprintf(feed->feed_filename, sizeof(feed->feed_filename),
595 "/tmp/%s.ffm", feed->filename);
596 feed->feed_max_size = 5 * 1024 * 1024;
598 feed->feed = feed; /* self feeding :-) */
603 if (!av_strcasecmp(cmd, "Launch")) {
606 feed->child_argv = av_mallocz(64 * sizeof(char *));
607 if (!feed->child_argv)
608 return AVERROR(ENOMEM);
609 for (i = 0; i < 62; i++) {
610 ffserver_get_arg(arg, sizeof(arg), p);
614 feed->child_argv[i] = av_strdup(arg);
615 if (!feed->child_argv[i])
616 return AVERROR(ENOMEM);
619 feed->child_argv[i] =
620 av_asprintf("http://%s:%d/%s",
621 (config->http_addr.sin_addr.s_addr == INADDR_ANY) ? "127.0.0.1" :
622 inet_ntoa(config->http_addr.sin_addr), ntohs(config->http_addr.sin_port),
624 if (!feed->child_argv[i])
625 return AVERROR(ENOMEM);
626 } else if (!av_strcasecmp(cmd, "ACL")) {
627 ffserver_parse_acl_row(NULL, feed, NULL, *p, config->filename,
629 } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
630 ffserver_get_arg(feed->feed_filename, sizeof(feed->feed_filename), p);
631 feed->readonly = !av_strcasecmp(cmd, "ReadOnlyFile");
632 } else if (!av_strcasecmp(cmd, "Truncate")) {
633 ffserver_get_arg(arg, sizeof(arg), p);
634 /* assume Truncate is true in case no argument is specified */
638 WARNING("Truncate N syntax in configuration file is deprecated, "
639 "use Truncate alone with no arguments\n");
640 feed->truncate = strtod(arg, NULL);
642 } else if (!av_strcasecmp(cmd, "FileMaxSize")) {
646 ffserver_get_arg(arg, sizeof(arg), p);
648 fsize = strtod(p1, &p1);
649 switch(av_toupper(*p1)) {
654 fsize *= 1024 * 1024;
657 fsize *= 1024 * 1024 * 1024;
660 ERROR("Invalid file size: %s\n", arg);
663 feed->feed_max_size = (int64_t)fsize;
664 if (feed->feed_max_size < FFM_PACKET_SIZE*4)
665 ERROR("Feed max file size is too small, must be at least %d\n",
667 } else if (!av_strcasecmp(cmd, "</Feed>")) {
670 ERROR("Invalid entry '%s' inside <Feed></Feed>\n", cmd);
675 static void ffserver_apply_stream_config(AVCodecContext *enc, const AVDictionary *conf, AVDictionary **opts)
677 AVDictionaryEntry *e;
679 /* Return values from ffserver_set_*_param are ignored.
680 Values are initially parsed and checked before inserting to
684 if ((e = av_dict_get(conf, "VideoBitRateRangeMin", NULL, 0)))
685 ffserver_set_int_param(&enc->rc_min_rate, e->value, 1000, INT_MIN,
686 INT_MAX, NULL, 0, NULL);
687 if ((e = av_dict_get(conf, "VideoBitRateRangeMax", NULL, 0)))
688 ffserver_set_int_param(&enc->rc_max_rate, e->value, 1000, INT_MIN,
689 INT_MAX, NULL, 0, NULL);
690 if ((e = av_dict_get(conf, "Debug", NULL, 0)))
691 ffserver_set_int_param(&enc->debug, e->value, 0, INT_MIN, INT_MAX,
693 if ((e = av_dict_get(conf, "Strict", NULL, 0)))
694 ffserver_set_int_param(&enc->strict_std_compliance, e->value, 0,
695 INT_MIN, INT_MAX, NULL, 0, NULL);
696 if ((e = av_dict_get(conf, "VideoBufferSize", NULL, 0)))
697 ffserver_set_int_param(&enc->rc_buffer_size, e->value, 8*1024,
698 INT_MIN, INT_MAX, NULL, 0, NULL);
699 if ((e = av_dict_get(conf, "VideoBitRateTolerance", NULL, 0)))
700 ffserver_set_int_param(&enc->bit_rate_tolerance, e->value, 1000,
701 INT_MIN, INT_MAX, NULL, 0, NULL);
702 if ((e = av_dict_get(conf, "VideoBitRate", NULL, 0)))
703 ffserver_set_int_param(&enc->bit_rate, e->value, 1000, INT_MIN,
704 INT_MAX, NULL, 0, NULL);
705 if ((e = av_dict_get(conf, "VideoSizeWidth", NULL, 0)))
706 ffserver_set_int_param(&enc->width, e->value, 0, INT_MIN, INT_MAX,
708 if ((e = av_dict_get(conf, "VideoSizeHeight", NULL, 0)))
709 ffserver_set_int_param(&enc->height, e->value, 0, INT_MIN, INT_MAX,
711 if ((e = av_dict_get(conf, "PixelFormat", NULL, 0))) {
713 ffserver_set_int_param(&val, e->value, 0, INT_MIN, INT_MAX, NULL, 0,
717 if ((e = av_dict_get(conf, "VideoGopSize", NULL, 0)))
718 ffserver_set_int_param(&enc->gop_size, e->value, 0, INT_MIN, INT_MAX,
720 if ((e = av_dict_get(conf, "VideoFrameRateNum", NULL, 0)))
721 ffserver_set_int_param(&enc->time_base.num, e->value, 0, INT_MIN,
722 INT_MAX, NULL, 0, NULL);
723 if ((e = av_dict_get(conf, "VideoFrameRateDen", NULL, 0)))
724 ffserver_set_int_param(&enc->time_base.den, e->value, 0, INT_MIN,
725 INT_MAX, NULL, 0, NULL);
726 if ((e = av_dict_get(conf, "VideoQDiff", NULL, 0)))
727 ffserver_set_int_param(&enc->max_qdiff, e->value, 0, INT_MIN, INT_MAX,
729 if ((e = av_dict_get(conf, "VideoQMax", NULL, 0)))
730 ffserver_set_int_param(&enc->qmax, e->value, 0, INT_MIN, INT_MAX, NULL,
732 if ((e = av_dict_get(conf, "VideoQMin", NULL, 0)))
733 ffserver_set_int_param(&enc->qmin, e->value, 0, INT_MIN, INT_MAX, NULL,
735 if ((e = av_dict_get(conf, "LumiMask", NULL, 0)))
736 ffserver_set_float_param(&enc->lumi_masking, e->value, 0, -FLT_MAX,
737 FLT_MAX, NULL, 0, NULL);
738 if ((e = av_dict_get(conf, "DarkMask", NULL, 0)))
739 ffserver_set_float_param(&enc->dark_masking, e->value, 0, -FLT_MAX,
740 FLT_MAX, NULL, 0, NULL);
741 if (av_dict_get(conf, "BitExact", NULL, 0))
742 enc->flags |= CODEC_FLAG_BITEXACT;
743 if (av_dict_get(conf, "DctFastint", NULL, 0))
744 enc->dct_algo = FF_DCT_FASTINT;
745 if (av_dict_get(conf, "IdctSimple", NULL, 0))
746 enc->idct_algo = FF_IDCT_SIMPLE;
747 if (av_dict_get(conf, "VideoHighQuality", NULL, 0))
748 enc->mb_decision = FF_MB_DECISION_BITS;
749 if ((e = av_dict_get(conf, "VideoTag", NULL, 0)))
750 enc->codec_tag = MKTAG(e->value[0], e->value[1], e->value[2], e->value[3]);
751 if ((e = av_dict_get(conf, "Qscale", NULL, 0))) {
752 enc->flags |= CODEC_FLAG_QSCALE;
753 ffserver_set_int_param(&enc->global_quality, e->value, FF_QP2LAMBDA,
754 INT_MIN, INT_MAX, NULL, 0, NULL);
756 if (av_dict_get(conf, "Video4MotionVector", NULL, 0)) {
757 enc->mb_decision = FF_MB_DECISION_BITS; //FIXME remove
758 enc->flags |= CODEC_FLAG_4MV;
761 if ((e = av_dict_get(conf, "AudioChannels", NULL, 0)))
762 ffserver_set_int_param(&enc->channels, e->value, 0, INT_MIN, INT_MAX,
764 if ((e = av_dict_get(conf, "AudioSampleRate", NULL, 0)))
765 ffserver_set_int_param(&enc->sample_rate, e->value, 0, INT_MIN,
766 INT_MAX, NULL, 0, NULL);
767 if ((e = av_dict_get(conf, "AudioBitRate", NULL, 0)))
768 ffserver_set_int_param(&enc->bit_rate, e->value, 0, INT_MIN, INT_MAX,
771 av_opt_set_dict2(enc->priv_data, opts, AV_OPT_SEARCH_CHILDREN);
772 av_opt_set_dict2(enc, opts, AV_OPT_SEARCH_CHILDREN);
774 if (av_dict_count(*opts))
775 av_log(NULL, AV_LOG_ERROR, "Something went wrong, %d options not set!!!\n", av_dict_count(*opts));
778 static int ffserver_parse_config_stream(FFServerConfig *config, const char *cmd, const char **p,
779 int line_num, FFServerStream **pstream)
781 char arg[1024], arg2[1024];
782 FFServerStream *stream;
788 if (!av_strcasecmp(cmd, "<Stream")) {
791 stream = av_mallocz(sizeof(FFServerStream));
793 return AVERROR(ENOMEM);
794 config->dummy_actx = avcodec_alloc_context3(NULL);
795 config->dummy_vctx = avcodec_alloc_context3(NULL);
796 if (!config->dummy_vctx || !config->dummy_actx) {
798 avcodec_free_context(&config->dummy_vctx);
799 avcodec_free_context(&config->dummy_actx);
800 return AVERROR(ENOMEM);
802 config->dummy_actx->codec_type = AVMEDIA_TYPE_AUDIO;
803 config->dummy_vctx->codec_type = AVMEDIA_TYPE_VIDEO;
804 ffserver_get_arg(stream->filename, sizeof(stream->filename), p);
805 q = strrchr(stream->filename, '>');
809 for (s = config->first_stream; s; s = s->next) {
810 if (!strcmp(stream->filename, s->filename))
811 ERROR("Stream '%s' already registered\n", s->filename);
814 stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);
816 config->guessed_audio_codec_id = stream->fmt->audio_codec;
817 config->guessed_video_codec_id = stream->fmt->video_codec;
819 config->guessed_audio_codec_id = AV_CODEC_ID_NONE;
820 config->guessed_video_codec_id = AV_CODEC_ID_NONE;
826 if (!av_strcasecmp(cmd, "Feed")) {
827 FFServerStream *sfeed;
828 ffserver_get_arg(arg, sizeof(arg), p);
829 sfeed = config->first_feed;
831 if (!strcmp(sfeed->filename, arg))
833 sfeed = sfeed->next_feed;
836 ERROR("Feed with name '%s' for stream '%s' is not defined\n", arg,
839 stream->feed = sfeed;
840 } else if (!av_strcasecmp(cmd, "Format")) {
841 ffserver_get_arg(arg, sizeof(arg), p);
842 if (!strcmp(arg, "status")) {
843 stream->stream_type = STREAM_TYPE_STATUS;
846 stream->stream_type = STREAM_TYPE_LIVE;
847 /* JPEG cannot be used here, so use single frame MJPEG */
848 if (!strcmp(arg, "jpeg"))
849 strcpy(arg, "mjpeg");
850 stream->fmt = ffserver_guess_format(arg, NULL, NULL);
852 ERROR("Unknown Format: %s\n", arg);
855 config->guessed_audio_codec_id = stream->fmt->audio_codec;
856 config->guessed_video_codec_id = stream->fmt->video_codec;
858 } else if (!av_strcasecmp(cmd, "InputFormat")) {
859 ffserver_get_arg(arg, sizeof(arg), p);
860 stream->ifmt = av_find_input_format(arg);
862 ERROR("Unknown input format: %s\n", arg);
863 } else if (!av_strcasecmp(cmd, "FaviconURL")) {
864 if (stream->stream_type == STREAM_TYPE_STATUS)
865 ffserver_get_arg(stream->feed_filename,
866 sizeof(stream->feed_filename), p);
868 ERROR("FaviconURL only permitted for status streams\n");
869 } else if (!av_strcasecmp(cmd, "Author") ||
870 !av_strcasecmp(cmd, "Comment") ||
871 !av_strcasecmp(cmd, "Copyright") ||
872 !av_strcasecmp(cmd, "Title")) {
875 ffserver_get_arg(arg, sizeof(arg), p);
876 for (i = 0; i < strlen(cmd); i++)
877 key[i] = av_tolower(cmd[i]);
879 WARNING("'%s' option in configuration file is deprecated, "
880 "use 'Metadata %s VALUE' instead\n", cmd, key);
881 if (av_dict_set(&stream->metadata, key, arg, 0) < 0)
883 } else if (!av_strcasecmp(cmd, "Metadata")) {
884 ffserver_get_arg(arg, sizeof(arg), p);
885 ffserver_get_arg(arg2, sizeof(arg2), p);
886 if (av_dict_set(&stream->metadata, arg, arg2, 0) < 0)
888 } else if (!av_strcasecmp(cmd, "Preroll")) {
889 ffserver_get_arg(arg, sizeof(arg), p);
890 stream->prebuffer = atof(arg) * 1000;
891 } else if (!av_strcasecmp(cmd, "StartSendOnKey")) {
892 stream->send_on_key = 1;
893 } else if (!av_strcasecmp(cmd, "AudioCodec")) {
894 ffserver_get_arg(arg, sizeof(arg), p);
895 ffserver_set_codec(config->dummy_actx, arg, config, line_num);
896 } else if (!av_strcasecmp(cmd, "VideoCodec")) {
897 ffserver_get_arg(arg, sizeof(arg), p);
898 ffserver_set_codec(config->dummy_vctx, arg, config, line_num);
899 } else if (!av_strcasecmp(cmd, "MaxTime")) {
900 ffserver_get_arg(arg, sizeof(arg), p);
901 stream->max_time = atof(arg) * 1000;
902 } else if (!av_strcasecmp(cmd, "AudioBitRate")) {
904 ffserver_get_arg(arg, sizeof(arg), p);
905 ffserver_set_float_param(&f, arg, 1000, 0, FLT_MAX, config, line_num,
906 "Invalid %s: %s\n", cmd, arg);
907 if (av_dict_set_int(&config->audio_conf, cmd, lrintf(f), 0) < 0)
909 } else if (!av_strcasecmp(cmd, "AudioChannels")) {
910 ffserver_get_arg(arg, sizeof(arg), p);
911 ffserver_set_int_param(NULL, arg, 0, 1, 8, config, line_num,
912 "Invalid %s: %s, valid range is 1-8.", cmd, arg);
913 if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0)
915 } else if (!av_strcasecmp(cmd, "AudioSampleRate")) {
916 ffserver_get_arg(arg, sizeof(arg), p);
917 ffserver_set_int_param(NULL, arg, 0, 0, INT_MAX, config, line_num,
918 "Invalid %s: %s", cmd, arg);
919 if (av_dict_set(&config->audio_conf, cmd, arg, 0) < 0)
921 } else if (!av_strcasecmp(cmd, "VideoBitRateRange")) {
922 int minrate, maxrate;
923 ffserver_get_arg(arg, sizeof(arg), p);
924 if (sscanf(arg, "%d-%d", &minrate, &maxrate) == 2) {
925 if (av_dict_set_int(&config->video_conf, "VideoBitRateRangeMin", minrate, 0) < 0 ||
926 av_dict_set_int(&config->video_conf, "VideoBitRateRangeMax", maxrate, 0) < 0)
929 ERROR("Incorrect format for VideoBitRateRange -- should be "
930 "<min>-<max>: %s\n", arg);
931 } else if (!av_strcasecmp(cmd, "Debug")) {
932 ffserver_get_arg(arg, sizeof(arg), p);
933 ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num,
934 "Invalid %s: %s", cmd, arg);
935 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
937 } else if (!av_strcasecmp(cmd, "Strict")) {
938 ffserver_get_arg(arg, sizeof(arg), p);
939 ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num,
940 "Invalid %s: %s", cmd, arg);
941 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
943 } else if (!av_strcasecmp(cmd, "VideoBufferSize")) {
944 ffserver_get_arg(arg, sizeof(arg), p);
945 ffserver_set_int_param(NULL, arg, 8*1024, 0, INT_MAX, config, line_num,
946 "Invalid %s: %s", cmd, arg);
947 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
949 } else if (!av_strcasecmp(cmd, "VideoBitRateTolerance")) {
950 ffserver_get_arg(arg, sizeof(arg), p);
951 ffserver_set_int_param(NULL, arg, 1000, INT_MIN, INT_MAX, config,
952 line_num, "Invalid %s: %s", cmd, arg);
953 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
955 } else if (!av_strcasecmp(cmd, "VideoBitRate")) {
956 ffserver_get_arg(arg, sizeof(arg), p);
957 ffserver_set_int_param(NULL, arg, 1000, 0, INT_MAX, config, line_num,
958 "Invalid %s: %s", cmd, arg);
959 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
961 } else if (!av_strcasecmp(cmd, "VideoSize")) {
963 ffserver_get_arg(arg, sizeof(arg), p);
964 ret = av_parse_video_size(&w, &h, arg);
966 ERROR("Invalid video size '%s'\n", arg);
967 else if ((w % 2) || (h % 2))
968 WARNING("Image size is not a multiple of 2\n");
969 if (av_dict_set_int(&config->video_conf, "VideoSizeWidth", w, 0) < 0 ||
970 av_dict_set_int(&config->video_conf, "VideoSizeHeight", h, 0) < 0)
972 } else if (!av_strcasecmp(cmd, "VideoFrameRate")) {
973 AVRational frame_rate;
974 ffserver_get_arg(arg, sizeof(arg), p);
975 if (av_parse_video_rate(&frame_rate, arg) < 0) {
976 ERROR("Incorrect frame rate: %s\n", arg);
978 if (av_dict_set_int(&config->video_conf, "VideoFrameRateNum", frame_rate.num, 0) < 0 ||
979 av_dict_set_int(&config->video_conf, "VideoFrameRateDen", frame_rate.den, 0) < 0)
982 } else if (!av_strcasecmp(cmd, "PixelFormat")) {
983 enum AVPixelFormat pix_fmt;
984 ffserver_get_arg(arg, sizeof(arg), p);
985 pix_fmt = av_get_pix_fmt(arg);
986 if (pix_fmt == AV_PIX_FMT_NONE)
987 ERROR("Unknown pixel format: %s\n", arg);
988 if (av_dict_set_int(&config->video_conf, cmd, pix_fmt, 0) < 0)
990 } else if (!av_strcasecmp(cmd, "VideoGopSize")) {
991 ffserver_get_arg(arg, sizeof(arg), p);
992 ffserver_set_int_param(NULL, arg, 0, INT_MIN, INT_MAX, config, line_num,
993 "Invalid %s: %s", cmd, arg);
994 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
996 } else if (!av_strcasecmp(cmd, "VideoIntraOnly")) {
997 if (av_dict_set(&config->video_conf, "VideoGopSize", "1", 0) < 0)
999 } else if (!av_strcasecmp(cmd, "VideoHighQuality")) {
1000 if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
1002 } else if (!av_strcasecmp(cmd, "Video4MotionVector")) {
1003 if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
1005 } else if (!av_strcasecmp(cmd, "AVOptionVideo") ||
1006 !av_strcasecmp(cmd, "AVOptionAudio")) {
1008 ffserver_get_arg(arg, sizeof(arg), p);
1009 ffserver_get_arg(arg2, sizeof(arg2), p);
1010 if (!av_strcasecmp(cmd, "AVOptionVideo"))
1011 ret = ffserver_save_avoption(config->dummy_vctx, arg, arg2, &config->video_opts,
1012 AV_OPT_FLAG_VIDEO_PARAM ,config, line_num);
1014 ret = ffserver_save_avoption(config->dummy_actx, arg, arg2, &config->audio_opts,
1015 AV_OPT_FLAG_AUDIO_PARAM ,config, line_num);
1018 } else if (!av_strcasecmp(cmd, "AVPresetVideo") ||
1019 !av_strcasecmp(cmd, "AVPresetAudio")) {
1020 ffserver_get_arg(arg, sizeof(arg), p);
1021 if (!av_strcasecmp(cmd, "AVPresetVideo"))
1022 ffserver_opt_preset(arg, config->dummy_vctx, config, line_num);
1024 ffserver_opt_preset(arg, config->dummy_actx, config, line_num);
1025 } else if (!av_strcasecmp(cmd, "VideoTag")) {
1026 ffserver_get_arg(arg, sizeof(arg), p);
1027 if (strlen(arg) == 4) {
1028 if (av_dict_set(&config->video_conf, "VideoTag", arg, 0) < 0)
1031 } else if (!av_strcasecmp(cmd, "BitExact")) {
1032 if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
1034 } else if (!av_strcasecmp(cmd, "DctFastint")) {
1035 if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
1037 } else if (!av_strcasecmp(cmd, "IdctSimple")) {
1038 if (av_dict_set(&config->video_conf, cmd, "", 0) < 0)
1040 } else if (!av_strcasecmp(cmd, "Qscale")) {
1041 ffserver_get_arg(arg, sizeof(arg), p);
1042 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
1044 } else if (!av_strcasecmp(cmd, "VideoQDiff")) {
1045 ffserver_get_arg(arg, sizeof(arg), p);
1046 ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num,
1047 "%s out of range\n", cmd);
1048 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
1050 } else if (!av_strcasecmp(cmd, "VideoQMax")) {
1051 ffserver_get_arg(arg, sizeof(arg), p);
1052 ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num,
1053 "%s out of range\n", cmd);
1054 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
1056 } else if (!av_strcasecmp(cmd, "VideoQMin")) {
1057 ffserver_get_arg(arg, sizeof(arg), p);
1058 ffserver_set_int_param(NULL, arg, 0, 1, 31, config, line_num,
1059 "%s out of range\n", cmd);
1060 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
1062 } else if (!av_strcasecmp(cmd, "LumiMask")) {
1063 ffserver_get_arg(arg, sizeof(arg), p);
1064 ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config,
1065 line_num, "Invalid %s: %s", cmd, arg);
1066 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
1068 } else if (!av_strcasecmp(cmd, "DarkMask")) {
1069 ffserver_get_arg(arg, sizeof(arg), p);
1070 ffserver_set_float_param(NULL, arg, 0, -FLT_MAX, FLT_MAX, config,
1071 line_num, "Invalid %s: %s", cmd, arg);
1072 if (av_dict_set(&config->video_conf, cmd, arg, 0) < 0)
1074 } else if (!av_strcasecmp(cmd, "NoVideo")) {
1075 config->no_video = 1;
1076 } else if (!av_strcasecmp(cmd, "NoAudio")) {
1077 config->no_audio = 1;
1078 } else if (!av_strcasecmp(cmd, "ACL")) {
1079 ffserver_parse_acl_row(stream, NULL, NULL, *p, config->filename,
1081 } else if (!av_strcasecmp(cmd, "DynamicACL")) {
1082 ffserver_get_arg(stream->dynamic_acl, sizeof(stream->dynamic_acl), p);
1083 } else if (!av_strcasecmp(cmd, "RTSPOption")) {
1084 ffserver_get_arg(arg, sizeof(arg), p);
1085 av_freep(&stream->rtsp_option);
1086 stream->rtsp_option = av_strdup(arg);
1087 } else if (!av_strcasecmp(cmd, "MulticastAddress")) {
1088 ffserver_get_arg(arg, sizeof(arg), p);
1089 if (resolve_host(&stream->multicast_ip, arg))
1090 ERROR("Invalid host/IP address: %s\n", arg);
1091 stream->is_multicast = 1;
1092 stream->loop = 1; /* default is looping */
1093 } else if (!av_strcasecmp(cmd, "MulticastPort")) {
1094 ffserver_get_arg(arg, sizeof(arg), p);
1095 ffserver_set_int_param(&val, arg, 0, 1, 65535, config, line_num,
1096 "Invalid MulticastPort: %s\n", arg);
1097 stream->multicast_port = val;
1098 } else if (!av_strcasecmp(cmd, "MulticastTTL")) {
1099 ffserver_get_arg(arg, sizeof(arg), p);
1100 ffserver_set_int_param(&val, arg, 0, INT_MIN, INT_MAX, config,
1101 line_num, "Invalid MulticastTTL: %s\n", arg);
1102 stream->multicast_ttl = val;
1103 } else if (!av_strcasecmp(cmd, "NoLoop")) {
1105 } else if (!av_strcasecmp(cmd, "</Stream>")) {
1106 if (stream->feed && stream->fmt && strcmp(stream->fmt->name, "ffm")) {
1107 if (config->dummy_actx->codec_id == AV_CODEC_ID_NONE)
1108 config->dummy_actx->codec_id = config->guessed_audio_codec_id;
1109 if (!config->no_audio && config->dummy_actx->codec_id != AV_CODEC_ID_NONE) {
1110 AVCodecContext *audio_enc = avcodec_alloc_context3(avcodec_find_encoder(config->dummy_actx->codec_id));
1111 ffserver_apply_stream_config(audio_enc, config->audio_conf, &config->audio_opts);
1112 add_codec(stream, audio_enc);
1114 if (config->dummy_vctx->codec_id == AV_CODEC_ID_NONE)
1115 config->dummy_vctx->codec_id = config->guessed_video_codec_id;
1116 if (!config->no_video && config->dummy_vctx->codec_id != AV_CODEC_ID_NONE) {
1117 AVCodecContext *video_enc = avcodec_alloc_context3(avcodec_find_encoder(config->dummy_vctx->codec_id));
1118 ffserver_apply_stream_config(video_enc, config->video_conf, &config->video_opts);
1119 add_codec(stream, video_enc);
1122 av_dict_free(&config->video_opts);
1123 av_dict_free(&config->video_conf);
1124 av_dict_free(&config->audio_opts);
1125 av_dict_free(&config->audio_conf);
1126 avcodec_free_context(&config->dummy_vctx);
1127 avcodec_free_context(&config->dummy_actx);
1129 } else if (!av_strcasecmp(cmd, "File") || !av_strcasecmp(cmd, "ReadOnlyFile")) {
1130 ffserver_get_arg(stream->feed_filename, sizeof(stream->feed_filename),
1133 ERROR("Invalid entry '%s' inside <Stream></Stream>\n", cmd);
1137 av_log(NULL, AV_LOG_ERROR, "Out of memory. Aborting.\n");
1138 av_dict_free(&config->video_opts);
1139 av_dict_free(&config->video_conf);
1140 av_dict_free(&config->audio_opts);
1141 av_dict_free(&config->audio_conf);
1142 avcodec_free_context(&config->dummy_vctx);
1143 avcodec_free_context(&config->dummy_actx);
1144 return AVERROR(ENOMEM);
1147 static int ffserver_parse_config_redirect(FFServerConfig *config, const char *cmd, const char **p,
1148 int line_num, FFServerStream **predirect)
1150 FFServerStream *redirect;
1151 av_assert0(predirect);
1152 redirect = *predirect;
1154 if (!av_strcasecmp(cmd, "<Redirect")) {
1156 redirect = av_mallocz(sizeof(FFServerStream));
1158 return AVERROR(ENOMEM);
1160 ffserver_get_arg(redirect->filename, sizeof(redirect->filename), p);
1161 q = strrchr(redirect->filename, '>');
1164 redirect->stream_type = STREAM_TYPE_REDIRECT;
1165 *predirect = redirect;
1168 av_assert0(redirect);
1169 if (!av_strcasecmp(cmd, "URL")) {
1170 ffserver_get_arg(redirect->feed_filename,
1171 sizeof(redirect->feed_filename), p);
1172 } else if (!av_strcasecmp(cmd, "</Redirect>")) {
1173 if (!redirect->feed_filename[0])
1174 ERROR("No URL found for <Redirect>\n");
1177 ERROR("Invalid entry '%s' inside <Redirect></Redirect>\n", cmd);
1182 int ffserver_parse_ffconfig(const char *filename, FFServerConfig *config)
1189 FFServerStream **last_stream, *stream = NULL, *redirect = NULL;
1190 FFServerStream **last_feed, *feed = NULL;
1195 f = fopen(filename, "r");
1197 ret = AVERROR(errno);
1198 av_log(NULL, AV_LOG_ERROR,
1199 "Could not open the configuration file '%s'\n", filename);
1203 config->first_stream = NULL;
1204 last_stream = &config->first_stream;
1205 config->first_feed = NULL;
1206 last_feed = &config->first_feed;
1207 config->errors = config->warnings = 0;
1210 if (fgets(line, sizeof(line), f) == NULL)
1214 while (av_isspace(*p))
1216 if (*p == '\0' || *p == '#')
1219 ffserver_get_arg(cmd, sizeof(cmd), &p);
1221 if (feed || !av_strcasecmp(cmd, "<Feed")) {
1222 int opening = !av_strcasecmp(cmd, "<Feed");
1223 if (opening && (stream || feed || redirect)) {
1224 ERROR("Already in a tag\n");
1226 if ((ret = ffserver_parse_config_feed(config, cmd, &p, line_num, &feed)) < 0)
1229 /* add in stream list */
1230 *last_stream = feed;
1231 last_stream = &feed->next;
1232 /* add in feed list */
1234 last_feed = &feed->next_feed;
1237 } else if (stream || !av_strcasecmp(cmd, "<Stream")) {
1238 int opening = !av_strcasecmp(cmd, "<Stream");
1239 if (opening && (stream || feed || redirect)) {
1240 ERROR("Already in a tag\n");
1242 if ((ret = ffserver_parse_config_stream(config, cmd, &p, line_num, &stream)) < 0)
1245 /* add in stream list */
1246 *last_stream = stream;
1247 last_stream = &stream->next;
1250 } else if (redirect || !av_strcasecmp(cmd, "<Redirect")) {
1251 int opening = !av_strcasecmp(cmd, "<Redirect");
1252 if (opening && (stream || feed || redirect))
1253 ERROR("Already in a tag\n");
1255 if ((ret = ffserver_parse_config_redirect(config, cmd, &p, line_num, &redirect)) < 0)
1258 /* add in stream list */
1259 *last_stream = redirect;
1260 last_stream = &redirect->next;
1264 ffserver_parse_config_global(config, cmd, &p, line_num);
1267 if (stream || feed || redirect)
1268 ERROR("Not closed tag %s\n", stream ? "<Stream>" : (feed ? "<Feed>" : "<Redirect>"));
1274 return AVERROR(EINVAL);