00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef CCXX_RTP_RTCPPKT_H_
00039 #define CCXX_RTP_RTCPPKT_H_
00040
00041 #include <ccrtp/base.h>
00042
00043 #ifdef CCXX_NAMESPACES
00044 namespace ost {
00045 #endif
00046
00067 typedef enum
00068 {
00069 SDESItemTypeEND = 0,
00070 SDESItemTypeCNAME,
00071 SDESItemTypeNAME,
00072 SDESItemTypeEMAIL,
00073 SDESItemTypePHONE,
00074 SDESItemTypeLOC,
00075 SDESItemTypeTOOL,
00076 SDESItemTypeNOTE,
00077 SDESItemTypePRIV,
00078 SDESItemTypeH323CADDR,
00079 SDESItemTypeLast = SDESItemTypeH323CADDR
00080 } SDESItemType;
00081
00092 class __EXPORT RTCPCompoundHandler
00093 {
00094 public:
00095 inline void setPathMTU(uint16 mtu)
00096 { pathMTU = mtu; }
00097
00098 inline uint16 getPathMTU()
00099 { return pathMTU; }
00100
00101 #ifdef CCXX_PACKED
00102 #pragma pack(1)
00103 #endif
00104
00111 struct ReceiverInfo
00112 {
00113 uint8 fractionLost;
00114 uint8 lostMSB;
00115 uint16 lostLSW;
00116 uint32 highestSeqNum;
00117 uint32 jitter;
00118 uint32 lsr;
00119 uint32 dlsr;
00120 };
00121
00128 struct RRBlock
00129 {
00130 uint32 ssrc;
00131 ReceiverInfo rinfo;
00132 };
00133
00140 struct RecvReport
00141 {
00142 uint32 ssrc;
00143 RRBlock blocks[1];
00144 };
00145
00152 struct SenderInfo
00153 {
00154 uint32 NTPMSW;
00155 uint32 NTPLSW;
00156 uint32 RTPTimestamp;
00157 uint32 packetCount;
00158 uint32 octetCount;
00159 };
00160
00166 struct SendReport
00167 {
00168 uint32 ssrc;
00169 SenderInfo sinfo;
00170 RRBlock blocks[1];
00171 };
00172
00178 struct SDESItem
00179 {
00180 uint8 type;
00181 uint8 len;
00182 char data[1];
00183 };
00184
00190 struct SDESChunk
00191 {
00192 uint32 getSSRC() const
00193 { return (ntohl(ssrc)); }
00194
00195 uint32 ssrc;
00196 SDESItem item;
00197 };
00198
00204 struct BYEPacket
00205 {
00206 uint32 ssrc;
00207 uint8 length;
00208 };
00209
00215 struct APPPacket
00216 {
00217 uint32 ssrc;
00218 char name [4];
00219
00220
00221 unsigned char data[1];
00222 };
00223
00230 struct FIRPacket
00231 {
00232 uint32 ssrc;
00233 };
00234
00241 struct NACKPacket
00242 {
00243 uint32 ssrc;
00244 uint16 fsn;
00245 uint16 blp;
00246 };
00247
00253 struct RTCPFixedHeader
00254 {
00255 #if __BYTE_ORDER == __BIG_ENDIAN
00257 unsigned char version:2;
00258 unsigned char padding:1;
00259 unsigned char block_count:5;
00260 #else
00262 unsigned char block_count:5;
00263 unsigned char padding:1;
00264 unsigned char version:2;
00265 #endif
00266 uint8 type;
00267 uint16 length;
00268 };
00269
00280 struct RTCPPacket
00281 {
00287 typedef enum {
00288 tSR = 200,
00289 tRR,
00290 tSDES,
00291 tBYE,
00292 tAPP,
00293 tFIR = 192,
00294 tNACK = 193,
00295 tXR
00296 } Type;
00297
00302 uint32 getLength() const
00303 { return ((ntohs(fh.length) + 1) << 2); }
00304
00309 uint32 getSSRC() const
00310 { return (ntohl(info.RR.ssrc)); }
00311
00312
00313 RTCPFixedHeader fh;
00314
00315
00316
00317 union
00318 {
00319 SendReport SR;
00320 RecvReport RR;
00321 SDESChunk SDES;
00322 BYEPacket BYE;
00323 APPPacket APP;
00324 NACKPacket NACK;
00325 FIRPacket FIR;
00326 } info;
00327 };
00328 #ifdef CCXX_PACKED
00329 #pragma pack()
00330 #endif
00331
00332 protected:
00333 enum { defaultPathMTU = 1500 };
00334
00335 RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
00336
00337 ~RTCPCompoundHandler();
00338
00350 bool
00351 checkCompoundRTCPHeader(size_t len);
00352
00353
00354
00355 unsigned char* rtcpSendBuffer;
00356
00357
00358 unsigned char* rtcpRecvBuffer;
00359
00360 friend class RTCPSenderInfo;
00361 friend class RTCPReceiverInfo;
00362 private:
00363
00364 uint16 pathMTU;
00365
00366 static const uint16 RTCP_VALID_MASK;
00367 static const uint16 RTCP_VALID_VALUE;
00368 };
00369
00376 class __EXPORT RTCPReceiverInfo
00377 {
00378 public:
00379 RTCPReceiverInfo(void* ri)
00380 { memcpy(&receiverInfo,&ri,
00381 sizeof(RTCPCompoundHandler::ReceiverInfo));}
00382
00383 RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo& si)
00384 : receiverInfo( si )
00385 {
00386 }
00387
00388 ~RTCPReceiverInfo()
00389 { }
00390
00395 inline uint8
00396 getFractionLost() const
00397 { return receiverInfo.fractionLost; }
00398
00399 inline uint32
00400 getCumulativePacketLost() const
00401 { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
00402 (((uint32)receiverInfo.lostMSB) << 16) ); }
00403
00404 inline uint32
00405 getExtendedSeqNum() const
00406 { return ntohl(receiverInfo.highestSeqNum); }
00407
00414 uint32
00415 getJitter() const
00416 { return ntohl(receiverInfo.jitter); }
00417
00423 uint16
00424 getLastSRNTPTimestampInt() const
00425 { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
00426
00432 uint16
00433 getLastSRNTPTimestampFrac() const
00434 { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
00435
00442 uint32
00443 getDelayLastSR() const
00444 { return ntohl(receiverInfo.dlsr); }
00445
00446 private:
00447 RTCPCompoundHandler::ReceiverInfo receiverInfo;
00448 };
00449
00456 class __EXPORT RTCPSenderInfo
00457 {
00458 public:
00459 RTCPSenderInfo(void* si)
00460 { memcpy(&senderInfo,&si,
00461 sizeof(RTCPCompoundHandler::SenderInfo));}
00462
00463 RTCPSenderInfo(RTCPCompoundHandler::SenderInfo& si)
00464 : senderInfo( si )
00465 {
00466 }
00467
00468 ~RTCPSenderInfo()
00469 { }
00470
00475 uint32
00476 getNTPTimestampInt() const
00477 { return ntohl(senderInfo.NTPMSW); }
00478
00483 uint32
00484 getNTPTimestampFrac() const
00485 { return ntohl(senderInfo.NTPLSW); }
00486
00487 inline uint32
00488 getRTPTimestamp() const
00489 { return ntohl(senderInfo.RTPTimestamp); }
00490
00494 inline uint32
00495 getPacketCount() const
00496 { return ntohl(senderInfo.packetCount); }
00497
00498 inline uint32
00499 getOctetCount() const
00500 { return ntohl(senderInfo.octetCount); }
00501
00502 private:
00503 RTCPCompoundHandler::SenderInfo senderInfo;
00504 };
00505
00514 timeval
00515 NTP2Timeval(uint32 msw, uint32 lsw);
00516
00524 uint32
00525 timevalIntervalTo65536(timeval& t);
00526
00528
00529 #ifdef CCXX_NAMESPACES
00530 }
00531 #endif
00532
00533 #endif // ndef CCXX_RTP_RTCPPKT_H_
00534