Suspend/resume media activity based on document activity

This commit is contained in:
Fernando Jiménez Moreno 2019-09-18 09:34:43 +02:00
parent 51ed44c77d
commit d7bebce537
2 changed files with 19 additions and 12 deletions

24
Cargo.lock generated
View file

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

View file

@ -145,6 +145,7 @@ use script_traits::{
use servo_arc::Arc; use servo_arc::Arc;
use servo_atoms::Atom; use servo_atoms::Atom;
use servo_config::pref; use servo_config::pref;
use servo_media::{ClientContextId, ServoMedia};
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use std::borrow::ToOwned; use std::borrow::ToOwned;
use std::cell::{Cell, Ref, RefMut}; 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. // Set the document's activity level, reflow if necessary, and suspend or resume timers.
if activity != self.activity.get() { if activity != self.activity.get() {
self.activity.set(activity); 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 { if activity == DocumentActivity::FullyActive {
self.title_changed(); self.title_changed();
self.dirty_all_nodes(); self.dirty_all_nodes();
self.window() self.window()
.reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow); .reflow(ReflowGoal::Full, ReflowReason::CachedPageNeededReflow);
self.window().resume(); self.window().resume();
media.resume(&client_context_id);
// html.spec.whatwg.org/multipage/#history-traversal // html.spec.whatwg.org/multipage/#history-traversal
// Step 4.6 // Step 4.6
if self.ready_state.get() == DocumentReadyState::Complete { if self.ready_state.get() == DocumentReadyState::Complete {
@ -544,6 +550,7 @@ impl Document {
} }
} else { } else {
self.window().suspend(); self.window().suspend();
media.suspend(&client_context_id);
} }
} }
} }