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

NackGenerator: upon key frame receipt remove older items in the NACK list.

上级 0fdd6356
......@@ -3,8 +3,8 @@
#include "common.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
......
......@@ -2,8 +2,8 @@
#define MS_RTC_CODECS_VP8_HPP
#include "common.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp"
namespace RTC
{
......
......@@ -12,7 +12,7 @@ namespace RTC
class ConsumerListener
{
public:
virtual void OnConsumerClosed(RTC::Consumer* consumer) = 0;
virtual void OnConsumerClosed(RTC::Consumer* consumer) = 0;
virtual void OnConsumerKeyFrameRequired(RTC::Consumer* consumer) = 0;
};
} // namespace RTC
......
......@@ -16,7 +16,7 @@ namespace RTC
{
public:
virtual void OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers) = 0;
virtual void OnNackGeneratorKeyFrameRequired() = 0;
virtual void OnNackGeneratorKeyFrameRequired() = 0;
};
private:
......@@ -45,6 +45,7 @@ namespace RTC
private:
void AddPacketsToNackList(uint32_t seq32Start, uint32_t seq32End);
void RemoveFromNackListOlderThan(uint32_t seq32);
std::vector<uint16_t> GetNackBatch(NackFilter filter);
void MayRunTimer() const;
......
......@@ -138,8 +138,8 @@ namespace RTC
uint8_t* payload{ nullptr };
size_t payloadLength{ 0 };
uint8_t payloadPadding{ 0 };
size_t size{ 0 }; // Full size of the packet in bytes.
uint32_t seq32{ 0 }; // Extended seq number.
size_t size{ 0 }; // Full size of the packet in bytes.
uint32_t seq32{ 0 }; // Extended seq number.
bool isKeyFrame{ false }; // Whether this packet contains a key frame.
};
......
......@@ -38,6 +38,7 @@ namespace RTC
virtual Json::Value ToJson() = 0;
virtual bool ReceivePacket(RTC::RtpPacket* packet);
uint32_t GetSsrc();
uint8_t GetPayloadType();
const RTC::RtpCodecMimeType& GetMimeType() const;
bool IsHealthy();
......@@ -83,6 +84,11 @@ namespace RTC
return this->params.ssrc;
}
inline uint8_t RtpStream::GetPayloadType()
{
return this->params.payloadType;
}
inline const RTC::RtpCodecMimeType& RtpStream::GetMimeType() const
{
return this->params.mime;
......
......@@ -22,8 +22,7 @@ namespace RTC
break;
}
default:
;
default:;
}
}
} // namespace Codecs
......
......@@ -336,7 +336,7 @@ namespace RTC
// profile.
if (this->effectiveProfile != this->targetProfile && profile == this->targetProfile)
{
bool isKeyFrame = false;
bool isKeyFrame = false;
bool canBeKeyFrame = Codecs::CanBeKeyFrame(this->rtpStream->GetMimeType());
if (canBeKeyFrame && packet->IsKeyFrame())
......@@ -688,9 +688,9 @@ namespace RTC
if (this->profiles.empty())
{
MS_ASSERT(
this->effectiveProfile == RtpEncodingParameters::Profile::NONE ||
this->effectiveProfile == RtpEncodingParameters::Profile::DEFAULT,
"no profiles, but effective profile is not none nor default");
this->effectiveProfile == RtpEncodingParameters::Profile::NONE ||
this->effectiveProfile == RtpEncodingParameters::Profile::DEFAULT,
"no profiles, but effective profile is not none nor default");
if (this->effectiveProfile == RtpEncodingParameters::Profile::NONE)
newTargetProfile = RtpEncodingParameters::Profile::NONE;
......@@ -700,7 +700,7 @@ namespace RTC
// If there is no preferred profile, take the best one available.
else if (this->preferredProfile == RTC::RtpEncodingParameters::Profile::DEFAULT)
{
auto it = this->profiles.crbegin();
auto it = this->profiles.crbegin();
newTargetProfile = *it;
}
// Otherwise take the highest available profile equal or lower than the preferred.
......
......@@ -47,6 +47,10 @@ namespace RTC
return;
}
// If a key frame remove all the items in the nack list older than this seq.
if (packet->IsKeyFrame())
RemoveFromNackListOlderThan(seq32);
// Obviously never nacked, so ignore.
if (seq32 == this->lastSeq32)
{
......@@ -141,8 +145,26 @@ namespace RTC
}
}
void NackGenerator::RemoveFromNackListOlderThan(uint32_t seq32)
{
MS_TRACE();
// Delete all the entries in the NACK list whose key (seq32) is older than
// the given one.
MS_ERROR("---- PRE, nackList.size:%zu", this->nackList.size());
auto it = this->nackList.lower_bound(seq32);
this->nackList.erase(this->nackList.begin(), it);
MS_ERROR("---- POST, nackList.size:%zu", this->nackList.size());
}
std::vector<uint16_t> NackGenerator::GetNackBatch(NackFilter filter)
{
MS_TRACE();
uint64_t now = DepLibUV::GetTime();
std::vector<uint16_t> nackBatch;
auto it = this->nackList.begin();
......
......@@ -270,6 +270,10 @@ namespace RTC
{
rtpStream = this->rtpStreams[ssrc];
// Process the packet at codec level.
if (packet->GetPayloadType() == rtpStream->GetPayloadType())
Codecs::ProcessRtpPacket(packet, rtpStream->GetMimeType());
// Process the packet.
if (!rtpStream->ReceivePacket(packet))
return;
......@@ -278,6 +282,10 @@ namespace RTC
{
rtpStream = this->mapRtxStreams[ssrc];
// Process the packet at codec level.
if (packet->GetPayloadType() == rtpStream->GetPayloadType())
Codecs::ProcessRtpPacket(packet, rtpStream->GetMimeType());
// Process the packet.
if (!rtpStream->ReceiveRtxPacket(packet))
return;
......@@ -300,9 +308,6 @@ namespace RTC
return;
}
// Process the packet at codec level.
Codecs::ProcessRtpPacket(packet, rtpStream->GetMimeType());
if (packet->IsKeyFrame())
{
MS_DEBUG_TAG(
......
......@@ -39,7 +39,7 @@ namespace RTC
{
/* Static. */
static constexpr uint64_t EffectiveMaxBitrateCheckInterval{ 2000 }; // In ms.
static constexpr uint64_t EffectiveMaxBitrateCheckInterval{ 2000 }; // In ms.
static constexpr double EffectiveMaxBitrateThresholdBeforeKeyFrame{ 0.6 }; // 0.0 - 1.0.
/* Instance methods. */
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论