一些介绍:
http://doserver.net/read.php?1028
http://doserver.net/read.php/1027.htm
http://doserver.net/read.php/1685.htm
现在开始对几个example分析一下,不过,就没有文档吗?
这里,详细的解释了几个例子:
http://hi.baidu.com/hanyuejun2006/blog/item/8a8ed939a9e344f53b87ce23.html
这里算一个:
http://xiyong8260.blog.163.com/blog/static/665146212008824112748499/
重要的是里面还讲了一些嵌入式方面的内容。
收和发的例子:
http://blog.chinaunix.net/u2/61880/showart_728528.html
比较详细的系列文章:http://www.cnitblog.com/tinnal/archive/2009/01/01/53342.html
PS:关于POLL的问题,发现只有调用者这个函数的时候,才会查询是否有包发过来,才会接收包。
If you're not using the poll thread, this function must be called regularly to process incoming data and to send RTCP data when necessary.
关于例程可以分为以下几个部分:
(一)BASIC USAGE: 1)SET PARAMS 关于会话的参数 2)SET TRANSPARAMS 关于传输层的参数 3)CREATE SESSION 创建会话 4)SET PACKET ATTRIBUTES 包的属性设置 5)ADD DESTINATION 添加目的地址 6)PREPARE DATA 准备数据 7)SEND PACKET 发送包 8)DATAACCESS 数据处理(锁定操作,是指此时POLL线程不能改变正在处理的数据) 9)BYE 退出会话 example: #include "rtpsession.h" #include "rtppacket.h" #include "rtpudpv4transmitter.h" #include "rtpsessionparams.h" #include "rtperrors.h" #include "rtpipv4address.h" #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string>
void checkerror(int rtperr) { if(rtperr < 0) { std::cout<<"ERROR:"<<RTPGetErrorString(rtperr)<<std::endl; exit(-1); } }
int main() { RTPSession sess; uint16_t portbase; int status;
//set params
RTPSessionParams sessparams; sessparams.SetOwnTimestampUnit(1.0/10.0); sessparams.SetAcceptOwnPackets(true);
//set transparams
RTPUDPv4TransmissionParams transparams; transparams.SetPortbase(8000);
//create a session
status = sess.Create(sessparams, &transparams); checkerror(status);
//set default packet attributes
sess.SetDefaultPayloadType(0); sess.SetDefaultMark(false); sess.SetDefaultTimestampIncrement(10);
//destination address
uint16_t destport; uint32_t destip; std::string ipstr; std::cout<<"Enter the IP: "<<std::endl; std::cin>>ipstr; destip = inet_addr(ipstr.c_str()); if(destip == INADDR_NONE) { std::cerr<<"Bad IP"<<std::endl; exit(-1); } destip = ntohl(destip); //uint8_t localip[] = {192, 168, 0, 3};
RTPIPv4Address addr(destip, 8000);
//add destination
status = sess.AddDestination(addr); checkerror(status);
//prepare payload data
uint8_t silencebuffer[160]; for(int i = 0; i < 160; i++) { silencebuffer[i] = 128; }
//for time checking
RTPTime delay(0.020); RTPTime starttime = RTPTime::CurrentTime();
bool done = false; sess.Poll();
while(!done) { status = sess.SendPacket(silencebuffer, 160); checkerror(status);
//receive data
sess.BeginDataAccess(); if(sess.GotoFirstSource()) { do { RTPPacket *pack; while((pack = sess.GetNextPacket()) != NULL) { std::cout<<"Got packet!"<<std::endl; std::cout<<"sequence number: "<<pack->GetSequenceNumber()<<std::endl; std::cout<<"Extended SN: "<<pack->GetExtendedSequenceNumber()<<std::endl; std::cout<<"SSRC: "<<pack->GetSSRC()<<std::endl; std::cout<<"Data: "<<pack->GetPayloadData()<<std::endl; sess.DeletePacket(pack); } }while(sess.GotoNextSource()); } sess.EndDataAccess(); RTPTime::Wait(delay); RTPTime t = RTPTime::CurrentTime(); t -= starttime; if(t > RTPTime(6, 0)) { done = true; } } delay = RTPTime(10.0); sess.BYEDestroy(delay, "Time's up", 9); return(0); } |