提交 18c32d29 authored 作者: José Luis Millán's avatar José Luis Millán

RtpStream: spatial and temporal layer granularity transmission counters

上级 694d28c5
...@@ -46,6 +46,7 @@ namespace RTC ...@@ -46,6 +46,7 @@ namespace RTC
void Dump() const; void Dump() const;
bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data); bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data);
void Restore(uint8_t* data); void Restore(uint8_t* data);
uint8_t GetSpatialLayer() const;
uint8_t GetTemporalLayer() const; uint8_t GetTemporalLayer() const;
bool IsKeyFrame() const; bool IsKeyFrame() const;
...@@ -70,6 +71,11 @@ namespace RTC ...@@ -70,6 +71,11 @@ namespace RTC
{ {
} }
inline uint8_t H264::PayloadDescriptorHandler::GetSpatialLayer() const
{
return 0u;
};
inline uint8_t H264::PayloadDescriptorHandler::GetTemporalLayer() const inline uint8_t H264::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
return 0u; return 0u;
......
...@@ -45,6 +45,7 @@ namespace RTC ...@@ -45,6 +45,7 @@ namespace RTC
virtual void Dump() const = 0; virtual void Dump() const = 0;
virtual bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data) = 0; virtual bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data) = 0;
virtual void Restore(uint8_t* data) = 0; virtual void Restore(uint8_t* data) = 0;
virtual uint8_t GetSpatialLayer() const = 0;
virtual uint8_t GetTemporalLayer() const = 0; virtual uint8_t GetTemporalLayer() const = 0;
virtual bool IsKeyFrame() const = 0; virtual bool IsKeyFrame() const = 0;
......
...@@ -102,6 +102,7 @@ namespace RTC ...@@ -102,6 +102,7 @@ namespace RTC
void Dump() const; void Dump() const;
bool Encode(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data); bool Encode(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data);
void Restore(uint8_t* data); void Restore(uint8_t* data);
uint8_t GetSpatialLayer() const;
uint8_t GetTemporalLayer() const; uint8_t GetTemporalLayer() const;
bool IsKeyFrame() const; bool IsKeyFrame() const;
...@@ -119,6 +120,11 @@ namespace RTC ...@@ -119,6 +120,11 @@ namespace RTC
/* Inline PayloadDescriptorHandler methods */ /* Inline PayloadDescriptorHandler methods */
inline uint8_t VP8::PayloadDescriptorHandler::GetSpatialLayer() const
{
return 0u;
};
inline uint8_t VP8::PayloadDescriptorHandler::GetTemporalLayer() const inline uint8_t VP8::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
if (this->payloadDescriptor->hasTlIndex) if (this->payloadDescriptor->hasTlIndex)
......
...@@ -137,6 +137,7 @@ namespace RTC ...@@ -137,6 +137,7 @@ namespace RTC
uint8_t* GetPayload() const; uint8_t* GetPayload() const;
size_t GetPayloadLength() const; size_t GetPayloadLength() const;
uint8_t GetPayloadPadding() const; uint8_t GetPayloadPadding() const;
uint8_t GetSpatialLayer() const;
uint8_t GetTemporalLayer() const; uint8_t GetTemporalLayer() const;
bool IsKeyFrame() const; bool IsKeyFrame() const;
RtpPacket* Clone(const uint8_t* buffer) const; RtpPacket* Clone(const uint8_t* buffer) const;
...@@ -509,6 +510,14 @@ namespace RTC ...@@ -509,6 +510,14 @@ namespace RTC
return this->payloadDescriptorHandler->GetTemporalLayer(); return this->payloadDescriptorHandler->GetTemporalLayer();
} }
inline uint8_t RtpPacket::GetSpatialLayer() const
{
if (!this->payloadDescriptorHandler)
return 0u;
return this->payloadDescriptorHandler->GetSpatialLayer();
}
inline bool RtpPacket::IsKeyFrame() const inline bool RtpPacket::IsKeyFrame() const
{ {
if (!this->payloadDescriptorHandler) if (!this->payloadDescriptorHandler)
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include <string> #include <string>
...@@ -73,8 +72,10 @@ namespace RTC ...@@ -73,8 +72,10 @@ namespace RTC
virtual bool ReceivePacket(RTC::RtpPacket* packet); virtual bool ReceivePacket(RTC::RtpPacket* packet);
virtual void Pause() = 0; virtual void Pause() = 0;
virtual void Resume() = 0; virtual void Resume() = 0;
virtual uint32_t GetBitrate(uint64_t now) = 0;
virtual uint32_t GetBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer) = 0;
virtual uint32_t GetLayerBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer) = 0;
void ResetScore(uint8_t score, bool notify); void ResetScore(uint8_t score, bool notify);
uint32_t GetBitrate(uint64_t now);
uint8_t GetFractionLost() const; uint8_t GetFractionLost() const;
float GetLossPercentage() const; float GetLossPercentage() const;
uint64_t GetMaxPacketMs() const; uint64_t GetMaxPacketMs() const;
...@@ -114,7 +115,6 @@ namespace RTC ...@@ -114,7 +115,6 @@ namespace RTC
size_t repairedPrior{ 0 }; // Packets repaired at last interval. size_t repairedPrior{ 0 }; // Packets repaired at last interval.
size_t retransmittedPrior{ 0 }; // Packets retransmitted at last interval. size_t retransmittedPrior{ 0 }; // Packets retransmitted at last interval.
uint32_t expectedPrior{ 0 }; // Packets expected at last interval. uint32_t expectedPrior{ 0 }; // Packets expected at last interval.
RTC::RtpDataCounter transmissionCounter;
private: private:
// Score related. // Score related.
...@@ -191,11 +191,6 @@ namespace RTC ...@@ -191,11 +191,6 @@ namespace RTC
return this->params.temporalLayers; return this->params.temporalLayers;
} }
inline uint32_t RtpStream::GetBitrate(uint64_t now)
{
return this->transmissionCounter.GetRate(now);
}
inline uint8_t RtpStream::GetFractionLost() const inline uint8_t RtpStream::GetFractionLost() const
{ {
return this->fractionLost; return this->fractionLost;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_RTP_STREAM_RECV_HPP #define MS_RTC_RTP_STREAM_RECV_HPP
#include "RTC/NackGenerator.hpp" #include "RTC/NackGenerator.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
#include <vector> #include <vector>
...@@ -22,6 +23,22 @@ namespace RTC ...@@ -22,6 +23,22 @@ namespace RTC
RTC::RtpStreamRecv* rtpStream, uint8_t& worstRemoteFractionLost) = 0; RTC::RtpStreamRecv* rtpStream, uint8_t& worstRemoteFractionLost) = 0;
}; };
public:
class TransmissionCounter
{
public:
TransmissionCounter(uint8_t spatialLayers, uint8_t temporalLayers);
void Update(RTC::RtpPacket* packet);
uint32_t GetRate(uint64_t now);
uint32_t GetRate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer);
uint32_t GetLayerRate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer);
size_t GetPacketCount() const;
size_t GetBytes() const;
private:
std::vector<std::vector<RTC::RtpDataCounter>> spatialLayerCounters;
};
public: public:
RtpStreamRecv(RTC::RtpStreamRecv::Listener* listener, RTC::RtpStream::Params& params); RtpStreamRecv(RTC::RtpStreamRecv::Listener* listener, RTC::RtpStream::Params& params);
~RtpStreamRecv(); ~RtpStreamRecv();
...@@ -35,6 +52,9 @@ namespace RTC ...@@ -35,6 +52,9 @@ namespace RTC
void RequestKeyFrame(); void RequestKeyFrame();
void Pause() override; void Pause() override;
void Resume() override; void Resume() override;
uint32_t GetBitrate(uint64_t now) override;
uint32_t GetBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer) override;
uint32_t GetLayerBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer) override;
private: private:
void CalculateJitter(uint32_t rtpTimestamp); void CalculateJitter(uint32_t rtpTimestamp);
...@@ -63,7 +83,25 @@ namespace RTC ...@@ -63,7 +83,25 @@ namespace RTC
bool inactive{ false }; // Stream is inactive. bool inactive{ false }; // Stream is inactive.
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
Timer* inactivityCheckPeriodicTimer{ nullptr }; Timer* inactivityCheckPeriodicTimer{ nullptr };
TransmissionCounter transmissionCounter;
}; };
/* Inline instance methods */
inline uint32_t RtpStreamRecv::GetBitrate(uint64_t now)
{
return this->transmissionCounter.GetRate(now);
}
inline uint32_t RtpStreamRecv::GetBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer)
{
return this->transmissionCounter.GetRate(now, spatialLayer, temporalLayer);
}
inline uint32_t RtpStreamRecv::GetLayerBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer)
{
return this->transmissionCounter.GetRate(now, spatialLayer, temporalLayer);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_RTP_STREAM_SEND_HPP #define MS_RTC_RTP_STREAM_SEND_HPP
#include "Utils.hpp" #include "Utils.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include <list> #include <list>
#include <vector> #include <vector>
...@@ -50,6 +51,9 @@ namespace RTC ...@@ -50,6 +51,9 @@ namespace RTC
RTC::RTCP::SdesChunk* GetRtcpSdesChunk(); RTC::RTCP::SdesChunk* GetRtcpSdesChunk();
void Pause() override; void Pause() override;
void Resume() override; void Resume() override;
uint32_t GetBitrate(uint64_t now) override;
uint32_t GetBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer) override;
uint32_t GetLayerBitrate(uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer) override;
private: private:
void StorePacket(RTC::RtpPacket* packet); void StorePacket(RTC::RtpPacket* packet);
...@@ -64,14 +68,22 @@ namespace RTC ...@@ -64,14 +68,22 @@ namespace RTC
std::list<BufferItem> buffer; std::list<BufferItem> buffer;
float rtt{ 0 }; float rtt{ 0 };
uint16_t rtxSeq{ 0 }; uint16_t rtxSeq{ 0 };
RTC::RtpDataCounter transmissionCounter;
}; };
/* Inline instance methods */
inline void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc) inline void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc)
{ {
RTC::RtpStream::SetRtx(payloadType, ssrc); RTC::RtpStream::SetRtx(payloadType, ssrc);
this->rtxSeq = Utils::Crypto::GetRandomUInt(0u, 0xFFFF); this->rtxSeq = Utils::Crypto::GetRandomUInt(0u, 0xFFFF);
} }
inline uint32_t RtpStreamSend::GetBitrate(uint64_t now)
{
return this->transmissionCounter.GetRate(now);
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -50,15 +50,9 @@ namespace RTC ...@@ -50,15 +50,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
uint64_t now = DepLibUV::GetTime();
jsonObject["timestamp"] = now;
jsonObject["ssrc"] = this->params.ssrc; jsonObject["ssrc"] = this->params.ssrc;
jsonObject["kind"] = RtpCodecMimeType::type2String[this->params.mimeType.type]; jsonObject["kind"] = RtpCodecMimeType::type2String[this->params.mimeType.type];
jsonObject["mimeType"] = this->params.mimeType.ToString(); jsonObject["mimeType"] = this->params.mimeType.ToString();
jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount();
jsonObject["byteCount"] = this->transmissionCounter.GetBytes();
jsonObject["bitrate"] = this->transmissionCounter.GetRate(now);
jsonObject["packetsLost"] = this->packetsLost; jsonObject["packetsLost"] = this->packetsLost;
jsonObject["fractionLost"] = this->fractionLost; jsonObject["fractionLost"] = this->fractionLost;
jsonObject["packetsDiscarded"] = this->packetsDiscarded; jsonObject["packetsDiscarded"] = this->packetsDiscarded;
......
...@@ -12,10 +12,120 @@ namespace RTC ...@@ -12,10 +12,120 @@ namespace RTC
static constexpr uint16_t InactivityCheckPeriod{ 250 }; static constexpr uint16_t InactivityCheckPeriod{ 250 };
/* TransmissionCounter methods. */
RtpStreamRecv::TransmissionCounter::TransmissionCounter(uint8_t spatialLayers, uint8_t temporalLayers)
{
// Reserve vectors capacity.
this->spatialLayerCounters = std::vector<std::vector<RTC::RtpDataCounter>>(spatialLayers);
;
for (auto& spatialLayerCounter : this->spatialLayerCounters)
{
spatialLayerCounter = std::vector<RTC::RtpDataCounter>(temporalLayers);
}
}
void RtpStreamRecv::TransmissionCounter::Update(RTC::RtpPacket* packet)
{
auto spatialLayer = packet->GetSpatialLayer();
auto temporalLayer = packet->GetTemporalLayer();
// Sanity check. Do not allow spatial layers higher than defined.
if (spatialLayer > this->spatialLayerCounters.size() - 1)
spatialLayer = this->spatialLayerCounters.size() - 1;
// Sanity check. Do not allow temporal layers higher than defined.
if (temporalLayer > this->spatialLayerCounters[0].size() - 1)
temporalLayer = this->spatialLayerCounters[0].size() - 1;
auto& counter = this->spatialLayerCounters.at(spatialLayer).at(temporalLayer);
counter.Update(packet);
}
uint32_t RtpStreamRecv::TransmissionCounter::GetRate(uint64_t now)
{
uint32_t rate{ 0u };
for (auto& spatialLayerCounter : this->spatialLayerCounters)
{
for (auto& temporalLayerCounter : spatialLayerCounter)
{
rate += temporalLayerCounter.GetRate(now);
}
}
return rate;
}
uint32_t RtpStreamRecv::TransmissionCounter::GetRate(
uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer)
{
uint32_t rate{ 0u };
uint8_t spatialLayerIdx{ 0u };
uint8_t temporalLayerIdx{ 0u };
for (auto& spatialLayerCounter : this->spatialLayerCounters)
{
for (auto& temporalLayerCounter : spatialLayerCounter)
{
rate += temporalLayerCounter.GetRate(now);
if (++temporalLayerIdx > temporalLayer)
break;
}
if (++spatialLayerIdx > spatialLayer)
break;
}
return rate;
}
size_t RtpStreamRecv::TransmissionCounter::GetPacketCount() const
{
size_t packetCount{ 0u };
for (auto& spatialLayerCounter : this->spatialLayerCounters)
{
for (auto& temporalLayerCounter : spatialLayerCounter)
{
packetCount += temporalLayerCounter.GetPacketCount();
}
}
return packetCount;
}
size_t RtpStreamRecv::TransmissionCounter::GetBytes() const
{
size_t bytes{ 0u };
for (auto& spatialLayerCounter : this->spatialLayerCounters)
{
for (auto& temporalLayerCounter : spatialLayerCounter)
{
bytes += temporalLayerCounter.GetBytes();
}
}
return bytes;
}
uint32_t RtpStreamRecv::TransmissionCounter::GetLayerRate(
uint64_t now, uint8_t spatialLayer, uint8_t temporalLayer)
{
auto& counter = this->spatialLayerCounters.at(spatialLayer).at(temporalLayer);
return counter.GetRate(now);
}
/* Instance methods. */ /* Instance methods. */
RtpStreamRecv::RtpStreamRecv(RTC::RtpStreamRecv::Listener* listener, RTC::RtpStream::Params& params) RtpStreamRecv::RtpStreamRecv(RTC::RtpStreamRecv::Listener* listener, RTC::RtpStream::Params& params)
: RTC::RtpStream::RtpStream(listener, params, 10) : RTC::RtpStream::RtpStream(listener, params, 10),
transmissionCounter(params.spatialLayers, params.temporalLayers)
{ {
MS_TRACE(); MS_TRACE();
...@@ -45,10 +155,16 @@ namespace RTC ...@@ -45,10 +155,16 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
uint64_t now = DepLibUV::GetTime();
RTC::RtpStream::FillJsonStats(jsonObject); RTC::RtpStream::FillJsonStats(jsonObject);
jsonObject["timestamp"] = now;
jsonObject["type"] = "inbound-rtp"; jsonObject["type"] = "inbound-rtp";
jsonObject["jitter"] = this->jitter; jsonObject["jitter"] = this->jitter;
jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount();
jsonObject["byteCount"] = this->transmissionCounter.GetBytes();
jsonObject["bitrate"] = this->transmissionCounter.GetRate(now);
} }
bool RtpStreamRecv::ReceivePacket(RTC::RtpPacket* packet) bool RtpStreamRecv::ReceivePacket(RTC::RtpPacket* packet)
......
...@@ -39,10 +39,16 @@ namespace RTC ...@@ -39,10 +39,16 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
uint64_t now = DepLibUV::GetTime();
RTC::RtpStream::FillJsonStats(jsonObject); RTC::RtpStream::FillJsonStats(jsonObject);
jsonObject["timestamp"] = now;
jsonObject["type"] = "outbound-rtp"; jsonObject["type"] = "outbound-rtp";
jsonObject["roundTripTime"] = this->rtt; jsonObject["roundTripTime"] = this->rtt;
jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount();
jsonObject["byteCount"] = this->transmissionCounter.GetBytes();
jsonObject["bitrate"] = this->transmissionCounter.GetRate(now);
} }
bool RtpStreamSend::ReceivePacket(RTC::RtpPacket* packet) bool RtpStreamSend::ReceivePacket(RTC::RtpPacket* packet)
...@@ -209,6 +215,17 @@ namespace RTC ...@@ -209,6 +215,17 @@ namespace RTC
MS_TRACE(); MS_TRACE();
} }
uint32_t RtpStreamSend::GetBitrate(uint64_t /*now*/, uint8_t /*spatialLayer*/, uint8_t /*temporalLayer*/)
{
MS_ABORT("Invalid method call");
}
uint32_t RtpStreamSend::GetLayerBitrate(
uint64_t /*now*/, uint8_t /*spatialLayer*/, uint8_t /*temporalLayer*/)
{
MS_ABORT("Invalid method call");
}
void RtpStreamSend::ClearRetransmissionBuffer() void RtpStreamSend::ClearRetransmissionBuffer()
{ {
MS_TRACE(); MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论