Skip to content

Commit

Permalink
[core] Add capacity property to CPacket.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Sep 30, 2022
1 parent 0f49f1c commit 6dd47c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion srtcore/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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]));
Expand Down
10 changes: 10 additions & 0 deletions srtcore/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -335,6 +342,7 @@ class CPacket

int32_t m_extra_pad;
bool m_data_owned;
size_t m_zCapacity;

protected:
CPacket& operator=(const CPacket&);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6dd47c3

Please sign in to comment.