Auto merge of #24223 - ferjm:suspend.media.playback, r=jdm,gterzian

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 https://github.com/servo/media/pull/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 -->
This commit is contained in:
bors-servo 2019-09-19 15:34:06 -04:00 committed by GitHub
commit 9047ae97dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 41 deletions

24
Cargo.lock generated
View file

@ -4221,7 +4221,7 @@ dependencies = [
[[package]]
name = "servo-media"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"servo-media-audio 0.1.0 (git+https://github.com/servo/media)",
"servo-media-player 0.1.0 (git+https://github.com/servo/media)",
@ -4233,7 +4233,7 @@ dependencies = [
[[package]]
name = "servo-media-audio"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-slice-cast 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4250,7 +4250,7 @@ dependencies = [
[[package]]
name = "servo-media-dummy"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4265,7 +4265,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-slice-cast 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4301,7 +4301,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer-render"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"gstreamer 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer-video 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4311,7 +4311,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer-render-android"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"glib 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4324,7 +4324,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer-render-unix"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"glib 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"gstreamer 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4337,7 +4337,7 @@ dependencies = [
[[package]]
name = "servo-media-player"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"ipc-channel 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4349,7 +4349,7 @@ dependencies = [
[[package]]
name = "servo-media-streams"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4358,12 +4358,12 @@ dependencies = [
[[package]]
name = "servo-media-traits"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
[[package]]
name = "servo-media-webrtc"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4462,7 +4462,7 @@ dependencies = [
[[package]]
name = "servo_media_derive"
version = "0.1.0"
source = "git+https://github.com/servo/media#8c072eb922d0c8cb431f8c1cf80b304e03fe66bb"
source = "git+https://github.com/servo/media#7776958f353b5881fa1d6ec97a236940f7a30d16"
dependencies = [
"proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -23,7 +23,7 @@ use crate::dom::promise::Promise;
use crate::dom::window::Window;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use msg::constellation_msg::BrowsingContextId;
use msg::constellation_msg::PipelineId;
use servo_media::audio::context::{LatencyCategory, ProcessingState, RealTimeAudioContextOptions};
use std::rc::Rc;
@ -40,14 +40,11 @@ pub struct AudioContext {
impl AudioContext {
#[allow(unrooted_must_root)]
// https://webaudio.github.io/web-audio-api/#AudioContext-constructors
fn new_inherited(
options: &AudioContextOptions,
browsing_context_id: BrowsingContextId,
) -> AudioContext {
fn new_inherited(options: &AudioContextOptions, pipeline_id: PipelineId) -> AudioContext {
// Steps 1-3.
let context = BaseAudioContext::new_inherited(
BaseAudioContextOptions::AudioContext(options.into()),
browsing_context_id,
pipeline_id,
);
// Step 4.1.
@ -70,8 +67,10 @@ impl AudioContext {
#[allow(unrooted_must_root)]
pub fn new(window: &Window, options: &AudioContextOptions) -> DomRoot<AudioContext> {
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0;
let context = AudioContext::new_inherited(options, browsing_context_id);
let pipeline_id = window
.pipeline_id()
.expect("Cannot create AudioContext outside of a pipeline");
let context = AudioContext::new_inherited(options, pipeline_id);
let context = reflect_dom_object(Box::new(context), window, AudioContextBinding::Wrap);
context.resume();
context

View file

@ -51,7 +51,7 @@ use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use js::rust::CustomAutoRooterGuard;
use js::typedarray::ArrayBuffer;
use msg::constellation_msg::BrowsingContextId;
use msg::constellation_msg::PipelineId;
use servo_media::audio::context::{AudioContext, AudioContextOptions, ProcessingState};
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
use servo_media::audio::decoder::AudioDecoderCallbacks;
@ -109,7 +109,7 @@ impl BaseAudioContext {
#[allow(unrooted_must_root)]
pub fn new_inherited(
options: BaseAudioContextOptions,
browsing_context_id: BrowsingContextId,
pipeline_id: PipelineId,
) -> BaseAudioContext {
let (sample_rate, channel_count) = match options {
BaseAudioContextOptions::AudioContext(ref opt) => (opt.sample_rate, 2),
@ -118,10 +118,8 @@ impl BaseAudioContext {
},
};
let client_context_id = ClientContextId::build(
browsing_context_id.namespace_id.0,
browsing_context_id.index.0.get(),
);
let client_context_id =
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
let context = BaseAudioContext {
eventtarget: EventTarget::new_inherited(),
audio_context_impl: ServoMedia::get()

View file

@ -145,6 +145,7 @@ use script_traits::{
use servo_arc::Arc;
use servo_atoms::Atom;
use servo_config::pref;
use servo_media::{ClientContextId, ServoMedia};
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::borrow::ToOwned;
use std::cell::{Cell, Ref, RefMut};
@ -499,12 +500,17 @@ impl Document {
// Set the document's activity level, reflow if necessary, and suspend or resume timers.
if activity != self.activity.get() {
self.activity.set(activity);
let media = ServoMedia::get().unwrap();
let pipeline_id = self.window().pipeline_id().expect("doc with no pipeline");
let client_context_id =
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
if activity == DocumentActivity::FullyActive {
self.title_changed();
self.dirty_all_nodes();
self.window()
.reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow);
self.window().resume();
media.resume(&client_context_id);
// html.spec.whatwg.org/multipage/#history-traversal
// Step 4.6
if self.ready_state.get() == DocumentReadyState::Complete {
@ -544,6 +550,7 @@ impl Document {
}
} else {
self.window().suspend();
media.suspend(&client_context_id);
}
}
}

View file

@ -1329,11 +1329,11 @@ impl HTMLMediaElement {
HTMLMediaElementTypeId::HTMLVideoElement => Some(self.frame_renderer.clone()),
};
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0;
let client_context_id = ClientContextId::build(
browsing_context_id.namespace_id.0,
browsing_context_id.index.0.get(),
);
let pipeline_id = window
.pipeline_id()
.expect("Cannot create player outside of a pipeline");
let client_context_id =
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
let player = ServoMedia::get().unwrap().create_player(
&client_context_id,
stream_type,

View file

@ -23,7 +23,7 @@ use crate::dom::promise::Promise;
use crate::dom::window::Window;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
use msg::constellation_msg::BrowsingContextId;
use msg::constellation_msg::PipelineId;
use servo_media::audio::context::OfflineAudioContextOptions as ServoMediaOfflineAudioContextOptions;
use std::cell::Cell;
use std::rc::Rc;
@ -47,7 +47,7 @@ impl OfflineAudioContext {
channel_count: u32,
length: u32,
sample_rate: f32,
browsing_context_id: BrowsingContextId,
pipeline_id: PipelineId,
) -> OfflineAudioContext {
let options = ServoMediaOfflineAudioContextOptions {
channels: channel_count as u8,
@ -56,7 +56,7 @@ impl OfflineAudioContext {
};
let context = BaseAudioContext::new_inherited(
BaseAudioContextOptions::OfflineAudioContext(options),
browsing_context_id,
pipeline_id,
);
OfflineAudioContext {
context,
@ -82,13 +82,11 @@ impl OfflineAudioContext {
{
return Err(Error::NotSupported);
}
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0;
let context = OfflineAudioContext::new_inherited(
channel_count,
length,
sample_rate,
browsing_context_id,
);
let pipeline_id = window
.pipeline_id()
.expect("Cannot create audio context outside of a pipeline");
let context =
OfflineAudioContext::new_inherited(channel_count, length, sample_rate, pipeline_id);
Ok(reflect_dom_object(
Box::new(context),
window,