Implement step 6 of media element 'time marches on' algoritm

This commit is contained in:
Fernando Jiménez Moreno 2018-12-13 16:35:26 +01:00
parent 9223d6248d
commit 6c2c3f75b9
5 changed files with 19 additions and 8 deletions

View file

@ -130,7 +130,7 @@ use style::values::specified::Length;
use tendril::fmt::UTF8; use tendril::fmt::UTF8;
use tendril::stream::LossyDecoder; use tendril::stream::LossyDecoder;
use tendril::{StrTendril, TendrilSink}; use tendril::{StrTendril, TendrilSink};
use time::Duration; use time::{Duration, Timespec};
use uuid::Uuid; use uuid::Uuid;
use webrender_api::{DocumentId, ImageKey, RenderApiSender}; use webrender_api::{DocumentId, ImageKey, RenderApiSender};
use webvr_traits::WebVRGamepadHand; use webvr_traits::WebVRGamepadHand;
@ -488,6 +488,7 @@ unsafe_no_jsmanaged_fields!(dyn Player<Error = ServoMediaError>);
unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>); unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>);
unsafe_no_jsmanaged_fields!(RenderApiSender); unsafe_no_jsmanaged_fields!(RenderApiSender);
unsafe_no_jsmanaged_fields!(ResourceFetchTiming); unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
unsafe_no_jsmanaged_fields!(Timespec);
unsafe impl<'a> JSTraceable for &'a str { unsafe impl<'a> JSTraceable for &'a str {
#[inline] #[inline]

View file

@ -204,6 +204,9 @@ pub struct HTMLMediaElement {
text_tracks_list: MutNullableDom<TextTrackList>, text_tracks_list: MutNullableDom<TextTrackList>,
/// Expected content length of the media asset being fetched or played. /// Expected content length of the media asset being fetched or played.
content_length: Cell<Option<u64>>, content_length: Cell<Option<u64>>,
/// Time of last timeupdate notification.
#[ignore_malloc_size_of = "Defined in time"]
next_timeupdate_event: Cell<Timespec>,
} }
/// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate> /// <https://html.spec.whatwg.org/multipage/#dom-media-networkstate>
@ -261,6 +264,7 @@ impl HTMLMediaElement {
played: Rc::new(DomRefCell::new(TimeRangesContainer::new())), played: Rc::new(DomRefCell::new(TimeRangesContainer::new())),
text_tracks_list: Default::default(), text_tracks_list: Default::default(),
content_length: Cell::new(None), content_length: Cell::new(None),
next_timeupdate_event: Cell::new(time::get_time() + Duration::milliseconds(250)),
} }
} }
@ -303,7 +307,15 @@ impl HTMLMediaElement {
/// https://html.spec.whatwg.org/multipage/#time-marches-on /// https://html.spec.whatwg.org/multipage/#time-marches-on
fn time_marches_on(&self) { fn time_marches_on(&self) {
// TODO: implement this. // Step 6.
if time::get_time() > self.next_timeupdate_event.get() {
let window = window_from_node(self);
window
.task_manager()
.media_element_task_source()
.queue_simple_event(self.upcast(), atom!("timeupdate"), &window);
self.next_timeupdate_event.set(time::get_time() + Duration::milliseconds(350));
}
} }
/// <https://html.spec.whatwg.org/multipage/#internal-pause-steps> /// <https://html.spec.whatwg.org/multipage/#internal-pause-steps>
@ -1173,6 +1185,7 @@ impl HTMLMediaElement {
.borrow_mut() .borrow_mut()
.add(self.playback_position.get(), position); .add(self.playback_position.get(), position);
self.playback_position.set(position); self.playback_position.set(position);
self.time_marches_on();
}, },
PlayerEvent::StateChanged(ref state) => match *state { PlayerEvent::StateChanged(ref state) => match *state {
PlaybackState::Paused => { PlaybackState::Paused => {

View file

@ -1,7 +1,9 @@
[autoplay-with-broken-track.html] [autoplay-with-broken-track.html]
expected: TIMEOUT expected: TIMEOUT
[<video autoplay> with <track> child] [<video autoplay> with <track> child]
expected: TIMEOUT expected:
if debug and (os == "mac") and (version == "OS X 10.14.1") and (processor == "x86_64") and (bits == 64): PASS
TIMEOUT
[<video autoplay> with <track src=\"invalid://url\" default=\"\"> child] [<video autoplay> with <track src=\"invalid://url\" default=\"\"> child]
expected: TIMEOUT expected: TIMEOUT

View file

@ -2,9 +2,6 @@
type: testharness type: testharness
disabled: Until https://github.com/servo/servo/pull/22477 is merged disabled: Until https://github.com/servo/servo/pull/22477 is merged
expected: TIMEOUT expected: TIMEOUT
[setting src attribute on a sufficiently long autoplay audio should trigger timeupdate event]
expected: NOTRUN
[setting src attribute on a sufficiently long autoplay video should trigger timeupdate event] [setting src attribute on a sufficiently long autoplay video should trigger timeupdate event]
expected: NOTRUN expected: NOTRUN

View file

@ -5,6 +5,4 @@
[calling play() on a sufficiently long audio should trigger timeupdate event] [calling play() on a sufficiently long audio should trigger timeupdate event]
expected: NOTRUN expected: NOTRUN
[calling play() on a sufficiently long video should trigger timeupdate event]
expected: FAIL