Unverified 提交 295dbf6e authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

ActiveSpeakerObserver: fix memory leak and more improvements (#942)

上级 0284e0ff
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Transport: Remove duplicate call to method (PR #931). * Transport: Remove duplicate call to method (PR #931).
* RTCP: Adjust maximum compound packet size (PR #934). * RTCP: Adjust maximum compound packet size (PR #934).
* Fix `bufferedAmount` type to be a number again (PR #936). * Fix `bufferedAmount` type to be a number again (PR #936).
* `ActiveSpeakerObserver`: Fix memory leak (PR #942).
### 3.10.12 ### 3.10.12
......
...@@ -9,10 +9,9 @@ ...@@ -9,10 +9,9 @@
#include <vector> #include <vector>
// Implementation of Dominant Speaker Identification for Multipoint // Implementation of Dominant Speaker Identification for Multipoint
// Videoconferencing by Ilana Volfin and Israel Cohen. This // Videoconferencing by Ilana Volfin and Israel Cohen. This implementation uses
// implementation uses the RTP Audio Level extension from RFC-6464 // the RTP Audio Level extension from RFC-6464 for the input signal. This has
// for the input signal. // been ported from DominantSpeakerIdentification.java in Jitsi:
// This has been ported from DominantSpeakerIdentification.java in Jitsi.
// https://github.com/jitsi/jitsi-utils/blob/master/src/main/java/org/jitsi/utils/dsi/DominantSpeakerIdentification.java // https://github.com/jitsi/jitsi-utils/blob/master/src/main/java/org/jitsi/utils/dsi/DominantSpeakerIdentification.java
namespace RTC namespace RTC
{ {
...@@ -24,7 +23,7 @@ namespace RTC ...@@ -24,7 +23,7 @@ namespace RTC
public: public:
Speaker(); Speaker();
void EvalActivityScores(); void EvalActivityScores();
double GetActivityScore(int32_t interval); double GetActivityScore(uint8_t interval);
void LevelChanged(uint32_t level, uint64_t now); void LevelChanged(uint32_t level, uint64_t now);
void LevelTimedOut(uint64_t now); void LevelTimedOut(uint64_t now);
...@@ -39,28 +38,36 @@ namespace RTC ...@@ -39,28 +38,36 @@ namespace RTC
public: public:
bool paused{ false }; bool paused{ false };
double immediateActivityScore; double immediateActivityScore{ 0 };
double mediumActivityScore; double mediumActivityScore{ 0 };
double longActivityScore; double longActivityScore{ 0 };
uint64_t lastLevelChangeTime{ 0 }; uint64_t lastLevelChangeTime{ 0 };
private: private:
uint8_t minLevel; uint8_t minLevel{ 0u };
uint8_t nextMinLevel; uint8_t nextMinLevel{ 0u };
uint32_t nextMinLevelWindowLen{ 0 }; uint32_t nextMinLevelWindowLen{ 0u };
std::vector<uint8_t> immediates; std::vector<uint8_t> immediates;
std::vector<uint8_t> mediums; std::vector<uint8_t> mediums;
std::vector<uint8_t> longs; std::vector<uint8_t> longs;
std::vector<uint8_t> levels; std::vector<uint8_t> levels;
size_t nextLevelIndex; size_t nextLevelIndex{ 0u };
}; };
struct ProducerSpeaker class ProducerSpeaker
{ {
public:
explicit ProducerSpeaker(RTC::Producer* producer);
~ProducerSpeaker();
public:
RTC::Producer* producer; RTC::Producer* producer;
Speaker* speaker; Speaker* speaker;
}; };
private:
static const size_t RelativeSpeachActivitiesLen{ 3u };
public: public:
ActiveSpeakerObserver(const std::string& id, RTC::RtpObserver::Listener* listener, json& data); ActiveSpeakerObserver(const std::string& id, RTC::RtpObserver::Listener* listener, json& data);
~ActiveSpeakerObserver() override; ~ActiveSpeakerObserver() override;
...@@ -84,13 +91,13 @@ namespace RTC ...@@ -84,13 +91,13 @@ namespace RTC
void OnTimer(Timer* timer) override; void OnTimer(Timer* timer) override;
private: private:
static constexpr int relativeSpeachActivitiesLen{ 3 }; double relativeSpeachActivities[RelativeSpeachActivitiesLen];
double relativeSpeachActivities[relativeSpeachActivitiesLen]; std::string dominantId;
std::string dominantId{ "" };
Timer* periodicTimer{ nullptr }; Timer* periodicTimer{ nullptr };
uint16_t interval{ 300u }; uint16_t interval{ 300u };
absl::flat_hash_map<std::string, struct ProducerSpeaker> mapProducerSpeaker; // Map of ProducerSpeakers indexed by Producer id.
uint64_t lastLevelIdleTime{ 0 }; absl::flat_hash_map<std::string, ProducerSpeaker*> mapProducerSpeakers;
uint64_t lastLevelIdleTime{ 0u };
}; };
} // namespace RTC } // namespace RTC
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论