这段代码谁帮忙解释下~~~~~~~~~~~
#include "Mp4ProxySrc.h"#define MSG_CLOSE MSG_USR_DEFINE1
#define MSG_INIT MSG_USR_DEFINE2
#define MSG_PLAY MSG_USR_DEFINE3
Mp4ProxySrc::Mp4ProxySrc()
:m_session(NULL),
m_invalid(false),
m_pts_us(0),
m_prebuf_us(0),
m_speed(1.0),
m_i_frame(false),
m_conn_fd(-1)
{
memset( m_content, 0, sizeof(m_content) );
}
Mp4ProxySrc::~Mp4ProxySrc()
{
DEL_CLIENT_OBJ(m_session);
if( GetWorkEnv() != NULL )
leave_uwe();
}
void Mp4ProxySrc::Close()
{
notify_int( GetUTOID(), MSG_CLOSE, 0 );
}
int Mp4ProxySrc::Init( const char* content )
{
ASSERT( content != NULL );
strncpy( m_content, content, sizeof(m_content)-1 );
m_invalid = false;
notify_int( GetUTOID(), MSG_INIT, 0 );
ASSERT( content != NULL );
strncpy( m_content, content, sizeof(m_content)-1 );
m_invalid = false;
notify_int( GetUTOID(), MSG_INIT, 0 );
return 0;
}
int Mp4ProxySrc::do_init()
{
StrParser parser(m_content);
if( ("rtsp://") == 0 ){
m_session = NEW_CLIENT_OBJ(ClientTcpSession);
((ClientTcpSession *)m_session)->SetDescribeURL((char *)m_content);
((ClientTcpSession *)m_session)->SetConnectURL((char *)m_content);
}else if( ("/") == 0 && parser.LocateStringCase(".sdp") > 0 ){
m_session = NEW_CLIENT_OBJ(ClientUdpSession);
if( ((ClientUdpSession *)m_session)->SetSdpFile((char *)m_content) == CLIENT_ERR )
return -1;
}else
return -1;
m_session->Init( m_conn_fd );
return 0;
}
int Mp4ProxySrc::Pause()
{
return m_session->Pause();
}
int Mp4ProxySrc::Play(uint64_t pts_us, uint64_t prebuf_us, float speed, bool i_frame_only )
{
m_pts_us = pts_us;
m_prebuf_us = prebuf_us;
m_speed = speed;
m_i_frame = i_frame_only;
notify_int( GetUTOID(), MSG_PLAY, 0 );
return 0;
}
int32_t Mp4ProxySrc::GetNextPackage( uint16_t trackID, unsigned char * package,
int32_t maxlen, uint64_t * pts_us, uint32_t * duration_us )
{
int16_t index = get_index(trackID);
int len = m_session->getNextPackage( index, package, maxlen, pts_us, duration_us );
if( len > 0 )
update_rtp_header( trackID, package, *pts_us );
return len;
}
int Mp4ProxySrc::handle_timeout( const URE_Time_Value & origts, long time_id, const void * act )
{
delete this;
return -1;
}
int Mp4ProxySrc::handle_message( const URE_Message & msg )
{
switch( msg.msgtype() ){
case MSG_SDP_READY:
m_sdp = m_session->GetSdp();
for( int i = 0; i < m_sdp->GetTrackNum(); i++)
m_trackID[i] = m_sdp->GetTrackID( i );
notify_int( m_creator, MSG_SDP_READY, 0 );
break;
case MSG_TYPE_MC:
do{
char sdp[4096];
m_sdp = m_session->GetSdp();
strncpy( sdp, m_sdp->GetMediaSdp(), 4096 );
for( int16_t i = 0; i < m_sdp->GetTrackNum(); i++)
strcat( sdp, m_sdp->GetTrackSdp( m_sdp->GetTrackID(i) ) );
DEL_CLIENT_OBJ(m_session);
m_session = NEW_CLIENT_OBJ(ClientUdpSession);
((ClientUdpSession *)m_session)->SetMCSdp(sdp);
((ClientUdpSession *)m_session)->Init(true);
}while(0);
break;
case MSG_RTSP_FAIL:
if( m_invalid == false ){
PR_DEBUG( "notify MSG_SRC_FAIL!" );
notify_int( m_creator, MSG_SRC_FAIL, 0 );
m_invalid = true;
}
break;
case MSG_CLOSE:
{
URE_Time_Value tv( 8, 0 );
schedule_timer( tv );
return 0;
}
case MSG_INIT:
if( do_init() < 0 ){
m_invalid = true;
PR_DEBUG( "notify MSG_SRC_FAIL!" );
notify_int( m_creator, MSG_SRC_FAIL, 0 );
}
break;
case MSG_PLAY:
m_session->Play( m_pts_us, m_prebuf_us, m_speed, m_i_frame );
break;
default:
msg.SetReceiver( m_creator );
notify( msg );
break;
}
return 0;
}