![](/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
call.cpp@132:05cd37f7e007, 2015-09-01 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 01 17:21:11 2015 +0000
- Revision:
- 132:05cd37f7e007
- Parent:
- 121:ee02790d00b7
- Child:
- 135:2f4290590e51
Substitui??o de; send_msg -> vz_printf; debug_msg -> vz_debug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "call.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 0:4d17cd9c8f9d | 3 | VZ_call::VZ_call( int cb_ext, int cb_port, int rtp_server_ext, int rtp_server_port ){ |
klauss | 0:4d17cd9c8f9d | 4 | this->cb_ext = cb_ext; |
klauss | 0:4d17cd9c8f9d | 5 | this->cb_port = cb_port; |
klauss | 0:4d17cd9c8f9d | 6 | |
klauss | 0:4d17cd9c8f9d | 7 | this->rtp_server_ext = rtp_server_ext; |
klauss | 0:4d17cd9c8f9d | 8 | this->rtp_server_port = rtp_server_port; |
klauss | 119:ee6a53069455 | 9 | this->rtp_server.set_address( SERVER_IP, rtp_server_port ); |
klauss | 114:472502b31a12 | 10 | rtp_sock.set_blocking( false, 0 ); |
klauss | 114:472502b31a12 | 11 | this->rtp_sock.bind( cb_port ); // rtp port |
klauss | 114:472502b31a12 | 12 | this->rtp_sock.init(); |
klauss | 0:4d17cd9c8f9d | 13 | this->rtp = new RTP( this->cb_ext ); |
klauss | 0:4d17cd9c8f9d | 14 | |
klauss | 89:0fe315117b00 | 15 | if( rtp == NULL ) |
klauss | 89:0fe315117b00 | 16 | { |
klauss | 89:0fe315117b00 | 17 | memory_is_over = true; |
klauss | 132:05cd37f7e007 | 18 | if( debug_memory ) vz_debug ("[%d] Call_Box cb allocation fail", this->cb_ext ); |
klauss | 89:0fe315117b00 | 19 | } |
klauss | 87:679ee0d594a9 | 20 | |
klauss | 0:4d17cd9c8f9d | 21 | t.start(); |
klauss | 0:4d17cd9c8f9d | 22 | finish.start(); |
klauss | 0:4d17cd9c8f9d | 23 | rtpbuf_clear( &( this->rtpbuf ) ); |
klauss | 91:c2a86b1f8aaa | 24 | call_new_counter++; |
klauss | 0:4d17cd9c8f9d | 25 | } |
klauss | 0:4d17cd9c8f9d | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | VZ_call::~VZ_call(){ |
klauss | 0:4d17cd9c8f9d | 28 | rtp_sock.close(); |
klauss | 0:4d17cd9c8f9d | 29 | delete( this->rtp ); |
klauss | 91:c2a86b1f8aaa | 30 | call_delete_counter++; |
klauss | 0:4d17cd9c8f9d | 31 | } |
klauss | 0:4d17cd9c8f9d | 32 | |
klauss | 132:05cd37f7e007 | 33 | char * |
klauss | 132:05cd37f7e007 | 34 | VZ_call::get_eth_message ( int * length ) |
klauss | 132:05cd37f7e007 | 35 | { |
klauss | 0:4d17cd9c8f9d | 36 | uint8_t * pkg; |
klauss | 119:ee6a53069455 | 37 | Endpoint rtp_from; |
klauss | 119:ee6a53069455 | 38 | |
klauss | 132:05cd37f7e007 | 39 | *length = rtp_sock.receiveFrom ( rtp_server, server2cb, sizeof( server2cb ) ); |
klauss | 0:4d17cd9c8f9d | 40 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 41 | |
klauss | 132:05cd37f7e007 | 42 | rtpbuf_next ( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 43 | |
klauss | 132:05cd37f7e007 | 44 | if ( *length > 0 ) |
klauss | 132:05cd37f7e007 | 45 | { |
klauss | 132:05cd37f7e007 | 46 | rtpbuf_put ( &rtpbuf, *length - ( RTP_HEADER_SIZE + ( server2cb [ 0 ] & 0xf ) ), |
klauss | 132:05cd37f7e007 | 47 | ( uint8_t * )server2cb + ( RTP_HEADER_OFFSET + ( server2cb [ 0 ] & 0xf ) ) ); |
klauss | 132:05cd37f7e007 | 48 | } |
klauss | 132:05cd37f7e007 | 49 | else if ( *length == -1 ) |
klauss | 132:05cd37f7e007 | 50 | { |
klauss | 132:05cd37f7e007 | 51 | miss_rtp_udp_rcv_pkg ++; |
klauss | 132:05cd37f7e007 | 52 | reconnect (); |
klauss | 0:4d17cd9c8f9d | 53 | } |
klauss | 0:4d17cd9c8f9d | 54 | |
klauss | 132:05cd37f7e007 | 55 | pkg = rtpbuf_get ( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 56 | |
klauss | 132:05cd37f7e007 | 57 | if ( pkg != NULL ) |
klauss | 132:05cd37f7e007 | 58 | { |
klauss | 0:4d17cd9c8f9d | 59 | *length = 240; |
klauss | 132:05cd37f7e007 | 60 | return (char *)pkg; |
klauss | 0:4d17cd9c8f9d | 61 | } |
klauss | 132:05cd37f7e007 | 62 | |
klauss | 0:4d17cd9c8f9d | 63 | *length = 0; |
klauss | 0:4d17cd9c8f9d | 64 | return NULL; |
klauss | 0:4d17cd9c8f9d | 65 | } |
klauss | 0:4d17cd9c8f9d | 66 | |
klauss | 132:05cd37f7e007 | 67 | int |
klauss | 132:05cd37f7e007 | 68 | VZ_call::send_message ( char * buffer ) |
klauss | 119:ee6a53069455 | 69 | { |
klauss | 132:05cd37f7e007 | 70 | this -> t.reset (); |
klauss | 132:05cd37f7e007 | 71 | const uint16_t SEND_MSG_SIZE = CB_AUDIO_DATA_SIZE + this -> rtp -> header_size (); |
klauss | 132:05cd37f7e007 | 72 | |
klauss | 132:05cd37f7e007 | 73 | int send = this -> rtp_sock.sendTo ( this -> rtp_server, buffer, SEND_MSG_SIZE ); |
klauss | 132:05cd37f7e007 | 74 | |
klauss | 132:05cd37f7e007 | 75 | if ( send not_eq SEND_MSG_SIZE ) |
klauss | 119:ee6a53069455 | 76 | { |
klauss | 132:05cd37f7e007 | 77 | if ( debug_reconnect ) |
klauss | 119:ee6a53069455 | 78 | { |
klauss | 132:05cd37f7e007 | 79 | vz_printf ( "[%d] Reconnect RTP", this -> cb_ext ); |
klauss | 119:ee6a53069455 | 80 | } |
klauss | 132:05cd37f7e007 | 81 | |
klauss | 132:05cd37f7e007 | 82 | miss_rtp_udp_send_pkg ++; |
klauss | 132:05cd37f7e007 | 83 | |
klauss | 132:05cd37f7e007 | 84 | reconnect (); |
klauss | 119:ee6a53069455 | 85 | } |
klauss | 132:05cd37f7e007 | 86 | |
klauss | 132:05cd37f7e007 | 87 | return ( send ); |
klauss | 114:472502b31a12 | 88 | } |
klauss | 0:4d17cd9c8f9d | 89 | |
klauss | 0:4d17cd9c8f9d | 90 | char * VZ_call::build_eth_package( uint8_t * buffer ){ |
klauss | 0:4d17cd9c8f9d | 91 | return this->rtp->build_eth_package( ( char * )buffer ); |
klauss | 0:4d17cd9c8f9d | 92 | } |
klauss | 0:4d17cd9c8f9d | 93 | |
klauss | 119:ee6a53069455 | 94 | int VZ_call::get_cb_ext () |
klauss | 119:ee6a53069455 | 95 | { |
klauss | 119:ee6a53069455 | 96 | return this->cb_ext; |
klauss | 119:ee6a53069455 | 97 | } |
klauss | 119:ee6a53069455 | 98 | |
klauss | 119:ee6a53069455 | 99 | int VZ_call::get_cb_port () |
klauss | 119:ee6a53069455 | 100 | { |
klauss | 119:ee6a53069455 | 101 | return this->cb_port; |
klauss | 119:ee6a53069455 | 102 | } |
klauss | 0:4d17cd9c8f9d | 103 | |
klauss | 0:4d17cd9c8f9d | 104 | int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } |
klauss | 0:4d17cd9c8f9d | 105 | int VZ_call::get_rtp_server_port(){ return rtp_server_port; } |
klauss | 119:ee6a53069455 | 106 | |
klauss | 0:4d17cd9c8f9d | 107 | uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; } |
klauss | 0:4d17cd9c8f9d | 108 | char * VZ_call::get_server2cb_buffer(){ return server2cb; } |
klauss | 0:4d17cd9c8f9d | 109 | inline uint8_t * VZ_call::get_buffer(){ return buffer; } |
klauss | 0:4d17cd9c8f9d | 110 | |
klauss | 0:4d17cd9c8f9d | 111 | bool VZ_call::is_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 112 | return ( t.read() > __CALL_MAX_IDLE_TIME__ ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 113 | } |
klauss | 0:4d17cd9c8f9d | 114 | |
klauss | 0:4d17cd9c8f9d | 115 | bool VZ_call::is_timetofinish( void ){ |
klauss | 0:4d17cd9c8f9d | 116 | return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; |
klauss | 92:92df17f538a8 | 117 | } |
klauss | 92:92df17f538a8 | 118 | |
klauss | 119:ee6a53069455 | 119 | uint16_t VZ_call::get_elapsed_time( void ){ |
klauss | 92:92df17f538a8 | 120 | return ( finish.read_ms() ); |
klauss | 92:92df17f538a8 | 121 | } |
klauss | 92:92df17f538a8 | 122 | |
klauss | 132:05cd37f7e007 | 123 | void VZ_call::cbx_pkg_idle_timer_reset ( void ){ |
klauss | 92:92df17f538a8 | 124 | cbx_pkg_idle_timer.reset(); |
klauss | 92:92df17f538a8 | 125 | } |
klauss | 92:92df17f538a8 | 126 | |
klauss | 92:92df17f538a8 | 127 | bool VZ_call::cbx_pkg_is_idle( void ){ |
klauss | 92:92df17f538a8 | 128 | return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false; |
klauss | 92:92df17f538a8 | 129 | } |
klauss | 92:92df17f538a8 | 130 | |
klauss | 92:92df17f538a8 | 131 | void VZ_call::init_cbx_pkg_idle_timer(){ |
klauss | 92:92df17f538a8 | 132 | cbx_pkg_idle_timer.start(); |
klauss | 104:62646ef786a3 | 133 | } |
klauss | 104:62646ef786a3 | 134 | |
klauss | 109:a5b8264ffbbc | 135 | int VZ_call::print_yourself ( void ) |
klauss | 104:62646ef786a3 | 136 | { |
klauss | 132:05cd37f7e007 | 137 | vz_printf ("t :: %d", ( int ) t.read () ); |
klauss | 132:05cd37f7e007 | 138 | vz_printf ("finish :: %d", ( int ) finish.read () ); |
klauss | 132:05cd37f7e007 | 139 | vz_printf ("cbx_pkg_idle_timer :: %d", ( int ) cbx_pkg_idle_timer.read () ); |
klauss | 132:05cd37f7e007 | 140 | vz_printf ("cb_port :: %d", cb_port ); |
klauss | 132:05cd37f7e007 | 141 | vz_printf ("cb2server :: %p", ( void * ) cb2server ); |
klauss | 132:05cd37f7e007 | 142 | vz_printf ("server2cb :: %p", ( void * ) server2cb ); |
klauss | 132:05cd37f7e007 | 143 | vz_printf ("buffer :: %p", ( void * ) buffer ); |
klauss | 132:05cd37f7e007 | 144 | vz_printf ("rtp_sock :: %p", ( void * )&rtp_sock ); |
klauss | 132:05cd37f7e007 | 145 | vz_printf ("rtp_server_ext :: %d", rtp_server_ext ); |
klauss | 132:05cd37f7e007 | 146 | vz_printf ("rtp_server_port :: %d", rtp_server_port ); |
klauss | 132:05cd37f7e007 | 147 | vz_printf ("rtp_server :: %p", &rtp_server ); |
klauss | 132:05cd37f7e007 | 148 | vz_printf ("rtp :: %p", ( void * ) rtp ); |
klauss | 132:05cd37f7e007 | 149 | vz_printf ("rtpbuf :: %p", ( void * ) &rtpbuf ); |
klauss | 109:a5b8264ffbbc | 150 | return ( sizeof( VZ_call ) ); |
klauss | 109:a5b8264ffbbc | 151 | } |
klauss | 109:a5b8264ffbbc | 152 | |
klauss | 109:a5b8264ffbbc | 153 | void * VZ_call::check_rtp ( void ) { return rtp; } |
klauss | 109:a5b8264ffbbc | 154 | |
klauss | 109:a5b8264ffbbc | 155 | int VZ_call::rtp_print_yourself ( void ) |
klauss | 109:a5b8264ffbbc | 156 | { |
klauss | 109:a5b8264ffbbc | 157 | return rtp -> print_yourself (); |
klauss | 119:ee6a53069455 | 158 | } |
klauss | 119:ee6a53069455 | 159 | |
klauss | 132:05cd37f7e007 | 160 | void |
klauss | 132:05cd37f7e007 | 161 | VZ_call::reconnect ( void ) |
klauss | 119:ee6a53069455 | 162 | { |
klauss | 132:05cd37f7e007 | 163 | this -> rtp_sock.close (); |
klauss | 132:05cd37f7e007 | 164 | |
klauss | 132:05cd37f7e007 | 165 | this -> rtp_sock.bind ( cb_port ); |
klauss | 132:05cd37f7e007 | 166 | |
klauss | 132:05cd37f7e007 | 167 | this -> rtp_sock.set_blocking ( false, 0 ); |
klauss | 0:4d17cd9c8f9d | 168 | } |