![](/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
rtp.cpp@0:4d17cd9c8f9d, 2014-09-09 (annotated)
- Committer:
- klauss
- Date:
- Tue Sep 09 20:01:24 2014 +0000
- Revision:
- 0:4d17cd9c8f9d
- Child:
- 2:93bec7313ccc
20140726 copy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 0:4d17cd9c8f9d | 1 | #include "rtp.h" |
klauss | 0:4d17cd9c8f9d | 2 | |
klauss | 0:4d17cd9c8f9d | 3 | RTP_Header::RTP_Header( int cb_ext ){ |
klauss | 0:4d17cd9c8f9d | 4 | // por algum motivo do alem, comecar do 0 nao funcionou |
klauss | 0:4d17cd9c8f9d | 5 | ss_id = 0x01010101 + ( uint32_t )cb_ext; |
klauss | 0:4d17cd9c8f9d | 6 | seq_number = 0x0101; |
klauss | 0:4d17cd9c8f9d | 7 | timestamp = 240; |
klauss | 0:4d17cd9c8f9d | 8 | } |
klauss | 0:4d17cd9c8f9d | 9 | |
klauss | 0:4d17cd9c8f9d | 10 | RTP_Header::~RTP_Header(){ |
klauss | 0:4d17cd9c8f9d | 11 | // something |
klauss | 0:4d17cd9c8f9d | 12 | } |
klauss | 0:4d17cd9c8f9d | 13 | |
klauss | 0:4d17cd9c8f9d | 14 | char * RTP_Header::build_header( char * pkg ){ |
klauss | 0:4d17cd9c8f9d | 15 | if( pkg == NULL ) return( NULL ); |
klauss | 0:4d17cd9c8f9d | 16 | |
klauss | 0:4d17cd9c8f9d | 17 | for( register int i = 0; i < __RTP_HEADER_SIZE__; i++ ) pkg[ i ] = 0xff; |
klauss | 0:4d17cd9c8f9d | 18 | |
klauss | 0:4d17cd9c8f9d | 19 | pkg[ 0 ] &= 0x80; |
klauss | 0:4d17cd9c8f9d | 20 | |
klauss | 0:4d17cd9c8f9d | 21 | pkg[ 1 ] &= 0x08; |
klauss | 0:4d17cd9c8f9d | 22 | |
klauss | 0:4d17cd9c8f9d | 23 | pkg[ 2 ] = 0xff; |
klauss | 0:4d17cd9c8f9d | 24 | pkg[ 2 ] &= ( char )( seq_number >> 8 ); |
klauss | 0:4d17cd9c8f9d | 25 | pkg[ 3 ] &= ( char )( seq_number & 0xff ); |
klauss | 0:4d17cd9c8f9d | 26 | |
klauss | 0:4d17cd9c8f9d | 27 | pkg[ 4 ] &= ( char )( timestamp >> 24 & 0xff ); |
klauss | 0:4d17cd9c8f9d | 28 | pkg[ 5 ] &= ( char )( timestamp >> 16 & 0xff ); |
klauss | 0:4d17cd9c8f9d | 29 | pkg[ 6 ] &= ( char )( timestamp >> 8 & 0xff ); |
klauss | 0:4d17cd9c8f9d | 30 | pkg[ 7 ] &= ( char )( timestamp & 0xff ); |
klauss | 0:4d17cd9c8f9d | 31 | |
klauss | 0:4d17cd9c8f9d | 32 | pkg[ 8 ] &= ( char )( ss_id >> 24 & 0xff ); |
klauss | 0:4d17cd9c8f9d | 33 | pkg[ 9 ] &= ( char )( ss_id >> 16 & 0xff ); |
klauss | 0:4d17cd9c8f9d | 34 | pkg[ 10 ] &= ( char )( ss_id >> 8 & 0xff ); |
klauss | 0:4d17cd9c8f9d | 35 | pkg[ 11 ] &= ( char )( ss_id & 0xff ); |
klauss | 0:4d17cd9c8f9d | 36 | |
klauss | 0:4d17cd9c8f9d | 37 | pkg[ __RTP_HEADER_SIZE__ ] = 0; |
klauss | 0:4d17cd9c8f9d | 38 | timestamp += 240; |
klauss | 0:4d17cd9c8f9d | 39 | seq_number++; |
klauss | 0:4d17cd9c8f9d | 40 | |
klauss | 0:4d17cd9c8f9d | 41 | return( pkg ); |
klauss | 0:4d17cd9c8f9d | 42 | } |
klauss | 0:4d17cd9c8f9d | 43 | |
klauss | 0:4d17cd9c8f9d | 44 | size_t RTP_Header::size( void ){ |
klauss | 0:4d17cd9c8f9d | 45 | return( __RTP_HEADER_SIZE__ ); |
klauss | 0:4d17cd9c8f9d | 46 | } |
klauss | 0:4d17cd9c8f9d | 47 | |
klauss | 0:4d17cd9c8f9d | 48 | RTP_Body::RTP_Body(){ |
klauss | 0:4d17cd9c8f9d | 49 | // do something |
klauss | 0:4d17cd9c8f9d | 50 | } |
klauss | 0:4d17cd9c8f9d | 51 | |
klauss | 0:4d17cd9c8f9d | 52 | RTP_Body::~RTP_Body(){ |
klauss | 0:4d17cd9c8f9d | 53 | // something |
klauss | 0:4d17cd9c8f9d | 54 | } |
klauss | 0:4d17cd9c8f9d | 55 | |
klauss | 0:4d17cd9c8f9d | 56 | size_t RTP_Body::size( void ){ |
klauss | 0:4d17cd9c8f9d | 57 | return( sizeof( RTP_Body ) ); |
klauss | 0:4d17cd9c8f9d | 58 | } |
klauss | 0:4d17cd9c8f9d | 59 | |
klauss | 0:4d17cd9c8f9d | 60 | char * RTP_Body::build_body( char * dest, char * buffer ){ |
klauss | 0:4d17cd9c8f9d | 61 | for( register int i = 0; i < __CB_AUDIO_DATA_SIZE__; i++ ) dest[ i ] = buffer[ i ]; |
klauss | 0:4d17cd9c8f9d | 62 | return( dest ); |
klauss | 0:4d17cd9c8f9d | 63 | } |
klauss | 0:4d17cd9c8f9d | 64 | |
klauss | 0:4d17cd9c8f9d | 65 | RTP::RTP( int ext ){ |
klauss | 0:4d17cd9c8f9d | 66 | rtp_header = new RTP_Header( ext ); |
klauss | 0:4d17cd9c8f9d | 67 | rtp_body = new RTP_Body(); |
klauss | 0:4d17cd9c8f9d | 68 | } |
klauss | 0:4d17cd9c8f9d | 69 | |
klauss | 0:4d17cd9c8f9d | 70 | RTP::~RTP(){ |
klauss | 0:4d17cd9c8f9d | 71 | if( rtp_header ) delete( rtp_header ); |
klauss | 0:4d17cd9c8f9d | 72 | if( rtp_body ) delete( rtp_body ); |
klauss | 0:4d17cd9c8f9d | 73 | } |
klauss | 0:4d17cd9c8f9d | 74 | |
klauss | 0:4d17cd9c8f9d | 75 | char * RTP::build_eth_package( char * buffer ){ |
klauss | 0:4d17cd9c8f9d | 76 | rtp_header->build_header( this->pkg ); |
klauss | 0:4d17cd9c8f9d | 77 | rtp_body->build_body( this->pkg + __RTP_HEADER_OFFSET__, buffer ); |
klauss | 0:4d17cd9c8f9d | 78 | return( this->pkg ); |
klauss | 0:4d17cd9c8f9d | 79 | } |
klauss | 0:4d17cd9c8f9d | 80 | |
klauss | 0:4d17cd9c8f9d | 81 | size_t RTP::header_size( void ){ |
klauss | 0:4d17cd9c8f9d | 82 | return rtp_header->size(); |
klauss | 0:4d17cd9c8f9d | 83 | } |