mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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:
commit
9047ae97dd
6 changed files with 43 additions and 41 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -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)",
|
||||||
|
|
|
@ -23,7 +23,7 @@ use crate::dom::promise::Promise;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use crate::task_source::TaskSource;
|
use crate::task_source::TaskSource;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use msg::constellation_msg::BrowsingContextId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use servo_media::audio::context::{LatencyCategory, ProcessingState, RealTimeAudioContextOptions};
|
use servo_media::audio::context::{LatencyCategory, ProcessingState, RealTimeAudioContextOptions};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -40,14 +40,11 @@ pub struct AudioContext {
|
||||||
impl AudioContext {
|
impl AudioContext {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
// https://webaudio.github.io/web-audio-api/#AudioContext-constructors
|
// https://webaudio.github.io/web-audio-api/#AudioContext-constructors
|
||||||
fn new_inherited(
|
fn new_inherited(options: &AudioContextOptions, pipeline_id: PipelineId) -> AudioContext {
|
||||||
options: &AudioContextOptions,
|
|
||||||
browsing_context_id: BrowsingContextId,
|
|
||||||
) -> AudioContext {
|
|
||||||
// Steps 1-3.
|
// Steps 1-3.
|
||||||
let context = BaseAudioContext::new_inherited(
|
let context = BaseAudioContext::new_inherited(
|
||||||
BaseAudioContextOptions::AudioContext(options.into()),
|
BaseAudioContextOptions::AudioContext(options.into()),
|
||||||
browsing_context_id,
|
pipeline_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Step 4.1.
|
// Step 4.1.
|
||||||
|
@ -70,8 +67,10 @@ impl AudioContext {
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new(window: &Window, options: &AudioContextOptions) -> DomRoot<AudioContext> {
|
pub fn new(window: &Window, options: &AudioContextOptions) -> DomRoot<AudioContext> {
|
||||||
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0;
|
let pipeline_id = window
|
||||||
let context = AudioContext::new_inherited(options, browsing_context_id);
|
.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);
|
let context = reflect_dom_object(Box::new(context), window, AudioContextBinding::Wrap);
|
||||||
context.resume();
|
context.resume();
|
||||||
context
|
context
|
||||||
|
|
|
@ -51,7 +51,7 @@ use crate::task_source::TaskSource;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use js::rust::CustomAutoRooterGuard;
|
use js::rust::CustomAutoRooterGuard;
|
||||||
use js::typedarray::ArrayBuffer;
|
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::{AudioContext, AudioContextOptions, ProcessingState};
|
||||||
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
|
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
|
||||||
use servo_media::audio::decoder::AudioDecoderCallbacks;
|
use servo_media::audio::decoder::AudioDecoderCallbacks;
|
||||||
|
@ -109,7 +109,7 @@ impl BaseAudioContext {
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn new_inherited(
|
pub fn new_inherited(
|
||||||
options: BaseAudioContextOptions,
|
options: BaseAudioContextOptions,
|
||||||
browsing_context_id: BrowsingContextId,
|
pipeline_id: PipelineId,
|
||||||
) -> BaseAudioContext {
|
) -> BaseAudioContext {
|
||||||
let (sample_rate, channel_count) = match options {
|
let (sample_rate, channel_count) = match options {
|
||||||
BaseAudioContextOptions::AudioContext(ref opt) => (opt.sample_rate, 2),
|
BaseAudioContextOptions::AudioContext(ref opt) => (opt.sample_rate, 2),
|
||||||
|
@ -118,10 +118,8 @@ impl BaseAudioContext {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let client_context_id = ClientContextId::build(
|
let client_context_id =
|
||||||
browsing_context_id.namespace_id.0,
|
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
|
||||||
browsing_context_id.index.0.get(),
|
|
||||||
);
|
|
||||||
let context = BaseAudioContext {
|
let context = BaseAudioContext {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
audio_context_impl: ServoMedia::get()
|
audio_context_impl: ServoMedia::get()
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1329,11 +1329,11 @@ impl HTMLMediaElement {
|
||||||
HTMLMediaElementTypeId::HTMLVideoElement => Some(self.frame_renderer.clone()),
|
HTMLMediaElementTypeId::HTMLVideoElement => Some(self.frame_renderer.clone()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0;
|
let pipeline_id = window
|
||||||
let client_context_id = ClientContextId::build(
|
.pipeline_id()
|
||||||
browsing_context_id.namespace_id.0,
|
.expect("Cannot create player outside of a pipeline");
|
||||||
browsing_context_id.index.0.get(),
|
let client_context_id =
|
||||||
);
|
ClientContextId::build(pipeline_id.namespace_id.0, pipeline_id.index.0.get());
|
||||||
let player = ServoMedia::get().unwrap().create_player(
|
let player = ServoMedia::get().unwrap().create_player(
|
||||||
&client_context_id,
|
&client_context_id,
|
||||||
stream_type,
|
stream_type,
|
||||||
|
|
|
@ -23,7 +23,7 @@ use crate::dom::promise::Promise;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use crate::task_source::TaskSource;
|
use crate::task_source::TaskSource;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use msg::constellation_msg::BrowsingContextId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use servo_media::audio::context::OfflineAudioContextOptions as ServoMediaOfflineAudioContextOptions;
|
use servo_media::audio::context::OfflineAudioContextOptions as ServoMediaOfflineAudioContextOptions;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -47,7 +47,7 @@ impl OfflineAudioContext {
|
||||||
channel_count: u32,
|
channel_count: u32,
|
||||||
length: u32,
|
length: u32,
|
||||||
sample_rate: f32,
|
sample_rate: f32,
|
||||||
browsing_context_id: BrowsingContextId,
|
pipeline_id: PipelineId,
|
||||||
) -> OfflineAudioContext {
|
) -> OfflineAudioContext {
|
||||||
let options = ServoMediaOfflineAudioContextOptions {
|
let options = ServoMediaOfflineAudioContextOptions {
|
||||||
channels: channel_count as u8,
|
channels: channel_count as u8,
|
||||||
|
@ -56,7 +56,7 @@ impl OfflineAudioContext {
|
||||||
};
|
};
|
||||||
let context = BaseAudioContext::new_inherited(
|
let context = BaseAudioContext::new_inherited(
|
||||||
BaseAudioContextOptions::OfflineAudioContext(options),
|
BaseAudioContextOptions::OfflineAudioContext(options),
|
||||||
browsing_context_id,
|
pipeline_id,
|
||||||
);
|
);
|
||||||
OfflineAudioContext {
|
OfflineAudioContext {
|
||||||
context,
|
context,
|
||||||
|
@ -82,13 +82,11 @@ impl OfflineAudioContext {
|
||||||
{
|
{
|
||||||
return Err(Error::NotSupported);
|
return Err(Error::NotSupported);
|
||||||
}
|
}
|
||||||
let browsing_context_id = window.window_proxy().top_level_browsing_context_id().0;
|
let pipeline_id = window
|
||||||
let context = OfflineAudioContext::new_inherited(
|
.pipeline_id()
|
||||||
channel_count,
|
.expect("Cannot create audio context outside of a pipeline");
|
||||||
length,
|
let context =
|
||||||
sample_rate,
|
OfflineAudioContext::new_inherited(channel_count, length, sample_rate, pipeline_id);
|
||||||
browsing_context_id,
|
|
||||||
);
|
|
||||||
Ok(reflect_dom_object(
|
Ok(reflect_dom_object(
|
||||||
Box::new(context),
|
Box::new(context),
|
||||||
window,
|
window,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue