#include "config.h"#include <string.h>#include <strings.h>#include <stdlib.h>#include "libavformat/avformat.h"#include "libavformat/network.h"#include "libavformat/os_support.h"#include "libavformat/rtpdec.h"#include "libavformat/rtsp.h"#include "libavutil/avstring.h"#include "libavutil/random.h"#include "libavutil/intreadwrite.h"#include "libavcodec/opt.h"#include <stdarg.h>#include <unistd.h>#include <fcntl.h>#include <sys/ioctl.h>#include <errno.h>#include <sys/time.h>#include <time.h>#include <sys/wait.h>#include <signal.h>#include "cmdutils.h"Go to the source code of this file.
Data Structures | |
| struct | RTSPActionServerSetup | 
| struct | DataRateData | 
| struct | HTTPContext | 
| struct | IPAddressACL | 
| struct | FFStream | 
| struct | FeedData | 
Defines | |
| #define | _XOPEN_SOURCE 600 | 
| #define | closesocket close | 
| #define | IOBUFFER_INIT_SIZE 8192 | 
| #define | HTTP_REQUEST_TIMEOUT (15 * 1000) | 
| #define | RTSP_REQUEST_TIMEOUT (3600 * 24 * 1000) | 
| #define | SYNC_TIMEOUT (10 * 1000) | 
| #define | CHECK_CODEC(x) (ccf->x != ccs->x) | 
Enumerations | |
| enum | HTTPState {  HTTPSTATE_WAIT_REQUEST, HTTPSTATE_SEND_HEADER, HTTPSTATE_SEND_DATA_HEADER, HTTPSTATE_SEND_DATA, HTTPSTATE_SEND_DATA_TRAILER, HTTPSTATE_RECEIVE_DATA, HTTPSTATE_WAIT_FEED, HTTPSTATE_READY, RTSPSTATE_WAIT_REQUEST, RTSPSTATE_SEND_REPLY, RTSPSTATE_SEND_PACKET }  | 
| enum | StreamType { STREAM_TYPE_LIVE, STREAM_TYPE_STATUS, STREAM_TYPE_REDIRECT } | 
| enum | IPAddressAction { IP_ALLOW = 1, IP_DENY } | 
| enum | RedirType {  REDIR_NONE, REDIR_ASX, REDIR_RAM, REDIR_ASF, REDIR_RTSP, REDIR_SDP }  | 
Functions | |
| static void | new_connection (int server_fd, int is_rtsp) | 
| static void | close_connection (HTTPContext *c) | 
| static int | handle_connection (HTTPContext *c) | 
| static int | http_parse_request (HTTPContext *c) | 
| static int | http_send_data (HTTPContext *c) | 
| static void | compute_status (HTTPContext *c) | 
| static int | open_input_stream (HTTPContext *c, const char *info) | 
| static int | http_start_receive_data (HTTPContext *c) | 
| static int | http_receive_data (HTTPContext *c) | 
| static int | rtsp_parse_request (HTTPContext *c) | 
| static void | rtsp_cmd_describe (HTTPContext *c, const char *url) | 
| static void | rtsp_cmd_options (HTTPContext *c, const char *url) | 
| static void | rtsp_cmd_setup (HTTPContext *c, const char *url, RTSPMessageHeader *h) | 
| static void | rtsp_cmd_play (HTTPContext *c, const char *url, RTSPMessageHeader *h) | 
| static void | rtsp_cmd_pause (HTTPContext *c, const char *url, RTSPMessageHeader *h) | 
| static void | rtsp_cmd_teardown (HTTPContext *c, const char *url, RTSPMessageHeader *h) | 
| static int | prepare_sdp_description (FFStream *stream, uint8_t **pbuffer, struct in_addr my_ip) | 
| static HTTPContext * | rtp_new_connection (struct sockaddr_in *from_addr, FFStream *stream, const char *session_id, enum RTSPLowerTransport rtp_protocol) | 
| static int | rtp_new_av_stream (HTTPContext *c, int stream_index, struct sockaddr_in *dest_addr, HTTPContext *rtsp_c) | 
| static char * | ctime1 (char *buf2) | 
| static void | http_vlog (const char *fmt, va_list vargs) | 
| void | http_log (const char *fmt,...) | 
| static void | http_av_log (void *ptr, int level, const char *fmt, va_list vargs) | 
| static void | log_connection (HTTPContext *c) | 
| static void | update_datarate (DataRateData *drd, int64_t count) | 
| static int | compute_datarate (DataRateData *drd, int64_t count) | 
| static void | start_children (FFStream *feed) | 
| static int | socket_open_listen (struct sockaddr_in *my_addr) | 
| static void | start_multicast (void) | 
| static int | http_server (void) | 
| static void | start_wait_request (HTTPContext *c, int is_rtsp) | 
| static int | extract_rates (char *rates, int ratelen, const char *request) | 
| static int | find_stream_in_feed (FFStream *feed, AVCodecContext *codec, int bit_rate) | 
| static int | modify_current_stream (HTTPContext *c, char *rates) | 
| static void | do_switch_stream (HTTPContext *c, int i) | 
| static void | skip_spaces (const char **pp) | 
| static void | get_word (char *buf, int buf_size, const char **pp) | 
| static int | validate_acl (FFStream *stream, HTTPContext *c) | 
| static void | compute_real_filename (char *filename, int max_size) | 
| static void | fmt_bytecount (ByteIOContext *pb, int64_t count) | 
| static void | open_parser (AVFormatContext *s, int i) | 
| static int64_t | get_server_clock (HTTPContext *c) | 
| static int64_t | get_packet_send_clock (HTTPContext *c) | 
| static int | http_prepare_data (HTTPContext *c) | 
| static void | rtsp_reply_header (HTTPContext *c, enum RTSPStatusCode error_number) | 
| static void | rtsp_reply_error (HTTPContext *c, enum RTSPStatusCode error_number) | 
| static HTTPContext * | find_rtp_session (const char *session_id) | 
| static RTSPTransportField * | find_transport (RTSPMessageHeader *h, enum RTSPLowerTransport lower_transport) | 
| static HTTPContext * | find_rtp_session_with_url (const char *url, const char *session_id) | 
| static AVStream * | add_av_stream1 (FFStream *stream, AVCodecContext *codec) | 
| static int | add_av_stream (FFStream *feed, AVStream *st) | 
| static void | remove_stream (FFStream *stream) | 
| static void | extract_mpeg4_header (AVFormatContext *infile) | 
| static void | build_file_streams (void) | 
| static void | build_feed_streams (void) | 
| static void | compute_bandwidth (void) | 
| static void | get_arg (char *buf, int buf_size, const char **pp) | 
| static void | add_codec (FFStream *stream, AVCodecContext *av) | 
| static enum CodecID | opt_audio_codec (const char *arg) | 
| static enum CodecID | opt_video_codec (const char *arg) | 
| static int | ffserver_opt_default (const char *opt, const char *arg, AVCodecContext *avctx, int type) | 
| static int | parse_ffconfig (const char *filename) | 
| static void | handle_child_exit (int sig) | 
| static void | opt_debug (void) | 
| static void | opt_show_help (void) | 
| int | main (int argc, char **argv) | 
Variables | |
| const char | program_name [] = "FFserver" | 
| program name, defined by the program for show_version().   | |
| const int | program_birth_year = 2000 | 
| program birth year, defined by the program for show_banner()   | |
| static const OptionDef | options [] | 
| static const char * | http_state [] | 
| static struct sockaddr_in | my_http_addr | 
| static struct sockaddr_in | my_rtsp_addr | 
| static char | logfilename [1024] | 
| static HTTPContext * | first_http_ctx | 
| static FFStream * | first_feed | 
| static FFStream * | first_stream | 
| static const char * | my_program_name | 
| static const char * | my_program_dir | 
| static const char * | config_filename | 
| static int | ffserver_debug | 
| static int | ffserver_daemon | 
| static int | no_launch | 
| static int | need_to_start_children | 
| 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 | 
| static int64_t | cur_time | 
| static AVRandomState | random_state | 
| static FILE * | logfile = NULL | 
| #define _XOPEN_SOURCE 600 | 
Definition at line 22 of file ffserver.c.
| #define CHECK_CODEC | ( | x | ) | (ccf->x != ccs->x) | 
Referenced by build_feed_streams().
| #define closesocket close | 
Definition at line 26 of file ffserver.c.
Referenced by close_connection(), new_connection(), socket_open_listen(), tcp_close(), tcp_open(), udp_close(), and udp_open().
| #define HTTP_REQUEST_TIMEOUT (15 * 1000) | 
| #define IOBUFFER_INIT_SIZE 8192 | 
| #define RTSP_REQUEST_TIMEOUT (3600 * 24 * 1000) | 
| #define SYNC_TIMEOUT (10 * 1000) | 
Definition at line 104 of file ffserver.c.
| enum HTTPState | 
Definition at line 67 of file ffserver.c.
| enum IPAddressAction | 
| enum RedirType | 
Definition at line 1220 of file ffserver.c.
| enum StreamType | 
Definition at line 180 of file ffserver.c.
| static AVStream* add_av_stream1 | ( | FFStream * | stream, | |
| AVCodecContext * | codec | |||
| ) |  [static] | 
        
Definition at line 3240 of file ffserver.c.
Referenced by add_av_stream(), and build_file_streams().
| static void add_codec | ( | FFStream * | stream, | |
| AVCodecContext * | av | |||
| ) |  [static] | 
        
| static void build_feed_streams | ( | void | ) |  [static] | 
        
| static void build_file_streams | ( | void | ) |  [static] | 
        
| static void close_connection | ( | HTTPContext * | c | ) |  [static] | 
        
| static void compute_bandwidth | ( | void | ) |  [static] | 
        
| static int compute_datarate | ( | DataRateData * | drd, | |
| int64_t | count | |||
| ) |  [static] | 
        
| static void compute_real_filename | ( | char * | filename, | |
| int | max_size | |||
| ) |  [static] | 
        
| static void compute_status | ( | HTTPContext * | c | ) |  [static] | 
        
| static char* ctime1 | ( | char * | buf2 | ) |  [static] | 
        
| static void do_switch_stream | ( | HTTPContext * | c, | |
| int | i | |||
| ) |  [static] | 
        
Definition at line 1136 of file ffserver.c.
Referenced by http_parse_request(), and http_prepare_data().
| static void extract_mpeg4_header | ( | AVFormatContext * | infile | ) |  [static] | 
        
| static int extract_rates | ( | char * | rates, | |
| int | ratelen, | |||
| const char * | request | |||
| ) |  [static] | 
        
