当前位置:首页 » 编程软件 » jrtplib编译

jrtplib编译

发布时间: 2024-11-01 18:06:01

⑴ 求一份c语言的RTP音频传输源码

1.项目前期工作(配置好环境)
2.发送端文件编写(见下面的send.cpp)
3.接收端文件编写(见下面的receive.cpp)
4.编译文件
(1)发送端
g++-osendsend.cpp-I/usr/local/include/jrtplib3/-ljrtp
(2)接收端
g++-oreceivereceive.cpp-I/usr/local/include/jrtplib3/-ljrtp
附录:
(1)send.cpp
[cpp]
#include"rtpsession.h"
#include"rtppacket.h"
#include"rtpudpv4transmitter.h"
#include"rtpipv4address.h"
#include"rtpsessionparams.h"
#include"rtperrors.h"
#include"rtpmemorymanager.h"
#ifndefWIN32
#include<netinet/in.h>
#include<arpa/inet.h>
#else
#include<winsock2.h>
#endif//WIN32
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<string>

//
//.Ifso,itdisplaysanerror
//messageandexists.
//

voidcheckerror(intrtperr)
{
if(rtperr<0)
{
std::cout<<"ERROR:"<<RTPGetErrorString(rtperr)<<std::endl;
exit(-1);
}
}

//
//Themainroutine
//

#ifdefRTP_SUPPORT_THREAD

classMyMemoryManager:publicRTPMemoryManager
{
public:
MyMemoryManager()
{
mutex.Init();
alloccount=0;
freecount=0;
}
~MyMemoryManager()
{
std::cout<<"alloc:"<<alloccount<<"free:"<<freecount<<std::endl;
}
void*AllocateBuffer(size_tnumbytes,intmemtype)
{
mutex.Lock();
void*buf=malloc(numbytes);
std::cout<<"Allocated"<<numbytes<<"bytesatlocation"<<buf<<"(memtype="<<memtype<<")"<<std::endl;
alloccount++;
mutex.Unlock();
returnbuf;
}

voidFreeBuffer(void*p)
{
mutex.Lock();
std::cout<<"Freeingblock"<<p<<std::endl;
freecount++;
free(p);
mutex.Unlock();
}
private:
intalloccount,freecount;
JMutexmutex;
};

#else

classMyMemoryManager:publicRTPMemoryManager
{
public:
MyMemoryManager()
{
alloccount=0;
freecount=0;
}
~MyMemoryManager()
{
std::cout<<"alloc:"<<alloccount<<"free:"<<freecount<<std::endl;
}
void*AllocateBuffer(size_tnumbytes,intmemtype)
{
void*buf=malloc(numbytes);
std::cout<<"Allocated"<<numbytes<<"bytesatlocation"<<buf<<"(memtype="<<memtype<<")"<<std::endl;
alloccount++;
returnbuf;
}

voidFreeBuffer(void*p)
{
std::cout<<"Freeingblock"<<p<<std::endl;
freecount++;
free(p);
}
private:
intalloccount,freecount;
};

#endif//RTP_SUPPORT_THREAD

