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

- Refactor RTC/Codecs so we have RtpPacket::IsKeyFrame().

- s/fullframe/keyframe/g
上级 3df732bb
...@@ -3,15 +3,31 @@ ...@@ -3,15 +3,31 @@
#include "common.hpp" #include "common.hpp"
#include "RTC/Codecs/VP8.hpp" #include "RTC/Codecs/VP8.hpp"
#include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace RTC namespace RTC
{ {
namespace Codecs namespace Codecs
{ {
bool IsKnown(const RTC::RtpCodecMimeType& mimeType); bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType);
bool IsKeyFrame(const RTC::RtpCodecMimeType& mimeType, const RTC::RtpPacket* packet); void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType);
// Inline namespace methods.
inline bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType)
{
if (mimeType.type != RTC::RtpCodecMimeType::Type::VIDEO)
return false;
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
return true;
default:
return false;
}
}
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +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"
namespace RTC namespace RTC
{ {
...@@ -10,7 +12,7 @@ namespace RTC ...@@ -10,7 +12,7 @@ namespace RTC
class VP8 class VP8
{ {
public: public:
static bool IsKeyFrame(const uint8_t* data, size_t len); static void ProcessRtpPacket(RTC::RtpPacket* packet);
}; };
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -56,7 +56,7 @@ namespace RTC ...@@ -56,7 +56,7 @@ namespace RTC
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket); void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now); uint32_t GetTransmissionRate(uint64_t now);
void RequestFullFrame(); void RequestKeyFrame();
private: private:
void FillSupportedCodecPayloadTypes(); void FillSupportedCodecPayloadTypes();
......
...@@ -13,7 +13,7 @@ namespace RTC ...@@ -13,7 +13,7 @@ namespace RTC
{ {
public: public:
virtual void OnConsumerClosed(RTC::Consumer* consumer) = 0; virtual void OnConsumerClosed(RTC::Consumer* consumer) = 0;
virtual void OnConsumerFullFrameRequired(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 OnNackGeneratorFullFrameRequired() = 0; virtual void OnNackGeneratorKeyFrameRequired() = 0;
}; };
private: private:
......
...@@ -72,7 +72,7 @@ namespace RTC ...@@ -72,7 +72,7 @@ namespace RTC
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const;
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const;
void RequestFullFrame(bool force = false); void RequestKeyFrame(bool force = false);
const std::set<RTC::RtpEncodingParameters::Profile> GetProfiles() const; const std::set<RTC::RtpEncodingParameters::Profile> GetProfiles() const;
private: private:
...@@ -111,7 +111,7 @@ namespace RTC ...@@ -111,7 +111,7 @@ namespace RTC
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams; std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> profiles; std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> profiles;
Timer* fullFrameRequestBlockTimer{ nullptr }; Timer* keyFrameRequestBlockTimer{ nullptr };
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
struct RTC::Transport::HeaderExtensionIds transportHeaderExtensionIds; struct RTC::Transport::HeaderExtensionIds transportHeaderExtensionIds;
...@@ -119,7 +119,7 @@ namespace RTC ...@@ -119,7 +119,7 @@ namespace RTC
bool paused{ false }; bool paused{ false };
bool rtpRawEventEnabled{ false }; bool rtpRawEventEnabled{ false };
bool rtpObjectEventEnabled{ false }; bool rtpObjectEventEnabled{ false };
bool isFullFrameRequested{ false }; bool isKeyFrameRequested{ false };
// Timestamp when last RTCP was sent. // Timestamp when last RTCP was sent.
uint64_t lastRtcpSentTime{ 0 }; uint64_t lastRtcpSentTime{ 0 };
uint16_t maxRtcpInterval{ 0 }; uint16_t maxRtcpInterval{ 0 };
......
...@@ -79,7 +79,7 @@ namespace RTC ...@@ -79,7 +79,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
public: public:
void OnConsumerClosed(RTC::Consumer* consumer) override; void OnConsumerClosed(RTC::Consumer* consumer) override;
void OnConsumerFullFrameRequired(RTC::Consumer* consumer) override; void OnConsumerKeyFrameRequired(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
......
...@@ -117,6 +117,8 @@ namespace RTC ...@@ -117,6 +117,8 @@ namespace RTC
bool ReadRid(const uint8_t** data, size_t* len) const; bool ReadRid(const uint8_t** data, size_t* len) const;
uint8_t* GetPayload() const; uint8_t* GetPayload() const;
size_t GetPayloadLength() const; size_t GetPayloadLength() const;
void SetKeyFrame(bool flag);
bool IsKeyFrame() const;
void Serialize(uint8_t* buffer); void Serialize(uint8_t* buffer);
RtpPacket* Clone(uint8_t* buffer) const; RtpPacket* Clone(uint8_t* buffer) const;
void RtxEncode(uint8_t payloadType, uint32_t ssrc, uint16_t seq); void RtxEncode(uint8_t payloadType, uint32_t ssrc, uint16_t seq);
...@@ -138,6 +140,7 @@ namespace RTC ...@@ -138,6 +140,7 @@ namespace RTC
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.
}; };
/* Inline static methods. */ /* Inline static methods. */
...@@ -362,6 +365,16 @@ namespace RTC ...@@ -362,6 +365,16 @@ namespace RTC
{ {
return this->payloadLength; return this->payloadLength;
} }
inline void RtpPacket::SetKeyFrame(bool flag)
{
this->isKeyFrame = flag;
}
inline bool RtpPacket::IsKeyFrame() const
{
return this->isKeyFrame;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -30,7 +30,7 @@ namespace RTC ...@@ -30,7 +30,7 @@ namespace RTC
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport(); RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void SetRtx(uint8_t payloadType, uint32_t ssrc); void SetRtx(uint8_t payloadType, uint32_t ssrc);
void RequestFullFrame(); void RequestKeyFrame();
uint32_t GetBitRate(); uint32_t GetBitRate();
private: private:
...@@ -44,7 +44,7 @@ namespace RTC ...@@ -44,7 +44,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::NackGenerator. */ /* Pure virtual methods inherited from RTC::NackGenerator. */
protected: protected:
void OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers) override; void OnNackGeneratorNackRequired(const std::vector<uint16_t>& seqNumbers) override;
void OnNackGeneratorFullFrameRequired() override; void OnNackGeneratorKeyFrameRequired() override;
private: private:
// Passed by argument. // Passed by argument.
......
...@@ -176,7 +176,7 @@ namespace RTC ...@@ -176,7 +176,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::ConsumerListener. */ /* Pure virtual methods inherited from RTC::ConsumerListener. */
public: public:
void OnConsumerClosed(RTC::Consumer* consumer) override; void OnConsumerClosed(RTC::Consumer* consumer) override;
void OnConsumerFullFrameRequired(RTC::Consumer* consumer) override; void OnConsumerKeyFrameRequired(RTC::Consumer* consumer) override;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
......
#define MS_CLASS "RTC::Codecs" #define MS_CLASS "RTC::Codecs"
#define MS_LOG_DEV // #define MS_LOG_DEV
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Codecs.hpp"
#include "Logger.hpp" #include "Logger.hpp"
...@@ -9,41 +9,21 @@ namespace RTC ...@@ -9,41 +9,21 @@ namespace RTC
{ {
namespace Codecs namespace Codecs
{ {
bool IsKnown(const RTC::RtpCodecMimeType& mimeType) void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType)
{ {
MS_TRACE(); MS_TRACE();
if (mimeType.type != RTC::RtpCodecMimeType::Type::VIDEO)
return false;
switch (mimeType.subtype) switch (mimeType.subtype)
{ {
case RTC::RtpCodecMimeType::Subtype::VP8: case RTC::RtpCodecMimeType::Subtype::VP8:
return true; {
default: VP8::ProcessRtpPacket(packet);
return false;
}
}
bool IsKeyFrame(const RTC::RtpCodecMimeType& mimeType, const RTC::RtpPacket* packet)
{
MS_TRACE();
if (!IsKnown(mimeType))
return false;
auto data = packet->GetPayload();
auto len = packet->GetPayloadLength();
switch (mimeType.subtype) break;
{ }
case RTC::RtpCodecMimeType::Subtype::VP8:
return VP8::IsKeyFrame(data, len);
default: default:
MS_DEBUG_TAG( ;
rtp, "requested key frame for an unsupported codec: %s", mimeType.GetName().c_str());
return false;
} }
} }
} // namespace Codecs } // namespace Codecs
......
#define MS_CLASS "RTC::Codecs::VP8" #define MS_CLASS "RTC::Codecs::VP8"
#define MS_LOG_DEV // #define MS_LOG_DEV
#include "RTC/Codecs/VP8.hpp" #include "RTC/Codecs/VP8.hpp"
#include "Logger.hpp" #include "Logger.hpp"
...@@ -9,10 +9,15 @@ namespace RTC ...@@ -9,10 +9,15 @@ namespace RTC
{ {
namespace Codecs namespace Codecs
{ {
bool VP8::IsKeyFrame(const uint8_t* data, size_t len) void VP8::ProcessRtpPacket(RTC::RtpPacket* packet)
{ {
MS_TRACE();
auto data = packet->GetPayload();
auto len = packet->GetPayloadLength();
if (len < 1) if (len < 1)
return false; return;
size_t offset = 0; size_t offset = 0;
uint8_t byte = data[offset++]; uint8_t byte = data[offset++];
...@@ -28,10 +33,8 @@ namespace RTC ...@@ -28,10 +33,8 @@ namespace RTC
if (x) if (x)
{ {
{ if (len < offset + 1)
if (len < offset + 1) return;
return false;
}
byte = data[offset++]; byte = data[offset++];
...@@ -44,34 +47,29 @@ namespace RTC ...@@ -44,34 +47,29 @@ namespace RTC
if (i) if (i)
{ {
if (len < offset++) if (len < offset++)
{ return;
return false;
}
if ((byte >> 7) & 0x1) if ((byte >> 7) & 0x1)
{ {
if (len < offset++) if (len < offset++)
return false; return;
} }
} }
if (l) if (l)
{ {
if (len < offset++) if (len < offset++)
{ return;
return false;
}
} }
if (t || k) if (t || k)
{ {
if (len < offset++) if (len < offset++)
{ return;
return false;
}
} }
return start && pid == 0 && (!(data[offset] & 0x1)); if (start && pid == 0 && (!(data[offset] & 0x1)))
packet->SetKeyFrame(true);
} }
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
...@@ -175,7 +175,7 @@ namespace RTC ...@@ -175,7 +175,7 @@ namespace RTC
MS_DEBUG_DEV("Consumer resumed [consumerId:%" PRIu32 "]", this->consumerId); MS_DEBUG_DEV("Consumer resumed [consumerId:%" PRIu32 "]", this->consumerId);
if (IsEnabled() && !this->sourcePaused) if (IsEnabled() && !this->sourcePaused)
RequestFullFrame(); RequestKeyFrame();
} }
void Consumer::SourcePause() void Consumer::SourcePause()
...@@ -209,7 +209,7 @@ namespace RTC ...@@ -209,7 +209,7 @@ namespace RTC
this->notifier->Emit(this->consumerId, "sourceresumed"); this->notifier->Emit(this->consumerId, "sourceresumed");
if (IsEnabled() && !this->paused) if (IsEnabled() && !this->paused)
RequestFullFrame(); RequestKeyFrame();
} }
void Consumer::SourceRtpParametersUpdated() void Consumer::SourceRtpParametersUpdated()
...@@ -337,8 +337,9 @@ namespace RTC ...@@ -337,8 +337,9 @@ namespace RTC
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());
if (Codecs::IsKnown(this->rtpStream->GetMimeType()) && Codecs::IsKeyFrame(this->rtpStream->GetMimeType(), packet)) if (canBeKeyFrame && packet->IsKeyFrame())
{ {
isKeyFrame = true; isKeyFrame = true;
...@@ -348,7 +349,7 @@ namespace RTC ...@@ -348,7 +349,7 @@ namespace RTC
RTC::RtpEncodingParameters::profile2String[profile].c_str()); RTC::RtpEncodingParameters::profile2String[profile].c_str());
} }
if (!Codecs::IsKnown(this->rtpStream->GetMimeType()) || isKeyFrame) if (isKeyFrame || !canBeKeyFrame)
{ {
SetEffectiveProfile(this->targetProfile); SetEffectiveProfile(this->targetProfile);
...@@ -549,7 +550,7 @@ namespace RTC ...@@ -549,7 +550,7 @@ namespace RTC
this->rtpStream->ReceiveRtcpReceiverReport(report); this->rtpStream->ReceiveRtcpReceiverReport(report);
} }
void Consumer::RequestFullFrame() void Consumer::RequestKeyFrame()
{ {
MS_TRACE(); MS_TRACE();
...@@ -561,7 +562,7 @@ namespace RTC ...@@ -561,7 +562,7 @@ namespace RTC
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
listener->OnConsumerFullFrameRequired(this); listener->OnConsumerKeyFrameRequired(this);
} }
} }
...@@ -727,7 +728,7 @@ namespace RTC ...@@ -727,7 +728,7 @@ namespace RTC
return; return;
if (IsEnabled() && !IsPaused()) if (IsEnabled() && !IsPaused())
RequestFullFrame(); RequestKeyFrame();
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
......
...@@ -112,15 +112,15 @@ namespace RTC ...@@ -112,15 +112,15 @@ namespace RTC
this->nackList.erase(this->nackList.begin(), it); this->nackList.erase(this->nackList.begin(), it);
// If the nack list is too large, clear it and request a full frame. // If the nack list is too large, clear it and request a key frame.
uint32_t numNewNacks = seq32End - seq32Start; uint32_t numNewNacks = seq32End - seq32Start;
if (this->nackList.size() + numNewNacks > MaxNackPackets) if (this->nackList.size() + numNewNacks > MaxNackPackets)
{ {
MS_DEBUG_TAG(rtx, "NACK list too large, clearing it and requesting a full frame"); MS_DEBUG_TAG(rtx, "NACK list too large, clearing it and requesting a key frame");
this->nackList.clear(); this->nackList.clear();
this->listener->OnNackGeneratorFullFrameRequired(); this->listener->OnNackGeneratorKeyFrameRequired();
return; return;
} }
......
...@@ -13,8 +13,7 @@ namespace RTC ...@@ -13,8 +13,7 @@ namespace RTC
{ {
/* Static. */ /* Static. */
// TODO: Set a proper value. static constexpr uint64_t KeyFrameRequestBlockTimeout{ 1000 }; // In ms.
static constexpr uint64_t FullFrameRequestBlockTimeout{ 1000 }; // In ms.
/* Instance methods. */ /* Instance methods. */
...@@ -43,8 +42,8 @@ namespace RTC ...@@ -43,8 +42,8 @@ namespace RTC
else else
this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs; this->maxRtcpInterval = RTC::RTCP::MaxAudioIntervalMs;
// Set the RTP full frame request block timer. // Set the RTP key frame request block timer.
this->fullFrameRequestBlockTimer = new Timer(this); this->keyFrameRequestBlockTimer = new Timer(this);
} }
Producer::~Producer() Producer::~Producer()
...@@ -65,8 +64,8 @@ namespace RTC ...@@ -65,8 +64,8 @@ namespace RTC
listener->OnProducerClosed(this); listener->OnProducerClosed(this);
} }
// Close the RTP full frame request block timer. // Close the RTP key frame request block timer.
this->fullFrameRequestBlockTimer->Destroy(); this->keyFrameRequestBlockTimer->Destroy();
delete this; delete this;
} }
...@@ -200,7 +199,7 @@ namespace RTC ...@@ -200,7 +199,7 @@ namespace RTC
listener->OnProducerResumed(this); listener->OnProducerResumed(this);
} }
RequestFullFrame(true); RequestKeyFrame(true);
} }
void Producer::SetRtpRawEvent(bool enabled) void Producer::SetRtpRawEvent(bool enabled)
...@@ -221,9 +220,9 @@ namespace RTC ...@@ -221,9 +220,9 @@ namespace RTC
MS_DEBUG_DEV("Producer rtpraw event disabled [producerId:%" PRIu32 "]", this->producerId); MS_DEBUG_DEV("Producer rtpraw event disabled [producerId:%" PRIu32 "]", this->producerId);
} }
// If set (and not paused), require a full frame. // If set (and not paused), require a key frame.
if (this->rtpRawEventEnabled && !this->paused) if (this->rtpRawEventEnabled && !this->paused)
RequestFullFrame(true); RequestKeyFrame(true);
} }
void Producer::SetRtpObjectEvent(bool enabled) void Producer::SetRtpObjectEvent(bool enabled)
...@@ -244,9 +243,9 @@ namespace RTC ...@@ -244,9 +243,9 @@ namespace RTC
MS_DEBUG_DEV("Producer rtpobject event disabled [producerId:%" PRIu32 "]", this->producerId); MS_DEBUG_DEV("Producer rtpobject event disabled [producerId:%" PRIu32 "]", this->producerId);
} }
// If set (and not paused), require a full frame. // If set (and not paused), require a key frame.
if (this->rtpObjectEventEnabled && !this->paused) if (this->rtpObjectEventEnabled && !this->paused)
RequestFullFrame(true); RequestKeyFrame(true);
} }
void Producer::ReceiveRtpPacket(RTC::RtpPacket* packet) void Producer::ReceiveRtpPacket(RTC::RtpPacket* packet)
...@@ -301,7 +300,10 @@ namespace RTC ...@@ -301,7 +300,10 @@ namespace RTC
return; return;
} }
if (Codecs::IsKeyFrame(rtpStream->GetMimeType(), packet)) // Process the packet at codec level.
Codecs::ProcessRtpPacket(packet, rtpStream->GetMimeType());
if (packet->IsKeyFrame())
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
...@@ -398,7 +400,7 @@ namespace RTC ...@@ -398,7 +400,7 @@ namespace RTC
this->transport->SendRtcpPacket(packet); this->transport->SendRtcpPacket(packet);
} }
void Producer::RequestFullFrame(bool force) void Producer::RequestKeyFrame(bool force)
{ {
MS_TRACE(); MS_TRACE();
...@@ -408,30 +410,30 @@ namespace RTC ...@@ -408,30 +410,30 @@ namespace RTC
if (force) if (force)
{ {
// Stop the timer. // Stop the timer.
this->fullFrameRequestBlockTimer->Stop(); this->keyFrameRequestBlockTimer->Stop();
} }
else if (this->fullFrameRequestBlockTimer->IsActive()) else if (this->keyFrameRequestBlockTimer->IsActive())
{ {
MS_DEBUG_TAG(rtcp, "blocking full frame request until timer expires"); MS_DEBUG_TAG(rtcp, "blocking key frame request until timer expires");
// Set flag. // Set flag.
this->isFullFrameRequested = true; this->isKeyFrameRequested = true;
return; return;
} }
// Run the timer. // Run the timer.
this->fullFrameRequestBlockTimer->Start(FullFrameRequestBlockTimeout); this->keyFrameRequestBlockTimer->Start(KeyFrameRequestBlockTimeout);
for (auto& kv : this->rtpStreams) for (auto& kv : this->rtpStreams)
{ {
auto rtpStream = kv.second; auto rtpStream = kv.second;
rtpStream->RequestFullFrame(); rtpStream->RequestKeyFrame();
} }
// Reset flag. // Reset flag.
this->isFullFrameRequested = false; this->isKeyFrameRequested = false;
} }
void Producer::FillHeaderExtensionIds() void Producer::FillHeaderExtensionIds()
...@@ -614,8 +616,8 @@ namespace RTC ...@@ -614,8 +616,8 @@ namespace RTC
} }
} }
// Request a full frame since we may have lost the first packets of this stream. // Request a key frame since we may have lost the first packets of this stream.
RequestFullFrame(true); RequestKeyFrame(true);
} }
void Producer::ClearRtpStream(RTC::RtpStreamRecv* rtpStream) void Producer::ClearRtpStream(RTC::RtpStreamRecv* rtpStream)
...@@ -850,15 +852,15 @@ namespace RTC ...@@ -850,15 +852,15 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (timer == this->fullFrameRequestBlockTimer) if (timer == this->keyFrameRequestBlockTimer)
{ {
// Nobody asked for a full frame since the timer was started. // Nobody asked for a key frame since the timer was started.
if (!this->isFullFrameRequested) if (!this->isKeyFrameRequested)
return; return;
MS_DEBUG_TAG(rtcp, "requesting full frame after timer expires"); MS_DEBUG_TAG(rtcp, "requesting key frame after timer expires");
RequestFullFrame(); RequestKeyFrame();
} }
} }
} // namespace RTC } // namespace RTC
...@@ -1476,7 +1476,7 @@ namespace RTC ...@@ -1476,7 +1476,7 @@ namespace RTC
this->mapConsumerProducer.erase(consumer); this->mapConsumerProducer.erase(consumer);
} }
void Router::OnConsumerFullFrameRequired(RTC::Consumer* consumer) void Router::OnConsumerKeyFrameRequired(RTC::Consumer* consumer)
{ {
MS_TRACE(); MS_TRACE();
...@@ -1486,7 +1486,7 @@ namespace RTC ...@@ -1486,7 +1486,7 @@ namespace RTC
auto* producer = this->mapConsumerProducer[consumer]; auto* producer = this->mapConsumerProducer[consumer];
producer->RequestFullFrame(); producer->RequestKeyFrame();
} }
inline void Router::OnTimer(Timer* timer) inline void Router::OnTimer(Timer* timer)
......
...@@ -291,9 +291,6 @@ namespace RTC ...@@ -291,9 +291,6 @@ namespace RTC
ptr += 4 + extensionValueSize; ptr += 4 + extensionValueSize;
} }
// Parse and regenerate RFC 5285 extension header.
ParseExtensions();
// Add payload. // Add payload.
if (this->payload != nullptr) if (this->payload != nullptr)
{ {
...@@ -367,6 +364,9 @@ namespace RTC ...@@ -367,6 +364,9 @@ namespace RTC
// Clone seq32. // Clone seq32.
packet->seq32 = this->seq32; packet->seq32 = this->seq32;
// Copy isKeyFrame.
packet->isKeyFrame = this->isKeyFrame;
// Parse RFC 5285 extension header. // Parse RFC 5285 extension header.
packet->ParseExtensions(); packet->ParseExtensions();
......
...@@ -213,7 +213,7 @@ namespace RTC ...@@ -213,7 +213,7 @@ namespace RTC
this->lastSrTimestamp += report->GetNtpFrac() >> 16; this->lastSrTimestamp += report->GetNtpFrac() >> 16;
} }
void RtpStreamRecv::RequestFullFrame() void RtpStreamRecv::RequestKeyFrame()
{ {
MS_TRACE(); MS_TRACE();
...@@ -285,11 +285,11 @@ namespace RTC ...@@ -285,11 +285,11 @@ namespace RTC
this->listener->OnRtpStreamRecvNackRequired(this, seqNumbers); this->listener->OnRtpStreamRecvNackRequired(this, seqNumbers);
} }
void RtpStreamRecv::OnNackGeneratorFullFrameRequired() void RtpStreamRecv::OnNackGeneratorKeyFrameRequired()
{ {
MS_TRACE(); MS_TRACE();
RequestFullFrame(); RequestKeyFrame();
} }
void RtpStreamRecv::SetRtx(uint8_t payloadType, uint32_t ssrc) void RtpStreamRecv::SetRtx(uint8_t payloadType, uint32_t ssrc)
......
...@@ -40,7 +40,7 @@ namespace RTC ...@@ -40,7 +40,7 @@ namespace RTC
/* Static. */ /* Static. */
static constexpr uint64_t EffectiveMaxBitrateCheckInterval{ 2000 }; // In ms. static constexpr uint64_t EffectiveMaxBitrateCheckInterval{ 2000 }; // In ms.
static constexpr double EffectiveMaxBitrateThresholdBeforeFullFrame{ 0.6 }; // 0.0 - 1.0. static constexpr double EffectiveMaxBitrateThresholdBeforeKeyFrame{ 0.6 }; // 0.0 - 1.0.
/* Instance methods. */ /* Instance methods. */
...@@ -461,16 +461,16 @@ namespace RTC ...@@ -461,16 +461,16 @@ namespace RTC
// Add us as listener. // Add us as listener.
consumer->AddListener(this); consumer->AddListener(this);
// If we are connected, ask a fullrequest for this enabled Consumer. // If we are connected, ask a key request for this enabled Consumer.
if (IsConnected()) if (IsConnected())
{ {
if (consumer->kind == RTC::Media::Kind::VIDEO) if (consumer->kind == RTC::Media::Kind::VIDEO)
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtcp, "requesting full frame for new Consumer since Transport already connected"); rtcp, "requesting key frame for new Consumer since Transport already connected");
} }
consumer->RequestFullFrame(); consumer->RequestKeyFrame();
} }
} }
...@@ -736,7 +736,7 @@ namespace RTC ...@@ -736,7 +736,7 @@ namespace RTC
break; break;
} }
consumer->RequestFullFrame(); consumer->RequestKeyFrame();
break; break;
} }
...@@ -1439,13 +1439,13 @@ namespace RTC ...@@ -1439,13 +1439,13 @@ namespace RTC
eventData[JsonStringDtlsRemoteCert] = remoteCert; eventData[JsonStringDtlsRemoteCert] = remoteCert;
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData); this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
// Iterate all the Consumers and request full frame. // Iterate all the Consumers and request key frame.
for (auto* consumer : this->consumers) for (auto* consumer : this->consumers)
{ {
if (consumer->kind == RTC::Media::Kind::VIDEO) if (consumer->kind == RTC::Media::Kind::VIDEO)
MS_DEBUG_TAG(rtcp, "Transport connected, requesting full frame for Consumers"); MS_DEBUG_TAG(rtcp, "Transport connected, requesting key frame for Consumers");
consumer->RequestFullFrame(); consumer->RequestKeyFrame();
} }
} }
...@@ -1550,21 +1550,21 @@ namespace RTC ...@@ -1550,21 +1550,21 @@ namespace RTC
packet.Serialize(RTC::RTCP::Buffer); packet.Serialize(RTC::RTCP::Buffer);
this->SendRtcpPacket(&packet); this->SendRtcpPacket(&packet);
// Trigger a full frame for all the suitable strams if the effective max bitrate // Trigger a key frame for all the suitable streams if the effective max bitrate
// has decreased abruptly. // has decreased abruptly.
if (now - this->lastEffectiveMaxBitrateAt > EffectiveMaxBitrateCheckInterval) if (now - this->lastEffectiveMaxBitrateAt > EffectiveMaxBitrateCheckInterval)
{ {
if ( if (
(bitrate != 0u) && (this->effectiveMaxBitrate != 0u) && (bitrate != 0u) && (this->effectiveMaxBitrate != 0u) &&
static_cast<double>(effectiveBitrate) / static_cast<double>(this->effectiveMaxBitrate) < static_cast<double>(effectiveBitrate) / static_cast<double>(this->effectiveMaxBitrate) <
EffectiveMaxBitrateThresholdBeforeFullFrame) EffectiveMaxBitrateThresholdBeforeKeyFrame)
{ {
MS_WARN_TAG(rbe, "uplink effective max bitrate abruptly decrease, requesting full frames"); MS_WARN_TAG(rbe, "uplink effective max bitrate abruptly decrease, requesting key frames");
// Request full frame for all the Producers. // Request key frame for all the Producers.
for (auto* producer : this->producers) for (auto* producer : this->producers)
{ {
producer->RequestFullFrame(); producer->RequestKeyFrame();
} }
} }
...@@ -1631,7 +1631,7 @@ namespace RTC ...@@ -1631,7 +1631,7 @@ namespace RTC
this->consumers.erase(consumer); this->consumers.erase(consumer);
} }
void Transport::OnConsumerFullFrameRequired(RTC::Consumer* /*consumer*/) void Transport::OnConsumerKeyFrameRequired(RTC::Consumer* /*consumer*/)
{ {
// Do nothing. // Do nothing.
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论