mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
use the right int type for port.
This commit is contained in:
parent
1c7d5f1852
commit
d8f18aee37
20 changed files with 105 additions and 149 deletions
|
@ -360,19 +360,17 @@ int SrsEdgeIngester::connect_server(string& ep_server, int& ep_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
// select the origin.
|
// select the origin.
|
||||||
|
if (true) {
|
||||||
std::string server = lb->select(conf->args);
|
std::string server = lb->select(conf->args);
|
||||||
int port = ::atoi(SRS_CONSTS_RTMP_DEFAULT_PORT);
|
ep_port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
srs_parse_hostport(server, server, port);
|
srs_parse_hostport(server, ep_server, ep_port);
|
||||||
|
}
|
||||||
// output the connected server and port.
|
|
||||||
ep_server = server;
|
|
||||||
ep_port = port;
|
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
int64_t timeout = SRS_EDGE_INGESTER_TIMEOUT_US;
|
int64_t timeout = SRS_EDGE_INGESTER_TIMEOUT_US;
|
||||||
if ((ret = srs_socket_connect(server, port, timeout, &stfd)) != ERROR_SUCCESS) {
|
if ((ret = srs_socket_connect(ep_server, ep_port, timeout, &stfd)) != ERROR_SUCCESS) {
|
||||||
srs_warn("edge pull failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
srs_warn("edge pull failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
||||||
_req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port, timeout, ret);
|
_req->stream.c_str(), _req->tcUrl.c_str(), ep_server.c_str(), ep_port, timeout, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +384,7 @@ int SrsEdgeIngester::connect_server(string& ep_server, int& ep_port)
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
srs_trace("edge pull connected, url=%s/%s, server=%s:%d",
|
srs_trace("edge pull connected, url=%s/%s, server=%s:%d",
|
||||||
_req->tcUrl.c_str(), _req->stream.c_str(), server.c_str(), port);
|
_req->tcUrl.c_str(), _req->stream.c_str(), ep_server.c_str(), ep_port);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -398,7 +396,7 @@ SrsEdgeForwarder::SrsEdgeForwarder()
|
||||||
client = NULL;
|
client = NULL;
|
||||||
_edge = NULL;
|
_edge = NULL;
|
||||||
_req = NULL;
|
_req = NULL;
|
||||||
origin_index = 0;
|
lb = new SrsLbRoundRobin();
|
||||||
stream_id = 0;
|
stream_id = 0;
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
pthread = new SrsReusableThread2("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US);
|
pthread = new SrsReusableThread2("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US);
|
||||||
|
@ -410,6 +408,7 @@ SrsEdgeForwarder::~SrsEdgeForwarder()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
srs_freep(lb);
|
||||||
srs_freep(pthread);
|
srs_freep(pthread);
|
||||||
srs_freep(queue);
|
srs_freep(queue);
|
||||||
srs_freep(kbps);
|
srs_freep(kbps);
|
||||||
|
@ -437,7 +436,8 @@ int SrsEdgeForwarder::start()
|
||||||
|
|
||||||
send_error_code = ERROR_SUCCESS;
|
send_error_code = ERROR_SUCCESS;
|
||||||
|
|
||||||
std::string ep_server, ep_port;
|
std::string ep_server;
|
||||||
|
int ep_port;
|
||||||
if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) {
|
if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -591,7 +591,7 @@ void SrsEdgeForwarder::close_underlayer_socket()
|
||||||
srs_close_stfd(stfd);
|
srs_close_stfd(stfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsEdgeForwarder::connect_server(string& ep_server, string& ep_port)
|
int SrsEdgeForwarder::connect_server(string& ep_server, int& ep_port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -602,27 +602,17 @@ int SrsEdgeForwarder::connect_server(string& ep_server, string& ep_port)
|
||||||
srs_assert(conf);
|
srs_assert(conf);
|
||||||
|
|
||||||
// select the origin.
|
// select the origin.
|
||||||
std::string server = conf->args.at(origin_index % conf->args.size());
|
if (true) {
|
||||||
origin_index = (origin_index + 1) % conf->args.size();
|
std::string server = lb->select(conf->args);
|
||||||
|
ep_port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
std::string s_port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
srs_parse_hostport(server, ep_server, ep_port);
|
||||||
int port = ::atoi(SRS_CONSTS_RTMP_DEFAULT_PORT);
|
|
||||||
size_t pos = server.find(":");
|
|
||||||
if (pos != std::string::npos) {
|
|
||||||
s_port = server.substr(pos + 1);
|
|
||||||
server = server.substr(0, pos);
|
|
||||||
port = ::atoi(s_port.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// output the connected server and port.
|
|
||||||
ep_server = server;
|
|
||||||
ep_port = s_port;
|
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
int64_t timeout = SRS_EDGE_FORWARDER_TIMEOUT_US;
|
int64_t timeout = SRS_EDGE_FORWARDER_TIMEOUT_US;
|
||||||
if ((ret = srs_socket_connect(server, port, timeout, &stfd)) != ERROR_SUCCESS) {
|
if ((ret = srs_socket_connect(ep_server, ep_port, timeout, &stfd)) != ERROR_SUCCESS) {
|
||||||
srs_warn("edge push failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
srs_warn("edge push failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
||||||
_req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port, timeout, ret);
|
_req->stream.c_str(), _req->tcUrl.c_str(), ep_server.c_str(), ep_port, timeout, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,13 +627,13 @@ int SrsEdgeForwarder::connect_server(string& ep_server, string& ep_port)
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
srs_trace("edge push connected, stream=%s, tcUrl=%s to server=%s, port=%d",
|
srs_trace("edge push connected, stream=%s, tcUrl=%s to server=%s, port=%d",
|
||||||
_req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port);
|
_req->stream.c_str(), _req->tcUrl.c_str(), ep_server.c_str(), ep_port);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: refine the connect_app.
|
// TODO: FIXME: refine the connect_app.
|
||||||
int SrsEdgeForwarder::connect_app(string ep_server, string ep_port)
|
int SrsEdgeForwarder::connect_app(string ep_server, int ep_port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -685,7 +675,7 @@ int SrsEdgeForwarder::connect_app(string ep_server, string ep_port)
|
||||||
// generate the tcUrl
|
// generate the tcUrl
|
||||||
std::string param = "";
|
std::string param = "";
|
||||||
std::string tc_url = srs_generate_tc_url(ep_server, vhost, req->app, ep_port, param);
|
std::string tc_url = srs_generate_tc_url(ep_server, vhost, req->app, ep_port, param);
|
||||||
srs_trace("edge forward to %s:%s at %s", ep_server.c_str(), ep_port.c_str(), tc_url.c_str());
|
srs_trace("edge forward to %s:%d at %s", ep_server.c_str(), ep_port, tc_url.c_str());
|
||||||
|
|
||||||
// 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().
|
||||||
|
|
|
@ -125,7 +125,7 @@ private:
|
||||||
ISrsProtocolReaderWriter* io;
|
ISrsProtocolReaderWriter* io;
|
||||||
SrsKbps* kbps;
|
SrsKbps* kbps;
|
||||||
SrsRtmpClient* client;
|
SrsRtmpClient* client;
|
||||||
int origin_index;
|
SrsLbRoundRobin* lb;
|
||||||
/**
|
/**
|
||||||
* we must ensure one thread one fd principle,
|
* we must ensure one thread one fd principle,
|
||||||
* that is, a fd must be write/read by the one thread.
|
* that is, a fd must be write/read by the one thread.
|
||||||
|
@ -153,8 +153,8 @@ public:
|
||||||
virtual int proxy(SrsCommonMessage* msg);
|
virtual int proxy(SrsCommonMessage* msg);
|
||||||
private:
|
private:
|
||||||
virtual void close_underlayer_socket();
|
virtual void close_underlayer_socket();
|
||||||
virtual int connect_server(std::string& ep_server, std::string& ep_port);
|
virtual int connect_server(std::string& ep_server, int& ep_port);
|
||||||
virtual int connect_app(std::string ep_server, std::string ep_port);
|
virtual int connect_app(std::string ep_server, int ep_port);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -281,7 +281,7 @@ int SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDir
|
||||||
// output stream, to other/self server
|
// output stream, to other/self server
|
||||||
// ie. rtmp://localhost:1935/live/livestream_sd
|
// ie. rtmp://localhost:1935/live/livestream_sd
|
||||||
output = srs_string_replace(output, "[vhost]", req->vhost);
|
output = srs_string_replace(output, "[vhost]", req->vhost);
|
||||||
output = srs_string_replace(output, "[port]", req->port);
|
output = srs_string_replace(output, "[port]", srs_int2str(req->port));
|
||||||
output = srs_string_replace(output, "[app]", req->app);
|
output = srs_string_replace(output, "[app]", req->app);
|
||||||
output = srs_string_replace(output, "[stream]", req->stream);
|
output = srs_string_replace(output, "[stream]", req->stream);
|
||||||
output = srs_string_replace(output, "[engine]", engine->arg0());
|
output = srs_string_replace(output, "[engine]", engine->arg0());
|
||||||
|
|
|
@ -44,6 +44,7 @@ using namespace std;
|
||||||
#include <srs_protocol_amf0.hpp>
|
#include <srs_protocol_amf0.hpp>
|
||||||
#include <srs_kernel_codec.hpp>
|
#include <srs_kernel_codec.hpp>
|
||||||
#include <srs_core_autofree.hpp>
|
#include <srs_core_autofree.hpp>
|
||||||
|
#include <srs_kernel_utility.hpp>
|
||||||
|
|
||||||
// when error, forwarder sleep for a while and retry.
|
// when error, forwarder sleep for a while and retry.
|
||||||
#define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
|
#define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL)
|
||||||
|
@ -105,7 +106,8 @@ int SrsForwarder::on_publish()
|
||||||
SrsRequest* req = _req;
|
SrsRequest* req = _req;
|
||||||
|
|
||||||
// discovery the server port and tcUrl from req and ep_forward.
|
// discovery the server port and tcUrl from req and ep_forward.
|
||||||
std::string server, port, tc_url;
|
int port;
|
||||||
|
std::string server, tc_url;
|
||||||
discovery_ep(server, port, tc_url);
|
discovery_ep(server, port, tc_url);
|
||||||
|
|
||||||
// dead loop check
|
// dead loop check
|
||||||
|
@ -228,7 +230,8 @@ int SrsForwarder::cycle()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
std::string ep_server, ep_port;
|
std::string ep_server;
|
||||||
|
int ep_port;
|
||||||
if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) {
|
if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -273,25 +276,18 @@ void SrsForwarder::close_underlayer_socket()
|
||||||
srs_close_stfd(stfd);
|
srs_close_stfd(stfd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsForwarder::discovery_ep(string& server, string& port, string& tc_url)
|
void SrsForwarder::discovery_ep(string& server, int& port, string& tc_url)
|
||||||
{
|
{
|
||||||
SrsRequest* req = _req;
|
SrsRequest* req = _req;
|
||||||
|
|
||||||
server = _ep_forward;
|
|
||||||
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
|
srs_parse_hostport(_ep_forward, server, port);
|
||||||
// TODO: FIXME: parse complex params
|
|
||||||
size_t pos = _ep_forward.find(":");
|
|
||||||
if (pos != std::string::npos) {
|
|
||||||
port = _ep_forward.substr(pos + 1);
|
|
||||||
server = _ep_forward.substr(0, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate tcUrl
|
// generate tcUrl
|
||||||
tc_url = srs_generate_tc_url(server, req->vhost, req->app, port, req->param);
|
tc_url = srs_generate_tc_url(server, req->vhost, req->app, port, req->param);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsForwarder::connect_server(string& ep_server, string& ep_port)
|
int SrsForwarder::connect_server(string& ep_server, int& ep_port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -299,19 +295,14 @@ int SrsForwarder::connect_server(string& ep_server, string& ep_port)
|
||||||
close_underlayer_socket();
|
close_underlayer_socket();
|
||||||
|
|
||||||
// discovery the server port and tcUrl from req and ep_forward.
|
// discovery the server port and tcUrl from req and ep_forward.
|
||||||
std::string server, s_port, tc_url;
|
string tc_url;
|
||||||
discovery_ep(server, s_port, tc_url);
|
discovery_ep(ep_server, ep_port, tc_url);
|
||||||
int port = ::atoi(s_port.c_str());
|
|
||||||
|
|
||||||
// output the connected server and port.
|
|
||||||
ep_server = server;
|
|
||||||
ep_port = s_port;
|
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
int64_t timeout = SRS_FORWARDER_SLEEP_US;
|
int64_t timeout = SRS_FORWARDER_SLEEP_US;
|
||||||
if ((ret = srs_socket_connect(ep_server, port, timeout, &stfd)) != ERROR_SUCCESS) {
|
if ((ret = srs_socket_connect(ep_server, ep_port, timeout, &stfd)) != ERROR_SUCCESS) {
|
||||||
srs_warn("forward failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
srs_warn("forward failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d",
|
||||||
_req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port, timeout, ret);
|
_req->stream.c_str(), _req->tcUrl.c_str(), ep_server.c_str(), ep_port, timeout, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,13 +316,13 @@ int SrsForwarder::connect_server(string& ep_server, string& ep_port)
|
||||||
kbps->set_io(io, io);
|
kbps->set_io(io, io);
|
||||||
|
|
||||||
srs_trace("forward connected, stream=%s, tcUrl=%s to server=%s, port=%d",
|
srs_trace("forward connected, stream=%s, tcUrl=%s to server=%s, port=%d",
|
||||||
_req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port);
|
_req->stream.c_str(), _req->tcUrl.c_str(), ep_server.c_str(), ep_port);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: refine the connect_app.
|
// TODO: FIXME: refine the connect_app.
|
||||||
int SrsForwarder::connect_app(string ep_server, string ep_port)
|
int SrsForwarder::connect_app(string ep_server, int ep_port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -100,9 +100,9 @@ public:
|
||||||
virtual int cycle();
|
virtual int cycle();
|
||||||
private:
|
private:
|
||||||
virtual void close_underlayer_socket();
|
virtual void close_underlayer_socket();
|
||||||
virtual void discovery_ep(std::string& server, std::string& port, std::string& tc_url);
|
virtual void discovery_ep(std::string& server, int& port, std::string& tc_url);
|
||||||
virtual int connect_server(std::string& ep_server, std::string& ep_port);
|
virtual int connect_server(std::string& ep_server, int& ep_port);
|
||||||
virtual int connect_app(std::string ep_server, std::string ep_port);
|
virtual int connect_app(std::string ep_server, int ep_port);
|
||||||
virtual int forward();
|
virtual int forward();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -332,13 +332,13 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
std::string port;
|
int port;
|
||||||
if (true) {
|
if (true) {
|
||||||
std::vector<std::string> ip_ports = _srs_config->get_listens();
|
std::vector<std::string> ip_ports = _srs_config->get_listens();
|
||||||
srs_assert(ip_ports.size() > 0);
|
srs_assert(ip_ports.size() > 0);
|
||||||
|
|
||||||
std::string ep = ip_ports[0];
|
|
||||||
std::string ip;
|
std::string ip;
|
||||||
|
std::string ep = ip_ports[0];
|
||||||
srs_parse_endpoint(ep, ip, port);
|
srs_parse_endpoint(ep, ip, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S
|
||||||
// output stream, to other/self server
|
// output stream, to other/self server
|
||||||
// ie. rtmp://localhost:1935/live/livestream_sd
|
// ie. rtmp://localhost:1935/live/livestream_sd
|
||||||
output = srs_string_replace(output, "[vhost]", vhost->arg0());
|
output = srs_string_replace(output, "[vhost]", vhost->arg0());
|
||||||
output = srs_string_replace(output, "[port]", port);
|
output = srs_string_replace(output, "[port]", srs_int2str(port));
|
||||||
if (output.empty()) {
|
if (output.empty()) {
|
||||||
ret = ERROR_ENCODER_NO_OUTPUT;
|
ret = ERROR_ENCODER_NO_OUTPUT;
|
||||||
srs_trace("empty output url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret);
|
srs_trace("empty output url, ingest=%s. ret=%d", ingest->arg0().c_str(), ret);
|
||||||
|
|
|
@ -198,7 +198,7 @@ string SrsNgExec::parse(SrsRequest* req, string tmpl)
|
||||||
string output = tmpl;
|
string output = tmpl;
|
||||||
|
|
||||||
output = srs_string_replace(output, "[vhost]", req->vhost);
|
output = srs_string_replace(output, "[vhost]", req->vhost);
|
||||||
output = srs_string_replace(output, "[port]", req->port);
|
output = srs_string_replace(output, "[port]", srs_int2str(req->port));
|
||||||
output = srs_string_replace(output, "[app]", req->app);
|
output = srs_string_replace(output, "[app]", req->app);
|
||||||
output = srs_string_replace(output, "[stream]", req->stream);
|
output = srs_string_replace(output, "[stream]", req->stream);
|
||||||
|
|
||||||
|
@ -207,7 +207,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, ::atoi(req->port.c_str()), req->vhost, req->app, req->stream);
|
string url = srs_generate_rtmp_url(req->host, req->port, req->vhost, req->app, req->stream);
|
||||||
output = srs_string_replace(output, "[url]", url);
|
output = srs_string_replace(output, "[url]", url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,11 +159,11 @@ int SrsRtmpConn::do_cycle()
|
||||||
srs_info("discovery app success. schema=%s, vhost=%s, port=%s, app=%s",
|
srs_info("discovery app success. schema=%s, vhost=%s, port=%s, app=%s",
|
||||||
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str());
|
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str());
|
||||||
|
|
||||||
if (req->schema.empty() || req->vhost.empty() || req->port.empty() || req->app.empty()) {
|
if (req->schema.empty() || req->vhost.empty() || req->app.empty()) {
|
||||||
ret = ERROR_RTMP_REQ_TCURL;
|
ret = ERROR_RTMP_REQ_TCURL;
|
||||||
srs_error("discovery tcUrl failed. "
|
srs_error("discovery tcUrl failed. "
|
||||||
"tcUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, ret=%d",
|
"tcUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, ret=%d",
|
||||||
req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port.c_str(), req->app.c_str(), ret);
|
req->tcUrl.c_str(), req->schema.c_str(), req->vhost.c_str(), req->port, req->app.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +175,9 @@ int SrsRtmpConn::do_cycle()
|
||||||
srs_verbose("check vhost success.");
|
srs_verbose("check vhost success.");
|
||||||
|
|
||||||
srs_trace("connect app, "
|
srs_trace("connect app, "
|
||||||
"tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%s, app=%s, args=%s",
|
"tcUrl=%s, pageUrl=%s, swfUrl=%s, schema=%s, vhost=%s, port=%d, app=%s, args=%s",
|
||||||
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
|
req->tcUrl.c_str(), req->pageUrl.c_str(), req->swfUrl.c_str(),
|
||||||
req->schema.c_str(), req->vhost.c_str(), req->port.c_str(),
|
req->schema.c_str(), req->vhost.c_str(), req->port,
|
||||||
req->app.c_str(), (req->args? "(obj)":"null"));
|
req->app.c_str(), (req->args? "(obj)":"null"));
|
||||||
|
|
||||||
// show client identity
|
// show client identity
|
||||||
|
@ -1230,9 +1230,10 @@ int SrsRtmpConn::check_edge_token_traverse_auth()
|
||||||
srs_assert(req);
|
srs_assert(req);
|
||||||
|
|
||||||
st_netfd_t stsock = NULL;
|
st_netfd_t stsock = NULL;
|
||||||
SrsConfDirective* conf = _srs_config->get_vhost_edge_origin(req->vhost);
|
vector<string> args = _srs_config->get_vhost_edge_origin(req->vhost)->args;
|
||||||
for (int i = 0; i < (int)conf->args.size(); i++) {
|
for (int i = 0; i < (int)args.size(); i++) {
|
||||||
if ((ret = connect_server(i, &stsock)) == ERROR_SUCCESS) {
|
string hostport = args.at(i);
|
||||||
|
if ((ret = connect_server(hostport, &stsock)) == ERROR_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1255,7 @@ int SrsRtmpConn::check_edge_token_traverse_auth()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsRtmpConn::connect_server(int origin_index, st_netfd_t* pstsock)
|
int SrsRtmpConn::connect_server(string hostport, st_netfd_t* pstsock)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -1262,17 +1263,9 @@ int SrsRtmpConn::connect_server(int origin_index, st_netfd_t* pstsock)
|
||||||
srs_assert(conf);
|
srs_assert(conf);
|
||||||
|
|
||||||
// select the origin.
|
// select the origin.
|
||||||
std::string server = conf->args.at(origin_index % conf->args.size());
|
string server;
|
||||||
origin_index = (origin_index + 1) % conf->args.size();
|
int port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
|
srs_parse_hostport(hostport, server, port);
|
||||||
std::string s_port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
|
||||||
int port = ::atoi(SRS_CONSTS_RTMP_DEFAULT_PORT);
|
|
||||||
size_t pos = server.find(":");
|
|
||||||
if (pos != std::string::npos) {
|
|
||||||
s_port = server.substr(pos + 1);
|
|
||||||
server = server.substr(0, pos);
|
|
||||||
port = ::atoi(s_port.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// open socket.
|
// open socket.
|
||||||
st_netfd_t stsock = NULL;
|
st_netfd_t stsock = NULL;
|
||||||
|
|
|
@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
#include <srs_app_conn.hpp>
|
#include <srs_app_conn.hpp>
|
||||||
#include <srs_app_reload.hpp>
|
#include <srs_app_reload.hpp>
|
||||||
|
@ -132,7 +134,7 @@ private:
|
||||||
virtual void set_sock_options();
|
virtual void set_sock_options();
|
||||||
private:
|
private:
|
||||||
virtual int check_edge_token_traverse_auth();
|
virtual int check_edge_token_traverse_auth();
|
||||||
virtual int connect_server(int origin_index, st_netfd_t* pstsock);
|
virtual int connect_server(std::string hostport, st_netfd_t* pstsock);
|
||||||
virtual int do_token_traverse_auth(SrsRtmpClient* client);
|
virtual int do_token_traverse_auth(SrsRtmpClient* client);
|
||||||
/**
|
/**
|
||||||
* when the connection disconnect, call this method.
|
* when the connection disconnect, call this method.
|
||||||
|
|
|
@ -205,29 +205,6 @@ string srs_path_build_timestamp(string template_path)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void srs_parse_endpoint(string ip_port, string& ip, string& port)
|
|
||||||
{
|
|
||||||
ip = "0.0.0.0";
|
|
||||||
port = ip_port;
|
|
||||||
|
|
||||||
size_t pos = string::npos;
|
|
||||||
if ((pos = port.find(":")) != string::npos) {
|
|
||||||
ip = port.substr(0, pos);
|
|
||||||
port = port.substr(pos + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void srs_parse_endpoint(string ip_port, string& ip, int& port)
|
|
||||||
{
|
|
||||||
std::string the_port;
|
|
||||||
srs_parse_endpoint(ip_port, ip, the_port);
|
|
||||||
port = ::atoi(the_port.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
string srs_bool2switch(bool v) {
|
|
||||||
return v? "on" : "off";
|
|
||||||
}
|
|
||||||
|
|
||||||
int srs_kill_forced(int& pid)
|
int srs_kill_forced(int& pid)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
|
@ -75,18 +75,6 @@ extern std::string srs_path_build_stream(std::string template_path, std::string
|
||||||
*/
|
*/
|
||||||
extern std::string srs_path_build_timestamp(std::string template_path);
|
extern std::string srs_path_build_timestamp(std::string template_path);
|
||||||
|
|
||||||
/**
|
|
||||||
* parse the endpoint to ip and port.
|
|
||||||
* @param ip_port the ip and port which formats in <[ip:]port>
|
|
||||||
*/
|
|
||||||
extern void srs_parse_endpoint(std::string ip_port, std::string& ip, std::string& port);
|
|
||||||
extern void srs_parse_endpoint(std::string ip_port, std::string& ip, int& port);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convert bool to switch value, true to "on", false to "off".
|
|
||||||
*/
|
|
||||||
extern std::string srs_bool2switch(bool v);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* kill the pid by SIGINT, then wait to quit,
|
* kill the pid by SIGINT, then wait to quit,
|
||||||
* kill the pid by SIGKILL again when exceed the timeout.
|
* kill the pid by SIGKILL again when exceed the timeout.
|
||||||
|
|
|
@ -44,7 +44,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#define SRS_CONSTS_RTMP_DEFAULT_VHOST "__defaultVhost__"
|
#define SRS_CONSTS_RTMP_DEFAULT_VHOST "__defaultVhost__"
|
||||||
#define SRS_CONSTS_RTMP_DEFAULT_APP "__defaultApp__"
|
#define SRS_CONSTS_RTMP_DEFAULT_APP "__defaultApp__"
|
||||||
// default port of rtmp
|
// default port of rtmp
|
||||||
#define SRS_CONSTS_RTMP_DEFAULT_PORT "1935"
|
#define SRS_CONSTS_RTMP_DEFAULT_PORT 1935
|
||||||
|
|
||||||
// the default chunk size for system.
|
// the default chunk size for system.
|
||||||
#define SRS_CONSTS_RTMP_SRS_CHUNK_SIZE 60000
|
#define SRS_CONSTS_RTMP_SRS_CHUNK_SIZE 60000
|
||||||
|
|
|
@ -180,13 +180,27 @@ string srs_dns_resolve(string host)
|
||||||
|
|
||||||
void srs_parse_hostport(const string& hostport, string& host, int& port)
|
void srs_parse_hostport(const string& hostport, string& host, int& port)
|
||||||
{
|
{
|
||||||
host = hostport;
|
|
||||||
|
|
||||||
size_t pos = hostport.find(":");
|
size_t pos = hostport.find(":");
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
string p = hostport.substr(pos + 1);
|
string p = hostport.substr(pos + 1);
|
||||||
host = hostport.substr(0, pos);
|
host = hostport.substr(0, pos);
|
||||||
port = ::atoi(p.c_str());
|
port = ::atoi(p.c_str());
|
||||||
|
} else {
|
||||||
|
host = hostport;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void srs_parse_endpoint(string hostport, string& ip, int& port)
|
||||||
|
{
|
||||||
|
ip = "0.0.0.0";
|
||||||
|
|
||||||
|
size_t pos = string::npos;
|
||||||
|
if ((pos = hostport.find(":")) != string::npos) {
|
||||||
|
ip = hostport.substr(0, pos);
|
||||||
|
string sport = hostport.substr(pos + 1);
|
||||||
|
port = ::atoi(sport.c_str());
|
||||||
|
} else {
|
||||||
|
port = ::atoi(hostport.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +220,10 @@ string srs_float2str(double value)
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string srs_bool2switch(bool v) {
|
||||||
|
return v? "on" : "off";
|
||||||
|
}
|
||||||
|
|
||||||
bool srs_is_little_endian()
|
bool srs_is_little_endian()
|
||||||
{
|
{
|
||||||
// convert to network(big-endian) order, if not equals,
|
// convert to network(big-endian) order, if not equals,
|
||||||
|
|
|
@ -52,13 +52,21 @@ extern int64_t srs_update_system_time_ms();
|
||||||
|
|
||||||
// dns resolve utility, return the resolved ip address.
|
// dns resolve utility, return the resolved ip address.
|
||||||
extern std::string srs_dns_resolve(std::string host);
|
extern std::string srs_dns_resolve(std::string host);
|
||||||
|
|
||||||
// split the host:port to host and port.
|
// split the host:port to host and port.
|
||||||
|
// @remark the hostport format in <host[:port]>, where port is optional.
|
||||||
extern void srs_parse_hostport(const std::string& hostport, std::string& host, int& port);
|
extern void srs_parse_hostport(const std::string& hostport, std::string& host, int& port);
|
||||||
|
|
||||||
|
// parse the endpoint to ip and port.
|
||||||
|
// @remark hostport format in <[ip:]port>, where ip is default to "0.0.0.0".
|
||||||
|
extern void srs_parse_endpoint(std::string hostport, std::string& ip, int& port);
|
||||||
|
|
||||||
// parse the int64 value to string.
|
// parse the int64 value to string.
|
||||||
extern std::string srs_int2str(int64_t value);
|
extern std::string srs_int2str(int64_t value);
|
||||||
// parse the float value to string, precise is 2.
|
// parse the float value to string, precise is 2.
|
||||||
extern std::string srs_float2str(double value);
|
extern std::string srs_float2str(double value);
|
||||||
|
// convert bool to switch value, true to "on", false to "off".
|
||||||
|
extern std::string srs_bool2switch(bool v);
|
||||||
|
|
||||||
// whether system is little endian
|
// whether system is little endian
|
||||||
extern bool srs_is_little_endian();
|
extern bool srs_is_little_endian();
|
||||||
|
|
|
@ -63,7 +63,7 @@ struct Context
|
||||||
std::string tcUrl;
|
std::string tcUrl;
|
||||||
std::string host;
|
std::string host;
|
||||||
std::string ip;
|
std::string ip;
|
||||||
std::string port;
|
int port;
|
||||||
std::string vhost;
|
std::string vhost;
|
||||||
std::string app;
|
std::string app;
|
||||||
std::string stream;
|
std::string stream;
|
||||||
|
@ -509,9 +509,7 @@ int srs_librtmp_context_connect(Context* context)
|
||||||
srs_assert(context->skt);
|
srs_assert(context->skt);
|
||||||
|
|
||||||
std::string ip = context->ip;
|
std::string ip = context->ip;
|
||||||
int port = ::atoi(context->port.c_str());
|
if ((ret = context->skt->connect(ip.c_str(), context->port)) != ERROR_SUCCESS) {
|
||||||
|
|
||||||
if ((ret = context->skt->connect(ip.c_str(), port)) != ERROR_SUCCESS) {
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -708,7 +708,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int flush_message_queue();
|
virtual int flush_message_queue();
|
||||||
private:
|
private:
|
||||||
virtual int connect_app(std::string ep_server, std::string ep_port);
|
virtual int connect_app(std::string ep_server, int ep_port);
|
||||||
// close the connected io and rtmp to ready to be re-connect.
|
// close the connected io and rtmp to ready to be re-connect.
|
||||||
virtual void close();
|
virtual void close();
|
||||||
};
|
};
|
||||||
|
@ -1235,8 +1235,8 @@ int SrsIngestSrsOutput::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// connect host.
|
// connect host.
|
||||||
if ((ret = srs_socket_connect(req->host, ::atoi(req->port.c_str()), ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) {
|
if ((ret = srs_socket_connect(req->host, req->port, ST_UTIME_NO_TIMEOUT, &stfd)) != ERROR_SUCCESS) {
|
||||||
srs_error("mpegts: connect server %s:%s failed. ret=%d", req->host.c_str(), req->port.c_str(), ret);
|
srs_error("mpegts: connect server %s:%d failed. ret=%d", req->host.c_str(), req->port, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
io = new SrsStSocket(stfd);
|
io = new SrsStSocket(stfd);
|
||||||
|
@ -1270,7 +1270,7 @@ int SrsIngestSrsOutput::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: refine the connect_app.
|
// TODO: FIXME: refine the connect_app.
|
||||||
int SrsIngestSrsOutput::connect_app(string ep_server, string ep_port)
|
int SrsIngestSrsOutput::connect_app(string ep_server, int ep_port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ using namespace std;
|
||||||
void srs_discovery_tc_url(
|
void srs_discovery_tc_url(
|
||||||
string tcUrl,
|
string tcUrl,
|
||||||
string& schema, string& host, string& vhost,
|
string& schema, string& host, string& vhost,
|
||||||
string& app, string& port, std::string& param
|
string& app, int& port, std::string& param
|
||||||
) {
|
) {
|
||||||
size_t pos = std::string::npos;
|
size_t pos = std::string::npos;
|
||||||
std::string url = tcUrl;
|
std::string url = tcUrl;
|
||||||
|
@ -63,8 +63,7 @@ void srs_discovery_tc_url(
|
||||||
|
|
||||||
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
if ((pos = host.find(":")) != std::string::npos) {
|
if ((pos = host.find(":")) != std::string::npos) {
|
||||||
port = host.substr(pos + 1);
|
srs_parse_hostport(host, host, port);
|
||||||
host = host.substr(0, pos);
|
|
||||||
srs_info("discovery host=%s, port=%s", host.c_str(), port.c_str());
|
srs_info("discovery host=%s, port=%s", host.c_str(), port.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,11 +125,6 @@ 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 ip, string vhost, string app, int port, string param)
|
||||||
{
|
|
||||||
return srs_generate_tc_url(ip, vhost, app, srs_int2str(port), param);
|
|
||||||
}
|
|
||||||
|
|
||||||
string srs_generate_tc_url(string ip, string vhost, string app, string port, string param)
|
|
||||||
{
|
{
|
||||||
string tcUrl = "rtmp://";
|
string tcUrl = "rtmp://";
|
||||||
|
|
||||||
|
@ -142,7 +136,7 @@ string srs_generate_tc_url(string ip, string vhost, string app, string port, str
|
||||||
|
|
||||||
if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
if (port != SRS_CONSTS_RTMP_DEFAULT_PORT) {
|
||||||
tcUrl += ":";
|
tcUrl += ":";
|
||||||
tcUrl += port;
|
tcUrl += srs_int2str(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
tcUrl += "/";
|
tcUrl += "/";
|
||||||
|
|
|
@ -58,7 +58,7 @@ class ISrsProtocolReaderWriter;
|
||||||
extern void srs_discovery_tc_url(
|
extern void srs_discovery_tc_url(
|
||||||
std::string tcUrl,
|
std::string tcUrl,
|
||||||
std::string& schema, std::string& host, std::string& vhost,
|
std::string& schema, std::string& host, std::string& vhost,
|
||||||
std::string& app, std::string& port, std::string& param
|
std::string& app, int& port, std::string& param
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,10 +85,6 @@ extern void srs_random_generate(char* bytes, int size);
|
||||||
* @remark when vhost equals to __defaultVhost__, use ip as vhost.
|
* @remark when vhost equals to __defaultVhost__, use ip as vhost.
|
||||||
* @remark ignore port if port equals to default port 1935.
|
* @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, std::string port,
|
|
||||||
std::string param
|
|
||||||
);
|
|
||||||
extern std::string srs_generate_tc_url(
|
extern std::string srs_generate_tc_url(
|
||||||
std::string ip, std::string vhost, std::string app, int port,
|
std::string ip, std::string vhost, std::string app, int port,
|
||||||
std::string param
|
std::string param
|
||||||
|
|
|
@ -1664,6 +1664,7 @@ SrsRequest::SrsRequest()
|
||||||
{
|
{
|
||||||
objectEncoding = RTMP_SIG_AMF0_VER;
|
objectEncoding = RTMP_SIG_AMF0_VER;
|
||||||
duration = -1;
|
duration = -1;
|
||||||
|
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
|
||||||
args = NULL;
|
args = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -554,7 +554,7 @@ public:
|
||||||
// the host in tcUrl.
|
// the host in tcUrl.
|
||||||
std::string host;
|
std::string host;
|
||||||
// the port in tcUrl.
|
// the port in tcUrl.
|
||||||
std::string port;
|
int port;
|
||||||
// the app in tcUrl, without param.
|
// the app in tcUrl, without param.
|
||||||
std::string app;
|
std::string app;
|
||||||
// the param in tcUrl(app).
|
// the param in tcUrl(app).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue