【流媒體】jrtplib—VS2010下RTP开源协议库JRTPLIB3.9.1编译
一、JRTPLIB簡(jiǎn)介
老外用C++編寫(xiě)的開(kāi)源RTP協(xié)議庫(kù),用來(lái)進(jìn)行實(shí)時(shí)數(shù)據(jù)傳輸,可以運(yùn)行在 Windows、Linux、 FreeBSD、Solaris、Unix和VxWorks 等多種操作系統(tǒng)上,主頁(yè)為:http://research.edm.uhasselt.be/~jori/page/index.php?n=Main.HomePage
二、相關(guān)下載
jrtplib: http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib
jthread: http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jthread
cmake: http://www.cmake.org/cmake/resources/software.html
三、 編譯步驟
1 下載jrtplib和jthread并解壓縮。閱讀README。
2 編譯jthread生成jthread.lib和jthread_d.lib。
① 打開(kāi)cmake,添加好輸入(where..)和輸出路徑(where to…),完成configure配置(選visual studio 10),配置結(jié)果如下圖:
② 點(diǎn)擊generate,生成VS2010工程文件
③ 打開(kāi)工程文件并編譯,在debug和release下分別生成jthread.lib和jthread_d.lib
編譯的具體方法為:選擇Solution Explorer里的 Solution jthread,點(diǎn)右鍵,運(yùn)行"Rebuild Solution";如編譯無(wú)錯(cuò)誤,再選擇INSTALL項(xiàng)目,運(yùn)行"Build"。
④ 如果編譯成功(如下圖),會(huì)在C:\Program Files\jthread的include\jthread下生成頭文件;在lib下生成lib和cmake文件
溫馨提示:在win7下,你必須擁有管理者權(quán)限,否則編譯不會(huì)通過(guò),因?yàn)闊o(wú)法在C:\Program Files創(chuàng)建jthread文件,當(dāng)然你可以手動(dòng)創(chuàng)建。
3 編譯jrtplib生成jrtplib.lib和jrtplib_d.lib。
① 同2-①,其中configure會(huì)稍微麻煩一些,詳細(xì)配置結(jié)果如下:
② 點(diǎn)擊generate,生成VS2010工程文件
③ 打開(kāi)工程文件并編譯,在debug和release下分別生成jrtplib_d.lib和jrtplib.lib
④ 編譯成功(如下圖),在C:\Program Files\jrtplib下include\jrtplib3下會(huì)生成一堆頭文件;在lib下會(huì)生成jrtplib_d.lib和jrtplib.lib以及cmake文件
說(shuō)明:網(wǎng)上提到的一些用VS2008和VC6.0方法中提到了兩個(gè)細(xì)節(jié): 一是要把"jmutex.h"和"jthread.h"兩個(gè)頭文件放入jrtplib/src目錄下,二是要把src文件夾下所有頭文件中的<jmutex.h>和<jthread.h>語(yǔ)句修改為"jmutex.h"和"jthread.h"。我在編譯時(shí)沒(méi)有處理這兩個(gè)細(xì)節(jié)成功了,后續(xù)調(diào)試出現(xiàn)相應(yīng)問(wèn)題相應(yīng)修改一下即可。
四、 使用實(shí)例
1 添加庫(kù)
①步驟一:
方法1. 將編譯生成的jrtplib.lib和jthread.lib庫(kù)拷貝到“*:\Program Files\Microsoft Visual Studio 10.0\VC\lib”下面
方法2. 將編譯生成的四個(gè)lib庫(kù)庫(kù)拷貝到當(dāng)前工程的cpp文件下
②步驟二:
方法1. [菜單]“項(xiàng)目->屬性->配置屬性->連接器->輸入->附加依賴(lài)項(xiàng)”里填寫(xiě)“jrtplib.lib;jthread.lib;WS2_32.lib”
方法2. pragma 方式,在stdafx.h文件中 添加
復(fù)制代碼
ifdef DEBUG
#pragma comment(lib, "jrtplib_d.lib")
#pragma comment(lib,"jthread_d.lib")
#pragma comment(lib,"WS2_32.lib")
else
#pragma comment(lib, "jrtplib.lib")
#pragma comment(lib,"jthread.lib")
#pragma comment(lib,"WS2_32.lib")
endif
復(fù)制代碼
2 添加頭文件
①步驟一:將所有的.h文件放到一起,如myJRTPLIBHeader里面,再添加include
②步驟二:
方法1.“項(xiàng)目->屬性->配置屬性->C/C++->常規(guī)->附加包含目錄”
方法2.“工具->選項(xiàng)->項(xiàng)目和解決方案->C++ 目錄”,選擇對(duì)應(yīng)平臺(tái),然后添加所需“包括文件”目錄(此法VS2010不通)
3 測(cè)試代碼(sample1)
cpp文件:
復(fù)制代碼
// jrtplibTest.cpp : 定義控制臺(tái)應(yīng)用程序的入口點(diǎn)。
//
include “stdafx.h”
// 頭文件
include “rtpsession.h”
include “rtpudpv4transmitter.h”
include “rtpipv4address.h”
include “rtpsessionparams.h”
include “rtperrors.h”
ifndef WIN32
include
include
else
include
endif // WIN32
include
include
include
include
using namespace jrtplib;
//
// 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;// First, we'll ask for the necessary informationstd::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;// 獲得接收端的IP地址和端口號(hào)
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);
// 創(chuàng)建RTP會(huì)話(huà)
status = sess.Create(sessparams,&transparams);
checkerror(status);RTPIPv4Address addr(destip,destport);
// 指定RTP數(shù)據(jù)接收端
status = sess.AddDestination(addr);
checkerror(status);for (i = 1 ; i <= num ; i++)
{printf("\nSending packet %d/%d\n",i,num);// send the packetstatus = sess.SendPacket((void *)"1234567890",10,0,false,10);checkerror(status);sess.BeginDataAccess();// check incoming packetsif (sess.GotoFirstSourceWithData()){do{RTPPacket *pack;while ((pack = sess.GetNextPacket()) != NULL){// You can examine the data hereprintf("Got packet !\n");// we don't longer need the packet, so// we'll delete itsess.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;
}
復(fù)制代碼
4 下載
在VS2010+Win7下編譯好的JRTPLIB庫(kù)及相關(guān)頭文件下載:(剛傳CSDN,現(xiàn)在打不開(kāi),等等,明天補(bǔ)上…)
補(bǔ)充:下載(猛擊)
Ref/Related
1 http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib
2 http://research.edm.uhasselt.be/jori/jrtplib/documentation/index.html
3 http://blog.csdn.net/nickche300/article/details/6408099
4 http://blog.csdn.net/sunloverain2/article/details/5398694
5 http://blog.csdn.net/aaronalan/article/details/5153604
轉(zhuǎn)載自這里
總結(jié)
以上是生活随笔為你收集整理的【流媒體】jrtplib—VS2010下RTP开源协议库JRTPLIB3.9.1编译的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: H.264 基础及 RTP 封包详解
- 下一篇: vc picture控件载入背景图,随控