编译jrtplib和jthread

来源:互联网 发布:哪里有卖白家乐软件的 编辑:程序博客网 时间:2024/05/15 11:27
 最近要做网络监控视频的传输,以前就接触过图像处理的基本东西,对于网络稍微了解一点,对于视频的编解码则是一窍不通。这两周查阅了不少资料,发现一般使

用的网路协议都是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 重新编译的才行了。

附上一个在网上找到的例子:

view plaincopy to clipboardprint?
  1. /* 
  2.    Here's a small IPv4 example: it asks for a portbase and a destination and  
  3.    starts sending packets to that destination. 
  4. */  
  5.   
  6. #include "rtpsession.h"   
  7. #include "rtpudpv4transmitter.h"  
  8. #include "rtpipv4address.h"   
  9. #include "rtpsessionparams.h"  
  10. #include "rtperrors.h"   
  11. #include "rtppacket.h"   
  12. #ifndef WIN32   
  13.     #include <netinet/in.h>  
  14.     #include <arpa/inet.h>   
  15. #else   
  16.     #include <winsock2.h>   
  17. #endif // WIN32   
  18. #include <stdlib.h>   
  19. #include <stdio.h>   
  20. #include <iostream>   
  21. #include <string>   
  22.   
  23. using namespace jrtplib;  
  24. #pragma comment(lib,"jrtplib_d.lib")   
  25. #pragma comment(lib,"jthread_d.lib")  
  26. #pragma comment(lib,"ws2_32.lib")   
  27. //   
  28. // This function checks if there was a RTP error. If so, it displays an error  
  29. // message and exists.   
  30. //   
  31.   
  32. void checkerror(int rtperr)  
  33. {  
  34.     if (rtperr < 0)  
  35.     {  
  36.         std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl;  
  37.         exit(-1);  
  38.     }  
  39. }  
  40.   
  41. //   
  42. // The main routine   
  43. //   
  44.   
  45. int main(void)  
  46. {  
  47. #ifdef WIN32   
  48.     WSADATA dat;  
  49.     WSAStartup(MAKEWORD(2,2),&dat);  
  50. #endif // WIN32   
  51.       
  52.     RTPSession sess;  
  53.     uint16_t portbase,destport;  
  54.     uint32_t destip;  
  55.     std::string ipstr;  
  56.     int status,i,num;  
  57.     BYTE *pBuffer;  
  58.     BYTE *pfBuffer;  
  59.         // First, we'll ask for the necessary information  
  60.           
  61.     std::cout << "Enter local portbase:" << std::endl;  
  62.     std::cin >> portbase;  
  63.     std::cout << std::endl;  
  64.       
  65.     std::cout << "Enter the destination IP address" << std::endl;  
  66.     std::cin >> ipstr;  
  67.     destip = inet_addr(ipstr.c_str());  
  68.     if (destip == INADDR_NONE)  
  69.     {  
  70.         std::cerr << "Bad IP address specified" << std::endl;  
  71.         return -1;  
  72.     }  
  73.       
  74.     // The inet_addr function returns a value in network byte order, but  
  75.     // we need the IP address in host byte order, so we use a call to  
  76.     // ntohl   
  77.     destip = ntohl(destip);  
  78.       
  79.     std::cout << "Enter the destination port" << std::endl;  
  80.     std::cin >> destport;  
  81.       
  82.     std::cout << std::endl;  
  83.     std::cout << "Number of packets you wish to be sent:" << std::endl;  
  84.     std::cin >> num;  
  85.       
  86.     // Now, we'll create a RTP session, set the destination, send some  
  87.     // packets and poll for incoming data.  
  88.       
  89.     RTPUDPv4TransmissionParams transparams;  
  90.     RTPSessionParams sessparams;  
  91.       
  92.     // IMPORTANT: The local timestamp unit MUST be set, otherwise  
  93.     //            RTCP Sender Report info will be calculated wrong  
  94.     // In this case, we'll be sending 10 samples each second, so we'll  
  95.     // put the timestamp unit to (1.0/10.0)  
  96.     sessparams.SetOwnTimestampUnit(1.0/10.0);         
  97.       
  98.     sessparams.SetAcceptOwnPackets(true);  
  99.     transparams.SetPortbase(portbase);  
  100.     status = sess.Create(sessparams,&transparams);    
  101.     checkerror(status);  
  102.       
  103.     RTPIPv4Address addr(destip,destport);  
  104.       
  105.     status = sess.AddDestination(addr);  
  106.     checkerror(status);  
  107.       
  108.     for (i = 1 ; i <= num ; i++)  
  109.     {  
  110.         printf("\nSending packet %d/%d\n",i,num);  
  111.           
  112.         // send the packet   
  113.         status = sess.SendPacket((void *)"1234567890",10,0,false,10);  
  114.         checkerror(status);  
  115.           
  116.         sess.BeginDataAccess();  
  117.           
  118.         // check incoming packets   
  119.         if (sess.GotoFirstSourceWithData())  
  120.         {  
  121.             do  
  122.             {  
  123.                 RTPPacket *pack;  
  124.                 while ((pack = sess.GetNextPacket()) != NULL)  
  125.                 {  
  126.                     // You can examine the data here  
  127.                     printf("Got packet !\n");  
  128.   
  129.                     std::cout << "Got packet with "   
  130.                         << "extended sequence number "   
  131.                         << pack->GetExtendedSequenceNumber()   
  132.                         << " from SSRC " << pack->GetSSRC()   
  133.                         << std::endl;  
  134.   
  135.                     int dataLength = pack->GetPayloadLength();  
  136.                     pfBuffer =(unsigned char*)pack->GetPayloadData();  
  137.                     pBuffer = new BYTE[dataLength + 1];  
  138.                     memcpy(pBuffer, pfBuffer, dataLength);  
  139.                     pBuffer[dataLength] = 0;  
  140.                     std::cout << pBuffer << std::endl;  
  141.                     delete []pBuffer;  
  142.                     pBuffer = NULL;  
  143.                     // we don't longer need the packet, so  
  144.                     // we'll delete it   
  145.                     sess.DeletePacket(pack);  
  146.                 }  
  147.             } while (sess.GotoNextSourceWithData());  
  148.         }  
  149.           
  150.         sess.EndDataAccess();  
  151.   
  152. #ifndef RTP_SUPPORT_THREAD   
  153.         status = sess.Poll();  
  154.         checkerror(status);  
  155. #endif // RTP_SUPPORT_THREAD  
  156.           
  157.         RTPTime::Wait(RTPTime(1,0));  
  158.     }  
  159.       
  160.     sess.BYEDestroy(RTPTime(10,0),0,0);  
  161.   
  162. #ifdef WIN32   
  163.     WSACleanup();  
  164. #endif // WIN32   
  165.     return 0;  
  166. }  

 

原创粉丝点击