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
This commit is contained in:
Anthony Ramine 2017-10-05 15:41:22 -05:00
Родитель 3208e48423
Коммит 7e6eedbdd8
3 изменённых файлов: 11 добавлений и 32 удалений

Просмотреть файл

@ -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<VecDeque<(Box<[Rc<Promise>]>, ErrorResult)>>,
/// The details of the video currently related to this media element.
// FIXME(nox): Why isn't this in HTMLVideoElement?
video: DomRefCell<Option<VideoMedia>>,
}
/// 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<String>,
}
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;
}
}
}

Просмотреть файл

@ -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()
}
}

Просмотреть файл

@ -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;
};