![](/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@105:a930035b6556, 2015-03-10 (annotated)
- Committer:
- klauss
- Date:
- Tue Mar 10 18:10:57 2015 +0000
- Revision:
- 105:a930035b6556
- Parent:
- 104:62646ef786a3
- Child:
- 108:18a3702650f3
sprint 0;
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 | 69:65665afbad5d | 9 | this->rtp_server.set_address( __RTP_SEVER_IP__, rtp_server_port ); |
klauss | 104:62646ef786a3 | 10 | this->rtp_sock.set_blocking( false, 0 ); |
klauss | 0:4d17cd9c8f9d | 11 | this->rtp_sock.bind( cb_port ); // rtp port |
klauss | 104:62646ef786a3 | 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 | 89:0fe315117b00 | 18 | if( debug_memory ) debug_msg("Call_Box cb allocation fail"); |
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 | 0:4d17cd9c8f9d | 33 | char * VZ_call::get_eth_message( int * length ){ |
klauss | 0:4d17cd9c8f9d | 34 | uint8_t * pkg; |
klauss | 104:62646ef786a3 | 35 | Endpoint rtp_from; |
klauss | 104:62646ef786a3 | 36 | |
klauss | 104:62646ef786a3 | 37 | *length = rtp_sock.receiveFrom( rtp_from, server2cb, sizeof( server2cb ) ); |
klauss | 0:4d17cd9c8f9d | 38 | t.reset(); |
klauss | 0:4d17cd9c8f9d | 39 | |
klauss | 0:4d17cd9c8f9d | 40 | rtpbuf_next( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 41 | |
klauss | 0:4d17cd9c8f9d | 42 | if( *length > 0 ){ |
klauss | 0:4d17cd9c8f9d | 43 | rtpbuf_put( &rtpbuf, *length - ( __RTP_HEADER_SIZE__ + ( server2cb[ 0 ] & 0xf ) ), |
klauss | 0:4d17cd9c8f9d | 44 | ( uint8_t * )server2cb + ( __RTP_HEADER_OFFSET__ + ( server2cb[ 0 ] & 0xf ) ) ); |
klauss | 0:4d17cd9c8f9d | 45 | } |
klauss | 0:4d17cd9c8f9d | 46 | |
klauss | 0:4d17cd9c8f9d | 47 | pkg = rtpbuf_get( &rtpbuf ); |
klauss | 0:4d17cd9c8f9d | 48 | |
klauss | 0:4d17cd9c8f9d | 49 | if (pkg != NULL) { |
klauss | 0:4d17cd9c8f9d | 50 | *length = 240; |
klauss | 0:4d17cd9c8f9d | 51 | return (char *) pkg; |
klauss | 0:4d17cd9c8f9d | 52 | } |
klauss | 0:4d17cd9c8f9d | 53 | *length = 0; |
klauss | 0:4d17cd9c8f9d | 54 | return NULL; |
klauss | 0:4d17cd9c8f9d | 55 | } |
klauss | 0:4d17cd9c8f9d | 56 | |
klauss | 0:4d17cd9c8f9d | 57 | int VZ_call::send_message( char * buffer ){ |
klauss | 0:4d17cd9c8f9d | 58 | t.reset(); |
klauss | 104:62646ef786a3 | 59 | int send = this->rtp_sock.sendTo( this->rtp_server, buffer, __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ); |
klauss | 104:62646ef786a3 | 60 | if( send != __CB_AUDIO_DATA_SIZE__ + this->rtp->header_size() ) |
klauss | 104:62646ef786a3 | 61 | { |
klauss | 104:62646ef786a3 | 62 | if( debug_reconnect ) |
klauss | 104:62646ef786a3 | 63 | { |
klauss | 104:62646ef786a3 | 64 | send_msg("Reconnect RTP"); |
klauss | 105:a930035b6556 | 65 | miss_ftp_udp_send_pkg++; |
klauss | 104:62646ef786a3 | 66 | } |
klauss | 104:62646ef786a3 | 67 | reconnect(); |
klauss | 104:62646ef786a3 | 68 | } |
klauss | 104:62646ef786a3 | 69 | return( send ); |
klauss | 0:4d17cd9c8f9d | 70 | } |
klauss | 0:4d17cd9c8f9d | 71 | |
klauss | 105:a930035b6556 | 72 | //uint8_t * VZ_call::build_cb_package( void ){ |
klauss | 105:a930035b6556 | 73 | // return build_cb_package( cb_ext, cb_port, __AUDIO__, server2cb, buffer ); |
klauss | 0:4d17cd9c8f9d | 74 | // colocar esta funcao novamente pra envio de msg, assim como encapsular melhor a funcao |
klauss | 0:4d17cd9c8f9d | 75 | // de criacao dos pacotes pro cb em algumas funcoes. |
klauss | 105:a930035b6556 | 76 | // return 0x00; |
klauss | 105:a930035b6556 | 77 | //} |
klauss | 0:4d17cd9c8f9d | 78 | |
klauss | 0:4d17cd9c8f9d | 79 | char * VZ_call::build_eth_package( uint8_t * buffer ){ |
klauss | 0:4d17cd9c8f9d | 80 | return this->rtp->build_eth_package( ( char * )buffer ); |
klauss | 0:4d17cd9c8f9d | 81 | } |
klauss | 0:4d17cd9c8f9d | 82 | |
klauss | 0:4d17cd9c8f9d | 83 | int VZ_call::get_cb_ext(){ return this->cb_ext; } |
klauss | 0:4d17cd9c8f9d | 84 | int VZ_call::get_cb_port(){ return this->cb_port; } |
klauss | 0:4d17cd9c8f9d | 85 | |
klauss | 0:4d17cd9c8f9d | 86 | int VZ_call::get_rtp_server_ext(){ return rtp_server_ext; } |
klauss | 0:4d17cd9c8f9d | 87 | int VZ_call::get_rtp_server_port(){ return rtp_server_port; } |
klauss | 0:4d17cd9c8f9d | 88 | uint8_t * VZ_call::get_cb2server_buffer(){ return cb2server; } |
klauss | 0:4d17cd9c8f9d | 89 | char * VZ_call::get_server2cb_buffer(){ return server2cb; } |
klauss | 0:4d17cd9c8f9d | 90 | inline uint8_t * VZ_call::get_buffer(){ return buffer; } |
klauss | 0:4d17cd9c8f9d | 91 | |
klauss | 0:4d17cd9c8f9d | 92 | bool VZ_call::is_timeout( void ){ |
klauss | 0:4d17cd9c8f9d | 93 | return ( t.read() > __CALL_MAX_IDLE_TIME__ ) ? true : false; |
klauss | 0:4d17cd9c8f9d | 94 | } |
klauss | 0:4d17cd9c8f9d | 95 | |
klauss | 0:4d17cd9c8f9d | 96 | bool VZ_call::is_timetofinish( void ){ |
klauss | 0:4d17cd9c8f9d | 97 | return ( finish.read() > __MAX_CALL_TIME__ ) ? true : false; |
klauss | 92:92df17f538a8 | 98 | } |
klauss | 92:92df17f538a8 | 99 | |
klauss | 92:92df17f538a8 | 100 | int VZ_call::get_elapsed_time( void ){ |
klauss | 92:92df17f538a8 | 101 | return ( finish.read_ms() ); |
klauss | 92:92df17f538a8 | 102 | } |
klauss | 92:92df17f538a8 | 103 | |
klauss | 92:92df17f538a8 | 104 | void VZ_call::cbx_pkg_idle_timer_reset( void ){ |
klauss | 92:92df17f538a8 | 105 | cbx_pkg_idle_timer.reset(); |
klauss | 92:92df17f538a8 | 106 | } |
klauss | 92:92df17f538a8 | 107 | |
klauss | 92:92df17f538a8 | 108 | bool VZ_call::cbx_pkg_is_idle( void ){ |
klauss | 92:92df17f538a8 | 109 | return ( cbx_pkg_idle_timer.read() > CBX_PKG_IDLE_MAX_TIME ) ? true : false; |
klauss | 92:92df17f538a8 | 110 | } |
klauss | 92:92df17f538a8 | 111 | |
klauss | 92:92df17f538a8 | 112 | void VZ_call::init_cbx_pkg_idle_timer(){ |
klauss | 92:92df17f538a8 | 113 | cbx_pkg_idle_timer.start(); |
klauss | 104:62646ef786a3 | 114 | } |
klauss | 104:62646ef786a3 | 115 | |
klauss | 104:62646ef786a3 | 116 | void VZ_call::reconnect( void ) |
klauss | 104:62646ef786a3 | 117 | { |
klauss | 104:62646ef786a3 | 118 | this->rtp_sock.close(); |
klauss | 104:62646ef786a3 | 119 | this->rtp_sock.set_blocking( false, 0 ); |
klauss | 104:62646ef786a3 | 120 | this->rtp_sock.bind( cb_port ); |
klauss | 0:4d17cd9c8f9d | 121 | } |