Auto merge of #23853 - ferjm:media.update, r=ceyusa

Fix HTMLMediaElement seek race condition

- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #___ (GitHub issue number if applicable)

This depends on https://github.com/servo/media/pull/289 and it's blocked by the servo-media update issue mentioned [here](https://github.com/servo/servo/pull/23842#issuecomment-515007529)

<!-- 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/23853)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-08-14 02:03:52 -04:00 committed by GitHub
commit d7433c9a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 20 deletions

54
Cargo.lock generated
View file

@ -2101,6 +2101,16 @@ dependencies = [
"unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "idna"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "image"
version = "0.21.0"
@ -3472,6 +3482,11 @@ name = "percent-encoding"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "percent-encoding"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "petgraph"
version = "0.4.13"
@ -4285,7 +4300,7 @@ dependencies = [
[[package]]
name = "servo-media"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
@ -4297,11 +4312,11 @@ dependencies = [
[[package]]
name = "servo-media-audio"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
"euclid 0.19.8 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4314,7 +4329,7 @@ dependencies = [
[[package]]
name = "servo-media-dummy"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
dependencies = [
"boxfnonce 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4329,7 +4344,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
@ -4357,14 +4372,14 @@ dependencies = [
"servo-media-streams 0.1.0 (git+https://github.com/servo/media)",
"servo-media-traits 0.1.0 (git+https://github.com/servo/media)",
"servo-media-webrtc 0.1.0 (git+https://github.com/servo/media)",
"url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"zip 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "servo-media-gstreamer-render"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
@ -4374,7 +4389,7 @@ dependencies = [
[[package]]
name = "servo-media-gstreamer-render-unix"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
@ -4387,7 +4402,7 @@ dependencies = [
[[package]]
name = "servo-media-player"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
dependencies = [
"ipc-channel 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.88 (registry+https://github.com/rust-lang/crates.io-index)",
@ -4399,7 +4414,7 @@ dependencies = [
[[package]]
name = "servo-media-streams"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
@ -4408,12 +4423,12 @@ dependencies = [
[[package]]
name = "servo-media-traits"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
[[package]]
name = "servo-media-webrtc"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
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)",
@ -4512,7 +4527,7 @@ dependencies = [
[[package]]
name = "servo_media_derive"
version = "0.1.0"
source = "git+https://github.com/servo/media#ae9d071e72cef4bbf1aaf54004007c7047b2d4b6"
source = "git+https://github.com/servo/media#3e3dc52e9b2e49a8ac14f8bbd873028c8482d463"
dependencies = [
"proc-macro2 0.4.26 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -5384,6 +5399,16 @@ dependencies = [
"percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "url"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "url_serde"
version = "0.2.0"
@ -6098,6 +6123,7 @@ dependencies = [
"checksum hyper_serde 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ce9b7b7efb67dec22beaf71defbec5688240399889fc3050186db41b4a40cd"
"checksum ident_case 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9826188e666f2ed92071d2dadef6edc430b11b158b5b2b3f4babbcc891eaaa"
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9"
"checksum image 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "52fb0666a1273dac46f9725aa4859bcd5595fc3554cf3495051b4de8db745e7d"
"checksum immeta 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7371aa3c98fad60de2d9b517e2e1ed45593c32b0c77249310fa507749a2a318b"
"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
@ -6201,6 +6227,7 @@ dependencies = [
"checksum peek-poke-derive 0.2.0 (git+https://github.com/servo/webrender)" = "<none>"
"checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
"checksum percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de154f638187706bde41d9b4738748933d64e6b37bdbffc0b47a97d16a6ae356"
"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
"checksum petgraph 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
"checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18"
"checksum phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e"
@ -6345,6 +6372,7 @@ dependencies = [
"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
"checksum unwind-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bd1c4a6d1cfe0072924d1b1d4ca6faa211c95056666979d7ef1bab4cd206057f"
"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a"
"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61"
"checksum url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74e7d099f1ee52f823d4bdd60c93c3602043c728f5db3b97bdb548467f7bddea"
"checksum urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3df3561629a8bb4c57e5a2e4c43348d9e29c7c29d9b1c4c1f47166deca8f37ed"
"checksum utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7"

View file

@ -80,7 +80,7 @@ use net_traits::{NetworkError, ResourceFetchTiming, ResourceTimingType};
use script_layout_interface::HTMLMediaData;
use servo_config::pref;
use servo_media::player::frame::{Frame, FrameRenderer};
use servo_media::player::{PlaybackState, Player, PlayerError, PlayerEvent, StreamType};
use servo_media::player::{PlaybackState, Player, PlayerError, PlayerEvent, SeekLock, StreamType};
use servo_media::{ClientContextId, ServoMedia, SupportsMediaType};
use servo_url::ServoUrl;
use std::cell::Cell;
@ -787,7 +787,7 @@ impl HTMLMediaElement {
}
}
fn fetch_request(&self, offset: Option<u64>) {
fn fetch_request(&self, offset: Option<u64>, seek_lock: Option<SeekLock>) {
if self.resource_url.borrow().is_none() && self.blob_url.borrow().is_none() {
eprintln!("Missing request url");
self.queue_dedicated_media_source_failure_steps();
@ -835,6 +835,7 @@ impl HTMLMediaElement {
self,
url.clone(),
offset.unwrap_or(0),
seek_lock,
)));
let (action_sender, action_receiver) = ipc::channel().unwrap();
let window = window_from_node(self);
@ -918,7 +919,7 @@ impl HTMLMediaElement {
// Step 4.remote.2.
*self.resource_url.borrow_mut() = Some(url);
self.fetch_request(None);
self.fetch_request(None, None);
},
Resource::Object => {
if let Some(ref src_object) = *self.src_object.borrow() {
@ -927,7 +928,7 @@ impl HTMLMediaElement {
let blob_url = URL::CreateObjectURL(&self.global(), &*blob);
*self.blob_url.borrow_mut() =
Some(ServoUrl::parse(&blob_url).expect("infallible"));
self.fetch_request(None);
self.fetch_request(None, None);
},
SrcObject::MediaStream(ref stream) => {
let tracks = &*stream.get_tracks();
@ -1728,8 +1729,8 @@ impl HTMLMediaElement {
self.playback_position.set(position);
self.time_marches_on();
},
PlayerEvent::SeekData(p) => {
self.fetch_request(Some(p));
PlayerEvent::SeekData(p, ref seek_lock) => {
self.fetch_request(Some(p), Some(seek_lock.clone()));
},
PlayerEvent::SeekDone(_) => {
// Continuation of
@ -2469,6 +2470,10 @@ struct HTMLMediaElementFetchListener {
/// EnoughData event uses this value to restart the download from
/// the last fetched position.
latest_fetched_content: u64,
/// The media player discards all data pushes until the seek block
/// is released right before pushing the data from the offset requested
/// by a seek request.
seek_lock: Option<SeekLock>,
}
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
@ -2565,6 +2570,10 @@ impl FetchResponseListener for HTMLMediaElementFetchListener {
let payload_len = payload.len() as u64;
if let Some(seek_lock) = self.seek_lock.take() {
seek_lock.unlock(/* successful seek */ true);
}
// Push input data into the player.
if let Err(e) = elem
.player
@ -2609,6 +2618,10 @@ impl FetchResponseListener for HTMLMediaElementFetchListener {
// https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list
fn process_response_eof(&mut self, status: Result<ResourceFetchTiming, NetworkError>) {
if let Some(seek_lock) = self.seek_lock.take() {
seek_lock.unlock(/* successful seek */ false);
}
let elem = self.elem.root();
if elem.player.borrow().is_none() {
@ -2718,7 +2731,12 @@ impl PreInvoke for HTMLMediaElementFetchListener {
}
impl HTMLMediaElementFetchListener {
fn new(elem: &HTMLMediaElement, url: ServoUrl, offset: u64) -> Self {
fn new(
elem: &HTMLMediaElement,
url: ServoUrl,
offset: u64,
seek_lock: Option<SeekLock>,
) -> Self {
Self {
elem: Trusted::new(elem),
metadata: None,
@ -2728,6 +2746,7 @@ impl HTMLMediaElementFetchListener {
url,
expected_content_length: None,
latest_fetched_content: offset,
seek_lock,
}
}
}

View file

@ -37,6 +37,7 @@ packages = [
"crossbeam-deque",
"euclid", # https://github.com/servo/rust-webvr/pull/89
"gl_generator", # https://github.com/servo/servo/pull/23288#issuecomment-494687746
"idna", # https://github.com/servo/servo/pull/23838
"lock_api",
"log",
"mime",
@ -44,9 +45,11 @@ packages = [
"nix", # https://github.com/servo/servo/issues/23189#issuecomment-487512605
"parking_lot",
"parking_lot_core",
"percent-encoding", # https://github.com/servo/servo/pull/23838
"rand_core",
"scopeguard",
"unicase",
"url", # https://github.com/servo/servo/pull/23838
]
# Files that are ignored for all tidy and lint checks.
files = [