FFmpeg
|
multiple format streaming server based on the FFmpeg libraries More...
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "libavformat/avformat.h"
#include "libavformat/ffm.h"
#include "libavformat/network.h"
#include "libavformat/os_support.h"
#include "libavformat/rtpdec.h"
#include "libavformat/rtpproto.h"
#include "libavformat/rtsp.h"
#include "libavformat/rtspcodes.h"
#include "libavformat/avio_internal.h"
#include "libavformat/internal.h"
#include "libavformat/url.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/lfg.h"
#include "libavutil/dict.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/random_seed.h"
#include "libavutil/parseutils.h"
#include "libavutil/opt.h"
#include "libavutil/time.h"
#include <stdarg.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/wait.h>
#include <signal.h>
#include "cmdutils.h"
#include "ffserver_config.h"
#include "cmdutils_common_opts.h"
Go to the source code of this file.
Data Structures | |
struct | RTSPActionServerSetup |
struct | DataRateData |
struct | HTTPContext |
struct | FeedData |
Macros | |
#define | closesocket close |
#define | PATH_LENGTH 1024 |
#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) |
Functions | |
static void | new_connection (int server_fd, int is_rtsp) |
static void | close_connection (HTTPContext *c) |
static int | handle_connection (HTTPContext *c) |
static void | print_stream_params (AVIOContext *pb, FFServerStream *stream) |
static void | compute_status (HTTPContext *c) |
static int | open_input_stream (HTTPContext *c, const char *info) |
static int | http_parse_request (HTTPContext *c) |
static int | http_send_data (HTTPContext *c) |
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_interrupt (HTTPContext *c, const char *url, RTSPMessageHeader *h, int pause_only) |
static int | prepare_sdp_description (FFServerStream *stream, uint8_t **pbuffer, struct in_addr my_ip) |
static HTTPContext * | rtp_new_connection (struct sockaddr_in *from_addr, FFServerStream *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) |
add a new RTP stream in an RTP connection (used in RTSP SETUP command). More... | |
static size_t | htmlencode (const char *src, char **dest) |
Substitutes known conflicting chars on a text string with their corresponding HTML entities. More... | |
static void | cp_html_entity (char *buffer, const char *entity) |
static int | check_codec_match (AVCodecContext *ccf, AVCodecContext *ccs, int stream) |
static int64_t | ffm_read_write_index (int fd) |
static int | ffm_write_write_index (int fd, int64_t pos) |
static void | ffm_set_write_index (AVFormatContext *s, int64_t pos, int64_t file_size) |
static char * | ctime1 (char *buf2, size_t buf_size) |
static void | http_vlog (const char *fmt, va_list vargs) |
static 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 (FFServerStream *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 void | http_send_too_busy_reply (int fd) |
static int | extract_rates (char *rates, int ratelen, const char *request) |
static int | find_stream_in_feed (FFServerStream *feed, AVCodecContext *codec, int bit_rate) |
static int | modify_current_stream (HTTPContext *c, char *rates) |
static void | get_word (char *buf, int buf_size, const char **pp) |
static FFServerIPAddressACL * | parse_dynamic_acl (FFServerStream *stream, HTTPContext *c) |
static void | free_acl_list (FFServerIPAddressACL *in_acl) |
static int | validate_acl_list (FFServerIPAddressACL *in_acl, HTTPContext *c) |
static int | validate_acl (FFServerStream *stream, HTTPContext *c) |
static void | compute_real_filename (char *filename, int max_size) |
compute the real filename of a file by matching it without its extensions to all the stream's filenames More... | |
static void | fmt_bytecount (AVIOContext *pb, int64_t count) |
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) |
find an RTP connection by using the session ID. More... | |
static AVStream * | add_av_stream1 (FFServerStream *stream, AVCodecContext *codec, int copy) |
static int | add_av_stream (FFServerStream *feed, AVStream *st) |
static void | remove_stream (FFServerStream *stream) |
static void | extract_mpeg4_header (AVFormatContext *infile) |
static void | build_file_streams (void) |
static int | build_feed_streams (void) |
static void | compute_bandwidth (void) |
static void | handle_child_exit (int sig) |
static void | opt_debug (void) |
void | show_help_default (const char *opt, const char *arg) |
Per-fftool specific help handler. More... | |
int | main (int argc, char **argv) |
Variables | |
const char | program_name [] = "ffserver" |
program name, defined by the program for show_version(). More... | |
const int | program_birth_year = 2000 |
program birth year, defined by the program for show_banner() More... | |
static const OptionDef | options [] |
static const char *const | http_state [] |
static HTTPContext * | first_http_ctx |
static FFServerConfig | config |
static const char * | my_program_name |
static int | no_launch |
static int | need_to_start_children |
static unsigned int | nb_connections |
static uint64_t | current_bandwidth |
static int64_t | cur_time |
static AVLFG | random_state |
static FILE * | logfile = NULL |
multiple format streaming server based on the FFmpeg libraries
Definition in file ffserver.c.
#define closesocket close |
Definition at line 28 of file ffserver.c.
Referenced by close_connection(), ff_listen_bind(), http_server(), new_connection(), sctp_close(), sctp_open(), socket_open_listen(), tcp_close(), tcp_open(), udp_close(), udp_open(), udp_socket_create(), unix_close(), and unix_open().
#define PATH_LENGTH 1024 |
Definition at line 74 of file ffserver.c.
Referenced by start_children().
#define IOBUFFER_INIT_SIZE 8192 |
Definition at line 112 of file ffserver.c.
Referenced by new_connection(), and rtp_new_connection().
#define HTTP_REQUEST_TIMEOUT (15 * 1000) |
Definition at line 115 of file ffserver.c.
Referenced by start_wait_request().
#define RTSP_REQUEST_TIMEOUT (3600 * 24 * 1000) |
Definition at line 116 of file ffserver.c.
Referenced by start_wait_request().
#define SYNC_TIMEOUT (10 * 1000) |
Definition at line 118 of file ffserver.c.
#define CHECK_CODEC | ( | x | ) | (ccf->x != ccs->x) |
Referenced by check_codec_match().
enum HTTPState |
Definition at line 81 of file ffserver.c.
enum RedirType |
Enumerator | |
---|---|
REDIR_NONE | |
REDIR_ASX | |
REDIR_RAM | |
REDIR_ASF | |
REDIR_RTSP | |
REDIR_SDP |
Definition at line 1409 of file ffserver.c.
|
static |
Definition at line 836 of file ffserver.c.
Referenced by http_server().
|
static |
Definition at line 887 of file ffserver.c.
Referenced by handle_connection(), http_server(), and rtsp_cmd_interrupt().
|
static |
Definition at line 971 of file ffserver.c.
Referenced by http_server().
|
inlinestatic |
Definition at line 1870 of file ffserver.c.
Referenced by compute_status().
|
static |
Definition at line 1916 of file ffserver.c.
Referenced by http_parse_request().
|
static |
Definition at line 2147 of file ffserver.c.
Referenced by http_parse_request(), http_prepare_data(), rtsp_cmd_setup(), and start_multicast().
|
static |
Definition at line 1419 of file ffserver.c.
Referenced by handle_connection().
|
static |
Definition at line 2500 of file ffserver.c.
Referenced by handle_connection().
|
static |
Definition at line 2621 of file ffserver.c.
Referenced by http_parse_request().
|
static |
Definition at line 2682 of file ffserver.c.
Referenced by handle_connection().
|
static |
Definition at line 2872 of file ffserver.c.
Referenced by handle_connection().
|
static |
Definition at line 3023 of file ffserver.c.
Referenced by rtsp_parse_request().
|
static |
Definition at line 3013 of file ffserver.c.
Referenced by rtsp_parse_request().
|
static |
Definition at line 3098 of file ffserver.c.
Referenced by rtsp_parse_request().
|
static |
Definition at line 3281 of file ffserver.c.
Referenced by rtsp_parse_request().
|
static |
Definition at line 3307 of file ffserver.c.
Referenced by rtsp_parse_request().
|
static |
Definition at line 2961 of file ffserver.c.
Referenced by http_parse_request(), and rtsp_cmd_describe().
|
static |
Definition at line 3341 of file ffserver.c.
Referenced by rtsp_cmd_setup(), and start_multicast().
|
static |
add a new RTP stream in an RTP connection (used in RTSP SETUP command).
If RTP/TCP protocol is used, TCP connection 'rtsp_c' is used.
Definition at line 3410 of file ffserver.c.
Referenced by rtsp_cmd_setup(), and start_multicast().
|
static |
Substitutes known conflicting chars on a text string with their corresponding HTML entities.
Returns the number of bytes in the 'encoded' representation not including the terminating NUL.
Definition at line 282 of file ffserver.c.
Referenced by http_parse_request().
|
inlinestatic |
Definition at line 268 of file ffserver.c.
Referenced by htmlencode().
|
inlinestatic |
Definition at line 3712 of file ffserver.c.
Referenced by build_feed_streams().
|
static |
Definition at line 343 of file ffserver.c.
Referenced by build_feed_streams(), and http_start_receive_data().
|
static |
Definition at line 354 of file ffserver.c.
Referenced by http_receive_data(), and http_start_receive_data().
|
static |
Definition at line 372 of file ffserver.c.
Referenced by http_prepare_data().
|
static |
Definition at line 380 of file ffserver.c.
Referenced by http_vlog().
|
static |
Definition at line 398 of file ffserver.c.
Referenced by http_av_log(), and http_log().
|
static |
Definition at line 418 of file ffserver.c.
Referenced by build_feed_streams(), build_file_streams(), check_codec_match(), 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().
Definition at line 426 of file ffserver.c.
Referenced by main().
|
static |
Definition at line 438 of file ffserver.c.
Referenced by http_server().
|
static |
Definition at line 448 of file ffserver.c.
Referenced by http_receive_data(), and http_send_data().
|
static |
Definition at line 462 of file ffserver.c.
Referenced by compute_status().
|
static |
FIXME: WIP Safeguard. Remove after clearing all harcoded '1024' path lengths
Definition at line 471 of file ffserver.c.
Referenced by http_server().
|
static |
Definition at line 555 of file ffserver.c.
Referenced by http_server().
Definition at line 594 of file ffserver.c.
Referenced by http_server().
|
static |
Definition at line 654 of file ffserver.c.
Referenced by main().
|
static |
Definition at line 804 of file ffserver.c.
Referenced by handle_connection(), and new_connection().
|
static |
Definition at line 814 of file ffserver.c.
Referenced by new_connection().
|
static |
Definition at line 1152 of file ffserver.c.
Referenced by http_parse_request().
|
static |
Definition at line 1199 of file ffserver.c.
Referenced by modify_current_stream().
|
static |
Definition at line 1237 of file ffserver.c.
Referenced by http_parse_request().
|
static |
Definition at line 1277 of file ffserver.c.
Referenced by http_parse_request(), and rtsp_parse_request().
|
static |
Definition at line 1295 of file ffserver.c.
Referenced by validate_acl().
|
static |
Definition at line 1336 of file ffserver.c.
Referenced by validate_acl().
|
static |
Definition at line 1348 of file ffserver.c.
Referenced by validate_acl().
|
static |
Definition at line 1365 of file ffserver.c.
Referenced by http_parse_request().
|
static |
compute the real filename of a file by matching it without its extensions to all the stream's filenames
Definition at line 1386 of file ffserver.c.
Referenced by http_parse_request().
|
static |
Definition at line 1860 of file ffserver.c.
Referenced by compute_status().
|
static |
Definition at line 2233 of file ffserver.c.
Referenced by http_send_data().
|
static |
Definition at line 2240 of file ffserver.c.
Referenced by http_send_data().
|
static |
Definition at line 2254 of file ffserver.c.
Referenced by http_send_data().
|
static |
Definition at line 2845 of file ffserver.c.
Referenced by rtsp_cmd_describe(), rtsp_cmd_interrupt(), rtsp_cmd_play(), rtsp_cmd_setup(), and rtsp_reply_error().
|
static |
Definition at line 2866 of file ffserver.c.
Referenced by rtsp_cmd_describe(), rtsp_cmd_interrupt(), rtsp_cmd_play(), rtsp_cmd_setup(), and rtsp_parse_request().
|
static |
Definition at line 3071 of file ffserver.c.
Referenced by find_rtp_session_with_url(), and rtsp_cmd_setup().
|
static |
Definition at line 3085 of file ffserver.c.
Referenced by rtsp_cmd_setup().
|
static |
find an RTP connection by using the session ID.
Check consistency with filename
Definition at line 3247 of file ffserver.c.
Referenced by rtsp_cmd_interrupt(), and rtsp_cmd_play().
|
static |
Definition at line 3512 of file ffserver.c.
Referenced by add_av_stream(), and build_file_streams().
|
static |
Definition at line 3546 of file ffserver.c.
Referenced by build_feed_streams().
|
static |
Definition at line 3588 of file ffserver.c.
Referenced by build_file_streams().
|
static |
Definition at line 3601 of file ffserver.c.
Referenced by build_file_streams().
Definition at line 3652 of file ffserver.c.
Referenced by main().
|
static |
Definition at line 3747 of file ffserver.c.
Referenced by main().
Definition at line 3896 of file ffserver.c.
Referenced by main().
|
static |
Definition at line 3919 of file ffserver.c.
Referenced by main().
Definition at line 3948 of file ffserver.c.
void show_help_default | ( | const char * | opt, |
const char * | arg | ||
) |
Per-fftool specific help handler.
Implemented in each fftool, called by show_help().
Definition at line 3954 of file ffserver.c.
Referenced by show_help().
int main | ( | int | argc, |
char ** | argv | ||
) |
Definition at line 3970 of file ffserver.c.
const char program_name[] = "ffserver" |
program name, defined by the program for show_version().
Definition at line 76 of file ffserver.c.
Referenced by compute_status(), expand_filename_template(), init_report(), print_program_info(), show_help_default(), show_license(), and show_usage().
const int program_birth_year = 2000 |
program birth year, defined by the program for show_banner()
Definition at line 77 of file ffserver.c.
Referenced by print_program_info().
|
static |
Definition at line 79 of file ffserver.c.
|
static |
Definition at line 96 of file ffserver.c.
Referenced by compute_status().
|
static |
Definition at line 200 of file ffserver.c.
Referenced by close_connection(), compute_status(), http_server(), new_connection(), and rtp_new_connection().
|
static |
Definition at line 202 of file ffserver.c.
Referenced by dshow_cycle_formats(), dshow_set_audio_buffer_size(), dxva2_create_decoder(), parse_dsd_prop(), parse_fmtp_config(), and wavpack_encode_init().
|
static |
Definition at line 251 of file ffserver.c.
Referenced by main(), and start_children().
|
static |
Definition at line 253 of file ffserver.c.
Referenced by start_children().
|
static |
Definition at line 254 of file ffserver.c.
Referenced by handle_child_exit(), and http_server().
|
static |
Definition at line 257 of file ffserver.c.
Referenced by close_connection(), compute_status(), http_send_too_busy_reply(), new_connection(), and rtp_new_connection().
|
static |
Definition at line 259 of file ffserver.c.
Referenced by close_connection(), compute_status(), http_parse_request(), and rtp_new_connection().
|
static |
Definition at line 262 of file ffserver.c.
Referenced by audio_read_packet(), check_keyboard_interaction(), compute_datarate(), get_server_clock(), handle_connection(), http_prepare_data(), http_server(), open_input_stream(), output_segment_list(), print_report(), start_wait_request(), transcode(), update_datarate(), and video_refresh().
|
static |
Definition at line 264 of file ffserver.c.
|
static |
Definition at line 266 of file ffserver.c.
Referenced by http_vlog(), and main().