From 6e43ef6866499468f590b8781aae93a45ffa4dfc Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 26 Dec 2020 22:11:23 +0800 Subject: [PATCH] For RTMP edge/forward, pass vhost in tcUrl, not in stream. 3.0.156 --- README.md | 1 + trunk/src/app/srs_app_edge.cpp | 14 ++++++---- trunk/src/app/srs_app_forward.cpp | 6 +++-- trunk/src/core/srs_core_version3.hpp | 2 +- trunk/src/protocol/srs_protocol_utility.cpp | 30 +++++++++++---------- trunk/src/protocol/srs_protocol_utility.hpp | 2 +- trunk/src/service/srs_service_rtmp_conn.cpp | 8 +++--- trunk/src/service/srs_service_rtmp_conn.hpp | 4 +-- 8 files changed, 38 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ad8b81df6..52add2a15 100755 --- a/README.md +++ b/README.md @@ -145,6 +145,7 @@ For previous versions, please read: ## V3 changes +* v3.0, 2020-12-26, For RTMP edge/forward, pass vhost in tcUrl, not in stream. 3.0.156 * v3.0, 2020-12-17, Fix [#1694][bug #1694], Support DVR 2GB+ MP4 file. 3.0.155 * v3.0, 2020-12-17, Fix [#1548][bug #1548], Add edts in MP4 for Windows10. 3.0.154 * v3.0, 2020-10-31, [3.0 release2(3.0.153)][r3.0r2] released. 122663 lines. diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 63237fba5..f883524a3 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -124,8 +124,10 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) if ((err = sdk->connect()) != srs_success) { return srs_error_wrap(err, "edge pull %s failed, cto=%dms, sto=%dms.", url.c_str(), srsu2msi(cto), srsu2msi(sto)); } - - if ((err = sdk->play(_srs_config->get_chunk_size(req->vhost))) != srs_success) { + + // For RTMP client, we pass the vhost in tcUrl when connecting, + // so we publish without vhost in stream. + if ((err = sdk->play(_srs_config->get_chunk_size(req->vhost), false)) != srs_success) { return srs_error_wrap(err, "edge pull %s stream failed", url.c_str()); } @@ -504,8 +506,10 @@ srs_error_t SrsEdgeForwarder::start() if ((err = sdk->connect()) != srs_success) { return srs_error_wrap(err, "sdk connect %s failed, cto=%dms, sto=%dms.", url.c_str(), srsu2msi(cto), srsu2msi(sto)); } - - if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost))) != srs_success) { + + // For RTMP client, we pass the vhost in tcUrl when connecting, + // so we publish without vhost in stream. + if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false)) != srs_success) { return srs_error_wrap(err, "sdk publish"); } @@ -515,7 +519,7 @@ srs_error_t SrsEdgeForwarder::start() if ((err = trd->start()) != srs_success) { return srs_error_wrap(err, "coroutine"); } - srs_trace("edge-fwr publish url %s", url.c_str()); + srs_trace("edge-fwr publish url %s, stream=%s%s", url.c_str(), req->stream.c_str(), req->param.c_str()); return err; } diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 882d33a8c..2890324a4 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -222,8 +222,10 @@ srs_error_t SrsForwarder::do_cycle() if ((err = sdk->connect()) != srs_success) { return srs_error_wrap(err, "sdk connect url=%s, cto=%dms, sto=%dms.", url.c_str(), srsu2msi(cto), srsu2msi(sto)); } - - if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost))) != srs_success) { + + // For RTMP client, we pass the vhost in tcUrl when connecting, + // so we publish without vhost in stream. + if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false)) != srs_success) { return srs_error_wrap(err, "sdk publish"); } diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp index a64066df2..281b3955d 100644 --- a/trunk/src/core/srs_core_version3.hpp +++ b/trunk/src/core/srs_core_version3.hpp @@ -24,6 +24,6 @@ #ifndef SRS_CORE_VERSION3_HPP #define SRS_CORE_VERSION3_HPP -#define SRS_VERSION3_REVISION 155 +#define SRS_VERSION3_REVISION 156 #endif diff --git a/trunk/src/protocol/srs_protocol_utility.cpp b/trunk/src/protocol/srs_protocol_utility.cpp index 57e65ecf0..03fcab3bf 100644 --- a/trunk/src/protocol/srs_protocol_utility.cpp +++ b/trunk/src/protocol/srs_protocol_utility.cpp @@ -181,24 +181,26 @@ string srs_generate_tc_url(string host, string vhost, string app, int port) return tcUrl; } -string srs_generate_stream_with_query(string host, string vhost, string stream, string param) +string srs_generate_stream_with_query(string host, string vhost, string stream, string param, bool with_vhost) { string url = stream; string query = param; - - // If no vhost in param, try to append one. - string guessVhost; - if (query.find("vhost=") == string::npos) { - if (vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) { - guessVhost = vhost; - } else if (!srs_is_ipv4(host)) { - guessVhost = host; + + if (with_vhost) { + // If no vhost in param, try to append one. + string guessVhost; + if (query.find("vhost=") == string::npos) { + if (vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) { + guessVhost = vhost; + } else if (!srs_is_ipv4(host)) { + guessVhost = host; + } + } + + // Well, if vhost exists, always append in query string. + if (!guessVhost.empty()) { + query += "&vhost=" + guessVhost; } - } - - // Well, if vhost exists, always append in query string. - if (!guessVhost.empty()) { - query += "&vhost=" + guessVhost; } // Remove the start & when param is empty. diff --git a/trunk/src/protocol/srs_protocol_utility.hpp b/trunk/src/protocol/srs_protocol_utility.hpp index 3f4cc03d2..777ec1900 100644 --- a/trunk/src/protocol/srs_protocol_utility.hpp +++ b/trunk/src/protocol/srs_protocol_utility.hpp @@ -80,7 +80,7 @@ extern std::string srs_generate_tc_url(std::string host, std::string vhost, std: * Generate the stream with param. * @remark Append vhost in query string if not default vhost. */ -extern std::string srs_generate_stream_with_query(std::string host, std::string vhost, std::string stream, std::string param); +extern std::string srs_generate_stream_with_query(std::string host, std::string vhost, std::string stream, std::string param, bool with_vhost = true); /** * create shared ptr message from bytes. diff --git a/trunk/src/service/srs_service_rtmp_conn.cpp b/trunk/src/service/srs_service_rtmp_conn.cpp index 01343eb51..28908cf62 100644 --- a/trunk/src/service/srs_service_rtmp_conn.cpp +++ b/trunk/src/service/srs_service_rtmp_conn.cpp @@ -147,12 +147,12 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug) return err; } -srs_error_t SrsBasicRtmpClient::publish(int chunk_size) +srs_error_t SrsBasicRtmpClient::publish(int chunk_size, bool with_vhost) { srs_error_t err = srs_success; // Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733 - string stream = srs_generate_stream_with_query(req->host, req->vhost, req->stream, req->param); + string stream = srs_generate_stream_with_query(req->host, req->vhost, req->stream, req->param, with_vhost); // publish. if ((err = client->publish(stream, stream_id, chunk_size)) != srs_success) { @@ -162,12 +162,12 @@ srs_error_t SrsBasicRtmpClient::publish(int chunk_size) return err; } -srs_error_t SrsBasicRtmpClient::play(int chunk_size) +srs_error_t SrsBasicRtmpClient::play(int chunk_size, bool with_vhost) { srs_error_t err = srs_success; // Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733 - string stream = srs_generate_stream_with_query(req->host, req->vhost, req->stream, req->param); + string stream = srs_generate_stream_with_query(req->host, req->vhost, req->stream, req->param, with_vhost); if ((err = client->play(stream, stream_id, chunk_size)) != srs_success) { return srs_error_wrap(err, "connect with server failed, stream=%s, stream_id=%d", stream.c_str(), stream_id); diff --git a/trunk/src/service/srs_service_rtmp_conn.hpp b/trunk/src/service/srs_service_rtmp_conn.hpp index 2ade55f9f..afa06e847 100644 --- a/trunk/src/service/srs_service_rtmp_conn.hpp +++ b/trunk/src/service/srs_service_rtmp_conn.hpp @@ -74,8 +74,8 @@ protected: virtual srs_error_t connect_app(); virtual srs_error_t do_connect_app(std::string local_ip, bool debug); public: - virtual srs_error_t publish(int chunk_size); - virtual srs_error_t play(int chunk_size); + virtual srs_error_t publish(int chunk_size, bool with_vhost = true); + virtual srs_error_t play(int chunk_size, bool with_vhost = true); virtual void kbps_sample(const char* label, int64_t age); virtual void kbps_sample(const char* label, int64_t age, int msgs); virtual int sid();