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 NAMESPACE_COMMONCPP
00044
00065 typedef enum
00066 {
00067 SDESItemTypeEND = 0,
00068 SDESItemTypeCNAME,
00069 SDESItemTypeNAME,
00070 SDESItemTypeEMAIL,
00071 SDESItemTypePHONE,
00072 SDESItemTypeLOC,
00073 SDESItemTypeTOOL,
00074 SDESItemTypeNOTE,
00075 SDESItemTypePRIV,
00076 SDESItemTypeH323CADDR,
00077 SDESItemTypeLast = SDESItemTypeH323CADDR
00078 } SDESItemType;
00079
00090 class __EXPORT RTCPCompoundHandler
00091 {
00092 public:
00093 inline void setPathMTU(uint16 mtu)
00094 { pathMTU = mtu; }
00095
00096 inline uint16 getPathMTU()
00097 { return pathMTU; }
00098
00099 #ifdef CCXX_PACKED
00100 #pragma pack(1)
00101 #endif
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
00255 unsigned char version:2;
00256 unsigned char padding:1;
00257 unsigned char block_count:5;
00258 #else
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 #ifdef CCXX_PACKED
00327 #pragma pack()
00328 #endif
00329
00330 protected:
00331 enum { defaultPathMTU = 1500 };
00332
00333 RTCPCompoundHandler(uint16 mtu = defaultPathMTU);
00334
00335 ~RTCPCompoundHandler();
00336
00348 bool
00349 checkCompoundRTCPHeader(size_t len);
00350
00351
00352
00353 unsigned char* rtcpSendBuffer;
00354
00355
00356 unsigned char* rtcpRecvBuffer;
00357
00358 friend class RTCPSenderInfo;
00359 friend class RTCPReceiverInfo;
00360 private:
00361
00362 uint16 pathMTU;
00363
00364 static const uint16 RTCP_VALID_MASK;
00365 static const uint16 RTCP_VALID_VALUE;
00366 };
00367
00374 class __EXPORT RTCPReceiverInfo
00375 {
00376 public:
00377 RTCPReceiverInfo(void* ri)
00378 { memcpy(&receiverInfo,&ri,
00379 sizeof(RTCPCompoundHandler::ReceiverInfo));}
00380
00381 RTCPReceiverInfo(RTCPCompoundHandler::ReceiverInfo& si)
00382 : receiverInfo( si )
00383 {
00384 }
00385
00386 ~RTCPReceiverInfo()
00387 { }
00388
00393 inline uint8
00394 getFractionLost() const
00395 { return receiverInfo.fractionLost; }
00396
00397 inline uint32
00398 getCumulativePacketLost() const
00399 { return ( ((uint32)ntohs(receiverInfo.lostLSW)) +
00400 (((uint32)receiverInfo.lostMSB) << 16) ); }
00401
00402 inline uint32
00403 getExtendedSeqNum() const
00404 { return ntohl(receiverInfo.highestSeqNum); }
00405
00412 uint32
00413 getJitter() const
00414 { return ntohl(receiverInfo.jitter); }
00415
00421 uint16
00422 getLastSRNTPTimestampInt() const
00423 { return (uint16)((ntohl(receiverInfo.lsr) & 0xFFFF0000) >> 16); }
00424
00430 uint16
00431 getLastSRNTPTimestampFrac() const
00432 { return (uint16)(ntohl(receiverInfo.lsr) & 0xFFFF); }
00433
00440 uint32
00441 getDelayLastSR() const
00442 { return ntohl(receiverInfo.dlsr); }
00443
00444 private:
00445 RTCPCompoundHandler::ReceiverInfo receiverInfo;
00446 };
00447
00454 class __EXPORT RTCPSenderInfo
00455 {
00456 public:
00457 RTCPSenderInfo(void* si)
00458 { memcpy(&senderInfo,&si,
00459 sizeof(RTCPCompoundHandler::SenderInfo));}
00460
00461 RTCPSenderInfo(RTCPCompoundHandler::SenderInfo& si)
00462 : senderInfo( si )
00463 {
00464 }
00465
00466 ~RTCPSenderInfo()
00467 { }
00468
00473 uint32
00474 getNTPTimestampInt() const
00475 { return ntohl(senderInfo.NTPMSW); }
00476
00481 uint32
00482 getNTPTimestampFrac() const
00483 { return ntohl(senderInfo.NTPLSW); }
00484
00485 inline uint32
00486 getRTPTimestamp() const
00487 { return ntohl(senderInfo.RTPTimestamp); }
00488
00492 inline uint32
00493 getPacketCount() const
00494 { return ntohl(senderInfo.packetCount); }
00495
00496 inline uint32
00497 getOctetCount() const
00498 { return ntohl(senderInfo.octetCount); }
00499
00500 private:
00501 RTCPCompoundHandler::SenderInfo senderInfo;
00502 };
00503
00512 timeval
00513 NTP2Timeval(uint32 msw, uint32 lsw);
00514
00522 uint32
00523 timevalIntervalTo65536(timeval& t);
00524
00526
00527 END_NAMESPACE
00528
00529 #endif // ndef CCXX_RTP_RTCPPKT_H_
00530