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

Fix naming on RtpStreamSend and RtpStreamRecv check methods

上级 66063670
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
namespace RTC namespace RTC
{ {
class Consumer : public RTC::RtpStream::Listener class Consumer : public RTC::RtpStreamSend::Listener
{ {
public: public:
Consumer( Consumer(
...@@ -71,9 +71,8 @@ namespace RTC ...@@ -71,9 +71,8 @@ namespace RTC
void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile); void SetEffectiveProfile(RTC::RtpEncodingParameters::Profile profile);
void MayRunProbation(); void MayRunProbation();
/* Pure virtual methods inherited from RTC::RtpStream::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamSend::Listener. */
public: public:
void OnRtpStreamInactivity(RTC::RtpStream* rtpStream) override;
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;
......
...@@ -72,7 +72,7 @@ namespace RTC ...@@ -72,7 +72,7 @@ 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::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>& GetHealthyProfiles() const; const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>& GetActiveProfiles() const;
private: private:
void FillHeaderExtensionIds(); void FillHeaderExtensionIds();
...@@ -82,17 +82,16 @@ namespace RTC ...@@ -82,17 +82,16 @@ namespace RTC
void ClearRtpStreams(); void ClearRtpStreams();
void ApplyRtpMapping(RTC::RtpPacket* packet) const; void ApplyRtpMapping(RTC::RtpPacket* packet) const;
RTC::RtpEncodingParameters::Profile GetProfile(RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet); RTC::RtpEncodingParameters::Profile GetProfile(RTC::RtpStreamRecv* rtpStream, RTC::RtpPacket* packet);
void AddHealthyProfiles(RTC::RtpStreamRecv* rtpStream); void AddActiveProfiles(RTC::RtpStreamRecv* rtpStream);
void RemoveHealthyProfiles(RTC::RtpStreamRecv* rtpStream); void RemoveActiveProfiles(RTC::RtpStreamRecv* rtpStream);
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
void OnRtpStreamRecvNackRequired( void OnRtpStreamRecvNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override; RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) override;
void OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream) override; void OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream) override;
void OnRtpStreamInactivity(RTC::RtpStream* rtpStream) override; void OnRtpStreamInactive(RTC::RtpStream* rtpStream) override;
void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) override; void OnRtpStreamActive(RTC::RtpStream* rtpStream) override;
void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) override;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -114,7 +113,7 @@ namespace RTC ...@@ -114,7 +113,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::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*> healthyProfiles; std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*> activeProfiles;
Timer* keyFrameRequestBlockTimer{ nullptr }; Timer* keyFrameRequestBlockTimer{ nullptr };
// Others. // Others.
std::vector<RtpEncodingParameters> outputEncodings; std::vector<RtpEncodingParameters> outputEncodings;
...@@ -179,9 +178,9 @@ namespace RTC ...@@ -179,9 +178,9 @@ namespace RTC
} }
inline const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>& Producer:: inline const std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>& Producer::
GetHealthyProfiles() const GetActiveProfiles() const
{ {
return this->healthyProfiles; return this->activeProfiles;
} }
} // namespace RTC } // namespace RTC
......
...@@ -12,15 +12,6 @@ namespace RTC ...@@ -12,15 +12,6 @@ namespace RTC
{ {
class RtpStream : public Timer::Listener class RtpStream : public Timer::Listener
{ {
public:
class Listener
{
public:
virtual void OnRtpStreamInactivity(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) = 0;
};
public: public:
struct Params struct Params
{ {
...@@ -35,7 +26,7 @@ namespace RTC ...@@ -35,7 +26,7 @@ namespace RTC
}; };
public: public:
static constexpr uint16_t HealthCheckPeriod{ 1000 }; static constexpr uint16_t StatusCheckPeriod{ 1000 };
public: public:
explicit RtpStream(RTC::RtpStream::Params& params); explicit RtpStream(RTC::RtpStream::Params& params);
...@@ -49,9 +40,7 @@ namespace RTC ...@@ -49,9 +40,7 @@ namespace RTC
uint8_t GetPayloadType() const; uint8_t GetPayloadType() const;
const RTC::RtpCodecMimeType& GetMimeType() const; const RTC::RtpCodecMimeType& GetMimeType() const;
float GetLossPercentage() const; float GetLossPercentage() const;
bool IsHealthy() const; void ResetStatusCheckTimer(uint16_t timeout = StatusCheckPeriod);
void SetUnhealthy();
void ResetHealthCheckTimer(uint16_t timeout = HealthCheckPeriod);
protected: protected:
bool UpdateSeq(RTC::RtpPacket* packet); bool UpdateSeq(RTC::RtpPacket* packet);
...@@ -61,7 +50,7 @@ namespace RTC ...@@ -61,7 +50,7 @@ namespace RTC
/* Pure virtual methods that must be implemented by the subclass. */ /* Pure virtual methods that must be implemented by the subclass. */
protected: protected:
virtual void CheckHealth() = 0; virtual void CheckStatus() = 0;
/* Pure virtual methods inherited from Timer::Listener. */ /* Pure virtual methods inherited from Timer::Listener. */
public: public:
...@@ -95,9 +84,8 @@ namespace RTC ...@@ -95,9 +84,8 @@ namespace RTC
// Others. // Others.
uint32_t maxPacketTs{ 0 }; // Highest timestamp seen. uint32_t maxPacketTs{ 0 }; // Highest timestamp seen.
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* statusCheckTimer{ nullptr };
bool healthy{ true }; bool notifyStatus{ true };
bool notifyHealth{ true };
private: private:
std::string rtpStreamId{}; std::string rtpStreamId{};
...@@ -124,16 +112,6 @@ namespace RTC ...@@ -124,16 +112,6 @@ namespace RTC
{ {
return static_cast<float>(this->fractionLost) * 100 / 256; return static_cast<float>(this->fractionLost) * 100 / 256;
} }
inline bool RtpStream::IsHealthy() const
{
return this->healthy;
}
inline void RtpStream::SetUnhealthy()
{
this->healthy = false;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -11,12 +11,14 @@ namespace RTC ...@@ -11,12 +11,14 @@ namespace RTC
class RtpStreamRecv : public RtpStream, public RTC::NackGenerator::Listener class RtpStreamRecv : public RtpStream, public RTC::NackGenerator::Listener
{ {
public: public:
class Listener : public RtpStream::Listener class Listener
{ {
public: public:
virtual void OnRtpStreamRecvNackRequired( virtual void OnRtpStreamRecvNackRequired(
RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0; RTC::RtpStreamRecv* rtpStream, const std::vector<uint16_t>& seqNumbers) = 0;
virtual void OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream) = 0; virtual void OnRtpStreamRecvPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
virtual void OnRtpStreamInactive(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamActive(RTC::RtpStream* rtpStream) = 0;
}; };
public: public:
...@@ -30,13 +32,14 @@ namespace RTC ...@@ -30,13 +32,14 @@ namespace RTC
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void SetRtx(uint8_t payloadType, uint32_t ssrc); void SetRtx(uint8_t payloadType, uint32_t ssrc);
void RequestKeyFrame(); void RequestKeyFrame();
bool IsActive() const;
private: private:
void CalculateJitter(uint32_t rtpTimestamp); void CalculateJitter(uint32_t rtpTimestamp);
/* Pure virtual methods inherited from RtpStream. */ /* Pure virtual methods inherited from RtpStream. */
protected: protected:
virtual void CheckHealth() override; virtual void CheckStatus() override;
/* Pure virtual methods inherited from RTC::NackGenerator. */ /* Pure virtual methods inherited from RTC::NackGenerator. */
protected: protected:
...@@ -61,7 +64,14 @@ namespace RTC ...@@ -61,7 +64,14 @@ namespace RTC
uint32_t rtxSsrc{ 0 }; uint32_t rtxSsrc{ 0 };
// Stats. // Stats.
uint32_t jitter{ 0 }; uint32_t jitter{ 0 };
// Others.
bool active { true };
}; };
inline bool RtpStreamRecv::IsActive() const
{
return this->active;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -11,6 +11,14 @@ namespace RTC ...@@ -11,6 +11,14 @@ namespace RTC
{ {
class RtpStreamSend : public RtpStream class RtpStreamSend : public RtpStream
{ {
public:
class Listener
{
public:
virtual void OnRtpStreamHealthy(RTC::RtpStream* rtpStream) = 0;
virtual void OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) = 0;
};
private: private:
struct StorageItem struct StorageItem
{ {
...@@ -26,7 +34,7 @@ namespace RTC ...@@ -26,7 +34,7 @@ namespace RTC
}; };
public: public:
RtpStreamSend(RTC::RtpStream::Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize); RtpStreamSend(Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize);
~RtpStreamSend() override; ~RtpStreamSend() override;
Json::Value GetStats() override; Json::Value GetStats() override;
...@@ -39,22 +47,25 @@ namespace RTC ...@@ -39,22 +47,25 @@ namespace RTC
bool HasRtx() const; bool HasRtx() const;
void RtxEncode(RtpPacket* packet); void RtxEncode(RtpPacket* packet);
void ClearRetransmissionBuffer(); void ClearRetransmissionBuffer();
bool IsHealthy() const;
private: private:
void StorePacket(RTC::RtpPacket* packet); void StorePacket(RTC::RtpPacket* packet);
/* Pure virtual methods inherited from RtpStream. */ /* Pure virtual methods inherited from RtpStream. */
protected: protected:
void CheckHealth() override; void CheckStatus() override;
private: private:
// Passed by argument. // Passed by argument.
RTC::RtpStream::Listener* listener{ nullptr }; 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;
// Stats. // Stats.
uint32_t rtt{ 0 }; uint32_t rtt{ 0 };
// Others.
bool healthy{ true };
private: private:
// Retransmittion related. // Retransmittion related.
...@@ -68,6 +79,11 @@ namespace RTC ...@@ -68,6 +79,11 @@ namespace RTC
{ {
return this->hasRtx; return this->hasRtx;
} }
inline bool RtpStreamSend::IsHealthy() const
{
return this->healthy;
}
} // namespace RTC } // namespace RTC
#endif #endif
...@@ -307,7 +307,7 @@ namespace RTC ...@@ -307,7 +307,7 @@ namespace RTC
this->probingProfile = RtpEncodingParameters::Profile::NONE; this->probingProfile = RtpEncodingParameters::Profile::NONE;
// Reset the health check timer so this probation doesn't affect the effective profile. // Reset the health check timer so this probation doesn't affect the effective profile.
this->rtpStream->ResetHealthCheckTimer(); this->rtpStream->ResetStatusCheckTimer();
return; return;
} }
...@@ -699,13 +699,6 @@ namespace RTC ...@@ -699,13 +699,6 @@ namespace RTC
} }
} }
void Consumer::OnRtpStreamInactivity(RtpStream* rtpStream)
{
MS_TRACE();
OnRtpStreamUnhealthy(rtpStream);
}
void Consumer::OnRtpStreamHealthy(RtpStream* rtpStream) void Consumer::OnRtpStreamHealthy(RtpStream* rtpStream)
{ {
MS_TRACE(); MS_TRACE();
...@@ -789,7 +782,7 @@ namespace RTC ...@@ -789,7 +782,7 @@ namespace RTC
RequestKeyFrame(); RequestKeyFrame();
// We want to be notified about this new profile's health. // We want to be notified about this new profile's health.
this->rtpStream->ResetHealthCheckTimer(); this->rtpStream->ResetStatusCheckTimer();
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
...@@ -1011,7 +1004,7 @@ namespace RTC ...@@ -1011,7 +1004,7 @@ namespace RTC
{ {
this->isProbing = true; this->isProbing = true;
this->probingProfile = newTargetProfile; this->probingProfile = newTargetProfile;
this->rtpStream->ResetHealthCheckTimer(); this->rtpStream->ResetStatusCheckTimer();
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtp, rtp,
......
...@@ -543,8 +543,8 @@ namespace RTC ...@@ -543,8 +543,8 @@ namespace RTC
// Add the stream to the profiles map. // Add the stream to the profiles map.
this->mapRtpStreamProfiles[rtpStream].insert(profile); this->mapRtpStreamProfiles[rtpStream].insert(profile);
// Add new profile/s into healthyProfiles and notify the listener. // Add new profile/s into activeProfiles and notify the listener.
AddHealthyProfiles(rtpStream); AddActiveProfiles(rtpStream);
// Request a key frame since we may have lost the first packets of this stream. // Request a key frame since we may have lost the first packets of this stream.
RequestKeyFrame(true); RequestKeyFrame(true);
...@@ -554,8 +554,8 @@ namespace RTC ...@@ -554,8 +554,8 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// Remove the profiles related to this stream from healthyProfiles and notify the listener. // Remove the profiles related to this stream from activeProfiles and notify the listener.
RemoveHealthyProfiles(rtpStream); RemoveActiveProfiles(rtpStream);
this->rtpStreams.erase(rtpStream->GetSsrc()); this->rtpStreams.erase(rtpStream->GetSsrc());
...@@ -609,7 +609,7 @@ namespace RTC ...@@ -609,7 +609,7 @@ namespace RTC
this->rtpStreams.clear(); this->rtpStreams.clear();
this->mapRtxStreams.clear(); this->mapRtxStreams.clear();
this->mapRtpStreamProfiles.clear(); this->mapRtpStreamProfiles.clear();
this->healthyProfiles.clear(); this->activeProfiles.clear();
} }
void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const void Producer::ApplyRtpMapping(RTC::RtpPacket* packet) const
...@@ -662,7 +662,7 @@ namespace RTC ...@@ -662,7 +662,7 @@ namespace RTC
MS_THROW_ERROR("unknown RTP packet received [ssrc:%" PRIu32 "]", packet->GetSsrc()); MS_THROW_ERROR("unknown RTP packet received [ssrc:%" PRIu32 "]", packet->GetSsrc());
} }
void Producer::AddHealthyProfiles(RTC::RtpStreamRecv* rtpStream) void Producer::AddActiveProfiles(RTC::RtpStreamRecv* rtpStream)
{ {
auto& profiles = this->mapRtpStreamProfiles[rtpStream]; auto& profiles = this->mapRtpStreamProfiles[rtpStream];
...@@ -670,11 +670,11 @@ namespace RTC ...@@ -670,11 +670,11 @@ namespace RTC
for (auto& profile : profiles) for (auto& profile : profiles)
{ {
MS_ASSERT( MS_ASSERT(
this->healthyProfiles.find(profile) == this->healthyProfiles.end(), this->activeProfiles.find(profile) == this->activeProfiles.end(),
"profile already in headltyProfiles set"); "profile already in headltyProfiles set");
// Add the profile to the healthy profiles set. // Add the profile to the active profiles map.
this->healthyProfiles[profile] = rtpStream; this->activeProfiles[profile] = rtpStream;
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
...@@ -683,7 +683,7 @@ namespace RTC ...@@ -683,7 +683,7 @@ namespace RTC
} }
} }
void Producer::RemoveHealthyProfiles(RTC::RtpStreamRecv* rtpStream) void Producer::RemoveActiveProfiles(RTC::RtpStreamRecv* rtpStream)
{ {
auto& profiles = this->mapRtpStreamProfiles[rtpStream]; auto& profiles = this->mapRtpStreamProfiles[rtpStream];
...@@ -691,11 +691,11 @@ namespace RTC ...@@ -691,11 +691,11 @@ namespace RTC
for (auto& profile : profiles) for (auto& profile : profiles)
{ {
MS_ASSERT( MS_ASSERT(
this->healthyProfiles.find(profile) != this->healthyProfiles.end(), this->activeProfiles.find(profile) != this->activeProfiles.end(),
"profile not in headltyProfiles"); "profile not in headltyProfiles");
// Remove the profile from the healthy profiles set. // Remove the profile from the active profiles map.
this->healthyProfiles.erase(profile); this->activeProfiles.erase(profile);
for (auto& listener : this->listeners) for (auto& listener : this->listeners)
{ {
...@@ -772,7 +772,7 @@ namespace RTC ...@@ -772,7 +772,7 @@ namespace RTC
rtpStream->pliCount++; rtpStream->pliCount++;
} }
void Producer::OnRtpStreamInactivity(RTC::RtpStream* rtpStream) void Producer::OnRtpStreamInactive(RTC::RtpStream* rtpStream)
{ {
MS_TRACE(); MS_TRACE();
...@@ -782,18 +782,18 @@ namespace RTC ...@@ -782,18 +782,18 @@ namespace RTC
this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(), this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in mapRtpStreamProfiles"); "stream not present in mapRtpStreamProfiles");
// Single healthy profile present. Ignore. // Single active profile present. Ignore.
if (this->healthyProfiles.size() == 1) if (this->activeProfiles.size() == 1)
return; return;
// Simulcast. Check whether any RTP is being received at all. // Simulcast. Check whether any RTP is being received at all.
uint32_t totalBitrate = 0; uint32_t totalBitrate = 0;
uint64_t now = DepLibUV::GetTime(); uint64_t now = DepLibUV::GetTime();
for (auto it : this->healthyProfiles) for (auto it : this->activeProfiles)
{ {
auto healthyRtpStream = it.second; auto activeRtpStream = it.second;
auto ssrc = healthyRtpStream->GetSsrc(); auto ssrc = activeRtpStream->GetSsrc();
totalBitrate += this->rtpStreams[ssrc]->GetRate(now); totalBitrate += this->rtpStreams[ssrc]->GetRate(now);
} }
...@@ -802,23 +802,22 @@ namespace RTC ...@@ -802,23 +802,22 @@ namespace RTC
if (totalBitrate == 0) if (totalBitrate == 0)
return; return;
// Simulcast. Remove the stream from healthy profiles. // Simulcast. Remove the stream from active profiles.
MS_DEBUG_TAG(rtp, "rtp inactivity detected [ssrc:%" PRIu32, rtpStream->GetSsrc()); MS_DEBUG_TAG(rtp, "rtp inactivity detected [ssrc:%" PRIu32, rtpStream->GetSsrc());
rtpStream->SetUnhealthy(); RemoveActiveProfiles(rtpStreamRecv);
RemoveHealthyProfiles(rtpStreamRecv);
// Reset health check timer on every healthy stream. // Reset stream check timer on every active stream.
for (auto it : this->healthyProfiles) for (auto it : this->activeProfiles)
{ {
auto healthyRtpStream = it.second; auto activeRtpStream = it.second;
auto ssrc = healthyRtpStream->GetSsrc(); auto ssrc = activeRtpStream->GetSsrc();
this->rtpStreams[ssrc]->ResetHealthCheckTimer(RTC::RtpStream::HealthCheckPeriod * 2); this->rtpStreams[ssrc]->ResetStatusCheckTimer(RTC::RtpStream::StatusCheckPeriod * 2);
} }
} }
void Producer::OnRtpStreamHealthy(RTC::RtpStream* rtpStream) void Producer::OnRtpStreamActive(RTC::RtpStream* rtpStream)
{ {
MS_TRACE(); MS_TRACE();
...@@ -828,26 +827,22 @@ namespace RTC ...@@ -828,26 +827,22 @@ namespace RTC
this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(), this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in mapRtpStreamProfiles"); "stream not present in mapRtpStreamProfiles");
MS_DEBUG_TAG(rtp, "stream is now healthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc()); MS_DEBUG_TAG(rtp, "stream is now active [ssrc:%" PRIu32 "]", rtpStream->GetSsrc());
// Add the profiles related to this stream into healthyProfiles and notify the listener. // Check whether the stream is active.
AddHealthyProfiles(rtpStreamRecv); const RtpStream* activeRtpStream = nullptr;
}
void Producer::OnRtpStreamUnhealthy(RTC::RtpStream* rtpStream) for (auto it : this->activeProfiles)
{ {
MS_TRACE(); activeRtpStream = it.second;
auto rtpStreamRecv = dynamic_cast<RtpStreamRecv*>(rtpStream);
MS_ASSERT(
this->mapRtpStreamProfiles.find(rtpStreamRecv) != this->mapRtpStreamProfiles.end(),
"stream not present in mapRtpStreamProfiles");
MS_DEBUG_TAG(rtp, "stream is now unhealthy [ssrc:%" PRIu32 "]", rtpStream->GetSsrc()); if (activeRtpStream != nullptr)
break;
}
// Remove the profiles related to this stream from healthyProfiles and notify the listener. // Add the profiles related to this stream into activeProfiles and notify the listener.
RemoveHealthyProfiles(rtpStreamRecv); if (!activeRtpStream)
AddActiveProfiles(rtpStreamRecv);
} }
inline void Producer::OnTimer(Timer* timer) inline void Producer::OnTimer(Timer* timer)
......
...@@ -514,10 +514,10 @@ namespace RTC ...@@ -514,10 +514,10 @@ namespace RTC
// Add us as listener. // Add us as listener.
consumer->AddListener(this); consumer->AddListener(this);
auto healthyProfiles = producer->GetHealthyProfiles(); auto activeProfiles = producer->GetActiveProfiles();
std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>::reverse_iterator it; std::map<RTC::RtpEncodingParameters::Profile, const RTC::RtpStream*>::reverse_iterator it;
for (it = healthyProfiles.rbegin(); it != healthyProfiles.rend(); ++it) for (it = activeProfiles.rbegin(); it != activeProfiles.rend(); ++it)
{ {
auto profile = it->first; auto profile = it->first;
auto stats = it->second; auto stats = it->second;
......
...@@ -24,19 +24,19 @@ namespace RTC ...@@ -24,19 +24,19 @@ namespace RTC
// Generate a random rtpStreamId. // Generate a random rtpStreamId.
this->rtpStreamId = Utils::Crypto::GetRandomString(16); this->rtpStreamId = Utils::Crypto::GetRandomString(16);
// Set the health check timer. // Set the status check timer.
this->healthCheckTimer = new Timer(this); this->statusCheckTimer = new Timer(this);
// Run the timer. // Run the timer.
this->healthCheckTimer->Start(HealthCheckPeriod, HealthCheckPeriod); this->statusCheckTimer->Start(StatusCheckPeriod, StatusCheckPeriod);
} }
RtpStream::~RtpStream() RtpStream::~RtpStream()
{ {
MS_TRACE(); MS_TRACE();
// Close the health check timer. // Close the status check timer.
this->healthCheckTimer->Destroy(); this->statusCheckTimer->Destroy();
} }
Json::Value RtpStream::ToJson() Json::Value RtpStream::ToJson()
...@@ -61,7 +61,6 @@ namespace RTC ...@@ -61,7 +61,6 @@ namespace RTC
static const Json::StaticString JsonStringSsrc{ "ssrc" }; static const Json::StaticString JsonStringSsrc{ "ssrc" };
static const Json::StaticString JsonStringMediaType{ "mediaType" }; static const Json::StaticString JsonStringMediaType{ "mediaType" };
static const Json::StaticString JsonStringMimeType{ "mimeType" }; static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringHealthy{ "healthy" };
static const Json::StaticString JsonStringPacketCount{ "packetCount" }; static const Json::StaticString JsonStringPacketCount{ "packetCount" };
static const Json::StaticString JsonStringByteCount{ "byteCount" }; static const Json::StaticString JsonStringByteCount{ "byteCount" };
static const Json::StaticString JsonStringBitRate{ "bitrate" }; static const Json::StaticString JsonStringBitRate{ "bitrate" };
...@@ -82,7 +81,6 @@ namespace RTC ...@@ -82,7 +81,6 @@ namespace RTC
json[JsonStringSsrc] = Json::UInt{ this->params.ssrc }; json[JsonStringSsrc] = Json::UInt{ this->params.ssrc };
json[JsonStringMediaType] = RtpCodecMimeType::type2String[this->params.mimeType.type]; json[JsonStringMediaType] = RtpCodecMimeType::type2String[this->params.mimeType.type];
json[JsonStringMimeType] = this->params.mimeType.ToString(); json[JsonStringMimeType] = this->params.mimeType.ToString();
json[JsonStringHealthy] = this->healthy ? "true" : "false";
json[JsonStringPacketCount] = static_cast<Json::UInt>(this->transmissionCounter.GetPacketCount()); json[JsonStringPacketCount] = static_cast<Json::UInt>(this->transmissionCounter.GetPacketCount());
json[JsonStringByteCount] = static_cast<Json::UInt>(this->transmissionCounter.GetBytes()); json[JsonStringByteCount] = static_cast<Json::UInt>(this->transmissionCounter.GetBytes());
json[JsonStringBitRate] = Json::UInt{ this->transmissionCounter.GetRate(now) }; json[JsonStringBitRate] = Json::UInt{ this->transmissionCounter.GetRate(now) };
...@@ -143,11 +141,11 @@ namespace RTC ...@@ -143,11 +141,11 @@ namespace RTC
return this->transmissionCounter.GetRate(now); return this->transmissionCounter.GetRate(now);
} }
void RtpStream::ResetHealthCheckTimer(uint16_t timeout) void RtpStream::ResetStatusCheckTimer(uint16_t timeout)
{ {
// Notify about next health status. // Notify about status on next check.
this->notifyHealth = true; this->notifyStatus = true;
this->healthCheckTimer->Start(timeout, HealthCheckPeriod); this->statusCheckTimer->Start(timeout, StatusCheckPeriod);
} }
void RtpStream::InitSeq(uint16_t seq) void RtpStream::InitSeq(uint16_t seq)
...@@ -253,9 +251,9 @@ namespace RTC ...@@ -253,9 +251,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (timer == this->healthCheckTimer) if (timer == this->statusCheckTimer)
{ {
this->CheckHealth(); this->CheckStatus();
} }
} }
} // namespace RTC } // namespace RTC
...@@ -227,20 +227,24 @@ namespace RTC ...@@ -227,20 +227,24 @@ namespace RTC
this->jitter += (1. / 16.) * (static_cast<double>(d) - this->jitter); this->jitter += (1. / 16.) * (static_cast<double>(d) - this->jitter);
} }
void RtpStreamRecv::CheckHealth() void RtpStreamRecv::CheckStatus()
{ {
MS_TRACE(); MS_TRACE();
auto now = DepLibUV::GetTime(); auto now = DepLibUV::GetTime();
if (this->transmissionCounter.GetRate(now) == 0 && this->healthy) if (this->transmissionCounter.GetRate(now) == 0)
{ {
this->listener->OnRtpStreamInactivity(this); if (this->active)
{
this->active = false;
this->listener->OnRtpStreamInactive(this);
}
} }
else if (!this->healthy) else if (!this->active)
{ {
this->healthy = true; this->active = true;
this->listener->OnRtpStreamHealthy(this); this->listener->OnRtpStreamActive(this);
} }
} }
......
...@@ -20,7 +20,7 @@ namespace RTC ...@@ -20,7 +20,7 @@ namespace RTC
/* Instance methods. */ /* Instance methods. */
RtpStreamSend::RtpStreamSend( RtpStreamSend::RtpStreamSend(
RTC::RtpStream::Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize) Listener* listener, RTC::RtpStream::Params& params, size_t bufferSize)
: RtpStream::RtpStream(params), listener(listener), storage(bufferSize) : RtpStream::RtpStream(params), listener(listener), storage(bufferSize)
{ {
MS_TRACE(); MS_TRACE();
...@@ -398,7 +398,7 @@ namespace RTC ...@@ -398,7 +398,7 @@ namespace RTC
(*newBufferIt).packet = packet->Clone(store); (*newBufferIt).packet = packet->Clone(store);
} }
void RtpStreamSend::CheckHealth() void RtpStreamSend::CheckStatus()
{ {
MS_TRACE(); MS_TRACE();
...@@ -408,19 +408,19 @@ namespace RTC ...@@ -408,19 +408,19 @@ namespace RTC
{ {
MS_DEBUG_TAG(rtp, "last period loss percentage: %.2f", lossPercentage); MS_DEBUG_TAG(rtp, "last period loss percentage: %.2f", lossPercentage);
if (this->notifyHealth || this->healthy) if (this->notifyStatus || this->healthy)
{ {
this->healthy = false; this->healthy = false;
this->listener->OnRtpStreamUnhealthy(this); this->listener->OnRtpStreamUnhealthy(this);
} }
} }
else if (this->notifyHealth || !this->healthy) else if (this->notifyStatus || !this->healthy)
{ {
this->healthy = true; this->healthy = true;
this->listener->OnRtpStreamHealthy(this); this->listener->OnRtpStreamHealthy(this);
} }
this->notifyHealth = false; this->notifyStatus = false;
} }
void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc) void RtpStreamSend::SetRtx(uint8_t payloadType, uint32_t ssrc)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论