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

Cancel MediaRelay's consumer task when the last proxy is stopped #919

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

whitphx
Copy link
Contributor

@whitphx whitphx commented Aug 21, 2023

Stop the MediaRelay.__run_track() task when all the downstream relay tracks are stopped.
This is kind of optimization, not a bug fix.

@@ -578,6 +578,10 @@ def _stop(self, proxy: RelayStreamTrack) -> None:
# unregister proxy
self.__log_debug("Stop proxy %s", id(proxy))
self.__proxies[track].discard(proxy)
if len(self.__proxies[track]) == 0 and track in self.__tasks:
self.__tasks[track].cancel()
del self.__tasks[track]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather have the un-registration happen in a single place. Couldn't we handle cancellation in __run_track?

@jlaine
Copy link
Collaborator

jlaine commented Oct 25, 2023

This looks interesting but I don't see the corresponding unit test?

@jlaine jlaine added the changes requested Some changes are required before the PR can be merged. label Oct 25, 2023
@whitphx whitphx requested a review from jlaine November 20, 2023 04:46
@@ -578,18 +578,24 @@ def _stop(self, proxy: RelayStreamTrack) -> None:
# unregister proxy
self.__log_debug("Stop proxy %s", id(proxy))
self.__proxies[track].discard(proxy)
if len(self.__proxies[track]) == 0 and track in self.__tasks:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if len(self.__proxies[track]) == 0 and track in self.__tasks:
# stop worker if this was the last proxy
if not self.__proxies[track] and track in self.__tasks:

Copy link
Collaborator

Choose a reason for hiding this comment

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

How can track not be in self.__tasks ?

Copy link

codecov bot commented Nov 30, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (9f14474) 100.00% compared to head (67b5b01) 100.00%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #919   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           30        30           
  Lines         5816      5824    +8     
=========================================
+ Hits          5816      5824    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jlaine
Copy link
Collaborator

jlaine commented Nov 30, 2023

One thing I'm wondering about: if you stop all the consumer, isn't data just going to build up indefinitely in the source track?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes requested Some changes are required before the PR can be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants