Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement video-metadata check
  • Loading branch information
GuillaumeGomez committed Jul 24, 2016
1 parent 20ab47c commit 1d9d77e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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 \
Expand Down
3 changes: 3 additions & 0 deletions components/script/dom/bindings/trace.rs
Expand Up @@ -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;
Expand All @@ -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<JSVal>) {
unsafe {
Expand Down
37 changes: 32 additions & 5 deletions components/script/dom/htmlmediaelement.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<String>,
}

#[dom_struct]
pub struct HTMLMediaElement {
htmlelement: HTMLElement,
Expand All @@ -175,6 +200,7 @@ pub struct HTMLMediaElement {
error: MutNullableHeap<JS<MediaError>>,
paused: Cell<bool>,
autoplaying: Cell<bool>,
video: DOMRefCell<Option<VideoMedia>>,
}

impl HTMLMediaElement {
Expand All @@ -192,6 +218,7 @@ impl HTMLMediaElement {
error: Default::default(),
paused: Cell::new(true),
autoplaying: Cell::new(true),
video: DOMRefCell::new(None),
}
}

Expand Down

0 comments on commit 1d9d77e

Please sign in to comment.