Auto merge of #12186 - GuillaumeGomez:video-metadata, r=larsbergstrom,jdm,KiChjang

Implement video-metadata check

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12186)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-07-29 17:46:42 -05:00 committed by GitHub
commit d053fb16f6
17 changed files with 129 additions and 11 deletions

View file

@ -17,6 +17,9 @@ debugmozjs = ['js/debugmozjs']
[target.'cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))'.dependencies]
tinyfiledialogs = {git = "https://github.com/jdm/tinyfiledialogs"}
[target.'cfg(not(any(target_os = "android", target_arch = "arm", target_arch = "aarch64")))'.dependencies]
video-metadata = {git = "https://github.com/GuillaumeGomez/video-metadata-rs"}
[dependencies]
angle = {git = "https://github.com/servo/angle", branch = "servo"}
app_units = "0.2.5"

View file

@ -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<JSVal>) {
unsafe {

View file

@ -35,6 +35,8 @@ use string_cache::Atom;
use task_source::TaskSource;
use time::{self, Timespec, Duration};
use url::Url;
#[cfg(not(any(target_os = "android", target_arch = "arm", target_arch = "aarch64")))]
use video_metadata;
struct HTMLMediaElementContext {
/// The element that initiated the request.
@ -75,12 +77,11 @@ impl AsyncResponseListener for HTMLMediaElementContext {
}
}
fn data_available(&mut self, payload: Vec<u8>) {
fn data_available(&mut self, mut payload: Vec<u8>) {
if self.ignore_response {
return;
}
let mut payload = payload;
self.data.append(&mut payload);
let elem = self.elem.root();
@ -88,11 +89,7 @@ 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;
self.check_metadata(&elem);
} else {
elem.change_ready_state(HAVE_CURRENT_DATA);
}
@ -162,6 +159,46 @@ impl HTMLMediaElementContext {
ignore_response: false,
}
}
#[cfg(not(any(target_os = "android", target_arch = "arm", target_arch = "aarch64")))]
fn check_metadata(&mut self, elem: &HTMLMediaElement) {
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;
}
_ => {}
}
}
#[cfg(any(target_os = "android", target_arch = "arm", target_arch = "aarch64"))]
fn check_metadata(&mut self, elem: &HTMLMediaElement) {
// Step 6.
elem.change_ready_state(HAVE_METADATA);
self.have_metadata = true;
}
}
#[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]
@ -175,6 +212,7 @@ pub struct HTMLMediaElement {
error: MutNullableHeap<JS<MediaError>>,
paused: Cell<bool>,
autoplaying: Cell<bool>,
video: DOMRefCell<Option<VideoMedia>>,
}
impl HTMLMediaElement {
@ -192,6 +230,7 @@ impl HTMLMediaElement {
error: Default::default(),
paused: Cell::new(true),
autoplaying: Cell::new(true),
video: DOMRefCell::new(None),
}
}

View file

@ -87,6 +87,8 @@ extern crate url;
#[macro_use]
extern crate util;
extern crate uuid;
#[cfg(not(any(target_os = "android", target_arch = "arm", target_arch = "aarch64")))]
extern crate video_metadata;
extern crate webrender_traits;
extern crate websocket;
extern crate xml5ever;