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 #pragma pack(1)
00102
00109 struct ReceiverInfo
00110 {
00111 uint8 fractionLost;
00112 uint8 lostMSB;
00113 uint16 lostLSW;
00114 uint32 highestSeqNum;
00115 uint32 jitter;
00116 uint32 lsr;
00117 uint32 dlsr;
00118 };
00119
00126 struct RRBlock
00127 {
00128 uint32 ssrc;
00129 ReceiverInfo rinfo;
00130 };
00131
00138 struct RecvReport
00139 {
00140 uint32 ssrc;
00141 RRBlock blocks[1];
00142 };
00143
00150 struct SenderInfo
00151 {
00152 uint32 NTPMSW;
00153 uint32 NTPLSW;
00154 uint32 RTPTimestamp;
00155 uint32 packetCount;
00156 uint32 octetCount;
00157 };
00158
00164 struct SendReport
00165 {
00166 uint32 ssrc;
00167 SenderInfo sinfo;
00168 RRBlock blocks[1];
00169 };
00170
00176 struct SDESItem
00177 {
00178 uint8 type;
00179 uint8 len;
00180 char data[1];
00181 };
00182
00188 struct SDESChunk
00189 {
00190 uint32 getSSRC() const
00191 { return (ntohl(ssrc)); }
00192
00193 uint32 ssrc;
00194 SDESItem item;
00195 };
00196
00202 struct BYEPacket
00203 {
00204 uint32 ssrc;
00205 uint8 length;
00206 };
00207
00213 struct APPPacket
00214 {
00215 uint32 ssrc;
00216 char name [4];
00217
00218
00219 unsigned char data[1];
00220 };
00221
00228 struct FIRPacket
00229 {
00230 uint32 ssrc;
00231 };
00232
00239 struct NACKPacket
00240 {
00241 uint32 ssrc;
00242 uint16 fsn;
00243 uint16 blp;
00244 };
00245
00251 struct RTCPFixedHeader
00252 {
00253 #if __BYTE_ORDER == __BIG_ENDIAN
00254
00255 unsigned char version:2;
00256 unsigned char padding:1;
00257 unsigned char block_count:5;
00258 #else
00259
00260 unsigned char block_count:5;
00261 unsigned char padding:1;
00262 unsigned char version:2;
00263 #endif
00264 uint8 type;
00265 uint16 length;
00266 };
00267
00278 struct RTCPPacket
00279 {
00285 typedef enum {
00286 tSR = 200,
00287 tRR,
00288 tSDES,
00289 tBYE,
00290 tAPP,
00291 tFIR = 192,
00292 tNACK = 193,
00293 tXR
00294 } Type;
00295
00300 uint32 getLength() const
00301 { return ((ntohs(fh.length) + 1) << 2); }
00302
00307 uint32 getSSRC() const
00308 { return (ntohl(info.RR.ssrc)); }
00309
00310
00311 RTCPFixedHeader fh;
00312
00313
00314
00315 union
00316 {
00317 SendReport SR;
00318 RecvReport RR;
00319 SDESChunk SDES;
00320 BYEPacket BYE;
00321 APPPacket APP;
00322 NACKPacket NACK;
00323 FIRPacket FIR;
00324 } info;
00325 };
00326 #pragma pack()
00327
00328 protected:
00329 enum { defaultPathMTU = 1500 };
00330
00331 RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
00332
00333 ~RTCPCompoundHandler();
00334
00346 bool
00347 checkCompoundRTCPHeader(size_t len);
00348
00349
00350
00351 unsigned char* rtcpSendBuffer;
00352
00353
00354 unsigned char* rtcpRecvBuffer;
00355
00356 friend class RTCPSenderInfo;
00357 friend class RTCPReceiverInfo;
00358 private:
00359
00360 uint16 pathMTU;
00361
00362 static const uint16 RTCP_VALID_MASK;
00363 static const uint16 RTCP_VALID_VALUE;
00364 };
00365
00372 class __EXPORT RTCPReceiverInfo
00373 {
00374 public:
00375 RTCPReceiverInfo(void* ri)
00376 { memcpy(&receiverInfo,&ri,
00377 sizeof(RTCPCompoundHandler::ReceiverInfo));}
00378
00379 ~RTCPReceiverInfo()
00380 { }
00381
00386 inline uint8
00387 getFractionLost() const
00388 { return receiverInfo.fractionLost; }
00389
00390 inline uint32
00391 getCumulativePacketLost() const
00392 { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
00393 (((uint32)receiverInfo.lostMSB) << 16) ); }
00394
00395 inline uint32
00396 getExtendedSeqNum() const
00397 { return ntohl(receiverInfo.highestSeqNum); }
00398
00405 uint32
00406 getJitter() const
00407 { return ntohl(receiverInfo.jitter); }
00408
00414 uint16
00415 getLastSRNTPTimestampInt() const
00416 { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
00417
00423 uint16
00424 getLastSRNTPTimestampFrac() const
00425 { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
00426
00433 uint32
00434 getDelayLastSR() const
00435 { return ntohl(receiverInfo.dlsr); }
00436
00437 private:
00438 RTCPCompoundHandler::ReceiverInfo receiverInfo;
00439 };
00440
00447 class __EXPORT RTCPSenderInfo
00448 {
00449 public:
00450 RTCPSenderInfo(void* si)
00451 { memcpy(&senderInfo,&si,
00452 sizeof(RTCPCompoundHandler::SenderInfo));}
00453
00454 ~RTCPSenderInfo()
00455 { }
00456
00461 uint32
00462 getNTPTimestampInt() const
00463 { return ntohl(senderInfo.NTPMSW); }
00464
00469 uint32
00470 getNTPTimestampFrac() const
00471 { return ntohl(senderInfo.NTPLSW); }
00472
00473 inline uint32
00474 getRTPTimestamp() const
00475 { return ntohl(senderInfo.RTPTimestamp); }
00476
00480 inline uint32
00481 getPacketCount() const
00482 { return ntohl(senderInfo.octetCount); }
00483
00484 inline uint32
00485 getOctetCount() const
00486 { return ntohl(senderInfo.packetCount); }
00487
00488 private:
00489 RTCPCompoundHandler::SenderInfo senderInfo;
00490 };
00491
00500 timeval
00501 NTP2Timeval(uint32 msw, uint32 lsw);
00502
00510 uint32
00511 timevalIntervalTo65536(timeval& t);
00512
00514
00515 #ifdef CCXX_NAMESPACES
00516 }
00517 #endif
00518
00519 #endif // ndef CCXX_RTP_RTCPPKT_H_
00520