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

RTC: lossPercentage

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