Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNRTPNetTypes.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_RTP_NET_TYPES_H 00025 #define MN_RTP_NET_TYPES_H 00026 00027 #include <config.h> 00028 00029 #include <assert.h> 00030 #include <sys/time.h> 00031 #include <unistd.h> 00032 #include <errno.h> 00033 #include <string.h> 00034 #include <stdlib.h> 00035 #include <netinet/in.h> 00036 #include <sys/socket.h> 00037 #include <stdio.h> 00038 #include <dlfcn.h> 00039 #include <net/if.h> 00040 00041 #ifdef sun 00042 #include <sys/sockio.h> 00043 #include <arpa/inet.h> 00044 #endif 00045 00046 #include "mnstream.h" 00047 #include "var_type.h" 00048 #include "protected_var_type.h" 00049 #include "sdp/PayloadTypes.h" 00050 00051 /* RTP defs */ 00052 00053 /* 00054 * Current protocol version. 00055 */ 00056 #define RTP_VERSION 2 00057 00058 #define RTP_MAX_SDES 255 /* maximum text length for SDES */ 00059 00060 /* maximum misordered packet arrival. 00061 * If the Jump is greater than this, it is counted as a wrap 00062 * around (backward jump) / only needed in RTPList, as seq 00063 * misorder and wrap arounds should be processed by the app 00064 */ 00065 #define RTP_MAX_BACK_JUMP 3000 00066 00067 #define RTP_HDR_SIZE 12 00068 #define RTPX_HDR_SIZE 4 00069 #define RTCP_CMN_HDR_SIZE 4 00070 #define RTCP_SR_HDR_SIZE 24 00071 #define RTCP_RR_HDR_SIZE 4 00072 #define RTCP_RRBLOCK_SIZE 24 00073 #define RTCP_SDES_HDR_SIZE 4 00074 #define RTCP_APP_HDR_SIZE 8 00075 #define RTCP_APP_TFRC_SIZE 16 /* Experimental for TFRC integration - MZ */ 00076 #define RTCP_BYE_HDR_SIZE 4 00077 00078 enum rtcp_type_t 00079 { 00080 RTCP_SR = 200, 00081 RTCP_RR = 201, 00082 RTCP_SDES = 202, 00083 RTCP_BYE = 203, 00084 RTCP_APP = 204 00085 }; 00086 00087 enum rtcp_sdes_type_t 00088 { 00089 RTCP_SDES_END = 0, 00090 RTCP_SDES_CNAME = 1, 00091 RTCP_SDES_NAME = 2, 00092 RTCP_SDES_EMAIL = 3, 00093 RTCP_SDES_PHONE = 4, 00094 RTCP_SDES_LOC = 5, 00095 RTCP_SDES_TOOL = 6, 00096 RTCP_SDES_NOTE = 7, 00097 RTCP_SDES_PRIV = 8 00098 }; 00099 00100 /* Experimental for TFRC integration - MZ */ 00101 enum rtp_ext_hdr_type_t 00102 { 00103 RTP_EXT_HDR_RT = 211, 00104 RTP_EXT_HDR_LC = 242, 00105 RTP_EXT_HDR_TFRC = 243 00106 }; 00107 00108 /**********************************************************************/ 00109 /* RTP packet in network byte order */ 00110 /**********************************************************************/ 00111 00112 /**********************************************************************/ 00115 struct rtp_hdr_t 00116 { 00117 #ifdef WORDS_BIGENDIAN 00118 00119 unsigned int version:2; 00121 unsigned int p:1; 00123 unsigned int x:1; 00125 unsigned int cc:4; 00127 unsigned int m:1; 00129 unsigned int pt:7; 00130 #else 00131 unsigned int cc:4; 00132 unsigned int x:1; 00133 unsigned int p:1; 00134 unsigned int version:2; 00135 unsigned int pt:7; 00136 unsigned int m:1; 00137 #endif 00138 00139 u_int16 seq; 00141 u_int32 ts; 00143 u_int32 ssrc; 00145 u_int32 csrc[1]; 00146 00151 int rate() const 00152 { 00153 return SDP::default_rate_from_pt( SDP::pt_from_int( pt ) ); 00154 } 00155 00156 u_int32 get_ssrc() const 00157 { 00158 return ntohl(ssrc); 00159 } 00160 00161 u_int32 get_hdr_and_csrc_byte_size() const 00162 { 00163 return ( RTP_HDR_SIZE + cc * sizeof(u_int32) ); 00164 } 00165 00169 bool check_version() const; 00170 }; 00171 00172 struct rtp_hdr_ext 00173 { 00174 u_int16 etype; 00175 u_int16 elen; 00176 u_int32 epayload[1]; 00177 00178 u_int32 get_ext_hdr_byte_size() const 00179 { 00180 return ( RTPX_HDR_SIZE + ntohs(elen) * sizeof(u_int32) ); 00181 } 00182 }; 00183 00184 /* Experimental for TFRC integration - MZ */ 00185 //struct rtp_hdr_ext_tfrc : public rtp_hdr_ext 00186 struct rtp_hdr_ext_tfrc 00187 { 00188 u_int32 rtt; 00189 u_int32 bitrate; 00190 u_int32 lmr; 00191 u_int32 mode; 00192 }; 00193 00194 struct rtp_packet 00195 { 00196 rtp_hdr_t *RTP_header; 00197 rtp_hdr_ext *RTP_Extension; 00198 char *payload; 00199 long payload_len; 00200 }; 00201 00202 00203 /**********************************************************************/ 00204 /* RTCP packet in network byte order */ 00205 /**********************************************************************/ 00206 00207 struct text_item_t; 00208 00209 /**********************************************************************/ 00216 struct rtcp_common_t 00217 { 00218 #ifdef WORDS_BIGENDIAN 00219 00220 unsigned int version:2; 00222 unsigned int p:1; 00224 unsigned int count:5; 00225 #else 00226 unsigned int count:5; 00227 unsigned int p:1; 00228 unsigned int version:2; 00229 #endif 00230 00231 unsigned int pt:8; 00233 u_int16 length; 00234 }; 00235 00236 /**********************************************************************/ 00243 struct rtcp_rr_t 00244 { 00250 u_int32 ssrc; 00251 00269 unsigned int fraction:8; 00270 00284 int lost:24; 00285 00296 u_int32 last_seq; 00297 00304 u_int32 jitter; 00305 00314 u_int32 lsr; 00315 00323 u_int32 dlsr; 00324 }; 00325 00326 /**********************************************************************/ 00341 struct rr_t 00342 { 00344 u_int32 ssrc; 00345 00347 rtcp_rr_t rr[1]; 00348 }; 00349 00350 /**********************************************************************/ 00381 struct sr_t 00382 { 00388 u_int32 ssrc; 00389 00407 u_int32 ntp_sec; 00409 u_int32 ntp_frac; 00410 00426 u_int32 rtp_ts; 00427 00435 u_int32 psent; 00436 00446 u_int32 osent; 00447 00458 rtcp_rr_t rr[1]; 00459 }; 00460 00461 /**********************************************************************/ 00469 struct rtcp_sdes_item_t 00470 { 00472 u_int8 type; 00474 u_int8 length; 00476 char data[1]; 00477 }; 00478 00479 /**********************************************************************/ 00488 struct rtcp_sdes_t 00489 { 00491 u_int32 src; 00493 rtcp_sdes_item_t item[1]; 00494 }; 00495 00496 /**********************************************************************/ 00503 struct app_t 00504 { 00505 u_int32 ssrc; 00506 char name[4]; 00507 char data[1]; 00508 }; 00509 00510 /**********************************************************************/ 00517 struct bye_t 00518 { 00520 u_int32 src[1]; 00521 /* can't express trailing text for reason */ 00522 }; 00523 00524 /**********************************************************************/ 00543 struct rtcp_t 00544 { 00545 rtcp_common_t common; /* common header */ 00546 union 00547 { 00548 /* sender report (SR) */ 00549 sr_t sr; 00550 00551 /* reception report (RR) */ 00552 rr_t rr; 00553 00554 /* source description (SDES) */ 00555 rtcp_sdes_t sdes; 00556 00557 /* BYE */ 00558 bye_t bye; 00559 00560 /* APP */ 00561 app_t app; 00562 } r; 00563 00568 u_int16 get_length() const; 00569 00574 size_t get_byte_length() const; 00575 00580 size_t get_total_byte_length() const; 00581 00585 size_t get_app_data_byte_length() const; 00586 00591 size_t get_bye_text_byte_length() const; 00592 00598 text_item_t* get_bye_text_ptr() const; 00599 00603 u_int32 get_rr_ssrc() const; 00604 00608 bool check_version() const; 00609 00613 bool check_first_pt() const; 00614 }; 00615 00616 /**********************************************************************/ 00619 struct text_item_t 00620 { 00621 u_int8 length; 00622 char data[1]; 00623 00629 size_t init( const char* msg, size_t len ) 00630 { 00631 length = len; 00632 00633 // Text items must be padded to 32bit boundaries without 00634 // additional indication. 00635 // Add the length field first, because this may break the 00636 // alignment. 00637 len++; 00638 while ((len % sizeof(u_int32)) != 0) len++; 00639 00640 // Initialize the data field, but don't forget to subtract 00641 // one for the length field. 00642 memset( data, 0, len-1 ); 00643 memcpy( data, msg, length ); 00644 return len; 00645 } 00646 }; 00647 00648 /**********************************************************************/ 00649 /* Convert between network byte order and host byte order */ 00650 /**********************************************************************/ 00651 00653 inline int32 hton24(int32 x); 00654 00656 inline int32 ntoh24(int32 x); 00657 00659 inline int64 htonll(int64 number); 00660 00662 inline int64 ntohll(int64 number); 00663 00664 #ifdef WORDS_BIGENDIAN 00665 inline int32 hton24(int32 x) 00666 { 00667 return x; 00668 } 00669 00670 inline int32 ntoh24(int32 x) 00671 { 00672 return x; 00673 } 00674 00675 inline int64 htonll(int64 number) 00676 { 00677 return number; 00678 } 00679 00680 inline int64 ntohll(int64 number) 00681 { 00682 return number; 00683 } 00684 00685 #else /* WORDS_BIGENDIAN */ 00686 00687 inline int32 hton24(int32 x) 00688 { 00689 int32 ergebnis; 00690 00691 ergebnis = (x & 0xFF00) | ( (x & 0xFF) << 16) | ( (x & 0xFF0000) >> 16); 00692 return ergebnis; 00693 } 00694 00695 inline int32 ntoh24(int32 x) 00696 { 00697 int32 ergebnis; 00698 00699 ergebnis = (x & 0xFF00) | ( (x & 0xFF) << 16) | ( (x & 0xFF0000) >> 16); 00700 return ergebnis; 00701 } 00702 00703 inline int64 htonll(int64 number) 00704 { 00705 return ( htonl( (number >> 32) & 0xFFFFFFFF) | 00706 ((int64) (htonl(number & 0xFFFFFFFF)) << 32)); 00707 } 00708 00709 inline int64 ntohll(int64 number) 00710 { 00711 return ( htonl( (number >> 32) & 0xFFFFFFFF) | 00712 ((int64) (htonl(number & 0xFFFFFFFF)) << 32)); 00713 } 00714 #endif /* WORDS_BIGENDIAN */ 00715 00716 #endif /* MN_RTP_NET_TYPES_H */ 00717

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8