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
00061 class RTPPacket
00062 {
00063 protected:
00064 #pragma pack(1)
00065
00077 struct RTPFixedHeader
00078 {
00079 #if __BYTE_ORDER == __BIG_ENDIAN
00080
00081 unsigned char version:2;
00082 unsigned char padding:1;
00083 unsigned char extension:1;
00084 unsigned char cc:4;
00085 unsigned char marker:1;
00086 unsigned char payload:7;
00087 #else
00088
00089 unsigned char cc:4;
00090 unsigned char extension:1;
00091 unsigned char padding:1;
00092 unsigned char version:2;
00093 unsigned char payload:7;
00094 unsigned char marker:1;
00095 #endif
00096 uint16 sequence;
00097 uint32 timestamp;
00098 uint32 sources[1];
00099 };
00100
00108 typedef struct
00109 {
00110 uint16 undefined;
00111 uint16 length;
00112 } RTPHeaderExt;
00113 #pragma pack()
00114
00115
00116 uint32 hdrsize;
00117
00118 uint32 payload_size;
00119
00120 uint32 total;
00121
00122 unsigned char* buffer;
00123
00124 bool duplicated;
00125
00126 public:
00138 RTPPacket(const unsigned char* const block, size_t len,
00139 bool duplicate = false);
00140
00149 RTPPacket(size_t hdrlen, size_t plen);
00150
00154
00155 ~RTPPacket()
00156 { endPacket(); };
00157
00163 inline const RTPFixedHeader*
00164 getHeader(void) const
00165 { return reinterpret_cast<const RTPFixedHeader*>(buffer); };
00166
00173 inline uint32
00174 getHeaderSize(void) const
00175 { return hdrsize; };
00176
00184 inline const RTPHeaderExt*
00185 getHeaderExt() const
00186 { uint32 fixsize = sizeof(RTPFixedHeader) +
00187 (getHeader()->cc << 2);
00188 return (reinterpret_cast<RTPHeaderExt*>(buffer + fixsize));
00189 }
00190
00195 inline const unsigned char* const
00196 getPayload(void) const
00197 { return buffer + getHeaderSize(); };
00198
00202 inline uint32
00203 getPayloadSize() const
00204 { return payload_size; };
00205
00209 inline rtp_payload_t
00210 getPayloadType() const
00211 { return static_cast<rtp_payload_t>(getHeader()->payload); };
00212
00216 inline uint16
00217 getSeqNum() const
00218 { return ntohs(getHeader()->sequence); };
00219
00225 inline uint32
00226 getRawTimestamp(void) const
00227 { return ntohl(getHeader()->timestamp); };
00228
00233 inline bool
00234 isPadded() const
00235 { return getHeader()->padding; };
00236
00242 inline uint8
00243 getPaddingSize() const
00244 { return buffer[total - 1]; };
00245
00251 inline bool
00252 isMarked() const
00253 { return getHeader()->marker; };
00254
00259 inline bool
00260 isExtended() const
00261 { return getHeader()->extension; };
00262
00267 inline uint16
00268 getCSRCsCount() const
00269 { return getHeader()->cc; };
00270
00275 inline const uint32*
00276 getCSRCs() const
00277 { return static_cast<const uint32*>(&(getHeader()->sources[1])); };
00278
00285 inline const unsigned char* const
00286 getRawPacket() const
00287 { return buffer; };
00288
00295 inline uint32
00296 getRawPacketSize() const
00297 { return total; };
00298
00299 protected:
00300 inline void
00301 setbuffer(const void* src, size_t len, size_t pos)
00302 { memcpy(buffer + pos,src,len); }
00303
00307 void
00308 endPacket();
00309 };
00310
00322 class OutgoingRTPPkt: public RTPPacket
00323 {
00324 public:
00342 OutgoingRTPPkt::OutgoingRTPPkt(
00343 const uint32* const csrcs, uint16 numcsrc,
00344 const unsigned char* const hdrext, uint32 hdrextlen,
00345 const unsigned char* const data, uint32 datalen);
00346
00358 OutgoingRTPPkt::OutgoingRTPPkt(
00359 const uint32* const csrcs, uint16 numcsrc,
00360 const unsigned char* const data, uint32 datalen);
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 OutgoingRTPPkt::OutgoingRTPPkt(
00373 const unsigned char* const data, uint32 datalen);
00374
00378 ~OutgoingRTPPkt();
00379
00383 inline void
00384 setPayloadType(rtp_payload_t pt)
00385 { const_cast<RTPFixedHeader*>(getHeader())->payload = pt; };
00386
00390 inline void
00391 setSeqNum(uint16 seq)
00392 { const_cast<RTPFixedHeader*>(getHeader())->sequence = htons(seq); };
00393
00397 inline void
00398 setTimestamp(uint32 ts)
00399 { const_cast<RTPFixedHeader*>(getHeader())->timestamp =
00400 htonl(ts); };
00401
00408 inline void
00409 setSSRC(uint32 ssrc) const
00410 { const_cast<RTPFixedHeader*>(getHeader())->sources[0] = ssrc; };
00411
00415 inline void
00416 setMarker(bool mark)
00417 { const_cast<RTPFixedHeader*>(getHeader())->marker = mark; };
00418
00423 inline uint32
00424 getTimestamp() const
00425 { return getRawTimestamp(); };
00426
00430 inline bool
00431 operator==(const OutgoingRTPPkt &p) const
00432 { return ( this->getSeqNum() == p.getSeqNum() ); }
00433
00437 inline bool
00438 operator!=(const OutgoingRTPPkt &p) const
00439 { return !( *this==p ); };
00440
00441 private:
00446 OutgoingRTPPkt(const OutgoingRTPPkt &o);
00447
00452 OutgoingRTPPkt&
00453 operator=(const OutgoingRTPPkt &o);
00454
00455
00456 OutgoingRTPPkt *next, *prev;
00457
00458 friend RTPQueue;
00459 };
00460
00474 class IncomingRTPPkt : public RTPPacket
00475 {
00476 public:
00496 IncomingRTPPkt(RTPQueue &queue, const unsigned char* block,
00497 size_t len, struct timeval recvtime);
00498
00502 ~IncomingRTPPkt();
00503
00509 inline bool
00510 isHeaderValid()
00511 { return valid; }
00512
00516 inline bool
00517 operator==(const IncomingRTPPkt &p) const
00518 { return ( (this->getSeqNum() == p.getSeqNum()) &&
00519 (this->getSSRC() == p.getSSRC()) ); }
00520
00524 inline bool
00525 operator!=(const IncomingRTPPkt &p) const
00526 { return !( *this == p ); };
00527
00534 inline uint32
00535 getSSRC() const
00536 { return static_cast<uint32>(getHeader()->sources[0]); };
00537
00544 inline RTPSource&
00545 getSource() const
00546 { return source; };
00547
00556 inline uint32
00557 getTimestamp() const
00558 { return cached_timestamp; };
00559
00567 inline void
00568 setRecvTimestamp(const timeval &t)
00569 { reception_timestamp = t; }
00570
00578 inline timeval
00579 getRecvTimestamp() const
00580 { return reception_timestamp; }
00581
00594 inline uint16
00595 getExtUndefined() const
00596 { return (isExtended()? getHeaderExt()->undefined : 0); };
00597
00609 inline uint32
00610 getExtSize() const
00611 { return (isExtended()? getHeaderExt()->length : 0); };
00612
00613 private:
00618 IncomingRTPPkt(const IncomingRTPPkt &ip);
00619
00624 IncomingRTPPkt&
00625 operator=(const IncomingRTPPkt &ip);
00626
00627
00628 IncomingRTPPkt *next, *prev;
00629
00630 IncomingRTPPkt *srcnext, *srcprev;
00631
00632 RTPSource &source;
00633
00634 struct timeval reception_timestamp;
00635
00636 bool valid;
00637
00638
00639
00640 uint32 cached_timestamp;
00641
00642
00643 static const uint16 RTP_INVALID_MASK = (0x7e);
00644 static const uint16 RTP_INVALID_VALUE = (0x48);
00645
00646 friend RTPQueue;
00647 friend RTPSource;
00648 };
00649
00650 #pragma pack(1)
00651
00655 typedef struct
00656 {
00657 #if __BYTE_ORDER == __BIG_ENDIAN
00658
00659 unsigned char version:2;
00660 unsigned char padding:1;
00661 unsigned char block_count:5;
00662 #else
00663
00664 unsigned char block_count:5;
00665 unsigned char padding:1;
00666 unsigned char version:2;
00667 #endif
00668 uint8 type;
00669 uint16 length;
00670 } RTCPFixedHeader;
00671 #pragma pack()
00672
00673 #endif //CCXX_RTPEXT_H
00674