mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 20:01:56 +00:00
Merge branch '4.0release' into develop
This commit is contained in:
commit
03389f5e8c
5 changed files with 53 additions and 20 deletions
|
@ -128,10 +128,13 @@ 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");
|
||||
}
|
||||
|
||||
|
@ -237,6 +238,8 @@ srs_error_t SrsForwarder::do_cycle()
|
|||
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,7 +205,6 @@ 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) {
|
||||
|
@ -217,9 +216,25 @@ string srs_generate_stream_with_query(string host, string vhost, string stream,
|
|||
}
|
||||
|
||||
// Well, if vhost exists, always append in query string.
|
||||
if (!guessVhost.empty()) {
|
||||
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();
|
||||
}
|
||||
|
||||
if (pos != string::npos && end != string::npos && end > pos) {
|
||||
query = query.substr(0, pos) + query.substr(end);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the start & when param is empty.
|
||||
|
|
|
@ -148,13 +148,18 @@ 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) {
|
||||
return srs_error_wrap(err, "publish failed, stream=%s, stream_id=%d", stream.c_str(), stream_id);
|
||||
|
@ -163,13 +168,18 @@ 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…
Reference in a new issue