編譯jrtplib和jthread

 最近要做網絡監控視頻的傳輸,以前就接觸過圖像處理的基本東西,對於網絡稍微瞭解一點,對於視頻的編解碼則是一竅不通。這兩週查閱了不少資料,發現一般使

用的網路協議都是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 重新編譯的才行了。

附上一個在網上找到的例子:

  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. }  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章