Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveSpeakerObserver: fix memory leak and more improvements #942

Merged
merged 6 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Transport: Remove duplicate call to method (PR #931).
* RTCP: Adjust maximum compound packet size (PR #934).
* Fix `bufferedAmount` type to be a number again (PR #936).
* `ActiveSpeakerObserver`: Fix memory leak (PR #942).


### 3.10.12
Expand Down
36 changes: 19 additions & 17 deletions worker/include/RTC/ActiveSpeakerObserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#include <vector>

// Implementation of Dominant Speaker Identification for Multipoint
// Videoconferencing by Ilana Volfin and Israel Cohen. This
// implementation uses the RTP Audio Level extension from RFC-6464
// for the input signal.
// This has been ported from DominantSpeakerIdentification.java in Jitsi.
// Videoconferencing by Ilana Volfin and Israel Cohen. This implementation uses
// the RTP Audio Level extension from RFC-6464 for the input signal. 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
namespace RTC
{
Expand All @@ -24,7 +23,7 @@ namespace RTC
public:
Speaker();
void EvalActivityScores();
double GetActivityScore(int32_t interval);
double GetActivityScore(uint8_t interval);
void LevelChanged(uint32_t level, uint64_t now);
void LevelTimedOut(uint64_t now);

Expand All @@ -39,20 +38,20 @@ namespace RTC

public:
bool paused{ false };
double immediateActivityScore;
double mediumActivityScore;
double longActivityScore;
double immediateActivityScore{ 0 };
double mediumActivityScore{ 0 };
double longActivityScore{ 0 };
uint64_t lastLevelChangeTime{ 0 };

private:
uint8_t minLevel;
uint8_t nextMinLevel;
uint32_t nextMinLevelWindowLen{ 0 };
uint8_t minLevel{ 0u };
uint8_t nextMinLevel{ 0u };
uint32_t nextMinLevelWindowLen{ 0u };
std::vector<uint8_t> immediates;
std::vector<uint8_t> mediums;
std::vector<uint8_t> longs;
std::vector<uint8_t> levels;
size_t nextLevelIndex;
size_t nextLevelIndex{ 0u };
};

struct ProducerSpeaker
Expand All @@ -61,6 +60,9 @@ namespace RTC
Speaker* speaker;
};

private:
static const size_t RelativeSpeachActivitiesLen{ 3u };

public:
ActiveSpeakerObserver(const std::string& id, RTC::RtpObserver::Listener* listener, json& data);
~ActiveSpeakerObserver() override;
Expand All @@ -84,13 +86,13 @@ namespace RTC
void OnTimer(Timer* timer) override;

private:
static constexpr int relativeSpeachActivitiesLen{ 3 };
double relativeSpeachActivities[relativeSpeachActivitiesLen];
std::string dominantId{ "" };
double relativeSpeachActivities[RelativeSpeachActivitiesLen];
std::string dominantId;
Timer* periodicTimer{ nullptr };
uint16_t interval{ 300u };
absl::flat_hash_map<std::string, struct ProducerSpeaker> mapProducerSpeaker;
uint64_t lastLevelIdleTime{ 0 };
// Map of ProducerSpeakers indeed by Producer id.
ibc marked this conversation as resolved.
Show resolved Hide resolved
absl::flat_hash_map<std::string, struct ProducerSpeaker> mapProducerSpeakers;
uint64_t lastLevelIdleTime{ 0u };
};
} // namespace RTC

Expand Down
Loading