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

Consumer: add probation

上级 af04dc66
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace RTC namespace RTC
{ {
class Consumer : public RtpStream::Listener class Consumer : public RTC::RtpStream::Listener
{ {
public: public:
Consumer( Consumer(
...@@ -43,7 +43,7 @@ namespace RTC ...@@ -43,7 +43,7 @@ namespace RTC
void Resume(); void Resume();
void SourcePause(); void SourcePause();
void SourceResume(); void SourceResume();
void AddProfile(const RTC::RtpEncodingParameters::Profile profile); void AddProfile(const RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStreamInfo* info);
void RemoveProfile(const RTC::RtpEncodingParameters::Profile profile); void RemoveProfile(const RTC::RtpEncodingParameters::Profile profile);
void SourceRtpParametersUpdated(); void SourceRtpParametersUpdated();
void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile); void SetPreferredProfile(const RTC::RtpEncodingParameters::Profile profile);
...@@ -62,8 +62,9 @@ namespace RTC ...@@ -62,8 +62,9 @@ namespace RTC
void FillSupportedCodecPayloadTypes(); void FillSupportedCodecPayloadTypes();
void CreateRtpStream(RTC::RtpEncodingParameters& encoding); void CreateRtpStream(RTC::RtpEncodingParameters& encoding);
void RetransmitRtpPacket(RTC::RtpPacket* packet); void RetransmitRtpPacket(RTC::RtpPacket* packet);
void RecalculateTargetProfile(); void RecalculateTargetProfile(bool forcePreferred = false);
void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile); void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile);
void MayRunProbation();
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */ /* Pure virtual methods inherited from RTC::RtpStream::Listener. */
public: public:
...@@ -103,9 +104,14 @@ namespace RTC ...@@ -103,9 +104,14 @@ namespace RTC
// RTP profiles. // RTP profiles.
std::set<RTC::RtpEncodingParameters::Profile> profiles; std::set<RTC::RtpEncodingParameters::Profile> profiles;
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*> mapProfileRtpStreamInfo;
RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT }; RTC::RtpEncodingParameters::Profile preferredProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile targetProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT }; RTC::RtpEncodingParameters::Profile targetProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT }; RTC::RtpEncodingParameters::Profile effectiveProfile{ RTC::RtpEncodingParameters::Profile::DEFAULT };
RTC::RtpEncodingParameters::Profile probingProfile{ RTC::RtpEncodingParameters::Profile::NONE };
// RTP probation
bool isProbing{ false };
uint16_t rtpPacketsBeforeProbation{ 0 };
}; };
/* Inline methods. */ /* Inline methods. */
......
...@@ -69,7 +69,8 @@ namespace RTC ...@@ -69,7 +69,8 @@ namespace RTC
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackPsPacket* packet) const;
void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const; void ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) const;
void RequestKeyFrame(bool force = false); void RequestKeyFrame(bool force = false);
const std::set<RTC::RtpEncodingParameters::Profile>& GetHealthyProfiles() const; const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*>& GetHealthyProfiles()
const;
private: private:
void FillHeaderExtensionIds(); void FillHeaderExtensionIds();
...@@ -111,7 +112,7 @@ namespace RTC ...@@ -111,7 +112,7 @@ namespace RTC
std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams; std::map<uint32_t, RTC::RtpStreamRecv*> rtpStreams;
std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams; std::map<uint32_t, RTC::RtpStreamRecv*> mapRtxStreams;
std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> mapRtpStreamProfiles; std::map<RTC::RtpStreamRecv*, std::set<RTC::RtpEncodingParameters::Profile>> mapRtpStreamProfiles;
std::set<RTC::RtpEncodingParameters::Profile> healthyProfiles; std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*> healthyProfiles;
Timer* keyFrameRequestBlockTimer{ nullptr }; Timer* keyFrameRequestBlockTimer{ nullptr };
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
...@@ -163,7 +164,8 @@ namespace RTC ...@@ -163,7 +164,8 @@ namespace RTC
} }
} }
inline const std::set<RTC::RtpEncodingParameters::Profile>& Producer::GetHealthyProfiles() const inline const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*>& Producer::
GetHealthyProfiles() const
{ {
return this->healthyProfiles; return this->healthyProfiles;
} }
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_PRODUCER_LISTENER_HPP #define MS_RTC_PRODUCER_LISTENER_HPP
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpStream.hpp"
namespace RTC namespace RTC
{ {
...@@ -19,7 +20,9 @@ namespace RTC ...@@ -19,7 +20,9 @@ namespace RTC
virtual void OnProducerRtpPacket( virtual void OnProducerRtpPacket(
RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0; RTC::Producer* producer, RTC::RtpPacket* packet, RTC::RtpEncodingParameters::Profile profile) = 0;
virtual void OnProducerProfileEnabled( virtual void OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0; RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStreamInfo* info) = 0;
virtual void OnProducerProfileDisabled( virtual void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0; RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) = 0;
}; };
......
...@@ -72,7 +72,9 @@ namespace RTC ...@@ -72,7 +72,9 @@ namespace RTC
RTC::RtpPacket* packet, RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override; RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileEnabled( void OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override; RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStreamInfo* info) override;
void OnProducerProfileDisabled( void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override; RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
......
...@@ -10,7 +10,18 @@ ...@@ -10,7 +10,18 @@
namespace RTC namespace RTC
{ {
class RtpStream : public Timer::Listener 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 };
};
class RtpStream : public Timer::Listener, public RtpStreamInfo
{ {
public: public:
class Listener class Listener
...@@ -45,6 +56,7 @@ namespace RTC ...@@ -45,6 +56,7 @@ namespace RTC
uint8_t GetPayloadType(); uint8_t GetPayloadType();
const RTC::RtpCodecMimeType& GetMimeType() const; const RTC::RtpCodecMimeType& GetMimeType() const;
bool IsHealthy(); bool IsHealthy();
void ResetHealthCheckTimer();
protected: protected:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
...@@ -76,10 +88,7 @@ namespace RTC ...@@ -76,10 +88,7 @@ namespace RTC
uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen. uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen.
Timer* healthCheckTimer{ nullptr }; Timer* healthCheckTimer{ nullptr };
bool healthy{ true }; bool healthy{ true };
uint32_t totalLost{ 0 }; bool notifyHealth{ true };
uint8_t fractionLost{ 0 };
uint32_t jitter{ 0 };
uint32_t rtt{ 0 };
// RTP counters. // RTP counters.
RTC::RtpDataCounter counter; RTC::RtpDataCounter counter;
}; };
......
...@@ -26,7 +26,7 @@ namespace RTC ...@@ -26,7 +26,7 @@ namespace RTC
}; };
public: public:
RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize); RtpStreamSend(RTC::RtpStream::Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize);
~RtpStreamSend() override; ~RtpStreamSend() override;
bool ReceivePacket(RTC::RtpPacket* packet) override; bool ReceivePacket(RTC::RtpPacket* packet) override;
...@@ -47,6 +47,8 @@ namespace RTC ...@@ -47,6 +47,8 @@ namespace RTC
void CheckHealth() override; void CheckHealth() override;
private: private:
// Passed by argument.
RTC::RtpStream::Listener* listener{ nullptr };
std::vector<StorageItem> storage; std::vector<StorageItem> storage;
using Buffer = std::list<BufferItem>; using Buffer = std::list<BufferItem>;
Buffer buffer; Buffer buffer;
......
...@@ -96,7 +96,9 @@ namespace RTC ...@@ -96,7 +96,9 @@ namespace RTC
RTC::RtpPacket* packet, RTC::RtpPacket* packet,
RTC::RtpEncodingParameters::Profile profile) override; RTC::RtpEncodingParameters::Profile profile) override;
void OnProducerProfileEnabled( void OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override; RTC::Producer* producer,
RTC::RtpEncodingParameters::Profile profile,
const RTC::RtpStreamInfo* info) override;
void OnProducerProfileDisabled( void OnProducerProfileDisabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override; RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) override;
......
...@@ -636,14 +636,16 @@ namespace RTC ...@@ -636,14 +636,16 @@ namespace RTC
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT) if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break; break;
MS_ASSERT(
this->healthyProfiles.find(profile) == this->healthyProfiles.end(),
"profile already in headltyProfiles set");
// Add the profile to the healthy profiles set. // Add the profile to the healthy profiles set.
const auto& result = this->healthyProfiles.insert(profile); this->healthyProfiles[profile] = rtpStream;
bool profileExisted = !result.second;
MS_ASSERT(!profileExisted, "profile already in headltyProfiles set");
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
listener->OnProducerProfileEnabled(this, profile); listener->OnProducerProfileEnabled(this, profile, rtpStream);
} }
} }
} }
...@@ -659,10 +661,12 @@ namespace RTC ...@@ -659,10 +661,12 @@ namespace RTC
if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT) if (profile == RTC::RtpEncodingParameters::Profile::DEFAULT)
break; break;
MS_ASSERT(
this->healthyProfiles.find(profile) != this->healthyProfiles.end(),
"profile already in headltyProfiles set");
// Remove the profile from the healthy profiles set. // Remove the profile from the healthy profiles set.
auto result = this->healthyProfiles.erase(profile); this->healthyProfiles.erase(profile);
bool profileExisted = (result == 1);
MS_ASSERT(profileExisted, "profile not present in headltyProfiles set");
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/WebRtcTransport.hpp" #include "RTC/WebRtcTransport.hpp"
#include <cmath> // std::lround() #include <cmath> // std::lround()
#include <map>
#include <set> #include <set>
#include <string> #include <string>
...@@ -511,14 +512,15 @@ namespace RTC ...@@ -511,14 +512,15 @@ namespace RTC
// Add us as listener. // Add us as listener.
consumer->AddListener(this); consumer->AddListener(this);
auto profiles = producer->GetHealthyProfiles(); auto healthyProfiles = producer->GetHealthyProfiles();
std::set<RtpEncodingParameters::Profile>::reverse_iterator it; std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStreamInfo*>::reverse_iterator it;
for (it = profiles.rbegin(); it != profiles.rend(); ++it) for (it = healthyProfiles.rbegin(); it != healthyProfiles.rend(); ++it)
{ {
auto profile = *it; auto profile = it->first;
auto info = it->second;
consumer->AddProfile(profile); consumer->AddProfile(profile, info);
} }
// Insert into the maps. // Insert into the maps.
...@@ -1530,7 +1532,7 @@ namespace RTC ...@@ -1530,7 +1532,7 @@ namespace RTC
} }
void Router::OnProducerProfileEnabled( void Router::OnProducerProfileEnabled(
RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile) RTC::Producer* producer, RTC::RtpEncodingParameters::Profile profile, const RTC::RtpStreamInfo* info)
{ {
MS_TRACE(); MS_TRACE();
...@@ -1542,7 +1544,7 @@ namespace RTC ...@@ -1542,7 +1544,7 @@ namespace RTC
for (auto* consumer : consumers) for (auto* consumer : consumers)
{ {
consumer->AddProfile(profile); consumer->AddProfile(profile, info);
} }
} }
......
...@@ -49,6 +49,7 @@ namespace RTC ...@@ -49,6 +49,7 @@ namespace RTC
static const Json::StaticString JsonStringRtt{ "rtt" }; static const Json::StaticString JsonStringRtt{ "rtt" };
static const Json::StaticString JsonStringFractionLost{ "fractionLost" }; static const Json::StaticString JsonStringFractionLost{ "fractionLost" };
static const Json::StaticString JsonStringTotalLost{ "totalLost" }; static const Json::StaticString JsonStringTotalLost{ "totalLost" };
static const Json::StaticString JsonStringHealthy{ "healthy" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -62,6 +63,7 @@ namespace RTC ...@@ -62,6 +63,7 @@ namespace RTC
json[JsonStringRtt] = Json::UInt{ this->rtt }; json[JsonStringRtt] = Json::UInt{ this->rtt };
json[JsonStringFractionLost] = Json::UInt{ this->fractionLost }; json[JsonStringFractionLost] = Json::UInt{ this->fractionLost };
json[JsonStringTotalLost] = Json::UInt{ this->totalLost }; json[JsonStringTotalLost] = Json::UInt{ this->totalLost };
json[JsonStringHealthy] = this->healthy ? "true" : "false";
return json; return json;
} }
...@@ -115,6 +117,13 @@ namespace RTC ...@@ -115,6 +117,13 @@ namespace RTC
return this->counter.GetRate(now); return this->counter.GetRate(now);
} }
void RtpStream::ResetHealthCheckTimer()
{
// Notify about next health status.
this->notifyHealth = true;
this->healthCheckTimer->Start(HealthCheckPeriod, HealthCheckPeriod);
}
void RtpStream::InitSeq(uint16_t seq) void RtpStream::InitSeq(uint16_t seq)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -15,11 +15,13 @@ namespace RTC ...@@ -15,11 +15,13 @@ namespace RTC
// TODO: This must be tunned. // TODO: This must be tunned.
static constexpr uint32_t MaxRetransmissionDelay{ 1000 }; static constexpr uint32_t MaxRetransmissionDelay{ 1000 };
static constexpr uint32_t DefaultRtt{ 100 }; static constexpr uint32_t DefaultRtt{ 100 };
static constexpr uint8_t MaxHealthLossPercentage{ 20 };
/* Instance methods. */ /* Instance methods. */
RtpStreamSend::RtpStreamSend(RTC::RtpStream::Params& params, size_t bufferSize) RtpStreamSend::RtpStreamSend(
: RtpStream::RtpStream(params), storage(bufferSize) RTC::RtpStream::Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize)
: RtpStream::RtpStream(params), listener(listener), storage(bufferSize)
{ {
MS_TRACE(); MS_TRACE();
} }
...@@ -416,6 +418,25 @@ namespace RTC ...@@ -416,6 +418,25 @@ namespace RTC
void RtpStreamSend::CheckHealth() void RtpStreamSend::CheckHealth()
{ {
MS_TRACE(); MS_TRACE();
uint16_t currentLossPercentage = this->fractionLost * 100 / 256;
if (currentLossPercentage >= MaxHealthLossPercentage)
{
MS_DEBUG_TAG(rtp, "last period loss percentage: %" PRIu16, currentLossPercentage);
if (this->notifyHealth || this->healthy)
{
this->healthy = false;
this->listener->OnRtpStreamUnhealthy(this);
}
}
else if (this->notifyHealth || !this->healthy)
{
this->healthy = true;
this->listener->OnRtpStreamHealthy(this);
}
this->notifyHealth = false;
} }
void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc) void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc)
......
...@@ -542,7 +542,9 @@ namespace RTC ...@@ -542,7 +542,9 @@ namespace RTC
} }
void Transport::OnProducerProfileEnabled( void Transport::OnProducerProfileEnabled(
RTC::Producer* /*producer*/, RTC::RtpEncodingParameters::Profile /*profile*/) RTC::Producer* /*producer*/,
RTC::RtpEncodingParameters::Profile /*profile*/,
const RTC::RtpStreamInfo* /*info*/)
{ {
// Do nothing. // Do nothing.
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论