Skip to content

Commit

Permalink
Olof/jbfix (#334)
Browse files Browse the repository at this point in the history
* JB crash fix
* test for jb list
  • Loading branch information
olofkallander authored Nov 3, 2023
1 parent f7c277f commit 71c522f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
13 changes: 5 additions & 8 deletions rtp/JitterBufferList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,14 @@ bool JitterBufferList::add(memory::UniquePacket packet)
return true;
}

for (ListItem* item = _head; item; item = item->next)
for (ListItem** itemPtr = &_head; *itemPtr; itemPtr = &(*itemPtr)->next)
{
const auto itemHeader = RtpHeader::fromPacket(*item->next->packet);
auto item = *itemPtr;
const auto itemHeader = RtpHeader::fromPacket(*item->packet);
if (static_cast<int16_t>(itemHeader->sequenceNumber.get() - newHeader->sequenceNumber.get()) > 0)
{
newItem->next = item->next;
item->next = newItem;
if (item == _head)
{
_head = newItem;
}
newItem->next = item;
*itemPtr = newItem;
return true;
}
}
Expand Down
32 changes: 32 additions & 0 deletions test/transport/JitterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,35 @@ TEST_F(JitterBufferTest, reorderedFull)
EXPECT_EQ(_buffer.count(), _buffer.SIZE - 50);
EXPECT_TRUE(_buffer.add(std::move(p)));
}

TEST_F(JitterBufferTest, reorderedOne)
{
memory::Packet stageArea;
{
auto header = rtp::RtpHeader::create(stageArea);
header->ssrc = 4000;
stageArea.setLength(250);
}

EXPECT_EQ(_buffer.pop(), nullptr);

auto p = memory::makeUniquePacket(_allocator, stageArea);
auto header = rtp::RtpHeader::create(*p);
header->sequenceNumber = 100;
header->timestamp = 56000;
EXPECT_TRUE(_buffer.add(std::move(p)));

p = memory::makeUniquePacket(_allocator, stageArea);
header = rtp::RtpHeader::create(*p);
header->sequenceNumber = 98;
header->timestamp = 57000;
EXPECT_TRUE(_buffer.add(std::move(p)));

p = _buffer.pop();
header = rtp::RtpHeader::fromPacket(*p);
EXPECT_EQ(header->sequenceNumber.get(), 98);

p = _buffer.pop();
header = rtp::RtpHeader::fromPacket(*p);
EXPECT_EQ(header->sequenceNumber.get(), 100);
}

0 comments on commit 71c522f

Please sign in to comment.