📄 rtppkt.h
字号:
}; /** * @struct RFC2833Payload * @short a structure defining RFC2833 Telephony events. * * structure to define RFC2833 telephony events in RTP. You can * use this by recasing the pointer returned by getPayload(). */public: struct RFC2833Payload {#if __BYTE_ORDER == __BIG_ENDIAN uint8 event : 8; bool ebit : 1; bool rbit : 1; uint8 vol : 6; uint16 duration : 16;#else uint8 event : 8; uint8 vol : 6; bool rbit : 1; bool ebit : 1; uint16 duration : 16;#endif };private: /** * @struct RTPHeaderExt * * Fixed component of the variable-length header extension, * appended to the fixed header, after the CSRC list, when X * == 1. **/ struct RTPHeaderExt { uint16 undefined; ///< to be defined uint16 length; ///< number of 32-bit words in the extension };#ifdef CCXX_PACKED#pragma pack()#endif /* definitions for access to most common 2833 fields... */public: /** * Fetch a raw 2833 packet. * * @return low level 2833 data structure. */ inline struct RFC2833Payload *getRaw2833Payload(void) {return (struct RFC2833Payload *)getPayload();}; /** * Fetch 2833 duration field. * * @return 2833 duration in native host machine byte order. */ inline uint16 get2833Duration(void) {return ntohs(getRaw2833Payload()->duration);}; /** * Set 2833 duration field. * * @param timestamp to use, native host machine byte order. */ inline void set2833Duration(uint16 timestamp) {getRaw2833Payload()->duration = htons(timestamp);};};/** * @class OutgoingRTPPkt * @short RTP packets being sent. * * This class is intented to construct packet objects just before they * are inserted into the sending queue, so that they are processed in * a understandable and format independent manner inside the stack. * * @author Federico Montesino Pouzols <fedemp@altern.org> **/class __EXPORT OutgoingRTPPkt : public RTPPacket{public: /** * Construct a new packet to be sent, containing several * contributing source identifiers, header extensions and * payload. * * A new copy in memory (holding all this components * along with the fixed header) is created. If the pointer * to the SRTP CryptoContext is not NULL and holds a CryptoContext * for the SSRC take the SSRC data into account when computing * the required memory buffer. * * @param csrcs array of countributing source 32-bit * identifiers, in host order. * @param numcsrc number of CSRC identifiers in the array. * @param hdrext whole header extension. * @param hdrextlen size of whole header extension, in octets. * @param data payload. * @param datalen payload length, in octets. * @param paddinglen pad packet to a multiple of paddinglen. * @param pcc Pointer to the SRTP CryptoContext, defaults to NULL * if not specified. * * @note For efficiency purposes, since this constructor is * valid for all packets but is too complex for the common * case, two simpler others are provided. **/ OutgoingRTPPkt(const uint32* const csrcs, uint16 numcsrc, const unsigned char* const hdrext, uint32 hdrextlen, const unsigned char* const data, size_t datalen, uint8 paddinglen= 0, CryptoContext* pcc= NULL); /** * Construct a new packet to be sent, containing several * contributing source identifiers and payload. * * A new copy in * memory (holding all this components along with the fixed * header) is created. If the pointer * to the SRTP CryptoContext is not NULL and holds a CryptoContext * for the SSRC take the SSRC data into account when computing * the required memory buffer. * * @param csrcs array of countributing source 32-bit * identifiers, in host order. * @param numcsrc number of CSRC identifiers in the array. * @param data payload. * @param datalen payload length, in octets. * @param paddinglen pad packet to a multiple of paddinglen. * @param pcc Pointer to the SRTP CryptoContext, defaults to NULL * if not specified. **/ OutgoingRTPPkt(const uint32* const csrcs, uint16 numcsrc, const unsigned char* const data, size_t datalen, uint8 paddinglen= 0, CryptoContext* pcc= NULL); /** * Construct a new packet (fast variant, with no contributing * sources and no header extension) to be sent. * * A new copy in * memory (holding the whole packet) is created. If the pointer * to the SRTP CryptoContext is not NULL and holds a CryptoContext * for the SSRC take the SSRC data into account when computing * the required memory buffer. * * @param data payload. * @param datalen payload length, in octets. * @param paddinglen pad packet to a multiple of paddinglen. * @param pcc Pointer to the SRTP CryptoContext, defaults to NULL * if not specified. **/ OutgoingRTPPkt(const unsigned char* const data, size_t datalen, uint8 paddinglen= 0, CryptoContext* pcc= NULL); ~OutgoingRTPPkt() { } /** * @param pt Packet payload type. **/ inline void setPayloadType(PayloadType pt) { getHeader()->payload = pt; }; /** * Sets the sequence number in the header. * * @param seq Packet sequence number, in host order. **/ inline void setSeqNum(uint16 seq) { cachedSeqNum = seq; getHeader()->sequence = htons(seq); } /** * @param pts Packet timestamp, in host order. **/ inline void setTimestamp(uint32 pts) { cachedTimestamp = pts; getHeader()->timestamp = htonl(pts); } /** * Set synchronization source numeric identifier. * * @param ssrc 32-bit Synchronization SouRCe numeric * identifier, in host order. **/ inline void setSSRC(uint32 ssrc) const { getHeader()->sources[0] = htonl(ssrc); } /** * Set synchronization source numeric identifier. Special * version to save endianness conversion. * * @param ssrc 32-bit Synchronization SouRCe numeric * identifier, in network order. **/ inline void setSSRCNetwork(uint32 ssrc) const { getHeader()->sources[0] = ssrc; } /** * Specify the value of the marker bit. By default, the marker * bit of outgoing packets is false/0. This method allows to * explicity specify and change that value. * * @param mark value for the market bit. */ inline void setMarker(bool mark) { getHeader()->marker = mark; } /** * Called packet is setup. * * This private method computes the SRTP data and stores it in the * packet. Then encrypt the payload data (ex padding). */ void protect(uint32 ssrc, CryptoContext* pcc); /** * Outgoing packets are equal if their sequence numbers match. **/ inline bool operator==(const OutgoingRTPPkt &p) const { return ( this->getSeqNum() == p.getSeqNum() ); } /** * Outgoing packets are not equal if their sequence numbers differ. **/ inline bool operator!=(const OutgoingRTPPkt &p) const { return ( this->getSeqNum() != p.getSeqNum() ); } void enableZrtpChecksum() { zrtpChecksumLength = 2;} void computeZrtpChecksum();private: /** * Copy constructor from objects of its same kind, declared * private to avoid its use. **/ OutgoingRTPPkt(const OutgoingRTPPkt &o); /** * Assignment operator from objects of its same kind, declared * private to avoid its use. **/ OutgoingRTPPkt& operator=(const OutgoingRTPPkt &o); /** * Set the list of CSRC identifiers in an RTP packet, * switching host to network order. */ void setCSRCArray(const uint32* const csrcs, uint16 numcsrc); int32 zrtpChecksumLength;};/** * @class IncomingRTPPkt * * @short RTP packets received from other participants. * * This class is intented to construct a packet object just after * every packet is received by the scheduled queue, so that they are * processed in an understandable and format independent manner inside * the stack. * * @author Federico Montesino Pouzols <fedemp@altern.org> */class __EXPORT IncomingRTPPkt : public RTPPacket{public: /** * Build an RTP packet object from a data buffer. This * constructor first performs a generic RTP data packet header * check, whose result can be checked via isHeaderValid(). * * @param block pointer to the buffer the whole packet is stored in. * @param len length of the whole packet, expressed in octets. * * @note If check fails, the packet object is * incomplete. checking isHeaderValid() is recommended before * using a new RTPPacket object. **/ IncomingRTPPkt(const unsigned char* block, size_t len); ~IncomingRTPPkt() { } /** * Get validity of this packet * @return whether the header check performed at construction * time ended successfully. **/ inline bool isHeaderValid() { return headerValid; } /** * Get synchronization source numeric identifier. * * @return 32-bits Synchronization SouRCe numeric identifier, * in host order. **/ inline uint32 getSSRC() const { return cachedSSRC; } /** * Unprotect a received packet. * * Perform SRTP processing on this packet. * * @param pcc Pointer to SRTP CryptoContext. * @return * one if no errors, -1 if authentication failed, -2 if * replay check failed */ int32 unprotect(CryptoContext* pcc); /** * Two incoming packets are equal if they come from sources * with the same SSRC and have the same sequence number. **/ inline bool operator==(const IncomingRTPPkt &p) const { return ( (this->getSeqNum() == p.getSeqNum()) && (this->getSSRC() == p.getSSRC()) ); } /** * Two incoming packets are not equal if they come from * different sources or have different sequence numbers. **/ inline bool operator!=(const IncomingRTPPkt &p) const { return !( *this == p ); } /** * Recompute and check ZRTP checksum * * If the <em>check</em> parameter is true then * this method recomputes the ZRTP checksum and compares it * with the checksum conatined in the packet. If the parameter * is set to false the method only adjusts the length of the * data. * * @param check * if <code>true</code> recompute and check, otherwise * adjust length of packet data only. * @return <code>true</code> if check is ok or only length was * adjusted. If check fails returns <code>false</code> */ bool checkZrtpChecksum(bool check);private: /** * Copy constructor from objects of its same kind, declared * private to avoid its use. **/ IncomingRTPPkt(const IncomingRTPPkt &ip); /** * Assignment operator from objects of its same kind, declared * private to avoid its use. */ IncomingRTPPkt& operator=(const IncomingRTPPkt &ip); /// Header validity, checked at construction time. bool headerValid; /// SSRC 32-bit identifier in host order. uint32 cachedSSRC; // Masks for RTP header validation: types matching RTCP SR or // RR must be rejected to avoid accepting misaddressed RTCP // packets. static const uint16 RTP_INVALID_PT_MASK; static const uint16 RTP_INVALID_PT_VALUE;};/** @}*/ // rtppacket#ifdef CCXX_NAMESPACES}#endif#endif // ndef CCXX_RTP_RTPPKT_H_/** EMACS ** * Local variables: * mode: c++ * c-basic-offset: 8 * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -