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

Found a bug in NACK|RtpStreamSend

上级 307ae3b1
......@@ -24,7 +24,7 @@ namespace RTC
};
public:
explicit RtpStreamSend(uint32_t clockRate, size_t bufferSize);
RtpStreamSend(uint32_t clockRate, size_t bufferSize);
virtual ~RtpStreamSend();
bool ReceivePacket(RTC::RtpPacket* packet);
......
......@@ -235,6 +235,7 @@
[
# C++ source files
'test/tests.cpp',
'test/test-nack.cpp',
'test/test-rtp.cpp',
'test/test-rtcp.cpp',
# C++ include files
......
......@@ -295,7 +295,6 @@ namespace RTC
return;
}
for (auto it = nackPacket->Begin(); it != nackPacket->End(); ++it)
{
RTC::RTCP::NackItem* item = *it;
......@@ -311,9 +310,6 @@ namespace RTC
RetransmitRtpPacket(packet);
}
// Reset the container by setting its first element to nullptr.
RtpSender::rtpRetransmissionContainer[0] = nullptr;
}
}
......
......@@ -71,7 +71,10 @@ namespace RTC
// 17: 16 bit mask + the initial sequence number.
static size_t maxRequestedPackets = 17;
// If the buffer is empty, just return.
// Ensure the container's first element is 0.
container[0] = nullptr;
// If the buffer is empty just return.
if (this->buffer.size() == 0)
return;
......@@ -124,6 +127,10 @@ namespace RTC
do
{
// TODO: REMOVE
MS_WARN_TAG(rtcp, "loop [bitmask:" UINT16_TO_BINARY_PATTERN "]",
UINT16_TO_BINARY(ntohs(bitmask)));
bool sent = false;
if (requested)
......@@ -183,12 +190,12 @@ namespace RTC
if (first_packet_sent && orig_bitmask != sent_bitmask)
{
MS_WARN_TAG(rtcp, "first packet sent but bitmask not [bitmask:" UINT16_TO_BINARY_PATTERN ", sent: " UINT16_TO_BINARY_PATTERN "]",
UINT16_TO_BINARY(orig_bitmask), UINT16_TO_BINARY(sent_bitmask));
UINT16_TO_BINARY(ntohs(orig_bitmask)), UINT16_TO_BINARY(ntohs(sent_bitmask)));
}
else if (first_packet_sent && orig_bitmask && orig_bitmask == sent_bitmask)
{
MS_WARN_TAG(rtcp, "first packet and bitmask sent [bitmask:" UINT16_TO_BINARY_PATTERN "]",
UINT16_TO_BINARY(orig_bitmask));
UINT16_TO_BINARY(ntohs(orig_bitmask)));
}
// Set the next container element to null.
......
#include "include/catch.hpp"
#include "common.h"
#include "RTC/RtpPacket.h"
#include "RTC/RTCP/FeedbackRtpNack.h"
#include "RTC/RtpStreamSend.h"
#include <vector>
using namespace RTC;
// Can retransmit up to 17 RTP packets.
static std::vector<RtpPacket*> rtpRetransmissionContainer(18);
SCENARIO("NACK and RTP packets retransmission", "[rtp][rtcp]")
{
SECTION("receive NACK and get retransmitted packets")
{
uint8_t rtp_buffer1[] =
{
0b10000000, 0b01111011, 0b01010010, 0b00001110,
0b01011011, 0b01101011, 0b11001010, 0b10110101,
0, 0, 0, 2
};
uint8_t rtp_buffer2[65536];
uint8_t rtp_buffer3[65536];
uint8_t rtp_buffer4[65536];
uint8_t rtp_buffer5[65536];
// packet1 [pt:123, seq:21006, timestamp:1533790901]
RtpPacket* packet1 = RtpPacket::Parse(rtp_buffer1, sizeof(rtp_buffer1));
REQUIRE(packet1);
REQUIRE(packet1->GetSequenceNumber() == 21006);
REQUIRE(packet1->GetTimestamp() == 1533790901);
// packet2 [pt:123, seq:21007, timestamp:1533790901]
RtpPacket* packet2 = packet1->Clone(rtp_buffer2);
packet2->SetSequenceNumber(21007);
packet2->SetTimestamp(1533790901);
REQUIRE(packet2->GetSequenceNumber() == 21007);
REQUIRE(packet2->GetTimestamp() == 1533790901);
// packet3 [pt:123, seq:21008, timestamp:1533793871]
RtpPacket* packet3 = packet1->Clone(rtp_buffer3);
packet3->SetSequenceNumber(21008);
packet3->SetTimestamp(1533793871);
REQUIRE(packet3->GetSequenceNumber() == 21008);
REQUIRE(packet3->GetTimestamp() == 1533793871);
// packet4 [pt:123, seq:21009, timestamp:1533793871]
RtpPacket* packet4 = packet1->Clone(rtp_buffer4);
packet4->SetSequenceNumber(21009);
packet4->SetTimestamp(1533793871);
REQUIRE(packet4->GetSequenceNumber() == 21009);
REQUIRE(packet4->GetTimestamp() == 1533793871);
// packet5 [pt:123, seq:21010, timestamp:1533796931]
RtpPacket* packet5 = packet1->Clone(rtp_buffer4);
packet5->SetSequenceNumber(21010);
packet5->SetTimestamp(1533796931);
REQUIRE(packet5->GetSequenceNumber() == 21010);
REQUIRE(packet5->GetTimestamp() == 1533796931);
// Create a RtpStreamSend.
RtpStreamSend* stream = new RtpStreamSend(90000, 200);
// Receive all the packets in order into the stream.
stream->ReceivePacket(packet1);
stream->ReceivePacket(packet2);
stream->ReceivePacket(packet3);
stream->ReceivePacket(packet4);
stream->ReceivePacket(packet5);
// Create a NACK item that request for all the packets.
RTCP::NackItem nack_item(21006, 0b0000000000001111);
REQUIRE(nack_item.GetPacketId() == 21006);
REQUIRE(nack_item.GetLostPacketBitmask() == htons(0b0000000000001111));
stream->RequestRtpRetransmission(nack_item.GetPacketId(), nack_item.GetLostPacketBitmask(), rtpRetransmissionContainer);
REQUIRE(rtpRetransmissionContainer[0] == packet1);
REQUIRE(rtpRetransmissionContainer[1] == packet2);
REQUIRE(rtpRetransmissionContainer[2] == packet3);
REQUIRE(rtpRetransmissionContainer[3] == packet4);
REQUIRE(rtpRetransmissionContainer[4] == packet5);
REQUIRE(rtpRetransmissionContainer[5] == nullptr);
// Clean stuff.
delete packet1;
delete packet2;
delete packet3;
delete packet4;
delete packet5;
delete stream;
}
}
......@@ -5,8 +5,8 @@
using namespace RTC;
uint8_t buffer[65536];
uint8_t buffer2[65536];
static uint8_t buffer[65536];
static uint8_t buffer2[65536];
SCENARIO("parse RTP packets", "[parser][rtp]")
{
......
......@@ -8,8 +8,8 @@ int main(int argc, char* argv[])
{
Settings::configuration.logLevel = LogLevel::LOG_DEBUG;
// TODO: think about this.
// Settings::configuration.logTags.rtp = true;
// Settings::configuration.logTags.rtcp = true;
Settings::configuration.logTags.rtp = true;
Settings::configuration.logTags.rtcp = true;
int ret = Catch::Session().run(argc, argv);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论