From 074d7dc50490b736a73736be841c1f558bd9f786 Mon Sep 17 00:00:00 2001 From: shiwei05 Date: Fri, 17 Feb 2023 11:29:20 +0800 Subject: [PATCH 01/21] add push/pull ports --- trunk/src/app/srs_app_config.cpp | 25 ++++++++++++++++--- trunk/src/app/srs_app_config.hpp | 3 ++- trunk/src/app/srs_app_srt_conn.cpp | 12 +++++---- trunk/src/app/srs_app_srt_conn.hpp | 3 ++- trunk/src/app/srs_app_srt_server.cpp | 36 ++++++++++++++++++--------- trunk/src/app/srs_app_srt_server.hpp | 8 +++--- trunk/src/app/srs_app_srt_utility.cpp | 12 +++++++++ trunk/src/app/srs_app_srt_utility.hpp | 1 + 8 files changed, 74 insertions(+), 26 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 0ee7c2f5aa0..018a8957b65 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2311,7 +2311,7 @@ srs_error_t SrsConfig::check_normal_config() 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" && n != "maxbw" + if (n != "enabled" && n != "pullport" && n != "pushport" && n != "maxbw" && n != "mss" && n != "latency" && n != "recvlatency" && n != "peerlatency" && n != "connect_timeout" && n != "sendbuf" && n != "recvbuf" && n != "payloadsize" @@ -7673,9 +7673,9 @@ bool SrsConfig::get_srt_enabled() return SRS_CONF_PERFER_FALSE(conf->arg0()); } -unsigned short SrsConfig::get_srt_listen_port() +unsigned short SrsConfig::get_srt_push_port() { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.listen"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pushport"); // SRS_SRT_SERVER_LISTEN static unsigned short DEFAULT = 10080; SrsConfDirective* conf = root->get("srt_server"); @@ -7683,7 +7683,24 @@ unsigned short SrsConfig::get_srt_listen_port() return DEFAULT; } - conf = conf->get("listen"); + conf = conf->get("pushport"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + return (unsigned short)atoi(conf->arg0().c_str()); +} + +unsigned short SrsConfig::get_srt_pull_port() +{ + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pullport"); // SRS_SRT_SERVER_LISTEN + + static unsigned short DEFAULT = 10080; + SrsConfDirective* conf = root->get("srt_server"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("pullport"); if (!conf || conf->arg0().empty()) { return DEFAULT; } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 4cbd4b91016..aaa8790f974 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -653,7 +653,8 @@ class SrsConfig // Whether the srt sevice enabled virtual bool get_srt_enabled(); // Get the srt service listen port - virtual unsigned short get_srt_listen_port(); + virtual unsigned short get_srt_push_port(); + virtual unsigned short get_srt_pull_port(); // Get the srt SRTO_MAXBW, max bandwith, default is -1. virtual int64_t get_srto_maxbw(); // Get the srt SRTO_MSS, Maximum Segment Size, default is 1500. diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index df51160597e..62ea9f2ee52 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -152,7 +152,7 @@ srs_error_t SrsSrtRecvThread::get_recv_err() return srs_error_copy(recv_err_); } -SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port) +SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port, enum SrtMode mode) { // Create a identify for this client. _srs_context->set_id(_srs_context->generate_id()); @@ -163,6 +163,7 @@ SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, s srt_conn_ = new SrsSrtConnection(srt_fd_); ip_ = ip; port_ = port; + mode_ = mode; kbps_ = new SrsNetworkKbps(); kbps_->set_io(srt_conn_, srt_conn_); @@ -269,6 +270,7 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_new(ERROR_SRT_CONN, "invalid srt streamid=%s", streamid.c_str()); } + (void)mode; // discovery vhost, resolve the vhost from config SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req_->vhost); if (parsed_vhost) { @@ -279,8 +281,8 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_new(ERROR_SRT_CONN, "srt disabled, vhost=%s", req_->vhost.c_str()); } - srs_trace("@srt, streamid=%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", - streamid.c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); + srs_trace("@srt, streamid=%s, mode:%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", + streamid.c_str(), SrtMode2String(mode_).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); if ((err = _srs_srt_sources->fetch_or_create(req_, &srt_source_)) != srs_success) { return srs_error_wrap(err, "fetch srt source"); @@ -290,9 +292,9 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_wrap(err, "on connect"); } - if (mode == SrtModePush) { + if (mode_ == SrtModePush) { err = publishing(); - } else if (mode == SrtModePull) { + } else if (mode_ == SrtModePull) { err = playing(); } diff --git a/trunk/src/app/srs_app_srt_conn.hpp b/trunk/src/app/srs_app_srt_conn.hpp index d651659f296..4e1388e90d2 100644 --- a/trunk/src/app/srs_app_srt_conn.hpp +++ b/trunk/src/app/srs_app_srt_conn.hpp @@ -74,7 +74,7 @@ class SrsSrtRecvThread : public ISrsCoroutineHandler class SrsMpegtsSrtConn : public ISrsConnection, public ISrsStartable, public ISrsCoroutineHandler, public ISrsExpire { public: - SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port); + SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port, enum SrtMode mode); virtual ~SrsMpegtsSrtConn(); // Interface ISrsResource. public: @@ -119,6 +119,7 @@ class SrsMpegtsSrtConn : public ISrsConnection, public ISrsStartable, public ISr SrsNetworkKbps* kbps_; std::string ip_; int port_; + enum SrtMode mode_; SrsCoroutine* trd_; SrsRequest* req_; diff --git a/trunk/src/app/srs_app_srt_server.cpp b/trunk/src/app/srs_app_srt_server.cpp index 5f0635e405e..1d03fdbf6a6 100644 --- a/trunk/src/app/srs_app_srt_server.cpp +++ b/trunk/src/app/srs_app_srt_server.cpp @@ -19,11 +19,12 @@ using namespace std; SrsSrtEventLoop* _srt_eventloop = NULL; #endif -SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server) +SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode) { port_ = 0; srt_server_ = srt_server; listener_ = NULL; + mode_ = mode; } SrsSrtAcceptor::~SrsSrtAcceptor() @@ -133,7 +134,7 @@ srs_error_t SrsSrtAcceptor::on_srt_client(srs_srt_t srt_fd) srs_error_t err = srs_success; // Notify srt server to accept srt client, and create new SrsSrtConn on it. - if ((err = srt_server_->accept_srt_client(srt_fd)) != srs_success) { + if ((err = srt_server_->accept_srt_client(srt_fd, mode_)) != srs_success) { srs_warn("accept srt client failed, err is %s", srs_error_desc(err).c_str()); srs_freep(err); } @@ -195,16 +196,27 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() // Close all listener for SRT if exists. close_listeners(); - // Start a listener for SRT, we might need multiple listeners in the future. - SrsSrtAcceptor* acceptor = new SrsSrtAcceptor(this); - acceptors_.push_back(acceptor); + // Start a push listener for SRT + SrsSrtAcceptor* pushAcceptor = new SrsSrtAcceptor(this, SrtModePush); + acceptors_.push_back(pushAcceptor); int port; string ip; - srs_parse_endpoint(srs_int2str(_srs_config->get_srt_listen_port()), ip, port); + srs_parse_endpoint(srs_int2str(_srs_config->get_srt_push_port()), ip, port); - if ((err = acceptor->listen(ip, port)) != srs_success) { - return srs_error_wrap(err, "srt listen %s:%d", ip.c_str(), port); + if ((err = pushAcceptor->listen(ip, port)) != srs_success) { + return srs_error_wrap(err, "srt push listen %s:%d", ip.c_str(), port); } + srs_trace("srt push listen:%s:%d", ip.c_str(), port); + + // Start a pull listener for SRT + SrsSrtAcceptor* pullAcceptor = new SrsSrtAcceptor(this, SrtModePull); + acceptors_.push_back(pullAcceptor); + + srs_parse_endpoint(srs_int2str(_srs_config->get_srt_pull_port()), ip, port); + if ((err = pullAcceptor->listen(ip, port)) != srs_success) { + return srs_error_wrap(err, "srt pull listen %s:%d", ip.c_str(), port); + } + srs_trace("srt pull listen:%s:%d", ip.c_str(), port); return err; } @@ -220,12 +232,12 @@ void SrsSrtServer::close_listeners() } } -srs_error_t SrsSrtServer::accept_srt_client(srs_srt_t srt_fd) +srs_error_t SrsSrtServer::accept_srt_client(srs_srt_t srt_fd, enum SrtMode mode) { srs_error_t err = srs_success; ISrsResource* resource = NULL; - if ((err = fd_to_resource(srt_fd, &resource)) != srs_success) { + if ((err = fd_to_resource(srt_fd, mode, &resource)) != srs_success) { //close fd on conn error, otherwise will lead to fd leak -gs // TODO: FIXME: Handle error. srs_srt_close(srt_fd); @@ -244,7 +256,7 @@ srs_error_t SrsSrtServer::accept_srt_client(srs_srt_t srt_fd) return err; } -srs_error_t SrsSrtServer::fd_to_resource(srs_srt_t srt_fd, ISrsResource** pr) +srs_error_t SrsSrtServer::fd_to_resource(srs_srt_t srt_fd, enum SrtMode mode, ISrsResource** pr) { srs_error_t err = srs_success; @@ -260,7 +272,7 @@ srs_error_t SrsSrtServer::fd_to_resource(srs_srt_t srt_fd, ISrsResource** pr) SrsContextRestore(_srs_context->get_id()); // Covert to SRT conection. - *pr = new SrsMpegtsSrtConn(this, srt_fd, ip, port); + *pr = new SrsMpegtsSrtConn(this, srt_fd, ip, port, mode); return err; } diff --git a/trunk/src/app/srs_app_srt_server.hpp b/trunk/src/app/srs_app_srt_server.hpp index 23332d70295..24628084eb4 100644 --- a/trunk/src/app/srs_app_srt_server.hpp +++ b/trunk/src/app/srs_app_srt_server.hpp @@ -12,6 +12,7 @@ #include #include #include +#include class SrsSrtServer; class SrsHourGlass; @@ -22,11 +23,12 @@ class SrsSrtAcceptor : public ISrsSrtHandler private: std::string ip_; int port_; + enum SrtMode mode_; SrsSrtServer* srt_server_; private: SrsSrtListener* listener_; public: - SrsSrtAcceptor(SrsSrtServer* srt_server); + SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode); virtual ~SrsSrtAcceptor(); public: virtual srs_error_t listen(std::string ip, int port); @@ -60,9 +62,9 @@ class SrsSrtServer : public ISrsResourceManager, public ISrsHourGlass public: // When listener got a fd, notice server to accept it. // @param srt_fd, the client fd in srt boxed, the underlayer fd. - virtual srs_error_t accept_srt_client(srs_srt_t srt_fd); + virtual srs_error_t accept_srt_client(srs_srt_t srt_fd, enum SrtMode mode); private: - virtual srs_error_t fd_to_resource(srs_srt_t srt_fd, ISrsResource** pr); + virtual srs_error_t fd_to_resource(srs_srt_t srt_fd, enum SrtMode mode, ISrsResource** pr); // Interface ISrsResourceManager public: // A callback for connection to remove itself. diff --git a/trunk/src/app/srs_app_srt_utility.cpp b/trunk/src/app/srs_app_srt_utility.cpp index 28a26834f32..2a514e33ed4 100644 --- a/trunk/src/app/srs_app_srt_utility.cpp +++ b/trunk/src/app/srs_app_srt_utility.cpp @@ -145,3 +145,15 @@ bool srs_srt_streamid_to_request(const std::string& streamid, SrtMode& mode, Srs return ret; } + +std::string SrtMode2String(enum SrtMode mode) { + if (mode == SrtModePull) { + return "srtPull"; + } + + if (mode == SrtModePush) { + return "srtPush"; + } + + return "unkown"; +} diff --git a/trunk/src/app/srs_app_srt_utility.hpp b/trunk/src/app/srs_app_srt_utility.hpp index 74d2a912512..e4785f0ec7b 100644 --- a/trunk/src/app/srs_app_srt_utility.hpp +++ b/trunk/src/app/srs_app_srt_utility.hpp @@ -28,5 +28,6 @@ extern bool srs_srt_streamid_info(const std::string& streamid, SrtMode& mode, st // SRT streamid to request. extern bool srs_srt_streamid_to_request(const std::string& streamid, SrtMode& mode, SrsRequest* request); +extern std::string SrtMode2String(enum SrtMode mode); #endif From 0bb98721c6c30f54c08d8563b093241b4c5e5443 Mon Sep 17 00:00:00 2001 From: shiwei05 Date: Fri, 17 Feb 2023 14:39:04 +0800 Subject: [PATCH 02/21] add push/pull ports in srt --- trunk/conf/srt.conf | 3 ++- trunk/conf/srt2rtc.conf | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/trunk/conf/srt.conf b/trunk/conf/srt.conf index 582bc005639..3d6e5e374e3 100644 --- a/trunk/conf/srt.conf +++ b/trunk/conf/srt.conf @@ -18,7 +18,8 @@ http_server { srt_server { enabled on; - listen 10080; + pushport 10080; + pullport 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; diff --git a/trunk/conf/srt2rtc.conf b/trunk/conf/srt2rtc.conf index 2f4ac6ba460..d0f72ef8942 100644 --- a/trunk/conf/srt2rtc.conf +++ b/trunk/conf/srt2rtc.conf @@ -17,7 +17,8 @@ http_server { srt_server { enabled on; - listen 10080; + pushport 10080; + pullport 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; From 3dea82b18e723d948eb8364b4dad018d07ae7293 Mon Sep 17 00:00:00 2001 From: "alex.cr" Date: Fri, 17 Feb 2023 15:23:27 +0800 Subject: [PATCH 03/21] update mode in default unkown type --- trunk/src/app/srs_app_srt_conn.cpp | 12 +++++++----- trunk/src/app/srs_app_srt_utility.hpp | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index 62ea9f2ee52..aa6b270a8cc 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -265,12 +265,14 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() } // Detect streamid of srt to request. - SrtMode mode = SrtModePull; + SrtMode mode = SrtModeUnkown; if (!srs_srt_streamid_to_request(streamid, mode, req_)) { return srs_error_new(ERROR_SRT_CONN, "invalid srt streamid=%s", streamid.c_str()); } - (void)mode; + if (mode == SrtModeUnkown) { + mode = mode_; + } // discovery vhost, resolve the vhost from config SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req_->vhost); if (parsed_vhost) { @@ -282,7 +284,7 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() } srs_trace("@srt, streamid=%s, mode:%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", - streamid.c_str(), SrtMode2String(mode_).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); + streamid.c_str(), SrtMode2String(mode).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); if ((err = _srs_srt_sources->fetch_or_create(req_, &srt_source_)) != srs_success) { return srs_error_wrap(err, "fetch srt source"); @@ -292,9 +294,9 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_wrap(err, "on connect"); } - if (mode_ == SrtModePush) { + if (mode == SrtModePush) { err = publishing(); - } else if (mode_ == SrtModePull) { + } else if (mode == SrtModePull) { err = playing(); } diff --git a/trunk/src/app/srs_app_srt_utility.hpp b/trunk/src/app/srs_app_srt_utility.hpp index e4785f0ec7b..99806cb0b4f 100644 --- a/trunk/src/app/srs_app_srt_utility.hpp +++ b/trunk/src/app/srs_app_srt_utility.hpp @@ -18,8 +18,9 @@ class SrsRequest; enum SrtMode { - SrtModePull = 1, - SrtModePush = 2, + SrtModeUnkown = 0, + SrtModePull = 1, + SrtModePush = 2, }; // Get SRT streamid info. From 99234ed3ff507d9c4e4f87300e0ebf42d19519bb Mon Sep 17 00:00:00 2001 From: "alex.cr" Date: Fri, 17 Feb 2023 15:41:39 +0800 Subject: [PATCH 04/21] init srt mode=srt unkown type --- trunk/src/app/srs_app_srt_utility.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_srt_utility.cpp b/trunk/src/app/srs_app_srt_utility.cpp index 2a514e33ed4..f46fe94d475 100644 --- a/trunk/src/app/srs_app_srt_utility.cpp +++ b/trunk/src/app/srs_app_srt_utility.cpp @@ -20,7 +20,7 @@ using namespace std; // TODO: FIMXE: We should parse SRT streamid to URL object, rather than a HTTP url subpath. bool srs_srt_streamid_info(const std::string& streamid, SrtMode& mode, std::string& vhost, std::string& url_subpath) { - mode = SrtModePull; + mode = SrtModeUnkown; size_t pos = streamid.find("#!::"); if (pos != 0) { @@ -89,6 +89,7 @@ bool srs_srt_streamid_info(const std::string& streamid, SrtMode& mode, std::stri } else if (mode_str == "request") { mode = SrtModePull; } else { + mode = SrtModeUnkown; srs_warn("unknown mode_str:%s", mode_str.c_str()); return false; } From bc53d8fc12da214338e5b75c8330db7695e2fe4f Mon Sep 17 00:00:00 2001 From: shiwei05 Date: Thu, 16 Mar 2023 16:06:19 +0800 Subject: [PATCH 05/21] add new config --- trunk/src/app/srs_app_config.cpp | 228 +++++++++++---------------- trunk/src/app/srs_app_config.hpp | 36 +++-- trunk/src/app/srs_app_srt_server.cpp | 96 ++++++----- trunk/src/app/srs_app_srt_server.hpp | 3 +- 4 files changed, 167 insertions(+), 196 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 018a8957b65..4925aac15f0 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2311,7 +2311,7 @@ srs_error_t SrsConfig::check_normal_config() 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 != "pullport" && n != "pushport" && n != "maxbw" + if (n != "enabled" && n != "type" && n != "port" && n != "maxbw" && n != "mss" && n != "latency" && n != "recvlatency" && n != "peerlatency" && n != "connect_timeout" && n != "sendbuf" && n != "recvbuf" && n != "payloadsize" @@ -7654,308 +7654,262 @@ string SrsConfig::get_https_api_ssl_cert() return conf->arg0(); } +bool SrsConfig::is_srt_server(SrsConfDirective* srt_conf) { + return srt_conf->name == "srt_server"; +} + +void SrsConfig::get_srt_servers(vector& servers) +{ + srs_assert(root); + + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + if (!is_srt_server(conf)) { + continue; + } + servers.push_back(conf); + } +} + bool SrsConfig::get_srt_enabled() { SRS_OVERWRITE_BY_ENV_BOOL("srs.srt_server.enabled"); // SRS_SRT_SERVER_ENABLED + bool ret = false; - 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; + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + + srs_trace("name:%s", conf->name.c_str()); + if (!is_srt_server(conf)) { + continue; + } + conf = conf->get("enabled"); + if (!conf || conf->arg0().empty()) { + ret = false; + } else { + ret = true; + break; + } } - - return SRS_CONF_PERFER_FALSE(conf->arg0()); + + return ret; } -unsigned short SrsConfig::get_srt_push_port() +std::string SrsConfig::get_srt_type(SrsConfDirective* srt_conf) { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pushport"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.type"); - static unsigned short DEFAULT = 10080; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("pushport"); - if (!conf || conf->arg0().empty()) { + static std::string DEFAULT("push"); + + SrsConfDirective* type_conf = srt_conf->get("type"); + if (!type_conf || type_conf->arg0().empty()) { return DEFAULT; } - return (unsigned short)atoi(conf->arg0().c_str()); + return type_conf->arg0(); } -unsigned short SrsConfig::get_srt_pull_port() +unsigned short SrsConfig::get_srt_port(SrsConfDirective* srt_conf) { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pullport"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.port"); // SRS_SRT_SERVER_LISTEN static unsigned short DEFAULT = 10080; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("pullport"); - if (!conf || conf->arg0().empty()) { + + SrsConfDirective* port_conf = srt_conf->get("port"); + if (!port_conf || port_conf->arg0().empty()) { return DEFAULT; } - return (unsigned short)atoi(conf->arg0().c_str()); + return (unsigned short)atoi(port_conf->arg0().c_str()); } -int64_t SrsConfig::get_srto_maxbw() +int64_t SrsConfig::get_srto_maxbw(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.maxbw"); // SRS_SRT_SERVER_MAXBW static int64_t DEFAULT = -1; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("maxbw"); + SrsConfDirective* conf = srt_conf->get("maxbw"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoll(conf->arg0().c_str()); } -int SrsConfig::get_srto_mss() +int SrsConfig::get_srto_mss(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.mms"); // SRS_SRT_SERVER_MMS static int DEFAULT = 1500; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("mms"); + + SrsConfDirective* conf = srt_conf->get("mms"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -bool SrsConfig::get_srto_tsbpdmode() +bool SrsConfig::get_srto_tsbpdmode(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_BOOL2("srs.srt_server.tsbpdmode"); // SRS_SRT_SERVER_TSBPDMODE static bool DEFAULT = true; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("tsbpdmode"); + SrsConfDirective* conf = srt_conf->get("tsbpdmode"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return SRS_CONF_PERFER_TRUE(conf->arg0()); } -int SrsConfig::get_srto_latency() +int SrsConfig::get_srto_latency(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.latency"); // SRS_SRT_SERVER_LATENCY static int DEFAULT = 120; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("latency"); + SrsConfDirective* conf = srt_conf->get("latency"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_recv_latency() +int SrsConfig::get_srto_recv_latency(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.recvlatency"); // SRS_SRT_SERVER_RECVLATENCY static int DEFAULT = 120; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("recvlatency"); + SrsConfDirective* conf = srt_conf->get("recvlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_peer_latency() +int SrsConfig::get_srto_peer_latency(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.peerlatency"); // SRS_SRT_SERVER_PEERLATENCY static int DEFAULT = 0; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("peerlatency"); + SrsConfDirective* conf = srt_conf->get("peerlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -bool SrsConfig::get_srt_sei_filter() +bool SrsConfig::get_srt_sei_filter(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_BOOL2("srs.srt_server.sei_filter"); // SRS_SRT_SERVER_SEI_FILTER static bool DEFAULT = true; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("sei_filter"); + SrsConfDirective* conf = srt_conf->get("sei_filter"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return SRS_CONF_PERFER_TRUE(conf->arg0()); } -bool SrsConfig::get_srto_tlpktdrop() +bool SrsConfig::get_srto_tlpktdrop(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_BOOL2("srs.srt_server.tlpktdrop"); // SRS_SRT_SERVER_TLPKTDROP static bool DEFAULT = true; - SrsConfDirective* srt_server_conf = root->get("srt_server"); - if (!srt_server_conf) { - return DEFAULT; - } - SrsConfDirective* conf = srt_server_conf->get("tlpktdrop"); + SrsConfDirective* conf = srt_conf->get("tlpktdrop"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return SRS_CONF_PERFER_TRUE(conf->arg0()); } -srs_utime_t SrsConfig::get_srto_conntimeout() +srs_utime_t SrsConfig::get_srto_conntimeout(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_MILLISECONDS("srs.srt_server.connect_timeout"); // SRS_SRT_SERVER_CONNECT_TIMEOUT static srs_utime_t DEFAULT = 3 * SRS_UTIME_SECONDS; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("connect_timeout"); + + SrsConfDirective* conf = srt_conf->get("connect_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); } -srs_utime_t SrsConfig::get_srto_peeridletimeout() +srs_utime_t SrsConfig::get_srto_peeridletimeout(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_MILLISECONDS("srs.srt_server.peer_idle_timeout"); // SRS_SRT_SERVER_PEER_IDLE_TIMEOUT static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("peer_idle_timeout"); + SrsConfDirective* conf = srt_conf->get("peer_idle_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); } -int SrsConfig::get_srto_sendbuf() +int SrsConfig::get_srto_sendbuf(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.sendbuf"); // SRS_SRT_SERVER_SENDBUF static int DEFAULT = 8192 * (1500-28); - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("sendbuf"); + SrsConfDirective* conf = srt_conf->get("sendbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_recvbuf() +int SrsConfig::get_srto_recvbuf(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.recvbuf"); // SRS_SRT_SERVER_RECVBUF static int DEFAULT = 8192 * (1500-28); - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("recvbuf"); + SrsConfDirective* conf = srt_conf->get("recvbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_payloadsize() +int SrsConfig::get_srto_payloadsize(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.payloadsize"); // SRS_SRT_SERVER_PAYLOADSIZE static int DEFAULT = 1316; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("payloadsize"); + SrsConfDirective* conf = srt_conf->get("payloadsize"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -string SrsConfig::get_srto_passphrase() +string SrsConfig::get_srto_passphrase(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.passphrase"); // SRS_SRT_SERVER_PASSPHRASE static string DEFAULT = ""; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("passphrase"); + SrsConfDirective* conf = srt_conf->get("passphrase"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return conf->arg0(); } -int SrsConfig::get_srto_pbkeylen() +int SrsConfig::get_srto_pbkeylen(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pbkeylen"); // SRS_SRT_SERVER_PBKEYLEN static int DEFAULT = 0; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("pbkeylen"); + SrsConfDirective* conf = srt_conf->get("pbkeylen"); if (!conf || conf->arg0().empty()) { return DEFAULT; } @@ -7966,17 +7920,21 @@ string SrsConfig::get_default_app_name() { SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.default_app"); // SRS_SRT_SERVER_DEFAULT_APP - static string DEFAULT = "live"; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } + string ret = "live"; - conf = conf->get("default_app"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + + if (!is_srt_server(conf)) { + continue; + } + conf = conf->get("default_app"); + if (!conf || conf->arg0().empty()) { + ret = conf->arg0(); + break; + } } - return conf->arg0(); + return ret; } SrsConfDirective* SrsConfig::get_srt(std::string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index aaa8790f974..ee2538be1a2 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -650,41 +650,43 @@ class SrsConfig virtual SrsConfDirective* get_forward_backend(std::string vhost); public: + virtual bool is_srt_server(SrsConfDirective* srt_conf); + virtual void get_srt_servers(std::vector& servers); // Whether the srt sevice enabled virtual bool get_srt_enabled(); // Get the srt service listen port - virtual unsigned short get_srt_push_port(); - virtual unsigned short get_srt_pull_port(); + virtual unsigned short get_srt_port(SrsConfDirective* srt_conf); + virtual std::string get_srt_type(SrsConfDirective* srt_conf); // Get the srt SRTO_MAXBW, max bandwith, default is -1. - virtual int64_t get_srto_maxbw(); + virtual int64_t get_srto_maxbw(SrsConfDirective* srt_conf); // Get the srt SRTO_MSS, Maximum Segment Size, default is 1500. - virtual int get_srto_mss(); + virtual int get_srto_mss(SrsConfDirective* srt_conf); // Get the srt SRTO_TSBPDMODE, timestamp base packet delivery mode, default is false. - virtual bool get_srto_tsbpdmode(); + virtual bool get_srto_tsbpdmode(SrsConfDirective* srt_conf); // Get the srt SRTO_LATENCY, latency, default is 0 which means peer/recv latency is 120ms. - virtual int get_srto_latency(); + virtual int get_srto_latency(SrsConfDirective* srt_conf); // Get the srt SRTO_RCVLATENCY, recv latency, default is 120ms. - virtual int get_srto_recv_latency(); + virtual int get_srto_recv_latency(SrsConfDirective* srt_conf); // Get the srt SRTO_PEERLATENCY, peer latency, default is 0.. - virtual int get_srto_peer_latency(); + virtual int get_srto_peer_latency(SrsConfDirective* srt_conf); // Get the srt h264 sei filter, default is on, it will drop h264 sei packet. - virtual bool get_srt_sei_filter(); + virtual bool get_srt_sei_filter(SrsConfDirective* srt_conf); // Get the srt SRTO_TLPKTDROP, Too-late Packet Drop, default is true. - virtual bool get_srto_tlpktdrop(); + virtual bool get_srto_tlpktdrop(SrsConfDirective* srt_conf); // Get the srt SRTO_CONNTIMEO, connection timeout, default is 3000ms. - virtual srs_utime_t get_srto_conntimeout(); + virtual srs_utime_t get_srto_conntimeout(SrsConfDirective* srt_conf); // Get the srt SRTO_PEERIDLETIMEO, peer idle timeout, default is 10000ms. - virtual srs_utime_t get_srto_peeridletimeout(); + virtual srs_utime_t get_srto_peeridletimeout(SrsConfDirective* srt_conf); // Get the srt SRTO_SNDBUF, send buffer, default is 8192 × (1500-28). - virtual int get_srto_sendbuf(); + virtual int get_srto_sendbuf(SrsConfDirective* srt_conf); // Get the srt SRTO_RCVBUF, recv buffer, default is 8192 × (1500-28). - virtual int get_srto_recvbuf(); + virtual int get_srto_recvbuf(SrsConfDirective* srt_conf); // SRTO_PAYLOADSIZE - virtual int get_srto_payloadsize(); + virtual int get_srto_payloadsize(SrsConfDirective* srt_conf); // Get the srt SRTO_PASSPHRASE, default is empty. - virtual std::string get_srto_passphrase(); + virtual std::string get_srto_passphrase(SrsConfDirective* srt_conf); // Get the srt SRTO_PBKEYLEN, default is 0. - virtual int get_srto_pbkeylen(); + virtual int get_srto_pbkeylen(SrsConfDirective* srt_conf); // Get the default app. virtual std::string get_default_app_name(); private: diff --git a/trunk/src/app/srs_app_srt_server.cpp b/trunk/src/app/srs_app_srt_server.cpp index 1d03fdbf6a6..ffbaa36bc78 100644 --- a/trunk/src/app/srs_app_srt_server.cpp +++ b/trunk/src/app/srs_app_srt_server.cpp @@ -19,8 +19,9 @@ using namespace std; SrsSrtEventLoop* _srt_eventloop = NULL; #endif -SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode) +SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode, SrsConfDirective* srt_conf) { + srt_conf_ = srt_conf; port_ = 0; srt_server_ = srt_server; listener_ = NULL; @@ -66,61 +67,61 @@ srs_error_t SrsSrtAcceptor::set_srt_opt() { srs_error_t err = srs_success; - if ((err = srs_srt_set_maxbw(listener_->fd(), _srs_config->get_srto_maxbw())) != srs_success) { - return srs_error_wrap(err, "set opt maxbw=%" PRId64 " failed", _srs_config->get_srto_maxbw()); + if ((err = srs_srt_set_maxbw(listener_->fd(), _srs_config->get_srto_maxbw(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt maxbw=%" PRId64 " failed", _srs_config->get_srto_maxbw(srt_conf_)); } - if ((err = srs_srt_set_mss(listener_->fd(), _srs_config->get_srto_mss())) != srs_success) { - return srs_error_wrap(err, "set opt mss=%d failed", _srs_config->get_srto_mss()); + if ((err = srs_srt_set_mss(listener_->fd(), _srs_config->get_srto_mss(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt mss=%d failed", _srs_config->get_srto_mss(srt_conf_)); } - if ((err = srs_srt_set_tsbpdmode(listener_->fd(), _srs_config->get_srto_tsbpdmode())) != srs_success) { - return srs_error_wrap(err, "set opt tsbpdmode=%d failed", _srs_config->get_srto_tsbpdmode()); + if ((err = srs_srt_set_tsbpdmode(listener_->fd(), _srs_config->get_srto_tsbpdmode(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt tsbpdmode=%d failed", _srs_config->get_srto_tsbpdmode(srt_conf_)); } - if ((err = srs_srt_set_latency(listener_->fd(), _srs_config->get_srto_latency())) != srs_success) { - return srs_error_wrap(err, "set opt latency=%d failed", _srs_config->get_srto_latency()); + if ((err = srs_srt_set_latency(listener_->fd(), _srs_config->get_srto_latency(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt latency=%d failed", _srs_config->get_srto_latency(srt_conf_)); } - if ((err = srs_srt_set_rcv_latency(listener_->fd(), _srs_config->get_srto_recv_latency())) != srs_success) { - return srs_error_wrap(err, "set opt recvlatency=%d failed", _srs_config->get_srto_recv_latency()); + if ((err = srs_srt_set_rcv_latency(listener_->fd(), _srs_config->get_srto_recv_latency(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt recvlatency=%d failed", _srs_config->get_srto_recv_latency(srt_conf_)); } - if ((err = srs_srt_set_peer_latency(listener_->fd(), _srs_config->get_srto_peer_latency())) != srs_success) { - return srs_error_wrap(err, "set opt peerlatency=%d failed", _srs_config->get_srto_peer_latency()); + if ((err = srs_srt_set_peer_latency(listener_->fd(), _srs_config->get_srto_peer_latency(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt peerlatency=%d failed", _srs_config->get_srto_peer_latency(srt_conf_)); } - if ((err = srs_srt_set_tlpktdrop(listener_->fd(), _srs_config->get_srto_tlpktdrop())) != srs_success) { - return srs_error_wrap(err, "set opt tlpktdrop=%d failed", _srs_config->get_srto_tlpktdrop()); + if ((err = srs_srt_set_tlpktdrop(listener_->fd(), _srs_config->get_srto_tlpktdrop(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt tlpktdrop=%d failed", _srs_config->get_srto_tlpktdrop(srt_conf_)); } - if ((err = srs_srt_set_connect_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_conntimeout()))) != srs_success) { - return srs_error_wrap(err, "set opt connect_timeout=%d failed", _srs_config->get_srto_conntimeout()); + if ((err = srs_srt_set_connect_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_conntimeout(srt_conf_)))) != srs_success) { + return srs_error_wrap(err, "set opt connect_timeout=%d failed", _srs_config->get_srto_conntimeout(srt_conf_)); } - if ((err = srs_srt_set_peer_idle_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_peeridletimeout()))) != srs_success) { - return srs_error_wrap(err, "set opt peer_idle_timeout=%d failed", _srs_config->get_srto_peeridletimeout()); + if ((err = srs_srt_set_peer_idle_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_peeridletimeout(srt_conf_)))) != srs_success) { + return srs_error_wrap(err, "set opt peer_idle_timeout=%d failed", _srs_config->get_srto_peeridletimeout(srt_conf_)); } - if ((err = srs_srt_set_sndbuf(listener_->fd(), _srs_config->get_srto_sendbuf())) != srs_success) { - return srs_error_wrap(err, "set opt sendbuf=%d failed", _srs_config->get_srto_sendbuf()); + if ((err = srs_srt_set_sndbuf(listener_->fd(), _srs_config->get_srto_sendbuf(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt sendbuf=%d failed", _srs_config->get_srto_sendbuf(srt_conf_)); } - if ((err = srs_srt_set_rcvbuf(listener_->fd(), _srs_config->get_srto_recvbuf())) != srs_success) { - return srs_error_wrap(err, "set opt recvbuf=%d failed", _srs_config->get_srto_recvbuf()); + if ((err = srs_srt_set_rcvbuf(listener_->fd(), _srs_config->get_srto_recvbuf(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt recvbuf=%d failed", _srs_config->get_srto_recvbuf(srt_conf_)); } - if ((err = srs_srt_set_payload_size(listener_->fd(), _srs_config->get_srto_payloadsize())) != srs_success) { - return srs_error_wrap(err, "set opt payload_size=%d failed", _srs_config->get_srto_payloadsize()); + if ((err = srs_srt_set_payload_size(listener_->fd(), _srs_config->get_srto_payloadsize(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt payload_size=%d failed", _srs_config->get_srto_payloadsize(srt_conf_)); } - string passphrase = _srs_config->get_srto_passphrase(); + string passphrase = _srs_config->get_srto_passphrase(srt_conf_); if (! passphrase.empty()) { if ((err = srs_srt_set_passphrase(listener_->fd(), passphrase)) != srs_success) { return srs_error_wrap(err, "set opt passphrase=%s failed", passphrase.c_str()); } - int pbkeylen = _srs_config->get_srto_pbkeylen(); + int pbkeylen = _srs_config->get_srto_pbkeylen(srt_conf_); if ((err = srs_srt_set_pbkeylen(listener_->fd(), pbkeylen)) != srs_success) { return srs_error_wrap(err, "set opt pbkeylen=%d failed", pbkeylen); } @@ -189,6 +190,7 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() { srs_error_t err = srs_success; + srs_trace("srt enable:%s", _srs_config->get_srt_enabled() ? "true" : "false"); if (! _srs_config->get_srt_enabled()) { return err; } @@ -196,27 +198,35 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() // Close all listener for SRT if exists. close_listeners(); - // Start a push listener for SRT - SrsSrtAcceptor* pushAcceptor = new SrsSrtAcceptor(this, SrtModePush); - acceptors_.push_back(pushAcceptor); + std::vector srt_conf_vec; - int port; string ip; - srs_parse_endpoint(srs_int2str(_srs_config->get_srt_push_port()), ip, port); + _srs_config->get_srt_servers(srt_conf_vec); - if ((err = pushAcceptor->listen(ip, port)) != srs_success) { - return srs_error_wrap(err, "srt push listen %s:%d", ip.c_str(), port); - } - srs_trace("srt push listen:%s:%d", ip.c_str(), port); + for (auto srt_conf : srt_conf_vec) { + std::string srt_type = _srs_config->get_srt_type(srt_conf); + int port; + std::string ip; + enum SrtMode srt_mode = SrtModePush; - // Start a pull listener for SRT - SrsSrtAcceptor* pullAcceptor = new SrsSrtAcceptor(this, SrtModePull); - acceptors_.push_back(pullAcceptor); + srs_parse_endpoint(srs_int2str(_srs_config->get_srt_port(srt_conf)), ip, port); + if (srt_type == "pull") { + srt_mode = SrtModePull; + } else { + srt_mode = SrtModePush; + } - srs_parse_endpoint(srs_int2str(_srs_config->get_srt_pull_port()), ip, port); - if ((err = pullAcceptor->listen(ip, port)) != srs_success) { - return srs_error_wrap(err, "srt pull listen %s:%d", ip.c_str(), port); + SrsSrtAcceptor* acceptor = new SrsSrtAcceptor(this, srt_mode, srt_conf); + acceptors_.push_back(acceptor); + + if ((err = acceptor->listen(ip, port)) != srs_success) { + return srs_error_wrap(err, "srt %s listen %s:%d", + srt_mode == SrtModePull ? "pull" : "push", + ip.c_str(), port); + } + srs_trace("srt %s listen:%s:%d", + srt_mode == SrtModePull ? "pull" : "push", + ip.c_str(), port); } - srs_trace("srt pull listen:%s:%d", ip.c_str(), port); return err; } diff --git a/trunk/src/app/srs_app_srt_server.hpp b/trunk/src/app/srs_app_srt_server.hpp index 24628084eb4..c1ddbc041d0 100644 --- a/trunk/src/app/srs_app_srt_server.hpp +++ b/trunk/src/app/srs_app_srt_server.hpp @@ -21,6 +21,7 @@ class SrsHourGlass; class SrsSrtAcceptor : public ISrsSrtHandler { private: + SrsConfDirective* srt_conf_; std::string ip_; int port_; enum SrtMode mode_; @@ -28,7 +29,7 @@ class SrsSrtAcceptor : public ISrsSrtHandler private: SrsSrtListener* listener_; public: - SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode); + SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode, SrsConfDirective* srt_conf); virtual ~SrsSrtAcceptor(); public: virtual srs_error_t listen(std::string ip, int port); From 8bdc27f9455a3655e99af24b51f7fb1b758e5ed0 Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Thu, 16 Mar 2023 19:03:10 +0800 Subject: [PATCH 06/21] srt pull/push server config --- trunk/src/app/srs_app_config.cpp | 1 - trunk/src/app/srs_app_srt_conn.cpp | 3 ++- trunk/src/app/srs_app_srt_server.cpp | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 4925aac15f0..558e713c38b 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -7679,7 +7679,6 @@ bool SrsConfig::get_srt_enabled() for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* conf = root->at(i); - srs_trace("name:%s", conf->name.c_str()); if (!is_srt_server(conf)) { continue; } diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index aa6b270a8cc..2c0a1dba9ce 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -284,7 +284,8 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() } srs_trace("@srt, streamid=%s, mode:%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", - streamid.c_str(), SrtMode2String(mode).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); + streamid.c_str(), SrtMode2String(mode).c_str(), req_->get_stream_url().c_str(), + req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); if ((err = _srs_srt_sources->fetch_or_create(req_, &srt_source_)) != srs_success) { return srs_error_wrap(err, "fetch srt source"); diff --git a/trunk/src/app/srs_app_srt_server.cpp b/trunk/src/app/srs_app_srt_server.cpp index ffbaa36bc78..b65c8bbbd34 100644 --- a/trunk/src/app/srs_app_srt_server.cpp +++ b/trunk/src/app/srs_app_srt_server.cpp @@ -58,7 +58,8 @@ srs_error_t SrsSrtAcceptor::listen(std::string ip, int port) return srs_error_wrap(err, "message srt acceptor"); } - srs_trace("srt listen at udp://%s:%d, fd=%d", ip_.c_str(), port_, listener_->fd()); + srs_trace("srt listen at udp://%s:%d, fd=%d, mode:%s", + ip_.c_str(), port_, listener_->fd(), SrtMode2String(mode_).c_str()); return err; } @@ -223,9 +224,6 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() srt_mode == SrtModePull ? "pull" : "push", ip.c_str(), port); } - srs_trace("srt %s listen:%s:%d", - srt_mode == SrtModePull ? "pull" : "push", - ip.c_str(), port); } return err; From dfc33729498600a88d5ab605be42eb62b92dcf2e Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Thu, 16 Mar 2023 19:14:32 +0800 Subject: [PATCH 07/21] update for multiple srt_server --- trunk/conf/srt.conf | 19 +++++++++++++++++-- trunk/conf/srt2rtc.conf | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/trunk/conf/srt.conf b/trunk/conf/srt.conf index 3d6e5e374e3..3ea77dd10ac 100644 --- a/trunk/conf/srt.conf +++ b/trunk/conf/srt.conf @@ -18,8 +18,23 @@ http_server { srt_server { enabled on; - pushport 10080; - pullport 10081; + type push; + port 10080; + maxbw 1000000000; + connect_timeout 4000; + peerlatency 0; + recvlatency 0; + latency 0; + tsbpdmode off; + tlpktdrop off; + sendbuf 2000000; + recvbuf 2000000; +} + +srt_server { + enabled on; + type pull; + port 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; diff --git a/trunk/conf/srt2rtc.conf b/trunk/conf/srt2rtc.conf index d0f72ef8942..f263f9fe6b6 100644 --- a/trunk/conf/srt2rtc.conf +++ b/trunk/conf/srt2rtc.conf @@ -17,8 +17,18 @@ http_server { srt_server { enabled on; - pushport 10080; - pullport 10081; + type push; + port 10080; + maxbw 1000000000; + connect_timeout 4000; + peerlatency 0; + recvlatency 0; +} + +srt_server { + enabled on; + type pull; + port 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; From 954a75d361eb55ed5d34636eb3ade8cdae0928e1 Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Mon, 20 Mar 2023 11:08:36 +0800 Subject: [PATCH 08/21] solve utest --- trunk/src/app/srs_app_config.cpp | 55 +++++++++++++++++++++++++++- trunk/src/utest/srs_utest_config.cpp | 28 +++++++------- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 558e713c38b..5d49ce0545f 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -7655,7 +7655,7 @@ string SrsConfig::get_https_api_ssl_cert() } bool SrsConfig::is_srt_server(SrsConfDirective* srt_conf) { - return srt_conf->name == "srt_server"; + return srt_conf && srt_conf->name == "srt_server"; } void SrsConfig::get_srt_servers(vector& servers) @@ -7700,6 +7700,9 @@ std::string SrsConfig::get_srt_type(SrsConfDirective* srt_conf) static std::string DEFAULT("push"); + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* type_conf = srt_conf->get("type"); if (!type_conf || type_conf->arg0().empty()) { return DEFAULT; @@ -7713,6 +7716,10 @@ unsigned short SrsConfig::get_srt_port(SrsConfDirective* srt_conf) static unsigned short DEFAULT = 10080; + if (!srt_conf) { + return DEFAULT; + } + SrsConfDirective* port_conf = srt_conf->get("port"); if (!port_conf || port_conf->arg0().empty()) { return DEFAULT; @@ -7726,6 +7733,9 @@ int64_t SrsConfig::get_srto_maxbw(SrsConfDirective* srt_conf) static int64_t DEFAULT = -1; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("maxbw"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7739,6 +7749,10 @@ int SrsConfig::get_srto_mss(SrsConfDirective* srt_conf) static int DEFAULT = 1500; + if (!srt_conf) { + return DEFAULT; + } + SrsConfDirective* conf = srt_conf->get("mms"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7752,6 +7766,9 @@ bool SrsConfig::get_srto_tsbpdmode(SrsConfDirective* srt_conf) static bool DEFAULT = true; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("tsbpdmode"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7765,6 +7782,9 @@ int SrsConfig::get_srto_latency(SrsConfDirective* srt_conf) static int DEFAULT = 120; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("latency"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7778,6 +7798,9 @@ int SrsConfig::get_srto_recv_latency(SrsConfDirective* srt_conf) static int DEFAULT = 120; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("recvlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7791,6 +7814,9 @@ int SrsConfig::get_srto_peer_latency(SrsConfDirective* srt_conf) static int DEFAULT = 0; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("peerlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7804,6 +7830,9 @@ bool SrsConfig::get_srt_sei_filter(SrsConfDirective* srt_conf) static bool DEFAULT = true; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("sei_filter"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7817,6 +7846,9 @@ bool SrsConfig::get_srto_tlpktdrop(SrsConfDirective* srt_conf) static bool DEFAULT = true; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("tlpktdrop"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7830,6 +7862,9 @@ srs_utime_t SrsConfig::get_srto_conntimeout(SrsConfDirective* srt_conf) static srs_utime_t DEFAULT = 3 * SRS_UTIME_SECONDS; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("connect_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7843,6 +7878,9 @@ srs_utime_t SrsConfig::get_srto_peeridletimeout(SrsConfDirective* srt_conf) static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("peer_idle_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7856,6 +7894,9 @@ int SrsConfig::get_srto_sendbuf(SrsConfDirective* srt_conf) static int DEFAULT = 8192 * (1500-28); + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("sendbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7869,6 +7910,9 @@ int SrsConfig::get_srto_recvbuf(SrsConfDirective* srt_conf) static int DEFAULT = 8192 * (1500-28); + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("recvbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7882,6 +7926,9 @@ int SrsConfig::get_srto_payloadsize(SrsConfDirective* srt_conf) static int DEFAULT = 1316; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("payloadsize"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7895,6 +7942,9 @@ string SrsConfig::get_srto_passphrase(SrsConfDirective* srt_conf) static string DEFAULT = ""; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("passphrase"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7908,6 +7958,9 @@ int SrsConfig::get_srto_pbkeylen(SrsConfDirective* srt_conf) static int DEFAULT = 0; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("pbkeylen"); if (!conf || conf->arg0().empty()) { return DEFAULT; diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 9ea532676c6..b258cdac908 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -4185,49 +4185,49 @@ VOID TEST(ConfigEnvTest, CheckEnvValuesSrtServer) EXPECT_TRUE(conf.get_srt_enabled()); SrsSetEnvConfig(srt_listen_port, "SRS_SRT_SERVER_LISTEN", "10000"); - EXPECT_EQ(10000, conf.get_srt_listen_port()); + EXPECT_EQ(10000, conf.get_srt_port(nullptr)); SrsSetEnvConfig(srto_maxbw, "SRS_SRT_SERVER_MAXBW", "1000000000"); - EXPECT_EQ(1000000000, conf.get_srto_maxbw()); + EXPECT_EQ(1000000000, conf.get_srto_maxbw(nullptr)); SrsSetEnvConfig(srto_mss, "SRS_SRT_SERVER_MMS", "1000"); - EXPECT_EQ(1000, conf.get_srto_mss()); + EXPECT_EQ(1000, conf.get_srto_mss(nullptr)); SrsSetEnvConfig(srto_conntimeout, "SRS_SRT_SERVER_CONNECT_TIMEOUT", "2000"); - EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_conntimeout()); + EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_conntimeout(nullptr)); SrsSetEnvConfig(srto_peeridletimeout, "SRS_SRT_SERVER_PEER_IDLE_TIMEOUT", "2000"); - EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_peeridletimeout()); + EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_peeridletimeout(nullptr)); SrsSetEnvConfig(default_app_name, "SRS_SRT_SERVER_DEFAULT_APP", "xxx"); EXPECT_STREQ("xxx", conf.get_default_app_name().c_str()); SrsSetEnvConfig(srto_peer_latency, "SRS_SRT_SERVER_PEERLATENCY", "1"); - EXPECT_EQ(1, conf.get_srto_peer_latency()); + EXPECT_EQ(1, conf.get_srto_peer_latency(nullptr)); SrsSetEnvConfig(srto_recv_latency, "SRS_SRT_SERVER_RECVLATENCY", "100"); - EXPECT_EQ(100, conf.get_srto_recv_latency()); + EXPECT_EQ(100, conf.get_srto_recv_latency(nullptr)); SrsSetEnvConfig(srto_latency, "SRS_SRT_SERVER_LATENCY", "100"); - EXPECT_EQ(100, conf.get_srto_latency()); + EXPECT_EQ(100, conf.get_srto_latency(nullptr)); SrsSetEnvConfig(srto_tsbpdmode, "SRS_SRT_SERVER_TSBPDMODE", "off"); - EXPECT_FALSE(conf.get_srto_tsbpdmode()); + EXPECT_FALSE(conf.get_srto_tsbpdmode(nullptr)); SrsSetEnvConfig(srto_tlpktdrop, "SRS_SRT_SERVER_TLPKTDROP", "off"); - EXPECT_FALSE(conf.get_srto_tlpktdrop()); + EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); SrsSetEnvConfig(srto_sendbuf, "SRS_SRT_SERVER_SENDBUF", "2100000"); - EXPECT_EQ(2100000, conf.get_srto_sendbuf()); + EXPECT_EQ(2100000, conf.get_srto_sendbuf(nullptr)); SrsSetEnvConfig(srto_recvbuf, "SRS_SRT_SERVER_RECVBUF", "2100000"); - EXPECT_EQ(2100000, conf.get_srto_recvbuf()); + EXPECT_EQ(2100000, conf.get_srto_recvbuf(nullptr)); SrsSetEnvConfig(srto_passphrase, "SRS_SRT_SERVER_PASSPHRASE", "xxx2"); - EXPECT_STREQ("xxx2", conf.get_srto_passphrase().c_str()); + EXPECT_STREQ("xxx2", conf.get_srto_passphrase(nullptr).c_str()); SrsSetEnvConfig(srto_pbkeylen, "SRS_SRT_SERVER_PBKEYLEN", "16"); - EXPECT_EQ(16, conf.get_srto_pbkeylen()); + EXPECT_EQ(16, conf.get_srto_pbkeylen(nullptr)); } } From ee999ca51d9e06f9651192e7e180ef7e3e0c070d Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Mon, 20 Mar 2023 11:15:18 +0800 Subject: [PATCH 09/21] solve utest bug --- trunk/src/utest/srs_utest_config.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index b258cdac908..7f5ccdde6a1 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -3919,19 +3919,19 @@ VOID TEST(ConfigMainTest, SrtServerTlpktDrop) if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); - EXPECT_TRUE(conf.get_srto_tlpktdrop()); + EXPECT_TRUE(conf.get_srto_tlpktdrop(nullptr)); } if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srt_server{tlpktdrop off;}")); - EXPECT_FALSE(conf.get_srto_tlpktdrop()); + EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); } if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srt_server{tlpkdrop off;}")); - EXPECT_FALSE(conf.get_srto_tlpktdrop()); + EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); } } From c9a7ac3e35eef1f13ada767eb9d0ae098262ec95 Mon Sep 17 00:00:00 2001 From: shiwei05 Date: Fri, 17 Feb 2023 11:29:20 +0800 Subject: [PATCH 10/21] add push/pull ports --- trunk/src/app/srs_app_config.cpp | 25 ++++++++++++++++--- trunk/src/app/srs_app_config.hpp | 3 ++- trunk/src/app/srs_app_srt_conn.cpp | 12 +++++---- trunk/src/app/srs_app_srt_conn.hpp | 3 ++- trunk/src/app/srs_app_srt_server.cpp | 36 ++++++++++++++++++--------- trunk/src/app/srs_app_srt_server.hpp | 8 +++--- trunk/src/app/srs_app_srt_utility.cpp | 12 +++++++++ trunk/src/app/srs_app_srt_utility.hpp | 1 + 8 files changed, 74 insertions(+), 26 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 27c2000b05b..f8dc078df31 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2311,7 +2311,7 @@ srs_error_t SrsConfig::check_normal_config() 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" && n != "maxbw" + if (n != "enabled" && n != "pullport" && n != "pushport" && n != "maxbw" && n != "mss" && n != "latency" && n != "recvlatency" && n != "peerlatency" && n != "connect_timeout" && n != "sendbuf" && n != "recvbuf" && n != "payloadsize" @@ -7710,9 +7710,9 @@ bool SrsConfig::get_srt_enabled() return SRS_CONF_PERFER_FALSE(conf->arg0()); } -unsigned short SrsConfig::get_srt_listen_port() +unsigned short SrsConfig::get_srt_push_port() { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.listen"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pushport"); // SRS_SRT_SERVER_LISTEN static unsigned short DEFAULT = 10080; SrsConfDirective* conf = root->get("srt_server"); @@ -7720,7 +7720,24 @@ unsigned short SrsConfig::get_srt_listen_port() return DEFAULT; } - conf = conf->get("listen"); + conf = conf->get("pushport"); + if (!conf || conf->arg0().empty()) { + return DEFAULT; + } + return (unsigned short)atoi(conf->arg0().c_str()); +} + +unsigned short SrsConfig::get_srt_pull_port() +{ + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pullport"); // SRS_SRT_SERVER_LISTEN + + static unsigned short DEFAULT = 10080; + SrsConfDirective* conf = root->get("srt_server"); + if (!conf) { + return DEFAULT; + } + + conf = conf->get("pullport"); if (!conf || conf->arg0().empty()) { return DEFAULT; } diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index f0028b357b1..8eab37bedb5 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -656,7 +656,8 @@ class SrsConfig // Whether the srt sevice enabled virtual bool get_srt_enabled(); // Get the srt service listen port - virtual unsigned short get_srt_listen_port(); + virtual unsigned short get_srt_push_port(); + virtual unsigned short get_srt_pull_port(); // Get the srt SRTO_MAXBW, max bandwith, default is -1. virtual int64_t get_srto_maxbw(); // Get the srt SRTO_MSS, Maximum Segment Size, default is 1500. diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index df51160597e..62ea9f2ee52 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -152,7 +152,7 @@ srs_error_t SrsSrtRecvThread::get_recv_err() return srs_error_copy(recv_err_); } -SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port) +SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port, enum SrtMode mode) { // Create a identify for this client. _srs_context->set_id(_srs_context->generate_id()); @@ -163,6 +163,7 @@ SrsMpegtsSrtConn::SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, s srt_conn_ = new SrsSrtConnection(srt_fd_); ip_ = ip; port_ = port; + mode_ = mode; kbps_ = new SrsNetworkKbps(); kbps_->set_io(srt_conn_, srt_conn_); @@ -269,6 +270,7 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_new(ERROR_SRT_CONN, "invalid srt streamid=%s", streamid.c_str()); } + (void)mode; // discovery vhost, resolve the vhost from config SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req_->vhost); if (parsed_vhost) { @@ -279,8 +281,8 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_new(ERROR_SRT_CONN, "srt disabled, vhost=%s", req_->vhost.c_str()); } - srs_trace("@srt, streamid=%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", - streamid.c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); + srs_trace("@srt, streamid=%s, mode:%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", + streamid.c_str(), SrtMode2String(mode_).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); if ((err = _srs_srt_sources->fetch_or_create(req_, &srt_source_)) != srs_success) { return srs_error_wrap(err, "fetch srt source"); @@ -290,9 +292,9 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_wrap(err, "on connect"); } - if (mode == SrtModePush) { + if (mode_ == SrtModePush) { err = publishing(); - } else if (mode == SrtModePull) { + } else if (mode_ == SrtModePull) { err = playing(); } diff --git a/trunk/src/app/srs_app_srt_conn.hpp b/trunk/src/app/srs_app_srt_conn.hpp index d651659f296..4e1388e90d2 100644 --- a/trunk/src/app/srs_app_srt_conn.hpp +++ b/trunk/src/app/srs_app_srt_conn.hpp @@ -74,7 +74,7 @@ class SrsSrtRecvThread : public ISrsCoroutineHandler class SrsMpegtsSrtConn : public ISrsConnection, public ISrsStartable, public ISrsCoroutineHandler, public ISrsExpire { public: - SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port); + SrsMpegtsSrtConn(SrsSrtServer* srt_server, srs_srt_t srt_fd, std::string ip, int port, enum SrtMode mode); virtual ~SrsMpegtsSrtConn(); // Interface ISrsResource. public: @@ -119,6 +119,7 @@ class SrsMpegtsSrtConn : public ISrsConnection, public ISrsStartable, public ISr SrsNetworkKbps* kbps_; std::string ip_; int port_; + enum SrtMode mode_; SrsCoroutine* trd_; SrsRequest* req_; diff --git a/trunk/src/app/srs_app_srt_server.cpp b/trunk/src/app/srs_app_srt_server.cpp index 5f0635e405e..1d03fdbf6a6 100644 --- a/trunk/src/app/srs_app_srt_server.cpp +++ b/trunk/src/app/srs_app_srt_server.cpp @@ -19,11 +19,12 @@ using namespace std; SrsSrtEventLoop* _srt_eventloop = NULL; #endif -SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server) +SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode) { port_ = 0; srt_server_ = srt_server; listener_ = NULL; + mode_ = mode; } SrsSrtAcceptor::~SrsSrtAcceptor() @@ -133,7 +134,7 @@ srs_error_t SrsSrtAcceptor::on_srt_client(srs_srt_t srt_fd) srs_error_t err = srs_success; // Notify srt server to accept srt client, and create new SrsSrtConn on it. - if ((err = srt_server_->accept_srt_client(srt_fd)) != srs_success) { + if ((err = srt_server_->accept_srt_client(srt_fd, mode_)) != srs_success) { srs_warn("accept srt client failed, err is %s", srs_error_desc(err).c_str()); srs_freep(err); } @@ -195,16 +196,27 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() // Close all listener for SRT if exists. close_listeners(); - // Start a listener for SRT, we might need multiple listeners in the future. - SrsSrtAcceptor* acceptor = new SrsSrtAcceptor(this); - acceptors_.push_back(acceptor); + // Start a push listener for SRT + SrsSrtAcceptor* pushAcceptor = new SrsSrtAcceptor(this, SrtModePush); + acceptors_.push_back(pushAcceptor); int port; string ip; - srs_parse_endpoint(srs_int2str(_srs_config->get_srt_listen_port()), ip, port); + srs_parse_endpoint(srs_int2str(_srs_config->get_srt_push_port()), ip, port); - if ((err = acceptor->listen(ip, port)) != srs_success) { - return srs_error_wrap(err, "srt listen %s:%d", ip.c_str(), port); + if ((err = pushAcceptor->listen(ip, port)) != srs_success) { + return srs_error_wrap(err, "srt push listen %s:%d", ip.c_str(), port); } + srs_trace("srt push listen:%s:%d", ip.c_str(), port); + + // Start a pull listener for SRT + SrsSrtAcceptor* pullAcceptor = new SrsSrtAcceptor(this, SrtModePull); + acceptors_.push_back(pullAcceptor); + + srs_parse_endpoint(srs_int2str(_srs_config->get_srt_pull_port()), ip, port); + if ((err = pullAcceptor->listen(ip, port)) != srs_success) { + return srs_error_wrap(err, "srt pull listen %s:%d", ip.c_str(), port); + } + srs_trace("srt pull listen:%s:%d", ip.c_str(), port); return err; } @@ -220,12 +232,12 @@ void SrsSrtServer::close_listeners() } } -srs_error_t SrsSrtServer::accept_srt_client(srs_srt_t srt_fd) +srs_error_t SrsSrtServer::accept_srt_client(srs_srt_t srt_fd, enum SrtMode mode) { srs_error_t err = srs_success; ISrsResource* resource = NULL; - if ((err = fd_to_resource(srt_fd, &resource)) != srs_success) { + if ((err = fd_to_resource(srt_fd, mode, &resource)) != srs_success) { //close fd on conn error, otherwise will lead to fd leak -gs // TODO: FIXME: Handle error. srs_srt_close(srt_fd); @@ -244,7 +256,7 @@ srs_error_t SrsSrtServer::accept_srt_client(srs_srt_t srt_fd) return err; } -srs_error_t SrsSrtServer::fd_to_resource(srs_srt_t srt_fd, ISrsResource** pr) +srs_error_t SrsSrtServer::fd_to_resource(srs_srt_t srt_fd, enum SrtMode mode, ISrsResource** pr) { srs_error_t err = srs_success; @@ -260,7 +272,7 @@ srs_error_t SrsSrtServer::fd_to_resource(srs_srt_t srt_fd, ISrsResource** pr) SrsContextRestore(_srs_context->get_id()); // Covert to SRT conection. - *pr = new SrsMpegtsSrtConn(this, srt_fd, ip, port); + *pr = new SrsMpegtsSrtConn(this, srt_fd, ip, port, mode); return err; } diff --git a/trunk/src/app/srs_app_srt_server.hpp b/trunk/src/app/srs_app_srt_server.hpp index 23332d70295..24628084eb4 100644 --- a/trunk/src/app/srs_app_srt_server.hpp +++ b/trunk/src/app/srs_app_srt_server.hpp @@ -12,6 +12,7 @@ #include #include #include +#include class SrsSrtServer; class SrsHourGlass; @@ -22,11 +23,12 @@ class SrsSrtAcceptor : public ISrsSrtHandler private: std::string ip_; int port_; + enum SrtMode mode_; SrsSrtServer* srt_server_; private: SrsSrtListener* listener_; public: - SrsSrtAcceptor(SrsSrtServer* srt_server); + SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode); virtual ~SrsSrtAcceptor(); public: virtual srs_error_t listen(std::string ip, int port); @@ -60,9 +62,9 @@ class SrsSrtServer : public ISrsResourceManager, public ISrsHourGlass public: // When listener got a fd, notice server to accept it. // @param srt_fd, the client fd in srt boxed, the underlayer fd. - virtual srs_error_t accept_srt_client(srs_srt_t srt_fd); + virtual srs_error_t accept_srt_client(srs_srt_t srt_fd, enum SrtMode mode); private: - virtual srs_error_t fd_to_resource(srs_srt_t srt_fd, ISrsResource** pr); + virtual srs_error_t fd_to_resource(srs_srt_t srt_fd, enum SrtMode mode, ISrsResource** pr); // Interface ISrsResourceManager public: // A callback for connection to remove itself. diff --git a/trunk/src/app/srs_app_srt_utility.cpp b/trunk/src/app/srs_app_srt_utility.cpp index 28a26834f32..2a514e33ed4 100644 --- a/trunk/src/app/srs_app_srt_utility.cpp +++ b/trunk/src/app/srs_app_srt_utility.cpp @@ -145,3 +145,15 @@ bool srs_srt_streamid_to_request(const std::string& streamid, SrtMode& mode, Srs return ret; } + +std::string SrtMode2String(enum SrtMode mode) { + if (mode == SrtModePull) { + return "srtPull"; + } + + if (mode == SrtModePush) { + return "srtPush"; + } + + return "unkown"; +} diff --git a/trunk/src/app/srs_app_srt_utility.hpp b/trunk/src/app/srs_app_srt_utility.hpp index 74d2a912512..e4785f0ec7b 100644 --- a/trunk/src/app/srs_app_srt_utility.hpp +++ b/trunk/src/app/srs_app_srt_utility.hpp @@ -28,5 +28,6 @@ extern bool srs_srt_streamid_info(const std::string& streamid, SrtMode& mode, st // SRT streamid to request. extern bool srs_srt_streamid_to_request(const std::string& streamid, SrtMode& mode, SrsRequest* request); +extern std::string SrtMode2String(enum SrtMode mode); #endif From 45433cfd193c144d4ed07af30295d09bc0c02d73 Mon Sep 17 00:00:00 2001 From: shiwei05 Date: Fri, 17 Feb 2023 14:39:04 +0800 Subject: [PATCH 11/21] add push/pull ports in srt --- trunk/conf/srt.conf | 3 ++- trunk/conf/srt2rtc.conf | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/trunk/conf/srt.conf b/trunk/conf/srt.conf index 582bc005639..3d6e5e374e3 100644 --- a/trunk/conf/srt.conf +++ b/trunk/conf/srt.conf @@ -18,7 +18,8 @@ http_server { srt_server { enabled on; - listen 10080; + pushport 10080; + pullport 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; diff --git a/trunk/conf/srt2rtc.conf b/trunk/conf/srt2rtc.conf index 2f4ac6ba460..d0f72ef8942 100644 --- a/trunk/conf/srt2rtc.conf +++ b/trunk/conf/srt2rtc.conf @@ -17,7 +17,8 @@ http_server { srt_server { enabled on; - listen 10080; + pushport 10080; + pullport 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; From e0ca038328cae7a9897a255bb19585f1b3c7eaa5 Mon Sep 17 00:00:00 2001 From: "alex.cr" Date: Fri, 17 Feb 2023 15:23:27 +0800 Subject: [PATCH 12/21] update mode in default unkown type --- trunk/src/app/srs_app_srt_conn.cpp | 12 +++++++----- trunk/src/app/srs_app_srt_utility.hpp | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index 62ea9f2ee52..aa6b270a8cc 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -265,12 +265,14 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() } // Detect streamid of srt to request. - SrtMode mode = SrtModePull; + SrtMode mode = SrtModeUnkown; if (!srs_srt_streamid_to_request(streamid, mode, req_)) { return srs_error_new(ERROR_SRT_CONN, "invalid srt streamid=%s", streamid.c_str()); } - (void)mode; + if (mode == SrtModeUnkown) { + mode = mode_; + } // discovery vhost, resolve the vhost from config SrsConfDirective* parsed_vhost = _srs_config->get_vhost(req_->vhost); if (parsed_vhost) { @@ -282,7 +284,7 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() } srs_trace("@srt, streamid=%s, mode:%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", - streamid.c_str(), SrtMode2String(mode_).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); + streamid.c_str(), SrtMode2String(mode).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); if ((err = _srs_srt_sources->fetch_or_create(req_, &srt_source_)) != srs_success) { return srs_error_wrap(err, "fetch srt source"); @@ -292,9 +294,9 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() return srs_error_wrap(err, "on connect"); } - if (mode_ == SrtModePush) { + if (mode == SrtModePush) { err = publishing(); - } else if (mode_ == SrtModePull) { + } else if (mode == SrtModePull) { err = playing(); } diff --git a/trunk/src/app/srs_app_srt_utility.hpp b/trunk/src/app/srs_app_srt_utility.hpp index e4785f0ec7b..99806cb0b4f 100644 --- a/trunk/src/app/srs_app_srt_utility.hpp +++ b/trunk/src/app/srs_app_srt_utility.hpp @@ -18,8 +18,9 @@ class SrsRequest; enum SrtMode { - SrtModePull = 1, - SrtModePush = 2, + SrtModeUnkown = 0, + SrtModePull = 1, + SrtModePush = 2, }; // Get SRT streamid info. From 5e4747237d92450707be49f1fe99b1e9ea4c4703 Mon Sep 17 00:00:00 2001 From: "alex.cr" Date: Fri, 17 Feb 2023 15:41:39 +0800 Subject: [PATCH 13/21] init srt mode=srt unkown type --- trunk/src/app/srs_app_srt_utility.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_srt_utility.cpp b/trunk/src/app/srs_app_srt_utility.cpp index 2a514e33ed4..f46fe94d475 100644 --- a/trunk/src/app/srs_app_srt_utility.cpp +++ b/trunk/src/app/srs_app_srt_utility.cpp @@ -20,7 +20,7 @@ using namespace std; // TODO: FIMXE: We should parse SRT streamid to URL object, rather than a HTTP url subpath. bool srs_srt_streamid_info(const std::string& streamid, SrtMode& mode, std::string& vhost, std::string& url_subpath) { - mode = SrtModePull; + mode = SrtModeUnkown; size_t pos = streamid.find("#!::"); if (pos != 0) { @@ -89,6 +89,7 @@ bool srs_srt_streamid_info(const std::string& streamid, SrtMode& mode, std::stri } else if (mode_str == "request") { mode = SrtModePull; } else { + mode = SrtModeUnkown; srs_warn("unknown mode_str:%s", mode_str.c_str()); return false; } From 7db32f7b9caf910988402dde6ce6e8db6ceacb37 Mon Sep 17 00:00:00 2001 From: shiwei05 Date: Thu, 16 Mar 2023 16:06:19 +0800 Subject: [PATCH 14/21] add new config --- trunk/src/app/srs_app_config.cpp | 228 +++++++++++---------------- trunk/src/app/srs_app_config.hpp | 36 +++-- trunk/src/app/srs_app_srt_server.cpp | 96 ++++++----- trunk/src/app/srs_app_srt_server.hpp | 3 +- 4 files changed, 167 insertions(+), 196 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index f8dc078df31..8686b886358 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -2311,7 +2311,7 @@ srs_error_t SrsConfig::check_normal_config() 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 != "pullport" && n != "pushport" && n != "maxbw" + if (n != "enabled" && n != "type" && n != "port" && n != "maxbw" && n != "mss" && n != "latency" && n != "recvlatency" && n != "peerlatency" && n != "connect_timeout" && n != "sendbuf" && n != "recvbuf" && n != "payloadsize" @@ -7691,308 +7691,262 @@ string SrsConfig::get_https_api_ssl_cert() return conf->arg0(); } +bool SrsConfig::is_srt_server(SrsConfDirective* srt_conf) { + return srt_conf->name == "srt_server"; +} + +void SrsConfig::get_srt_servers(vector& servers) +{ + srs_assert(root); + + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + if (!is_srt_server(conf)) { + continue; + } + servers.push_back(conf); + } +} + bool SrsConfig::get_srt_enabled() { SRS_OVERWRITE_BY_ENV_BOOL("srs.srt_server.enabled"); // SRS_SRT_SERVER_ENABLED + bool ret = false; - 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; + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + + srs_trace("name:%s", conf->name.c_str()); + if (!is_srt_server(conf)) { + continue; + } + conf = conf->get("enabled"); + if (!conf || conf->arg0().empty()) { + ret = false; + } else { + ret = true; + break; + } } - - return SRS_CONF_PERFER_FALSE(conf->arg0()); + + return ret; } -unsigned short SrsConfig::get_srt_push_port() +std::string SrsConfig::get_srt_type(SrsConfDirective* srt_conf) { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pushport"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.type"); - static unsigned short DEFAULT = 10080; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("pushport"); - if (!conf || conf->arg0().empty()) { + static std::string DEFAULT("push"); + + SrsConfDirective* type_conf = srt_conf->get("type"); + if (!type_conf || type_conf->arg0().empty()) { return DEFAULT; } - return (unsigned short)atoi(conf->arg0().c_str()); + return type_conf->arg0(); } -unsigned short SrsConfig::get_srt_pull_port() +unsigned short SrsConfig::get_srt_port(SrsConfDirective* srt_conf) { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pullport"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.port"); // SRS_SRT_SERVER_LISTEN static unsigned short DEFAULT = 10080; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("pullport"); - if (!conf || conf->arg0().empty()) { + + SrsConfDirective* port_conf = srt_conf->get("port"); + if (!port_conf || port_conf->arg0().empty()) { return DEFAULT; } - return (unsigned short)atoi(conf->arg0().c_str()); + return (unsigned short)atoi(port_conf->arg0().c_str()); } -int64_t SrsConfig::get_srto_maxbw() +int64_t SrsConfig::get_srto_maxbw(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.maxbw"); // SRS_SRT_SERVER_MAXBW static int64_t DEFAULT = -1; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("maxbw"); + SrsConfDirective* conf = srt_conf->get("maxbw"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoll(conf->arg0().c_str()); } -int SrsConfig::get_srto_mss() +int SrsConfig::get_srto_mss(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.mms"); // SRS_SRT_SERVER_MMS static int DEFAULT = 1500; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("mms"); + + SrsConfDirective* conf = srt_conf->get("mms"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -bool SrsConfig::get_srto_tsbpdmode() +bool SrsConfig::get_srto_tsbpdmode(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_BOOL2("srs.srt_server.tsbpdmode"); // SRS_SRT_SERVER_TSBPDMODE static bool DEFAULT = true; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("tsbpdmode"); + SrsConfDirective* conf = srt_conf->get("tsbpdmode"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return SRS_CONF_PERFER_TRUE(conf->arg0()); } -int SrsConfig::get_srto_latency() +int SrsConfig::get_srto_latency(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.latency"); // SRS_SRT_SERVER_LATENCY static int DEFAULT = 120; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("latency"); + SrsConfDirective* conf = srt_conf->get("latency"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_recv_latency() +int SrsConfig::get_srto_recv_latency(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.recvlatency"); // SRS_SRT_SERVER_RECVLATENCY static int DEFAULT = 120; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("recvlatency"); + SrsConfDirective* conf = srt_conf->get("recvlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_peer_latency() +int SrsConfig::get_srto_peer_latency(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.peerlatency"); // SRS_SRT_SERVER_PEERLATENCY static int DEFAULT = 0; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("peerlatency"); + SrsConfDirective* conf = srt_conf->get("peerlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -bool SrsConfig::get_srt_sei_filter() +bool SrsConfig::get_srt_sei_filter(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_BOOL2("srs.srt_server.sei_filter"); // SRS_SRT_SERVER_SEI_FILTER static bool DEFAULT = true; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("sei_filter"); + SrsConfDirective* conf = srt_conf->get("sei_filter"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return SRS_CONF_PERFER_TRUE(conf->arg0()); } -bool SrsConfig::get_srto_tlpktdrop() +bool SrsConfig::get_srto_tlpktdrop(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_BOOL2("srs.srt_server.tlpktdrop"); // SRS_SRT_SERVER_TLPKTDROP static bool DEFAULT = true; - SrsConfDirective* srt_server_conf = root->get("srt_server"); - if (!srt_server_conf) { - return DEFAULT; - } - SrsConfDirective* conf = srt_server_conf->get("tlpktdrop"); + SrsConfDirective* conf = srt_conf->get("tlpktdrop"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return SRS_CONF_PERFER_TRUE(conf->arg0()); } -srs_utime_t SrsConfig::get_srto_conntimeout() +srs_utime_t SrsConfig::get_srto_conntimeout(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_MILLISECONDS("srs.srt_server.connect_timeout"); // SRS_SRT_SERVER_CONNECT_TIMEOUT static srs_utime_t DEFAULT = 3 * SRS_UTIME_SECONDS; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("connect_timeout"); + + SrsConfDirective* conf = srt_conf->get("connect_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); } -srs_utime_t SrsConfig::get_srto_peeridletimeout() +srs_utime_t SrsConfig::get_srto_peeridletimeout(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_MILLISECONDS("srs.srt_server.peer_idle_timeout"); // SRS_SRT_SERVER_PEER_IDLE_TIMEOUT static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("peer_idle_timeout"); + SrsConfDirective* conf = srt_conf->get("peer_idle_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_MILLISECONDS); } -int SrsConfig::get_srto_sendbuf() +int SrsConfig::get_srto_sendbuf(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.sendbuf"); // SRS_SRT_SERVER_SENDBUF static int DEFAULT = 8192 * (1500-28); - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("sendbuf"); + SrsConfDirective* conf = srt_conf->get("sendbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_recvbuf() +int SrsConfig::get_srto_recvbuf(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.recvbuf"); // SRS_SRT_SERVER_RECVBUF static int DEFAULT = 8192 * (1500-28); - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("recvbuf"); + SrsConfDirective* conf = srt_conf->get("recvbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -int SrsConfig::get_srto_payloadsize() +int SrsConfig::get_srto_payloadsize(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.payloadsize"); // SRS_SRT_SERVER_PAYLOADSIZE static int DEFAULT = 1316; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("payloadsize"); + SrsConfDirective* conf = srt_conf->get("payloadsize"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return atoi(conf->arg0().c_str()); } -string SrsConfig::get_srto_passphrase() +string SrsConfig::get_srto_passphrase(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.passphrase"); // SRS_SRT_SERVER_PASSPHRASE static string DEFAULT = ""; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("passphrase"); + SrsConfDirective* conf = srt_conf->get("passphrase"); if (!conf || conf->arg0().empty()) { return DEFAULT; } return conf->arg0(); } -int SrsConfig::get_srto_pbkeylen() +int SrsConfig::get_srto_pbkeylen(SrsConfDirective* srt_conf) { SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.pbkeylen"); // SRS_SRT_SERVER_PBKEYLEN static int DEFAULT = 0; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } - conf = conf->get("pbkeylen"); + SrsConfDirective* conf = srt_conf->get("pbkeylen"); if (!conf || conf->arg0().empty()) { return DEFAULT; } @@ -8003,17 +7957,21 @@ string SrsConfig::get_default_app_name() { SRS_OVERWRITE_BY_ENV_STRING("srs.srt_server.default_app"); // SRS_SRT_SERVER_DEFAULT_APP - static string DEFAULT = "live"; - SrsConfDirective* conf = root->get("srt_server"); - if (!conf) { - return DEFAULT; - } + string ret = "live"; - conf = conf->get("default_app"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; + for (int i = 0; i < (int)root->directives.size(); i++) { + SrsConfDirective* conf = root->at(i); + + if (!is_srt_server(conf)) { + continue; + } + conf = conf->get("default_app"); + if (!conf || conf->arg0().empty()) { + ret = conf->arg0(); + break; + } } - return conf->arg0(); + return ret; } SrsConfDirective* SrsConfig::get_srt(std::string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 8eab37bedb5..6258f8fbafa 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -653,41 +653,43 @@ class SrsConfig virtual SrsConfDirective* get_forward_backend(std::string vhost); public: + virtual bool is_srt_server(SrsConfDirective* srt_conf); + virtual void get_srt_servers(std::vector& servers); // Whether the srt sevice enabled virtual bool get_srt_enabled(); // Get the srt service listen port - virtual unsigned short get_srt_push_port(); - virtual unsigned short get_srt_pull_port(); + virtual unsigned short get_srt_port(SrsConfDirective* srt_conf); + virtual std::string get_srt_type(SrsConfDirective* srt_conf); // Get the srt SRTO_MAXBW, max bandwith, default is -1. - virtual int64_t get_srto_maxbw(); + virtual int64_t get_srto_maxbw(SrsConfDirective* srt_conf); // Get the srt SRTO_MSS, Maximum Segment Size, default is 1500. - virtual int get_srto_mss(); + virtual int get_srto_mss(SrsConfDirective* srt_conf); // Get the srt SRTO_TSBPDMODE, timestamp base packet delivery mode, default is false. - virtual bool get_srto_tsbpdmode(); + virtual bool get_srto_tsbpdmode(SrsConfDirective* srt_conf); // Get the srt SRTO_LATENCY, latency, default is 0 which means peer/recv latency is 120ms. - virtual int get_srto_latency(); + virtual int get_srto_latency(SrsConfDirective* srt_conf); // Get the srt SRTO_RCVLATENCY, recv latency, default is 120ms. - virtual int get_srto_recv_latency(); + virtual int get_srto_recv_latency(SrsConfDirective* srt_conf); // Get the srt SRTO_PEERLATENCY, peer latency, default is 0.. - virtual int get_srto_peer_latency(); + virtual int get_srto_peer_latency(SrsConfDirective* srt_conf); // Get the srt h264 sei filter, default is on, it will drop h264 sei packet. - virtual bool get_srt_sei_filter(); + virtual bool get_srt_sei_filter(SrsConfDirective* srt_conf); // Get the srt SRTO_TLPKTDROP, Too-late Packet Drop, default is true. - virtual bool get_srto_tlpktdrop(); + virtual bool get_srto_tlpktdrop(SrsConfDirective* srt_conf); // Get the srt SRTO_CONNTIMEO, connection timeout, default is 3000ms. - virtual srs_utime_t get_srto_conntimeout(); + virtual srs_utime_t get_srto_conntimeout(SrsConfDirective* srt_conf); // Get the srt SRTO_PEERIDLETIMEO, peer idle timeout, default is 10000ms. - virtual srs_utime_t get_srto_peeridletimeout(); + virtual srs_utime_t get_srto_peeridletimeout(SrsConfDirective* srt_conf); // Get the srt SRTO_SNDBUF, send buffer, default is 8192 × (1500-28). - virtual int get_srto_sendbuf(); + virtual int get_srto_sendbuf(SrsConfDirective* srt_conf); // Get the srt SRTO_RCVBUF, recv buffer, default is 8192 × (1500-28). - virtual int get_srto_recvbuf(); + virtual int get_srto_recvbuf(SrsConfDirective* srt_conf); // SRTO_PAYLOADSIZE - virtual int get_srto_payloadsize(); + virtual int get_srto_payloadsize(SrsConfDirective* srt_conf); // Get the srt SRTO_PASSPHRASE, default is empty. - virtual std::string get_srto_passphrase(); + virtual std::string get_srto_passphrase(SrsConfDirective* srt_conf); // Get the srt SRTO_PBKEYLEN, default is 0. - virtual int get_srto_pbkeylen(); + virtual int get_srto_pbkeylen(SrsConfDirective* srt_conf); // Get the default app. virtual std::string get_default_app_name(); private: diff --git a/trunk/src/app/srs_app_srt_server.cpp b/trunk/src/app/srs_app_srt_server.cpp index 1d03fdbf6a6..ffbaa36bc78 100644 --- a/trunk/src/app/srs_app_srt_server.cpp +++ b/trunk/src/app/srs_app_srt_server.cpp @@ -19,8 +19,9 @@ using namespace std; SrsSrtEventLoop* _srt_eventloop = NULL; #endif -SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode) +SrsSrtAcceptor::SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode, SrsConfDirective* srt_conf) { + srt_conf_ = srt_conf; port_ = 0; srt_server_ = srt_server; listener_ = NULL; @@ -66,61 +67,61 @@ srs_error_t SrsSrtAcceptor::set_srt_opt() { srs_error_t err = srs_success; - if ((err = srs_srt_set_maxbw(listener_->fd(), _srs_config->get_srto_maxbw())) != srs_success) { - return srs_error_wrap(err, "set opt maxbw=%" PRId64 " failed", _srs_config->get_srto_maxbw()); + if ((err = srs_srt_set_maxbw(listener_->fd(), _srs_config->get_srto_maxbw(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt maxbw=%" PRId64 " failed", _srs_config->get_srto_maxbw(srt_conf_)); } - if ((err = srs_srt_set_mss(listener_->fd(), _srs_config->get_srto_mss())) != srs_success) { - return srs_error_wrap(err, "set opt mss=%d failed", _srs_config->get_srto_mss()); + if ((err = srs_srt_set_mss(listener_->fd(), _srs_config->get_srto_mss(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt mss=%d failed", _srs_config->get_srto_mss(srt_conf_)); } - if ((err = srs_srt_set_tsbpdmode(listener_->fd(), _srs_config->get_srto_tsbpdmode())) != srs_success) { - return srs_error_wrap(err, "set opt tsbpdmode=%d failed", _srs_config->get_srto_tsbpdmode()); + if ((err = srs_srt_set_tsbpdmode(listener_->fd(), _srs_config->get_srto_tsbpdmode(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt tsbpdmode=%d failed", _srs_config->get_srto_tsbpdmode(srt_conf_)); } - if ((err = srs_srt_set_latency(listener_->fd(), _srs_config->get_srto_latency())) != srs_success) { - return srs_error_wrap(err, "set opt latency=%d failed", _srs_config->get_srto_latency()); + if ((err = srs_srt_set_latency(listener_->fd(), _srs_config->get_srto_latency(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt latency=%d failed", _srs_config->get_srto_latency(srt_conf_)); } - if ((err = srs_srt_set_rcv_latency(listener_->fd(), _srs_config->get_srto_recv_latency())) != srs_success) { - return srs_error_wrap(err, "set opt recvlatency=%d failed", _srs_config->get_srto_recv_latency()); + if ((err = srs_srt_set_rcv_latency(listener_->fd(), _srs_config->get_srto_recv_latency(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt recvlatency=%d failed", _srs_config->get_srto_recv_latency(srt_conf_)); } - if ((err = srs_srt_set_peer_latency(listener_->fd(), _srs_config->get_srto_peer_latency())) != srs_success) { - return srs_error_wrap(err, "set opt peerlatency=%d failed", _srs_config->get_srto_peer_latency()); + if ((err = srs_srt_set_peer_latency(listener_->fd(), _srs_config->get_srto_peer_latency(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt peerlatency=%d failed", _srs_config->get_srto_peer_latency(srt_conf_)); } - if ((err = srs_srt_set_tlpktdrop(listener_->fd(), _srs_config->get_srto_tlpktdrop())) != srs_success) { - return srs_error_wrap(err, "set opt tlpktdrop=%d failed", _srs_config->get_srto_tlpktdrop()); + if ((err = srs_srt_set_tlpktdrop(listener_->fd(), _srs_config->get_srto_tlpktdrop(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt tlpktdrop=%d failed", _srs_config->get_srto_tlpktdrop(srt_conf_)); } - if ((err = srs_srt_set_connect_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_conntimeout()))) != srs_success) { - return srs_error_wrap(err, "set opt connect_timeout=%d failed", _srs_config->get_srto_conntimeout()); + if ((err = srs_srt_set_connect_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_conntimeout(srt_conf_)))) != srs_success) { + return srs_error_wrap(err, "set opt connect_timeout=%d failed", _srs_config->get_srto_conntimeout(srt_conf_)); } - if ((err = srs_srt_set_peer_idle_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_peeridletimeout()))) != srs_success) { - return srs_error_wrap(err, "set opt peer_idle_timeout=%d failed", _srs_config->get_srto_peeridletimeout()); + if ((err = srs_srt_set_peer_idle_timeout(listener_->fd(), srsu2msi(_srs_config->get_srto_peeridletimeout(srt_conf_)))) != srs_success) { + return srs_error_wrap(err, "set opt peer_idle_timeout=%d failed", _srs_config->get_srto_peeridletimeout(srt_conf_)); } - if ((err = srs_srt_set_sndbuf(listener_->fd(), _srs_config->get_srto_sendbuf())) != srs_success) { - return srs_error_wrap(err, "set opt sendbuf=%d failed", _srs_config->get_srto_sendbuf()); + if ((err = srs_srt_set_sndbuf(listener_->fd(), _srs_config->get_srto_sendbuf(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt sendbuf=%d failed", _srs_config->get_srto_sendbuf(srt_conf_)); } - if ((err = srs_srt_set_rcvbuf(listener_->fd(), _srs_config->get_srto_recvbuf())) != srs_success) { - return srs_error_wrap(err, "set opt recvbuf=%d failed", _srs_config->get_srto_recvbuf()); + if ((err = srs_srt_set_rcvbuf(listener_->fd(), _srs_config->get_srto_recvbuf(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt recvbuf=%d failed", _srs_config->get_srto_recvbuf(srt_conf_)); } - if ((err = srs_srt_set_payload_size(listener_->fd(), _srs_config->get_srto_payloadsize())) != srs_success) { - return srs_error_wrap(err, "set opt payload_size=%d failed", _srs_config->get_srto_payloadsize()); + if ((err = srs_srt_set_payload_size(listener_->fd(), _srs_config->get_srto_payloadsize(srt_conf_))) != srs_success) { + return srs_error_wrap(err, "set opt payload_size=%d failed", _srs_config->get_srto_payloadsize(srt_conf_)); } - string passphrase = _srs_config->get_srto_passphrase(); + string passphrase = _srs_config->get_srto_passphrase(srt_conf_); if (! passphrase.empty()) { if ((err = srs_srt_set_passphrase(listener_->fd(), passphrase)) != srs_success) { return srs_error_wrap(err, "set opt passphrase=%s failed", passphrase.c_str()); } - int pbkeylen = _srs_config->get_srto_pbkeylen(); + int pbkeylen = _srs_config->get_srto_pbkeylen(srt_conf_); if ((err = srs_srt_set_pbkeylen(listener_->fd(), pbkeylen)) != srs_success) { return srs_error_wrap(err, "set opt pbkeylen=%d failed", pbkeylen); } @@ -189,6 +190,7 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() { srs_error_t err = srs_success; + srs_trace("srt enable:%s", _srs_config->get_srt_enabled() ? "true" : "false"); if (! _srs_config->get_srt_enabled()) { return err; } @@ -196,27 +198,35 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() // Close all listener for SRT if exists. close_listeners(); - // Start a push listener for SRT - SrsSrtAcceptor* pushAcceptor = new SrsSrtAcceptor(this, SrtModePush); - acceptors_.push_back(pushAcceptor); + std::vector srt_conf_vec; - int port; string ip; - srs_parse_endpoint(srs_int2str(_srs_config->get_srt_push_port()), ip, port); + _srs_config->get_srt_servers(srt_conf_vec); - if ((err = pushAcceptor->listen(ip, port)) != srs_success) { - return srs_error_wrap(err, "srt push listen %s:%d", ip.c_str(), port); - } - srs_trace("srt push listen:%s:%d", ip.c_str(), port); + for (auto srt_conf : srt_conf_vec) { + std::string srt_type = _srs_config->get_srt_type(srt_conf); + int port; + std::string ip; + enum SrtMode srt_mode = SrtModePush; - // Start a pull listener for SRT - SrsSrtAcceptor* pullAcceptor = new SrsSrtAcceptor(this, SrtModePull); - acceptors_.push_back(pullAcceptor); + srs_parse_endpoint(srs_int2str(_srs_config->get_srt_port(srt_conf)), ip, port); + if (srt_type == "pull") { + srt_mode = SrtModePull; + } else { + srt_mode = SrtModePush; + } - srs_parse_endpoint(srs_int2str(_srs_config->get_srt_pull_port()), ip, port); - if ((err = pullAcceptor->listen(ip, port)) != srs_success) { - return srs_error_wrap(err, "srt pull listen %s:%d", ip.c_str(), port); + SrsSrtAcceptor* acceptor = new SrsSrtAcceptor(this, srt_mode, srt_conf); + acceptors_.push_back(acceptor); + + if ((err = acceptor->listen(ip, port)) != srs_success) { + return srs_error_wrap(err, "srt %s listen %s:%d", + srt_mode == SrtModePull ? "pull" : "push", + ip.c_str(), port); + } + srs_trace("srt %s listen:%s:%d", + srt_mode == SrtModePull ? "pull" : "push", + ip.c_str(), port); } - srs_trace("srt pull listen:%s:%d", ip.c_str(), port); return err; } diff --git a/trunk/src/app/srs_app_srt_server.hpp b/trunk/src/app/srs_app_srt_server.hpp index 24628084eb4..c1ddbc041d0 100644 --- a/trunk/src/app/srs_app_srt_server.hpp +++ b/trunk/src/app/srs_app_srt_server.hpp @@ -21,6 +21,7 @@ class SrsHourGlass; class SrsSrtAcceptor : public ISrsSrtHandler { private: + SrsConfDirective* srt_conf_; std::string ip_; int port_; enum SrtMode mode_; @@ -28,7 +29,7 @@ class SrsSrtAcceptor : public ISrsSrtHandler private: SrsSrtListener* listener_; public: - SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode); + SrsSrtAcceptor(SrsSrtServer* srt_server, enum SrtMode mode, SrsConfDirective* srt_conf); virtual ~SrsSrtAcceptor(); public: virtual srs_error_t listen(std::string ip, int port); From 0269ca3426b5d527c4acd1d45cb27baec9266301 Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Thu, 16 Mar 2023 19:03:10 +0800 Subject: [PATCH 15/21] srt pull/push server config --- trunk/src/app/srs_app_config.cpp | 1 - trunk/src/app/srs_app_srt_conn.cpp | 3 ++- trunk/src/app/srs_app_srt_server.cpp | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 8686b886358..a1ddebddca2 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -7716,7 +7716,6 @@ bool SrsConfig::get_srt_enabled() for (int i = 0; i < (int)root->directives.size(); i++) { SrsConfDirective* conf = root->at(i); - srs_trace("name:%s", conf->name.c_str()); if (!is_srt_server(conf)) { continue; } diff --git a/trunk/src/app/srs_app_srt_conn.cpp b/trunk/src/app/srs_app_srt_conn.cpp index aa6b270a8cc..2c0a1dba9ce 100644 --- a/trunk/src/app/srs_app_srt_conn.cpp +++ b/trunk/src/app/srs_app_srt_conn.cpp @@ -284,7 +284,8 @@ srs_error_t SrsMpegtsSrtConn::do_cycle() } srs_trace("@srt, streamid=%s, mode:%s, stream_url=%s, vhost=%s, app=%s, stream=%s, param=%s", - streamid.c_str(), SrtMode2String(mode).c_str(), req_->get_stream_url().c_str(), req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); + streamid.c_str(), SrtMode2String(mode).c_str(), req_->get_stream_url().c_str(), + req_->vhost.c_str(), req_->app.c_str(), req_->stream.c_str(), req_->param.c_str()); if ((err = _srs_srt_sources->fetch_or_create(req_, &srt_source_)) != srs_success) { return srs_error_wrap(err, "fetch srt source"); diff --git a/trunk/src/app/srs_app_srt_server.cpp b/trunk/src/app/srs_app_srt_server.cpp index ffbaa36bc78..b65c8bbbd34 100644 --- a/trunk/src/app/srs_app_srt_server.cpp +++ b/trunk/src/app/srs_app_srt_server.cpp @@ -58,7 +58,8 @@ srs_error_t SrsSrtAcceptor::listen(std::string ip, int port) return srs_error_wrap(err, "message srt acceptor"); } - srs_trace("srt listen at udp://%s:%d, fd=%d", ip_.c_str(), port_, listener_->fd()); + srs_trace("srt listen at udp://%s:%d, fd=%d, mode:%s", + ip_.c_str(), port_, listener_->fd(), SrtMode2String(mode_).c_str()); return err; } @@ -223,9 +224,6 @@ srs_error_t SrsSrtServer::listen_srt_mpegts() srt_mode == SrtModePull ? "pull" : "push", ip.c_str(), port); } - srs_trace("srt %s listen:%s:%d", - srt_mode == SrtModePull ? "pull" : "push", - ip.c_str(), port); } return err; From 712e41c1f98dd800114b836f1806cf6f0ea327e6 Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Thu, 16 Mar 2023 19:14:32 +0800 Subject: [PATCH 16/21] update for multiple srt_server --- trunk/conf/srt.conf | 19 +++++++++++++++++-- trunk/conf/srt2rtc.conf | 14 ++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/trunk/conf/srt.conf b/trunk/conf/srt.conf index 3d6e5e374e3..3ea77dd10ac 100644 --- a/trunk/conf/srt.conf +++ b/trunk/conf/srt.conf @@ -18,8 +18,23 @@ http_server { srt_server { enabled on; - pushport 10080; - pullport 10081; + type push; + port 10080; + maxbw 1000000000; + connect_timeout 4000; + peerlatency 0; + recvlatency 0; + latency 0; + tsbpdmode off; + tlpktdrop off; + sendbuf 2000000; + recvbuf 2000000; +} + +srt_server { + enabled on; + type pull; + port 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; diff --git a/trunk/conf/srt2rtc.conf b/trunk/conf/srt2rtc.conf index d0f72ef8942..f263f9fe6b6 100644 --- a/trunk/conf/srt2rtc.conf +++ b/trunk/conf/srt2rtc.conf @@ -17,8 +17,18 @@ http_server { srt_server { enabled on; - pushport 10080; - pullport 10081; + type push; + port 10080; + maxbw 1000000000; + connect_timeout 4000; + peerlatency 0; + recvlatency 0; +} + +srt_server { + enabled on; + type pull; + port 10081; maxbw 1000000000; connect_timeout 4000; peerlatency 0; From 2f5042ce3c1303c2119207b6c5d30253d0587328 Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Mon, 20 Mar 2023 11:08:36 +0800 Subject: [PATCH 17/21] solve utest --- trunk/src/app/srs_app_config.cpp | 55 +++++++++++++++++++++++++++- trunk/src/utest/srs_utest_config.cpp | 28 +++++++------- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index a1ddebddca2..ba34b5e1eb0 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -7692,7 +7692,7 @@ string SrsConfig::get_https_api_ssl_cert() } bool SrsConfig::is_srt_server(SrsConfDirective* srt_conf) { - return srt_conf->name == "srt_server"; + return srt_conf && srt_conf->name == "srt_server"; } void SrsConfig::get_srt_servers(vector& servers) @@ -7737,6 +7737,9 @@ std::string SrsConfig::get_srt_type(SrsConfDirective* srt_conf) static std::string DEFAULT("push"); + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* type_conf = srt_conf->get("type"); if (!type_conf || type_conf->arg0().empty()) { return DEFAULT; @@ -7750,6 +7753,10 @@ unsigned short SrsConfig::get_srt_port(SrsConfDirective* srt_conf) static unsigned short DEFAULT = 10080; + if (!srt_conf) { + return DEFAULT; + } + SrsConfDirective* port_conf = srt_conf->get("port"); if (!port_conf || port_conf->arg0().empty()) { return DEFAULT; @@ -7763,6 +7770,9 @@ int64_t SrsConfig::get_srto_maxbw(SrsConfDirective* srt_conf) static int64_t DEFAULT = -1; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("maxbw"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7776,6 +7786,10 @@ int SrsConfig::get_srto_mss(SrsConfDirective* srt_conf) static int DEFAULT = 1500; + if (!srt_conf) { + return DEFAULT; + } + SrsConfDirective* conf = srt_conf->get("mms"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7789,6 +7803,9 @@ bool SrsConfig::get_srto_tsbpdmode(SrsConfDirective* srt_conf) static bool DEFAULT = true; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("tsbpdmode"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7802,6 +7819,9 @@ int SrsConfig::get_srto_latency(SrsConfDirective* srt_conf) static int DEFAULT = 120; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("latency"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7815,6 +7835,9 @@ int SrsConfig::get_srto_recv_latency(SrsConfDirective* srt_conf) static int DEFAULT = 120; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("recvlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7828,6 +7851,9 @@ int SrsConfig::get_srto_peer_latency(SrsConfDirective* srt_conf) static int DEFAULT = 0; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("peerlatency"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7841,6 +7867,9 @@ bool SrsConfig::get_srt_sei_filter(SrsConfDirective* srt_conf) static bool DEFAULT = true; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("sei_filter"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7854,6 +7883,9 @@ bool SrsConfig::get_srto_tlpktdrop(SrsConfDirective* srt_conf) static bool DEFAULT = true; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("tlpktdrop"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7867,6 +7899,9 @@ srs_utime_t SrsConfig::get_srto_conntimeout(SrsConfDirective* srt_conf) static srs_utime_t DEFAULT = 3 * SRS_UTIME_SECONDS; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("connect_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7880,6 +7915,9 @@ srs_utime_t SrsConfig::get_srto_peeridletimeout(SrsConfDirective* srt_conf) static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("peer_idle_timeout"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7893,6 +7931,9 @@ int SrsConfig::get_srto_sendbuf(SrsConfDirective* srt_conf) static int DEFAULT = 8192 * (1500-28); + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("sendbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7906,6 +7947,9 @@ int SrsConfig::get_srto_recvbuf(SrsConfDirective* srt_conf) static int DEFAULT = 8192 * (1500-28); + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("recvbuf"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7919,6 +7963,9 @@ int SrsConfig::get_srto_payloadsize(SrsConfDirective* srt_conf) static int DEFAULT = 1316; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("payloadsize"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7932,6 +7979,9 @@ string SrsConfig::get_srto_passphrase(SrsConfDirective* srt_conf) static string DEFAULT = ""; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("passphrase"); if (!conf || conf->arg0().empty()) { return DEFAULT; @@ -7945,6 +7995,9 @@ int SrsConfig::get_srto_pbkeylen(SrsConfDirective* srt_conf) static int DEFAULT = 0; + if (!srt_conf) { + return DEFAULT; + } SrsConfDirective* conf = srt_conf->get("pbkeylen"); if (!conf || conf->arg0().empty()) { return DEFAULT; diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 925c010d902..52c46e7555a 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -4185,49 +4185,49 @@ VOID TEST(ConfigEnvTest, CheckEnvValuesSrtServer) EXPECT_TRUE(conf.get_srt_enabled()); SrsSetEnvConfig(srt_listen_port, "SRS_SRT_SERVER_LISTEN", "10000"); - EXPECT_EQ(10000, conf.get_srt_listen_port()); + EXPECT_EQ(10000, conf.get_srt_port(nullptr)); SrsSetEnvConfig(srto_maxbw, "SRS_SRT_SERVER_MAXBW", "1000000000"); - EXPECT_EQ(1000000000, conf.get_srto_maxbw()); + EXPECT_EQ(1000000000, conf.get_srto_maxbw(nullptr)); SrsSetEnvConfig(srto_mss, "SRS_SRT_SERVER_MMS", "1000"); - EXPECT_EQ(1000, conf.get_srto_mss()); + EXPECT_EQ(1000, conf.get_srto_mss(nullptr)); SrsSetEnvConfig(srto_conntimeout, "SRS_SRT_SERVER_CONNECT_TIMEOUT", "2000"); - EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_conntimeout()); + EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_conntimeout(nullptr)); SrsSetEnvConfig(srto_peeridletimeout, "SRS_SRT_SERVER_PEER_IDLE_TIMEOUT", "2000"); - EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_peeridletimeout()); + EXPECT_EQ(2000 * SRS_UTIME_MILLISECONDS, conf.get_srto_peeridletimeout(nullptr)); SrsSetEnvConfig(default_app_name, "SRS_SRT_SERVER_DEFAULT_APP", "xxx"); EXPECT_STREQ("xxx", conf.get_default_app_name().c_str()); SrsSetEnvConfig(srto_peer_latency, "SRS_SRT_SERVER_PEERLATENCY", "1"); - EXPECT_EQ(1, conf.get_srto_peer_latency()); + EXPECT_EQ(1, conf.get_srto_peer_latency(nullptr)); SrsSetEnvConfig(srto_recv_latency, "SRS_SRT_SERVER_RECVLATENCY", "100"); - EXPECT_EQ(100, conf.get_srto_recv_latency()); + EXPECT_EQ(100, conf.get_srto_recv_latency(nullptr)); SrsSetEnvConfig(srto_latency, "SRS_SRT_SERVER_LATENCY", "100"); - EXPECT_EQ(100, conf.get_srto_latency()); + EXPECT_EQ(100, conf.get_srto_latency(nullptr)); SrsSetEnvConfig(srto_tsbpdmode, "SRS_SRT_SERVER_TSBPDMODE", "off"); - EXPECT_FALSE(conf.get_srto_tsbpdmode()); + EXPECT_FALSE(conf.get_srto_tsbpdmode(nullptr)); SrsSetEnvConfig(srto_tlpktdrop, "SRS_SRT_SERVER_TLPKTDROP", "off"); - EXPECT_FALSE(conf.get_srto_tlpktdrop()); + EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); SrsSetEnvConfig(srto_sendbuf, "SRS_SRT_SERVER_SENDBUF", "2100000"); - EXPECT_EQ(2100000, conf.get_srto_sendbuf()); + EXPECT_EQ(2100000, conf.get_srto_sendbuf(nullptr)); SrsSetEnvConfig(srto_recvbuf, "SRS_SRT_SERVER_RECVBUF", "2100000"); - EXPECT_EQ(2100000, conf.get_srto_recvbuf()); + EXPECT_EQ(2100000, conf.get_srto_recvbuf(nullptr)); SrsSetEnvConfig(srto_passphrase, "SRS_SRT_SERVER_PASSPHRASE", "xxx2"); - EXPECT_STREQ("xxx2", conf.get_srto_passphrase().c_str()); + EXPECT_STREQ("xxx2", conf.get_srto_passphrase(nullptr).c_str()); SrsSetEnvConfig(srto_pbkeylen, "SRS_SRT_SERVER_PBKEYLEN", "16"); - EXPECT_EQ(16, conf.get_srto_pbkeylen()); + EXPECT_EQ(16, conf.get_srto_pbkeylen(nullptr)); } } From 80f1154b26407c357e6ad89dc1db1fd506bf295a Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Mon, 20 Mar 2023 11:15:18 +0800 Subject: [PATCH 18/21] solve utest bug --- trunk/src/utest/srs_utest_config.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 52c46e7555a..ee750c924ed 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -3919,19 +3919,19 @@ VOID TEST(ConfigMainTest, SrtServerTlpktDrop) if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); - EXPECT_TRUE(conf.get_srto_tlpktdrop()); + EXPECT_TRUE(conf.get_srto_tlpktdrop(nullptr)); } if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srt_server{tlpktdrop off;}")); - EXPECT_FALSE(conf.get_srto_tlpktdrop()); + EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); } if (true) { MockSrsConfig conf; HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srt_server{tlpkdrop off;}")); - EXPECT_FALSE(conf.get_srto_tlpktdrop()); + EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); } } From e9ec844b4314fde2f07bd550320df6bf91fc83bf Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Tue, 21 Mar 2023 14:32:25 +0800 Subject: [PATCH 19/21] for srt utest --- trunk/src/utest/srs_utest_srt.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/trunk/src/utest/srs_utest_srt.cpp b/trunk/src/utest/srs_utest_srt.cpp index dc9b154b2c9..9091c96f4c8 100644 --- a/trunk/src/utest/srs_utest_srt.cpp +++ b/trunk/src/utest/srs_utest_srt.cpp @@ -203,12 +203,16 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept) // Make utest fast timeout. srt_server.srt_socket_->set_recv_timeout(50 * SRS_UTIME_MILLISECONDS); err = srt_server.accept(&srt_fd); + + std::cout << "srt accept err code:" << srs_error_code(err) << ", timeout:" << ERROR_SRT_TIMEOUT << "\r\n"; EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT); EXPECT_EQ(srt_fd, srs_srt_socket_invalid()); srs_freep(err); // Client connect to server - HELPER_EXPECT_SUCCESS(srt_client_socket->connect(server_ip, server_port)); + err = srt_client_socket->connect(server_ip, server_port); + std::cout << "srt client connect return:" << err << "\r\n"; + HELPER_EXPECT_SUCCESS(err); // Server will accept one client. HELPER_EXPECT_SUCCESS(srt_server.accept(&srt_fd)); @@ -352,7 +356,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) { if (true) { SrtMode mode; string vhost; string subpath; - EXPECT_TRUE(srs_srt_streamid_info("#!::r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath)); + EXPECT_TRUE(srs_srt_streamid_info("#!::r=live/livestream,key1=value1,key2=value2,m=request", mode, vhost, subpath)); EXPECT_EQ(SrtModePull, mode); EXPECT_STREQ("", vhost.c_str()); EXPECT_STREQ("live/livestream?key1=value1&key2=value2", subpath.c_str()); @@ -360,7 +364,7 @@ VOID TEST(ProtocolSrtTest, SrtGetStreamInfoNormal) if (true) { SrtMode mode; string vhost; string subpath; - EXPECT_TRUE(srs_srt_streamid_info("#!::h=host.com,r=live/livestream,key1=value1,key2=value2", mode, vhost, subpath)); + EXPECT_TRUE(srs_srt_streamid_info("#!::h=host.com,r=live/livestream,key1=value1,key2=value2,m=request", mode, vhost, subpath)); EXPECT_EQ(SrtModePull, mode); EXPECT_STREQ("host.com", vhost.c_str()); EXPECT_STREQ("live/livestream?vhost=host.com&key1=value1&key2=value2", subpath.c_str()); @@ -432,7 +436,7 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest) if (true) { SrtMode mode; SrsRequest req; - EXPECT_TRUE(srs_srt_streamid_to_request("#!::r=live/livestream?key1=val1,key2=val2", mode, &req)); + EXPECT_TRUE(srs_srt_streamid_to_request("#!::r=live/livestream?key1=val1,key2=val2,m=request", mode, &req)); EXPECT_EQ(mode, SrtModePull); EXPECT_STREQ(req.vhost.c_str(), srs_get_public_internet_address().c_str()); EXPECT_STREQ(req.app.c_str(), "live"); @@ -443,7 +447,7 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest) if (true) { SrtMode mode; SrsRequest req; - EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn,r=live/livestream?key1=val1,key2=val2", mode, &req)); + EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn,r=live/livestream?key1=val1,key2=val2,m=request", mode, &req)); EXPECT_EQ(mode, SrtModePull); EXPECT_STREQ(req.vhost.c_str(), "srs.srt.com.cn"); EXPECT_STREQ(req.app.c_str(), "live"); @@ -454,7 +458,7 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest) if (true) { SrtMode mode; SrsRequest req; - EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=live/livestream?key1=val1,key2=val2", mode, &req)); + EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=live/livestream?key1=val1,key2=val2,m=request", mode, &req)); EXPECT_EQ(mode, SrtModePull); EXPECT_STREQ(req.vhost.c_str(), srs_get_public_internet_address().c_str()); EXPECT_STREQ(req.app.c_str(), "live"); @@ -465,7 +469,7 @@ VOID TEST(ProtocolSrtTest, SrtStreamIdToRequest) if (true) { SrtMode mode; SrsRequest req; - EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn/live/livestream?key1=val1,key2=val2", mode, &req)); + EXPECT_TRUE(srs_srt_streamid_to_request("#!::h=srs.srt.com.cn/live/livestream?key1=val1,key2=val2,m=request", mode, &req)); EXPECT_EQ(mode, SrtModePull); EXPECT_STREQ(req.vhost.c_str(), "srs.srt.com.cn"); EXPECT_STREQ(req.app.c_str(), "live"); From a0ae2034e6958b091067b2bbaad4b47df0392c1e Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Tue, 21 Mar 2023 16:29:45 +0800 Subject: [PATCH 20/21] solve srt utest --- trunk/src/app/srs_app_config.cpp | 3 +-- trunk/src/utest/srs_utest_config.cpp | 11 +++++++++-- trunk/src/utest/srs_utest_srt.cpp | 2 -- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index ba34b5e1eb0..f0b8cceeaee 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -5,7 +5,6 @@ // #include - #include #include #include @@ -7749,7 +7748,7 @@ std::string SrsConfig::get_srt_type(SrsConfDirective* srt_conf) unsigned short SrsConfig::get_srt_port(SrsConfDirective* srt_conf) { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.port"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.listen"); // SRS_SRT_SERVER_LISTEN static unsigned short DEFAULT = 10080; diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index ee750c924ed..c41f67e0c85 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -3918,20 +3918,27 @@ VOID TEST(ConfigMainTest, SrtServerTlpktDrop) if (true) { MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF)); EXPECT_TRUE(conf.get_srto_tlpktdrop(nullptr)); } if (true) { MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srt_server{tlpktdrop off;}")); - EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); + std::vector srt_server_confs; + conf.get_srt_servers(srt_server_confs); + EXPECT_FALSE(conf.get_srto_tlpktdrop(srt_server_confs[0])); } if (true) { MockSrsConfig conf; + HELPER_ASSERT_SUCCESS(conf.parse(_MIN_OK_CONF "srt_server{tlpkdrop off;}")); - EXPECT_FALSE(conf.get_srto_tlpktdrop(nullptr)); + std::vector srt_server_confs; + conf.get_srt_servers(srt_server_confs); + EXPECT_FALSE(conf.get_srto_tlpktdrop(srt_server_confs[0])); } } diff --git a/trunk/src/utest/srs_utest_srt.cpp b/trunk/src/utest/srs_utest_srt.cpp index 9091c96f4c8..779f479dd7e 100644 --- a/trunk/src/utest/srs_utest_srt.cpp +++ b/trunk/src/utest/srs_utest_srt.cpp @@ -204,14 +204,12 @@ VOID TEST(ServiceStSRTTest, ListenConnectAccept) srt_server.srt_socket_->set_recv_timeout(50 * SRS_UTIME_MILLISECONDS); err = srt_server.accept(&srt_fd); - std::cout << "srt accept err code:" << srs_error_code(err) << ", timeout:" << ERROR_SRT_TIMEOUT << "\r\n"; EXPECT_EQ(srs_error_code(err), ERROR_SRT_TIMEOUT); EXPECT_EQ(srt_fd, srs_srt_socket_invalid()); srs_freep(err); // Client connect to server err = srt_client_socket->connect(server_ip, server_port); - std::cout << "srt client connect return:" << err << "\r\n"; HELPER_EXPECT_SUCCESS(err); // Server will accept one client. From 259ec24ff9e0d0708de1d0451b66cb97b8d3c66e Mon Sep 17 00:00:00 2001 From: xiaoq_bj Date: Tue, 21 Mar 2023 17:04:48 +0800 Subject: [PATCH 21/21] solve srt listen bug --- trunk/src/app/srs_app_config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 37b58182763..f0b8cceeaee 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -7748,7 +7748,7 @@ std::string SrsConfig::get_srt_type(SrsConfDirective* srt_conf) unsigned short SrsConfig::get_srt_port(SrsConfDirective* srt_conf) { - SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.port"); // SRS_SRT_SERVER_LISTEN + SRS_OVERWRITE_BY_ENV_INT("srs.srt_server.listen"); // SRS_SRT_SERVER_LISTEN static unsigned short DEFAULT = 10080;