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

Expose methods to suspend and resume all media actions #310

Merged
merged 4 commits into from Sep 19, 2019

Conversation

@ferjm
Copy link
Member

ferjm commented Sep 16, 2019

This is required for fixing servo/servo#22763 and servo/servo#21989

ServoMedia shuts down AudioContexts and Players when these are dropped, but because Servo keeps a bfcache, DOM objects are not always released immediately after navigation. So we need a way to manually suspend playback.

A similar issue occurs with getUserMedia, where we keep input streams active after navigation. I'll fix it in a follow-up.

@ferjm ferjm mentioned this pull request Sep 16, 2019
3 of 4 tasks complete
@ferjm
Copy link
Member Author

ferjm commented Sep 16, 2019

r? @jdm

fn suspend(&self, id: &ClientContextId) {
let mut instances = self.instances.lock().unwrap();
match instances.get_mut(id) {
Some(vec) => vec.retain(|(_, weak)| {

This comment has been minimized.

@jdm

jdm Sep 16, 2019

Member

Should we abstract this operation (iterating over all known instances to perform an operation while dropping any dead ones) into a helper function that takes a closure argument, since it's used in two different places now?

This comment has been minimized.

@ferjm

ferjm Sep 18, 2019

Author Member

Done

@ferjm ferjm changed the title Expose a method to suspend all media actions Expose methods to suspend and restart all media actions Sep 18, 2019
@ferjm ferjm changed the title Expose methods to suspend and restart all media actions Expose methods to suspend and resume all media actions Sep 18, 2019
@ferjm
Copy link
Member Author

ferjm commented Sep 18, 2019

r? @jdm

I have added an additional resume method required to resume playback when navigating through the browsing history.

fn media_instance_action(
&self,
id: &ClientContextId,
cb: Rc<dyn Fn(Arc<Mutex<dyn MediaInstance>>) -> Result<(), ()>>,

This comment has been minimized.

@jdm

jdm Sep 18, 2019

Member

It's not clear why the Rc is needed here - what if we use &dyn Fn(...) -> ... instead, and don't add move to each closure? Also, why not call lock().unwrap() in this method and pass &mut dyn MediaInstance to the callback instead?

@ferjm ferjm force-pushed the ferjm:suspend branch from 884edfd to 06f1b5d Sep 19, 2019
@ferjm ferjm requested a review from jdm Sep 19, 2019
@jdm
Copy link
Member

jdm commented Sep 19, 2019

@bors-servo
Copy link
Contributor

bors-servo commented Sep 19, 2019

📌 Commit 06f1b5d has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Sep 19, 2019

Testing commit 06f1b5d with merge 7776958...

bors-servo added a commit that referenced this pull request Sep 19, 2019
Expose methods to suspend and resume all media actions

This is required for fixing servo/servo#22763 and servo/servo#21989

ServoMedia shuts down AudioContexts and Players when these are dropped, but because Servo keeps a bfcache, DOM objects are not always released immediately after navigation. So we need a way to manually suspend playback.

A similar issue occurs with `getUserMedia`, where we keep input streams active after navigation. I'll fix it in a follow-up.
@bors-servo
Copy link
Contributor

bors-servo commented Sep 19, 2019

☀️ Test successful - checks-travis
Approved by: jdm
Pushing 7776958 to master...

@bors-servo bors-servo merged commit 06f1b5d into servo:master Sep 19, 2019
3 checks passed
3 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
bors-servo added a commit to servo/servo that referenced this pull request Sep 19, 2019
Suspend media after navigation

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #21989 and fix #22763
- [ ] I am not sure how to test this

This depends on servo/media#310

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24223)
<!-- Reviewable:end -->
bors-servo added a commit to servo/servo that referenced this pull request Sep 19, 2019
Suspend media after navigation

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #21989 and fix #22763
- [ ] I am not sure how to test this

This depends on servo/media#310

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24223)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.