X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=avserver.c;h=16a24fff9c658ab9598cd264805dff783d53431e;hb=a157c7f2b8ac05188a116dbfc2fec401c1d4957a;hp=994edcd04cf4036610a71c0c02cb71afaa2c358a;hpb=3b20eb25e7b95fafdccbb594c947a69c5d027b2c;p=ffmpeg diff --git a/avserver.c b/avserver.c index 994edcd04cf..16a24fff9c6 100644 --- a/avserver.c +++ b/avserver.c @@ -25,6 +25,7 @@ #endif #include #include +#include #include "libavformat/avformat.h" // FIXME those are internal headers, avserver _really_ shouldn't use them #include "libavformat/ffm.h" @@ -301,12 +302,10 @@ static int rtp_new_av_stream(HTTPContext *c, HTTPContext *rtsp_c); static const char *my_program_name; -static const char *my_program_dir; static const char *config_filename = "/etc/avserver.conf"; static int avserver_debug; -static int avserver_daemon; static int no_launch; static int need_to_start_children; @@ -515,18 +514,14 @@ static void start_children(FFStream *feed) close(i); if (!avserver_debug) { - i = open("/dev/null", O_RDWR); - if (i != -1) { - dup2(i, 0); - dup2(i, 1); - dup2(i, 2); - close(i); - } + if (!freopen("/dev/null", "r", stdin)) + http_log("failed to redirect STDIN to /dev/null\n;"); + if (!freopen("/dev/null", "w", stdout)) + http_log("failed to redirect STDOUT to /dev/null\n;"); + if (!freopen("/dev/null", "w", stderr)) + http_log("failed to redirect STDERR to /dev/null\n;"); } - /* This is needed to make relative pathnames work */ - chdir(my_program_dir); - signal(SIGPIPE, SIG_DFL); execvp(pathname, feed->child_argv); @@ -799,7 +794,8 @@ static void http_send_too_busy_reply(int fd) static void new_connection(int server_fd, int is_rtsp) { struct sockaddr_in from_addr; - int fd, len; + socklen_t len; + int fd; HTTPContext *c = NULL; len = sizeof(from_addr); @@ -1117,7 +1113,7 @@ static int extract_rates(char *rates, int ratelen, const char *request) if (av_strncasecmp(p, "Pragma:", 7) == 0) { const char *q = p + 7; - while (*q && *q != '\n' && isspace(*q)) + while (*q && *q != '\n' && av_isspace(*q)) q++; if (av_strncasecmp(q, "stream-switch-entry=", 20) == 0) { @@ -1139,7 +1135,7 @@ static int extract_rates(char *rates, int ratelen, const char *request) if (stream_no < ratelen && stream_no >= 0) rates[stream_no] = rate_no; - while (*q && *q != '\n' && !isspace(*q)) + while (*q && *q != '\n' && !av_isspace(*q)) q++; } @@ -1250,7 +1246,7 @@ static void get_word(char *buf, int buf_size, const char **pp) p = *pp; skip_spaces(&p); q = buf; - while (!isspace(*p) && *p != '\0') { + while (!av_isspace(*p) && *p != '\0') { if ((q - buf) < buf_size - 1) *q++ = *p; p++; @@ -1267,7 +1263,7 @@ static void get_arg(char *buf, int buf_size, const char **pp) int quote; p = *pp; - while (isspace(*p)) p++; + while (av_isspace(*p)) p++; q = buf; quote = 0; if (*p == '\"' || *p == '\'') @@ -1277,7 +1273,7 @@ static void get_arg(char *buf, int buf_size, const char **pp) if (*p == quote) break; } else { - if (isspace(*p)) + if (av_isspace(*p)) break; } if (*p == '\0') @@ -1381,7 +1377,7 @@ static IPAddressACL* parse_dynamic_acl(FFStream *stream, HTTPContext *c) break; line_num++; p = line; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (*p == '\0' || *p == '#') continue; @@ -1482,7 +1478,8 @@ enum RedirType { /* parse http request and prepare header */ static int http_parse_request(HTTPContext *c) { - char *p; + const char *p; + char *p1; enum RedirType redir_type; char cmd[32]; char info[1024], filename[1024]; @@ -1493,10 +1490,10 @@ static int http_parse_request(HTTPContext *c) FFStream *stream; int i; char ratebuf[32]; - char *useragent = 0; + const char *useragent = 0; p = c->buffer; - get_word(cmd, sizeof(cmd), (const char **)&p); + get_word(cmd, sizeof(cmd), &p); av_strlcpy(c->method, cmd, sizeof(c->method)); if (!strcmp(cmd, "GET")) @@ -1506,7 +1503,7 @@ static int http_parse_request(HTTPContext *c) else return -1; - get_word(url, sizeof(url), (const char **)&p); + get_word(url, sizeof(url), &p); av_strlcpy(c->url, url, sizeof(c->url)); get_word(protocol, sizeof(protocol), (const char **)&p); @@ -1519,10 +1516,10 @@ static int http_parse_request(HTTPContext *c) http_log("%s - - New connection: %s %s\n", inet_ntoa(c->from_addr.sin_addr), cmd, url); /* find the filename and the optional info string in the request */ - p = strchr(url, '?'); - if (p) { - av_strlcpy(info, p, sizeof(info)); - *p = '\0'; + p1 = strchr(url, '?'); + if (p1) { + av_strlcpy(info, p1, sizeof(info)); + *p1 = '\0'; } else info[0] = '\0'; @@ -1531,7 +1528,7 @@ static int http_parse_request(HTTPContext *c) for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "User-Agent:", 11) == 0) { useragent = p + 11; - if (*useragent && *useragent != '\n' && isspace(*useragent)) + if (*useragent && *useragent != '\n' && av_isspace(*useragent)) useragent++; break; } @@ -1639,7 +1636,7 @@ static int http_parse_request(HTTPContext *c) } if (redir_type != REDIR_NONE) { - char *hostinfo = 0; + const char *hostinfo = 0; for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { if (av_strncasecmp(p, "Host:", 5) == 0) { @@ -1657,7 +1654,7 @@ static int http_parse_request(HTTPContext *c) char *eoh; char hostbuf[260]; - while (isspace(*hostinfo)) + while (av_isspace(*hostinfo)) hostinfo++; eoh = strchr(hostinfo, '\n'); @@ -1717,7 +1714,8 @@ static int http_parse_request(HTTPContext *c) case REDIR_SDP: { uint8_t *sdp_data; - int sdp_data_size, len; + int sdp_data_size; + socklen_t len; struct sockaddr_in my_addr; q += snprintf(q, c->buffer_size, @@ -1767,7 +1765,7 @@ static int http_parse_request(HTTPContext *c) if (!stream->is_feed) { /* 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; + const char *logline = 0; int client_id = 0; for (p = c->buffer; *p && *p != '\r' && *p != '\n'; ) { @@ -2991,7 +2989,8 @@ static void rtsp_cmd_describe(HTTPContext *c, const char *url) char path1[1024]; const char *path; uint8_t *content; - int content_length, len; + int content_length; + socklen_t len; struct sockaddr_in my_addr; /* find which url is asked */ @@ -3563,6 +3562,8 @@ static void extract_mpeg4_header(AVFormatContext *infile) AVStream *st; const uint8_t *p; + infile->flags |= AVFMT_FLAG_NOFILLIN | AVFMT_FLAG_NOPARSE; + mpeg4_count = 0; for(i=0;inb_streams;i++) { st = infile->streams[i]; @@ -3576,7 +3577,7 @@ static void extract_mpeg4_header(AVFormatContext *infile) printf("MPEG4 without extra data: trying to find header in %s\n", infile->filename); while (mpeg4_count > 0) { - if (av_read_packet(infile, &pkt) < 0) + if (av_read_frame(infile, &pkt) < 0) break; st = infile->streams[pkt.stream_index]; if (st->codec->codec_id == AV_CODEC_ID_MPEG4 && @@ -4059,7 +4060,7 @@ static int parse_ffconfig(const char *filename) break; line_num++; p = line; - while (isspace(*p)) + while (av_isspace(*p)) p++; if (*p == '\0' || *p == '#') continue; @@ -4078,8 +4079,6 @@ static int parse_ffconfig(const char *filename) if (resolve_host(&my_http_addr.sin_addr, arg) != 0) { ERROR("%s:%d: Invalid host/IP address: %s\n", arg); } - } else if (!av_strcasecmp(cmd, "NoDaemon")) { - avserver_daemon = 0; } else if (!av_strcasecmp(cmd, "RTSPPort")) { get_arg(arg, sizeof(arg), &p); val = atoi(arg); @@ -4199,7 +4198,7 @@ static int parse_ffconfig(const char *filename) get_arg(arg, sizeof(arg), &p); p1 = arg; fsize = strtod(p1, &p1); - switch(toupper(*p1)) { + switch(av_toupper(*p1)) { case 'K': fsize *= 1024; break; @@ -4506,14 +4505,6 @@ static int parse_ffconfig(const char *filename) ERROR("VideoQMin out of range\n"); } } - } else if (!av_strcasecmp(cmd, "LumaElim")) { - get_arg(arg, sizeof(arg), &p); - if (stream) - video_enc.luma_elim_threshold = atoi(arg); - } else if (!av_strcasecmp(cmd, "ChromaElim")) { - get_arg(arg, sizeof(arg), &p); - if (stream) - video_enc.chroma_elim_threshold = atoi(arg); } else if (!av_strcasecmp(cmd, "LumiMask")) { get_arg(arg, sizeof(arg), &p); if (stream) @@ -4652,7 +4643,6 @@ static void handle_child_exit(int sig) static void opt_debug(void) { avserver_debug = 1; - avserver_daemon = 0; logfilename[0] = '-'; } @@ -4683,8 +4673,6 @@ int main(int argc, char **argv) show_banner(); my_program_name = argv[0]; - my_program_dir = getcwd(0, 0); - avserver_daemon = 1; parse_options(NULL, argc, argv, options, NULL); @@ -4716,37 +4704,9 @@ int main(int argc, char **argv) compute_bandwidth(); - /* put the process in background and detach it from its TTY */ - if (avserver_daemon) { - int pid; - - pid = fork(); - if (pid < 0) { - perror("fork"); - exit(1); - } else if (pid > 0) { - /* parent : exit */ - exit(0); - } else { - /* child */ - setsid(); - close(0); - open("/dev/null", O_RDWR); - if (strcmp(logfilename, "-") != 0) { - close(1); - dup(0); - } - close(2); - dup(0); - } - } - /* signal init */ signal(SIGPIPE, SIG_IGN); - if (avserver_daemon) - chdir("/"); - if (http_server() < 0) { http_log("Could not start server\n"); exit(1);