jrtplib3.9.1 example2

  
  
  
  
这个例子好像有点问题,自身运行的话,自身发送的那个160长度的silencebuffer在本窗口是无法收到的。而且在一个1分钟的循环内,反复地调用sendpacket发送silencebuffer,也不知道是何用意。把本机端口和目标端口都改正成相同的,也无法接收到。
后来用例子1做发送方,用本例子做接收方,这样可以收到从例子1里发出的数据。截图如下:
jrtplib3.9.1 example2_第1张图片
用本例发送,例子3接收,也能收到发来的数据,但是还是不明白为什么本例为何要反复发送同一个数据?也许仅仅是个例子而已。先这样吧。
silencebuffer
#include "rtpsession.h"
#include "rtpsessionparams.h"
#include "rtpudpv4transmitter.h"
#include "rtpipv4address.h"
#include "rtptimeutilities.h"
#include "rtppacket.h"
#include <stdlib.h>
#include <iostream>

using namespace jrtplib ;

int main ( void )
{
#ifdef WIN32
WSADATA dat ;
WSAStartup ( MAKEWORD ( 2 , 2 ), & dat );
#endif // WIN32

RTPSession session ;

RTPSessionParams sessionparams ;
sessionparams . SetOwnTimestampUnit ( 1.0 / 8000.0 );

RTPUDPv4TransmissionParams transparams ;
transparams . SetPortbase ( 8000 );

int status = session . Create ( sessionparams , & transparams );
if ( status < 0 )
{
std :: cerr << RTPGetErrorString ( status ) << std :: endl ;
exit ( - 1 );
}

uint8_t localip [] = { 127 , 0 , 0 , 1 };
RTPIPv4Address addr ( localip , 9000 );

status = session . AddDestination ( addr );
if ( status < 0 )
{
std :: cerr << RTPGetErrorString ( status ) << std :: endl ;
exit ( - 1 );
}

session . SetDefaultPayloadType ( 96 );
session . SetDefaultMark ( false );
session . SetDefaultTimestampIncrement ( 160 );

uint8_t silencebuffer [ 160 ];
for ( int i = 0 ; i < 160 ; i ++ )
silencebuffer [ i ] = 128 ;

RTPTime delay ( 0.020 );
RTPTime starttime = RTPTime :: CurrentTime ();

bool done = false ;
while ( ! done )
{
status = session . SendPacket ( silencebuffer , 160 );
if ( status < 0 )
{
std :: cerr << RTPGetErrorString ( status ) << std :: endl ;
exit ( - 1 );
}

session . BeginDataAccess ();
if ( session . GotoFirstSource ())
{
do
{
RTPPacket * packet ;

while (( packet = session . GetNextPacket ()) != 0 )
{
std :: cout << "Got packet with "
<< "extended sequence number "
<< packet -> GetExtendedSequenceNumber ()
<< " from SSRC " << packet -> GetSSRC ()
<< std :: endl ;
session . DeletePacket ( packet );
}
} while ( session . GotoNextSource ());
}
session . EndDataAccess ();

RTPTime :: Wait ( delay );

RTPTime t = RTPTime :: CurrentTime ();
t -= starttime ;
if ( t > RTPTime ( 60.0 ))
done = true ;
}

delay = RTPTime ( 10.0 );
session . BYEDestroy ( delay , "Time's up" , 9 );
#ifdef WIN32
WSACleanup ();
#endif // WIN32
return 0 ;
}

你可能感兴趣的:(jrtplib3.9.1 example2)