Skip to content

Commit

Permalink
Refine SRT code, with StateThread adpater
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhihong committed Apr 15, 2022
1 parent 2b2379d commit 95ad1c7
Show file tree
Hide file tree
Showing 26 changed files with 4,126 additions and 56 deletions.
6 changes: 0 additions & 6 deletions trunk/auto/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,6 @@ function apply_auto_options() {
SRS_TOOL_LD=$SRS_TOOL_CC
fi

# The SRT code in SRS requires c++11, although we build libsrt without c++11.
# TODO: FIXME: Remove c++11 code in SRT of SRS.
if [[ $SRS_SRT == YES ]]; then
SRS_CXX11=YES
fi

# Enable FFmpeg fit for RTC to transcode audio from AAC to OPUS, if user enabled it.
if [[ $SRS_RTC == YES && $SRS_FFMPEG_FIT == RESERVED ]]; then
SRS_FFMPEG_FIT=YES
Expand Down
5 changes: 5 additions & 0 deletions trunk/conf/srt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ http_server {

srt_server {
enabled on;
tsbpdmode off;
tlpktdrop off;
latency 0;
sendbuf 2000000;
recvbuf 2000000;
listen 10080;
maxbw 1000000000;
connect_timeout 4000;
Expand Down
16 changes: 6 additions & 10 deletions trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack"
"srs_raw_avc" "srs_rtsp_stack" "srs_http_stack" "srs_protocol_kbps" "srs_protocol_json"
"srs_protocol_format" "srs_service_log" "srs_service_st" "srs_service_http_client" "srs_service_http_conn"
"srs_service_rtmp_conn" "srs_service_utility" "srs_service_conn")
if [[ $SRS_SRT == YES ]]; then
MODULE_FILES+=("srs_service_st_srt")
fi
if [[ $SRS_RTC == YES ]]; then
MODULE_FILES+=("srs_rtc_stun_stack")
ModuleLibIncs+=(${LibSrtpRoot})
Expand All @@ -237,16 +240,6 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then
fi
PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh
PROTOCOL_OBJS="${MODULE_OBJS[@]}"
#
#srt protocol features.
if [[ $SRS_SRT == YES ]]; then
MODULE_ID="SRT"
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot} ${LibSRTRoot})
MODULE_FILES=("srt_server" "srt_handle" "srt_conn" "srt_to_rtmp" "ts_demux" "srt_data" "srt_log")
SRT_INCS=(${LibSRTRoot} ${SrsSRTRoot}); MODULE_DIR=${SrsSRTRoot} . auto/modules.sh
SRT_OBJS="${MODULE_OBJS[@]}"
fi

#
#App Module, for SRS server only.
Expand All @@ -273,6 +266,9 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_sourc
"srs_app_caster_flv" "srs_app_latest_version" "srs_app_uuid" "srs_app_process" "srs_app_ng_exec"
"srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
"srs_app_coworkers" "srs_app_hybrid" "srs_app_threads")
if [[ $SRS_SRT == YES ]]; then
MODULE_FILES+=("srs_app_srt_server" "srs_app_srt_listener" "srs_app_srt_conn" "srs_app_srt_utility" "srs_app_srt_source")
fi
if [[ $SRS_RTC == YES ]]; then
MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp"
"srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")
Expand Down
45 changes: 39 additions & 6 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2546,8 +2546,9 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "mss" && n != "latency" && n != "recvlatency"
&& n != "peerlatency" && n != "tlpkdrop" && n != "connect_timeout"
&& n != "sendbuf" && n != "recvbuf" && n != "payloadsize"
&& n != "default_app" && n != "mix_correct" && n != "sei_filter") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_stream.%s", n.c_str());
&& n != "default_app" && n != "mix_correct" && n != "sei_filter"
&& n != "tlpktdrop" && n != "tsbpdmode") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_server.%s", n.c_str());
}
}
}
Expand Down Expand Up @@ -6798,6 +6799,20 @@ int SrsConfig::get_srto_mss() {
return atoi(conf->arg0().c_str());
}

bool SrsConfig::get_srto_tsbpdmode() {
static bool DEFAULT = false;
SrsConfDirective* conf = root->get("srt_server");
if (!conf) {
return DEFAULT;
}

conf = conf->get("tsbpdmode");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return SRS_CONF_PERFER_TRUE(conf->arg0());
}

int SrsConfig::get_srto_latency() {
static int DEFAULT = 120;
SrsConfDirective* conf = root->get("srt_server");
Expand Down Expand Up @@ -6854,14 +6869,18 @@ bool SrsConfig::get_srt_sei_filter() {
return SRS_CONF_PERFER_TRUE(conf->arg0());
}

bool SrsConfig::get_srto_tlpkdrop() {
bool SrsConfig::get_srto_tlpktdrop() {
static bool DEFAULT = true;
SrsConfDirective* conf = root->get("srt_server");
if (!conf) {
SrsConfDirective* srt_server_conf = root->get("srt_server");
if (!srt_server_conf) {
return DEFAULT;
}

conf = conf->get("tlpkdrop");
SrsConfDirective* conf = srt_server_conf->get("tlpkdrop");
if (! conf) {
// make it compatible tlpkdrop and tlpktdrop opt.
conf = srt_server_conf->get("tlpktdrop");
}
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
Expand All @@ -6882,6 +6901,20 @@ int SrsConfig::get_srto_conntimeout() {
return atoi(conf->arg0().c_str());
}

int SrsConfig::get_srto_peeridletimeout() {
static int DEFAULT = 10000;
SrsConfDirective* conf = root->get("srt_server");
if (!conf) {
return DEFAULT;
}

conf = conf->get("peer_idle_timeout");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return atoi(conf->arg0().c_str());
}

int SrsConfig::get_srto_sendbuf() {
static int64_t DEFAULT = 8192 * (1500-28);
SrsConfDirective* conf = root->get("srt_server");
Expand Down
8 changes: 6 additions & 2 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ class SrsConfig
virtual int get_srto_maxbw();
// Get the srt SRTO_MSS, Maximum Segment Size, default is 1500.
virtual int get_srto_mss();
// Get the srt SRTO_TSBPDMODE, timestamp base packet delivery mode, default is false.
virtual bool get_srto_tsbpdmode();
// Get the srt SRTO_LATENCY, latency, default is 0 which means peer/recv latency is 120ms.
virtual int get_srto_latency();
// Get the srt SRTO_RCVLATENCY, recv latency, default is 120ms.
Expand All @@ -644,10 +646,12 @@ class SrsConfig
virtual int get_srto_peer_latency();
// Get the srt h264 sei filter, default is on, it will drop h264 sei packet.
virtual bool get_srt_sei_filter();
// Get the srt SRTO_TLPKDROP, Too-late Packet Drop, default is true.
virtual bool get_srto_tlpkdrop();
// Get the srt SRTO_TLPKTDROP, Too-late Packet Drop, default is true.
virtual bool get_srto_tlpktdrop();
// Get the srt SRTO_CONNTIMEO, connection timeout, default is 3000ms.
virtual int get_srto_conntimeout();
// Get the srt SRTO_PEERIDLETIMEO, peer idle timeout, default is 10000ms.
virtual int get_srto_peeridletimeout();
// Get the srt SRTO_SNDBUF, send buffer, default is 8192 × (1500-28).
virtual int get_srto_sendbuf();
// Get the srt SRTO_RCVBUF, recv buffer, default is 8192 × (1500-28).
Expand Down
19 changes: 19 additions & 0 deletions trunk/src/app/srs_app_pithy_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ SrsPithyPrint::SrsPithyPrint(int _stage_id)
// for the rtc recv
#define SRS_CONSTS_STAGE_RTC_RECV 14

#ifdef SRS_SRT
// the pithy stage for srt play clients.
#define SRS_CONSTS_STAGE_SRT_PLAY 15
// the pithy stage for srt publish clients.
#define SRS_CONSTS_STAGE_SRT_PUBLISH 16
#endif

SrsPithyPrint* SrsPithyPrint::create_rtmp_play()
{
return new SrsPithyPrint(SRS_CONSTS_STAGE_PLAY_USER);
Expand Down Expand Up @@ -289,6 +296,18 @@ SrsPithyPrint* SrsPithyPrint::create_rtc_recv(int fd)
return new SrsPithyPrint(fd<<16 | SRS_CONSTS_STAGE_RTC_RECV);
}

#ifdef SRS_SRT
SrsPithyPrint* SrsPithyPrint::create_srt_play()
{
return new SrsPithyPrint(SRS_CONSTS_STAGE_SRT_PLAY);
}

SrsPithyPrint* SrsPithyPrint::create_srt_publish()
{
return new SrsPithyPrint(SRS_CONSTS_STAGE_SRT_PUBLISH);
}
#endif

SrsPithyPrint::~SrsPithyPrint()
{
leave_stage();
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_pithy_print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class SrsPithyPrint
// For RTC sender and receiver, we create printer for each fd.
static SrsPithyPrint* create_rtc_send(int fd);
static SrsPithyPrint* create_rtc_recv(int fd);
#ifdef SRS_SRT
static SrsPithyPrint* create_srt_play();
static SrsPithyPrint* create_srt_publish();
#endif
virtual ~SrsPithyPrint();
private:
// Enter the specified stage, return the client id.
Expand Down
Loading

0 comments on commit 95ad1c7

Please sign in to comment.