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

Conversation

ibc
Copy link
Member

@ibc ibc commented Nov 4, 2022

  • 🚨 When deleted, ActiveSpeakerObserver must iterate all entries in its mapProducerSpeakers and free them. This is because ActiveSpeakerObserver::RemoveProducer() won't be called for each existing Producer if the ActiveSpeakerObserver or its parent Router are directly closed. So fix a memory leak here.

  • Make mapProducerSpeakers contain pointers to ProducerSpeaker as done everywhere else.

  • If AddProducer() is called with an already paused Producer, consider it (because this can happen).

  • Code cleanup such as moving class static members to the top, initialize numeric members, make ProducerSpeaker be a class instead of a struct, use producerSpeaker to name values in this->mapProducerSpeakers instead of naming them rtpObserver, etc.

- When deleted, `ActiveSpeakerObserver` must iterate all entries in its `mapProducerSpeakers` and free them. This is because `ActiveSpeakerObserver::RemoveProducer()` **won't** be called for each existing `Producer` if the `ActiveSpeakerObserver` or its parent `Router` are directly closed.

- If `AddProducer()` is called with an already paused `Producer`, consider it (because this can happen).

- Code cleanup such as moving class `static` members to the top, initialize numeric members and so on.

- Use `producerSpeaker` to name values in `this->mapProducerSpeakers` instead of naming them `rtpObserver`.
@ibc ibc requested a review from jmillan November 4, 2022 09:35
Copy link
Member

@jmillan jmillan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few cosmetic changes requested 👍

worker/include/RTC/ActiveSpeakerObserver.hpp Outdated Show resolved Hide resolved
@@ -308,10 +325,11 @@ namespace RTC
dominantSpeaker->EvalActivityScores();
double newDominantC2 = C2;

for (const auto& it : this->mapProducerSpeaker)
for (auto& kv : this->mapProducerSpeakers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't it be const ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for consistency with the rest of the code. If we change this we should change it everywhere in tons of files.

@@ -351,10 +371,11 @@ namespace RTC
{
MS_TRACE();

for (const auto& it : this->mapProducerSpeaker)
for (auto& kv : this->mapProducerSpeakers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, can't it be const?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

Co-authored-by: José Luis Millán <jmillan@aliax.net>
@ibc
Copy link
Member Author

ibc commented Nov 4, 2022

In fact I'll do more changes.

  • Why are we allocating ProducerSpeaker instances directly in mapProducerSpeakers instead of storing pointers to ProducerSpeakeras we do everywhere?
  • And why do we need a pointer to Speaker in ProducerSpeaker class instead of directly having a Speaker?

@ibc ibc merged commit 295dbf6 into v3 Nov 4, 2022
@ibc ibc deleted the activespeakerobserver-improvements branch November 4, 2022 10:35
piranna pushed a commit to dyte-in/mediasoup that referenced this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants