Skip to content

Commit f58fa89

Browse files
committed
Refine SRT code, with StateThread adpater
1 parent 2b2379d commit f58fa89

26 files changed

+4127
-56
lines changed

trunk/auto/options.sh

-6
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,6 @@ function apply_auto_options() {
432432
SRS_TOOL_LD=$SRS_TOOL_CC
433433
fi
434434

435-
# The SRT code in SRS requires c++11, although we build libsrt without c++11.
436-
# TODO: FIXME: Remove c++11 code in SRT of SRS.
437-
if [[ $SRS_SRT == YES ]]; then
438-
SRS_CXX11=YES
439-
fi
440-
441435
# Enable FFmpeg fit for RTC to transcode audio from AAC to OPUS, if user enabled it.
442436
if [[ $SRS_RTC == YES && $SRS_FFMPEG_FIT == RESERVED ]]; then
443437
SRS_FFMPEG_FIT=YES

trunk/conf/srt.conf

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ http_server {
1818

1919
srt_server {
2020
enabled on;
21+
tsbpdmode off;
22+
tlpktdrop off;
23+
latency 0;
24+
sendbuf 2000000;
25+
recvbuf 2000000;
2126
listen 10080;
2227
maxbw 1000000000;
2328
connect_timeout 4000;

trunk/configure

+6-10
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack"
228228
"srs_raw_avc" "srs_rtsp_stack" "srs_http_stack" "srs_protocol_kbps" "srs_protocol_json"
229229
"srs_protocol_format" "srs_service_log" "srs_service_st" "srs_service_http_client" "srs_service_http_conn"
230230
"srs_service_rtmp_conn" "srs_service_utility" "srs_service_conn")
231+
if [[ $SRS_SRT == YES ]]; then
232+
MODULE_FILES+=("srs_service_st_srt")
233+
fi
231234
if [[ $SRS_RTC == YES ]]; then
232235
MODULE_FILES+=("srs_rtc_stun_stack")
233236
ModuleLibIncs+=(${LibSrtpRoot})
@@ -237,16 +240,6 @@ if [[ $SRS_FFMPEG_FIT == YES ]]; then
237240
fi
238241
PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh
239242
PROTOCOL_OBJS="${MODULE_OBJS[@]}"
240-
#
241-
#srt protocol features.
242-
if [[ $SRS_SRT == YES ]]; then
243-
MODULE_ID="SRT"
244-
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "APP")
245-
ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSSLRoot} ${LibSRTRoot})
246-
MODULE_FILES=("srt_server" "srt_handle" "srt_conn" "srt_to_rtmp" "ts_demux" "srt_data" "srt_log")
247-
SRT_INCS=(${LibSRTRoot} ${SrsSRTRoot}); MODULE_DIR=${SrsSRTRoot} . auto/modules.sh
248-
SRT_OBJS="${MODULE_OBJS[@]}"
249-
fi
250243

251244
#
252245
#App Module, for SRS server only.
@@ -273,6 +266,9 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_sourc
273266
"srs_app_caster_flv" "srs_app_latest_version" "srs_app_uuid" "srs_app_process" "srs_app_ng_exec"
274267
"srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
275268
"srs_app_coworkers" "srs_app_hybrid" "srs_app_threads")
269+
if [[ $SRS_SRT == YES ]]; then
270+
MODULE_FILES+=("srs_app_srt_server" "srs_app_srt_listener" "srs_app_srt_conn" "srs_app_srt_utility" "srs_app_srt_source")
271+
fi
276272
if [[ $SRS_RTC == YES ]]; then
277273
MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp"
278274
"srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")

trunk/src/app/srs_app_config.cpp

+39-6
Original file line numberDiff line numberDiff line change
@@ -2546,8 +2546,9 @@ srs_error_t SrsConfig::check_normal_config()
25462546
&& n != "mss" && n != "latency" && n != "recvlatency"
25472547
&& n != "peerlatency" && n != "tlpkdrop" && n != "connect_timeout"
25482548
&& n != "sendbuf" && n != "recvbuf" && n != "payloadsize"
2549-
&& n != "default_app" && n != "mix_correct" && n != "sei_filter") {
2550-
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_stream.%s", n.c_str());
2549+
&& n != "default_app" && n != "mix_correct" && n != "sei_filter"
2550+
&& n != "tlpktdrop" && n != "tsbpdmode") {
2551+
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_server.%s", n.c_str());
25512552
}
25522553
}
25532554
}
@@ -6798,6 +6799,20 @@ int SrsConfig::get_srto_mss() {
67986799
return atoi(conf->arg0().c_str());
67996800
}
68006801

6802+
bool SrsConfig::get_srto_tsbpdmode() {
6803+
static bool DEFAULT = false;
6804+
SrsConfDirective* conf = root->get("srt_server");
6805+
if (!conf) {
6806+
return DEFAULT;
6807+
}
6808+
6809+
conf = conf->get("tsbpdmode");
6810+
if (!conf || conf->arg0().empty()) {
6811+
return DEFAULT;
6812+
}
6813+
return SRS_CONF_PERFER_TRUE(conf->arg0());
6814+
}
6815+
68016816
int SrsConfig::get_srto_latency() {
68026817
static int DEFAULT = 120;
68036818
SrsConfDirective* conf = root->get("srt_server");
@@ -6854,14 +6869,18 @@ bool SrsConfig::get_srt_sei_filter() {
68546869
return SRS_CONF_PERFER_TRUE(conf->arg0());
68556870
}
68566871

6857-
bool SrsConfig::get_srto_tlpkdrop() {
6872+
bool SrsConfig::get_srto_tlpktdrop() {
68586873
static bool DEFAULT = true;
6859-
SrsConfDirective* conf = root->get("srt_server");
6860-
if (!conf) {
6874+
SrsConfDirective* srt_server_conf = root->get("srt_server");
6875+
if (!srt_server_conf) {
68616876
return DEFAULT;
68626877
}
68636878

6864-
conf = conf->get("tlpkdrop");
6879+
SrsConfDirective* conf = srt_server_conf->get("tlpkdrop");
6880+
if (! conf) {
6881+
// make it compatible tlpkdrop and tlpktdrop opt.
6882+
conf = srt_server_conf->get("tlpktdrop");
6883+
}
68656884
if (!conf || conf->arg0().empty()) {
68666885
return DEFAULT;
68676886
}
@@ -6882,6 +6901,20 @@ int SrsConfig::get_srto_conntimeout() {
68826901
return atoi(conf->arg0().c_str());
68836902
}
68846903

6904+
int SrsConfig::get_srto_peeridletimeout() {
6905+
static int DEFAULT = 10000;
6906+
SrsConfDirective* conf = root->get("srt_server");
6907+
if (!conf) {
6908+
return DEFAULT;
6909+
}
6910+
6911+
conf = conf->get("peer_idle_timeout");
6912+
if (!conf || conf->arg0().empty()) {
6913+
return DEFAULT;
6914+
}
6915+
return atoi(conf->arg0().c_str());
6916+
}
6917+
68856918
int SrsConfig::get_srto_sendbuf() {
68866919
static int64_t DEFAULT = 8192 * (1500-28);
68876920
SrsConfDirective* conf = root->get("srt_server");

trunk/src/app/srs_app_config.hpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,8 @@ class SrsConfig
636636
virtual int get_srto_maxbw();
637637
// Get the srt SRTO_MSS, Maximum Segment Size, default is 1500.
638638
virtual int get_srto_mss();
639+
// Get the srt SRTO_TSBPDMODE, timestamp base packet delivery mode, default is false.
640+
virtual bool get_srto_tsbpdmode();
639641
// Get the srt SRTO_LATENCY, latency, default is 0 which means peer/recv latency is 120ms.
640642
virtual int get_srto_latency();
641643
// Get the srt SRTO_RCVLATENCY, recv latency, default is 120ms.
@@ -644,10 +646,12 @@ class SrsConfig
644646
virtual int get_srto_peer_latency();
645647
// Get the srt h264 sei filter, default is on, it will drop h264 sei packet.
646648
virtual bool get_srt_sei_filter();
647-
// Get the srt SRTO_TLPKDROP, Too-late Packet Drop, default is true.
648-
virtual bool get_srto_tlpkdrop();
649+
// Get the srt SRTO_TLPKTDROP, Too-late Packet Drop, default is true.
650+
virtual bool get_srto_tlpktdrop();
649651
// Get the srt SRTO_CONNTIMEO, connection timeout, default is 3000ms.
650652
virtual int get_srto_conntimeout();
653+
// Get the srt SRTO_PEERIDLETIMEO, peer idle timeout, default is 10000ms.
654+
virtual int get_srto_peeridletimeout();
651655
// Get the srt SRTO_SNDBUF, send buffer, default is 8192 × (1500-28).
652656
virtual int get_srto_sendbuf();
653657
// Get the srt SRTO_RCVBUF, recv buffer, default is 8192 × (1500-28).

trunk/src/app/srs_app_pithy_print.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ SrsPithyPrint::SrsPithyPrint(int _stage_id)
219219
// for the rtc recv
220220
#define SRS_CONSTS_STAGE_RTC_RECV 14
221221

222+
#ifdef SRS_SRT
223+
// the pithy stage for srt play clients.
224+
#define SRS_CONSTS_STAGE_SRT_PLAY 15
225+
// the pithy stage for srt publish clients.
226+
#define SRS_CONSTS_STAGE_SRT_PUBLISH 16
227+
#endif
228+
222229
SrsPithyPrint* SrsPithyPrint::create_rtmp_play()
223230
{
224231
return new SrsPithyPrint(SRS_CONSTS_STAGE_PLAY_USER);
@@ -289,6 +296,18 @@ SrsPithyPrint* SrsPithyPrint::create_rtc_recv(int fd)
289296
return new SrsPithyPrint(fd<<16 | SRS_CONSTS_STAGE_RTC_RECV);
290297
}
291298

299+
#ifdef SRS_SRT
300+
SrsPithyPrint* SrsPithyPrint::create_srt_play()
301+
{
302+
return new SrsPithyPrint(SRS_CONSTS_STAGE_SRT_PLAY);
303+
}
304+
305+
SrsPithyPrint* SrsPithyPrint::create_srt_publish()
306+
{
307+
return new SrsPithyPrint(SRS_CONSTS_STAGE_SRT_PUBLISH);
308+
}
309+
#endif
310+
292311
SrsPithyPrint::~SrsPithyPrint()
293312
{
294313
leave_stage();

trunk/src/app/srs_app_pithy_print.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ class SrsPithyPrint
130130
// For RTC sender and receiver, we create printer for each fd.
131131
static SrsPithyPrint* create_rtc_send(int fd);
132132
static SrsPithyPrint* create_rtc_recv(int fd);
133+
#ifdef SRS_SRT
134+
static SrsPithyPrint* create_srt_play();
135+
static SrsPithyPrint* create_srt_publish();
136+
#endif
133137
virtual ~SrsPithyPrint();
134138
private:
135139
// Enter the specified stage, return the client id.

0 commit comments

Comments
 (0)