胡斌

add conf directive forward_append_stream_name,to support add ?vhost=xxxx to stre…

…am name when forward to cdn
# the config for srs to forward
# the cwrd_stream_name_appendnfig for srs to forward
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleForward
# @see full.conf for detail config.
... ... @@ -16,4 +16,6 @@ vhost __defaultVhost__ {
#if the forward server is same as this server , a origin,try use forward_peer,
#the stream pushed from other forward peer will not forward any more in this server
forward_peer 127.0.0.1:1936;
#append the string after start with ? to the stream name when forward to the server
forward_append_stream_name 127.0.0.1:19350?vhost=newrtmp.xuedianyun.com
}
... ...
... ... @@ -1832,7 +1832,8 @@ 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_other" && n != "forward_in_turn" && n != "forward_peer" && n != "transcode" && n != "bandcheck"
&& n != "forward" && n != "transcode" && n != "bandcheck"
&& n != "forward_server_other" && n != "forward_in_turn" && n != "forward_peer" && n != "forward_append_stream_name"
&& n != "time_jitter" && n != "mix_correct"
&& n != "atc" && n != "atc_auto"
&& n != "debug_srs_upnode"
... ... @@ -2816,6 +2817,17 @@ SrsConfDirective* SrsConfig::get_forward_in_turn(string vhost)
return conf->get("forward_in_turn");
}
SrsConfDirective* SrsConfig::get_forward_append_stream_name(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("forward_append_stream_name");
}
SrsConfDirective* SrsConfig::get_forward_peer(string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ...
... ... @@ -581,6 +581,10 @@ public:
* get the forward_peer directive of vhost.
*/
virtual SrsConfDirective* get_forward_peer(std::string vhost);
/**
* get the forward_append_stream_name directive of vhost.
*/
virtual SrsConfDirective* get_forward_append_stream_name(std::string vhost);
// http_hooks section
private:
/**
... ...
... ... @@ -138,6 +138,16 @@ int SrsForwarder::initialize(SrsRequest* req, string ep_forward)
}
}
size_t ep_len = ep_forward.length();
conf = _srs_config->get_forward_append_stream_name(_req->vhost);
for (int i = 0; conf && i < (int)conf->args.size(); i++) {
std::string forward_append_stream_name = conf->args.at(i);
if(forward_append_stream_name.length() > ep_len && forward_append_stream_name.at(ep_len)=='?' && !strncmp(ep_forward.c_str(),forward_append_stream_name.c_str(),ep_len)){
_steam_name_appender = forward_append_stream_name.substr(ep_len, forward_append_stream_name.length());
break;
}
}
return ret;
}
... ... @@ -300,7 +310,7 @@ int SrsForwarder::cycle()
return ret;
}
if ((ret = client->publish(_req->stream, stream_id)) != ERROR_SUCCESS) {
if ((ret = client->publish(_req->stream + _steam_name_appender, stream_id)) != ERROR_SUCCESS) {
srs_error("connect with server failed, stream_name=%s, stream_id=%d. ret=%d",
_req->stream.c_str(), stream_id, ret);
return ret;
... ...
... ... @@ -55,6 +55,8 @@ private:
std::string _ep_forward;
SrsRequest* _req;
int stream_id;
// the string append to stream name ,such as "?vhost=newrtmp.xuedianyun.com" for rtmp://video-center.alivecdn.com/live/test?vhost=newrtmp.xuedianyun.com
std::string _steam_name_appender;
private:
st_netfd_t stfd;
SrsReusableThread2* pthread;
... ...