mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
Merge branch '3.0release' into 4.0release
This commit is contained in:
commit
1df2ea5ca8
5 changed files with 53 additions and 20 deletions
|
@ -128,9 +128,12 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
|
||||||
|
|
||||||
// For RTMP client, we pass the vhost in tcUrl when connecting,
|
// For RTMP client, we pass the vhost in tcUrl when connecting,
|
||||||
// so we publish without vhost in stream.
|
// 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());
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -511,7 +514,8 @@ srs_error_t SrsEdgeForwarder::start()
|
||||||
|
|
||||||
// For RTMP client, we pass the vhost in tcUrl when connecting,
|
// For RTMP client, we pass the vhost in tcUrl when connecting,
|
||||||
// so we publish without vhost in stream.
|
// 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");
|
return srs_error_wrap(err, "sdk publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,7 +525,8 @@ srs_error_t SrsEdgeForwarder::start()
|
||||||
if ((err = trd->start()) != srs_success) {
|
if ((err = trd->start()) != srs_success) {
|
||||||
return srs_error_wrap(err, "coroutine");
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,8 @@ srs_error_t SrsForwarder::do_cycle()
|
||||||
|
|
||||||
// For RTMP client, we pass the vhost in tcUrl when connecting,
|
// For RTMP client, we pass the vhost in tcUrl when connecting,
|
||||||
// so we publish without vhost in stream.
|
// 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");
|
return srs_error_wrap(err, "sdk publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +237,8 @@ srs_error_t SrsForwarder::do_cycle()
|
||||||
if ((err = forward()) != srs_success) {
|
if ((err = forward()) != srs_success) {
|
||||||
return srs_error_wrap(err, "forward");
|
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;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,20 +205,35 @@ string srs_generate_stream_with_query(string host, string vhost, string stream,
|
||||||
string url = stream;
|
string url = stream;
|
||||||
string query = param;
|
string query = param;
|
||||||
|
|
||||||
if (with_vhost) {
|
// If no vhost in param, try to append one.
|
||||||
// If no vhost in param, try to append one.
|
string guessVhost;
|
||||||
string guessVhost;
|
if (query.find("vhost=") == string::npos) {
|
||||||
if (query.find("vhost=") == string::npos) {
|
if (vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
||||||
if (vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
guessVhost = vhost;
|
||||||
guessVhost = vhost;
|
} else if (!srs_is_ipv4(host)) {
|
||||||
} else if (!srs_is_ipv4(host)) {
|
guessVhost = 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=");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Well, if vhost exists, always append in query string.
|
size_t end = query.find("&", pos + 1);
|
||||||
if (!guessVhost.empty()) {
|
if (end == string::npos) {
|
||||||
query += "&vhost=" + guessVhost;
|
end = query.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
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;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
|
// 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);
|
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.
|
// publish.
|
||||||
if ((err = client->publish(stream, stream_id, chunk_size)) != srs_success) {
|
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;
|
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;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
|
// 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);
|
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) {
|
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);
|
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 connect_app();
|
||||||
virtual srs_error_t do_connect_app(std::string local_ip, bool debug);
|
virtual srs_error_t do_connect_app(std::string local_ip, bool debug);
|
||||||
public:
|
public:
|
||||||
virtual srs_error_t publish(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);
|
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);
|
||||||
virtual void kbps_sample(const char* label, int64_t age, int msgs);
|
virtual void kbps_sample(const char* label, int64_t age, int msgs);
|
||||||
virtual int sid();
|
virtual int sid();
|
||||||
|
|
Loading…
Reference in a new issue