提交 775a5e1e authored 作者: José Luis Millán's avatar José Luis Millán

RtpStream: GetStats()

上级 e9382bf9
......@@ -43,7 +43,7 @@ namespace RTC
void Resume();
void SourcePause();
void SourceResume();
void AddProfile(const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStreamInfo* info);
void AddProfile(const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStream* rtpStream);
void RemoveProfile(const RTC::RtpEncodingParameters::Profile profile);
void SourceRtpParametersUpdated();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
......@@ -54,6 +54,7 @@ namespace RTC
void SendRtpPacket(RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
void ReceiveKeyFrameRequest(RTCP::FeedbackPs::MessageType messageType);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now);
void RequestKeyFrame();
......@@ -104,7 +105,7 @@ namespace RTC
// RTP profiles.
std::set<RTC::RtpEncodingParameters::Profile> profiles;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*> mapProfileRtpStreamInfo;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*> mapProfileRtpStream;
RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile targetProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
......
......@@ -69,8 +69,7 @@ namespace RTC
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const;
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const;
void RequestKeyFrame(bool force = false);
const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*>& GetHealthyProfiles()
const;
const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>& GetHealthyProfiles() const;
private:
void FillHeaderExtensionIds();
......@@ -112,7 +111,7 @@ namespace RTC
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> mapRtpStreamProfiles;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*> healthyProfiles;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*> healthyProfiles;
Timer* keyFrameRequestBlockTimer{ nullptr };
// Others.
std::vector<RtpEncodingParameters> outputEncodings;
......@@ -164,7 +163,7 @@ namespace RTC
}
}
inline const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*>& Producer::
inline const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>& Producer::
GetHealthyProfiles() const
{
return this->healthyProfiles;
......
......@@ -22,7 +22,7 @@ namespace RTC
virtual void OnProducerProfileEnabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStreamInfo* info) = 0;
const RTC::RtpStream* rtpStream) = 0;
virtual void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
};
......
......@@ -74,7 +74,7 @@ namespace RTC
void OnProducerProfileEnabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStreamInfo* info) override;
const RTC::RtpStream* rtpStream) override;
void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
......
......@@ -69,7 +69,7 @@ namespace RTC
RED
};
private:
public:
static std::unordered_map<std::string, Type> string2Type;
static std::map<Type, std::string> type2String;
static std::unordered_map<std::string, Subtype> string2Subtype;
......
......@@ -10,20 +10,7 @@
namespace RTC
{
class RtpStreamInfo
{
public:
uint32_t totalLost{ 0 };
uint8_t fractionLost{ 0 };
uint32_t jitter{ 0 };
uint32_t rtt{ 0 };
size_t numPlis{ 0 };
size_t numNacks{ 0 };
// RTP counters.
RTC::RtpDataCounter counter;
};
class RtpStream : public Timer::Listener, public RtpStreamInfo
class RtpStream : public Timer::Listener
{
public:
class Listener
......@@ -55,6 +42,7 @@ namespace RTC
virtual ~RtpStream();
virtual Json::Value ToJson();
virtual Json::Value GetStats();
virtual bool ReceivePacket(RTC::RtpPacket* packet);
uint32_t GetRate(uint64_t now);
uint32_t GetSsrc();
......@@ -77,6 +65,24 @@ namespace RTC
public:
void OnTimer(Timer* timer) override;
public:
// Stats.
size_t packetCount{ 0 };
size_t byteCount{ 0 };
uint32_t packetsLost{ 0 };
uint8_t fractionLost{ 0 };
size_t packetsDiscarded{ 0 };
size_t packetsRepaired{ 0 };
uint32_t jitter{ 0 };
uint32_t rtt{ 0 };
size_t firCount{ 0 };
size_t pliCount{ 0 };
size_t nackCount{ 0 };
size_t sliCount{ 0 };
RtpDataCounter transmissionCounter;
RtpDataCounter retransmissionCounter;
protected:
// Given as argument.
RtpStream::Params params;
......
......@@ -23,6 +23,7 @@ namespace RTC
RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params);
~RtpStreamRecv() override;
Json::Value GetStats() override;
bool ReceivePacket(RTC::RtpPacket* packet) override;
bool ReceiveRtxPacket(RTC::RtpPacket* packet);
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
......
......@@ -29,6 +29,7 @@ namespace RTC
RtpStreamSend(RTC::RtpStream::Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize);
~RtpStreamSend() override;
Json::Value GetStats() override;
bool ReceivePacket(RTC::RtpPacket* packet) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
void RequestRtpRetransmission(
......
......@@ -98,7 +98,7 @@ namespace RTC
void OnProducerProfileEnabled(
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStreamInfo* info) override;
const RTC::RtpStream* rtpStream) override;
void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
......
......@@ -227,7 +227,7 @@ namespace RTC
}
void Consumer::AddProfile(
const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStreamInfo* info)
const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStream* rtpStream)
{
MS_ASSERT(
profile != RTC::RtpEncodingParameters::Profile::NONE &&
......@@ -237,7 +237,7 @@ namespace RTC
MS_ASSERT(this->profiles.find(profile) == this->profiles.end(), "profile already exists");
// Insert the new profile.
this->mapProfileRtpStreamInfo[profile] = info;
this->mapProfileRtpStream[profile] = rtpStream;
this->profiles.insert(profile);
MS_DEBUG_TAG(
......@@ -257,7 +257,7 @@ namespace RTC
MS_ASSERT(this->profiles.find(profile) != this->profiles.end(), "profile not found");
// Remove the profile.
this->mapProfileRtpStreamInfo.erase(profile);
this->mapProfileRtpStream.erase(profile);
this->profiles.erase(profile);
MS_DEBUG_TAG(
......@@ -553,6 +553,8 @@ namespace RTC
if (!IsEnabled())
return;
this->rtpStream->nackCount++;
for (auto it = nackPacket->Begin(); it != nackPacket->End(); ++it)
{
RTC::RTCP::FeedbackRtpNackItem* item = *it;
......@@ -569,8 +571,34 @@ namespace RTC
break;
RetransmitRtpPacket(packet);
this->rtpStream->packetsRepaired++;
}
}
}
void Consumer::ReceiveKeyFrameRequest(RTCP::FeedbackPs::MessageType messageType)
{
MS_TRACE();
if (!IsEnabled())
return;
switch (messageType)
{
case RTCP::FeedbackPs::MessageType::PLI:
this->rtpStream->pliCount++;
break;
case RTCP::FeedbackPs::MessageType::FIR:
this->rtpStream->firCount++;
break;
default:
MS_ASSERT(false, "invalid messageType");
break;
}
RequestKeyFrame();
}
void Consumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......
......@@ -210,6 +210,8 @@ namespace RTC
// Process the packet.
if (!rtpStream->ReceiveRtxPacket(packet))
return;
rtpStream->packetsRepaired++;
}
else
{
......@@ -645,8 +647,7 @@ namespace RTC
for (auto& listener : this->listeners)
{
listener->OnProducerProfileEnabled(
this, profile, dynamic_cast<RTC::RtpStreamInfo*>(rtpStream));
listener->OnProducerProfileEnabled(this, profile, rtpStream);
}
}
}
......@@ -723,6 +724,8 @@ namespace RTC
packet.Serialize(RTC::RTCP::Buffer);
this->transport->SendRtcpPacket(&packet);
rtpStream->nackCount++;
}
void Producer::OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream)
......@@ -738,6 +741,8 @@ namespace RTC
// Send two, because it's free.
this->transport->SendRtcpPacket(&packet);
this->transport->SendRtcpPacket(&packet);
rtpStream->pliCount++;
}
void Producer::OnRtpStreamDied(RTC::RtpStream* rtpStream)
......
......@@ -512,14 +512,14 @@ namespace RTC
consumer->AddListener(this);
auto healthyProfiles = producer->GetHealthyProfiles();
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*>::reverse_iterator it;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>::reverse_iterator it;
for (it = healthyProfiles.rbegin(); it != healthyProfiles.rend(); ++it)
{
auto profile = it->first;
auto info = it->second;
auto stats = it->second;
consumer->AddProfile(profile, info);
consumer->AddProfile(profile, stats);
}
// Insert into the maps.
......@@ -1531,7 +1531,9 @@ namespace RTC
}
void Router::OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStreamInfo* info)
RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStream* rtpStream)
{
MS_TRACE();
......@@ -1543,7 +1545,7 @@ namespace RTC
for (auto* consumer : consumers)
{
consumer->AddProfile(profile, info);
consumer->AddProfile(profile, rtpStream);
}
}
......
......@@ -40,29 +40,59 @@ namespace RTC
{
MS_TRACE();
static const Json::StaticString JsonStringBitRate{ "bitrate" };
static const Json::StaticString JsonStringJitter{ "jitter" };
static const Json::StaticString JsonStringParams{ "params" };
static const Json::StaticString JsonStringStats{ "stats" };
Json::Value json(Json::objectValue);
json[JsonStringParams] = this->params.ToJson();
json[JsonStringStats] = GetStats();
return json;
}
Json::Value RtpStream::GetStats()
{
MS_TRACE();
static const Json::StaticString JsonStringTimestamp{ "timestamp" };
static const Json::StaticString JsonStringSsrc{ "ssrc" };
static const Json::StaticString JsonStringMediaType{ "mediaType" };
static const Json::StaticString JsonStringHealthy{ "healthy" };
static const Json::StaticString JsonStringPacketCount{ "packetCount" };
static const Json::StaticString JsonStringOctetCount{ "octetCount" };
static const Json::StaticString JsonStringRtt{ "rtt" };
static const Json::StaticString JsonStringByteCount{ "byteCount" };
static const Json::StaticString JsonStringBitRate{ "bitrate" };
static const Json::StaticString JsonStringPacketsLost{ "packetsLost" };
static const Json::StaticString JsonStringFractionLost{ "fractionLost" };
static const Json::StaticString JsonStringTotalLost{ "totalLost" };
static const Json::StaticString JsonStringHealthy{ "healthy" };
static const Json::StaticString JsonStringJitter{ "jitter" };
static const Json::StaticString JsonStringRtt{ "rtt" };
static const Json::StaticString JsonStringPacketsDiscarded{ "packetsDiscarded" };
static const Json::StaticString JsonStringPacketsRepaired{ "packetsRepaired" };
static const Json::StaticString JsonStringFirCount{ "firCount" };
static const Json::StaticString JsonStringPliCount{ "pliCount" };
static const Json::StaticString JsonStringNackCount{ "nackCount" };
static const Json::StaticString JsonStringSliCount{ "sliCount" };
Json::Value json(Json::objectValue);
uint64_t now = DepLibUV::GetTime();
json[JsonStringBitRate] = Json::UInt{ GetRate(now) };
json[JsonStringTimestamp] = Json::UInt64{ now };
json[JsonStringSsrc] = Json::UInt{ this->params.ssrc };
json[JsonStringMediaType] = RtpCodecMimeType::type2String[this->params.mimeType.type];
json[JsonStringHealthy] = this->healthy ? "true" : "false";
json[JsonStringPacketCount] = static_cast<Json::UInt>(this->transmissionCounter.GetPacketCount());
json[JsonStringByteCount] = static_cast<Json::UInt>(this->transmissionCounter.GetBytes());
json[JsonStringBitRate] = Json::UInt{ this->transmissionCounter.GetRate(now) };
json[JsonStringPacketsLost] = Json::UInt{ this->packetsLost };
json[JsonStringFractionLost] = Json::UInt{ this->fractionLost };
json[JsonStringJitter] = Json::UInt{ this->jitter };
json[JsonStringParams] = this->params.ToJson();
json[JsonStringPacketCount] = static_cast<Json::UInt>(this->counter.GetPacketCount());
json[JsonStringOctetCount] = static_cast<Json::UInt>(this->counter.GetBytes());
json[JsonStringRtt] = Json::UInt{ this->rtt };
json[JsonStringFractionLost] = Json::UInt{ this->fractionLost };
json[JsonStringTotalLost] = Json::UInt{ this->totalLost };
json[JsonStringHealthy] = this->healthy ? "true" : "false";
json[JsonStringPacketsDiscarded] = static_cast<Json::UInt>(this->packetsDiscarded);
json[JsonStringPacketsRepaired] = static_cast<Json::UInt>(this->packetsRepaired);
json[JsonStringFirCount] = static_cast<Json::UInt>(this->firCount);
json[JsonStringPliCount] = static_cast<Json::UInt>(this->pliCount);
json[JsonStringNackCount] = static_cast<Json::UInt>(this->nackCount);
json[JsonStringSliCount] = static_cast<Json::UInt>(this->sliCount);
return json;
}
......@@ -95,7 +125,7 @@ namespace RTC
}
// Increase counters.
this->counter.Update(packet);
this->transmissionCounter.Update(packet);
// Update highest seen RTP timestamp.
if (packet->GetTimestamp() > this->maxPacketTs)
......@@ -109,7 +139,7 @@ namespace RTC
uint32_t RtpStream::GetRate(uint64_t now)
{
return this->counter.GetRate(now);
return this->transmissionCounter.GetRate(now);
}
void RtpStream::ResetHealthCheckTimer(uint16_t timeout)
......@@ -179,6 +209,7 @@ namespace RTC
packet->GetSequenceNumber());
this->badSeq = (seq + 1) & (RtpSeqMod - 1);
this->packetsDiscarded++;
return false;
}
......
......@@ -24,6 +24,18 @@ namespace RTC
MS_TRACE();
}
Json::Value RtpStreamRecv::GetStats()
{
static const std::string Type = "inboundrtp";
static const Json::StaticString JsonStringType{ "type" };
Json::Value json = RtpStream::GetStats();
json[JsonStringType] = Type;
return json;
}
bool RtpStreamRecv::ReceivePacket(RTC::RtpPacket* packet)
{
MS_TRACE();
......@@ -127,18 +139,18 @@ namespace RTC
// Calculate Packets Expected and Lost.
uint32_t expected = (this->cycles + this->maxSeq) - this->baseSeq + 1;
this->totalLost = expected - this->counter.GetPacketCount();
this->packetsLost = expected - this->transmissionCounter.GetPacketCount();
report->SetTotalLost(totalLost);
report->SetTotalLost(this->packetsLost);
// Calculate Fraction Lost.
uint32_t expectedInterval = expected - this->expectedPrior;
this->expectedPrior = expected;
uint32_t receivedInterval = this->counter.GetPacketCount() - this->receivedPrior;
uint32_t receivedInterval = this->transmissionCounter.GetPacketCount() - this->receivedPrior;
this->receivedPrior = counter.GetPacketCount();
this->receivedPrior = transmissionCounter.GetPacketCount();
int32_t lostInterval = expectedInterval - receivedInterval;
......@@ -217,7 +229,7 @@ namespace RTC
{
auto now = DepLibUV::GetTime();
if (this->counter.GetRate(now) == 0)
if (this->transmissionCounter.GetRate(now) == 0)
this->listener->OnRtpStreamDied(this);
}
......
......@@ -34,6 +34,18 @@ namespace RTC
ClearRetransmissionBuffer();
}
Json::Value RtpStreamSend::GetStats()
{
static const std::string Type = "outboundrtp";
static const Json::StaticString JsonStringType{ "type" };
Json::Value json = RtpStream::GetStats();
json[JsonStringType] = Type;
return json;
}
bool RtpStreamSend::ReceivePacket(RTC::RtpPacket* packet)
{
MS_TRACE();
......@@ -71,7 +83,7 @@ namespace RTC
this->rtt = ((rtt >> 16) * 1000);
this->rtt += (static_cast<float>(rtt & 0x0000FFFF) / 65536) * 1000;
this->totalLost = report->GetTotalLost();
this->packetsLost = report->GetTotalLost();
this->fractionLost = report->GetFractionLost();
this->jitter = report->GetJitter();
}
......@@ -261,13 +273,13 @@ namespace RTC
{
MS_TRACE();
if (this->counter.GetPacketCount() == 0u)
if (this->transmissionCounter.GetPacketCount() == 0u)
return nullptr;
auto report = new RTC::RTCP::SenderReport();
report->SetPacketCount(this->counter.GetPacketCount());
report->SetOctetCount(this->counter.GetBytes());
report->SetPacketCount(this->transmissionCounter.GetPacketCount());
report->SetOctetCount(this->transmissionCounter.GetBytes());
Utils::Time::Ntp ntp{};
Utils::Time::CurrentTimeNtp(ntp);
......
......@@ -252,7 +252,7 @@ namespace RTC
feedback->GetMediaSsrc(),
feedback->GetMediaSsrc());
consumer->RequestKeyFrame();
consumer->ReceiveKeyFrameRequest(feedback->GetMessageType());
break;
}
......@@ -544,7 +544,7 @@ namespace RTC
void Transport::OnProducerProfileEnabled(
RTC::Producer* /*producer*/,
RTC::RtpEncodingParameters::Profile /*profile*/,
const RTC::RtpStreamInfo* /*info*/)
const RTC::RtpStream* /*rtpStream*/)
{
// Do nothing.
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论