1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-12 11:21:52 +00:00

For RTMP edge/forward, pass vhost in tcUrl, not in stream. 3.0.156

This commit is contained in:
winlin 2020-12-26 22:11:23 +08:00
parent 4d18835f3c
commit 6e43ef6866
8 changed files with 38 additions and 29 deletions

View file

@ -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
* <strong>v3.0, 2020-10-31, [3.0 release2(3.0.153)][r3.0r2] released. 122663 lines.</strong>

View file

@ -125,7 +125,9 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
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());
}
@ -505,7 +507,9 @@ srs_error_t SrsEdgeForwarder::start()
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;
}

View file

@ -223,7 +223,9 @@ srs_error_t SrsForwarder::do_cycle()
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");
}

View file

@ -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

View file

@ -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.

View file

@ -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.

View file

@ -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);

View file

@ -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();