Method
Use the ProxyStream class to build large-scale applications that use DVR functionality. DVR functionality lets users pause live video and resume playback from the paused location. Users can rewind and play recorded sections of the video and seek forward to catch up again.
To scale applications, use server-side NetConnection objects to create a chain of servers. In such a scenario, all the servers run as local servers. To explain this scenario, the ingest servers at the top layer are called origin servers, servers in the middle layer are called intermediate servers, and the servers on the bottom layer (which serve subscribers) are called edge servers.
note: The terms “origin” and “edge” in this scenario do not refer to local and remote operation (see the Proxy section of the Vhost.xml configuration file). All servers in this scenario run in local mode.
Only the server controlled by the publisher records streams. Servers further down the chain, closer to subscribers, do not record the stream and do not have the stream available for playback. If a recorded stream does not exist on a server, subscribers cannot access it. Use the ProxyStream class to pull segments of recorded streams from another server where the segments are available. Call ProxyStream.proxyFrom() to line up an intermediate server with an origin server. When a recorded stream is requested in the intermediate server, it automatically pulls the required segment down from the origin server. The segment is stored in the memory cache of the intermediate server just as segments are stored in the origin server. Every subscriber going through the intermediate server gets the data directly from the cache so that segments can be shared across multiple clients. Set up an edge server to pull data from an intermediate server, which pulls data from the origin server when necessary. It’s a good idea to code your application so that when streams are idle they failover to a different source.
No disk usage is required in the intermediate and edge server. File segments that have been pulled from another server are stored in the memory cache. The server uses an LRU (Least Recently Used) scheme to maintain the cache. The server pushes older segments out of the cache when the memory reaches a value that you can configure. To save bandwidth and improve performance, the server can also save segments in the memory on disk. You can configure the location of the cache directory, and the maximum size of the cache.
Availability
Flash Media Server 3.5
Method summary
|
Description |
Proxies a stream from one Adobe Media Server to another over a NetConnection. |
|
Stops proxying a stream. |
Event handler summary
Event handler |
Description |
Called every time a status change or error occurs in a ProxyStream object. |
ProxyStream constructor
new ProxyStream(connection)
Creates an instance of the ProxyStream class.
Availability
Flash Media Server 3.5.
Parameters
connection
A NetConnection object.
Returns
A ProxyStream object.
Example
The following example creates an instance of the ProxyStream class:
nc = new NetConnection(); nc.connect("rtmp://amsexample.adobe.com/testapp"); nc.onStatus(info){ if(info.code == "NetConnection.Connect.Success"){ ps = new ProxyStream(nc); // Use ps.onStatus to check status } };
ProxyStream.onStatus()
ps.onStatus = function(infoObject){})
Called every time a status change or error occurs in a ProxyStream object.
Availability
Flash Media Server 3.5
Parameters
infoObject
An Object with code and level properties that provide information about the status of a ProxyStream object. Both properties are strings.
Code property |
Level property |
Description |
---|---|---|
ProxyStream.Proxy.Start |
status |
Successfully published the source stream. |
ProxyStream.Proxy.Stop |
status |
Successfully stopped the source stream. |
ProxyStream.Proxy.BadName |
error |
The publish attempt failed because the local name was invalid or exists. |
Example
nc = new NetConnection; nc.onStatus = function(info) { if (info.code == "NetConnection.Connect.Success"){ // Create a proxy to the remote stream "remoteStream" // This stream is published locally as "localStream" ps = new ProxyStream(nc); ps.onStatus = function(info) { if (info.code == "ProxyStream.Proxy.Start") { // The local stream was published. } else if (info.code == "ProxyStream.Proxy.Stop") { // The local stream was stopped. } else if (info.code == "ProxyStream.Proxy.BadName") { // The publish failed because the local name was invalid // or existed. } }; ps.proxyFrom("localStream", "remoteStream"); } }; nc.connect("rtmp://origin.mydvr.com/dvr");
The following example uses two origin connections, primaryURI and backupURI to demonstrate failover:
var primaryUri = "rtmp://primary/app"; var backupUri = "rtmp://backup//app"; function createNetConn(uri){ _root.netConn = new NetConnection(); _root.netConn.onStatus = function(info) { if (info.code == "NetConnection.Connect.Success"){ // Connection is good, create the ProxyStream createProxyStream(); } else if (info.code == "NetConnection.Proxy.NotResponding" || info.code == "NetConnection.Connect.Closed") { // The proxy isn't responding to our requests, or the connection was closed, // so switch to an alternate origin... var nextUri; if (uri == primaryUri){ nextUri = backupUri; } else { nextUri = primaryUri; } createNetConn(nextUri); } }; _root.netConn.connect(uri); } function createProxyStream() { _root.ps = new ProxyStream(_root.netConn); _root.ps.onStatus = function(info) { // Handle ProxyStream status notifications }; _root.ps.proxyFrom("localStream", "remoteStream"); } createNetConn(primaryUri);
ProxyStream.proxyFrom()
ps.proxyFrom(local, remote)
Proxies a stream from one Adobe Media Server to another over a NetConnection. The stream can be live, recorded, or both.
Availability
Flash Media Server 3.5
Parameters
local
A string specifying a local stream name.
remote
A string specifying a remote stream name.
ProxyStream.stop()
ps.stop()
Stops proxying a stream.
Availability
Flash Media Server 3.5
Parameters
None.