Skip to content

Commit

Permalink
Fix/periodic plis keyframe check (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Nov 28, 2019
1 parent fcdfdaa commit 188d23d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 9 additions & 3 deletions erizo/src/erizo/rtp/PeriodicPliHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ void PeriodicPliHandler::updateInterval(bool active, uint32_t interval_ms) {

void PeriodicPliHandler::read(Context *ctx, std::shared_ptr<DataPacket> packet) {
if (enabled_ && packet->is_keyframe) {
keyframes_received_in_interval_++;
ELOG_DEBUG("%s, message: Received Keyframe, total in interval %u", stream_->toLog(),
keyframes_received_in_interval_);
std::for_each(packet->compatible_spatial_layers.begin(),
packet->compatible_spatial_layers.end(),
[this](const int spatial_layer) {
if (spatial_layer == 0) {
keyframes_received_in_interval_++;
}
});
ELOG_DEBUG("%s, message: Received Keyframe, total from lowest layer in interval %u",
stream_->toLog(), keyframes_received_in_interval_);
}
ctx->fireRead(std::move(packet));
}
Expand Down
21 changes: 20 additions & 1 deletion erizo/src/test/rtp/PeriodicPliHandlerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ TEST_F(PeriodicPliHandlerTest, shouldUpdateIntervalIfRequested) {
executeTasksInNextMs(2*kArbitraryKeyframePeriodMs+1);
}

TEST_F(PeriodicPliHandlerTest, shouldNotSendPliIfMoreThanOneKeyframeIsReceivedInPeriod) {
TEST_F(PeriodicPliHandlerTest, shouldNotSendPliIfMoreThanOneKeyframeFromTheLowestLayerIsReceivedInPeriod) {
auto keyframe = erizo::PacketTools::createVP8Packet(erizo::kArbitrarySeqNumber, true, true);
keyframe->compatible_spatial_layers.push_back(0);
auto keyframe2 = erizo::PacketTools::createVP8Packet(erizo::kArbitrarySeqNumber + 1, true, true);
keyframe2->compatible_spatial_layers.push_back(0);

EXPECT_CALL(*writer.get(), write(_, _)).With(Args<1>(erizo::IsPLI())).Times(0);
EXPECT_CALL(*reader.get(), read(_, _)).
Expand All @@ -105,6 +107,23 @@ TEST_F(PeriodicPliHandlerTest, shouldNotSendPliIfMoreThanOneKeyframeIsReceivedIn
executeTasksInNextMs(kArbitraryKeyframePeriodMs/2 + 1);
}

TEST_F(PeriodicPliHandlerTest, shouldSendPliIfNoKeyframesFromLowestLayerAreReceivedInPeriod) {
auto keyframe = erizo::PacketTools::createVP8Packet(erizo::kArbitrarySeqNumber, true, true);
keyframe->compatible_spatial_layers.push_back(1);
auto keyframe2 = erizo::PacketTools::createVP8Packet(erizo::kArbitrarySeqNumber + 1, true, true);
keyframe2->compatible_spatial_layers.push_back(2);

EXPECT_CALL(*writer.get(), write(_, _)).With(Args<1>(erizo::IsPLI())).Times(1);
EXPECT_CALL(*reader.get(), read(_, _)).
With(Args<1>(erizo::RtpHasSequenceNumber(erizo::kArbitrarySeqNumber))).Times(1);

periodic_pli_handler->updateInterval(true, kArbitraryKeyframePeriodMs);
executeTasksInNextMs(kArbitraryKeyframePeriodMs/2);
pipeline->read(keyframe);
pipeline->read(keyframe2);
executeTasksInNextMs(kArbitraryKeyframePeriodMs/2 + 1);
}

TEST_F(PeriodicPliHandlerTest, shouldSendPliWhenRequestedToStop) {
auto keyframe = erizo::PacketTools::createVP8Packet(erizo::kArbitrarySeqNumber, true, true);

Expand Down

0 comments on commit 188d23d

Please sign in to comment.