diff --git a/erizo/src/erizo/rtp/PeriodicPliHandler.cpp b/erizo/src/erizo/rtp/PeriodicPliHandler.cpp index 3cabb960f2..b3ab8bf206 100644 --- a/erizo/src/erizo/rtp/PeriodicPliHandler.cpp +++ b/erizo/src/erizo/rtp/PeriodicPliHandler.cpp @@ -45,9 +45,15 @@ void PeriodicPliHandler::updateInterval(bool active, uint32_t interval_ms) { void PeriodicPliHandler::read(Context *ctx, std::shared_ptr 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)); } diff --git a/erizo/src/test/rtp/PeriodicPliHandlerTest.cpp b/erizo/src/test/rtp/PeriodicPliHandlerTest.cpp index 8d25956b45..a76e5a66c9 100644 --- a/erizo/src/test/rtp/PeriodicPliHandlerTest.cpp +++ b/erizo/src/test/rtp/PeriodicPliHandlerTest.cpp @@ -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(_, _)). @@ -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);