ffserver.c File Reference

#include "config.h"
#include <string.h>
#include <stdlib.h>
#include "avformat.h"
#include "rtsp.h"
#include "rtp.h"
#include "os_support.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 "network.h"
#include "version.h"
#include "ffserver.h"
#include "random.h"
#include "avstring.h"
#include "cmdutils.h"

Go to the source code of this file.

Data Structures

struct  DataRateData
struct  HTTPContext
struct  IPAddressACL
struct  FFStream
struct  FeedData

Defines

#define closesocket   close
#define HTTP_MAX_CONNECTIONS   2000
#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_stats (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, RTSPHeader *h)
static void rtsp_cmd_play (HTTPContext *c, const char *url, RTSPHeader *h)
static void rtsp_cmd_pause (HTTPContext *c, const char *url, RTSPHeader *h)
static void rtsp_cmd_teardown (HTTPContext *c, const char *url, RTSPHeader *h)
static int prepare_sdp_description (FFStream *stream, uint8_t **pbuffer, struct in_addr my_ip)
static HTTPContextrtp_new_connection (struct sockaddr_in *from_addr, FFStream *stream, const char *session_id, enum RTSPProtocol rtp_protocol)
static int rtp_new_av_stream (HTTPContext *c, int stream_index, struct sockaddr_in *dest_addr, HTTPContext *rtsp_c)
static void http_log (const char *fmt,...)
static char * ctime1 (char *buf2)
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 HTTPContextfind_rtp_session (const char *session_id)
static RTSPTransportFieldfind_transport (RTSPHeader *h, enum RTSPProtocol protocol)
static HTTPContextfind_rtp_session_with_url (const char *url, const char *session_id)
static AVStreamadd_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 int opt_audio_codec (const char *arg)
static int opt_video_codec (const char *arg)
static int parse_ffconfig (const char *filename)
static void show_help (void)
static void handle_child_exit (int sig)
int main (int argc, char **argv)

Variables

static const char program_name [] = "FFserver"
static const int program_birth_year = 2000
const char * http_state []
static AVFrame dummy_frame
static struct sockaddr_in my_http_addr
static struct sockaddr_in my_rtsp_addr
static char logfilename [1024]
static HTTPContextfirst_http_ctx
static FFStreamfirst_feed
static FFStreamfirst_stream
static const char * my_program_name
static const char * my_program_dir
static int ffserver_debug
static int ffserver_daemon
static int no_launch
static int need_to_start_children
static int nb_max_connections
static int nb_connections
static int max_bandwidth
static int current_bandwidth
static int64_t cur_time
static AVRandomState random_state
static FILE * logfile = NULL


Define Documentation

#define CHECK_CODEC (  )     (ccf->x != ccs->x)

Referenced by build_feed_streams().

#define closesocket   close

#define HTTP_MAX_CONNECTIONS   2000

Definition at line 63 of file ffserver.c.

Referenced by parse_ffconfig().

#define HTTP_REQUEST_TIMEOUT   (15 * 1000)

Definition at line 99 of file ffserver.c.

Referenced by start_wait_request().

#define IOBUFFER_INIT_SIZE   8192

Definition at line 96 of file ffserver.c.

Referenced by new_connection(), and rtp_new_connection().

#define RTSP_REQUEST_TIMEOUT   (3600 * 24 * 1000)

Definition at line 100 of file ffserver.c.

Referenced by start_wait_request().

#define SYNC_TIMEOUT   (10 * 1000)

Definition at line 102 of file ffserver.c.


Enumeration Type Documentation

enum HTTPState

Enumerator:
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 

Definition at line 65 of file ffserver.c.

Enumerator:
IP_ALLOW 
IP_DENY 

Definition at line 181 of file ffserver.c.

enum RedirType

Enumerator:
REDIR_NONE 
REDIR_ASX 
REDIR_RAM 
REDIR_ASF 
REDIR_RTSP 
REDIR_SDP 

