提交 e6ce9ebe authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

RtpPacket: add Clone() method that receives a pointer to a buffer in which the…

RtpPacket: add Clone() method that receives a pointer to a buffer in which the packet will be copied.
上级 cecd5034
......@@ -64,6 +64,7 @@ namespace RTC
uint8_t* GetPayload();
size_t GetPayloadLength();
void Serialize();
RtpPacket* Clone(uint8_t* buffer);
private:
// Passed by argument.
......
......@@ -196,19 +196,19 @@ namespace RTC
// Add minimum header.
std::memcpy(this->raw, this->header, sizeof(Header));
size_t pos = sizeof(Header);
// Update the header pointer.
this->header = (Header*)(this->raw);
size_t pos = sizeof(Header);
// Add CSRC list.
if (this->csrcList)
{
std::memcpy(this->raw + pos, this->csrcList, this->header->csrc_count * sizeof(header->ssrc));
std::memcpy(this->raw + pos, this->csrcList, this->header->csrc_count * sizeof(this->header->ssrc));
// Update the pointer.
this->csrcList = this->raw + pos;
pos += this->header->csrc_count * sizeof(header->ssrc);
pos += this->header->csrc_count * sizeof(this->header->ssrc);
}
// Add extension header.
......@@ -240,4 +240,52 @@ namespace RTC
MS_ASSERT(pos == this->length, "pos != this->length");
}
RtpPacket* RtpPacket::Clone(uint8_t* buffer)
{
MS_TRACE();
// Copy the full packet into the given buffer.
std::memcpy(buffer, GetRaw(), GetLength());
// Set header pointer pointing to the given buffer.
Header* header = (Header*)buffer;
size_t pos = sizeof(Header);
// Check CSRC list.
if (this->csrcList)
pos += header->csrc_count * sizeof(header->ssrc);
// Check extension header.
ExtensionHeader* extensionHeader = nullptr;
if (this->extensionHeader)
{
// Set the header extension pointer.
extensionHeader = (ExtensionHeader*)(buffer + pos);
pos += 4 + GetExtensionHeaderLength();
}
// Check payload.
uint8_t* payload = nullptr;
if (this->payload)
{
// Set the payload pointer.
payload = buffer + pos;
pos += this->payloadLength;
}
// Check payload padding.
if (this->payloadPadding)
{
buffer[pos + (size_t)this->payloadPadding - 1] = this->payloadPadding;
pos += (size_t)this->payloadPadding;
}
MS_ASSERT(pos == this->length, "pos != this->length");
// Create the new RtpPacket instance and return it.
return new RtpPacket(header, extensionHeader, payload, this->payloadLength, this->payloadPadding, buffer, this->length);
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论