采用该技术,能large-scale你的直播系统,结构如图所示:
A. Live Video B. Server 1 (New York City) C. Server 2 (Chicago) and Server 3 (Los Angeles) D. Users
1.客户端代码:ns.publish("localnews", "live");
2.LiveVideo代码:
// Called when the client publishes
application.onPublish = function(client, myStream) {
trace(myStream.name + " is publishing into application " + application.name);
// This is an example of using the multi-point publish feature to republish
// streams to another application instance on the local server.
if (application.name == "livestreams/_definst_"){
trace("Republishing the stream into livestreams/anotherinstance");
nc = new NetConnection();
nc.connect( "rtmp://localhost/livestreams/anotherinstance" );
ns = new NetStream(nc);
// called when the server NetStream object has a status
ns.onStatus = function(info) {
trace("Stream Status: " + info.code)
if (info.code == "NetStream.Publish.Start") {
trace("The stream is now publishing");
}
}
ns.setBufferTime(2);
ns.attach(myStream);
ns.publish( myStream.name, "live" );
}
}
ns.onStatus = function(info) {
trace("Stream Status: " + info.code)
if (info.code == "NetStream.Publish.Start") {
trace("The stream is now publishing");
}
}
application.onUnpublish = function( client, myStream ) {
trace(myStream.name + " is unpublishing" );
}
3.Server1 和 Server2采用正常服务器流程
需要说明的是,FMS分为FMSS/FMIS/FMES/FMDS,FMSS因为不能配置成edge服务器,不适合提供运营级别的高性能/高分布的视频应用方案FMIS/FMES/FMDS除了都能配置成edge服务器外,还是有些区别的,FMDS是试用版本,有10个连接数的现在,FMES除了具备FMIS功能外,还多了P2P的功能;通过edge服务器,用户连接到的是edge服务器,而不是origin服务器,Edge分为是聚合大量的来自客户端的请求,并发送到源服务器,这样可以将负载的请求连接分布化,保证了流媒体高并发情况下的带宽及系统资源分配合理性,他管理连接,缓存内容,推送数据到客户端,文件缓存在edge端,降低了访问源服务器文件存储的需求量,突破了大规模视频应用的服务器瓶颈
上述的结构解决了S->C的问题,C->S的问题是需要采用Edge服务器,就要对Edge服务器进行配置,修改<RootInstall>/conf/_defaultRoot_/_defaultVHost_/Vhost.xml中的Mode/Anonymous/CacheDir/LocalAddress/RouteTable/RouteEntry;比如有以下两个服务器:
Edge服务器为edge1.adobe.com
Origin服务器为fms.adobe.com
Client连接Edge服务器就可以采用以下两中方式:
1).Explicit显式:Anonymous字段为false,直接将edgeURL作为originURL的前缀
rtmp://edge1.adobe.com/?rtmp://fms.adobe.com/app/instance
2).Implicit隐式:Anonymous字段为true,修改RouteTable/RouteEntry值为Edge/Origin的IP和Port
<RouteTable protocol="">
<RouteEntry>edge1.adobe.com:*;fms.adobe.com:1935</RouteEntry>
</RouteTable>
如果是多级就以此类推,比如Edge1->Edge2->Origin,注意哥没写错
<RouteEntry>edge1.adobe.com:*;edge2.adobe.com:1935</RouteEntry>
<RouteEntry>edge1.adobe.com:*;fms.adobe.com:1935</RouteEntry>