X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ffserver.c;h=f6898e54216722c8f4b62fb6cb7d13de10f0d2b6;hb=f2eb8c5bf63f5efdcb5d57b2b0e85530ffc52843;hp=3a854b3bf000c36bac8cbf91353cbbd33aa5c4d6;hpb=8bf61f5ba9d0e1108281c5952e0f695a2bbacd4e;p=ffmpeg diff --git a/ffserver.c b/ffserver.c index 3a854b3bf00..f6898e54216 100644 --- a/ffserver.c +++ b/ffserver.c @@ -19,11 +19,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#define _XOPEN_SOURCE 600 + #include "config.h" #ifndef HAVE_CLOSESOCKET #define closesocket close #endif #include +#include #include #include "libavutil/random.h" #include "libavutil/avstring.h" @@ -59,9 +62,6 @@ const int program_birth_year = 2000; static const OptionDef options[]; -/* maximum number of simultaneous HTTP connections */ -#define HTTP_MAX_CONNECTIONS 2000 - enum HTTPState { HTTPSTATE_WAIT_REQUEST, HTTPSTATE_SEND_HEADER, @@ -292,8 +292,10 @@ static int ffserver_daemon; static int no_launch; static int need_to_start_children; -static int nb_max_connections = 5; -static int nb_connections; +/* maximum number of simultaneous HTTP connections */ +static unsigned int nb_max_http_connections = 2000; +static unsigned int nb_max_connections = 5; +static unsigned int nb_connections; static uint64_t max_bandwidth = 1000; static uint64_t current_bandwidth; @@ -348,7 +350,7 @@ static void http_av_log(void *ptr, int level, const char *fmt, va_list vargs) if (level > av_log_level) return; if (print_prefix && avc) - http_log("[%s @ %p]", avc->item_name(ptr), avc); + http_log("[%s @ %p]", avc->item_name(ptr), ptr); print_prefix = strstr(fmt, "\n") != NULL; http_vlog(fmt, vargs); } @@ -540,9 +542,14 @@ static int http_server(void) { int server_fd = 0, rtsp_server_fd = 0; int ret, delay, delay1; - struct pollfd poll_table[HTTP_MAX_CONNECTIONS + 2], *poll_entry; + struct pollfd *poll_table, *poll_entry; HTTPContext *c, *c_next; + if(!(poll_table = av_mallocz(nb_max_http_connections + 2))) { + http_log("Impossible to allocate a poll table handling %d connections.\n", nb_max_http_connections); + return -1; + } + if (my_http_addr.sin_port) { server_fd = socket_open_listen(&my_http_addr); if (server_fd < 0) @@ -564,9 +571,6 @@ static int http_server(void) start_children(first_feed); - first_http_ctx = NULL; - nb_connections = 0; - start_multicast(); for(;;) { @@ -1500,9 +1504,8 @@ static int http_parse_request(HTTPContext *c) if (c->post) { /* if post, it means a feed is being sent */ if (!stream->is_feed) { - /* However it might be a status report from WMP! Lets log the data - * as it might come in handy one day - */ + /* However it might be a status report from WMP! Let us log the + * data as it might come in handy one day. */ char *logline = 0; int client_id = 0; @@ -3446,7 +3449,7 @@ static void build_feed_streams(void) if (sf->index != ss->index || sf->id != ss->id) { - printf("Index & Id do not match for stream %d (%s)\n", + http_log("Index & Id do not match for stream %d (%s)\n", i, feed->feed_filename); matches = 0; } else { @@ -3457,28 +3460,28 @@ static void build_feed_streams(void) #define CHECK_CODEC(x) (ccf->x != ccs->x) if (CHECK_CODEC(codec) || CHECK_CODEC(codec_type)) { - printf("Codecs do not match for stream %d\n", i); + http_log("Codecs do not match for stream %d\n", i); matches = 0; } else if (CHECK_CODEC(bit_rate) || CHECK_CODEC(flags)) { - printf("Codec bitrates do not match for stream %d\n", i); + http_log("Codec bitrates do not match for stream %d\n", i); matches = 0; } else if (ccf->codec_type == CODEC_TYPE_VIDEO) { if (CHECK_CODEC(time_base.den) || CHECK_CODEC(time_base.num) || CHECK_CODEC(width) || CHECK_CODEC(height)) { - printf("Codec width, height and framerate do not match for stream %d\n", i); + http_log("Codec width, height and framerate do not match for stream %d\n", i); matches = 0; } } else if (ccf->codec_type == CODEC_TYPE_AUDIO) { if (CHECK_CODEC(sample_rate) || CHECK_CODEC(channels) || CHECK_CODEC(frame_size)) { - printf("Codec sample_rate, channels, frame_size do not match for stream %d\n", i); + http_log("Codec sample_rate, channels, frame_size do not match for stream %d\n", i); matches = 0; } } else { - printf("Unknown codec type\n"); + http_log("Unknown codec type\n"); matches = 0; } } @@ -3486,17 +3489,17 @@ static void build_feed_streams(void) break; } } else - printf("Deleting feed file '%s' as stream counts differ (%d != %d)\n", + http_log("Deleting feed file '%s' as stream counts differ (%d != %d)\n", feed->feed_filename, s->nb_streams, feed->nb_streams); av_close_input_file(s); } else - printf("Deleting feed file '%s' as it appears to be corrupt\n", + http_log("Deleting feed file '%s' as it appears to be corrupt\n", feed->feed_filename); if (!matches) { if (feed->readonly) { - printf("Unable to delete feed file '%s' as it is marked readonly\n", + http_log("Unable to delete feed file '%s' as it is marked readonly\n", feed->feed_filename); exit(1); } @@ -3507,7 +3510,7 @@ static void build_feed_streams(void) AVFormatContext s1, *s = &s1; if (feed->readonly) { - printf("Unable to create feed file '%s' as it is marked readonly\n", + http_log("Unable to create feed file '%s' as it is marked readonly\n", feed->feed_filename); exit(1); } @@ -3735,7 +3738,7 @@ static int opt_default(const char *opt, const char *arg, const AVOption *o = NULL; const AVOption *o2 = av_find_opt(avctx, opt, NULL, type, type); if(o2) - o = av_set_string(avctx, opt, arg); + o = av_set_string2(avctx, opt, arg, 1); if(!o) return -1; return 0; @@ -3817,10 +3820,19 @@ static int parse_ffconfig(const char *filename) filename, line_num, arg); errors++; } + } else if (!strcasecmp(cmd, "MaxHTTPConnections")) { + get_arg(arg, sizeof(arg), &p); + val = atoi(arg); + if (val < 1 || val > 65536) { + fprintf(stderr, "%s:%d: Invalid MaxHTTPConnections: %s\n", + filename, line_num, arg); + errors++; + } + nb_max_http_connections = val; } else if (!strcasecmp(cmd, "MaxClients")) { get_arg(arg, sizeof(arg), &p); val = atoi(arg); - if (val < 1 || val > HTTP_MAX_CONNECTIONS) { + if (val < 1 || val > nb_max_http_connections) { fprintf(stderr, "%s:%d: Invalid MaxClients: %s\n", filename, line_num, arg); errors++; @@ -4483,6 +4495,15 @@ int main(int argc, char **argv) exit(1); } + /* open log file if needed */ + if (logfilename[0] != '\0') { + if (!strcmp(logfilename, "-")) + logfile = stdout; + else + logfile = fopen(logfilename, "a"); + av_log_set_callback(http_av_log); + } + build_file_streams(); build_feed_streams(); @@ -4517,15 +4538,6 @@ int main(int argc, char **argv) /* signal init */ signal(SIGPIPE, SIG_IGN); - /* open log file if needed */ - if (logfilename[0] != '\0') { - if (!strcmp(logfilename, "-")) - logfile = stderr; - else - logfile = fopen(logfilename, "a"); - av_log_set_callback(http_av_log); - } - if (ffserver_daemon) chdir("/");