From 1d9d77ee787beffc0ad9d4f1a2a9f4d0c95f7d87 Mon Sep 17 00:00:00 2001 From: ggomez Date: Tue, 5 Jul 2016 17:25:31 +0200 Subject: [PATCH] Implement video-metadata check --- README.md | 2 +- components/script/dom/bindings/trace.rs | 3 ++ components/script/dom/htmlmediaelement.rs | 37 ++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 887a638c0634..5164f01c9582 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ pacman -Su pacman -Sy git mingw-w64-x86_64-toolchain mingw-w64-x86_64-freetype \ mingw-w64-x86_64-icu mingw-w64-x86_64-nspr mingw-w64-x86_64-ca-certificates \ mingw-w64-x86_64-expat mingw-w64-x86_64-cmake tar diffutils patch \ - patchutils make python2-setuptools + patchutils make python2-setuptools mingw-w64-x86_64-ffmpeg export GCC_URL=http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-gcc export GCC_EXT=5.4.0-1-any.pkg.tar.xz pacman -U --noconfirm $GCC_URL-$GCC_EXT $GCC_URL-ada-$GCC_EXT \ diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 3c13572bf37e..618061fe769a 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -91,6 +91,7 @@ use style::element_state::*; use style::properties::PropertyDeclarationBlock; use style::selector_impl::{PseudoElement, ElementSnapshot}; use style::values::specified::Length; +use time::Duration; use url::Origin as UrlOrigin; use url::Url; use uuid::Uuid; @@ -109,6 +110,8 @@ no_jsmanaged_fields!(EncodingRef); no_jsmanaged_fields!(Reflector); +no_jsmanaged_fields!(Duration); + /// Trace a `JSVal`. pub fn trace_jsval(tracer: *mut JSTracer, description: &str, val: &Heap) { unsafe { diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 7a94768c13ab..cc8bed31ebd9 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -35,6 +35,7 @@ use string_cache::Atom; use task_source::TaskSource; use time::{self, Timespec, Duration}; use url::Url; +use video_metadata; struct HTMLMediaElementContext { /// The element that initiated the request. @@ -88,11 +89,24 @@ impl AsyncResponseListener for HTMLMediaElementContext { // https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list // => "Once enough of the media data has been fetched to determine the duration..." if !self.have_metadata { - //TODO: actually check if the payload contains the full metadata - - // Step 6 - elem.change_ready_state(HAVE_METADATA); - self.have_metadata = true; + match video_metadata::get_format_from_slice(&self.data) { + Ok(meta) => { + let dur = meta.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.size.width, + height: meta.size.height, + video: meta.video, + audio: meta.audio, + }); + // Step 6 + elem.change_ready_state(HAVE_METADATA); + self.have_metadata = true; + } + _ => {} + } } else { elem.change_ready_state(HAVE_CURRENT_DATA); } @@ -164,6 +178,17 @@ impl HTMLMediaElementContext { } } +#[derive(JSTraceable, HeapSizeOf)] +pub struct VideoMedia { + format: String, + #[ignore_heap_size_of = "defined in time"] + duration: Duration, + width: u32, + height: u32, + video: String, + audio: Option, +} + #[dom_struct] pub struct HTMLMediaElement { htmlelement: HTMLElement, @@ -175,6 +200,7 @@ pub struct HTMLMediaElement { error: MutNullableHeap>, paused: Cell, autoplaying: Cell, + video: DOMRefCell>, } impl HTMLMediaElement { @@ -192,6 +218,7 @@ impl HTMLMediaElement { error: Default::default(), paused: Cell::new(true), autoplaying: Cell::new(true), + video: DOMRefCell::new(None), } }