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

RtpStream::ResetScore(uint8_t score, bool notify)

上级 78851605
...@@ -67,9 +67,9 @@ namespace RTC ...@@ -67,9 +67,9 @@ namespace RTC
uint32_t GetRtxSsrc() const; uint32_t GetRtxSsrc() const;
uint8_t GetRtxPayloadType() const; uint8_t GetRtxPayloadType() const;
virtual bool ReceivePacket(RTC::RtpPacket* packet); virtual bool ReceivePacket(RTC::RtpPacket* packet);
void PostProcessPacket(RTC::RtpPacket* packet);
virtual void Pause() = 0; virtual void Pause() = 0;
virtual void Resume() = 0; virtual void Resume() = 0;
void ResetScore(uint8_t score, bool notify);
uint32_t GetRate(uint64_t now); uint32_t GetRate(uint64_t now);
uint8_t GetFractionLost() const; uint8_t GetFractionLost() const;
float GetLossPercentage() const; float GetLossPercentage() const;
...@@ -79,7 +79,6 @@ namespace RTC ...@@ -79,7 +79,6 @@ namespace RTC
protected: protected:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
void UpdateScore(uint8_t score); void UpdateScore(uint8_t score);
void ResetScore();
void PacketRetransmitted(RTC::RtpPacket* packet); void PacketRetransmitted(RTC::RtpPacket* packet);
void PacketRepaired(RTC::RtpPacket* packet); void PacketRepaired(RTC::RtpPacket* packet);
uint32_t GetExpectedPackets(); uint32_t GetExpectedPackets();
......
...@@ -118,6 +118,26 @@ namespace RTC ...@@ -118,6 +118,26 @@ namespace RTC
return true; return true;
} }
void RtpStream::ResetScore(uint8_t score, bool notify)
{
MS_TRACE();
this->totalSourceLoss = 0;
this->totalReportedLoss = 0;
this->totalSentPackets = 0;
this->scores.clear();
if (this->score != score)
{
this->score = score;
// Notify the listener.
if (notify)
this->listener->OnRtpStreamScore(this, score);
}
}
bool RtpStream::UpdateSeq(RTC::RtpPacket* packet) bool RtpStream::UpdateSeq(RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
...@@ -254,25 +274,6 @@ namespace RTC ...@@ -254,25 +274,6 @@ namespace RTC
} }
} }
void RtpStream::ResetScore()
{
MS_TRACE();
this->totalSourceLoss = 0;
this->totalReportedLoss = 0;
this->totalSentPackets = 0;
this->scores.clear();
if (this->score != 0)
{
this->score = 0;
// Notify the listener.
this->listener->OnRtpStreamScore(this, 0);
}
}
void RtpStream::PacketRetransmitted(RTC::RtpPacket* packet) void RtpStream::PacketRetransmitted(RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -443,7 +443,7 @@ namespace RTC ...@@ -443,7 +443,7 @@ namespace RTC
if (GetScore() != 0) if (GetScore() != 0)
MS_WARN_2TAGS(rtp, score, "RTP inactivity detected, resetting score to 0"); MS_WARN_2TAGS(rtp, score, "RTP inactivity detected, resetting score to 0");
ResetScore(); ResetScore(0, true);
} }
} }
} }
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Codecs.hpp"
#include <iostream>
namespace RTC namespace RTC
{ {
...@@ -587,6 +586,9 @@ namespace RTC ...@@ -587,6 +586,9 @@ namespace RTC
this->currentSpatialLayer = spatialLayer; this->currentSpatialLayer = spatialLayer;
// Reset the score of our RtpStream to 10.
this->rtpStream->ResetScore(10, false);
MS_DEBUG_DEV( MS_DEBUG_DEV(
"current spatial layer changed to %" PRIi16 " [consumerId:%s]", "current spatial layer changed to %" PRIi16 " [consumerId:%s]",
this->currentSpatialLayer, this->currentSpatialLayer,
...@@ -608,34 +610,10 @@ namespace RTC ...@@ -608,34 +610,10 @@ namespace RTC
int16_t newTargetSpatialLayer{ -1 }; int16_t newTargetSpatialLayer{ -1 };
if (this->GetProducerCurrentRtpStream())
{
std::cout << "RecalculateTargetSpatialLayer."
<< ", consumer score: " << static_cast<unsigned int>(this->rtpStream->GetScore())
<< ", producer score: "
<< static_cast<unsigned int>(this->GetProducerCurrentRtpStream()->GetScore())
<< ", currentSpatialLayer: " << static_cast<int>(this->currentSpatialLayer)
<< ", targetSpatialLayer: " << static_cast<int>(this->targetSpatialLayer)
<< ", preferredSpatialLayer: " << static_cast<int>(this->preferredSpatialLayer)
<< std::endl;
}
else
{
std::cout << "RecalculateTargetSpatialLayer."
<< ", consumer score: " << static_cast<unsigned int>(this->rtpStream->GetScore())
<< ", producer score: "
<< "nullptr"
<< ", currentSpatialLayer: " << static_cast<int>(this->currentSpatialLayer)
<< ", targetSpatialLayer: " << static_cast<int>(this->targetSpatialLayer)
<< ", preferredSpatialLayer: " << static_cast<int>(this->preferredSpatialLayer)
<< std::endl;
}
// No current spatial layer, select the highest possible. // No current spatial layer, select the highest possible.
if (this->currentSpatialLayer == -1) if (this->currentSpatialLayer == -1)
{ {
std::cout << "RecalculateTargetSpatialLayer. no current spatial layer, selecting the highest possible..." MS_DEBUG_TAG(simulcast, "no current spatial layer, selecting the highest possible");
<< std::endl;
uint8_t maxScore = 0; uint8_t maxScore = 0;
...@@ -651,15 +629,12 @@ namespace RTC ...@@ -651,15 +629,12 @@ namespace RTC
if (producerRtpStream->GetScore() >= maxScore) if (producerRtpStream->GetScore() >= maxScore)
{ {
std::cout << "RecalculateTargetSpatialLayer. we have something: " << spatialLayer
<< std::endl;
maxScore = producerRtpStream->GetScore(); maxScore = producerRtpStream->GetScore();
newTargetSpatialLayer = spatialLayer; newTargetSpatialLayer = spatialLayer;
if (maxScore > 7) if (maxScore > 7)
{ {
std::cout << "RecalculateTargetSpatialLayer. score > 7, keep it : " << spatialLayer MS_DEBUG_TAG(simulcast, "found Producer RtpStream with score > 7, keep it");
<< std::endl;
break; break;
} }
...@@ -671,7 +646,7 @@ namespace RTC ...@@ -671,7 +646,7 @@ namespace RTC
!this->GetProducerCurrentRtpStream() || this->GetProducerCurrentRtpStream()->GetScore() < 7 || !this->GetProducerCurrentRtpStream() || this->GetProducerCurrentRtpStream()->GetScore() < 7 ||
this->rtpStream->GetScore() < 5 || this->preferredSpatialLayer < this->currentSpatialLayer) this->rtpStream->GetScore() < 5 || this->preferredSpatialLayer < this->currentSpatialLayer)
{ {
std::cout << "RecalculateTargetSpatialLayer. downgrading..." << std::endl; MS_DEBUG_TAG(simulcast, "trying to downgrade current spatial layer");
uint8_t maxScore = 0; uint8_t maxScore = 0;
...@@ -686,15 +661,12 @@ namespace RTC ...@@ -686,15 +661,12 @@ namespace RTC
if (producerRtpStream->GetScore() >= maxScore) if (producerRtpStream->GetScore() >= maxScore)
{ {
std::cout << "RecalculateTargetSpatialLayer. we have something: " << spatialLayer
<< std::endl;
maxScore = producerRtpStream->GetScore(); maxScore = producerRtpStream->GetScore();
newTargetSpatialLayer = spatialLayer; newTargetSpatialLayer = spatialLayer;
if (maxScore > 7) if (maxScore > 7)
{ {
std::cout << "RecalculateTargetSpatialLayer. score > 7, keep it : " << spatialLayer MS_DEBUG_TAG(simulcast, "found Producer RtpStream with score > 7, keep it");
<< std::endl;
break; break;
} }
...@@ -704,7 +676,7 @@ namespace RTC ...@@ -704,7 +676,7 @@ namespace RTC
// Update to the highest possible spatial layer. // Update to the highest possible spatial layer.
else else
{ {
std::cout << "RecalculateTargetSpatialLayer. trying to upgrade..." << std::endl; MS_DEBUG_TAG(simulcast, "trying to upgrade current spatial layer");
int16_t idx = this->currentSpatialLayer == -1 ? 0 : this->currentSpatialLayer + 1; int16_t idx = this->currentSpatialLayer == -1 ? 0 : this->currentSpatialLayer + 1;
...@@ -721,8 +693,8 @@ namespace RTC ...@@ -721,8 +693,8 @@ namespace RTC
// Take this as the new target if it is good enough. // Take this as the new target if it is good enough.
if (producerRtpStream->GetScore() >= 7) if (producerRtpStream->GetScore() >= 7)
{ {
std::cout << "RecalculateTargetSpatialLayer. good enough spatial layer found: " MS_DEBUG_TAG(simulcast, "good enough spatial layer found: %" PRIi16, spatialLayer);
<< spatialLayer << std::endl;
newTargetSpatialLayer = spatialLayer; newTargetSpatialLayer = spatialLayer;
break; break;
...@@ -732,7 +704,8 @@ namespace RTC ...@@ -732,7 +704,8 @@ namespace RTC
if (newTargetSpatialLayer == -1) if (newTargetSpatialLayer == -1)
{ {
std::cout << "RecalculateTargetSpatialLayer, target layer not updated" << std::endl; MS_DEBUG_TAG(simulcast, "newTargetSpatialLayer remains unset");
return; return;
} }
...@@ -749,7 +722,7 @@ namespace RTC ...@@ -749,7 +722,7 @@ namespace RTC
RequestKeyFrame(); RequestKeyFrame();
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, simulcast,
"target spatial layer changed to %" PRIi16 " [consumerId:%s]", "target spatial layer changed to %" PRIi16 " [consumerId:%s]",
this->targetSpatialLayer, this->targetSpatialLayer,
this->id.c_str()); this->id.c_str());
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论