当前位置:首页 » 编程软件 » 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-23 08:03:03 浏览:916
安卓随机数有什么用 发布:2024-11-23 07:57:37 浏览:599
svn的服务器地址 发布:2024-11-23 07:57:37 浏览:430
编程跨平台 发布:2024-11-23 07:56:01 浏览:437
奔驰slk200怎么看配置 发布:2024-11-23 07:55:05 浏览:136
宝元数控编程 发布:2024-11-23 07:54:28 浏览:957
存储过程的语法结构 发布:2024-11-23 07:49:17 浏览:345
黑客工具源码 发布:2024-11-23 07:47:44 浏览:510
php长链接 发布:2024-11-23 07:41:40 浏览:754
linuxdump 发布:2024-11-23 07:06:05 浏览:394