Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SRT in SRS #1585

Merged
merged 22 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*.pyc
*.swp
.DS_Store
.vscode
.vscode/*
/trunk/Makefile
/trunk/objs
/trunk/src/build-qt-Desktop-Debug
Expand Down
6 changes: 6 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ else
srs_undefine_macro "SRS_AUTO_HDS" $SRS_AUTO_HEADERS_H
fi

if [ $SRS_SRT = YES ]; then
srs_define_macro "SRS_AUTO_SRT" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_AUTO_SRT" $SRS_AUTO_HEADERS_H
fi

if [ $SRS_MEM_WATCH = YES ]; then
srs_define_macro "SRS_AUTO_MEM_WATCH" $SRS_AUTO_HEADERS_H
else
Expand Down
6 changes: 6 additions & 0 deletions trunk/auto/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ help=no
################################################################
# feature options
SRS_HDS=NO
SRS_SRT=NO
SRS_NGINX=NO
SRS_FFMPEG_TOOL=NO
SRS_LIBRTMP=NO
Expand Down Expand Up @@ -121,6 +122,7 @@ Options:
--with-librtmp enable srs-librtmp, library for client.
--with-research build the research tools.
--with-utest build the utest for SRS.
--with-srt build the srt for SRS.
--with-gperf build SRS with gperf tools(no gmd/gmc/gmp/gcp, with tcmalloc only).
--with-gmc build memory check for SRS with gperf tools.
--with-gmd build memory defense(corrupt memory) for SRS with gperf tools.
Expand All @@ -141,6 +143,7 @@ Options:
--without-librtmp disable srs-librtmp, library for client.
--without-research do not build the research tools.
--without-utest do not build the utest for SRS.
--without-srt do not build the srt for SRS.
--without-gperf do not build SRS with gperf tools(without tcmalloc and gmd/gmc/gmp/gcp).
--without-gmc do not build memory check for SRS with gperf tools.
--without-gmd do not build memory defense for SRS with gperf tools.
Expand Down Expand Up @@ -231,6 +234,7 @@ function parse_user_option() {
--with-librtmp) SRS_LIBRTMP=YES ;;
--with-research) SRS_RESEARCH=YES ;;
--with-utest) SRS_UTEST=YES ;;
--with-srt) SRS_SRT=YES ;;
--with-gperf) SRS_GPERF=YES ;;
--with-gmc) SRS_GPERF_MC=YES ;;
--with-gmd) SRS_GPERF_MD=YES ;;
Expand All @@ -251,6 +255,7 @@ function parse_user_option() {
--without-librtmp) SRS_LIBRTMP=NO ;;
--without-research) SRS_RESEARCH=NO ;;
--without-utest) SRS_UTEST=NO ;;
--without-srt) SRS_SRT=NO ;;
--without-gperf) SRS_GPERF=NO ;;
--without-gmc) SRS_GPERF_MC=NO ;;
--without-gmd) SRS_GPERF_MD=NO ;;
Expand Down Expand Up @@ -536,6 +541,7 @@ SRS_AUTO_CONFIGURE="--prefix=${SRS_PREFIX}"
if [ $SRS_LIBRTMP = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-librtmp"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-librtmp"; fi
if [ $SRS_RESEARCH = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-research"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-research"; fi
if [ $SRS_UTEST = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-utest"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-utest"; fi
if [ $SRS_SRT = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-srt"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-srt"; fi
if [ $SRS_GPERF = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-gperf"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-gperf"; fi
if [ $SRS_GPERF_MC = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-gmc"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-gmc"; fi
if [ $SRS_GPERF_MD = YES ]; then SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --with-gmd"; else SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --without-gmd"; fi
Expand Down
2 changes: 1 addition & 1 deletion trunk/auto/utest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ USER_DIR = .
CPPFLAGS += -I\$(GTEST_DIR)/include

# Flags passed to the C++ compiler.
CXXFLAGS += -g -Wall -Wextra -O0 ${EXTRA_DEFINES}
CXXFLAGS += ${CXXFLAGS} -Wextra ${EXTRA_DEFINES}

# All tests produced by this Makefile. Remember to add new tests you
# created to the list.
Expand Down
32 changes: 32 additions & 0 deletions trunk/conf/srt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SRT config.

listen 1935;
max_connections 1000;
srs_log_tank console;
daemon off;

http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}

srt_server {
enabled on;
listen 10080;
}

# @doc https://github.com/ossrs/srs/issues/1147#issuecomment-577492117
vhost __defaultVhost__ {
}
vhost srs.srt.com.cn {
}

stats {
network 0;
disk sda sdb xvda xvdb;
}
42 changes: 41 additions & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ GDBDebug=" -g -O0"
WarnLevel=" -Wall"
# the compile standard.
CppStd="-ansi"
if [[ $SRS_SRT == YES ]]; then
CppStd="-std=c++11"
fi
# for library compile
if [[ $SRS_EXPORT_LIBRTMP_PROJECT == YES ]]; then
LibraryCompile=" -fPIC"
Expand Down Expand Up @@ -157,8 +160,15 @@ fi
if [ $SRS_GPERF_MD = YES ]; then
LibGperfFile="${SRS_OBJS_DIR}/gperf/lib/libtcmalloc_debug.a";
fi
# srt code path
if [[ $SRS_SRT == YES ]]; then
LibSRTRoot="${SRS_WORKDIR}/src/srt"
fi
# the link options, always use static link
SrsLinkOptions="-ldl";
if [[ $SRS_SRT == YES ]]; then
SrsLinkOptions="${SrsLinkOptions} -pthread -lsrt";
fi
if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then
SrsLinkOptions="${SrsLinkOptions} -lssl -lcrypto";
fi
Expand Down Expand Up @@ -205,6 +215,17 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack"
"srs_protocol_format")
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" "SERVICE" "APP")
ModuleLibIncs=(${SRS_OBJS_DIR})
MODULE_FILES=("srt_server" "srt_handle" "srt_conn" "srt_to_rtmp" "ts_demux" "srt_data")
SRT_INCS=${LibSRTRoot}; MODULE_DIR=${LibSRTRoot} . auto/modules.sh
SRT_OBJS="${MODULE_OBJS[@]}"
fi

#
#Service Module, for both Server and Client Modules.
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
Expand All @@ -224,6 +245,9 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
MODULE_ID="APP"
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE")
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibSSLRoot})
if [[ $SRS_SRT == YES ]]; then
ModuleLibIncs+=("${LibSRTRoot[*]}")
fi
MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_source"
"srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http_stream"
"srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config"
Expand Down Expand Up @@ -258,7 +282,13 @@ LIBS_OBJS="${MODULE_OBJS[@]}"
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
MODULE_ID="SERVER"
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP")
if [[ $SRS_SRT == YES ]]; then
MODULE_DEPENDS+=("SRT")
fi
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibSSLRoot})
if [[ $SRS_SRT == YES ]]; then
ModuleLibIncs+=("${LibSRTRoot[*]}")
fi
MODULE_FILES=("srs_main_server")
SERVER_INCS="src/main"; MODULE_DIR=${SERVER_INCS} . auto/modules.sh
SERVER_OBJS="${MODULE_OBJS[@]}"
Expand Down Expand Up @@ -298,6 +328,10 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile})
# all depends objects
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]} ${SERVER_OBJS[@]}"
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibSSLRoot})
if [[ $SRS_SRT == YES ]]; then
MODULE_OBJS="${MODULE_OBJS} ${SRT_OBJS[@]}"
fi
LINK_OPTIONS="${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}"
#
# srs: srs(simple rtmp server) over st(state-threads)
Expand Down Expand Up @@ -325,9 +359,15 @@ if [ $SRS_UTEST = YES ]; then
"srs_utest_config" "srs_utest_rtmp" "srs_utest_http" "srs_utest_avc" "srs_utest_reload"
"srs_utest_mp4" "srs_utest_service" "srs_utest_app")
ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot})
if [[ $SRS_SRT == YES ]]; then
ModuleLibIncs+=("${LibSRTRoot[*]}")
fi
ModuleLibFiles=(${LibSTfile} ${LibSSLfile})
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP")
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]}"
if [[ $SRS_SRT == YES ]]; then
MODULE_DEPENDS+=("SRT")
fi
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]} ${SRT_OBJS[@]}"
LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . auto/utest.sh
fi

Expand Down
47 changes: 45 additions & 2 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ srs_error_t srs_config_transform_vhost(SrsConfDirective* root)
++it;
continue;
}

// SRS3.0, change the folowing like a shadow:
// mode, origin, token_traverse, vhost, debug_srs_upnode
// SRS1/2:
Expand Down Expand Up @@ -3470,7 +3470,7 @@ srs_error_t SrsConfig::check_normal_config()
&& n != "srs_log_tank" && n != "srs_log_level" && n != "srs_log_file"
&& n != "max_connections" && n != "daemon" && n != "heartbeat"
&& n != "http_api" && n != "stats" && n != "vhost" && n != "pithy_print_ms"
&& n != "http_server" && n != "stream_caster"
&& n != "http_server" && n != "stream_caster" && n != "srt_server"
&& n != "utc_time" && n != "work_dir" && n != "asprocess"
) {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal directive %s", n.c_str());
Expand Down Expand Up @@ -3504,6 +3504,15 @@ srs_error_t SrsConfig::check_normal_config()
}
}
}
if (true) {
SrsConfDirective* conf = root->get("srt_server");
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
string n = conf->at(i)->name;
if (n != "enabled" && n != "listen") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal srt_stream.%s", n.c_str());
}
}
}
if (true) {
SrsConfDirective* conf = get_heartbeart();
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
Expand Down Expand Up @@ -3631,6 +3640,7 @@ srs_error_t SrsConfig::check_normal_config()
get_vhosts(vhosts);
for (int n = 0; n < (int)vhosts.size(); n++) {
SrsConfDirective* vhost = vhosts[n];

for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) {
SrsConfDirective* conf = vhost->at(i);
string n = conf->name;
Expand Down Expand Up @@ -6629,6 +6639,39 @@ bool SrsConfig::get_raw_api_allow_update()
return SRS_CONF_PERFER_FALSE(conf->arg0());
}


bool SrsConfig::get_srt_enabled()
{
static bool DEFAULT = false;

SrsConfDirective* conf = root->get("srt_server");
if (!conf) {
return DEFAULT;
}

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

return SRS_CONF_PERFER_FALSE(conf->arg0());
}

unsigned short SrsConfig::get_srt_listen_port()
{
static unsigned short DEFAULT = 10080;
SrsConfDirective* conf = root->get("srt_server");
if (!conf) {
return DEFAULT;
}

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

bool SrsConfig::get_http_stream_enabled()
{
SrsConfDirective* conf = root->get("http_server");
Expand Down
7 changes: 7 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ class SrsConfig
virtual bool get_forward_enabled(std::string vhost);
// Get the forward directive of vhost.
virtual SrsConfDirective* get_forwards(std::string vhost);

public:
// Whether the srt sevice enabled
virtual bool get_srt_enabled();
// Get the srt service listen port
virtual unsigned short get_srt_listen_port();

// http_hooks section
private:
// Get the http_hooks directive of vhost.
Expand Down
33 changes: 32 additions & 1 deletion trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,12 @@ srs_error_t SrsServer::listen()
if ((err = conn_manager->start()) != srs_success) {
return srs_error_wrap(err, "connection manager");
}

#ifdef SRS_AUTO_SRT
if ((err = listen_srt()) != srs_success) {
return srs_error_wrap(err, "srt listen");
}
#endif

return err;
}

Expand Down Expand Up @@ -1004,6 +1009,32 @@ srs_error_t SrsServer::do_cycle()
return err;
}

#ifdef SRS_AUTO_SRT
srs_error_t SrsServer::listen_srt() {
srs_error_t err = srs_success;

if(_srs_config->get_srt_enabled()) {
srs_trace("srt server is enabled...");
unsigned short srt_port = _srs_config->get_srt_listen_port();
srs_trace("srt server listen port:%d", srt_port);
err = srt2rtmp::get_instance()->init();
if (err != srs_success) {
srs_error_wrap(err, "srt start srt2rtmp error");
return err;
}

srt_ptr = std::make_shared<srt_server>(srt_port);
if (!srt_ptr) {
srs_error_wrap(err, "srt listen %d", srt_port);
}
srt_ptr->start();
} else {
srs_trace("srt server is disabled...");
}
return err;
}
#endif

srs_error_t SrsServer::listen_rtmp()
{
srs_error_t err = srs_success;
Expand Down
12 changes: 12 additions & 0 deletions trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <srs_app_listener.hpp>
#include <srs_app_conn.hpp>
#include <srs_service_st.hpp>
#ifdef SRS_AUTO_SRT
#include <srt_server.hpp>
#include <srt_to_rtmp.hpp>
#endif

class SrsServer;
class SrsConnection;
Expand Down Expand Up @@ -209,6 +213,10 @@ class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHan
SrsHttpHeartbeat* http_heartbeat;
SrsIngester* ingester;
SrsCoroutineManager* conn_manager;
#ifdef SRS_AUTO_SRT
// srt server
SRT_SERVER_PTR srt_ptr;
#endif
private:
// The pid file fd, lock the file write when server is running.
// @remark the init.d script should cleanup the pid file, when stop service,
Expand Down Expand Up @@ -279,6 +287,10 @@ class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHan
virtual srs_error_t listen_http_api();
virtual srs_error_t listen_http_stream();
virtual srs_error_t listen_stream_caster();
#ifdef SRS_AUTO_SRT
//start listen srt udp port
virtual srs_error_t listen_srt();
#endif
// Close the listeners for specified type,
// Remove the listen object from manager.
virtual void close_listeners(SrsListenerType type);
Expand Down
1 change: 1 addition & 0 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void show_macro_features()
ss << ", dash:" << "on";
ss << ", hls:" << srs_bool2switch(true);
ss << ", hds:" << srs_bool2switch(SRS_AUTO_HDS_BOOL);
ss << ", srt:" << srs_bool2switch(SRS_AUTO_SRT_BOOL);
// hc(http callback)
ss << ", hc:" << srs_bool2switch(true);
// ha(http api)
Expand Down