From 7e6eedbdd8824f548edf60344eecfabf3b1ad5dc Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 5 Oct 2017 15:41:22 -0500 Subject: [PATCH] servo: Merge #18742 - Some low-key media improvements (from servo:media-metadata); r=jdm This just makes our code fail more gracefully. Source-Repo: https://github.com/servo/servo Source-Revision: 0444d76c6b117c3ad8dc4d3a59de252eaececbf1 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 72109f74604bfbdff846e5304098d221d0c5bbd9 --- .../components/script/dom/htmlmediaelement.rs | 36 +++---------------- servo/components/script/dom/mediaerror.rs | 6 ++++ .../script/dom/webidls/MediaError.webidl | 1 + 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/servo/components/script/dom/htmlmediaelement.rs b/servo/components/script/dom/htmlmediaelement.rs index 7d976a9d899a..0d66f1d63aa2 100644 --- a/servo/components/script/dom/htmlmediaelement.rs +++ b/servo/components/script/dom/htmlmediaelement.rs @@ -79,9 +79,6 @@ pub struct HTMLMediaElement { /// Play promises which are soon to be fulfilled by a queued task. #[ignore_heap_size_of = "promises are hard"] in_flight_play_promises_queue: DomRefCell]>, ErrorResult)>>, - /// The details of the video currently related to this media element. - // FIXME(nox): Why isn't this in HTMLVideoElement? - video: DomRefCell>, } /// https://html.spec.whatwg.org/multipage/#dom-media-networkstate @@ -105,17 +102,6 @@ enum ReadyState { HaveEnoughData = HTMLMediaElementConstants::HAVE_ENOUGH_DATA as u8, } -#[derive(HeapSizeOf, JSTraceable)] -pub struct VideoMedia { - format: String, - #[ignore_heap_size_of = "defined in time"] - duration: Duration, - width: u32, - height: u32, - video: String, - audio: Option, -} - impl HTMLMediaElement { pub fn new_inherited( tag_name: LocalName, @@ -136,7 +122,6 @@ impl HTMLMediaElement { delaying_the_load_event_flag: Default::default(), pending_play_promises: Default::default(), in_flight_play_promises_queue: Default::default(), - video: DomRefCell::new(None), } } @@ -1111,23 +1096,10 @@ impl HTMLMediaElementContext { } fn check_metadata(&mut self, elem: &HTMLMediaElement) { - match audio_video_metadata::get_format_from_slice(&self.data) { - Ok(audio_video_metadata::Metadata::Video(meta)) => { - let dur = meta.audio.duration.unwrap_or(::std::time::Duration::new(0, 0)); - *elem.video.borrow_mut() = Some(VideoMedia { - format: format!("{:?}", meta.format), - duration: Duration::seconds(dur.as_secs() as i64) + - Duration::nanoseconds(dur.subsec_nanos() as i64), - width: meta.dimensions.width, - height: meta.dimensions.height, - video: meta.video.unwrap_or("".to_owned()), - audio: meta.audio.audio, - }); - // Step 6 - elem.change_ready_state(ReadyState::HaveMetadata); - self.have_metadata = true; - } - _ => {} + if audio_video_metadata::get_format_from_slice(&self.data).is_ok() { + // Step 6. + elem.change_ready_state(ReadyState::HaveMetadata); + self.have_metadata = true; } } } diff --git a/servo/components/script/dom/mediaerror.rs b/servo/components/script/dom/mediaerror.rs index 5787085e9fc7..d8176e690447 100644 --- a/servo/components/script/dom/mediaerror.rs +++ b/servo/components/script/dom/mediaerror.rs @@ -5,6 +5,7 @@ use dom::bindings::codegen::Bindings::MediaErrorBinding::{self, MediaErrorMethods}; use dom::bindings::reflector::{Reflector, reflect_dom_object}; use dom::bindings::root::DomRoot; +use dom::bindings::str::DOMString; use dom::window::Window; use dom_struct::dom_struct; @@ -34,4 +35,9 @@ impl MediaErrorMethods for MediaError { fn Code(&self) -> u16 { self.code } + + // https://html.spec.whatwg.org/multipage/#dom-mediaerror-message + fn Message(&self) -> DOMString { + DOMString::new() + } } diff --git a/servo/components/script/dom/webidls/MediaError.webidl b/servo/components/script/dom/webidls/MediaError.webidl index ab1966d1095a..c570320ef032 100644 --- a/servo/components/script/dom/webidls/MediaError.webidl +++ b/servo/components/script/dom/webidls/MediaError.webidl @@ -11,4 +11,5 @@ interface MediaError { const unsigned short MEDIA_ERR_DECODE = 3; const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4; readonly attribute unsigned short code; + readonly attribute DOMString message; };