diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index da062849a..a12cddcde 100644 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -14,9 +14,19 @@ http_server { listen 8080; dir ./objs/nginx/html; } + +srt_server { + enabled on; + listen 10080; +} + stats { network 0; disk sda sdb xvda xvdb; } vhost __defaultVhost__ { + forward { + enabled on; + destination 172.16.43.153:19350; + } } diff --git a/trunk/configure b/trunk/configure index 3b366397f..e3e31ef61 100755 --- a/trunk/configure +++ b/trunk/configure @@ -96,6 +96,8 @@ END GDBDebug=" -g -O0" # the warning level. WarnLevel=" -Wall" +# c++11 enable. +cpp11=" -std=c++11 -pthread" # the compile standard. CppStd="-ansi" # for library compile @@ -107,7 +109,7 @@ SrsGprof=""; SrsGprofLink=""; if [ $SRS_GPROF = YES ]; then SrsGprof=" -pg -lc_p # performance of gperf SrsGperf=""; SrsGperfLink=""; if [ $SRS_GPERF = YES ]; then SrsGperfLink=" -lpthread"; fi # the cxx flag generated. -CXXFLAGS="${CXXFLAGS} ${CppStd}${WarnLevel}${GDBDebug}${LibraryCompile}${SrsGprof}" +CXXFLAGS="${CXXFLAGS} ${CppStd}${WarnLevel}${cpp11}${GDBDebug}${LibraryCompile}${SrsGprof}" if [ $SRS_GPERF = YES ]; then CXXFLAGS="${CXXFLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free"; fi @@ -158,7 +160,7 @@ if [ $SRS_GPERF_MD = YES ]; then LibGperfFile="${SRS_OBJS_DIR}/gperf/lib/libtcmalloc_debug.a"; fi # the link options, always use static link -SrsLinkOptions="-ldl"; +SrsLinkOptions="-pthread -ldl"; if [[ $SRS_SSL == YES && $SRS_USE_SYS_SSL == YES ]]; then SrsLinkOptions="${SrsLinkOptions} -lssl -lcrypto"; fi @@ -206,6 +208,14 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_rtmp_stack" PROTOCOL_INCS="src/protocol"; MODULE_DIR=${PROTOCOL_INCS} . auto/modules.sh PROTOCOL_OBJS="${MODULE_OBJS[@]}" # +#srt protocol features. +MODULE_ID="SRT" +MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP") +ModuleLibIncs=(${SRS_OBJS_DIR}) +MODULE_FILES=("srt_server") +SRT_INCS="src/srt"; MODULE_DIR=${SRT_INCS} . auto/modules.sh +SRT_OBJS="${MODULE_OBJS[@]}" +# #Service Module, for both Server and Client Modules. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then MODULE_ID="SERVICE" @@ -257,7 +267,7 @@ LIBS_OBJS="${MODULE_OBJS[@]}" #Server Module, for SRS only. if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then MODULE_ID="SERVER" - MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP") + MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP" "SRT") ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibGperfRoot} ${LibSSLRoot}) MODULE_FILES=("srs_main_server") SERVER_INCS="src/main"; MODULE_DIR=${SERVER_INCS} . auto/modules.sh @@ -297,14 +307,14 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then # all depends libraries ModuleLibFiles=(${LibSTfile} ${LibSSLfile} ${LibGperfFile}) # all depends objects - MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]} ${SERVER_OBJS[@]}" + MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SRT_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]} ${SERVER_OBJS[@]}" LINK_OPTIONS="${SrsLinkOptions}${SrsGprofLink}${SrsGperfLink}" # # srs: srs(simple rtmp server) over st(state-threads) BUILD_KEY="srs" APP_MAIN="srs_main_server" APP_NAME="srs" . auto/apps.sh # # For modules, without the app module. - MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${MAIN_OBJS[@]}" + MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${SRT_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${MAIN_OBJS[@]}" # for SRS_MODULE in ${SRS_MODULES[*]}; do . $SRS_MODULE/config @@ -326,7 +336,7 @@ if [ $SRS_UTEST = YES ]; then "srs_utest_mp4" "srs_utest_service" "srs_utest_app") ModuleLibIncs=(${SRS_OBJS_DIR} ${LibSTRoot} ${LibSSLRoot}) ModuleLibFiles=(${LibSTfile} ${LibSSLfile}) - MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP") + MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL" "SERVICE" "APP" "SRT") MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${PROTOCOL_OBJS[@]} ${SERVICE_OBJS[@]} ${APP_OBJS[@]}" LINK_OPTIONS="-lpthread ${SrsLinkOptions}" MODULE_DIR="src/utest" APP_NAME="srs_utest" . auto/utest.sh fi diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index a0277f3c9..e443a3318 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -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: @@ -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()); @@ -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++) { @@ -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]; + printf("virtural host name:%s, arg:%s\r\n", vhost->name.c_str(), vhost->args[0].c_str()); for (int i = 0; vhost && i < (int)vhost->directives.size(); i++) { SrsConfDirective* conf = vhost->at(i); string n = conf->name; @@ -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"); diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index c9c03e24f..cc936affc 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -588,6 +588,13 @@ public: 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. diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 8c6d21470..226f0dc1e 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -688,7 +688,10 @@ srs_error_t SrsServer::listen() if ((err = conn_manager->start()) != srs_success) { return srs_error_wrap(err, "connection manager"); } - + if ((err = listen_srt()) != srs_success) { + return srs_error_wrap(err, "srt listen"); + } + return err; } @@ -1004,6 +1007,24 @@ srs_error_t SrsServer::do_cycle() return err; } +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); + srt_ptr = std::make_shared(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; +} + srs_error_t SrsServer::listen_rtmp() { srs_error_t err = srs_success; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index fd8cbe3ad..625c161e7 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -36,6 +36,7 @@ #include #include #include +#include "../srt/srt_server.hpp" class SrsServer; class SrsConnection; @@ -209,6 +210,11 @@ private: SrsHttpHeartbeat* http_heartbeat; SrsIngester* ingester; SrsCoroutineManager* conn_manager; + +private: + //srt server + SRT_SERVER_PTR srt_ptr; + 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, @@ -279,6 +285,8 @@ private: virtual srs_error_t listen_http_api(); virtual srs_error_t listen_http_stream(); virtual srs_error_t listen_stream_caster(); + //start listen srt udp port + virtual srs_error_t listen_srt(); // Close the listeners for specified type, // Remove the listen object from manager. virtual void close_listeners(SrsListenerType type); diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 788773c80..bfe3e1577 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -1456,6 +1456,7 @@ srs_error_t SrsOriginHub::create_forwarders() if (!_srs_config->get_forward_enabled(req->vhost)) { return err; } + srs_trace("srs vhost(%s) forward is enable.", req->host.c_str()); SrsConfDirective* conf = _srs_config->get_forwards(req->vhost); for (int i = 0; conf && i < (int)conf->args.size(); i++) { diff --git a/trunk/src/srt/srt_server.cpp b/trunk/src/srt/srt_server.cpp new file mode 100644 index 000000000..f4f7ee8da --- /dev/null +++ b/trunk/src/srt/srt_server.cpp @@ -0,0 +1,43 @@ +#include "srt_server.hpp" +#include +#include +#include +#include +#include + +srt_server::srt_server(unsigned short port):listen_port(port) +{ + +} + +srt_server::~srt_server() +{ + +} + +int srt_server::start() +{ + run_flag = true; + srs_trace("srt server is starting... port(%d)", listen_port); + thread_run_ptr = std::make_shared(&srt_server::on_work, this); + return 0; +} + +void srt_server::stop() +{ + run_flag = false; + if (!thread_run_ptr) { + return; + } + thread_run_ptr->join(); + return; +} + +void srt_server::on_work() +{ + srs_trace("srt server is working port(%d)", listen_port); + while (run_flag) + { + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } +} diff --git a/trunk/src/srt/srt_server.hpp b/trunk/src/srt/srt_server.hpp new file mode 100644 index 000000000..49229dc6d --- /dev/null +++ b/trunk/src/srt/srt_server.hpp @@ -0,0 +1,25 @@ +#ifndef SRT_SERVER_H +#define SRT_SERVER_H +#include +#include + +class srt_server { +public: + srt_server(unsigned short port); + ~srt_server(); + + int start(); + void stop(); + +private: + void on_work(); + +private: + unsigned short listen_port; + bool run_flag; + std::shared_ptr thread_run_ptr; +}; + +typedef std::shared_ptr SRT_SERVER_PTR; + +#endif//SRT_SERVER_H \ No newline at end of file