![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: sip.cpp
- Revision:
- 108:18a3702650f3
- Parent:
- 107:cf1e43414adb
- Child:
- 109:a5b8264ffbbc
--- a/sip.cpp Mon Mar 16 14:05:05 2015 +0000 +++ b/sip.cpp Wed Mar 18 13:33:54 2015 +0000 @@ -23,7 +23,9 @@ strncpy( this->my_ip, my_ip, 20 ); this->my_ip[19] = 0; this->my_port = my_port; - this->my_rtp_port = fill_random_rtp_port(); + //this->my_rtp_port = fill_random_rtp_port(); + this->my_rtp_port = 0; + if( debug_rtp ) debug_msg("new with rtp port %d ", this->my_rtp_port ); this->my_ext = my_ext; itoa( this->my_ext, this->my_display, 10 ); this->peer_ext = peer_ext; @@ -56,6 +58,8 @@ if( debug_sip ) debug_msg("Building SIP ext :: %d | Port :: %d", id, my_port ); this->id = id; + this->my_ext = id; + this->my_port = my_port; fp = fopen( "/qspi/serverip.txt", "r"); if( fp == NULL){ @@ -119,12 +123,13 @@ this->my_ip[ 15 ] = '\0'; - this->my_port = my_port; if( debug_sip ) debug_msg("Fixado na porta %d", this->my_port ); - this->my_rtp_port = fill_random_rtp_port(); - this->my_ext = id; itoa( this->my_ext, this->my_display, 10 ); + + //this->my_rtp_port = fill_random_rtp_port(); + this->my_rtp_port = 0; + if( debug_rtp ) debug_msg("new with rtp port %d ", this->my_rtp_port ); fp = fopen( "/qspi/peerext.txt", "r"); if( fp == NULL ) { @@ -462,8 +467,10 @@ strcat( body, itoa_buffer ); strcat( body, "\r\n" ); strcat( body, "m=audio " ); + this->my_rtp_port = fill_random_rtp_port(); itoa( this->my_rtp_port, itoa_buffer, 10 ); strcat( body, itoa_buffer ); + if( debug_rtp ) debug_msg("Invite PKG with rtp port ( %d - %s )", this->my_rtp_port, itoa_buffer ); strcat( body, " RTP/AVP " ); itoa( 8, itoa_buffer, 10 ); strcat( body, itoa_buffer ); @@ -897,9 +904,13 @@ int Sip::get_my_rtp_port( void ){ return this->my_rtp_port; } -inline int Sip::fill_random_rtp_port(){ - // o range [ 16384 - 32767 ] eh configuravel no server - return ( ( this->my_ext + 16384 ) ); +int Sip::fill_random_rtp_port () +{ + static uint16_t port = 0; + port += 2; + //port &= 0x7fe; // 0 to 2046, always even + port &= 0x0e; // just for testing + return port + 16384; } void Sip::change_sip_server(){ @@ -1104,7 +1115,7 @@ ref = strtok( ref, " "); if( call == NULL ){ call = new VZ_call( this->my_ext, this->my_rtp_port, this->peer_ext, atoi( ref ) ); - //TODO colocar um debug que me exibe "rtp port client-server + if( debug_rtp ) debug_msg("Ok invite ( %d, %d, %d, %d ( %s ) ) ", this->my_ext, this->my_rtp_port, this->peer_ext, atoi( ref ), ref ); if( call == NULL ) memory_is_over = true; } char ans[ 1024 ]; @@ -1143,7 +1154,7 @@ ref = strtok( ref, " "); if( call == NULL ){ this->call = new VZ_call( this->my_ext, this->my_rtp_port, this->peer_ext, atoi( ref ) ); - if( dcolinas + if( debug_rtp ) debug_msg("Session in Progress ( %d, %d, %d, %d ( %s ) ) ", this->my_ext, this->my_rtp_port, this->peer_ext, atoi( ref ), ref ); if( call == NULL ) memory_is_over = true; } waiting = true; @@ -1158,7 +1169,6 @@ } } if( status == sip_waiting_trying ){ - //if( !( strncasecmp( buffer + 7, " 100 ", 5 ) ) ){ if( sip_response == 100 ){ if( debug_invite ) debug_msg("trying") set_status( status, sip_trying ); @@ -1179,6 +1189,8 @@ if( debug_invite ) debug_msg("sizeof( bye reply pkg ) :: %d\nServer request BYE to %d ext\nBye request received from *", strlen( ans ), my_ext ); + set_sip_rtp_port( 0 ); + listen_SIP_server_return = my_ext; } } @@ -1192,4 +1204,11 @@ int Sip::get_ext( void ){ return my_ext; } -int Sip::get_port( void ){ return my_port; } \ No newline at end of file +int Sip::get_port( void ){ return my_port; } + +int Sip::get_sip_rtp_port( void ){ return my_rtp_port; } + +void Sip::set_sip_rtp_port ( int new_rtp_port ) +{ + this->my_rtp_port = new_rtp_port; +} \ No newline at end of file