Newer
Older
* Copyright (c) 2000, 2001, 2002 Fabrice Bellard
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define HAVE_AV_CONFIG_H
#include "avformat.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <errno.h>
#include <sys/time.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
Fabrice Bellard
committed
#include <dlfcn.h>
#include "ffserver.h"
/* maximum number of simultaneous HTTP connections */
#define HTTP_MAX_CONNECTIONS 2000
enum HTTPState {
HTTPSTATE_WAIT_REQUEST,
HTTPSTATE_SEND_HEADER,
HTTPSTATE_SEND_DATA_HEADER,
Fabrice Bellard
committed
HTTPSTATE_SEND_DATA, /* sending TCP or UDP data */
Fabrice Bellard
committed
HTTPSTATE_RECEIVE_DATA,
HTTPSTATE_WAIT_FEED, /* wait for data from the feed */
HTTPSTATE_WAIT, /* wait before sending next packets */
HTTPSTATE_WAIT_SHORT, /* short wait for short term
bandwidth limitation */
HTTPSTATE_READY,
RTSPSTATE_WAIT_REQUEST,
RTSPSTATE_SEND_REPLY,
Fabrice Bellard
committed
"HTTP_WAIT_REQUEST",
"HTTP_SEND_HEADER",
"SEND_DATA_HEADER",
"SEND_DATA",
"SEND_DATA_TRAILER",
"RECEIVE_DATA",
"WAIT_FEED",
Fabrice Bellard
committed
"WAIT",
"WAIT_SHORT",
"READY",
"RTSP_WAIT_REQUEST",
"RTSP_SEND_REPLY",
/* coef for exponential mean for bitrate estimation in statistics */
#define AVG_COEF 0.9
/* timeouts are in ms */
Fabrice Bellard
committed
#define HTTP_REQUEST_TIMEOUT (15 * 1000)
#define RTSP_REQUEST_TIMEOUT (3600 * 24 * 1000)
typedef struct {
INT64 count1, count2;
long time1, time2;
} DataRateData;
/* context associated with one connection */
typedef struct HTTPContext {
enum HTTPState state;
int fd; /* socket file descriptor */
struct sockaddr_in from_addr; /* origin */
struct pollfd *poll_entry; /* used when polling */
long timeout;
UINT8 *buffer_ptr, *buffer_end;
int http_error;
struct HTTPContext *next;
int got_key_frame; /* stream 0 => 1, stream 1 => 2, stream 2=> 4 */
INT64 data_count;
/* feed input */
int feed_fd;
/* input format handling */
AVFormatContext *fmt_in;
Fabrice Bellard
committed
long start_time; /* In milliseconds - this wraps fairly often */
INT64 first_pts; /* initial pts value */
int pts_stream_index; /* stream we choose as clock reference */
/* -1 is invalid stream */
int feed_streams[MAX_STREAMS]; /* index of streams in the feed */
int switch_feed_streams[MAX_STREAMS]; /* index of streams in the feed */
int switch_pending;
Fabrice Bellard
committed
AVFormatContext fmt_ctx; /* instance of FFStream for one user */
int suppress_log;
int wmp_client_id;
char protocol[16];
char method[16];
char url[128];
Fabrice Bellard
committed
int is_packetized; /* if true, the stream is packetized */
int packet_stream_index; /* current stream for output in state machine */
/* RTSP state specific */
UINT8 *pb_buffer; /* XXX: use that in all the code */
ByteIOContext *pb;
int seq; /* RTSP sequence number */
/* RTP state specific */
enum RTSPProtocol rtp_protocol;
char session_id[32]; /* session id */
AVFormatContext *rtp_ctx[MAX_STREAMS];
URLContext *rtp_handles[MAX_STREAMS];
/* RTP short term bandwidth limitation */
int packet_byte_count;
int packet_start_time_us; /* used for short durations (a few
seconds max) */
} HTTPContext;
/* each generated stream is described here */
enum StreamType {
STREAM_TYPE_LIVE,
STREAM_TYPE_STATUS,
enum IPAddressAction {
IP_ALLOW = 1,
IP_DENY,
};
typedef struct IPAddressACL {
struct IPAddressACL *next;
enum IPAddressAction action;
struct in_addr first;
struct in_addr last;
} IPAddressACL;
/* description of each stream of the ffserver.conf file */
typedef struct FFStream {
enum StreamType stream_type;
char filename[1024]; /* stream filename */
Fabrice Bellard
committed
struct FFStream *feed; /* feed we are using (can be null if
coming from file) */
IPAddressACL *acl;
int prebuffer; /* Number of millseconds early to start */
long max_time; /* Number of milliseconds to run */
Philip Gladstone
committed
int send_on_key;
AVStream *streams[MAX_STREAMS];
int feed_streams[MAX_STREAMS]; /* index of streams in the feed */
char feed_filename[1024]; /* file name of the feed storage, or
input file name for a stream */
char author[512];
char title[512];
char copyright[512];
char comment[512];
time_t pid_start; /* Of ffmpeg process */
int bandwidth; /* bandwidth, in kbits/s */
Fabrice Bellard
committed
/* RTSP options */
char *rtsp_option;
Fabrice Bellard
committed
/* multicast specific */
int is_multicast;
struct in_addr multicast_ip;
int multicast_port; /* first port used for multicast */
int multicast_ttl;
int loop; /* if true, send the stream in loops (only meaningful if file) */
Loading
Loading full blame...