mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implement video-metadata check
This commit is contained in:
parent
20ab47cb1a
commit
1d9d77ee78
3 changed files with 36 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<String>,
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
pub struct HTMLMediaElement {
|
||||
htmlelement: HTMLElement,
|
||||
|
@ -175,6 +200,7 @@ pub struct HTMLMediaElement {
|
|||
error: MutNullableHeap<JS<MediaError>>,
|
||||
paused: Cell<bool>,
|
||||
autoplaying: Cell<bool>,
|
||||
video: DOMRefCell<Option<VideoMedia>>,
|
||||
}
|
||||
|
||||
impl HTMLMediaElement {
|
||||
|
@ -192,6 +218,7 @@ impl HTMLMediaElement {
|
|||
error: Default::default(),
|
||||
paused: Cell::new(true),
|
||||
autoplaying: Cell::new(true),
|
||||
video: DOMRefCell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue