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