胡斌

add config directive forward_in_turn to support forward streams to one of the server

in forward_in_turn list in turn
... ... @@ -9,6 +9,8 @@ daemon off;
srs_log_tank console;
vhost __defaultVhost__ {
forward 127.0.0.1:19350;
#select on of the listed servers in turn to forward,not all of them
forward_in_turn 127.0.0.1:19351 127.0.0.1:19352;
#the forward destination server type,default true. if the server is not srs server,connect app maybe fail,try config as false
forward_server_srs true;
}
... ...
... ... @@ -1823,7 +1823,7 @@ int SrsConfig::check_config()
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
&& n != "gop_cache" && n != "queue_length"
&& n != "refer" && n != "refer_publish" && n != "refer_play"
&& n != "forward" && n != "forward_server_srs" && n != "transcode" && n != "bandcheck"
&& n != "forward" && n != "forward_server_srs" && n != "forward_in_turn" && n != "transcode" && n != "bandcheck"
&& n != "time_jitter" && n != "mix_correct"
&& n != "atc" && n != "atc_auto"
&& n != "debug_srs_upnode"
... ... @@ -2772,6 +2772,17 @@ bool SrsConfig::get_forward_server_srs(string vhost)
return conf->arg0()=="true";
}
SrsConfDirective* SrsConfig::get_forward_in_turn(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward_in_turn");
}
SrsConfDirective* SrsConfig::get_vhost_http_hooks(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ...
... ... @@ -573,6 +573,10 @@ public:
* get the forward server type of vhost,if srs return true,else false.
*/
virtual bool get_forward_server_srs(std::string vhost);
/**
* get the forward_in_turn directive of vhost.
*/
virtual SrsConfDirective* get_forward_in_turn(std::string vhost);
// http_hooks section
private:
/**
... ...
... ... @@ -2448,6 +2448,44 @@ int SrsSource::create_forwarders()
}
}
//forward a server in forward_in_turn
static int server_index = 0;
conf = _srs_config->get_forward_in_turn(_req->vhost);
if(!conf){
return ret;
}
int servers_size = (int)conf->args.size();
if(servers_size <= 0){
return ret;
}
if(server_index >= servers_size){
server_index = 0;
}
std::string forward_server = conf->args.at(server_index);
server_index ++;
SrsForwarder* forwarder = new SrsForwarder(this);
forwarders.push_back(forwarder);
// initialize the forwarder with request.
if ((ret = forwarder->initialize(_req, forward_server)) != ERROR_SUCCESS) {
return ret;
}
double queue_size = _srs_config->get_queue_length(_req->vhost);
forwarder->set_queue_size(queue_size);
if ((ret = forwarder->on_publish()) != ERROR_SUCCESS) {
srs_error("start forwarder failed. "
"vhost=%s, app=%s, stream=%s, forward-to=%s",
_req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(),
forward_server.c_str());
return ret;
}
return ret;
}
... ...