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
- Committer:
- klauss
- Date:
- 2015-04-30
- Revision:
- 119:ee6a53069455
- Parent:
- 117:e9facba9db27
- Child:
- 121:ee02790d00b7
File content as of revision 119:ee6a53069455:
#include "call.h"
VZ_call::VZ_call( int cb_ext, int cb_port, int rtp_server_ext, int rtp_server_port ){
this->cb_ext = cb_ext;
this->cb_port = cb_port;
this->rtp_server_ext = rtp_server_ext;
this->rtp_server_port = rtp_server_port;
this->rtp_server.set_address( SERVER_IP, rtp_server_port );
rtp_sock.set_blocking( false, 0 );
this->rtp_sock.bind( cb_port ); // rtp port
this->rtp_sock.init();
this->rtp = new RTP( this->cb_ext );
if( rtp == NULL )
{
memory_is_over = true;
if( debug_memory ) debug_msg("[%d] Call_Box cb allocation fail", this->cb_ext );
}
t.start();
finish.start();
rtpbuf_clear( &( this->rtpbuf ) );
call_new_counter++;
}
VZ_call::~VZ_call(){
rtp_sock.close();
delete( this->rtp );
call_delete_counter++;
}
char * VZ_call::get_eth_message( int * length ){
uint8_t * pkg;
Endpoint rtp_from;
*length = rtp_sock.receiveFrom( rtp_server, server2cb, sizeof( server2cb ) );
t.reset();
rtpbuf_next( &rtpbuf );
if( *length > 0 ){
rtpbuf_put( &rtpbuf, *length - ( __RTP_HEADER_SIZE__ + ( server2cb[ 0 ] & 0xf ) ),
( uint8_t * )server2cb + ( __RTP_HEADER_OFFSET__ + ( server2cb[ 0 ] & 0xf ) ) );
}
pkg = rtpbuf_get( &rtpbuf );
if (pkg != NULL) {
*length = 240;
return (char *) pkg;
}
*length = 0;
return NULL;
}
int VZ_call::send_message ( char * buffer )
{
this->t.reset();
int send = this->rtp_sock.sendTo( this->rtp_server, buffer, CB_AUDIO_DATA_SIZE + this->rtp->header_size() );
if( send != CB_AUDIO_DATA_SIZE + this->rtp->header_size() )
{
if( debug_reconnect )
{
send_msg("[%d] Reconnect RTP", this->cb_ext );
miss_ftp_udp_send_pkg++;
}
reconnect();
}
return( send );
}
char * VZ_call::build_eth_package( uint8_t * buffer ){
return this->rtp->build_eth_package( ( char * )buffer );
}
int VZ_call::get_cb_ext ()
{
return this->cb_ext;
}
int VZ_call::get_cb_port ()
{
return this->cb_port;
}
int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; }
int VZ_call::get_rtp_server_port(){ return rtp_server_port; }
uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; }
char * VZ_call::get_server2cb_buffer(){ return server2cb; }
inline uint8_t * VZ_call::get_buffer(){ return buffer; }
bool VZ_call::is_timeout( void ){
return ( t.read() > __CALL_MAX_IDLE_TIME__ ) ? true : false;
}
bool VZ_call::is_timetofinish( void ){
return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false;
}
uint16_t VZ_call::get_elapsed_time( void ){
return ( finish.read_ms() );
}
void VZ_call::cbx_pkg_idle_timer_reset( void ){
cbx_pkg_idle_timer.reset();
}
bool VZ_call::cbx_pkg_is_idle( void ){
return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false;
}
void VZ_call::init_cbx_pkg_idle_timer(){
cbx_pkg_idle_timer.start();
}
int VZ_call::print_yourself ( void )
{
send_msg("t :: %d", ( int ) t.read () );
send_msg("finish :: %d", ( int ) finish.read () );
send_msg("cbx_pkg_idle_timer :: %d", ( int ) cbx_pkg_idle_timer.read () );
send_msg("cb_port :: %d", cb_port );
send_msg("cb2server :: %p", ( void * ) cb2server );
send_msg("server2cb :: %p", ( void * ) server2cb );
send_msg("buffer :: %p", ( void * ) buffer );
send_msg("rtp_sock :: %p", ( void * )&rtp_sock );
send_msg("rtp_server_ext :: %d", rtp_server_ext );
send_msg("rtp_server_port :: %d", rtp_server_port );
send_msg("rtp_server :: %p", &rtp_server );
send_msg("rtp :: %p", ( void * ) rtp );
send_msg("rtpbuf :: %p", ( void * ) &rtpbuf );
return ( sizeof( VZ_call ) );
}
void * VZ_call::check_rtp ( void ) { return rtp; }
int VZ_call::rtp_print_yourself ( void )
{
return rtp -> print_yourself ();
}
void VZ_call::reconnect ( void )
{
this->rtp_sock.close();
this->rtp_sock.set_blocking( false, 0 );
this->rtp_sock.bind( cb_port );
}
