ccRTP
|
00001 // Copyright (C) 2001-2015 Federico Montesino Pouzols <fedemp@altern.org>. 00002 // 00003 // This program is free software; you can redistribute it and/or modify 00004 // it under the terms of the GNU General Public License as published by 00005 // the Free Software Foundation; either version 2 of the License, or 00006 // (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public License 00014 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>. 00015 // 00016 // As a special exception, you may use this file as part of a free software 00017 // library without restriction. Specifically, if other files instantiate 00018 // templates or use macros or inline functions from this file, or you compile 00019 // this file and link it with other files to produce an executable, this 00020 // file does not by itself cause the resulting executable to be covered by 00021 // the GNU General Public License. This exception does not however 00022 // invalidate any other reasons why the executable file might be covered by 00023 // the GNU General Public License. 00024 // 00025 // This exception applies only to the code released under the name GNU 00026 // ccRTP. If you copy code from other releases into a copy of GNU 00027 // ccRTP, as the General Public License permits, the exception does 00028 // not apply to the code that you add in this way. To avoid misleading 00029 // anyone as to the status of such modified files, you must delete 00030 // this exception notice from them. 00031 // 00032 // If you write modifications of your own for GNU ccRTP, it is your choice 00033 // whether to permit this exception to apply to your modifications. 00034 // If you do not wish that, delete this exception notice. 00035 // 00036 00037 #ifndef CCXX_RTP_RTCPPKT_H_ 00038 #define CCXX_RTP_RTCPPKT_H_ 00039 00040 #include <ccrtp/base.h> 00041 00042 NAMESPACE_COMMONCPP 00043 00064 typedef enum 00065 { 00066 SDESItemTypeEND = 0, 00067 SDESItemTypeCNAME, 00068 SDESItemTypeNAME, 00069 SDESItemTypeEMAIL, 00070 SDESItemTypePHONE, 00071 SDESItemTypeLOC, 00072 SDESItemTypeTOOL, 00073 SDESItemTypeNOTE, 00074 SDESItemTypePRIV, 00075 SDESItemTypeH323CADDR, 00076 SDESItemTypeLast = SDESItemTypeH323CADDR 00077 } SDESItemType; 00078 00089 class __EXPORT RTCPCompoundHandler 00090 { 00091 public: 00092 inline void setPathMTU(uint16 mtu) 00093 { pathMTU = mtu; } 00094 00095 inline uint16 getPathMTU() 00096 { return pathMTU; } 00097 00098 #ifdef CCXX_PACKED 00099 #pragma pack(1) 00100 #endif 00101 00108 struct ReceiverInfo 00109 { 00110 uint8 fractionLost; 00111 uint8 lostMSB; 00112 uint16 lostLSW; 00113 uint32 highestSeqNum; 00114 uint32 jitter; 00115 uint32 lsr; 00116 uint32 dlsr; 00117 }; 00118 00125 struct RRBlock 00126 { 00127 uint32 ssrc; 00128 ReceiverInfo rinfo; 00129 }; 00130 00137 struct RecvReport 00138 { 00139 uint32 ssrc; 00140 RRBlock blocks[1]; 00141 }; 00142 00149 struct SenderInfo 00150 { 00151 uint32 NTPMSW; 00152 uint32 NTPLSW; 00153 uint32 RTPTimestamp; 00154 uint32 packetCount; 00155 uint32 octetCount; 00156 }; 00157 00163 struct SendReport 00164 { 00165 uint32 ssrc; 00166 SenderInfo sinfo; 00167 RRBlock blocks[1]; 00168 }; 00169 00175 struct SDESItem 00176 { 00177 uint8 type; 00178 uint8 len; 00179 char data[1]; 00180 }; 00181 00187 struct SDESChunk 00188 { 00189 uint32 getSSRC() const 00190 { return (ntohl(ssrc)); } 00191 00192 uint32 ssrc; 00193 SDESItem item; 00194 }; 00195 00201 struct BYEPacket 00202 { 00203 uint32 ssrc; 00204 uint8 length; 00205 }; 00206 00212 struct APPPacket 00213 { 00214 uint32 ssrc; 00215 char name [4]; 00216 00217 00218 unsigned char data[1]; 00219 }; 00220 00227 struct FIRPacket 00228 { 00229 uint32 ssrc; 00230 }; 00231 00238 struct NACKPacket 00239 { 00240 uint32 ssrc; 00241 uint16 fsn; 00242 uint16 blp; 00243 }; 00244 00250 struct RTCPFixedHeader 00251 { 00252 #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN 00253 00254 unsigned char version:2; 00255 unsigned char padding:1; 00256 unsigned char block_count:5; 00257 #else 00258 00259 unsigned char block_count:5; 00260 unsigned char padding:1; 00261 unsigned char version:2; 00262 #endif 00263 uint8 type; 00264 uint16 length; 00265 }; 00266 00277 struct RTCPPacket 00278 { 00284 typedef enum { 00285 tSR = 200, 00286 tRR, 00287 tSDES, 00288 tBYE, 00289 tAPP, 00290 tFIR = 192, 00291 tNACK = 193, 00292 tXR 00293 } Type; 00294 00299 uint32 getLength() const 00300 { return ((ntohs(fh.length) + 1) << 2); } 00301 00306 uint32 getSSRC() const 00307 { return (ntohl(info.RR.ssrc)); } // SSRC is always the first 00308 // word after fh. 00309 00310 RTCPFixedHeader fh; 00311 00312 // An RTCP packet may be of any of the types defined 00313 // above, including APP specific ones. 00314 union 00315 { 00316 SendReport SR; 00317 RecvReport RR; 00318 SDESChunk SDES; 00319 BYEPacket BYE; 00320 APPPacket APP; 00321 NACKPacket NACK; 00322 FIRPacket FIR; 00323 } info; 00324 }; 00325 #ifdef CCXX_PACKED 00326 #pragma pack() 00327 #endif 00328 00329 protected: 00330 enum { defaultPathMTU = 1500 }; 00331 00332 RTCPCompoundHandler(uint16 mtu = defaultPathMTU); 00333 00334 ~RTCPCompoundHandler(); 00335 00347 bool 00348 checkCompoundRTCPHeader(size_t len); 00349 00350 // buffer to hold RTCP compound packets being sent. Allocated 00351 // in construction time 00352 unsigned char* rtcpSendBuffer; 00353 // buffer to hold RTCP compound packets being 00354 // received. Allocated at construction time 00355 unsigned char* rtcpRecvBuffer; 00356 00357 friend class RTCPSenderInfo; 00358 friend class RTCPReceiverInfo; 00359 private: 00360 // path MTU. RTCP packets should not be greater than this 00361 uint16 pathMTU; 00362 // masks for RTCP header validation; 00363 static const uint16 RTCP_VALID_MASK; 00364 static const uint16 RTCP_VALID_VALUE; 00365 }; 00366 00373 class __EXPORT RTCPReceiverInfo 00374 { 00375 public: 00376 RTCPReceiverInfo(void* ri) 00377 { memcpy(&receiverInfo,&ri, 00378 sizeof(RTCPCompoundHandler::ReceiverInfo));} 00379 00380 RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo& si) 00381 : receiverInfo( si ) 00382 { 00383 } 00384 00385 ~RTCPReceiverInfo() 00386 { } 00387 00392 inline uint8 00393 getFractionLost() const 00394 { return receiverInfo.fractionLost; } 00395 00396 inline uint32 00397 getCumulativePacketLost() const 00398 { return ( ((uint32)ntohs(receiverInfo.lostLSW)) + 00399 (((uint32)receiverInfo.lostMSB) << 16) ); } 00400 00401 inline uint32 00402 getExtendedSeqNum() const 00403 { return ntohl(receiverInfo.highestSeqNum); } 00404 00411 uint32 00412 getJitter() const 00413 { return ntohl(receiverInfo.jitter); } 00414 00420 uint16 00421 getLastSRNTPTimestampInt() const 00422 { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); } 00423 00429 uint16 00430 getLastSRNTPTimestampFrac() const 00431 { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); } 00432 00439 uint32 00440 getDelayLastSR() const 00441 { return ntohl(receiverInfo.dlsr); } 00442 00443 private: 00444 RTCPCompoundHandler::ReceiverInfo receiverInfo; 00445 }; 00446 00453 class __EXPORT RTCPSenderInfo 00454 { 00455 public: 00456 RTCPSenderInfo(void* si) 00457 { memcpy(&senderInfo,&si, 00458 sizeof(RTCPCompoundHandler::SenderInfo));} 00459 00460 RTCPSenderInfo(RTCPCompoundHandler::SenderInfo& si) 00461 : senderInfo( si ) 00462 { 00463 } 00464 00465 ~RTCPSenderInfo() 00466 { } 00467 00472 uint32 00473 getNTPTimestampInt() const 00474 { return ntohl(senderInfo.NTPMSW); } 00475 00480 uint32 00481 getNTPTimestampFrac() const 00482 { return ntohl(senderInfo.NTPLSW); } 00483 00484 inline uint32 00485 getRTPTimestamp() const 00486 { return ntohl(senderInfo.RTPTimestamp); } 00487 00491 inline uint32 00492 getPacketCount() const 00493 { return ntohl(senderInfo.packetCount); } 00494 00495 inline uint32 00496 getOctetCount() const 00497 { return ntohl(senderInfo.octetCount); } 00498 00499 private: 00500 RTCPCompoundHandler::SenderInfo senderInfo; 00501 }; 00502 00511 timeval 00512 NTP2Timeval(uint32 msw, uint32 lsw); 00513 00521 uint32 00522 timevalIntervalTo65536(timeval& t); 00523 // rtcppacket 00525 00526 END_NAMESPACE 00527 00528 #endif // ndef CCXX_RTP_RTCPPKT_H_ 00529