Skip to content
Permalink
Browse files

Shutdown player when HTMLMediaElement is dropped

  • Loading branch information...
ferjm committed Feb 27, 2019
1 parent 7a67443 commit 36825b82f3e619df2205150ec6beed5703001e36

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -50,7 +50,7 @@ use servo_media::audio::context::{AudioContext, AudioContextOptions, ProcessingS
use servo_media::audio::context::{OfflineAudioContextOptions, RealTimeAudioContextOptions};
use servo_media::audio::decoder::AudioDecoderCallbacks;
use servo_media::audio::graph::NodeId;
use servo_media::{Backend, ServoMedia};
use servo_media::ServoMedia;
use std::cell::Cell;
use std::collections::{HashMap, VecDeque};
use std::mem;
@@ -75,7 +75,7 @@ struct DecodeResolver {
pub struct BaseAudioContext {
eventtarget: EventTarget,
#[ignore_malloc_size_of = "servo_media"]
audio_context_impl: AudioContext<Backend>,
audio_context_impl: AudioContext,
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-destination
destination: MutNullableDom<AudioDestinationNode>,
listener: MutNullableDom<AudioListener>,
@@ -131,7 +131,7 @@ impl BaseAudioContext {
false
}

pub fn audio_context_impl(&self) -> &AudioContext<Backend> {
pub fn audio_context_impl(&self) -> &AudioContext {
&self.audio_context_impl
}

@@ -103,7 +103,6 @@ use servo_media::audio::param::ParamType;
use servo_media::player::Player;
use servo_media::streams::MediaStream as BackendMediaStream;
use servo_media::webrtc::WebRtcController;
use servo_media::Backend;
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use smallvec::SmallVec;
use std::cell::{Cell, RefCell, UnsafeCell};
@@ -481,7 +480,7 @@ unsafe_no_jsmanaged_fields!(InteractiveWindow);
unsafe_no_jsmanaged_fields!(CanvasId);
unsafe_no_jsmanaged_fields!(SourceSet);
unsafe_no_jsmanaged_fields!(AudioBuffer);
unsafe_no_jsmanaged_fields!(AudioContext<Backend>);
unsafe_no_jsmanaged_fields!(AudioContext);
unsafe_no_jsmanaged_fields!(NodeId);
unsafe_no_jsmanaged_fields!(AnalysisEngine, DistanceModel, PanningModel, ParamType);
unsafe_no_jsmanaged_fields!(dyn Player);
@@ -1147,15 +1147,16 @@ impl HTMLMediaElement {
action_receiver.to_opaque(),
Box::new(move |message| {
let event: PlayerEvent = message.to().unwrap();
trace!("Player event {:?}", event);
let this = trusted_node.clone();
task_source
.queue_with_canceller(
task!(handle_player_event: move || {
this.root().handle_player_event(&event);
}),
&canceller,
)
.unwrap();
if let Err(err) = task_source.queue_with_canceller(
task!(handle_player_event: move || {
this.root().handle_player_event(&event);
}),
&canceller,
) {
warn!("Could not queue player event handler task {:?}", err);
}
}),
);

@@ -1489,6 +1490,14 @@ impl HTMLMediaElement {
}
}

impl Drop for HTMLMediaElement {
fn drop(&mut self) {
if let Err(err) = self.player.shutdown() {
warn!("Error shutting down player {:?}", err);
}
}
}

impl HTMLMediaElementMethods for HTMLMediaElement {
// https://html.spec.whatwg.org/multipage/#dom-media-networkstate
fn NetworkState(&self) -> u16 {
@@ -1,5 +1,11 @@
{
"items": {
"conformancechecker": {
"mozilla/remove_video_iframe.html": []
},
"manual": {
"mozilla/remove_video_iframe.html": []
},
"reftest": {
"css/abs-overflow-stackingcontext.html": [
[
@@ -7325,6 +7331,7 @@
{}
]
],
"mozilla/remove_video_iframe.html": [],
"mozilla/reparse_style_elements.html": [
[
"mozilla/reparse_style_elements.html",
@@ -7626,7 +7633,11 @@
],
{}
]
]
],
"mozilla/remove_video_iframe.html": []
},
"stub": {
"mozilla/remove_video_iframe.html": []
},
"support": {
".gitignore": [
@@ -10864,6 +10875,7 @@
{}
]
],
"mozilla/remove_video_iframe.html": [],
"mozilla/reparse_style_elements_ref.html": [
[
{}
@@ -10939,6 +10951,11 @@
{}
]
],
"mozilla/resources/remove_video_iframe_inner.html": [
[
{}
]
],
"mozilla/resources/second.html": [
[
{}
@@ -10949,6 +10966,11 @@
{}
]
],
"mozilla/resources/video.mp4": [
[
{}
]
],
"mozilla/resources/worker_success.js": [
[
{}
@@ -13550,6 +13572,12 @@
{}
]
],
"mozilla/remove_video_iframe.html": [
[
"/_mozilla/mozilla/remove_video_iframe.html",
{}
]
],
"mozilla/response-data-brotli.htm": [
[
"mozilla/response-data-brotli.htm",
@@ -13862,6 +13890,12 @@
{}
]
]
},
"visual": {
"mozilla/remove_video_iframe.html": []
},
"wdspec": {
"mozilla/remove_video_iframe.html": []
}
},
"paths": {
@@ -20461,6 +20495,10 @@
"d562e12720350501ad14223b668131837fd10620",
"support"
],
"mozilla/remove_video_iframe.html": [
"67b28d100828334ba96736d5fb2bcf01ed554d68",
"testharness"
],
"mozilla/reparse_style_elements.html": [
"e54f5a28d131ab41f89d3d70a9d01ea2fae751c1",
"reftest"
@@ -20529,6 +20567,10 @@
"b0883f382e1a80609b7b2c7904e701fbe6760b14",
"support"
],
"mozilla/resources/remove_video_iframe_inner.html": [
"bdd3d9349af8ade8bb4dcec1d7d46256ee2cffa1",
"support"
],
"mozilla/resources/second.html": [
"c4fbe534ed193e1d192c0338997a8d9da8eb6406",
"support"
@@ -20537,6 +20579,10 @@
"8faa57c0c47c4fdf27c052d059b28ee1088235e9",
"support"
],
"mozilla/resources/video.mp4": [
"fb5dbca23808bee44003692cb0e139dd6a22e874",
"support"
],
"mozilla/resources/worker_success.js": [
"327986f34b9b20476b6a7b1189c732a9ea8b9f68",
"support"
@@ -0,0 +1,14 @@
<!doctype html>
<meta charset="utf-8">
<title>Removing an iframe loading a video should not panic</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe id="video" src="resources/remove_video_iframe_inner.html"></iframe>
<script>
async_test(function(t) {
setTimeout(function() {
document.getElementById('video').remove();
t.done();
}, 1000);
});
</script>
@@ -0,0 +1 @@
<video autoplay src="video.mp4"></video>
Binary file not shown.

0 comments on commit 36825b8

Please sign in to comment.
You can’t perform that action at this time.