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

RtpStreamRecv: add method 'GetBitrate'

RtpStream::ToJson constness has been removed since
RtpDataCounter::GetRate modifies itself.
上级 02b489cc
......@@ -27,7 +27,7 @@ namespace RTC
explicit RtpStream(RTC::RtpStream::Params& params);
virtual ~RtpStream();
virtual Json::Value ToJson() const = 0;
virtual Json::Value ToJson() = 0;
uint32_t GetSsrc();
virtual bool ReceivePacket(RTC::RtpPacket* packet);
......
......@@ -4,6 +4,7 @@
#include "RTC/NackGenerator.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RtpDataCounter.hpp"
#include "RTC/RtpStream.hpp"
namespace RTC
......@@ -23,13 +24,14 @@ namespace RTC
RtpStreamRecv(Listener* listener, RTC::RtpStream::Params& params);
~RtpStreamRecv() override;
Json::Value ToJson() const override;
Json::Value ToJson() override;
bool ReceivePacket(RTC::RtpPacket* packet) override;
bool ReceiveRtxPacket(RTC::RtpPacket* packet);
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void SetRtx(uint8_t payloadType, uint32_t ssrc);
void RequestFullFrame();
uint32_t GetBitRate();
private:
void CalculateJitter(uint32_t rtpTimestamp);
......@@ -54,11 +56,12 @@ namespace RTC
uint32_t transit{ 0 }; // Relative trans time for prev pkt.
uint32_t jitter{ 0 }; // Estimated jitter.
std::unique_ptr<RTC::NackGenerator> nackGenerator;
// RTX related.
bool hasRtx{ false };
uint8_t rtxPayloadType{ 0 };
uint32_t rtxSsrc{ 0 };
// RTP counters.
RTC::RtpDataCounter receivedCounter;
};
} // namespace RTC
......
......@@ -29,7 +29,7 @@ namespace RTC
RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize);
~RtpStreamSend() override;
Json::Value ToJson() const override;
Json::Value ToJson() override;
bool ReceivePacket(RTC::RtpPacket* packet) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
void RequestRtpRetransmission(
......
......@@ -23,7 +23,7 @@ namespace RTC
MS_TRACE();
}
Json::Value RtpStreamRecv::ToJson() const
Json::Value RtpStreamRecv::ToJson()
{
MS_TRACE();
......@@ -32,6 +32,7 @@ namespace RTC
static const Json::StaticString JsonStringMaxTimestamp{ "maxTimestamp" };
static const Json::StaticString JsonStringTransit{ "transit" };
static const Json::StaticString JsonStringJitter{ "jitter" };
static const Json::StaticString JsonStringBitRate{ "bitrate" };
Json::Value json(Json::objectValue);
......@@ -40,6 +41,7 @@ namespace RTC
json[JsonStringMaxTimestamp] = Json::UInt{ this->maxTimestamp };
json[JsonStringTransit] = Json::UInt{ this->transit };
json[JsonStringJitter] = Json::UInt{ this->jitter };
json[JsonStringBitRate] = Json::UInt{ GetBitRate() };
return json;
}
......@@ -56,6 +58,8 @@ namespace RTC
return false;
}
this->receivedCounter.Update(packet);
// Calculate Jitter.
CalculateJitter(packet->GetTimestamp());
......@@ -214,6 +218,13 @@ namespace RTC
}
}
uint32_t RtpStreamRecv::GetBitRate()
{
uint64_t now = DepLibUV::GetTime();
return this->receivedCounter.GetRate(now);
}
void RtpStreamRecv::CalculateJitter(uint32_t rtpTimestamp)
{
MS_TRACE();
......@@ -242,7 +253,7 @@ namespace RTC
MS_ASSERT(this->params.useNack, "NACK required but not supported");
MS_WARN_TAG(
MS_DEBUG_TAG(
rtx,
"triggering NACK [ssrc:%" PRIu32 ", first seq:%" PRIu16 ", num packets:%zu]",
this->params.ssrc,
......
......@@ -31,7 +31,7 @@ namespace RTC
ClearRetransmissionBuffer();
}
Json::Value RtpStreamSend::ToJson() const
Json::Value RtpStreamSend::ToJson()
{
MS_TRACE();
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论