【vc++精品源码栏目提醒】:本文主要为网学会员提供“开源RTP源代码 - 其它资料”,希望对需要开源RTP源代码 - 其它资料网友有所帮助,学习一下!
开源 RTP 库 JRTPLIB 初学 转2008-12-10 18:58:00 转载标签: 分类: 技术无限it RTP 是一个实时通讯网络协议,网络上的音视频传输可以用它来做,像 QQ 的语音聊天等都是使用这个。
real 开发 的在线 rm 文件播放协议 rstp 也是基于 RTP 协议,可以自己搜索一下, 在网上可找到“RTP 实时网络协议 rfc3550.pdf” 文档,有详细介绍。
JRTPLIB 是一个开源的 RTP 协议实现库,支持 Windows 和 unix 平台,应该也很多人用了,封装的类方式很不错。
他的主页是 http://research.edm.uhasselt.be/jori/page/index.phpnCS.Jrtplib ,帮助文档:http://research.edm.uhasselt.be/jori/jrtplib/documentation/index.htmlRTPSession ClassReferencehttp://research.edm.uhasselt.be/jori/jrtplib/documentation/classRTPSession.html从他主页上下载完整的 JRTPLIB 源码包下来解压就行了,不过 JRTPLIB 用到了他的JThread 库,在主页上可以找到,也把 JThread 库下载下来就行了。
解压之后再 examples 目录下有几个例子,我试了一下,example2.cpp 和 example4.cpp 两个,刚好一个可以作为客户端,一个作为服务器端,在 vc2003 中测试了一下。
首先建一个 win32 console 项目,把 把 JRTPLIB example2.cpp 和 example4.cpp加进了,再把 JRTPLIB 和 JThread 添加到工程中来。
在 include 目下中指定JRTPLIB 和 JThread 的 src 源码目录。
下一步把工程属性中把 “RuntimeLibrary” 改成“Multi-threaded Debug DLL /MDd” ,需要改成这个 JThread 才能编 最后包含一个 Ws2_32.lib 这个 lib 库,译通过。
我是直接在 example2.cpp 和 example4.cpp前面添加 pragma comment lib quotWs2_32.libquot 这一句了,在工程属性修改应该一样的。
两个例子的代码如下也贴一下吧:pragma comment lib quotWs2_32.libquotinclude quotrtpsession.hquotinclude quotrtppacket.hquotinclude quotrtpudpv4transmitter.hquotinclude quotrtpipv4address.hquotinclude quotrtpsessionparams.hquotinclude quotrtperrors.hquotifndef WIN32include ltnetinet/in.hgtinclude ltarpa/inet.hgtelseinclude ltwinsock2.hgtendif // WIN32include quotrtpsourcedata.hquotinclude ltstdlib.hgtinclude ltstdio.hgtinclude ltiostreamgtinclude ltstringgtifdef RTP_SUPPORT_THREADThis function checks if there was a RTP error. If so it displays an errormessage and exists.void checkerrorint rtperrif rtperr lt 0 std::cout ltlt quotERROR: quot ltlt RTPGetErrorStringrtperr ltlt std::endl exit-1The new class routineclass MyRTPSession : public RTPSessionprotected:void OnPollThreadStepvoid ProcessRTPPacketconst RTPSourceData ampsrcdatconst RTPPacket amprtppackvoid MyRTPSession::OnPollThreadStepBeginDataAccesscheck incoming packetsif GotoFirstSourceWithData do RTPPacket pack RTPSourceData srcdat srcdat GetCurrentSourceInfo while pack GetNextPacket NULL ProcessRTPPacketsrcdatpack DeletePacketpack while GotoNextSourceWithDataEndDataAccessvoid MyRTPSession::ProcessRTPPacketconst RTPSourceData ampsrcdatconst RTPPacketamprtppackYou can inspect the packet and the sources info herestd::cout ltlt quotGot packet quot ltlt rtppack.GetExtendedSequenceNumber ltlt quot from SSRCquot ltlt srcdat.GetSSRC ltlt std::endlThe main routineint mainvoidifdef WIN32WSADATA datWSAStartupMAKEWORD22ampdatendif // WIN32MyRTPSession sessuint16_t portbasestd::string ipstrint statusnum First well ask for the necessary informationstd::cout ltlt quotEnter local portbase:quot ltlt std::endlstd::cin gtgt portbasestd::cout ltlt std::endlstd::cout