| static int ffserver_opt_default | ( | const char * | opt, | |
| const char * | arg, | |||
| AVCodecContext * | avctx, | |||
| int | type | |||
| ) |  [static] | 
        
| static HTTPContext* find_rtp_session | ( | const char * | session_id | ) |  [static] | 
        
Definition at line 2793 of file ffserver.c.
Referenced by find_rtp_session_with_url(), and rtsp_cmd_setup().
| static HTTPContext* find_rtp_session_with_url | ( | const char * | url, | |
| const char * | session_id | |||
| ) |  [static] | 
        
Definition at line 2962 of file ffserver.c.
Referenced by rtsp_cmd_pause(), rtsp_cmd_play(), and rtsp_cmd_teardown().
| static int find_stream_in_feed | ( | FFStream * | feed, | |
| AVCodecContext * | codec, | |||
| int | bit_rate | |||
| ) |  [static] | 
        
| static RTSPTransportField* find_transport | ( | RTSPMessageHeader * | h, | |
| enum RTSPLowerTransport | lower_transport | |||
| ) |  [static] | 
        
| static void fmt_bytecount | ( | ByteIOContext * | pb, | |
| int64_t | count | |||
| ) |  [static] | 
        
| static void get_arg | ( | char * | buf, | |
| int | buf_size, | |||
| const char ** | pp | |||
| ) |  [static] | 
        
| static int64_t get_packet_send_clock | ( | HTTPContext * | c | ) |  [static] | 
        
| static int64_t get_server_clock | ( | HTTPContext * | c | ) |  [static] | 
        
| static void get_word | ( | char * | buf, | |
| int | buf_size, | |||
| const char ** | pp | |||
| ) |  [static] | 
        
Definition at line 1159 of file ffserver.c.
Referenced by http_parse_request(), rtsp_parse_request(), rtsp_send_cmd(), and sdp_parse_line().
| static void handle_child_exit | ( | int | sig | ) |  [static] | 
        
| static int handle_connection | ( | HTTPContext * | c | ) |  [static] | 
        
| static void http_av_log | ( | void * | ptr, | |
| int | level, | |||
| const char * | fmt, | |||
| va_list | vargs | |||
| ) |  [static] | 
        
| void http_log | ( | const char * | fmt, | |
| ... | ||||
| ) | 
Definition at line 345 of file ffserver.c.
Referenced by build_feed_streams(), build_file_streams(), http_av_log(), http_parse_request(), http_prepare_data(), http_receive_data(), http_server(), http_start_receive_data(), log_connection(), main(), new_connection(), open_input_stream(), rtp_new_av_stream(), start_children(), and start_multicast().
| static int http_parse_request | ( | HTTPContext * | c | ) |  [static] | 
        
| static int http_prepare_data | ( | HTTPContext * | c | ) |  [static] | 
        
| static int http_receive_data | ( | HTTPContext * | c | ) |  [static] | 
        
| static int http_send_data | ( | HTTPContext * | c | ) |  [static] | 
        
| static int http_server | ( | void | ) |  [static] | 
        
| static int http_start_receive_data | ( | HTTPContext * | c | ) |  [static] | 
        
| static void http_vlog | ( | const char * | fmt, | |
| va_list | vargs | |||
| ) |  [static] | 
        
| static void log_connection | ( | HTTPContext * | c | ) |  [static] | 
        
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) | 
Definition at line 4473 of file ffserver.c.
| static int modify_current_stream | ( | HTTPContext * | c, | |
| char * | rates | |||
| ) |  [static] | 
        
| static void new_connection | ( | int | server_fd, | |
| int | is_rtsp | |||
| ) |  [static] | 
        
| static int open_input_stream | ( | HTTPContext * | c, | |
| const char * | info | |||
| ) |  [static] | 
        
Definition at line 1937 of file ffserver.c.
Referenced by http_parse_request(), http_prepare_data(), rtsp_cmd_setup(), and start_multicast().
| static void open_parser | ( | AVFormatContext * | s, | |
| int | i | |||
| ) |  [static] | 
        
| static enum CodecID opt_audio_codec | ( | const char * | arg | ) |  [static] | 
        
Definition at line 3695 of file ffserver.c.
| static void opt_debug | ( | void | ) |  [static] | 
        
Definition at line 4447 of file ffserver.c.
| static void opt_show_help | ( | void | ) |  [static] | 
        
Definition at line 4454 of file ffserver.c.
| static enum CodecID opt_video_codec | ( | const char * | arg | ) |  [static] | 
        
Definition at line 3705 of file ffserver.c.
| static int parse_ffconfig | ( | const char * | filename | ) |  [static] | 
        
| static int prepare_sdp_description | ( | FFStream * | stream, | |
| uint8_t ** | pbuffer, | |||
| struct in_addr | my_ip | |||
| ) |  [static] | 
        
