mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Fix #1031, Always use vhost in stream query, the unify uri. 3.0.35
This commit is contained in:
parent
8cf5df5afb
commit
68a1656e07
18 changed files with 102 additions and 159 deletions
|
@ -151,43 +151,59 @@ void srs_random_generate(char* bytes, int size)
|
|||
}
|
||||
}
|
||||
|
||||
string srs_generate_tc_url(string ip, string vhost, string app, int port, string param)
|
||||
string srs_generate_tc_url(string host, string vhost, string app, int port)
|
||||
{
|
||||
string tcUrl = "rtmp://";
|
||||
|
||||
if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
||||
tcUrl += ip;
|
||||
tcUrl += host;
|
||||
} else {
|
||||
tcUrl += vhost;
|
||||
}
|
||||
|
||||
if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
||||
tcUrl += ":";
|
||||
tcUrl += srs_int2str(port);
|
||||
tcUrl += ":" + srs_int2str(port);
|
||||
}
|
||||
|
||||
tcUrl += "/";
|
||||
tcUrl += app;
|
||||
if (!param.empty()) {
|
||||
tcUrl += "?" + param;
|
||||
}
|
||||
tcUrl += "/" + app;
|
||||
|
||||
return tcUrl;
|
||||
}
|
||||
|
||||
string srs_generate_normal_tc_url(string ip, string vhost, string app, int port, string param)
|
||||
string srs_generate_stream_with_query(string host, string vhost, string stream, string param)
|
||||
{
|
||||
return "rtmp://" + vhost + ":" + srs_int2str(port) + "/" + app + (param.empty() ? "" : "?" + param);
|
||||
}
|
||||
|
||||
string srs_generate_via_tc_url(string ip, string vhost, string app, int port, string param)
|
||||
{
|
||||
return "rtmp://" + ip + ":" + srs_int2str(port) + "/" + vhost + "/" + app + (param.empty() ? "" : "?" + param);
|
||||
}
|
||||
|
||||
string srs_generate_vis_tc_url(string ip, string vhost, string app, int port, string param)
|
||||
{
|
||||
return "rtmp://" + ip + ":" + srs_int2str(port) + "/" + app + (param.empty() ? "" : "?" + param);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// Well, if vhost exists, always append in query string.
|
||||
if (!guessVhost.empty()) {
|
||||
query += "&vhost=" + guessVhost;
|
||||
}
|
||||
|
||||
// Remove the start & when param is empty.
|
||||
srs_string_trim_start(query, "&");
|
||||
|
||||
// Prefix query with ?.
|
||||
if (!srs_string_starts_with(query, "?")) {
|
||||
url += "?";
|
||||
}
|
||||
|
||||
// Append query to url.
|
||||
if (!query.empty()) {
|
||||
url += query;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -287,22 +303,12 @@ void srs_parse_rtmp_url(string url, string& tcUrl, string& stream)
|
|||
}
|
||||
}
|
||||
|
||||
string srs_generate_rtmp_url(string server, int port, string vhost, string app, string stream)
|
||||
string srs_generate_rtmp_url(string server, int port, string host, string vhost, string app, string stream, string param)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "rtmp://" << server << ":" << std::dec << port << "/" << app;
|
||||
|
||||
// when default or server is vhost, donot specifies the vhost in params.
|
||||
if (SRS_CONSTS_RTMP_DEFAULT_VHOST != vhost && server != vhost) {
|
||||
ss << "...vhost..." << vhost;
|
||||
}
|
||||
|
||||
if (!stream.empty()) {
|
||||
ss << "/" << stream;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
string tcUrl = "rtmp://" + server + ":" + srs_int2str(port) + "/" + app;
|
||||
string streamWithQuery = srs_generate_stream_with_query(host, vhost, stream, param);
|
||||
string url = tcUrl + "/" + streamWithQuery;
|
||||
return url;
|
||||
}
|
||||
|
||||
srs_error_t srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, ssize_t* pnwrite)
|
||||
|
|
|
@ -71,28 +71,16 @@ extern void srs_parse_query_string(std::string q, std::map<std::string, std::str
|
|||
extern void srs_random_generate(char* bytes, int size);
|
||||
|
||||
/**
|
||||
* generate the tcUrl.
|
||||
* @param param, the app parameters in tcUrl. for example, ?key=xxx,vhost=xxx
|
||||
* @return the tcUrl generated from ip/vhost/app/port.
|
||||
* @remark when vhost equals to __defaultVhost__, use ip as vhost.
|
||||
* @remark ignore port if port equals to default port 1935.
|
||||
* generate the tcUrl without param.
|
||||
* @remark Use host as tcUrl.vhost if vhost is default vhost.
|
||||
*/
|
||||
extern std::string srs_generate_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
||||
extern std::string srs_generate_tc_url(std::string host, std::string vhost, std::string app, int port);
|
||||
|
||||
/**
|
||||
* srs_detect_tools generate the normal tcUrl
|
||||
* Generate the stream with param.
|
||||
* @remark Append vhost in query string if not default vhost.
|
||||
*/
|
||||
extern std::string srs_generate_normal_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
||||
|
||||
/**
|
||||
* srs_detect_tools generate the normal tcUrl
|
||||
*/
|
||||
extern std::string srs_generate_via_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
||||
|
||||
/**
|
||||
* srs_detect_tools generate the vis/vis2 tcUrl
|
||||
*/
|
||||
extern std::string srs_generate_vis_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
||||
extern std::string srs_generate_stream_with_query(std::string host, std::string vhost, std::string stream, std::string param);
|
||||
|
||||
/**
|
||||
* create shared ptr message from bytes.
|
||||
|
@ -111,8 +99,9 @@ extern std::string srs_generate_stream_url(std::string vhost, std::string app, s
|
|||
// stream: livestream
|
||||
extern void srs_parse_rtmp_url(std::string url, std::string& tcUrl, std::string& stream);
|
||||
|
||||
// genereate the rtmp url, for instance, rtmp://server:port/app...vhost...vhost/stream
|
||||
extern std::string srs_generate_rtmp_url(std::string server, int port, std::string vhost, std::string app, std::string stream);
|
||||
// Genereate the rtmp url, for instance, rtmp://server:port/app/stream?param
|
||||
// @remark We always put vhost in param, in the query of url.
|
||||
extern std::string srs_generate_rtmp_url(std::string server, int port, std::string host, std::string vhost, std::string app, std::string stream, std::string param);
|
||||
|
||||
// write large numbers of iovs.
|
||||
extern srs_error_t srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, ssize_t* pnwrite = NULL);
|
||||
|
@ -120,5 +109,8 @@ extern srs_error_t srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* io
|
|||
// join string in vector with indicated separator
|
||||
extern std::string srs_join_vector_string(std::vector<std::string>& vs, std::string separator);
|
||||
|
||||
// Whether domain is an IPv4 address.
|
||||
extern bool srs_is_ipv4(std::string domain);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -2053,7 +2053,7 @@ srs_error_t SrsRtmpClient::create_stream(int& stream_id)
|
|||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsRtmpClient::play(string stream, int stream_id)
|
||||
srs_error_t SrsRtmpClient::play(string stream, int stream_id, int chunk_size)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
@ -2081,27 +2081,27 @@ srs_error_t SrsRtmpClient::play(string stream, int stream_id)
|
|||
}
|
||||
|
||||
// SetChunkSize
|
||||
if (true) {
|
||||
if (chunk_size != SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE) {
|
||||
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
|
||||
pkt->chunk_size = SRS_CONSTS_RTMP_SRS_CHUNK_SIZE;
|
||||
pkt->chunk_size = chunk_size;
|
||||
if ((err = protocol->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send set chunk size failed. stream=%s, chunk_size=%d", stream.c_str(), SRS_CONSTS_RTMP_SRS_CHUNK_SIZE);
|
||||
return srs_error_wrap(err, "send set chunk size failed. stream=%s, chunk_size=%d", stream.c_str(), chunk_size);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsRtmpClient::publish(string stream, int stream_id)
|
||||
srs_error_t SrsRtmpClient::publish(string stream, int stream_id, int chunk_size)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// SetChunkSize
|
||||
if (true) {
|
||||
if (chunk_size != SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE) {
|
||||
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
|
||||
pkt->chunk_size = SRS_CONSTS_RTMP_SRS_CHUNK_SIZE;
|
||||
pkt->chunk_size = chunk_size;
|
||||
if ((err = protocol->send_and_free_packet(pkt, 0)) != srs_success) {
|
||||
return srs_error_wrap(err, "send set chunk size failed. stream=%s, chunk_size=%d", stream.c_str(), SRS_CONSTS_RTMP_SRS_CHUNK_SIZE);
|
||||
return srs_error_wrap(err, "send set chunk size failed. stream=%s, chunk_size=%d", stream.c_str(), chunk_size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2407,7 +2407,7 @@ srs_error_t SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool&
|
|||
srs_error_t err = srs_success;
|
||||
|
||||
if (true) {
|
||||
string url = srs_generate_rtmp_url(host, port, r->vhost, r->app, "");
|
||||
string url = srs_generate_rtmp_url(host, port, r->host, r->vhost, r->app, r->stream, r->param);
|
||||
|
||||
SrsAmf0Object* ex = SrsAmf0Any::object();
|
||||
ex->set("code", SrsAmf0Any::number(302));
|
||||
|
|
|
@ -729,12 +729,12 @@ public:
|
|||
/**
|
||||
* start play stream.
|
||||
*/
|
||||
virtual srs_error_t play(std::string stream, int stream_id);
|
||||
virtual srs_error_t play(std::string stream, int stream_id, int chunk_size);
|
||||
/**
|
||||
* start publish stream. use flash publish workflow:
|
||||
* connect-app => create-stream => flash-publish
|
||||
*/
|
||||
virtual srs_error_t publish(std::string stream, int stream_id);
|
||||
virtual srs_error_t publish(std::string stream, int stream_id, int chunk_size);
|
||||
/**
|
||||
* start publish stream. use FMLE publish workflow:
|
||||
* connect-app => FMLE publish
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue