转:jrtp例二

1.设置基本参数    
RTPSession   m_RTPSocket;              
m_RTPSocket.Create(m_SPort);
m_RTPSocket.SetTimestampUnit(1.0/25.0);
m_RTPSocket.SetSessionBandwidth(900.0);
m_RTPSocket.SetMaxPacketSize(65535);
m_RTPSocket.SetDefaultPayloadType(0);
m_RTPSocket.SetDefaultMark(false);
m_RTPSocket.SetDefaultTimeStampIncrement(10);
2.发送
int   status   = m_RTPSocket.SendPacket(pFrame,wSize,1,name,10);
3,接收
int   size   =   0;
SOCKET   sockRtp,sockRtcp;
struct   timeval   rttprev   =   {0,0},rtt,tv;
fd_set   fdset;
bool   frist   =   true;
int   port   =   ((CRNetVideoCtrl*)m_pMainClass)-> m_destport;
if(port   ==   -1)
StopThread();
RTPSession   m_RTPSocket;
m_RTPSocket.Create(port);
m_RTPSocket.SetSessionBandwidth(64);

m_RTPSocket.GetRTPSocket(&sockRtp);
m_RTPSocket.GetRTCPSocket(&sockRtcp);

m_pDecoder   =   new   CVideoDecode();
m_pDecoder-> dec_init(1);  

unsigned   char*   pBuffer   =   new   unsigned   char   [320*240*2];

while(!m_bClose){
tv.tv_sec   =   0;
tv.tv_usec   =   100000;
FD_ZERO(&fdset);
FD_SET(sockRtcp,&fdset);
FD_SET(sockRtp,&fdset);
int   maxSize   =   max(sockRtp,   sockRtcp);
int   selectRet   =   select(maxSize   +   1,&fdset,NULL,NULL,&tv);
if   (-1   ==   selectRet   ||   0   ==   selectRet)
continue;
/*   poll   for   incoming   data   *///调用这个,这样才能够获得数据
m_RTPSocket.PollData();
/*   check   incoming   packets   *///原来是rtp数据包
if   (FD_ISSET(sockRtp,   &fdset)){

if   (m_RTPSocket.GotoFirstSourceWithData()){
RTPPacket   *pack;
while   ((pack   =   m_RTPSocket.GetNextPacket())   !=   NULL){
if(frist){
//检查是否是关键帧
if(pack-> IsMarked()){
if((CRNetVideoCtrl*)m_pMainClass){
m_pDecoder-> dec_main(pack-> GetPayload(),pBuffer,pack-> GetPayloadLength(),&size);
((CRNetVideoCtrl*)m_pMainClass)-> DecodeVideo(pBuffer,size);
TRACE( "Client   Received   IFrame\n ");
frist   =   false;
}
}
}
else{
//解码并显示
m_pDecoder-> dec_main(pack-> GetPayload(),pBuffer,pack-> GetPayloadLength(),&size);
((CRNetVideoCtrl*)m_pMainClass)-> DecodeVideo(pBuffer,size);
}
delete   pack;
}
}
}
if   (FD_ISSET(sockRtcp,   &fdset)){
if   (m_RTPSocket.GotoFirstSource())
{
do
{
RTPSourceData   *srcdat;
srcdat   =   m_RTPSocket.GetCurrentSourceInfo();
if   (NULL   !=   srcdat)
{
rtt   =   srcdat-> INF_GetRoundTripTime();
if   (rtt.tv_sec   !=   0   ||   rtt.tv_usec   !=   0)
{
double   t;
t   =   (double)rtt.tv_sec;
t   +=   ((double)rtt.tv_usec)/1000000.0;
t   *=   1000.0;   //   we   want   milliseconds;
TRACE( "rtt:   %f   ms\n ",   (float)t);
rttprev   =   rtt;
}
if   (parent-> m_canSend)
{
sprintf(msg,   "丢包:   %f\n ",   srcdat-> RR_GetPacketsLost());
sprintf(msg,   "包序号:   %d\n ",   srcdat-> RR_GetExtendedHighestSequenceNumber());
sprintf(msg,   "jitter:   %d\n ",   srcdat-> RR_GetJitter());
reportNum   =   0;
}
srcdat-> FlushPackets();   //   we   don 't   need   the   actual   data
}
srcdat   =   NULL;
}   while   (m_RTPSocket.GotoNextSource());
}

}

}

if(m_pDecoder)
delete   m_pDecoder;
m_pDecoder   =   NULL;

delete   []pBuffer;

return   1L;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值