Requirements

Prerequisite knowledge
You should have basic knowledge of Adobe Media Server and RTMFP.
 
User level
Intermediate

In this article, I review how to publish a VOD file into multicast groups and then playback the same as a multicast stream. Normally, the multicast solution delivers a single, live stream to Flash Player clients over IP multicast, P2P multicast, or a combination of both (called fusion multicast).

Flash Player 10 and AIR 1.5 (and later) support Real-Time Media Flow Protocol (RTMFP). To multicast VOD assets, you need to publish VOD file from Adobe Media Server into RTMFP groups, which is equivalent to a live scenario and then playback the stream being published.

To play a stream over RTMFP, a client must know the name of the stream and know the peer ID of the publisher. The peer ID is a 256-bit value associated with the publisher's identity. The publisher must accept a peer request before a connection is made.

Note: NetConnection protocol must be rtmfp for NetConnection.connect() if the groupspec parameter is present while creating the NetStream object for playing back the multicast stream.

Publish VOD file from AMS into RTMFP Groups

For this, you can create a server-side app, which will do server-side publish to a multicast group. Here is a code example of how to do that:

 

application.onNC=function(){ nc=new NetConnection(); nc.onStatus = onNCStatus; nc.connect("rtmp://localhost/multicast"); } function onNCStatus(evt){ trace("NetConnection "+evt.code); if(evt.code=="NetConnection.Connect.Success"){ streamObj=Stream.get("foo"); streamObj.onStatus = onStreamStatus; switch(streamname.split(".")[1]){ case "mp4": case "3gp": case "f4v": streamPlayName="mp4:"+streamname; break; case "mp3": streamPlayName="mp3:"+streamname.split(".")[0]; break; case "flv": streamPlayName=streamname.split(".")[0]; break; } trace(streamPlayName); streamObj.play(streamPlayName); }else{ trace("Error: "+evt.code); } } function onStreamStatus(info){ trace("Stream "+info.code); if(info.code=="NetStream.Play.Start"){ gs = new GroupSpecifier("discovery-test"); // Must be enabled for LAN peer discovery to work gs.ipMulticastMemberUpdatesEnabled = true; // Multicast address over which to exchange peer discovery. gs.addIPMulticastAddress("224.0.0.254:30000"); // Necessary to multicast over a NetStream. gs.multicastEnabled = true; ns=new NetStream(nc); ns.onStatus=function(obj){ trace("NetStream "+obj.code); } ns.attach(streamObj); ns.publish(streamname.split(".")[0]+"?fms.multicast.type=1&fms.multicast.groupspec="+gs.toString()+"&fms.multicast.address=224.0.0.254%3A30000"); } }

Note in the above code with NetStream.publish() method, I am passing three parameters as a query string.

  • fms.multicast.type
  • fms.multicast.groupspec
  • fms.multicast.address

Following are the values for fms.multicast.type for different multicast types for publishing onto a multicast app:

  • Fusion: 1
  • IP Multicast: 2
  • Peer to Peer: 3
  • P2P with Peer Discovery: 3

 

Playback the VOD stream which is being published as multicast stream

For playing back the VOD stream being published, you need to know the GroupSpecifier, the multicast stream name by which the stream is getting published, the Multicast type, etc. You can know this by connecting to the same server-side app which is publishing and calling a server side function. This will return the GroupSpecifier string, the stream name, and other required params. Then you can playback by connecting to the NetGroup using the GroupSpecifier. The following code is an example of how to do that.

function connectRTMFP():void{ nc = new NetConnection(); var clientObj:Object = {}; nc.client = clientObj; nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); //For IP Multicast, the multicast url is “rtmfp:” nc.connect("rtmfp://<server-ip>/multicast"); } function netStatusHandler(evt:NetStatusEvent):void{ switch(evt.info.code) { case "NetConnection.Connect.Success": { formNetGroup(); break; } case "NetGroup.Connect.Success": { playStream(); break; } case "NetGroup.Connect.Rejected": { trace("Peer Assisted Networking is required.\n" + "Please reload this page and select \"Allow\" "+ " when prompted.", ""); break; } default: { break; } } } function formNetGroup():void{ ng = new NetGroup(nc, groupspec); ng.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); // wait for NetGroup.Connect.Success before moving foward in case user declines } function playStream():void{ ns = new NetStream(nc, groupspec); ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); // typical status handlers in a NetStream, set defaults to suppress errors var co:Object = {}; co.onPlayStatus = function(...rest):void {} co.onMetaData = function(...rest):void {} co.onXMPData = function(...rest):void {} co.onFI = function(...rest):void {} ns.client = co; ns.play(streamName); ns.bufferTime = Number(bufferTime);

 

Where to go from here

To learn more about the multicast APIs, you can read the Adobe Media Server client and server-side Action Script APIs.


More Like This