Definition at line 2709 of file ffserver.c.
Referenced by http_parse_request(), and rtsp_cmd_describe().
| static void remove_stream | ( | FFStream * | stream | ) |  [static] | 
        
| static int rtp_new_av_stream | ( | HTTPContext * | c, | |
| int | stream_index, | |||
| struct sockaddr_in * | dest_addr, | |||
| HTTPContext * | rtsp_c | |||
| ) |  [static] | 
        
| static HTTPContext * rtp_new_connection | ( | struct sockaddr_in * | from_addr, | |
| FFStream * | stream, | |||
| const char * | session_id, | |||
| enum RTSPLowerTransport | rtp_protocol | |||
| ) |  [static] | 
        
| static void rtsp_cmd_describe | ( | HTTPContext * | c, | |
| const char * | url | |||
| ) |  [static] | 
        
| static void rtsp_cmd_options | ( | HTTPContext * | c, | |
| const char * | url | |||
| ) |  [static] | 
        
| static void rtsp_cmd_pause | ( | HTTPContext * | c, | |
| const char * | url, | |||
| RTSPMessageHeader * | h | |||
| ) |  [static] | 
        
| static void rtsp_cmd_play | ( | HTTPContext * | c, | |
| const char * | url, | |||
| RTSPMessageHeader * | h | |||
| ) |  [static] | 
        
| static void rtsp_cmd_setup | ( | HTTPContext * | c, | |
| const char * | url, | |||
| RTSPMessageHeader * | h | |||
| ) |  [static] | 
        
| static void rtsp_cmd_teardown | ( | HTTPContext * | c, | |
| const char * | url, | |||
| RTSPMessageHeader * | h | |||
| ) |  [static] | 
        
| static int rtsp_parse_request | ( | HTTPContext * | c | ) |  [static] | 
        
| static void rtsp_reply_error | ( | HTTPContext * | c, | |
| enum RTSPStatusCode | error_number | |||
| ) |  [static] | 
        
Definition at line 2613 of file ffserver.c.
Referenced by rtsp_cmd_describe(), rtsp_cmd_pause(), rtsp_cmd_play(), rtsp_cmd_setup(), rtsp_cmd_teardown(), and rtsp_parse_request().
| static void rtsp_reply_header | ( | HTTPContext * | c, | |
| enum RTSPStatusCode | error_number | |||
| ) |  [static] | 
        
Definition at line 2554 of file ffserver.c.
Referenced by rtsp_cmd_describe(), rtsp_cmd_pause(), rtsp_cmd_play(), rtsp_cmd_setup(), rtsp_cmd_teardown(), and rtsp_reply_error().
| static void skip_spaces | ( | const char ** | pp | ) |  [static] | 
        
Definition at line 1150 of file ffserver.c.
Referenced by get_word(), get_word_sep(), hex_to_data(), rtsp_next_attr_and_value(), rtsp_parse_line(), rtsp_parse_range(), rtsp_parse_range_npt(), rtsp_parse_transport(), and sdp_parse().
| static int socket_open_listen | ( | struct sockaddr_in * | my_addr | ) |  [static] | 
        
| static void start_children | ( | FFStream * | feed | ) |  [static] | 
        
| static void start_multicast | ( | void | ) |  [static] | 
        
| static void start_wait_request | ( | HTTPContext * | c, | |
| int | is_rtsp | |||
| ) |  [static] | 
        
| static void update_datarate | ( | DataRateData * | drd, | |
| int64_t | count | |||
| ) |  [static] | 
        
| static int validate_acl | ( | FFStream * | stream, | |
| HTTPContext * | c | |||
| ) |  [static] | 
        
const char* config_filename [static]           | 
        
int64_t cur_time [static]           | 
        
Definition at line 310 of file ffserver.c.
Referenced by audio_read_packet(), compute_datarate(), get_server_clock(), handle_connection(), http_prepare_data(), http_server(), open_input_stream(), print_report(), start_wait_request(), update_datarate(), and video_refresh_timer().
uint64_t current_bandwidth [static]           | 
        
Definition at line 308 of file ffserver.c.
Referenced by close_connection(), compute_status(), http_parse_request(), and rtp_new_connection().
int ffserver_daemon [static]           | 
        
int ffserver_debug [static]           | 
        
Definition at line 297 of file ffserver.c.
Referenced by http_parse_request(), opt_debug(), parse_ffconfig(), and start_children().
FFStream* first_feed [static]           | 
        
Definition at line 257 of file ffserver.c.
HTTPContext* first_http_ctx [static]           | 
        
Definition at line 256 of file ffserver.c.
FFStream* first_stream [static]           | 
        
Definition at line 258 of file ffserver.c.
const char* http_state[] [static]           | 
        
Initial value:
 {
    "HTTP_WAIT_REQUEST",
    "HTTP_SEND_HEADER",
    "SEND_DATA_HEADER",
    "SEND_DATA",
    "SEND_DATA_TRAILER",
    "RECEIVE_DATA",
    "WAIT_FEED",
    "READY",
    "RTSP_WAIT_REQUEST",
    "RTSP_SEND_REPLY",
    "RTSP_SEND_PACKET",
}
Definition at line 82 of file ffserver.c.
Referenced by compute_status().
FILE* logfile = NULL [static]           | 
        
char logfilename[1024] [static]           | 
        
Definition at line 255 of file ffserver.c.
Referenced by av_encode(), main(), opt_debug(), and parse_ffconfig().
uint64_t max_bandwidth = 1000 [static]           | 
        
Definition at line 307 of file ffserver.c.
Referenced by compute_status(), http_parse_request(), and parse_ffconfig().
struct sockaddr_in my_http_addr [static]           | 
        
const char* my_program_dir [static]           | 
        
const char* my_program_name [static]           | 
        
struct sockaddr_in my_rtsp_addr [static]           | 
        
Definition at line 253 of file ffserver.c.
Referenced by http_parse_request(), http_server(), and parse_ffconfig().
unsigned int nb_connections [static]           | 
        
Definition at line 305 of file ffserver.c.
Referenced by close_connection(), compute_status(), new_connection(), and rtp_new_connection().
unsigned int nb_max_connections = 5 [static]           | 
        
Definition at line 304 of file ffserver.c.
Referenced by compute_status(), new_connection(), parse_ffconfig(), and rtp_new_connection().
unsigned int nb_max_http_connections = 2000 [static]           | 
        
int need_to_start_children [static]           | 
        
int no_launch [static]           | 
        
Initial value:
 {
    { "h", OPT_EXIT, {(void*)opt_show_help}, "show help" },
    { "version", OPT_EXIT, {(void*)show_version}, "show version" },
    { "L", OPT_EXIT, {(void*)show_license}, "show license" },
    { "formats", OPT_EXIT, {(void*)show_formats}, "show available formats, codecs, protocols, ..." },
    { "n", OPT_BOOL, {(void *)&no_launch }, "enable no-launch mode" },
    { "d", 0, {(void*)opt_debug}, "enable debug mode" },
    { "f", HAS_ARG | OPT_STRING, {(void*)&config_filename }, "use configfile instead of /etc/ffserver.conf", "configfile" },
    { NULL },
}
Definition at line 65 of file ffserver.c.
| const int program_birth_year = 2000 | 
program birth year, defined by the program for show_banner()
Definition at line 63 of file ffserver.c.
Referenced by show_banner().
| const char program_name[] = "FFserver" | 
program name, defined by the program for show_version().
Definition at line 62 of file ffserver.c.
Referenced by compute_status(), show_banner(), show_license(), and show_version().
AVRandomState random_state [static]           | 
        
Definition at line 312 of file ffserver.c.
 1.5.8