1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Merge branch '3.0release' into 4.0release

This commit is contained in:
winlin 2020-12-26 22:15:37 +08:00
commit 2538b02a9b
8 changed files with 38 additions and 29 deletions

View file

@ -200,24 +200,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

@ -82,7 +82,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

@ -148,12 +148,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) {
@ -163,12 +163,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();