提交 5d623558 authored 作者: José Luis Millán's avatar José Luis Millán

RTC: lossPercentage

上级 1eda3c28
...@@ -57,6 +57,7 @@ namespace RTC ...@@ -57,6 +57,7 @@ namespace RTC
void ReceiveKeyFrameRequest(RTCP::FeedbackPs::MessageType messageType); void ReceiveKeyFrameRequest(RTCP::FeedbackPs::MessageType messageType);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report); void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now); uint32_t GetTransmissionRate(uint64_t now);
float GetLossPercentage() const;
void RequestKeyFrame(); void RequestKeyFrame();
private: private:
......
...@@ -48,6 +48,7 @@ namespace RTC ...@@ -48,6 +48,7 @@ namespace RTC
uint32_t GetSsrc(); uint32_t GetSsrc();
uint8_t GetPayloadType(); uint8_t GetPayloadType();
const RTC::RtpCodecMimeType& GetMimeType() const; const RTC::RtpCodecMimeType& GetMimeType() const;
float GetLossPercentage() const;
bool IsHealthy(); bool IsHealthy();
void ResetHealthCheckTimer(uint16_t timeout = HealthCheckPeriod); void ResetHealthCheckTimer(uint16_t timeout = HealthCheckPeriod);
...@@ -67,6 +68,8 @@ namespace RTC ...@@ -67,6 +68,8 @@ namespace RTC
public: public:
// Stats. // Stats.
uint32_t packetsLost{ 0 };
uint8_t fractionLost{ 0 };
size_t packetsDiscarded{ 0 }; size_t packetsDiscarded{ 0 };
size_t packetsRepaired{ 0 }; size_t packetsRepaired{ 0 };
size_t firCount{ 0 }; size_t firCount{ 0 };
...@@ -94,9 +97,6 @@ namespace RTC ...@@ -94,9 +97,6 @@ namespace RTC
Timer* healthCheckTimer{ nullptr }; Timer* healthCheckTimer{ nullptr };
bool healthy{ true }; bool healthy{ true };
bool notifyHealth{ true }; bool notifyHealth{ true };
// Stats.
uint32_t packetsLost{ 0 };
uint8_t fractionLost{ 0 };
}; };
/* Inline instance methods. */ /* Inline instance methods. */
...@@ -116,6 +116,11 @@ namespace RTC ...@@ -116,6 +116,11 @@ namespace RTC
return this->params.mimeType; return this->params.mimeType;
} }
inline float RtpStream::GetLossPercentage() const
{
return static_cast<float>(this->fractionLost) * 100 / 256;
}
inline bool RtpStream::IsHealthy() inline bool RtpStream::IsHealthy()
{ {
return this->healthy; return this->healthy;
......
...@@ -69,6 +69,7 @@ namespace RTC ...@@ -69,6 +69,7 @@ namespace RTC
static const Json::StaticString JsonStringSourcePaused{ "sourcePaused" }; static const Json::StaticString JsonStringSourcePaused{ "sourcePaused" };
static const Json::StaticString JsonStringPreferredProfile{ "preferredProfile" }; static const Json::StaticString JsonStringPreferredProfile{ "preferredProfile" };
static const Json::StaticString JsonStringEffectiveProfile{ "effectiveProfile" }; static const Json::StaticString JsonStringEffectiveProfile{ "effectiveProfile" };
static const Json::StaticString JsonStringLossPercentage{ "lossPercentage" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -94,6 +95,8 @@ namespace RTC ...@@ -94,6 +95,8 @@ namespace RTC
json[JsonStringEffectiveProfile] = json[JsonStringEffectiveProfile] =
RTC::RtpEncodingParameters::profile2String[this->effectiveProfile]; RTC::RtpEncodingParameters::profile2String[this->effectiveProfile];
json[JsonStringLossPercentage] = GetLossPercentage();
return json; return json;
} }
...@@ -615,6 +618,28 @@ namespace RTC ...@@ -615,6 +618,28 @@ namespace RTC
this->rtpStream->ReceiveRtcpReceiverReport(report); this->rtpStream->ReceiveRtcpReceiverReport(report);
} }
float Consumer::GetLossPercentage() const
{
float lossPercentage = 0;
if (this->effectiveProfile != RTC::RtpEncodingParameters::Profile::NONE)
{
auto it = this->mapProfileRtpStream.find(this->effectiveProfile);
MS_ASSERT(
it != this->mapProfileRtpStream.end(), "no RtpStream associated with current profile");
auto rtpStream = it->second;
if (rtpStream->GetLossPercentage() >= this->rtpStream->GetLossPercentage())
lossPercentage = 0;
else
lossPercentage = (this->rtpStream->GetLossPercentage() - rtpStream->GetLossPercentage());
}
return lossPercentage;
}
void Consumer::RequestKeyFrame() void Consumer::RequestKeyFrame()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -82,6 +82,7 @@ namespace RTC ...@@ -82,6 +82,7 @@ namespace RTC
static const Json::StaticString JsonStringAbsSendTime{ "absSendTime" }; static const Json::StaticString JsonStringAbsSendTime{ "absSendTime" };
static const Json::StaticString JsonStringRid{ "rid" }; static const Json::StaticString JsonStringRid{ "rid" };
static const Json::StaticString JsonStringPaused{ "paused" }; static const Json::StaticString JsonStringPaused{ "paused" };
static const Json::StaticString JsonStringLossPercentage{ "lossPercentage" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
Json::Value jsonHeaderExtensionIds(Json::objectValue); Json::Value jsonHeaderExtensionIds(Json::objectValue);
...@@ -93,14 +94,23 @@ namespace RTC ...@@ -93,14 +94,23 @@ namespace RTC
json[JsonStringRtpParameters] = this->rtpParameters.ToJson(); json[JsonStringRtpParameters] = this->rtpParameters.ToJson();
float lossPercentage = 0;
for (auto& kv : this->rtpStreams) for (auto& kv : this->rtpStreams)
{ {
auto rtpStream = kv.second; auto rtpStream = kv.second;
jsonRtpStreams.append(rtpStream->ToJson()); jsonRtpStreams.append(rtpStream->ToJson());
lossPercentage += rtpStream->GetLossPercentage();
} }
json[JsonStringRtpStreams] = jsonRtpStreams; json[JsonStringRtpStreams] = jsonRtpStreams;
if (!this->rtpStreams.empty())
lossPercentage = lossPercentage / this->rtpStreams.size();
json[JsonStringLossPercentage] = lossPercentage;
if (this->headerExtensionIds.ssrcAudioLevel != 0u) if (this->headerExtensionIds.ssrcAudioLevel != 0u)
jsonHeaderExtensionIds[JsonStringSsrcAudioLevel] = this->headerExtensionIds.ssrcAudioLevel; jsonHeaderExtensionIds[JsonStringSsrcAudioLevel] = this->headerExtensionIds.ssrcAudioLevel;
......
...@@ -402,11 +402,11 @@ namespace RTC ...@@ -402,11 +402,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
uint16_t currentLossPercentage = this->fractionLost * 100 / 256; auto lossPercentage = GetLossPercentage();
if (currentLossPercentage >= MaxHealthLossPercentage) if (lossPercentage >= MaxHealthLossPercentage)
{ {
MS_DEBUG_TAG(rtp, "last period loss percentage: %" PRIu16, currentLossPercentage); MS_DEBUG_TAG(rtp, "last period loss percentage: %.2f", lossPercentage);
if (this->notifyHealth || this->healthy) if (this->notifyHealth || this->healthy)
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论