胡斌

fix bug: using port of input source server as the input port of the source of transcoding

... ... @@ -96,7 +96,7 @@ int SrsEdgeIngester::start()
{
int ret = ERROR_SUCCESS;
if ((ret = _source->on_publish()) != ERROR_SUCCESS) {
if ((ret = _source->on_publish(_req)) != ERROR_SUCCESS) {
srs_error("edge pull stream then publish to edge failed. ret=%d", ret);
return ret;
}
... ...
... ... @@ -253,6 +253,8 @@ int SrsEncoder::parse_ffmpeg(SrsRequest* req, SrsConfDirective* conf)
return ret;
}
extern char rtmp_port[16];
int SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDirective* engine)
{
int ret = ERROR_SUCCESS;
... ... @@ -263,7 +265,7 @@ int SrsEncoder::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsRequest* req, SrsConfDir
input = "rtmp://";
input += SRS_CONSTS_LOCALHOST;
input += ":";
input += req->port;
input += rtmp_port;
input += "/";
input += req->app;
input += "?vhost=";
... ...
... ... @@ -82,7 +82,7 @@ SrsForwarder::~SrsForwarder()
int SrsForwarder::check_dead_loop(SrsRequest* req, std::string ep_forward)
{
int ret = ERROR_SUCCESS;
std::string server, port, tc_url;
std::string server, port;
server = ep_forward;
port = SRS_CONSTS_RTMP_DEFAULT_PORT;
... ... @@ -94,16 +94,12 @@ int SrsForwarder::check_dead_loop(SrsRequest* req, std::string ep_forward)
server = ep_forward.substr(0, pos);
}
// generate tcUrl
tc_url = 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) {
... ... @@ -114,8 +110,6 @@ int SrsForwarder::check_dead_loop(SrsRequest* req, std::string ep_forward)
}
dest_ep += ":";
dest_ep += port;
dest_ep += "?vhost=";
dest_ep += req->vhost;
if (source_ep == dest_ep) {
ret = ERROR_SYSTEM_FORWARD_LOOP;
... ...
... ... @@ -986,7 +986,7 @@ int SrsRtmpConn::acquire_publish(SrsSource* source, bool is_edge)
return ret;
}
} else {
if ((ret = source->on_publish()) != ERROR_SUCCESS) {
if ((ret = source->on_publish(req)) != ERROR_SUCCESS) {
srs_error("notify publish failed. ret=%d", ret);
return ret;
}
... ...
... ... @@ -1068,6 +1068,8 @@ int SrsServer::do_cycle()
return ret;
}
char rtmp_port[16] = SRS_CONSTS_RTMP_DEFAULT_PORT;
int SrsServer::listen_rtmp()
{
int ret = ERROR_SUCCESS;
... ... @@ -1078,6 +1080,8 @@ int SrsServer::listen_rtmp()
close_listeners(SrsListenerRtmpStream);
int first_port = 0;
for (int i = 0; i < (int)ip_ports.size(); i++) {
SrsListener* listener = new SrsStreamListener(this, SrsListenerRtmpStream);
listeners.push_back(listener);
... ... @@ -1090,8 +1094,14 @@ int SrsServer::listen_rtmp()
srs_error("RTMP stream listen at %s:%d failed. ret=%d", ip.c_str(), port, ret);
return ret;
}
if(!first_port){
first_port = port;
}
}
snprintf(rtmp_port, 16, "%d", first_port);
return ret;
}
... ...
... ... @@ -1233,7 +1233,7 @@ int SrsSource::on_reload_vhost_forward(string vhost)
return ret;
}
if ((ret = create_forwarders()) != ERROR_SUCCESS) {
if ((ret = create_forwarders(_req)) != ERROR_SUCCESS) {
srs_error("create forwarders failed. ret=%d", ret);
return ret;
}
... ... @@ -2193,7 +2193,7 @@ int SrsSource::on_aggregate(SrsCommonMessage* msg)
return ret;
}
int SrsSource::on_publish()
int SrsSource::on_publish(SrsRequest* req)
{
int ret = ERROR_SUCCESS;
... ... @@ -2214,7 +2214,7 @@ int SrsSource::on_publish()
last_packet_time = 0;
// create forwarders
if ((ret = create_forwarders()) != ERROR_SUCCESS) {
if ((ret = create_forwarders(req)) != ERROR_SUCCESS) {
srs_error("create forwarders failed. ret=%d", ret);
return ret;
}
... ... @@ -2420,7 +2420,7 @@ void SrsSource::on_edge_proxy_unpublish()
publish_edge->on_proxy_unpublish();
}
int SrsSource::create_forwarders()
int SrsSource::create_forwarders(SrsRequest* req)
{
int ret = ERROR_SUCCESS;
... ... @@ -2429,7 +2429,7 @@ int SrsSource::create_forwarders()
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
std::string forward_server = conf->args.at(i);
if (SrsForwarder::check_dead_loop(_req, forward_server)) {//if the source is from any of the peer list,don't forward it
if (SrsForwarder::check_dead_loop(req, forward_server)) {//if the source is from any of the peer list,don't forward it
srs_trace("the source is come from forward_peer,don't forward it any more: "
"vhost=%s, app=%s, stream=%s, forward-to=%s",
_req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(),
... ... @@ -2470,7 +2470,7 @@ int SrsSource::create_forwarders()
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
std::string forward_server = conf->args.at(i);
if (SrsForwarder::check_dead_loop(_req, forward_server)) {
if (SrsForwarder::check_dead_loop(req, forward_server)) {
srs_trace("start forward,dead loop checked,don't forward it: "
"vhost=%s, app=%s, stream=%s, forward-to=%s",
_req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(),
... ... @@ -2519,7 +2519,7 @@ int SrsSource::create_forwarders()
std::string forward_server = conf->args.at(server_index);
server_index ++;
if (SrsForwarder::check_dead_loop(_req, forward_server)) {
if (SrsForwarder::check_dead_loop(req, forward_server)) {
srs_trace("start forward_in_turn,dead loop checked,don't forward it: "
"vhost=%s, app=%s, stream=%s, forward-to=%s",
_req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(),
... ...
... ... @@ -571,7 +571,7 @@ public:
* @param _req the request from client, the source will deep copy it,
* for when reload the request of client maybe invalid.
*/
virtual int on_publish();
virtual int on_publish(SrsRequest* req);
virtual void on_unpublish();
// consumer methods
public:
... ... @@ -598,7 +598,7 @@ public:
// for edge, proxy stop publish
virtual void on_edge_proxy_unpublish();
private:
virtual int create_forwarders();
virtual int create_forwarders(SrsRequest* req);
virtual void destroy_forwarders();
};
... ...
... ... @@ -1765,11 +1765,6 @@ void SrsRequest::update_auth(SrsRequest* req)
swfUrl = req->swfUrl;
tcUrl = req->tcUrl;
vhost = req->vhost;
app = req->app;
param = req->param;
port = req->port;
if (args) {
srs_freep(args);
}
... ...