Skip to content
Snippets Groups Projects
ffserver.c 129 KiB
Newer Older
  • Learn to ignore specific revisions
  •     /* address on which the server will handle HTTP connections */
        my_http_addr.sin_family = AF_INET;
        my_http_addr.sin_port = htons (8080);
        my_http_addr.sin_addr.s_addr = htonl (INADDR_ANY);
    
        /* address on which the server will handle RTSP connections */
        my_rtsp_addr.sin_family = AF_INET;
        my_rtsp_addr.sin_port = htons (5454);
        my_rtsp_addr.sin_addr.s_addr = htonl (INADDR_ANY);
        
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        nb_max_connections = 5;
    
        nb_max_bandwidth = 1000;
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        first_stream = NULL;
        logfilename[0] = '\0';
    
    
        memset(&sigact, 0, sizeof(sigact));
        sigact.sa_handler = handle_child_exit;
        sigact.sa_flags = SA_NOCLDSTOP | SA_RESTART;
        sigaction(SIGCHLD, &sigact, 0);
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        if (parse_ffconfig(config_filename) < 0) {
            fprintf(stderr, "Incorrect config file - exiting.\n");
            exit(1);
        }
    
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        build_feed_streams();
    
    
        /* put the process in background and detach it from its TTY */
        if (ffserver_daemon) {
            int pid;
    
            pid = fork();
            if (pid < 0) {
                perror("fork");
                exit(1);
            } else if (pid > 0) {
                /* parent : exit */
                exit(0);
            } else {
                /* child */
                setsid();
                chdir("/");
                close(0);
                open("/dev/null", O_RDWR);
    
                if (strcmp(logfilename, "-") != 0) {
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
        /* signal init */
        signal(SIGPIPE, SIG_IGN);
    
        /* open log file if needed */
        if (logfilename[0] != '\0') {
            if (!strcmp(logfilename, "-"))
                logfile = stdout;
            else
                logfile = fopen(logfilename, "w");
        }
    
    
        if (http_server() < 0) {
            fprintf(stderr, "Could not start server\n");
    
    Fabrice Bellard's avatar
    Fabrice Bellard committed
            exit(1);
        }
    
        return 0;
    }