Multicast Explained in Flash 10.1 P2P

Multicast is one of the features of Flash Player 10.1 and it enables you to distribute NetStreams across the peer-to-peer mesh. It can be audio, video or even pure data stream (AMF3) – the data stream can be very handy for games, it’s much better for such purpose (like sending realtime positions, directions) than using Posting as Posting is more optimized for large number of senders to send something – like chat, status change and so on.

Difference between Unicast and Multicast

Unicast
Unicast simply delivers streams from a server to n clients. For this purpose you can use Flash Media Server and TCP protocols such as RTMP/T/S/E or HTTP protocol. Unicast also costs you a lot of resources -> 1 MBps stream delivered to 1000 clients means 1 GB upstream from server – which is CPU demanding and network transit is also huge.
unicast2


Application Level Multicast
Sometimes called P2P Multicast is an optimized stream distribution among peers. It’s very cost effective as the stream is distributed among peers. You can either distribute stream from a client or FMS (with the future release).
Multicast in Flash

Native IP Multicast
This one is distributed over the network not using P2P connection, but using network routing capabilities. It mostly works in internal, enterprise, VPN or LAN networks – basically in closed networks, which supports that. You can combine Native IP Multicast with Application Level Multicast to deliver combined solution called Multicast Fusion. This feature need Flash Media Server (next generation version). We will cover this feature once the new FMS is available.
Multicast Fusion with Flash

Developing Multicast in Flash

We are going to build two applications, one is going to be a receiver and one broadcaster.

Once you get connected to Cirrus or FMS. You need to setup the NetStream – same way like NetGroup (checkSimple Chat using NetGroup tutorial).

My group is called “myGroup/multicastOne” and I am streaming stream “multicast”. You can define whatever names you want.

Broadcaster app (see whole source-code Broadcaster.mxml):

private function setupStream():void{
	var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne");
	groupspec.serverChannelEnabled = true;
	groupspec.multicastEnabled = true;
 
	stream = new NetStream(nc, groupspec.groupspecWithAuthorizations());
	stream.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
 
	var cam:Camera = Camera.getCamera();
	video.attachCamera(cam);
 
	stream.attachCamera(cam);
	stream.publish("multicast");				
}

Receiver app (see whole source-code Receiver.mxml):

private function setupStream():void{
	var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne");
	groupspec.serverChannelEnabled = true;
	groupspec.multicastEnabled = true;
 
	stream = new NetStream(nc, groupspec.groupspecWithAuthorizations());
	stream.addEventListener(NetStatusEvent.NET_STATUS,netStatus);
 
	stream.play("multicast");
 
	video.attachNetStream(stream);
}

Watch: Developing Multicast Streaming in Flash Player 10.1 (Videotutorial)

Okay, but how can I stream from Flash Media Live Encoder. For this purpose you will need to get next generation of Flash Media Server. Once it’s available – I will write a tutorial how you can use it.

Packet distribution in Multicast

Multicast in Flash is optimized to be efficient. It works the way that you don’t upstream whole stream you received – you could do that – but you rather upstream only couple chunks that fits your network possibilities. Most of the normal DSL lines have around 8mbps download and 1mbps upload or more – so are able to receive 2mbps, but distribute only 1mbps (in optimal situation), so you would need more peers for further distribution, which would combine packets together.

Multicast in Flash is a Pull/Push system. Pull ensures to deliver the data to the peers. Push optimize the mesh, reduce latency and create multiple spanning trees. If there were only Pull, the latency of the live stream on the furthest peer would be too big. Push solves that.

Pull

There are these steps:

  1. Once you start distributing stream you send a map of blocks to one (or all) neighbor(s)
  2. Neighbor waits a short time to see who can source each block

    Multicast in Flash - Pull - Map of Blocks

  3. Neighbor picks you to send some of the blocks and sends request

    Multicast Flash - Pull 2

  4. Send requested blocks to neighbor
  5. All transmissions are partially-reliable
  6. Neighbor will ask someone else if requestgoes unfulfilled

    multicast flash pull 3

Pull then works this way:
multicastpullanimation1

Push

  1. Send map of what blocks you have to one (or all) neighbor(s)
  2. Neighbor notices that data is flowing
  3. Neighbor picks candidate sources for each sequence number slice
  4. Neighbor sends mask describing which sequence numbers to push
  5. Modulo size of mask (in this example every 3rd, 5th, and 6th)
  6. Periodically tests other neighbors to check for lower latency
  7. For each sequence number slice, keeps just quickest source
  8. Data is pushed immediately as it arrives for requested slices
  9. For each slice, there is a limit to the number of push clients served

Push then works this way
Multicast Push Flash

Push/Pull
By combining two above, you get effective/optimized multicast distribution, which can be illustrated like this:

multicast pull/push animation

Conclusion

For Multicast in Flash we use NetStream class together with GroupSpecifier and NetConnection. Multicast is the most complicated thing in Flash P2P implementation and it’s very intelligent in optimizing the delivery, chunk distribution and mesh reforming. We have three types of multicast: P2P, IP and Fusion (P2P+IP). Multicast is available with Adobe Cirrus and more will be available with new FMS.

Adobe TV resources:
- Watch the session about P2P from MAX 2009 explaining multicast by Matthew Kaufman(Seek to 36:28)
- Videotutorial: Developing Multicast Streaming in Flash Player 10.1

In the next tutorial I will explain how QoS and monitoring with multicast works.

Stay tuned for more!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值