srs_error_t SrsRtmpConn::acquire_publish(SrsSource* source)
{
srs_error_t err = srs_success;
SrsRequest* req = info->req;
if (!source->can_publish(info->edge)) {
return srs_error_new(ERROR_SYSTEM_STREAM_BUSY, "rtmp: stream %s is busy", req->get_stream_url().c_str());
}
// 边缘节点和核心节点完全的程序分支!
if (info->edge) {
if ((err = source->on_edge_start_publish()) != srs_success) {
return srs_error_wrap(err, "rtmp: edge start publish");
}
} else {
if ((err = source->on_publish()) != srs_success) {
return srs_error_wrap(err, "rtmp: source publish");
}
}
return err;
}
怎么判定是不是edge呢?info->edge这个值。
bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
{
static bool DEFAULT = false;
SrsConfDirective* conf = vhost;
if (!conf) {
return DEFAULT;
}
conf = conf->get("cluster");
if (!conf) {
return DEFAULT;
}
conf = conf->get("mode");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}
return "remote" == conf->arg0();
}
edge.conf
listen 1935;
max_connections 1000;
pid objs/edge.pid;
daemon off;
srs_log_tank console;
vhost __defaultVhost__ {
cluster {
mode remote;
origin 127.0.0.1:1935;
}
// 增加forward配置。但目前程序只会处理上面的edge配置。
forward {
enabled on;
destination 127.0.0.1:1936;
}
}
client(edge)做publish就一种情形:上行加速,直接forward到源站去。
// @see https://github.com/ossrs/srs/issues/180
// to avoid multiple publish the same stream on the same edge,
// directly enter the publish stage.
if (true) {
SrsEdgeState pstate = state;
state = SrsEdgeStatePublish;
srs_trace("edge change from %d to state %d (push).", pstate, state);
}
把info->edge这个业务逻辑处理一下,应该就可以支持了。