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
00039
00040
00049 #ifndef CCXX_RTPEXT_H
00050 # define CCXX_RTPEXT_H
00051
00052 #ifdef __NAMESPACES__
00053 namespace ost {
00054 #endif
00055
00065 class CCXX_CLASS_EXPORT RTPPacket
00066 {
00067 protected:
00068 #pragma pack(1)
00069
00081 struct RTPFixedHeader
00082 {
00083 #if __BYTE_ORDER == __BIG_ENDIAN
00084
00085 unsigned char version:2;
00086 unsigned char padding:1;
00087 unsigned char extension:1;
00088 unsigned char cc:4;
00089 unsigned char marker:1;
00090 unsigned char payload:7;
00091 #else
00092
00093 unsigned char cc:4;
00094 unsigned char extension:1;
00095 unsigned char padding:1;
00096 unsigned char version:2;
00097 unsigned char payload:7;
00098 unsigned char marker:1;
00099 #endif
00100 uint16 sequence;
00101 uint32 timestamp;
00102 uint32 sources[1];
00103 };
00104
00112 typedef struct
00113 {
00114 uint16 undefined;
00115 uint16 length;
00116 } RTPHeaderExt;
00117 #pragma pack()
00118
00119
00120 uint32 hdrsize;
00121
00122 uint32 payload_size;
00123
00124 uint32 total;
00125
00126 unsigned char* buffer;
00127
00128 bool duplicated;
00129
00130 public:
00142 RTPPacket(const unsigned char* const block, size_t len,
00143 bool duplicate = false);
00144
00153 RTPPacket(size_t hdrlen, size_t plen);
00154
00158
00159 ~RTPPacket()
00160 { endPacket(); };
00161
00167 inline const RTPFixedHeader*
00168 getHeader(void) const
00169 { return reinterpret_cast<const RTPFixedHeader*>(buffer); };
00170
00177 inline uint32
00178 getHeaderSize(void) const
00179 { return hdrsize; };
00180
00188 inline const RTPHeaderExt*
00189 getHeaderExt() const
00190 { uint32 fixsize = sizeof(RTPFixedHeader) +
00191 (getHeader()->cc << 2);
00192 return (reinterpret_cast<RTPHeaderExt*>(buffer + fixsize));
00193 }
00194
00199 inline const unsigned char* const
00200 getPayload(void) const
00201 { return buffer + getHeaderSize(); };
00202
00206 inline uint32
00207 getPayloadSize() const
00208 { return payload_size; };
00209
00213 inline rtp_payload_t
00214 getPayloadType() const
00215 { return static_cast<rtp_payload_t>(getHeader()->payload); };
00216
00220 inline uint16
00221 getSeqNum() const
00222 { return ntohs(getHeader()->sequence); };
00223
00229 inline uint32
00230 getRawTimestamp(void) const
00231 { return ntohl(getHeader()->timestamp); };
00232
00237 inline bool
00238 isPadded() const
00239 { return getHeader()->padding; };
00240
00246 inline uint8
00247 getPaddingSize() const
00248 { return buffer[total - 1]; };
00249
00255 inline bool
00256 isMarked() const
00257 { return getHeader()->marker; };
00258
00263 inline bool
00264 isExtended() const
00265 { return getHeader()->extension; };
00266
00271 inline uint16
00272 getCSRCsCount() const
00273 { return getHeader()->cc; };
00274
00279 inline const uint32*
00280 getCSRCs() const
00281 { return static_cast<const uint32*>(&(getHeader()->sources[1])); };
00282
00289 inline const unsigned char* const
00290 getRawPacket() const
00291 { return buffer; };
00292
00299 inline uint32
00300 getRawPacketSize() const
00301 { return total; };
00302
00303 protected:
00304 inline void
00305 setbuffer(const void* src, size_t len, size_t pos)
00306 { memcpy(buffer + pos,src,len); }
00307
00311 void
00312 endPacket();
00313 };
00314
00326 class CCXX_CLASS_EXPORT OutgoingRTPPkt: public RTPPacket
00327 {
00328 public:
00346 OutgoingRTPPkt::OutgoingRTPPkt(
00347 const uint32* const csrcs, uint16 numcsrc,
00348 const unsigned char* const hdrext, uint32 hdrextlen,
00349 const unsigned char* const data, uint32 datalen);
00350
00362 OutgoingRTPPkt::OutgoingRTPPkt(
00363 const uint32* const csrcs, uint16 numcsrc,
00364 const unsigned char* const data, uint32 datalen);
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376 OutgoingRTPPkt::OutgoingRTPPkt(
00377 const unsigned char* const data, uint32 datalen);
00378
00382 ~OutgoingRTPPkt();
00383
00387 inline void
00388 setPayloadType(rtp_payload_t pt)
00389 { const_cast<RTPFixedHeader*>(getHeader())->payload = pt; };
00390
00394 inline void
00395 setSeqNum(uint16 seq)
00396 { const_cast<RTPFixedHeader*>(getHeader())->sequence = htons(seq); };
00397
00401 inline void
00402 setTimestamp(uint32 ts)
00403 { const_cast<RTPFixedHeader*>(getHeader())->timestamp =
00404 htonl(ts); };
00405
00412 inline void
00413 setSSRC(uint32 ssrc) const
00414 { const_cast<RTPFixedHeader*>(getHeader())->sources[0] = ssrc; };
00415
00419 inline void
00420 setMarker(bool mark)
00421 { const_cast<RTPFixedHeader*>(getHeader())->marker = mark; };
00422
00427 inline uint32
00428 getTimestamp() const
00429 { return getRawTimestamp(); };
00430
00434 inline bool
00435 operator==(const OutgoingRTPPkt &p) const
00436 { return ( this->getSeqNum() == p.getSeqNum() ); }
00437
00441 inline bool
00442 operator!=(const OutgoingRTPPkt &p) const
00443 { return !( *this==p ); };
00444
00445 private:
00450 OutgoingRTPPkt(const OutgoingRTPPkt &o);
00451
00456 OutgoingRTPPkt&
00457 operator=(const OutgoingRTPPkt &o);
00458
00459
00460 OutgoingRTPPkt *next, *prev;
00461
00462 friend RTPQueue;
00463 };
00464
00478 class CCXX_CLASS_EXPORT IncomingRTPPkt : public RTPPacket
00479 {
00480 public:
00500 IncomingRTPPkt(RTPQueue &queue, const unsigned char* block,
00501 size_t len, struct timeval recvtime);
00502
00506 ~IncomingRTPPkt();
00507
00513 inline bool
00514 isHeaderValid()
00515 { return valid; }
00516
00520 inline bool
00521 operator==(const IncomingRTPPkt &p) const
00522 { return ( (this->getSeqNum() == p.getSeqNum()) &&
00523 (this->getSSRC() == p.getSSRC()) ); }
00524
00528 inline bool
00529 operator!=(const IncomingRTPPkt &p) const
00530 { return !( *this == p ); };
00531
00538 inline uint32
00539 getSSRC() const
00540 { return static_cast<uint32>(getHeader()->sources[0]); };
00541
00548 inline RTPSource&
00549 getSource() const
00550 { return source; };
00551
00560 inline uint32
00561 getTimestamp() const
00562 { return cached_timestamp; };
00563
00571 inline void
00572 setRecvTimestamp(const timeval &t)
00573 { reception_timestamp = t; }
00574
00582 inline timeval
00583 getRecvTimestamp() const
00584 { return reception_timestamp; }
00585
00598 inline uint16
00599 getExtUndefined() const
00600 { return (isExtended()? getHeaderExt()->undefined : 0); };
00601
00613 inline uint32
00614 getExtSize() const
00615 { return (isExtended()? getHeaderExt()->length : 0); };
00616
00617 private:
00622 IncomingRTPPkt(const IncomingRTPPkt &ip);
00623
00628 IncomingRTPPkt&
00629 operator=(const IncomingRTPPkt &ip);
00630
00631
00632 IncomingRTPPkt *next, *prev;
00633
00634 IncomingRTPPkt *srcnext, *srcprev;
00635
00636 RTPSource &source;
00637
00638 struct timeval reception_timestamp;
00639
00640 bool valid;
00641
00642
00643
00644 uint32 cached_timestamp;
00645
00646
00647 static const uint16 RTP_INVALID_MASK = (0x7e);
00648 static const uint16 RTP_INVALID_VALUE = (0x48);
00649
00650 friend RTPQueue;
00651 friend RTPSource;
00652 };
00653
00654 #pragma pack(1)
00655
00659 typedef struct
00660 {
00661 #if __BYTE_ORDER == __BIG_ENDIAN
00662
00663 unsigned char version:2;
00664 unsigned char padding:1;
00665 unsigned char block_count:5;
00666 #else
00667
00668 unsigned char block_count:5;
00669 unsigned char padding:1;
00670 unsigned char version:2;
00671 #endif
00672 uint8 type;
00673 uint16 length;
00674 } RTCPFixedHeader;
00675 #pragma pack()
00676
00677 #ifdef __NAMESPACES__
00678 };
00679 #endif
00680
00681 #endif //CCXX_RTPEXT_H
00682