Definition at line 1164 of file ffserver.c.

enum StreamType

Enumerator:
STREAM_TYPE_LIVE 
STREAM_TYPE_STATUS 
STREAM_TYPE_REDIRECT 

Definition at line 175 of file ffserver.c.


Function Documentation

static int add_av_stream ( FFStream feed,
AVStream st 
) [static]

Definition at line 3192 of file ffserver.c.

Referenced by build_feed_streams().

static AVStream* add_av_stream1 ( FFStream stream,
AVCodecContext codec 
) [static]

Definition at line 3174 of file ffserver.c.

Referenced by add_av_stream(), and build_file_streams().

static void add_codec ( FFStream stream,
AVCodecContext av 
) [static]

Definition at line 3555 of file ffserver.c.

Referenced by parse_ffconfig().

static void build_feed_streams ( void   )  [static]

Definition at line 3345 of file ffserver.c.

Referenced by main().

static void build_file_streams ( void   )  [static]

Definition at line 3296 of file ffserver.c.

Referenced by main().

static void close_connection ( HTTPContext c  )  [static]

Definition at line 696 of file ffserver.c.

Referenced by http_server(), and rtsp_cmd_teardown().

static void compute_bandwidth ( void   )  [static]

Definition at line 3500 of file ffserver.c.

Referenced by main().

static int compute_datarate ( DataRateData drd,
int64_t  count 
) [static]

Definition at line 361 of file ffserver.c.

Referenced by compute_stats().

static void compute_real_filename ( char *  filename,
int  max_size 
) [static]

Definition at line 1140 of file ffserver.c.

Referenced by http_parse_request().

static void compute_stats ( HTTPContext c  )  [static]

Definition at line 1593 of file ffserver.c.

Referenced by http_parse_request().

static char* ctime1 ( char *  buf2  )  [static]

Definition at line 320 of file ffserver.c.

Referenced by log_connection(), and rtp_new_av_stream().

static void do_switch_stream ( HTTPContext c,
int  i 
) [static]

Definition at line 1080 of file ffserver.c.

Referenced by http_parse_request(), and http_prepare_data().

static void extract_mpeg4_header ( AVFormatContext infile  )  [static]

Definition at line 3247 of file ffserver.c.

Referenced by build_file_streams().

static int extract_rates ( char *  rates,
int  ratelen,
const char *  request 
) [static]

Definition at line 957 of file ffserver.c.

Referenced by http_parse_request().

static HTTPContext* find_rtp_session ( const char *  session_id  )  [static]

Definition at line 2725 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 2894 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]

Definition at line 1004 of file ffserver.c.

Referenced by modify_current_stream().

static RTSPTransportField* find_transport ( RTSPHeader h,
enum RTSPProtocol  protocol 
) [static]

Definition at line 2739 of file ffserver.c.

Referenced by rtsp_cmd_setup().

static void fmt_bytecount ( ByteIOContext pb,
int64_t  count 
) [static]

Definition at line 1583 of file ffserver.c.

Referenced by compute_stats().

static void get_arg ( char *  buf,
int  buf_size,
const char **  pp 
) [static]

Definition at line 3522 of file ffserver.c.

Referenced by parse_ffconfig().

static int64_t get_packet_send_clock ( HTTPContext c  )  [static]

Definition at line 1971 of file ffserver.c.

Referenced by http_send_data().

static int64_t get_server_clock ( HTTPContext c  )  [static]

Definition at line 1963 of file ffserver.c.

Referenced by http_send_data().

static void get_word ( char *  buf,
int  buf_size,
const char **  pp 
) [static]

Definition at line 1103 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]

Definition at line 4317 of file ffserver.c.

Referenced by main().

static int handle_connection ( HTTPContext c  )  [static]

Definition at line 780 of file ffserver.c.

Referenced by http_server().

static void http_log ( const char *  fmt,
  ... 
) [static]

static int http_parse_request ( HTTPContext c  )  [static]

Definition at line 1174 of file ffserver.c.

Referenced by handle_connection().

static int http_prepare_data ( HTTPContext c  )  [static]

Definition at line 1986 of file ffserver.c.

Referenced by http_send_data().

static int http_receive_data ( HTTPContext c  )  [static]

Definition at line 2372 of file ffserver.c.

Referenced by handle_connection().

static int http_send_data ( HTTPContext c  )  [static]

Definition at line 2225 of file ffserver.c.

Referenced by handle_connection().

static int http_server ( void   )  [static]

Definition at line 514 of file ffserver.c.

Referenced by main().

static int http_start_receive_data ( HTTPContext c  )  [static]

Definition at line 2344 of file ffserver.c.

Referenced by http_parse_request().

static void log_connection ( HTTPContext c  )  [static]

Definition at line 334 of file ffserver.c.

Referenced by http_server().

int main ( int  argc,
char **  argv 
)

Definition at line 4342 of file ffserver.c.

static int modify_current_stream ( HTTPContext c,
char *  rates 
) [static]

Definition at line 1041 of file ffserver.c.

Referenced by http_parse_request().

static void new_connection ( int  server_fd,
int  is_rtsp 
) [static]

Definition at line 649 of file ffserver.c.

Referenced by http_server().

static int open_input_stream ( HTTPContext c,
const char *  info 
) [static]

static void open_parser ( AVFormatContext s,
int  i 
) [static]

Definition at line 1867 of file ffserver.c.

Referenced by open_input_stream().

static int opt_audio_codec ( const char *  arg  )  [static]

Definition at line 3628 of file ffserver.c.

static int opt_video_codec ( const char *  arg  )  [static]

Definition at line 3638 of file ffserver.c.

static int parse_ffconfig ( const char *  filename  )  [static]

Definition at line 3674 of file ffserver.c.

Referenced by main().

static int prepare_sdp_description ( FFStream stream,
uint8_t **  pbuffer,
struct in_addr  my_ip 
) [static]

Definition at line 2638 of file ffserver.c.

Referenced by http_parse_request(), and rtsp_cmd_describe().

static void remove_stream ( FFStream stream  )  [static]

Definition at line 3234 of file ffserver.c.

Referenced by build_file_streams().

static int rtp_new_av_stream ( HTTPContext c,
int  stream_index,
struct sockaddr_in *  dest_addr,
HTTPContext rtsp_c 
) [static]

Definition at line 3076 of file ffserver.c.

Referenced by rtsp_cmd_setup(), and start_multicast().

static HTTPContext * rtp_new_connection ( struct sockaddr_in *  from_addr,
FFStream stream,
const char *  session_id,
enum RTSPProtocol  rtp_protocol 
) [static]

Definition at line 3010 of file ffserver.c.

Referenced by rtsp_cmd_setup(), and start_multicast().

static void rtsp_cmd_describe ( HTTPContext c,
const char *  url 
) [static]

Definition at line 2681 of file ffserver.c.

Referenced by rtsp_parse_request().

static void rtsp_cmd_options ( HTTPContext c,
const char *  url 
) [static]

Definition at line 2672 of file ffserver.c.

Referenced by rtsp_parse_request().

static void rtsp_cmd_pause ( HTTPContext c,
const char *  url,
RTSPHeader h 
) [static]

Definition at line 2958 of file ffserver.c.

Referenced by rtsp_parse_request().

static void rtsp_cmd_play ( HTTPContext c,
const char *  url,
RTSPHeader h 
) [static]

Definition at line 2924 of file ffserver.c.

Referenced by rtsp_parse_request().

static void rtsp_cmd_setup ( HTTPContext c,
const char *  url,
RTSPHeader h 
) [static]

Definition at line 2752 of file ffserver.c.

Referenced by rtsp_parse_request().

static void rtsp_cmd_teardown ( HTTPContext c,
const char *  url,
RTSPHeader h 
) [static]

