flashplayer 10 的 p2p 基础
原文地址:http://www.adobe.com/devnet/flashplayer/articles/rtmfp_cirrus_app.html Adobe Flash Player 10 and Adobe AIR 1.5 introduce a new communications protocol,Real-Time Media Flow Protocol (RTMFP),whose low latency,end-to-end peering capability,security,and scalability make it especially well suited for developing real-time collaboration applications by not only providing superior user experience but also reducing operators' costs. Earlier versions of Flash Player use Real-Time Messaging Protocol (RTMP) and require Adobe Flash Media Server (FMS) for interactive collaboration applications (such as Adobe Acrobat Connect Pro) or audio/video streaming. While RTMP is an excellent choice for streaming media,shared objects,or remoting,it has limited ability of meeting real-time requirements of interactive audio and video communications. In order to use RTMFP,Flash Player endpoints must connect to an RTMFP-capable server,such as the Codename Cirrus (previously Codename Stratus) service or Flash Media Server 4. Cirrus is a hosted rendezvous service that aids establishing communications between Flash Player endpoints. Unlike FMS,Cirrus does not support media relay,scripting,etc. So by using Cirrus,you can develop applications only where Flash Player endpoints are directly communicating with one another. Flash Player is already the market leader in online video distribution over the web. With the introduction of RTMFP and advanced media compression technologies,Flash Player 10 is well positioned as the leader in real-time communications as well. In this article,I first highlight the benefits of using RTMFP in real-time communications applications. Second,I describe the new ActionScript 3 API for managing direct end-to-end RTMFP connections. Finally,I present our VideoPhone sample application. Benefits of RTMFPReal-Time Media Flow Protocol (RTMFP) is a new communications protocol introduced in Flash Player 10 and also available in AIR 1.5. One of its major differentiators from Real-Time Messaging Protocol (RTMP),which is based on the Transmission Control Protocol (TCP) and exclusively used in previous versions of Flash Player,is that RTMFP is built on User Datagram Protocol (UDP). While TCP provides reliable data delivery (well applicable for file transfer,e-mail,etc.),it does not provide any end-to-end delay guarantees. Reliable data transmission in TCP is achieved by re-transmission of lost data,which introduces latency. Because minimizing end-to-end delay is one of the most important goals in real-time communications (a few hundred milliseconds' delay may render a conversation unusable),TCP is not well suited for this purpose. Transmission error resilience and recovery form an integral part of most advanced audio and video compression techniques—such as Speex audio and H.264 video codec,both available in Flash Player 10. Reliable delivery provided by TCP is therefore not needed. As a result,UDP,which provides an efficient and rapid data delivery,is popularly used in real-time collaboration applications where minimizing end-to-end delay is of paramount importance. Another advantage of UDP over TCP that it enables end-to-end peering—that is,direct data transmission between two clients located behind network address translators (NATs). When compared to RTMP,RTMFP provides the following advantages for real-time communications:
All of these features represent tremendous benefits for real-time communications,providing a significantly greater user experience than is achievable with earlier versions of Flash Player. Firewall traversalRTMFP is built on top of UDP,which enables direct connection between clients even if they are located behind NATs or firewalls. In order for RTMFP to work,your firewall must be configured to allow outgoing UDP traffic. While this is the case with most consumer or small office/home office (SOHO) firewalls,many corporate firewalls block UDP traffic altogether. One solution is to configure Flash Player to use a TURN proxy (Traversal Using Relays around NAT). Flash Player supports IETF Internet Draft RTMFPTURNProxy=ip_address_or_hostname_of_TURN_proxy
Direct UDP traffic is always attempted and the TURN proxy is only used as a backup: it is used for UDP traffic that cannot flow between Flash Player and Cirrus (in case of UDP blocking firewall) or between Flash Player endpoints. Even if your firewall enables outgoing UDP traffic,it is possible that end-to-end peering cannot be established due to a combination of firewalls. When one endpoint is located behind a so-called "symmetric firewall," end-to-end communications may not be possible. (For a classification of firewalls,please see the Network address translation entry on Wikipedia.) In this situation,you may use a TURN proxy to aid firewall traversal. Cirrus serviceFlash Player instances must connect to the Cirrus service (using RTMFP support is available in Flash Media Server 4. With Flash Media Server,it will be possible to enable communications between Flash Player 9 or earlier clients (using RTMP) and Flash Player 10 clients (using RTMFP). SecurityRTMFP provides secure communications between endpoints. It uses a 128-bit AES with the key negotiated using the Diffie-Hellmann key exchange method. However,it does not provide strong endpoint authentication such as SSL or RTMPS. To aid endpoint authentication,RTMFP and ActionScript expose secure nonces to application developers. These nonces are available at both communicating Flash Player endpoints and are guaranteed to match. By verifying these nonces,end users can ensure that there is no man-in-the-middle attack. These nonces can also be used to develop key continuity mechanism. It is important to note that Flash Player only enables sending media from your microphone and webcam devices to other Flash Player endpoints that subscribe to your media streams. ActionScript 3 API supporting RTMFPThere is a new ActionScript 3 API in Flash Player 10 to support RTMFP. Connecting to the Cirrus service and creating end-to-end media streams are analogous to working with Flash Media Server. Please note that you must use ActionScript 3 with either Flash Professional (CS4 or later) or Flash Builder 4 targeting Flash Player 10 or AIR 1.5. As I mentioned before,first you must connect to the Cirrus service: private const CirrusAddress:String = "rtmfp://p2p.rtmfp.net";private const DeveloperKey:String = "your-developer-key";private var netConnection:NetConnection; netConnection = new NetConnection();netConnection.addEventListener(NetStatusEvent.NET_STATUS,netConnectionHandler);netConnection.connect(CirrusAddress,DeveloperKey);
The developer key is issued when you sign up for an Adobe Developer Connection account and is available on the Cirrus beta service site. Upon successful connection to Cirrus,you get a After successfully establishing a connection to the Cirrus service,you are assigned a unique 256-bit peer ID ( Direct communications between Flash Player instances is conducted using unidirectional First,create a sending private var sendStream:NetStream; sendStream = new NetStream(netConnection,NetStream.DIRECT_CONNECTIONS);sendStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);sendStream.publish("media");sendStream.attachAudio(Microphone.getMicrophone());sendStream.attachCamera(Camera.getCamera());
This means that Note: Audio/video is not sent out until another Flash Player endpoint subscribes to your Now,create the receiving private var recvStream:NetStream; recvStream = new NetStream(netConnection,id_of_publishing_client);recvStream.addEventListener(NetStatusEvent.NET_STATUS,netStreamHandler);recvStream.play("media");
At this point,you hear audio and you can create a Advanced topicsThe publisher has fine control over which endpoint can receive its published stream. When a subscriber attempts to receive a published stream,the var o:Object = new Object();o.onPeerConnect = function(subscriberStream:NetStream):Boolean{ if (accept) { return true; } else { return false; }}sendStream.client = o;
On the publisher side,the sendStream.peerStreams[i].send()
The
Figure 1. End-to-end connections using the Cirrus service
The Exploring the Video Phone sample applicationWe have developed a sample video phone application for illustrating how to use end-to-end capabilities of Flash Player 10. It is also available as part of this article. The Video Phone sample application relies on a simple HTTP service to exchange the Flash Player peer ID. The script is provided as part of the package,reg.cgi. This web service does not provide any user authentication. After Flash Player successfully connects to Cirrus,it registers its peer ID with the web service. When making a call,the Video Phone caller uses this web service to look up recipient's peer ID. Adobe runs this web service exclusively for the hosted Video Phone sample. When you build your own Video Phone sample,you must run your own web service and specify The following steps are necessary to build a Video Phone sample application—for more details,please see ReadMe.txt included in the package:
The Video Phone sample application uses the phone model. The call control procedure is implemented using the newly added Cirrus message passing capability. Client A sends an "Invite" message to client B through Cirrus service and publishes the media stream. Client B learns the caller's remote ID and username from the incoming "Invite" message and prompts the user to accept or reject the call. If Client B accepts the call,it sends an "Accept" message through Cirrus service,subscribes to Client A's media stream,and publishes the media streams. When Client A receives the "Accept" message,it subscribes to Client B's media stream and two-way communications is established. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |