1 下載下傳jrtplib和jthread并解壓縮。閱讀README。
2 編譯jthread生成jthread.lib和jthread_d.lib。
① 打開cmake,添加好輸入(where..)和輸出路徑(where to...),完成configure配置(選visual studio 10),配置結果如下圖:(編譯器選擇的時候明明是12,非得選11,很狗血)
②點選generate,生成VS2010工程檔案
③打開工程檔案并編譯,在debug和release下分别生成jthread.lib和jthread_d.lib
編譯的具體方法為:選擇Solution Explorer裡的 Solutionjthread,點右鍵,運作"Rebuild Solution";如編譯無錯誤,再選擇INSTALL項目,運作"Build"。
④如果編譯成功(如下圖),會在C:\Program Files\jthread的include\jthread下生成頭檔案;在lib下生成lib和cmake檔案
溫馨提示:在win7下,你必須擁有管理者權限,以管理者身份啟動VS,否則編譯不會通過,因為無法在C:\Program Files建立jthread檔案,當然你可以手動建立。
3 編譯jrtplib生成jrtplib.lib和jrtplib_d.lib。
①同2-①,其中configure會稍微麻煩一些,詳細配置結果如下:
②點選generate,生成VS2010工程檔案
③打開工程檔案并編譯,在debug和release下分别生成jrtplib_d.lib和jrtplib.lib
④ 編譯成功(如下圖),在C:\Program Files\jrtplib下include\jrtplib3下會生成一堆頭檔案;在lib下會生成jrtplib_d.lib和jrtplib.lib以及cmake檔案
說明:網上提到的一些用VS2008和VC6.0方法中提到了兩個細節: 一是要把"jmutex.h"和"jthread.h"兩個頭檔案放入jrtplib/src目錄下,二是要把src檔案夾下所有頭檔案中的<jmutex.h>和<jthread.h>語句修改為"jmutex.h"和"jthread.h"。(未遇到,可能與編譯器有關)
我在編譯時沒有處理這兩個細節成功了,後續調試出現相應問題相應修改一下即可。
四、 使用執行個體
1 添加庫
①步驟一:
方法1. 将編譯生成的jrtplib.lib和jthread.lib庫拷貝到“*:\Program Files\Microsoft Visual Studio 10.0\VC\lib”下面
方法2. 将編譯生成的四個lib庫庫拷貝到目前工程的cpp檔案下
②步驟二:
方法1. [菜單]“項目->屬性->配置屬性->連接配接器->輸入->附加依賴項”裡填寫“jrtplib.lib;jthread.lib;WS2_32.lib”
方法2. pragma 方式,在stdafx.h檔案中 添加
#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
2 添加頭檔案
①步驟一:将所有的.h檔案放到一起,如myJRTPLIBHeader裡面,再添加include
②步驟二:
方法1.“項目->屬性->配置屬性->C/C++->正常->附加包含目錄”
方法2.“工具->選項->項目和解決方案->C++ 目錄”,選擇對應平台,然後添加所需“包括檔案”目錄(此法VS2010不通)
3 測試代碼(sample1)
cpp檔案:
// jrtplibTest.cpp : 定義控制台應用程式的入口點。
//
#include "stdafx.h"
// 頭檔案
#include "rtpsession.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtpsessionparams.h"
#include "rtperrors.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;
//
// 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 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;
// 獲得接收端的IP位址和端口号
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);
// 建立RTP會話
status = sess.Create(sessparams,&transparams);
checkerror(status);
RTPIPv4Address addr(destip,destport);
// 指定RTP資料接收端
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");
// 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;
}
4 下載下傳
在VS2010+Win7下編譯好的JRTPLIB庫及相關頭檔案下載下傳:(剛傳CSDN,現在打不開,等等,明天補上...)
補充:下載下傳(猛擊)
Ref/Related
1http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib
2http://research.edm.uhasselt.be/jori/jrtplib/documentation/index.html
3http://blog.csdn.net/nickche300/article/details/6408099
4http://blog.csdn.net/sunloverain2/article/details/5398694
5http://blog.csdn.net/aaronalan/article/details/5153604