* 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 <string.h>
+#include <strings.h>
#include <stdlib.h>
#include "libavutil/random.h"
#include "libavutil/avstring.h"
static const OptionDef options[];
-/* maximum number of simultaneous HTTP connections */
-#define HTTP_MAX_CONNECTIONS 2000
-
enum HTTPState {
HTTPSTATE_WAIT_REQUEST,
HTTPSTATE_SEND_HEADER,
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;
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);
}
{
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)
start_children(first_feed);
- first_http_ctx = NULL;
- nb_connections = 0;
-
start_multicast();
for(;;) {
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;
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 {
#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;
}
}
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);
}
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);
}
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;
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++;
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();
/* 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("/");