crtmpserver基本流程介绍

1、初始化流程
InitNetworking---初始化网络
Initialize
Logger::Init()---初始化日志
lowerCase(extension) == "lua"---加载.lua后缀配置文件
LoadLuaFile
Normalize
NormalizeLogAppenders 初始化日志配置
NormalizeApplications 初始化监听配置


gRs.pConfigFile->ConfigLogAppenders()根据配置初始化
IOHandlerManager::Initialize() 初始化IO,读写队列清零
gRs.pConfigFile->ConfigModules() 加载动态库appselector.dll
ProtocolFactoryManager::RegisterProtocolFactory(gRs.pProtocolFactory) 加载默认支持的协议集合
gRs.pConfigFile->ConfigAcceptors() 根据IP和端口开启监听器
gRs.pConfigFile->ConfigInstances() 配置多实例,win下不支持
gRs.pConfigFile->ConfigApplications() 将监听器与实例绑定
installQuitSignal 设置程序退出机制


Run
IOHandlerManager::Pulse() 对socket资源进行轮询,查询是否有需要进行读写的socket操作






2、接收客户端的连接请求之connect
Pulse()
FD_ISSET(MAP_VAL(i)->GetInboundFd(), &_readFdsCopy)
MAP_VAL(i)->OnEvent(_currentEvent)
TCPAcceptor::Accept() 进入accept进行连接的创建
BaseProtocol *pProtocol = ProtocolFactoryManager::CreateProtocolChain 为连接创建对应配置的协议,比如tcp && rtmp,或者udp && rtcp==


TCPCarrier *pTCPCarrier = new TCPCarrier(fd) 为连接创建一个tcp交互对象,并将其和刚创建的协议对象绑定,创建时构造函数中就注册了读请求


FD_ISSET(MAP_VAL(i)->GetInboundFd(), &_readFdsCopy)
MAP_VAL(i)->OnEvent(_currentEvent)
TCPCarrier::OnEvent(select_event &event) 进入读分支读取数据,根据对应的协议分析读取的数据依据结果填充_outputBuffer发送缓冲区,并设置发送信号TCPCarrier::SignalOutputData()--->ENABLE_WRITE_DATA,通知Pulse轮询socket状态需要发送数据,然后再次进入TCPCarrier::OnEvent(select_event &event)写分支进行真正的数据发送操作


RTMP消息类型为:RM_INVOKE_FUNCTION_CONNECT


3、接收客户端的发布流之Publish
这一段属于rtmp协议交互的部分


RM_INVOKE_FUNCTION_RELEASESTREAM 这里没有获得stream名称,发送名称请求
RM_INVOKE_FUNCTION_FCPUBLISH 这里获得stream名称
RM_INVOKE_FUNCTION_CREATESTREAM
ProcessInvokeCreateStream
pFrom->CreateNeutralStream(id) == NULL
RTMPStream *pStream = new RTMPStream 这里创建一个rtmpstream流控制对象  RTMPStream ---> BaseStream
RM_INVOKE_FUNCTION_PUBLISH
ProcessInvokePublish
GetApplication()->GetAllowDuplicateInboundNetworkStreams()这里判断是否存在同名情况
InNetRTMPStream *pInNetRTMPStream = pFrom->CreateINS(VH_CI(request) 创建network inbound stream
GetApplication()->GetStreamsManager()->GetWaitingSubscribers 查询是否有请求这路流的连接并绑定pBaseOutStream->Link(pInNetRTMPStream);
pInNetRTMPStream->SendOnStatusStreamPublished() 发送准备接收流请求
BaseOutFileStream *pOutFileStream = CreateOutFileStream(pFrom, meta, appending);另外,如果需要录像,这里创建文件流连接


4、接收客户端请求实时流
这一段属于rtmp协议交互的部分


RM_INVOKE_FUNCTION_PLAY
ProcessInvokePlay
pFrom->CloseStream(VH_SI(request), true) 关闭该连接之前请求的流
TryLinkToLiveStream(pFrom, VH_SI(request), streamName, linked) 将该连接绑定
FOR_MAP(inboundStreams, uint32_t, BaseStream *, i) 通过streamName查询找到流输入
BaseOutNetRTMPStream * pBaseOutNetRTMPStream = pFrom->CreateONS(streamId, 先创建流输出
pBaseInNetStream->Link(pBaseOutNetRTMPStream) 然后将流输出绑定至流输入







C++ RTMP Server Instructions how to compile and use C++ RTMP Server (a.k.a crtmpserver) Requirements: * GCC and other C++ tools * SVN * libdl, libssl, libcrypto (make sure you have the "devel" packages of libdl, ssl and crypto installed prior to compiling) In order to get the source code, issue the following command: svn co --username anonymous https://svn.rtmpd.com/crtmpserver/trunk crtmpserver When it asks for password, hit Enter key Compile the package. Do the following steps: cd crtmpserver/builders/cmake cmake . (this step will create all the Makefile's that are required. If some package is missing, the cmake will complain) make The compilation procedure should be finished within few minutes. After you compiled the package, it's time to test it. Run the following command: ./crtmpserver/crtmpserver crtmpserver/crtmpserver.lua If everything goes well, you'll get on your console a table with IP's, ports, protocols, and application names If you see this table, then crtmpserver is working. Lets test it the server. Follow these simple steps: * Download a simple FLV or MP4 file. You can dowload a sample file from here: http://www.mediacollege.com/adobe/flash/video/tutorial/example-flv.html * Place the file you downloaded into the crtmpserver/media folder * Download an FLV player. For this example, we'll use JW Player. Get it here: http://www.longtailvideo.com/players/jw-flv-player * Extract the JW Player to a directory which is accessible through your web server * Go to the extracted directory and create an HTML file which will include the player and play the file. Here's an example: <html> <body> <script type='text/javascript' src='swfobject.js'></script> <div id='mediaspace'>This text will be replaced</div> <script type='text/javascript'> var so = new SWFObject('player.swf','mpl','640','360','9'); so.addParam('allowfullscreen','true'); so.addParam('allowscriptaccess','always'); so.addParam('wmode','opaque'); so.addVariable('file','file-download'); so.addVariable('streamer','rtmp://127.0.0.1/flvplayback/'); so.write('mediaspace'); </script> </body> </html> * Change the 127.0.0.1 to either the IP of your crtmpserver or simply use a hostname of your machine * Replace file-download with the actual filename of your sample you download. Remeber to omit the .flv if it's an FLV file * Open a web browser and point it to to the web server IP/Hostname and the directory you installed the player (example: http://127.0.0.1/player) * You should see a player. Click the play button and the video should be played. If you see the video, then everything works well. Installing crtmpserver: * Go to the directory crtmpserver/cmake * Run the following command: cmake -DCRTMPSERVER_INSTALL_PREFIX=<path> (for example /usr/local/crtmpserver) * After previous command done start build project with command: make * After build comlete run command: make install * After install you has installed crtmpserver in <path>(in our case /usr/local/crtmpserver) * Now you can start crtmpserver with command: sudo <path>/sbin/crtmpserver --uid=<UID> <path>/etc/crtmpserver.lua in our case: sudo /usr/local/crtmpserver/sbin/crtmpserver --uid=<UID> /usr/local/crtmpserver/etc/crtmpserver.lua Also look into builders/packing directory. There are several OS specific builders. * in directory "debian" builder for Debian, also can be used for Ubuntu and other distributions based on debian * in directory "freebsd" builder(port) for FreeBSD crtmpserver settings * All crtmpserver settings are located in a detailed file calle: crtmpserver.lua
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值