Merge branch '4.0release' into develop

pull/2128/head
winlin 4 years ago
commit 03389f5e8c

@ -128,9 +128,12 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
// 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) {
string stream;
if ((err = sdk->play(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) {
return srs_error_wrap(err, "edge pull %s stream failed", url.c_str());
}
srs_trace("edge-pull publish url %s, stream=%s%s as %s", url.c_str(), req->stream.c_str(), req->param.c_str(), stream.c_str());
return err;
}
@ -511,7 +514,8 @@ srs_error_t SrsEdgeForwarder::start()
// 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) {
string stream;
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) {
return srs_error_wrap(err, "sdk publish");
}
@ -521,7 +525,8 @@ srs_error_t SrsEdgeForwarder::start()
if ((err = trd->start()) != srs_success) {
return srs_error_wrap(err, "coroutine");
}
srs_trace("edge-fwr publish url %s, stream=%s%s", url.c_str(), req->stream.c_str(), req->param.c_str());
srs_trace("edge-fwr publish url %s, stream=%s%s as %s", url.c_str(), req->stream.c_str(), req->param.c_str(), stream.c_str());
return err;
}

@ -225,7 +225,8 @@ srs_error_t SrsForwarder::do_cycle()
// 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) {
string stream;
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost), false, &stream)) != srs_success) {
return srs_error_wrap(err, "sdk publish");
}
@ -236,6 +237,8 @@ srs_error_t SrsForwarder::do_cycle()
if ((err = forward()) != srs_success) {
return srs_error_wrap(err, "forward");
}
srs_trace("forward publish url %s, stream=%s%s as %s", url.c_str(), req->stream.c_str(), req->param.c_str(), stream.c_str());
return err;
}

@ -205,20 +205,35 @@ string srs_generate_stream_with_query(string host, string vhost, string stream,
string url = stream;
string query = param;
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;
}
// 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.find("vhost=") == string::npos) {
query += "&vhost=" + guessVhost;
}
// If not pass in query, remove it.
if (!with_vhost) {
size_t pos = query.find("&vhost=");
if (pos == string::npos) {
pos = query.find("vhost=");
}
size_t end = query.find("&", pos + 1);
if (end == string::npos) {
end = query.length();
}
// Well, if vhost exists, always append in query string.
if (!guessVhost.empty()) {
query += "&vhost=" + guessVhost;
if (pos != string::npos && end != string::npos && end > pos) {
query = query.substr(0, pos) + query.substr(end);
}
}

@ -148,12 +148,17 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug)
return err;
}
srs_error_t SrsBasicRtmpClient::publish(int chunk_size, bool with_vhost)
srs_error_t SrsBasicRtmpClient::publish(int chunk_size, bool with_vhost, std::string* pstream)
{
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, with_vhost);
// Return the generated stream.
if (pstream) {
*pstream = stream;
}
// publish.
if ((err = client->publish(stream, stream_id, chunk_size)) != srs_success) {
@ -163,12 +168,17 @@ srs_error_t SrsBasicRtmpClient::publish(int chunk_size, bool with_vhost)
return err;
}
srs_error_t SrsBasicRtmpClient::play(int chunk_size, bool with_vhost)
srs_error_t SrsBasicRtmpClient::play(int chunk_size, bool with_vhost, std::string* pstream)
{
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, with_vhost);
// Return the generated stream.
if (pstream) {
*pstream = stream;
}
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);

@ -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, bool with_vhost = true);
virtual srs_error_t play(int chunk_size, bool with_vhost = true);
virtual srs_error_t publish(int chunk_size, bool with_vhost = true, std::string* pstream = NULL);
virtual srs_error_t play(int chunk_size, bool with_vhost = true, std::string* pstream = NULL);
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();

Loading…
Cancel
Save