mirror of
https://github.com/ossrs/srs.git
synced 2025-02-12 19:31:53 +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
|
@ -184,6 +184,7 @@ Please select according to languages:
|
||||||
|
|
||||||
### V3 changes
|
### V3 changes
|
||||||
|
|
||||||
|
* v3.0, 2018-08-02, Always use vhost in stream query, the unify uri. 3.0.35
|
||||||
* v3.0, 2018-08-02, For [#1031][bug #1031], SRS edge support douyu.com. 3.0.34
|
* v3.0, 2018-08-02, For [#1031][bug #1031], SRS edge support douyu.com. 3.0.34
|
||||||
* v3.0, 2018-07-22, Replace hex to string to match MIT license. 3.0.33
|
* v3.0, 2018-07-22, Replace hex to string to match MIT license. 3.0.33
|
||||||
* v3.0, 2018-07-22, Replace base64 to match MIT license. 3.0.32
|
* v3.0, 2018-07-22, Replace base64 to match MIT license. 3.0.32
|
||||||
|
|
|
@ -202,7 +202,7 @@ srs_error_t SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecod
|
||||||
return srs_error_wrap(err, "connect %s failed, cto=%" PRId64 ", sto=%" PRId64, output.c_str(), cto, sto);
|
return srs_error_wrap(err, "connect %s failed, cto=%" PRId64 ", sto=%" PRId64, output.c_str(), cto, sto);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = sdk->publish()) != srs_success) {
|
if ((err = sdk->publish(SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE)) != srs_success) {
|
||||||
return srs_error_wrap(err, "publish");
|
return srs_error_wrap(err, "publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
|
||||||
std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost);
|
std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost);
|
||||||
vhost = srs_string_replace(vhost, "[vhost]", req->vhost);
|
vhost = srs_string_replace(vhost, "[vhost]", req->vhost);
|
||||||
|
|
||||||
url = srs_generate_rtmp_url(server, port, vhost, req->app, req->stream);
|
url = srs_generate_rtmp_url(server, port, req->host, vhost, req->app, req->stream, req->param);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
|
@ -122,7 +122,7 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb)
|
||||||
return srs_error_wrap(err, "edge pull %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
|
return srs_error_wrap(err, "edge pull %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = sdk->play()) != srs_success) {
|
if ((err = sdk->play(_srs_config->get_chunk_size(req->vhost))) != 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,15 +469,7 @@ srs_error_t SrsEdgeForwarder::start()
|
||||||
std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost);
|
std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost);
|
||||||
vhost = srs_string_replace(vhost, "[vhost]", req->vhost);
|
vhost = srs_string_replace(vhost, "[vhost]", req->vhost);
|
||||||
|
|
||||||
url = srs_generate_rtmp_url(server, port, vhost, req->app, req->stream);
|
url = srs_generate_rtmp_url(server, port, req->host, vhost, req->app, req->stream, req->param);
|
||||||
}
|
|
||||||
|
|
||||||
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
|
|
||||||
if (!req->param.empty()) {
|
|
||||||
if (req->param.find("?") != 0) {
|
|
||||||
url += "?";
|
|
||||||
}
|
|
||||||
url += req->param;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
|
@ -490,7 +482,7 @@ srs_error_t SrsEdgeForwarder::start()
|
||||||
return srs_error_wrap(err, "sdk connect %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
|
return srs_error_wrap(err, "sdk connect %s failed, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = sdk->publish()) != srs_success) {
|
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost))) != srs_success) {
|
||||||
return srs_error_wrap(err, "sdk publish");
|
return srs_error_wrap(err, "sdk publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,42 +94,6 @@ srs_error_t SrsForwarder::on_publish()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// discovery the server port and tcUrl from req and ep_forward.
|
|
||||||
std::string server;
|
|
||||||
std::string tcUrl;
|
|
||||||
int port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
|
||||||
if (true) {
|
|
||||||
// parse host:port from hostport.
|
|
||||||
srs_parse_hostport(ep_forward, server, port);
|
|
||||||
|
|
||||||
// generate tcUrl
|
|
||||||
tcUrl = srs_generate_tc_url(server, req->vhost, req->app, port, req->param);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dead loop check
|
|
||||||
std::string source_ep = "rtmp://";
|
|
||||||
source_ep += req->host;
|
|
||||||
source_ep += ":";
|
|
||||||
source_ep += req->port;
|
|
||||||
source_ep += "?vhost=";
|
|
||||||
source_ep += req->vhost;
|
|
||||||
|
|
||||||
std::string dest_ep = "rtmp://";
|
|
||||||
if (ep_forward == SRS_CONSTS_LOCALHOST) {
|
|
||||||
dest_ep += req->host;
|
|
||||||
} else {
|
|
||||||
dest_ep += server;
|
|
||||||
}
|
|
||||||
dest_ep += ":";
|
|
||||||
dest_ep += port;
|
|
||||||
dest_ep += "?vhost=";
|
|
||||||
dest_ep += req->vhost;
|
|
||||||
|
|
||||||
if (source_ep == dest_ep) {
|
|
||||||
return srs_error_new(ERROR_SYSTEM_FORWARD_LOOP, "forward loop detected. src=%s, dest=%s", source_ep.c_str(), dest_ep.c_str());
|
|
||||||
}
|
|
||||||
srs_trace("start forward %s to %s, tcUrl=%s, stream=%s", source_ep.c_str(), dest_ep.c_str(), tcUrl.c_str(), req->stream.c_str());
|
|
||||||
|
|
||||||
srs_freep(trd);
|
srs_freep(trd);
|
||||||
trd = new SrsSTCoroutine("forward", this);
|
trd = new SrsSTCoroutine("forward", this);
|
||||||
if ((err = trd->start()) != srs_success) {
|
if ((err = trd->start()) != srs_success) {
|
||||||
|
@ -245,7 +209,7 @@ srs_error_t SrsForwarder::do_cycle()
|
||||||
srs_parse_hostport(ep_forward, server, port);
|
srs_parse_hostport(ep_forward, server, port);
|
||||||
|
|
||||||
// generate url
|
// generate url
|
||||||
url = srs_generate_rtmp_url(server, port, req->vhost, req->app, req->stream);
|
url = srs_generate_rtmp_url(server, port, req->host, req->vhost, req->app, req->stream, req->param);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_freep(sdk);
|
srs_freep(sdk);
|
||||||
|
@ -257,7 +221,7 @@ srs_error_t SrsForwarder::do_cycle()
|
||||||
return srs_error_wrap(err, "sdk connect url=%s, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
|
return srs_error_wrap(err, "sdk connect url=%s, cto=%" PRId64 ", sto=%" PRId64, url.c_str(), cto, sto);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = sdk->publish()) != srs_success) {
|
if ((err = sdk->publish(_srs_config->get_chunk_size(req->vhost))) != srs_success) {
|
||||||
return srs_error_wrap(err, "sdk publish");
|
return srs_error_wrap(err, "sdk publish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -626,7 +626,7 @@ srs_error_t SrsMpegtsOverUdp::connect()
|
||||||
return srs_error_wrap(err, "connect %s failed, cto=%" PRId64 ", sto=%" PRId64, output.c_str(), cto, sto);
|
return srs_error_wrap(err, "connect %s failed, cto=%" PRId64 ", sto=%" PRId64, output.c_str(), cto, sto);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = sdk->publish()) != srs_success) {
|
if ((err = sdk->publish(SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE)) != srs_success) {
|
||||||
close();
|
close();
|
||||||
return srs_error_wrap(err, "publish");
|
return srs_error_wrap(err, "publish");
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,7 +221,7 @@ string SrsNgExec::parse(SrsRequest* req, string tmpl)
|
||||||
output = srs_string_replace(output, "[pageUrl]", req->pageUrl);
|
output = srs_string_replace(output, "[pageUrl]", req->pageUrl);
|
||||||
|
|
||||||
if (output.find("[url]") != string::npos) {
|
if (output.find("[url]") != string::npos) {
|
||||||
string url = srs_generate_rtmp_url(req->host, req->port, req->vhost, req->app, req->stream);
|
string url = srs_generate_rtmp_url(req->host, req->port, req->host, req->vhost, req->app, req->stream, req->param);
|
||||||
output = srs_string_replace(output, "[url]", url);
|
output = srs_string_replace(output, "[url]", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -661,7 +661,7 @@ srs_error_t SrsRtspConn::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish.
|
// publish.
|
||||||
if ((err = sdk->publish()) != srs_success) {
|
if ((err = sdk->publish(SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE)) != srs_success) {
|
||||||
close();
|
close();
|
||||||
return srs_error_wrap(err, "publish %s failed", url.c_str());
|
return srs_error_wrap(err, "publish %s failed", url.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1482,8 +1482,8 @@ srs_error_t SrsOriginHub::create_forwarders()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: support queue size.
|
// TODO: FIXME: support queue size.
|
||||||
//double queue_size = _srs_config->get_queue_length(req->vhost);
|
double queue_size = _srs_config->get_queue_length(req->vhost);
|
||||||
//forwarder->set_queue_size(queue_size);
|
forwarder->set_queue_size(queue_size);
|
||||||
|
|
||||||
if ((err = forwarder->on_publish()) != srs_success) {
|
if ((err = forwarder->on_publish()) != srs_success) {
|
||||||
return srs_error_wrap(err, "start forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s",
|
return srs_error_wrap(err, "start forwarder failed, vhost=%s, app=%s, stream=%s, forward-to=%s",
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR 3
|
#define VERSION_MAJOR 3
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 34
|
#define VERSION_REVISION 35
|
||||||
|
|
||||||
// generated by configure, only macros.
|
// generated by configure, only macros.
|
||||||
#include <srs_auto_headers.hpp>
|
#include <srs_auto_headers.hpp>
|
||||||
|
|
|
@ -750,16 +750,12 @@ extern "C"{
|
||||||
|
|
||||||
string tcUrl;
|
string tcUrl;
|
||||||
switch(context->schema) {
|
switch(context->schema) {
|
||||||
|
// For SRS3, only use one format url.
|
||||||
case srs_url_schema_normal:
|
case srs_url_schema_normal:
|
||||||
tcUrl=srs_generate_normal_tc_url(context->ip, context->vhost, context->app, context->port, context->param);
|
|
||||||
break;
|
|
||||||
case srs_url_schema_via:
|
case srs_url_schema_via:
|
||||||
tcUrl=srs_generate_via_tc_url(context->ip, context->vhost, context->app, context->port, context->param);
|
|
||||||
break;
|
|
||||||
case srs_url_schema_vis:
|
case srs_url_schema_vis:
|
||||||
case srs_url_schema_vis2:
|
case srs_url_schema_vis2:
|
||||||
tcUrl=srs_generate_vis_tc_url(context->ip, context->vhost, context->app, context->port, context->param);
|
tcUrl = srs_generate_tc_url(context->ip, context->vhost, context->app, context->port);
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -823,7 +819,10 @@ extern "C"{
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = context->rtmp->play(context->stream, context->stream_id)) != srs_success) {
|
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
|
||||||
|
string stream = srs_generate_stream_with_query(context->host, context->vhost, context->stream, context->param);
|
||||||
|
|
||||||
|
if ((err = context->rtmp->play(stream, context->stream_id, SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE)) != srs_success) {
|
||||||
ret = srs_error_code(err);
|
ret = srs_error_code(err);
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -840,7 +839,10 @@ extern "C"{
|
||||||
srs_assert(rtmp != NULL);
|
srs_assert(rtmp != NULL);
|
||||||
Context* context = (Context*)rtmp;
|
Context* context = (Context*)rtmp;
|
||||||
|
|
||||||
if ((err = context->rtmp->fmle_publish(context->stream, context->stream_id)) != srs_success) {
|
// Pass params in stream, @see https://github.com/ossrs/srs/issues/1031#issuecomment-409745733
|
||||||
|
string stream = srs_generate_stream_with_query(context->host, context->vhost, context->stream, context->param);
|
||||||
|
|
||||||
|
if ((err = context->rtmp->fmle_publish(stream, context->stream_id)) != srs_success) {
|
||||||
ret = srs_error_code(err);
|
ret = srs_error_code(err);
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1289,7 +1289,7 @@ int SrsIngestHlsOutput::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish.
|
// publish.
|
||||||
if ((err = sdk->publish()) != srs_success) {
|
if ((err = sdk->publish(SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE)) != srs_success) {
|
||||||
// TODO: FIXME: Use error
|
// TODO: FIXME: Use error
|
||||||
ret = srs_error_code(err);
|
ret = srs_error_code(err);
|
||||||
srs_freep(err);
|
srs_freep(err);
|
||||||
|
|
|
@ -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://";
|
string tcUrl = "rtmp://";
|
||||||
|
|
||||||
if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
if (vhost == SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
||||||
tcUrl += ip;
|
tcUrl += host;
|
||||||
} else {
|
} else {
|
||||||
tcUrl += vhost;
|
tcUrl += vhost;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
||||||
tcUrl += ":";
|
tcUrl += ":" + srs_int2str(port);
|
||||||
tcUrl += srs_int2str(port);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tcUrl += "/";
|
tcUrl += "/" + app;
|
||||||
tcUrl += app;
|
|
||||||
if (!param.empty()) {
|
|
||||||
tcUrl += "?" + param;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tcUrl;
|
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 url = stream;
|
||||||
}
|
string query = param;
|
||||||
|
|
||||||
string srs_generate_via_tc_url(string ip, string vhost, string app, int port, string param)
|
// If no vhost in param, try to append one.
|
||||||
{
|
string guessVhost;
|
||||||
return "rtmp://" + ip + ":" + srs_int2str(port) + "/" + vhost + "/" + app + (param.empty() ? "" : "?" + param);
|
if (query.find("vhost=") == string::npos) {
|
||||||
}
|
if (vhost != SRS_CONSTS_RTMP_DEFAULT_VHOST) {
|
||||||
|
guessVhost = vhost;
|
||||||
|
} else if (!srs_is_ipv4(host)) {
|
||||||
|
guessVhost = host;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string srs_generate_vis_tc_url(string ip, string vhost, string app, int port, string param)
|
// Well, if vhost exists, always append in query string.
|
||||||
{
|
if (!guessVhost.empty()) {
|
||||||
return "rtmp://" + ip + ":" + srs_int2str(port) + "/" + app + (param.empty() ? "" : "?" + param);
|
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>
|
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;
|
string tcUrl = "rtmp://" + server + ":" + srs_int2str(port) + "/" + app;
|
||||||
|
string streamWithQuery = srs_generate_stream_with_query(host, vhost, stream, param);
|
||||||
ss << "rtmp://" << server << ":" << std::dec << port << "/" << app;
|
string url = tcUrl + "/" + streamWithQuery;
|
||||||
|
return url;
|
||||||
// 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, ssize_t* pnwrite)
|
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);
|
extern void srs_random_generate(char* bytes, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate the tcUrl.
|
* generate the tcUrl without param.
|
||||||
* @param param, the app parameters in tcUrl. for example, ?key=xxx,vhost=xxx
|
* @remark Use host as tcUrl.vhost if vhost is default vhost.
|
||||||
* @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.
|
|
||||||
*/
|
*/
|
||||||
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);
|
extern std::string srs_generate_stream_with_query(std::string host, std::string vhost, std::string stream, 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);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create shared ptr message from bytes.
|
* 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
|
// stream: livestream
|
||||||
extern void srs_parse_rtmp_url(std::string url, std::string& tcUrl, std::string& stream);
|
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
|
// Genereate the rtmp url, for instance, rtmp://server:port/app/stream?param
|
||||||
extern std::string srs_generate_rtmp_url(std::string server, int port, std::string vhost, std::string app, std::string stream);
|
// @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.
|
// write large numbers of iovs.
|
||||||
extern srs_error_t srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, ssize_t* pnwrite = NULL);
|
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
|
// join string in vector with indicated separator
|
||||||
extern std::string srs_join_vector_string(std::vector<std::string>& vs, std::string 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
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -2053,7 +2053,7 @@ srs_error_t SrsRtmpClient::create_stream(int& stream_id)
|
||||||
return err;
|
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;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -2081,27 +2081,27 @@ srs_error_t SrsRtmpClient::play(string stream, int stream_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetChunkSize
|
// SetChunkSize
|
||||||
if (true) {
|
if (chunk_size != SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE) {
|
||||||
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
|
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) {
|
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;
|
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;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// SetChunkSize
|
// SetChunkSize
|
||||||
if (true) {
|
if (chunk_size != SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE) {
|
||||||
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
|
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) {
|
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;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
if (true) {
|
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();
|
SrsAmf0Object* ex = SrsAmf0Any::object();
|
||||||
ex->set("code", SrsAmf0Any::number(302));
|
ex->set("code", SrsAmf0Any::number(302));
|
||||||
|
|
|
@ -729,12 +729,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* start play stream.
|
* 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:
|
* start publish stream. use flash publish workflow:
|
||||||
* connect-app => create-stream => flash-publish
|
* 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:
|
* start publish stream. use FMLE publish workflow:
|
||||||
* connect-app => FMLE publish
|
* connect-app => FMLE publish
|
||||||
|
|
|
@ -134,7 +134,7 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug)
|
||||||
// generate the tcUrl
|
// generate the tcUrl
|
||||||
std::string param = "";
|
std::string param = "";
|
||||||
std::string target_vhost = req->vhost;
|
std::string target_vhost = req->vhost;
|
||||||
std::string tc_url = srs_generate_tc_url(req->host, req->vhost, req->app, req->port, param);
|
std::string tc_url = srs_generate_tc_url(req->host, req->vhost, req->app, req->port);
|
||||||
|
|
||||||
// replace the tcUrl in request,
|
// replace the tcUrl in request,
|
||||||
// which will replace the tc_url in client.connect_app().
|
// which will replace the tc_url in client.connect_app().
|
||||||
|
@ -150,43 +150,29 @@ srs_error_t SrsBasicRtmpClient::do_connect_app(string local_ip, bool debug)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsBasicRtmpClient::publish()
|
srs_error_t SrsBasicRtmpClient::publish(int chunk_size)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
string stream = req->stream;
|
|
||||||
|
|
||||||
// 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
|
||||||
if (!req->param.empty()) {
|
string stream = srs_generate_stream_with_query(req->host, req->vhost, req->stream, req->param);
|
||||||
if (req->param.find("?") != 0) {
|
|
||||||
stream += "?";
|
|
||||||
}
|
|
||||||
stream += req->param;
|
|
||||||
}
|
|
||||||
|
|
||||||
// publish.
|
// publish.
|
||||||
if ((err = client->publish(stream, stream_id)) != srs_success) {
|
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);
|
return srs_error_wrap(err, "publish failed, stream=%s, stream_id=%d", stream.c_str(), stream_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsBasicRtmpClient::play()
|
srs_error_t SrsBasicRtmpClient::play(int chunk_size)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
string stream = req->stream;
|
|
||||||
|
|
||||||
// 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
|
||||||
if (!req->param.empty()) {
|
string stream = srs_generate_stream_with_query(req->host, req->vhost, req->stream, req->param);
|
||||||
if (req->param.find("?") != 0) {
|
|
||||||
stream += "?";
|
|
||||||
}
|
|
||||||
stream += req->param;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((err = client->play(stream, stream_id)) != 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();
|
virtual srs_error_t publish(int chunk_size);
|
||||||
virtual srs_error_t play();
|
virtual srs_error_t play(int chunk_size);
|
||||||
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();
|
||||||
|
|
|
@ -559,15 +559,15 @@ VOID TEST(ProtocolUtilityTest, GenerateTcUrl)
|
||||||
string ip; string vhost; string app; int port; string tcUrl; string param;
|
string ip; string vhost; string app; int port; string tcUrl; string param;
|
||||||
|
|
||||||
ip = "127.0.0.1"; vhost = "__defaultVhost__"; app = "live"; port = 1935;
|
ip = "127.0.0.1"; vhost = "__defaultVhost__"; app = "live"; port = 1935;
|
||||||
tcUrl = srs_generate_tc_url(ip, vhost, app, port, param);
|
tcUrl = srs_generate_tc_url(ip, vhost, app, port);
|
||||||
EXPECT_STREQ("rtmp://127.0.0.1/live", tcUrl.c_str());
|
EXPECT_STREQ("rtmp://127.0.0.1/live", tcUrl.c_str());
|
||||||
|
|
||||||
ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 1935;
|
ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 1935;
|
||||||
tcUrl = srs_generate_tc_url(ip, vhost, app, port, param);
|
tcUrl = srs_generate_tc_url(ip, vhost, app, port);
|
||||||
EXPECT_STREQ("rtmp://demo/live", tcUrl.c_str());
|
EXPECT_STREQ("rtmp://demo/live", tcUrl.c_str());
|
||||||
|
|
||||||
ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 19351;
|
ip = "127.0.0.1"; vhost = "demo"; app = "live"; port = 19351;
|
||||||
tcUrl = srs_generate_tc_url(ip, vhost, app, port, param);
|
tcUrl = srs_generate_tc_url(ip, vhost, app, port);
|
||||||
EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str());
|
EXPECT_STREQ("rtmp://demo:19351/live", tcUrl.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue