最近要做网络监控视频的传输,以前就接触过图像处理的基本东西,对于网络稍微了解一点,对于视频的编解码则是一窍不通。这两周查阅了不少资料,发现一般使
用的网路协议都是RTP/RTCP,网络上找了不少资料,本来想整个现成的例子看看,下了不少发现都不满意,只好自己找到那个很牛的老外Jori写的开源的RTP库jrtplib研究一下自己编译一下,学学了。
首先从他的个人网站上http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib下载最新的jrtplib-3.9.0,以及最新的jthread-1.3.0(他的页面上也有下载),解压完之后,看了看ReadMe发现需要Cmake编译,oh!mygod!慢慢来吧。
使用Cmake_gui 2.8版本,首先编译生成jthread.lib。
添加完路径之后,很顺利的就可以得到vs2005下的工程文件,编译之后可以在C:/Program Files/jthread/include(默认的路径)下看到jthread的头文件以及在C:/Program Files/jthread/lib下的lib文件(一般吧debug和release都编译一下)。
然后就是jrtplib的编译了。
jrtplib的cmake编译需要jthread.lib(jthread_d.lib)编译,cmake不会用,开始时出现错误,后来自己摸索着试了试,成功了,就是在编译几个example时发现有warning,也没什么关系。设置如图所示
这样再generate就可以了(不知道以后有没有问题,反正现在没问题)。
然后就是vs2005中的生成lib库了。
首先需要将所有jrtplib中src下的头文件中包含jmutex.h和jthread.h的include全部修改为include "jmutex."和include"jthread.h",然后进行下一步
打开工程文件编译之后安装,可以在C:\Program Files\jrtplib下面看到两个文件夹include和lib分别放着头文件和库文件。
打开example1,进行相应的设置之后run,发现可以运行了!
这样应该就可以在工程中使用jrtplib库了---------还没有试,期待ing。。。。。
另:在Jori的主页上有关于这两个库jrtplib和jthread的使用手册的pdf下载可以参考。
NOTE:开始时没有将jthread和jmutex的include修改,虽然编译成功了,运行example也可以但是自己编的程序就出问题,后来参考了一下http://blog.csdn.net/aaronalan/article/details/5153604 重新编译的才行了。
附上一个在网上找到的例子:
/* Here's a small IPv4 example: it asks for a portbase and a destination and starts sending packets to that destination. */ #include "rtpsession.h" #include "rtpudpv4transmitter.h" #include "rtpipv4address.h" #include "rtpsessionparams.h" #include "rtperrors.h" #include "rtppacket.h" #ifndef WIN32 #include <netinet/in.h> #include <arpa/inet.h> #else #include <winsock2.h> #endif // WIN32 #include <stdlib.h> #include <stdio.h> #include <iostream> #include <string> using namespace jrtplib; #pragma comment(lib,"jrtplib_d.lib") #pragma comment(lib,"jthread_d.lib") #pragma comment(lib,"ws2_32.lib") // // This function checks if there was a RTP error. If so, it displays an error // message and exists. // void checkerror(int rtperr) { if (rtperr < 0) { std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl; exit(-1); } } // // The main routine // int main(void) { #ifdef WIN32 WSADATA dat; WSAStartup(MAKEWORD(2,2),&dat); #endif // WIN32 RTPSession sess; uint16_t portbase,destport; uint32_t destip; std::string ipstr; int status,i,num; BYTE *pBuffer; BYTE *pfBuffer; // First, we'll ask for the necessary information std::cout << "Enter local portbase:" << std::endl; std::cin >> portbase; std::cout << std::endl; std::cout << "Enter the destination IP address" << std::endl; std::cin >> ipstr; destip = inet_addr(ipstr.c_str()); if (destip == INADDR_NONE) { std::cerr << "Bad IP address specified" << std::endl; return -1; } // The inet_addr function returns a value in network byte order, but // we need the IP address in host byte order, so we use a call to // ntohl destip = ntohl(destip); std::cout << "Enter the destination port" << std::endl; std::cin >> destport; std::cout << std::endl; std::cout << "Number of packets you wish to be sent:" << std::endl; std::cin >> num; // Now, we'll create a RTP session, set the destination, send some // packets and poll for incoming data. RTPUDPv4TransmissionParams transparams; RTPSessionParams sessparams; // IMPORTANT: The local timestamp unit MUST be set, otherwise // RTCP Sender Report info will be calculated wrong // In this case, we'll be sending 10 samples each second, so we'll // put the timestamp unit to (1.0/10.0) sessparams.SetOwnTimestampUnit(1.0/10.0); sessparams.SetAcceptOwnPackets(true); transparams.SetPortbase(portbase); status = sess.Create(sessparams,&transparams); checkerror(status); RTPIPv4Address addr(destip,destport); status = sess.AddDestination(addr); checkerror(status); for (i = 1 ; i <= num ; i++) { printf("\nSending packet %d/%d\n",i,num); // send the packet status = sess.SendPacket((void *)"1234567890",10,0,false,10); checkerror(status); sess.BeginDataAccess(); // check incoming packets if (sess.GotoFirstSourceWithData()) { do { RTPPacket *pack; while ((pack = sess.GetNextPacket()) != NULL) { // You can examine the data here printf("Got packet !\n"); std::cout << "Got packet with " << "extended sequence number " << pack->GetExtendedSequenceNumber() << " from SSRC " << pack->GetSSRC() << std::endl; int dataLength = pack->GetPayloadLength(); pfBuffer =(unsigned char*)pack->GetPayloadData(); pBuffer = new BYTE[dataLength + 1]; memcpy(pBuffer, pfBuffer, dataLength); pBuffer[dataLength] = 0; std::cout << pBuffer << std::endl; delete []pBuffer; pBuffer = NULL; // we don't longer need the packet, so // we'll delete it sess.DeletePacket(pack); } } while (sess.GotoNextSourceWithData()); } sess.EndDataAccess(); #ifndef RTP_SUPPORT_THREAD status = sess.Poll(); checkerror(status); #endif // RTP_SUPPORT_THREAD RTPTime::Wait(RTPTime(1,0)); } sess.BYEDestroy(RTPTime(10,0),0,0); #ifdef WIN32 WSACleanup(); #endif // WIN32 return 0; }
例子是在Jori给的example中加入了收报后的解析,运行正常!
vs2005下编译jrtplib-3.9.0和jthread-1.3.0
最新推荐文章于 2023-11-03 11:38:19 发布