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