Skip to content

Commit

Permalink
Fix incorrect extension of RED packet
Browse files Browse the repository at this point in the history
  • Loading branch information
getroot committed Nov 2, 2021
1 parent c2e63a5 commit 78ea660
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 40 deletions.
43 changes: 16 additions & 27 deletions src/projects/modules/rtp_rtcp/red_rtp_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@ RedRtpPacket::RedRtpPacket()
{
}

RedRtpPacket::RedRtpPacket(uint8_t red_payload_type, const RtpPacket &src)
RedRtpPacket::RedRtpPacket(uint8_t red_payload_type, RtpPacket &src)
: RtpPacket(src)
{
PackageAsRed(red_payload_type, src);
_block_pt = PayloadType();
SetPayloadType(red_payload_type);

_payload_offset = _payload_offset + RED_HEADER_SIZE;
if(_data->GetLength() < _payload_offset)
{
_data->SetLength(_payload_offset);
_buffer = _data->GetWritableDataAs<uint8_t>();
}

_buffer[_payload_offset - RED_HEADER_SIZE] = _block_pt;

SetPayload(src.Payload(), src.PayloadSize());
}

RedRtpPacket::RedRtpPacket(RedRtpPacket &src)
:RtpPacket(src)
: RtpPacket(src)
{
_block_pt = src._block_pt;
}
Expand All @@ -20,30 +33,6 @@ RedRtpPacket::~RedRtpPacket()

}

void RedRtpPacket::PackageAsRed(uint8_t red_payload_type, const RtpPacket &src)
{
SetPayloadType(src.PayloadType());
SetUlpfec(src.IsUlpfec(), src.OriginPayloadType());
SetSsrc(src.Ssrc());
SetSequenceNumber(src.SequenceNumber());
SetTimestamp(src.Timestamp());
SetNTPTimestamp(src.NTPTimestamp());
SetKeyframe(src.IsKeyframe());
SetFirstPacketOfFrame(src.IsFirstPacketOfFrame());
SetVideoPacket(src.IsVideoPacket());

_payload_offset = src.HeadersSize();
_payload_size = src.PayloadSize();
_padding_size = src.PaddingSize();
_extension_size = src.ExtensionSize();

PackageAsRed(red_payload_type);

SetMarker(src.Marker());

SetPayload(src.Payload(), src.PayloadSize());
}

//Implement RED as part of the RTP header to reduce memory copying and improve performance.
void RedRtpPacket::PackageAsRed(uint8_t red_payload_type)
{
Expand Down
4 changes: 1 addition & 3 deletions src/projects/modules/rtp_rtcp/red_rtp_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ class RedRtpPacket : public RtpPacket
{
public:
RedRtpPacket();
RedRtpPacket(uint8_t red_payload_type, const RtpPacket &src);
RedRtpPacket(uint8_t red_payload_type, RtpPacket &src);
RedRtpPacket(RedRtpPacket &src);
~RedRtpPacket();

void PackageAsRed(uint8_t red_payload_type, const RtpPacket &src);
void PackageAsRed(uint8_t red_payload_type);

// Readjust the payload area that was adjusted for RED.
void PackageAsRtp();
uint8_t BlockPT();
Expand Down
3 changes: 1 addition & 2 deletions src/projects/modules/rtp_rtcp/rtp_packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ RtpPacket::RtpPacket()
_padding_size = 0;
_extension_size = 0;

_data = std::make_shared<ov::Data>();
_data->Reserve(RTP_DEFAULT_MAX_PACKET_SIZE);
_data = std::make_shared<ov::Data>(RTP_DEFAULT_MAX_PACKET_SIZE);
_data->SetLength(FIXED_HEADER_SIZE);
_buffer = _data->GetWritableDataAs<uint8_t>();

Expand Down
11 changes: 3 additions & 8 deletions src/projects/modules/rtp_rtcp/rtp_packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,25 +268,20 @@ std::shared_ptr<RedRtpPacket> RtpPacketizer::PackageAsRed(std::shared_ptr<RtpPac

std::shared_ptr<RtpPacket> RtpPacketizer::AllocatePacket(bool ulpfec)
{
std::shared_ptr<RedRtpPacket> red_packet;
std::shared_ptr<RtpPacket> rtp_packet;

if(ulpfec)
{
red_packet = std::make_shared<RedRtpPacket>();

auto red_packet = std::make_shared<RedRtpPacket>();
red_packet->SetSsrc(_ssrc);
red_packet->SetCsrcs(_csrcs);
red_packet->SetPayloadType(_ulpfec_payload_type);
red_packet->SetUlpfec(true, _payload_type);

red_packet->PackageAsRed(_red_payload_type);

return red_packet;
}
else
{
rtp_packet = std::make_shared<RtpPacket>();
auto rtp_packet = std::make_shared<RtpPacket>();
rtp_packet->SetSsrc(_ssrc);
rtp_packet->SetCsrcs(_csrcs);
rtp_packet->SetPayloadType(_payload_type);
Expand Down

0 comments on commit 78ea660

Please sign in to comment.