Definition at line 2983 of file ffserver.c.

Referenced by rtsp_parse_request().

static int rtsp_parse_request ( HTTPContext c  )  [static]

Definition at line 2548 of file ffserver.c.

Referenced by handle_connection().

static void rtsp_reply_error ( HTTPContext c,
enum RTSPStatusCode  error_number 
) [static]

static void rtsp_reply_header ( HTTPContext c,
enum RTSPStatusCode  error_number 
) [static]

static void show_help ( void   )  [static]

Definition at line 4306 of file ffserver.c.

static void skip_spaces ( const char **  pp  )  [static]

static int socket_open_listen ( struct sockaddr_in *  my_addr  )  [static]

Definition at line 427 of file ffserver.c.

Referenced by http_server().

static void start_children ( FFStream feed  )  [static]

Definition at line 370 of file ffserver.c.

Referenced by http_server().

static void start_multicast ( void   )  [static]

Definition at line 459 of file ffserver.c.

Referenced by http_server().

static void start_wait_request ( HTTPContext c,
int  is_rtsp 
) [static]

Definition at line 635 of file ffserver.c.

Referenced by handle_connection(), and new_connection().

static void update_datarate ( DataRateData drd,
int64_t  count 
) [static]

Definition at line 347 of file ffserver.c.

Referenced by http_receive_data(), and http_send_data().

static int validate_acl ( FFStream stream,
HTTPContext c 
) [static]

Definition at line 1121 of file ffserver.c.

Referenced by http_parse_request().


Variable Documentation

int64_t cur_time [static]

int current_bandwidth [static]

AVFrame dummy_frame [static]

Definition at line 172 of file ffserver.c.

int ffserver_daemon [static]

Definition at line 292 of file ffserver.c.

Referenced by main(), and parse_ffconfig().

int ffserver_debug [static]

Definition at line 291 of file ffserver.c.

Referenced by http_parse_request(), main(), parse_ffconfig(), and start_children().

FFStream* first_feed [static]

Definition at line 252 of file ffserver.c.

Definition at line 251 of file ffserver.c.

Definition at line 253 of file ffserver.c.

const char* http_state[]

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 80 of file ffserver.c.

Referenced by compute_stats().

FILE* logfile = NULL [static]

Definition at line 306 of file ffserver.c.

Referenced by http_log(), and main().

char logfilename[1024] [static]

Definition at line 250 of file ffserver.c.

Referenced by av_encode(), main(), and parse_ffconfig().

int max_bandwidth [static]

Definition at line 299 of file ffserver.c.

Referenced by compute_stats(), http_parse_request(), main(), and parse_ffconfig().

struct sockaddr_in my_http_addr [static]

Definition at line 247 of file ffserver.c.

Referenced by http_server(), main(), and parse_ffconfig().

const char* my_program_dir [static]

Definition at line 289 of file ffserver.c.

Referenced by main(), and start_children().

const char* my_program_name [static]

Definition at line 288 of file ffserver.c.

Referenced by main(), and start_children().

struct sockaddr_in my_rtsp_addr [static]

Definition at line 248 of file ffserver.c.

Referenced by http_parse_request(), http_server(), main(), and parse_ffconfig().

int nb_connections [static]

int nb_max_connections [static]

Definition at line 296 of file ffserver.c.

Referenced by compute_stats(), main(), new_connection(), parse_ffconfig(), and rtp_new_connection().

int need_to_start_children [static]

Definition at line 294 of file ffserver.c.

Referenced by handle_child_exit(), and http_server().

int no_launch [static]

Definition at line 293 of file ffserver.c.

Referenced by main(), and start_children().

const int program_birth_year = 2000 [static]

Definition at line 60 of file ffserver.c.

const char program_name[] = "FFserver" [static]

Definition at line 59 of file ffserver.c.

Definition at line 304 of file ffserver.c.


Generated on Fri Oct 3 22:46:54 2008 for ffmpeg by  doxygen 1.5.6