diff --git a/srtcore/packet.cpp b/srtcore/packet.cpp index aacc37f2c..813d07995 100644 --- a/srtcore/packet.cpp +++ b/srtcore/packet.cpp @@ -252,6 +252,13 @@ void srt::CPacket::setLength(size_t len) m_PacketVector[PV_DATA].setLength(len); } +void srt::CPacket::setLength(size_t len, size_t cap) +{ + SRT_ASSERT(len <= cap); + setLength(len); + m_zCapacity = cap; +} + void srt::CPacket::pack(UDTMessageType pkttype, const int32_t* lparam, void* rparam, size_t size) { // Set (bit-0 = 1) and (bit-1~15 = type) @@ -456,10 +463,15 @@ int32_t srt::CPacket::getMsgSeq(bool has_rexmit) const bool srt::CPacket::getRexmitFlag() const { - // return false; // return 0 != MSGNO_REXMIT::unwrap(m_nHeader[SRT_PH_MSGNO]); } +void srt::CPacket::setRexmitFlag(bool bRexmit) +{ + const int32_t clr_msgno = m_nHeader[SRT_PH_MSGNO] & ~MSGNO_REXMIT::mask; + m_nHeader[SRT_PH_MSGNO] = clr_msgno | MSGNO_REXMIT::wrap(bRexmit? 1 : 0); +} + srt::EncryptionKeySpec srt::CPacket::getMsgCryptoFlags() const { return EncryptionKeySpec(MSGNO_ENCKEYSPEC::unwrap(m_nHeader[SRT_PH_MSGNO])); diff --git a/srtcore/packet.h b/srtcore/packet.h index a288caa52..e6d2516a9 100644 --- a/srtcore/packet.h +++ b/srtcore/packet.h @@ -236,6 +236,11 @@ class CPacket /// @param len [in] the payload or the control information field length. void setLength(size_t len); + /// Set the payload or the control information field length. + /// @param len [in] the payload or the control information field length. + /// @param cap [in] capacity (if known). + void setLength(size_t len, size_t cap); + /// Pack a Control packet. /// @param pkttype [in] packet type filed. /// @param lparam [in] pointer to the first data structure, explained by the packet type. @@ -286,6 +291,8 @@ class CPacket /// (because the peer will understand this bit as a part of MSGNO field). bool getRexmitFlag() const; + void setRexmitFlag(bool bRexmit); + /// Read the message sequence number. /// @return packet header field [1] int32_t getMsgSeq(bool has_rexmit = true) const; @@ -335,6 +342,7 @@ class CPacket int32_t m_extra_pad; bool m_data_owned; + size_t m_zCapacity; protected: CPacket& operator=(const CPacket&); @@ -368,6 +376,8 @@ class CPacket char* data() { return m_pcData; } const char* data() const { return m_pcData; } size_t size() const { return getLength(); } + size_t capacity() const { return m_zCapacity; } + void setCapacity(size_t cap) { m_zCapacity = cap; } uint32_t header(SrtPktHeaderFields field) const { return m_nHeader[field]; } #if ENABLE_LOGGING