intmain(void)
{
#ifdefWIN32
WSADATAdat;
WSAStartup(MAKEWORD(2,2),&dat);
#endif//WIN32

MyMemoryManagermgr;
RTPSessionsess(&mgr);
uint16_tportbase,destport;
uint32_tdestip;
std::stringipstr;
intstatus,i,num;

//First,we'

std::cout<<"Enterlocalportbase:"<<std::endl;
std::cin>>portbase;
std::cout<<std::endl;

std::cout<<"EnterthedestinationIPaddress"<<std::endl;
std::cin>>ipstr;
destip=inet_addr(ipstr.c_str());
if(destip==INADDR_NONE)
{
std::cerr<<"BadIPaddressspecified"<<std::endl;
return-1;
}

//Theinet_,but
//,soweuseacallto
//ntohl
destip=ntohl(destip);

std::cout<<"Enterthedestinationport"<<std::endl;
std::cin>>destport;

std::cout<<std::endl;
std::cout<<":"<<std::endl;
std::cin>>num;

//Now,we'llcreateaRTPsession,setthedestination,sendsome
//packetsandpollforincomingdata.

;
RTPSessionParamssessparams;

//IMPORTANT:,otherwise
//
//Inthiscase,we',sowe'll
//putthetimestampunitto(1.0/10.0)
sessparams.SetOwnTimestampUnit(1.0/10.0);

sessparams.SetAcceptOwnPackets(true);
transparams.SetPortbase(portbase);
status=sess.Create(sessparams,&transparams);
checkerror(status);

RTPIPv4Addressaddr(destip,destport);

status=sess.AddDestination(addr);
checkerror(status);

for(i=1;i<=num;i++)
{
printf(" Sendingpacket%d/%d ",i,num);

//sendthepacket
status=sess.SendPacket((void*)"1234567890",10,0,false,10);
checkerror(status);

sess.BeginDataAccess();

//checkincomingpackets
if(sess.GotoFirstSourceWithData())
{
do
{
RTPPacket*pack;

while((pack=sess.GetNextPacket())!=NULL)
{
//Youcanexaminethedatahere
printf("Gotpacket! ");

//wedon'tlongerneedthepacket,so
//we'lldeleteit
sess.DeletePacket(pack);
}
}while(sess.GotoNextSourceWithData());
}

sess.EndDataAccess();

#ifndefRTP_SUPPORT_THREAD
status=sess.Poll();
checkerror(status);
#endif//RTP_SUPPORT_THREAD

RTPTime::Wait(RTPTime(1,0));
}

sess.BYEDestroy(RTPTime(10,0),0,0);

#ifdefWIN32
WSACleanup();
#endif//WIN32
return0;
}
(2)receive.cpp
[cpp]viewplain
#include"rtpsession.h"
#include"rtppacket.h"
#include"rtpudpv4transmitter.h"
#include"rtpipv4address.h"
#include"rtpsessionparams.h"
#include"rtperrors.h"
#ifndefWIN32
#include<netinet/in.h>
#include<arpa/inet.h>
#else
#include<winsock2.h>
#endif//WIN32
#include"rtpsourcedata.h"
#include<stdlib.h>
#include<stdio.h>
#include<iostream>
#include<string>

//
//.Ifso,itdisplaysanerror
//messageandexists.
//

voidcheckerror(intrtperr)
{
if(rtperr<0)
{
std::cout<<"ERROR:"<<RTPGetErrorString(rtperr)<<std::endl;
exit(-1);
}
}

//
//Thenewclassroutine
//

classMyRTPSession:publicRTPSession
{
protected:
voidOnNewSource(RTPSourceData*dat)
{
if(dat->IsOwnSSRC())
return;

uint32_tip;
uint16_tport;

if(dat->GetRTPDataAddress()!=0)
{
constRTPIPv4Address*addr=(constRTPIPv4Address*)(dat->GetRTPDataAddress());
ip=addr->GetIP();
port=addr->GetPort();
}
elseif(dat->GetRTCPDataAddress()!=0)
{
constRTPIPv4Address*addr=(constRTPIPv4Address*)(dat->GetRTCPDataAddress());
ip=addr->GetIP();
port=addr->GetPort()-1;
}
else
return;

RTPIPv4Addressdest(ip,port);
AddDestination(dest);

structin_addrinaddr;
inaddr.s_addr=htonl(ip);
std::cout<<"Addingdestination"<<std::string(inet_ntoa(inaddr))<<":"<<port<<std::endl;
}

voidOnBYEPacket(RTPSourceData*dat)
{
if(dat->IsOwnSSRC())
return;

uint32_tip;
uint16_tport;

if(dat->GetRTPDataAddress()!=0)
{
constRTPIPv4Address*addr=(constRTPIPv4Address*)(dat->GetRTPDataAddress());
ip=addr->GetIP();
port=addr->GetPort();
}
elseif(dat->GetRTCPDataAddress()!=0)
{
constRTPIPv4Address*addr=(constRTPIPv4Address*)(dat->GetRTCPDataAddress());
ip=addr->GetIP();
port=addr->GetPort()-1;
}
else
return;

RTPIPv4Addressdest(ip,port);
DeleteDestination(dest);

structin_addrinaddr;
inaddr.s_addr=htonl(ip);
std::cout<<"Deletingdestination"<<std::string(inet_ntoa(inaddr))<<":"<<port<<std::endl;
}

voidOnRemoveSource(RTPSourceData*dat)
{
if(dat->IsOwnSSRC())
return;
if(dat->ReceivedBYE())
return;

uint32_tip;
uint16_tport;

if(dat->GetRTPDataAddress()!=0)
{
constRTPIPv4Address*addr=(constRTPIPv4Address*)(dat->GetRTPDataAddress());
ip=addr->GetIP();
port=addr->GetPort();
}
elseif(dat->GetRTCPDataAddress()!=0)
{
constRTPIPv4Address*addr=(constRTPIPv4Address*)(dat->GetRTCPDataAddress());
ip=addr->GetIP();
port=addr->GetPort()-1;
}
else
return;

RTPIPv4Addressdest(ip,port);
DeleteDestination(dest);

structin_addrinaddr;
inaddr.s_addr=htonl(ip);
std::cout<<"Deletingdestination"<<std::string(inet_ntoa(inaddr))<<":"<<port<<std::endl;
}
};

//
//Themainroutine
//

intmain(void)
{
#ifdefWIN32
WSADATAdat;
WSAStartup(MAKEWORD(2,2),&dat);
#endif//WIN32

MyRTPSessionsess;
uint16_tportbase;
std::stringipstr;
intstatus,i,num;

//First,we'

std::cout<<"Enterlocalportbase:"<<std::endl;
std::cin>>portbase;
std::cout<<std::endl;

std::cout<<std::endl;
std::cout<<"Numberofsecondsyouwishtowait:"<<std::endl;
std::cin>>num;

//Now,we'llcreateaRTPsession,setthedestination
//andpollforincomingdata.

;
RTPSessionParamssessparams;

//IMPORTANT:,otherwise
//
//Inthiscase,we'.
sessparams.SetOwnTimestampUnit(1.0/8000.0);

sessparams.SetAcceptOwnPackets(true);
transparams.SetPortbase(portbase);
status=sess.Create(sessparams,&transparams);
checkerror(status);

for(i=1;i<=num;i++)
{
sess.BeginDataAccess();

//checkincomingpackets
if(sess.GotoFirstSourceWithData())
{
do
{
RTPPacket*pack;

while((pack=sess.GetNextPacket())!=NULL)
{
//Youcanexaminethedatahere
printf("Gotpacket! ");

//wedon'tlongerneedthepacket,so
//we'lldeleteit
sess.DeletePacket(pack);
}
}while(sess.GotoNextSourceWithData());
}

sess.EndDataAccess();

#ifndefRTP_SUPPORT_THREAD
status=sess.Poll();
checkerror(status);
#endif//RTP_SUPPORT_THREAD

RTPTime::Wait(RTPTime(1,0));
}

sess.BYEDestroy(RTPTime(10,0),0,0);

#ifdefWIN32
WSACleanup();
#endif//WIN32
return0;
}

⑵ jrtplib-3.11.1怎么在ubuntu上编译安装

1、环境Ubuntu10.04系统,(如果是其他系统可以跳过第2步) 2、安装库支持和alien等 sudo apt-get install build-essential sudo apt-get install libstdc++5 sudo apt-get install alien sudo apt-get install g++-multilib 若某步出现安装不了...

热点内容
怎么给自己手机写一个脚本 发布:2024-11-01 20:23:41 浏览:241
c语言大小写判断 发布:2024-11-01 20:21:53 浏览:130
php的点餐系统源码 发布:2024-11-01 20:13:53 浏览:714
拜占庭算法 发布:2024-11-01 20:10:31 浏览:357
xcode编译参数 发布:2024-11-01 20:00:04 浏览:665
苹果5怎么设置密码锁屏 发布:2024-11-01 19:54:55 浏览:124
宝塔上传文件夹 发布:2024-11-01 19:39:50 浏览:257
java云编译器 发布:2024-11-01 19:34:24 浏览:385
免费源码分享网 发布:2024-11-01 19:29:19 浏览:855
硬盘8mb缓存 发布:2024-11-01 19:20:02 浏览:192