Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
call.cpp
00001 #include "call.h" 00002 00003 VZ_call::VZ_call( int cb_ext, int cb_port, int rtp_server_ext, int rtp_server_port ){ 00004 this->cb_ext = cb_ext; 00005 this->cb_port = cb_port; 00006 00007 this->rtp_server_ext = rtp_server_ext; 00008 this->rtp_server_port = rtp_server_port; 00009 this->rtp_server.set_address( SERVER_IP, rtp_server_port ); 00010 rtp_sock.set_blocking( false, 0 ); 00011 this->rtp_sock.bind( cb_port ); // rtp port 00012 this->rtp_sock.init(); 00013 this->rtp = new RTP( this->cb_ext ); 00014 00015 if( rtp == NULL ) 00016 { 00017 memory_is_over = true; 00018 if( debug_memory ) vz_debug ("[%d] Call_Box cb allocation fail", this->cb_ext ); 00019 } 00020 00021 t.start(); 00022 finish.start(); 00023 rtpbuf_clear( &( this->rtpbuf ) ); 00024 call_new_counter++; 00025 } 00026 00027 VZ_call::~VZ_call(){ 00028 rtp_sock.close(); 00029 delete( this->rtp ); 00030 call_delete_counter++; 00031 } 00032 00033 char * 00034 VZ_call::get_eth_message ( int * length ) 00035 { 00036 uint8_t * pkg; 00037 Endpoint rtp_from; 00038 00039 *length = rtp_sock.receiveFrom ( rtp_server, server2cb, sizeof( server2cb ) ); 00040 t.reset(); 00041 00042 rtpbuf_next ( &rtpbuf ); 00043 00044 if ( *length > 0 ) 00045 { 00046 rtpbuf_put ( &rtpbuf, *length - ( RTP_HEADER_SIZE + ( server2cb [ 0 ] & 0xf ) ), 00047 ( uint8_t * )server2cb + ( RTP_HEADER_OFFSET + ( server2cb [ 0 ] & 0xf ) ) ); 00048 } 00049 else if ( *length == -1 ) 00050 { 00051 miss_rtp_udp_rcv_pkg ++; 00052 reconnect (); 00053 } 00054 00055 pkg = rtpbuf_get ( &rtpbuf ); 00056 00057 if ( pkg != NULL ) 00058 { 00059 *length = 240; 00060 return (char *)pkg; 00061 } 00062 00063 *length = 0; 00064 return NULL; 00065 } 00066 00067 int 00068 VZ_call::send_message ( char * buffer ) 00069 { 00070 this -> t.reset (); 00071 const uint16_t SEND_MSG_SIZE = CB_AUDIO_DATA_SIZE + this -> rtp -> header_size (); 00072 00073 int send = this -> rtp_sock.sendTo ( this -> rtp_server, buffer, SEND_MSG_SIZE ); 00074 00075 if ( send not_eq SEND_MSG_SIZE ) 00076 { 00077 miss_rtp_udp_send_pkg ++; 00078 00079 reconnect (); 00080 } 00081 00082 return ( send ); 00083 } 00084 00085 char * VZ_call::build_eth_package( uint8_t * buffer ){ 00086 return this->rtp->build_eth_package( ( char * )buffer ); 00087 } 00088 00089 int VZ_call::get_cb_ext () 00090 { 00091 return this->cb_ext; 00092 } 00093 00094 int VZ_call::get_cb_port () 00095 { 00096 return this->cb_port; 00097 } 00098 00099 int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } 00100 int VZ_call::get_rtp_server_port(){ return rtp_server_port; } 00101 00102 bool VZ_call::is_timetofinish( void ){ 00103 return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; 00104 } 00105 00106 uint16_t VZ_call::get_elapsed_time( void ){ 00107 return ( finish.read_ms() ); 00108 } 00109 00110 void VZ_call::cbx_pkg_idle_timer_reset ( void ){ 00111 cbx_pkg_idle_timer.reset(); 00112 } 00113 00114 bool VZ_call::cbx_pkg_is_idle( void ){ 00115 return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false; 00116 } 00117 00118 void VZ_call::init_cbx_pkg_idle_timer(){ 00119 cbx_pkg_idle_timer.start(); 00120 } 00121 00122 int VZ_call::print_yourself ( void ) 00123 { 00124 vz_printf ("t :: %d", ( int ) t.read () ); 00125 vz_printf ("finish :: %d", ( int ) finish.read () ); 00126 vz_printf ("cbx_pkg_idle_timer :: %d", ( int ) cbx_pkg_idle_timer.read () ); 00127 vz_printf ("cb_port :: %d", cb_port ); 00128 vz_printf ("cb2server :: %p", ( void * ) cb2server ); 00129 vz_printf ("server2cb :: %p", ( void * ) server2cb ); 00130 vz_printf ("buffer :: %p", ( void * ) buffer ); 00131 vz_printf ("rtp_sock :: %p", ( void * )&rtp_sock ); 00132 vz_printf ("rtp_server_ext :: %d", rtp_server_ext ); 00133 vz_printf ("rtp_server_port :: %d", rtp_server_port ); 00134 vz_printf ("rtp_server :: %p", &rtp_server ); 00135 vz_printf ("rtp :: %p", ( void * ) rtp ); 00136 vz_printf ("rtpbuf :: %p", ( void * ) &rtpbuf ); 00137 return ( sizeof( VZ_call ) ); 00138 } 00139 00140 void * VZ_call::check_rtp ( void ) { return rtp; } 00141 00142 int VZ_call::rtp_print_yourself ( void ) 00143 { 00144 return rtp -> print_yourself (); 00145 } 00146 00147 void 00148 VZ_call::reconnect ( void ) 00149 { 00150 this -> rtp_sock.close (); 00151 00152 this -> rtp_sock.bind ( cb_port ); 00153 00154 this -> rtp_sock.set_blocking ( false, 0 ); 00155 }
Generated on Tue Jul 12 2022 16:25:01 by
