安装好red5 windows安装后,为什么进入安装demo的页面,显示可选demo的列表为空

Category ArchiveRed5
& GgNET on 29 十二 2010
2.1 挑战FMS
在介绍RED5之前,有必要先介绍一下Flash Media Server:
Flash Media Server,简称FMS,是Flash大家庭里的一员,被称为是目前开发Web音视频应用程序(比如,视频聊天室、视频会议系统、播客系统、音视频留言等等)的最方便最快捷的解决方案。也在web应用程序开发上有着越来越广泛的应用。
典型应用:YouTube、土豆网
FMS如此的优良功能当然并不是免费提供给广大用户的,几千美金每个点的价格让很多开发人员望而却步。于是,开源的Red5成为人们的新宠。
2.2 RED5-穷人的流媒体服务器
Red5是一个采用Java开发的开源的Flash流媒体服务器,功能上与FMS类似。它支持:
把音频(MP3)和视频(FLV)转换成播放流;
录制客户端播放流(只支持FLV);
共享对象;
现场直播流发布;
远程调用。
Red5使用RSTP作为流媒体传输协议,在其自带的一些示例中实现了
flash流媒体播放
2.3 RED5中的几个个重要概念和模型
2.3.1 scope
Red5中,所有资源形成一颗树,每一个节点被称为scope,如果该节点是个叶子节点,那它被称为BasicScope,如果该节点还有子节点,那它被 称为Scope。
Red5里有两种预先定义好的BasicScope:SharedObject Scope和BroadcastStream Scope。
每一个应用都有自己的Scope等级体系,根就是WebScope(即此应用的实例)。Red5定义了一个全局scope意在提供一个通用的资源供各个应 用共享,称之为GlobalScope。GlobalScope是所有的WebScope的父节点,其余的中间scopes都是Scope的实例。每一个 scope有一个名称。GlobalScope的名称是:default。每一个WebScope的名字就是该应用上下文的名称。中间的Scope的名字 就是它所在路径的名称。SharedObject Scope的名字就是SharedOjbect的名字,BroadcastStream Scope的名字就是Stream的名字。
除了GlobalScope和BasicScopes外,其余scope都可以被一个client连接。一个客户端请求连接的结果会被用来创建一个 Scop对象.例如:一个客户端请求一个连接来连oflaDemo/room0,而此时room0的scope并未存在,当创建了这个连接后,room0 的scope被创建了,如果请求的url里包含了中间多个scope,所有的scope都会相应地被创建。比如:url为:oflaDemo/lobby0/room0,此时room0和lobby0都不存在,那他们都会被相应的创建,然后,连接指向了room0这个scope。
2.3.2 context
一个Context是和一个Scope对象绑定在一起的,它用来给scope object提供额外的功能.Context对象可以通过IContext.getScope()来获得.Context包装了spring的 application context,因此,spring里声明的各种bean在此都可以使用.
Context可以被继承.这就是说一个Scope可以继承它的父节点的Context而无需自己在定义一个context,只有GlobalScope和WebScope必须使用它们自己的Context对象.
“Scopes ”和“Contexts”是开发red5重要概念。
每个application 在Red5中 仅仅只有一个 Context。 Context 类实现了接口 IContext。 context 实例对象由Java Spring framework 初始化,它提供作用路径映射和不同服务接口。每个application只有一个context 和一个WebScope,WebScope 的名称和 context 的路径配置相关,它们名称虽相同但意义不同。
2.3.3 application
利用red5创建的任何应用常常都和“application”有关,applications 是建立在flash 客户端和red5 服务之间以任何形式交互的基础和基本概念。术语 “application” 来源于 Flash Media Server (FMS), Adobe 研发用于和 flash 客户端通信的软件。 red5 使用更复杂模式来处理flash 客户端的请求,red5 使用类似于搭积木组合方式来模拟 FMS
的application“ 概念;简而言之,如你在red 创建以一个 “application” ,那么同时创建了 一个WebScope
( scope 的一种)、一个 Context 和一个 handler。
树的根-RootScope-存在于所有的 applications 当中(所有的applications 都可以访问),RootScope 代码命名为 “default”,它是 类 GlobalScope 的一个实例主要为applications提供通用的共享资源。RootScope 隐含为其他 Scope 之上的 Scope,也就说不能被任何连接的客户端直接命名。
RootScope 直接下级 scope 是一系列特别的 scopes ,每一个 scope 代表了 red5 服务器运行的一个 application, 这些scope 命名和 application 上下文命名一致,这些scope 是类 WebScope 的一个实例,因为这些 scope 命名和 application 上下文命名一致导致很难区分它们,事实上他们是完全不同的两个东西。
WebScope 下面的节点,稍微有些不同,每一个 WebScope 被运行它的 red5服务器显示的定义; 每一个WebScope 拥有自己的配置文件,并且可以看做是独立的application。如果想创建 WebScope 作用域你需要在red5 下创建
application 目录和配置文件。在 WebScope 下创建指定的作用域,指定的作用域就会被动态的创建(如果指定作用域没有被创建)。例如,假如没有一个应用没有创建“myApp” 的作用域。某个 flash 客户端 连接到 “rtmp://red5serverHostname/myApp/aaa/bbb/ccc”
red5 会检查 “aaa” 是否已经存在,如果不存在就创建”aaa” 作用域,同理 “bbb” 和 “ccc”。
每一个WebScope
之下的动态作用域命名和给定的连接路径名称一致,例如上面的例子,作用域的名称分别是
‘aaa’, ‘bbb’, 和’ccc’ 。这些作用域 分别由 Scope 类 或者 BasicScope 类来实例化。没有子节点的叶子节点通常由 BasicScope 类实例化,非子节点由 Scope 类实例化。这些作用域都为flash 客户端提供功能调用,但是当flash 客户端连接到叶子域时,叶子域提供更有用的功能调用。例如,”ccc” 域可以提供在线流连接或者 “shared object” 连接,并允许多个flash客户端数据共享。
2.3.4 Handler
现在,我们有了如何让flash 客户端怎样去连接的scope 系统,有了来映射作用域请求的context,和服务应用代码。这些代码位于 Handler。
是red5 application 主要功能的实现,它实现了客户端连接和断开连接的方法,实现了客户端远程调用(RPC)的方法。
application 的初始化入口是从实例化WebScope
类开始的。当客户端连接这个application,red5 需要调用WebScope 类多个方法来初始化。因此 application’s handler 需要实现 IScopeHandler 接口 ,这个接口定义red5 必须要调用的方法。
handler 由这些开发red5应用的创建,通常也需要扩展 red5 已经实现的 ApplicationAdapter 类 或者 MultiThreadedApplicationAdapter 类,这些类已经实现了基本的 handler 功能,并且实现了必须实现的IScopeHandler 接口。
& & GgNET on 01 十二 2010
通过Stratus 服务器在Flash Player中使用RTMFP 开发 点对点应用
Adobe Flash Player 10 和 Adobe AIR 1.5 引入了一个新的通讯协议,Real-Time Media Flow Protocol (RTMFP),其低延迟,端到端的对等功能,安全性和可扩展性使它特别适合开发实时协作应用,不仅提供卓越的用户体验,而且运营商降低成本。
早前的Flash Player 版本使用 (RTMP) 需要Adobe Flash Media Server (FMS)提供合作应用(例如 Adobe Acrobat Connect Pro)或者音频视频流。RTMP是streaming media, shared objects, 和 remoting连接的卓越选择,它满足实时性要求的交互式音频和视频通信的能力有限。
为了能够使用RTMFP,Flash Player 客户端必须连接到一个支持RTMFP协议的服务器,例如 服务器或者是新版本的FMS。Stratus 是一台用于Flash Player 客户端间通信的主机。不同于FMS, Stratus 不支持视频转播,shared objects,脚本,等。因此,使用Stratus,只可以开发Flash Player的客户端直接相互交流的应用程序。
Flash Player 已经在web视频领域占有重要的市场份额。由于采用RTMFP和先进的媒体压缩技术,将有利于Flash Player 10处于实时通信的领先地位。
在这篇文章中,我首先强调在即时通讯领域使用RTMFP的优势。其次,我将要介绍直接管理点对点RTMFP管理所对应的新的ActionScript 3.0 API。最后,我介绍我们的VideoPhone应用实例。
Requirements
为了使用文中的文件,你需要以下软件和文件:
Flex Builder 3
注意:请按照指 南中的方法去安装Flex Builder 3.0.2.这里面包括Flex SDK 3.2, 这是为了建立 Flash Player 10应用。尽管你也可以使用Adobe Flash Professional CS4 作为开发工具,但这篇文件指导你如果使用Flex Builder 3建立一个简单的应用.
Flash Player 10
Sample files:
(ZIP, 13K)
Prerequisite knowledge
熟悉ActionScript 3.0 和 Flex Builder 是必要的。
Benefits of RTMFP
RTMFP的好处
Real-Time Media Flow Protocol (RTMFP)是一个引入到Flash Player 10 和 in AIR 1.5新的通讯协议。同Real-Time Messaging Protocol (RTMP)的主要不同点之一是,RTMP基于传输控制协议 (TCP) 和 先前版本的Flash Player,RTMFP建立在 User Datagram Protocol (UDP)协议.
TCP 提供了可靠的数据传输(也适用于文件传输,电子邮件等) ,它没有提供任何端到端延迟保证。可靠的数据传输的TCP实现了重新传输丢失的数据,其中包括了延迟。由于尽量减少端到端延迟是实时通信 (几百毫秒的延迟可能使一个会话不可用)中最重要的一个目标,TCP是不适合用于这一目的。传输错误复原和恢复不可分割的组成部分,最先进的音频和视频压 缩技术,如Speex音频和H.264视频编解码器,可同时在Flash Player 10 。因此,可靠的交付所提供的TCP没有必要的。因此, UDP连接,它提供了一个高效,快速的数据传输,是普遍使用的实时协作应用,尽量减少端到端延迟是至关重要的。另一个优势在于 UDP连接,它使端到端的对等,也就是说,数据直接的传输客户之间后面网络地址转换( NAT ) 。
当同RTMP做对比,RTMFP提供下列高级的即时通讯:
低 延迟:一但RTMFP建立起了UDP,它将给即时通讯提供最小的延迟。重要的是要注意RTMFP提供了可靠和不可靠的服务。当在两个Flash Player 实例之间发送数据的时候(例如,使用NetStream.send()方法),可靠的数据传输被使用。当在两个Flash Player 实例之间发送Speex 音频的时候,不可靠的交互方式被使用,以提供最小的延迟。
点对点媒体传 输:媒体直接发送给两个Flash Player的情况下,不通过路由,而是通过一个中央中继服务器。当同RTMP相比发现,在所有通过Flash Media Server传送的数据, RTMFP不仅进一步降低了端到端的延迟,而且也消除了中央数据中继的相关开销,因此,有助于自身的可扩展性部署。
数据的优先次序:音频传输具有较高优先于视频和非时间关键数据(如即时信息等) 。这可以通过带宽通信通道的限制大大提高在用户体验。
所有这些功能代表了应用于实时通信的巨大优势,提供了一个极大的用户体验,其成就比早期版本的Flash播放器的效应更为巨大。
Firewall traversal
穿越防火墙
RTMFP 是建立在UDP连接的基础上,使客户端直接的通信,即使它们位于NATs(译者注:是一个网络协议允许客户端后面的NAT (网络地址转换) ,以找出其公共地址,类型的NAT是延迟和互联网方面的端口相关的网络地址转换,尤其本地端口。此信息是用来建立UDP连接(用户数据报协议)之间的沟通 两个主机都是延迟的NAT路由器。该议定书是指在RFC 3489)或防火墙。为了RTMFP工作,您的防火墙必须配置为允许即将发出的UDP通信。大多数的消费者或小型办公室/家庭办公室( SOHO )的防火墙是这种情况,许多企业防火墙完全阻止UDP通信。
一种解决办法是配置的Flash Player使用转向代理 (遍历周围可用的NAT ) 。 Flash Player的支持IETF的因特网草案draft-ietf-behave-turn-08。如果网络管理员配置转向代理,允许即将发送的UDP连接, Flash播放器可以增加在mms.cfg的配置(更多的信息Flash Player的配置和位置mms.cfg ,请阅读 ) :
RTMFPTURNProxy=ip_address_or_hostname_of_TURN_proxy
直接UDP通信总是被尝试,转向代理只是用来作为备份:它是用于UDP通信,不能在Flash Player和Stratus (如UDP协议封锁防火墙)之间或Flash Player的端点之间流动。
即使你的防火墙使即将发送的UDP通信的用,可能和你对应端的防火墙不能够允许通过。当一个端点设在一个所谓的“对称的防火墙, ” 的后面,端到端的通信可能是不可以实现。 (对于多种防火墙,请进入维基百科参阅 。 )在这种情况下,你可以使用转代理援助你防火墙穿越。
Stratus service
Stratus 服务器
Flash Player实例必须连接到(使 用rtmfp : / /
) ,用以彼此的通讯。 Stratus是提供会合服务的主机,帮助Flash Player实例间的互相联系,即使它们位于NATs的后面。虽然连接到Stratus服务非常相似连接到Flash Media Server,Stratus没有提供任何Flash Media Server 典型的功能(媒体中继,共享对象,远程等)。 Flash Player客户端必须保持在整个通讯期间一直与Adobe Stratus连接。为了获得Stratus,您将需要您从Adobe公司申请来的开发密钥。
RTMFP支持正在计划添加到未来版 本的Flash Media Server(无发行日期) 。这样Flash Media Server,将有可能同Flash Player 9或更早的客户(使用RTMP )通信和Flash Player 10个客户端(使用RTMFP ) 通信。
RTMFP 提供终端设备之间的安全通信。它的密钥采用128位AES谈判使用密钥交换方法。不过,这并不提供强大的终端认证,如SSL或RTMPS 。为了帮助端点认证, RTMFP和ActionScript揭露给应用开发者。这些nonces可在双方沟通的Flash Player的终点,并保证比赛。通过核实这些nonces ,最终用户可以确保没有人在中间攻击。这些nonces还可以用来开发关键的连续性机制。
重要的是要注意到, Flash播放器不仅从您的麦克风和摄像头设备发送媒体,其他的Flash Player端点订阅您的媒体流。代表Flash播放器并不中继任何其他Flash Player的端点数据(如在一个多播的情况) 。
对于更多关于RTMFP的信息,请阅读Adobe Labs 上的帮助:
(PDF, 166K)
ActionScript 3.0 API supporting RTMFP
ActionScript 3.0 API 支持 RTMFP
有 一个新版本的ActionScript 3.0API支持Flash Player 10的RTMFP 。连接到Stratus错服务和创造端到端媒体流的方法类似于Flash Media Server的工作方法。请注意,您必须使用的ActionScript 3.0或者Flash Professional CS4或Flex Builder 3 构建目标于Flash Player 10或AIR 1.5 。
正如我前面提到的,首先你必须连接到Adobe公司Stratus的服务:
private const StratusAddress:String = &rtmfp://&;
private const DeveloperKey:String = &your-developer-key&;
private var netConnection:NetConnection;
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS,
netConnectionHandler);
netConnection.connect(StratusAddress + &/& + DeveloperKey);
开发者钥匙是你通过登陆你的Adobe公司开发者帐户申请得到,这个申请在服务的网站。
在成功连接到Stratus,你得到NetConnection.Connect.Success事件。失败可能有几个方面的原因。如果您提供了一 个无效的开发者或不正确的钥匙指定地址,您将收到NetConnection.Connect.Failed 。如果你的防火墙阻挡即将发送的UDP通信,您会收到的NetConnection.Connect.Failed事件后, 90秒超时。
在成功建立连接的Stratus服务中,您被分配一个独特的256位peer ID( NetConnection.nearID ) 。其他Flash Player的端点必须知道这个peer ID,以便收到您发表的音频/视频流。Flash Player或Stratus的服务是如何将这些ID在需要通讯的Flash Player客户端内传递,不在文章讨论范围内。对于交换ID ,你可以使用一个XMPP协议的服务或一个简单的网络服务,如视频电话样本应用程序。
Flash Player实例直接通讯使用单向网流渠道。也就是说,如果你想双向语音交谈,每个Flash Player的端点必须建立一个发送NetStream和接收NetStream。
首先创建一个发送NetStream:
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());
这意味着,媒体作为一个端到端的流发布。由于Stratus不能中继媒体,您只可以发布端到端的流。从您的设置管理器选择本地默认设备发出的流媒体将包括音频和视频。
注:音频/视频无法发送,直到另一Flash Player的客户端订阅您的媒体流。
现在,创建接收NetStream:
private var recvStream:NetS
recvStream = new NetStream(netConnection, id_of_publishing_client);
recvStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
recvStream.play("media");
在这一点上,你听到声音,你可以创建一个视频对象显示视频。为了创造接收NetStream,您必须知道发布者的256位peer ID(发布客户端的 id_ ) 。为了接收音频/视频,您必须知道被发布出来的流的名字。
Advanced topics
发布者有良好的控制权而接收端可以接收其发布的流。当一个用户试图获得发布的流时,onPeerConnect ()方法被调用(默认简单执行返回true )对发布的NetStream。发布者可以禁止某些Flash Player的终端接收媒体:
var o:Object = new Object();
o.onPeerConnect = function(subscriberStream:NetStream):Boolean
if (accept) {
sendStream.client =
在发布方, NetStream.peerStreams属性中拥有所有订阅发布的实例。例如,使用sendStream.send ()将发送相同的数据到所有用户。您可以使用下面的方法将信息发送到一个特定的用户:
sendStream.peerStreams[i].send()
NetConnection.maxPeerConnections属性指定被允许连接发布者的peer流的数量。默认值是设定为8但在实践中,这 取决于您的应用程序时,必须考虑到大多数互联网服务供应商提供非对称互联网接入服务的许可。图1说明了直接和三个Flash Player的实例通讯 。每个Flash Player客户端发送和接收两个流,建立一个完全连接网格。从互联网下载的能力普遍高于上传的能力,你必须要格外小心,不要超负荷用户终端的上行能力。
图1 使用Stratus服务点对点连接
NetConnection.unconnectedPeerStreams属性是一个没有相关发布的NetStreams数组。当一个发部流同一个订阅流相互竞争时,订阅NetStream从NetStream.peerStreams的数组中移除。
探索视频电话示例应用程序
我们已经开发了一个,说明如何使用Flash Player 10的端到端能力 。它也可作为部分文章。
该视频电话示例应用程序依赖于一个用于交流Flash Player peer ID简单的HTTP服务。提供的一部分该脚本,封装在( reg.cgi ) 。这种网络服务不提供任何用户认证。在Flash播放器成功地连接到Stratus,但其peer ID的网络服务。当创建一个呼叫电话时,视频电话呼叫使用此网络服务来查找收件人的peer ID。
Adobe公司运行这一网络服务专门提供视频电话样本。当您建立自己的视频电话样本,则必须运行您自己的网络服务,并在 VideoPhoneLabs.mxml 指定WebServiceUrl 。您应该使用自己重写的AbstractIdManager类来执行自己的peer ID身份证交流机制,例如, XMPP协议,谷歌应用服务,或Facebook的框架。
下列是建立一个视频电话示例应用程序的必要步骤(更多详情,请参阅ReadMe.txt包中包含) :
1.使用主机网络服务提供的peer ID的reg.cgi Python脚本。
2. 更新的Flex Builder 3.0.2配置,并对应开发于Flash Player 10或AIR 1.5 环境下。
3. 创建一个新的 Flex 项目。
4. 添加源文件的包( VideoPhoneLabs.mxml , AbstractIdManager.as , HttpIdManager.as , IdManagerError.as ,并IdManagerEvent.as )的项目源文件夹中。
5. 调试你的项目配制为Flex SDK 3.2 同时发布对象为Flash Player 10 或 AIR 1.5.
6. 在VideoPhoneLabs.mxml文件中替换DeveloperKey为您的Stratus开发密钥。
7. 在VideoPhoneLabs.mxml文件中替换WebServiceUrl为指定的web service。
该视频电话示例应用程序使用的手机模型。呼叫建立程序执行是使用端到端 NetStream.send ()的信息。既然你可以使用NetStream.send ( )方法只对指定的NetStream,视频电话发表其他Flash Player客户端可以连接的所谓的“听众流” (在这里我们这样叫它)。当客户端(调用者)希望与客户B通讯( A呼叫B) ,他或她订阅客户B的听众流。在这一点上,客户端B的通知访问者peer ID 的来电(使用onPeerConnect ()方法) ,并订阅客户A的媒体流。通过这个媒体流,客户端A通知客户B对他或她的好友用户的名称(使用NetStream.send ( )方法) ,用户可以选择接受或拒绝呼叫。如果要求被接受,客户端B发布的媒体流和双向通信将要被成立。
在本文中,我介绍了一些最令人激动的特点,新的RTMFP协议连同概述了新的ActionScript 3.0的API 。在阅读本文,您应该很好地理解如何使用这一革命性的协议。我希望你能利用端到端的和先进的媒体功能的Flash Player 10和AIR 1.5开发了不起的应用。
原文地址:
& GgNET on 17 十 2010
以red5 0.9.0为例介绍如何配置、编译、运行Red5源码。Red5 0.9.0与red5 0.9.1差不多,你可以用本文所介绍的方式来配置red5 0.9.1。
1.首先打开red5 0.9.0的下载页面:http://red5.org/wiki/0_9_0
我们点击“Windows”和”Source”两个链接来下载red5的安装包和red5的源码,我们下载安装包的目的是它包括了所有red5源码所依赖的jar包,这样很方便我们的配置。
2.下载完成之后,首先安装setup-Red5-0.9.0.exe,在安装过程中,如果提示你输入ip地址,则输入0.0.0.0,这样可以允许来自任何域的访问,如果提示输入端口,则输入5080,那么我们的web服务器将会绑定5080端口。
3.打开eclipse java开发环境,如果没有,则到http://eclipse.org/downloads/下载Eclipse IDE for Java Developers,将下载后的压缩包解压到本机你喜欢的地方,然后双击eclipse.exe,如果不能运行,说明你需要一个jdk,就到 /javase/downloads/widget/jdk6.jsp下载一个适合你的操作系统的jdk,安装 jdk之后,eclipse就可以运行了,打开eclipse开发 环境之后,选择一个你喜欢的工作空间。
4.新建一个Java Project
5.在新建工程对话框中输入Red5,点击“Finish”按钮则新建一个名为Red5的java工程
6.将red5安装目录下的所有文件夹拷贝到Red5工程根目录下
7.将下载的red5源文件解压并将org文件夹拷贝到我们的Red5工程的src目录下
8.这时我们看到工程中有些错误,说明缺少依赖的库,此时我们把lib文件夹中的所有jar文件添加构建路径中
9.我们找到org.red5.server.Bootstrap类,双击Bootstrap.java文件打开此类,按F11运行此工程。当你看到如下输出信息:Red5 is Active时,说明Red5服务器启动完成。
10.打开浏览器,在地址栏中输入,回车,如果你看到如下界面,说明你的Red5已经正在良好的运行。
11.接下来我们安装一个程序来测试一下,访问,点击“Install”链接,或者直接访问,则进入Red5安装应用程序列表界面
12.我们选择SOSample,点击“Install”按键安装它,等待安装完成
13.访问,点击“Launch a demo”链接,或者直接访问进入Red5应用演示列表界面
14.在Shared Ball栏目下,我们点击“View demo”进入应用程序Share Ball界面
我们用此地址复制,多打开几个浏览器窗口,将它们一一连接到red5服务器,尝试拖动Red5的图标,我们可以看到每个客户端的red5图标都被拖动。
15.下面我们一起来制作一个as3与red5通信的例子。 回到eclipse,在webapps目录下新建一个testred5目录,并将webapps里面的SOSample目录中所有内容拷贝到 testred5目录中(如果看不见SOSample目录,请刷新一下webapps目录)。
16.在testred5目录下新建一个src目录,并将此目录做为源文件目录
17.打开项目的属性面板,选择Java Build Path,在Java Build Path面板中选择Source选择卡,然后我们将Default output folder指向到Red5/webapps/testred5/WEB-INF/classes 目录,你可以通过浏览来选择此目录,也可以直接在输入框中输入“Red5/webapps/testred5/WEB-INF/classes”。点击“OK”关闭此面板。
18.我们在webapps/testred5/src源文件夹下建立一个Java类叫MainApp,
19.在MainApp类中输入如下代码
import org.red5.server.adapter.ApplicationAdapter;
public class MainApp extends ApplicationAdapter{
public String getValue(){
return &Hello world&;
20.分别修改webapps/testred5/WEB-INF目录下的文件 web.xml、red5-web.xml、red5-web.properties 如下:
&?xml version=&1.0& encoding=&ISO-8859-1&?&
xmlns=&/xml/ns/j2ee&
xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&
xsi:schemaLocation=&/xml/ns/j2ee /xml/ns/j2ee/web-app_2_4.xsd&
version=&2.4&&
&display-name&testred5&/display-name&
&context-param&
&param-name&webAppRootKey&/param-name&
&param-value&/testred5&/param-value&
&/context-param&
&/web-app&
red5-web.xml:
&?xml version=&1.0& encoding=&UTF-8&?&
&!DOCTYPE beans PUBLIC &-//SPRING//DTD BEAN//EN& &http://www.springframework.org/dtd/spring-beans.dtd&&
&bean id=&placeholderConfig&&
&property name=&location& value=&/WEB-INF/red5-web.properties& /&
&bean id=&web.context&
autowire=&byType& /&
&bean id=&web.scope&
init-method=&register&&
&property name=&server& ref=&red5.server& /&
&property name=&parent& ref=&global.scope& /&
&property name=&context& ref=&web.context& /&
&property name=&handler& ref=&web.handler& /&
&property name=&contextPath& value=&${webapp.contextPath}& /&
&property name=&virtualHosts& value=&${webapp.virtualHosts}& /&
&bean id=&web.handler&
singleton=&true& /&
web.properties:
webapp.contextPath=/testred5
webapp.virtualHosts=*, localhost, localhost:.0.1:8088
21.保存所有工程,按F11启动red5服务器。
22.打开FlashBuilder,创建一个名为Testred5client的ActionScript 项目,在生成的主文件中输入以下代码:
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.Responder;
public class Testred5client extends Sprite
private var _nc:NetConnection;
public function Testred5client()
_nc=new NetConnection;
_nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
_nc.connect(&rtmp://localhost/testred5&);
private function netStatusHandler(event:NetStatusEvent):void{
switch(event.info.code){
case &NetConnection.Connect.Success&:
_nc.call(&getValue&,new Responder(result));
private function result(obj:Object):void{
trace(obj);
23.按F11运行此代码,如果你看到输出面板中输出了Hello world,则说明你成功了。
GgNET on 17 十 2010
Red5 是建立在Jetty6(servlet engine) , Mina (networking)基础之上的,并通过使用Spring框架将起整合起来的.因此我们需要有一些配置文件.我们可能的通过载入properties 文件来简化配置,因此用户不需要深入了解XML.该文档就是要新手们去属性这些配置文件,其中一些需要改动,一些不必关心.
Jetty Config
———————————-
/conf/jetty.xml
servlet引擎主配置文件,如果你的应用程序是放在webapps文件中的,你就不需要更改该配置文件.该文件非常象一把瑞士军刀.你可以任意排序.关于其更多的详细信息参见jetty官方相关文档.
/conf/web-default.xml
缺省的web xml,其在WEB-INF/web.xml之前使用,它使得将servlets添加到所有的应用程序中.可以将其理解为一个webapp的模板文件.
/conf/keystore 文件存储指纹.
/conf/realm.properties web的归属,用户,密码等设置.
Red5 Server配置文件
———————————-
/conf/red5.properties
通过修改该文件我们就可以很轻松的指定端口,配置参数等,而不必去编辑xml文件.我们试图将所有的公用配置放到该文件中.
/conf/red5.xml
连接上下文.不知道是什么意思么?呵呵,不用担心,你不需要编辑该文件,除非你要添加另外一个全局的上下文.你可能在管理Red5的时候才会做这样的事情.
/conf/red5-common.xml
用来配置上下文环境树的根部,所有的服务都可以用于子环境.如果你想让在全局上下文环境中分享你的服务的话,你就需要修改该文件.99%的用户不需要编辑该文件.
/conf/log4j.properties
设置日值层,和输出文件等等.该文件作用于整个服务器.除非你要在webapp中的WEB-INF文件夹中使用log4j配置替代该文件,那么你就需要修改该文件.
/conf/red5-net.xml
安装Mina和启动Jetty.用户不需要修改该文件,类似端口的设置需要通过red5.properties文件配置.
/webapps/red5-default-global.xml
这是全局的上下文,大部分的服务器只需要一个,但是在安全的管理虚拟主机的时候需要将全局上下文分离.如果你想要在应用程序中分享服务的时候,将其加到这里.该上下文可以操作类似客户端注册和全局作用域.
Webapp配置文件
———————————-
/webapps/myapp/WEB-INF/web.xml
标准webapp配置文件,添加servlets,上下文参数等等.载入spring,使其于red5全局上下文相关联.
/webapps/myapp/WEB-INF/red5-web.xml
控制应用程序上下文环境,这里就是你添加应用,服务的地方.
/webapps/myapp/WEB-INF/red5-web.properties
该文件可以被red5-web.xml轻松的使用,也会被red5 jetty configurator读取从而设置ebapp.virtualHosts和webapp.contextPath.注意不同的servlet引擎要求的配置文件不同,要酌情决定.
/webapps/myapp/WEB-INF/log4j.properties
允许你为每个webapp分别设置日志等级等等.该文件也会被spring自动载入.听我的劝告请不要去修改它.
GgNET on 01 八 2010
public void streamSubscriberStart(ISubscriberStream stream) {
print(“streamSubscriberStart”);
IConnection conn = Red5.getConnectionLocal();
conn.setAttribute(“data”, conn.getWrittenBytes());
conn.setAttribute(“time”, System.currentTimeMillis());
super.streamSubscriberStart(stream);
public void streamSubscriberClose(ISubscriberStream arg0) {
IConnection conn = Red5.getConnectionLocal();
long data = conn.getWrittenBytes() – (Long) conn.getAttribute(“data”);
long time = System.currentTimeMillis() – (Long) conn.getAttribute(“time”);
print(“bytes per second:” + data * 1000 / time);
print(“streamSubscriberClose”);
super.streamSubscriberClose(arg0);
& GgNET on 01 八 2010
通过跟踪,得知当一个flash程序连接到RED5的时候所要调用的方法之最开始如下:
org.red5.server.net.rtmp.RTMPMinaIoHandler.sessionCreated
↓// 通过mina打开一个端口来开始session
org.red5.server.net.rtmp.RTMPMinaIoHandler.sessionOpened
org.red5.server.net.rtmp.RTMPMinaIoHandler.messageReceived
org.red5.server.net.rtmp.RTMPMinaIoHandler.messageSent
↓ // RTMPMinaIoHandler实现mina到rtmp的数据io
org.red5.server.net.rtmp.RTMPHandler.messageSent
↓ // 处理具体的rtmp数据,比较核心的对象
org.red5.server.net.rtmp.RTMPMinaIoHandler.messageReceived
org.red5.server.net.rtmp.RTMPHandler.messageReceived
↓ // 真正开始解析内容
org.red5.server.net.rtmp.RTMPHandler.onInvoke
↓ // 方法写的比较长,处理各种调用情况
org.red5.server.net.rtmp.RTMPHandler.getHostname
org.red5.server.Server.lookupGlobal
到达最后这个方法的事就即得到了主机名和程序路径名。
搞了半天,没有弄清楚第一步到第二步如何调用的,看来是mina内部的结构,需要细心研究mina才是。
另外,把log4j的RTMP调试信息输出也可以跟踪:
到conf目录下找到log4j.properties文件
将log4j.logger.org.red5.server.net.rtmp=INFO
改为log4j.logger.org.red5.server.net.rtmp=DEBUG
& & GgNET on 01 八 2010
官方在 H.264 和 1080P 方面支持的Demo ,我没有测试过,代码如下:
package org.red5.demos.oflaDemo;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IBandwidthConfigure;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.stream.IServerStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.red5.server.api.stream.support.SimpleConnectionBWConfig;
public class Application extends ApplicationAdapter {
private IScope appScope;
private IServerStream serverStream;
public boolean appStart(IScope app) {
appScope = app;
return true;
public boolean appConnect(IConnection conn, Object[] params) {
measureBandwidth(conn);
if (conn instanceof IStreamCapableConnection) {
SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();
bwConfig.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] = 1024 * 1024;
bwConfig.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] = 128 * 1024;
bwConfig.setUpstreamBandwidth(1024 * 1024);
return super.appConnect(conn, params);
public void appDisconnect(IConnection conn) {
if (appScope == conn.getScope() && serverStream != null) {
serverStream.close();
super.appDisconnect(conn);
& GgNET on 26 七 2010
一、第一篇,开始
首先不能完全 按照log4j的配置去搞log4j.properties,因为他们是用 log4j+slf4j 搞在一起的
在 classes下面要有个logback-myapp.xml的文件,里面配置
&?xml version=”1.0″ encoding=”UTF-8″?&
&configuration&
&appender name=”RED5DEMO” class=”ch.qos.logback.core.FileAppender”&
&File&log/red5demo.log&/File&
&Append&false&/Append&
&Encoding&UTF-8&/Encoding&
&BufferedIO&false&/BufferedIO&
&ImmediateFlush&true&/ImmediateFlush&
&layout class=”ch.qos.logback.classic.PatternLayout”&
%date [%thread] %-5level %logger{35} - %msg%n
&/Pattern&
&/appender&
&level value=”DEBUG” /&
&appender-ref ref=”RED5DEMO” /&
&logger name=”org.red5.demos.red5demo”&
&level value=”DEBUG” /&
&/configuration&
重启red5 在 red5/log 下看到一个red5demo.log文件了。
二. logback日志系统:
Red5起初使用的log4j日志系统,现在使用的是logback日志系统。
Ceki在Java日志领域世界知名。他创造了Log4J,这个最早的Java日志框架即便在JRE内置日志功能的竞争下
仍然非常流行。随后他又着手实现SLF4J这个“简单的日志前端接口(simple logging facade for
java)”来替代JCL(Jakarta
Commons-Logging)。这几年Ceki在从事他的新项目,LOGBack,一个“可靠、通用、快速而又灵活的Java日志框架”。
主要函数有:
package org.slf4j;
public interface Logger {
// Printing methods:
public void trace(String message);
public void debug(String message);
public void info(String message);
public void warn(String message);
public void error(String message);
主要日志级别有:TRACE DEBUG INFO WARN ERROR OFF
2、Red5LoggerFactory类:
red5-svn\java\server\trunk\src\org\red5\logging\Red5LoggerFactory文件中定义了”Red5LoggerFactory”类。
它简化了获取日志实例的请求操作,在Red5应用程序中推荐使用。
GgNET on 20 六 2010
1、Red5中的AMF对SharedObject中数据类型的映射:
AS3的Array 对应的是Java的LinkedHashMap
2、AS3里面的类使用RemoteClass绑定Java类,并且类可以嵌套使用
3、Red5对目前的FlashPlayer 9.0.60或9.0.64版本支持上有问题,在SharedObject更新的时候会产生错误,在9.0.47上可以正常运行。
4、连续的快速同步SharedObject,可能会导致SharedObject数据异常,尽量避免这样使用。
5、对于共享对象中的基本类型,使用setProperty方法,可以刷新SharedObject,对于对象类型,使用setDerty才能刷新SharedObject,让其他的Client同步。
要在RED5中使用远程sharedObject,必须注意以下几点:
sharedObject = SharedObject.getRemote( “远程sharedObject名称“, nc.uri, true );
对借助服务器在多个客户端间共享的对象返回一个SharedObject的引用。
nc为NetConnection对象。
sharedObject.client = this;
客户端对象为本身。便于广播消息,监听事件。
sharedObject.connect( nc );
通过nc链接到服务器。
在与flashplayer 9以前发布的FMS服务器进行sharedObject交互时,
一定要指定
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
否则flash无法监听到SYNC事件。目前使用的RED5服务器也是如此。
FLEX实例代码:
&?xml version=”1.0″ encoding=”utf-8″?&
&mx:Application xmlns:mx=”/2006/mxml” layout=”absolute” creationComplete=”initFun()”&
&mx:Script&
import mx.collections.ArrayC
private var nc:NetC
private var clientID:N
private var soChat:SharedO
private var arr:Array = new Array();
[Bindable]
private var con:ArrayC
private function initFun():void
nc = new NetConnection();
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
nc.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
nc.connect( “rtmp://localhost/MySOSample” );
private function statusHandler(event:NetStatusEvent):void
.code == “NetConnection.Connect.Success”){
connectToChat();
private function connectToChat():void
soChat = SharedObject.getRemote( “wxwred5″, nc.uri, true );
soChat.addEventListener( NetStatusEvent.NET_STATUS, netStatusHandler );
soChat.addEventListener( AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler );
soChat.addEventListener( SyncEvent.SYNC, sharedObjectSyncHandler );
soChat.client =
soChat.connect( nc );
soChat.send( “getName” );
public function getName():void
trace( “getName: ” + txtUser.text );
soChat.setProperty(”key”,txtUser.text);
public function newName(str:String):void
arr.push(str);
soChat.setProperty(”arr”,arr);
con = new ArrayCollection(arr);
private function sharedObjectSyncHandler( event:SyncEvent ):void
trace( “sharedObjectSyncHandler:code: ” + event.changeList );
arr.push(event.target.data.key);
con = new ArrayCollection(arr);
private function netStatusHandler( event:NetStatusEvent ):void
trace( “netStatusHandler:code: ” + .code );
private function asyncErrorHandler( event:AsyncErrorEvent ):void
trace( “asyncErrorHandler:code: ” + event.error );
&/mx:Script&
&mx:TextInput id=”txtUser” horizontalCenter=”1″ verticalCenter=”-109″/&
&mx:Button click=”getName()” label=”Button” horizontalCenter=”0″ verticalCenter=”-53″/&
&mx:List id=”listView” height=”203″ dataProvider=”{con}” verticalCenter=”68″ horizontalCenter=”0″&&/mx:List&
&/mx:Application&
& GgNET on 20 六 2010
public void streamSubscriberStart(ISubscriberStream stream) {
print(”streamSubscriberStart”);
IConnection conn = Red5.getConnectionLocal();
conn.setAttribute(”data”, conn.getWrittenBytes());
conn.setAttribute(”time”, System.currentTimeMillis());
super.streamSubscriberStart(stream);
public void streamSubscriberClose(ISubscriberStream arg0) {
IConnection conn = Red5.getConnectionLocal();
long data = conn.getWrittenBytes() - (Long) conn.getAttribute(”data”);
long time = System.currentTimeMillis() - (Long) conn.getAttribute(”time”);
print(”bytes per second:” + data * 1000 / time);
print(”streamSubscriberClose”);
super.streamSubscriberClose(arg0);
& & & & & & & & GgNET on 20 六 2010
* bigbluebutton是一个WWW电子学习和会议系统,他是基于Flash的视频会议,后台服务器使用Red5 Server。
* 本篇是参考installing from source英文版,根据自己的情况有点改动,系统是基于ubuntu之上。
* 如果想在ubuntu上快安装bigbluebutton请参见英文文档:/p /bigbluebutton/wiki/InstallationUbuntu。
* 如果不想安装bigbluebutton,只想测试bigbulebutton可以参见:/p /bigbluebutton/wiki/BigBlueButtonVM。
* 关于更多bigbluebutton的查看:/p/bigbluebutton
笔记开始:
1.检查网络
2.更新与升级
sudo apt-get update
sudo apt-get upgrade
3.安装JAVA 6
sudo apt-get install openjdk-6-jre-headless
安装了下列软件包:
ca-certificates-java icedtea-6-jre-cacao java-common libaccess-bridge-java openjdk-6-jre-headless openjdk-6-jre-lib rhino tzdata-java
4.安装MySQL
sudo apt-get install mysql-server
安装了下列软件包:
libdbd-mysql-perl libdbi-perl libhtml-template-perl libnet-daemon-perl libplrpc-perl mysql-client-5.0 mysql-server mysql-server-5.0 mysql-server-core-5.0
& GgNET on 20 六 2010
is an open source Flash
server written in Java. It does not include a standalone client yet but I
was able to write a Java program that uses Red5 to connect to an
video stream and record / save it to a file. Code is provided below and
also some tips on how to get the details required to download flash
videos that you come across on the internet.
& GgNET on 20 六 2010
Here are the steps to configure SSL in existing Red5
application. This article is keeping in the mind you have basic
knowledge of Red5 or you are aware of how Red5 applications are built.
Software required on machine where Red5 server is installed:-
1: Open SSL //Open source SSL libraries required for compiling
2: Stunnel //Open source SSL wrapper software uses open SSL works
Windows and Linux.
3: gcc // The GNU C compiler (although it always bundled with Linux
Machine, but I did not find it. Necessary if you are compiling the
Open SSL and Stunnel from source. Not required if using RPM
Configuration needed on server machine:-
1:- Install the Open SSL (if windows use exe RPM or source for Linux
machine can be downloaded from openssl website).
2:- Install Stunnel (if windows, use exe otherwise RPM or compilation
from source is preferred, can be downloaded from stunnel website). Make
sure that you already have compiled Open SSL in your machine before
proceeding with the installation of S otherwise it will fail to
Under Linux the standard command to compile Stunnel from source are
described below. For any update please always follow the installation
instructions given their website.
machine# gzip -dc stunnel-VERSION.tar.gz tar -xvzf –
machine# cd stunnel-VERSION
machine# ./configure
machine# make
machine# make install
There are several configurations that differ based on your computer
and environment. That can be read from the website itself.
3:- Running Stunnel (There are several ways/mode you can run the
stunnel. Follow the FAQ available in their website to choose the best
which matches your requirements).
To run stunnel, you always require a configuration file. The process of
making sample configuration file (stunnel.conf) is described below.
The sample configuration file used was like this:
sample.conf
; Sample stunnel configuration file by Sunil Gupta 2007
; Some options used here may not be adequate for your particular
configuration
; Certificate/key is needed in server mode and optional in client
; The default certificate is provided only for testing and should not
; be used in a production environment
cert = /etc/stunnel/stunnel.pem
;chroot = /var/run/stunnel/
pid = /stunnel.pid
key = /etc/stunnel/stunnel.pem
; Some performance tunings
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
; Workaround for Eudora bug
;options = DONT_INSERT_EMPTY_FRAGMENTS
; Authentication stuff
;verify = 2
; Don’t forget to c_rehash CApath
;CApath = certs
; It’s often easier to use CAfile
;CAfile = certs.pem
; Don’t forget to c_rehash CRLpath
;CRLpath = crls
; Alternatively you can use CRLfile
;CRLfile = crls.pem
; Some debugging stuff useful for troubleshooting
Output = /var/log/stunnel.log
foreground=yes
; Use it for client mode
; client = yes
; Service-level configuration
;accept = 995
;connect = 110
;accept = 993
;connect = 143
;accept = 465
;connect = 25
[rtmps – https]
TIMEOUTconnect=20
accept = 443
connect = 80
TIMEOUTclose = 20
; vim:ft=dosin
Note: – When you install Stunnel, you get a default sample file,
which is not enough in most of the cases to run the flash application.
The additions to configuration file I made are as follows.
A in the start denotes the commented portion in
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
pem stands for ‘privacy enhanced mail’ used as a key format. The
above two lines tells the location of pem files need to be generated.
This will be configured by user. The above is the best location for
Stunnel although you can change it to any desired location.
;Some performance tunings
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
The above two lines are for better performance of Stunnel in our
; Workaround for Eudora bug
;options = DONT_INSERT_EMPTY_FRAGMENTS
The above line is a bug in a specific platform, since we are running
it in L we commented this line, although it could be needed in some
; Some debugging stuff useful for troubleshooting
Output = /var/log/stunnel.log
foreground=yes
The above lines are very important, Because Stunnel by default run in
background mode. You will never be able to see if it is running. So
better to put it in foreground, so that you can make sure that stunnel
is running properly. Also the debug = 7 is very important since by
default stunnel does not generate any log. You can direct him to
generate log, so that you can debug your application by seeing all those
log messages. The above mentioned log directory is default Linux
directory where all system logs are generated.
; Use it for client mode
; client = yes
In the sample configuration file, you will always find this option
un-commented leading to a different architecture, since we are running
Stunnel in server mode not client mode, so we will comment this line.
[rtmps – https]
TIMEOUTconnect=20
accept = 443
connect = 80
TIMEOUTclose = 20
And the very last lines are mentioned above. In the sample
configuration file, you will never find rtmps and it is not even
mentioned anywhere in Stunnel. The default file contains only https, add
rtmps like it is added here. Also accept port is 443, which is the
default port used for secure communication and it is open like port 80
in all corporate firewalls in general. This port is to accept the
connection from flash and to get the encrypted data. The connect port is
80; this is the port where stunnel will forward the decrypted data to
red5 server.
The TIMEOUTconnect and TIMEOUTclose can be useful in some cases when the
server where the data is being forwarded by Stunnel is delaying the
connection. This is to make sure that connection is closed only when
server is not responding at all. The value is in seconds (i.e. 20 sec.)
Now in order to run your application under secure connection, you
require a certificate to be created on the machine where the Stunnel is
installed. The procedure for creating a certificate and the possible
directory to put this certificate is described below.
Use of certificate:-
When an SSL client connects to an SSL server, the server presents a
certificate, essentially an electronic piece of proof that machine is
who it claims to be. This certificate is signed by a ‘Certificate
Authority’ (hereafter a CA) — usually a trusted third party like
Verisign. A client will accept this certificate only if
The certificate presented matches the private key being used by the
remote end.
The certificate has been signed correctly by the CA. The client
recognizes the CA as trusted.
Every stunnel server has a private key. This is contained in the pem
file which stunnel uses to initialize its identity. If we notice above,
we have given the reference of this pem file in the start of our
configuration file under cert.
This private key is put in /usr/local/ssl/certs/stunnel.pem.
Note:-Under client mode we need not to have certificate in most of
the cases, but if we are running it in server mode, we require a
certificate. Since we are using server mode, I have generated a self
certificate.
To make certificate:-
1: Go to /etc/stunnel directory and
2: Run the following command:-’
openssl req -new -x509 -days 365 -nodes -f -out
stunnel.pem -keyout stunnel.pem
This creates a private key and self-signed certificate. More
information on the options of this can be read from FAQ section of
Stunnel website.
While executing the command, it will ask for some questions like
Country, City, Company etc., Give the answer of those and it will
generate the key and self certificate.
4:- Put your sample.conf file in /etc/stunnel directory where the
.pem file was created earlier.
5:- Start Stunnel by issuing the command –
machine# stunnel stunnel.conf
If you are /etc/stunnel directory otherwise complete path of
configuration file-
machine# stunnel /etc/stunnel/stunnel.conf
The above command will start the stunnel and you can verify the log
from /var/logs/stunnel.log file.
Red5 server side changes:-
6:- Now stunnel is up and running, we need to change the Red5
configuration to accept the connection from Stunnel.
Go to red5 installation directory and search for conf folder where
all red5 configuration files exist.
Open red5.properties file and under rtmps.host_port property put 443.
The sample file can be like below.
rtmp.host_port = 0.0.0.0:1935
rtmp.threadcount = 4
debug_proxy.host_port = 0.0.0.0:1936
proxy_forward.host_port = 127.0.0.1:1935
rtmps.host_port = 127.0.0.1:443
http.host=0.0.0.0
http.port=5080
rtmpt.host=0.0.0.0
rtmpt.port=80
Flash client side changes:-
7:-Now we are done with server side, In order to run application
under SSL, we need to change the client side protocol from rtmp to rtmps
like below. And compile the flash client and run it on browser, a
certificate will pop up, accept it and the application will run under
nc.connect (”rtmps://yourip/applicationname”); //used rtmps in place
To get all Red5 media server related stuffs, visit the website below-
Technology Makes Life Easier ()
Article Source:
& GgNET on 20 六 2010
package cn.xinsync.test;
import org.red5.server.api.service.IPendingServiceCall;
import org.red5.server.api.service.IPendingServiceCallback;
import org.red5.server.net.rtmp.RTMPClient;
public class Red5 extends RTMPClient {
public static void main(String[] args) {
String host = &localhost&;
String app = &test&;
int port = 1935;
final Red5 client = new Red5();
IPendingServiceCallback callback = new IPendingServiceCallback() {
@SuppressWarnings(&unchecked&)
public void resultReceived(IPendingServiceCall call) {
java.util.Map re = (java.util.Map) call.getResult();
System.out.println(&level:& + re.get(&level&));
System.out.println(&description:& + re.get(&description&));
System.out.println(&code:& + re.get(&code&));
client.connect(host, port, app, callback);
& & & & GgNET on 20 六 2010
程序如下:
发布端(Publish):
var nc:NetConnection = new NetConnection();
nc.connect(&rtmp://192.168.1.5/Red5Stream&);
nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
function connectHandler(par:NetStatusEvent):void {
trace(par.info.code);
var camera:Camera = Camera.getCamera();
camera.setQuality(163854,100);
var stream:NetStream = new NetStream(nc);
stream.attachCamera(camera);
stream.publish(&red5&);
package {
import flash.display.*;
import flash.utils.*;
import flash.events.*;
import flash.net.*;
import flash.media.Video;
import fl.data.DataProvider;
import flash.media.Camera;
public class NetStreamTestDocument extends Sprite {
var nc:NetConnection;
public function NetStreamTestDocument() {
nc= new NetConnection();
nc.connect(&rtmp://192.168.1.5/Red5Stream&);
nc.addEventListener(NetStatusEvent.NET_STATUS,connectHandler);
public function connectHandler(par:NetStatusEvent):void {
var ns:NetStream = new NetStream(nc);
var video:Video=new Video(320,240) ;
video.attachNetStream(ns);
ns.play(&red5&);
addChild(video);
package cn.xinsync.conference;
import org.red5.server.adapter.MultiThreadedApplicationAdapter;
import org.red5.server.api.IConnection;
import org.red5.server.api.Red5;
import org.red5.server.api.stream.IBroadcastStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.red5.server.api.stream.support.SimpleConnectionBWConfig;
public class OtherApplication extends MultiThreadedApplicationAdapter {
public void streamPublishStart(IBroadcastStream stream) {
IConnection conn=Red5.getConnectionLocal();
measureBandwidth(conn);
if (conn instanceof IStreamCapableConnection) {
IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();
bwConfig.getChannelBandwidth()[3] = 1048576L;
bwConfig.getChannelInitialBurst()[3] = 131072L;
streamConn.setBandwidthConfigure(bwConfig);
super.streamPublishStart(stream);
public void streamBroadcastClose(IBroadcastStream arg0) {
super.streamBroadcastClose(arg0);
以下是官方在 H.264 和 1080P 方面支持的Demo ,我没有测试过,代码如下:
package org.red5.demos.oflaDemo;
import org.red5.server.adapter.ApplicationAdapter;
import org.red5.server.api.IBandwidthConfigure;
import org.red5.server.api.IConnection;
import org.red5.server.api.IScope;
import org.red5.server.api.stream.IServerStream;
import org.red5.server.api.stream.IStreamCapableConnection;
import org.red5.server.api.stream.support.SimpleConnectionBWConfig;
public class Application extends ApplicationAdapter {
private IScope appScope;
private IServerStream serverStream;
public boolean appStart(IScope app) {
appScope = app;
return true;
public boolean appConnect(IConnection conn, Object[] params) {
measureBandwidth(conn);
if (conn instanceof IStreamCapableConnection) {
SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig();
bwConfig.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] =
1024 * 1024;
bwConfig.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] =
128 * 1024;
bwConfig.setUpstreamBandwidth(1024 * 1024);
return super.appConnect(conn, params);
public void appDisconnect(IConnection conn) {
if (appScope == conn.getScope() && serverStream != null) {
serverStream.close();
super.appDisconnect(conn);

我要回帖

更多关于 red5安装配置 的文章

 

随机推荐