mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Auto merge of #18804 - servo:media, r=emilio
Another couple of low-key media improvements 👶👣 <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18804) <!-- Reviewable:end -->
This commit is contained in:
commit
826352ab4c
2 changed files with 45 additions and 35 deletions
|
@ -20,6 +20,7 @@ use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::reflector::DomObject;
|
use dom::bindings::reflector::DomObject;
|
||||||
use dom::bindings::root::{DomRoot, MutNullableDom};
|
use dom::bindings::root::{DomRoot, MutNullableDom};
|
||||||
use dom::bindings::str::DOMString;
|
use dom::bindings::str::DOMString;
|
||||||
|
use dom::blob::Blob;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{Element, AttributeMutation};
|
use dom::element::{Element, AttributeMutation};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
@ -57,6 +58,8 @@ pub struct HTMLMediaElement {
|
||||||
network_state: Cell<NetworkState>,
|
network_state: Cell<NetworkState>,
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-media-readystate
|
/// https://html.spec.whatwg.org/multipage/#dom-media-readystate
|
||||||
ready_state: Cell<ReadyState>,
|
ready_state: Cell<ReadyState>,
|
||||||
|
/// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
|
||||||
|
src_object: MutNullableDom<Blob>,
|
||||||
/// https://html.spec.whatwg.org/multipage/#dom-media-currentsrc
|
/// https://html.spec.whatwg.org/multipage/#dom-media-currentsrc
|
||||||
current_src: DomRefCell<String>,
|
current_src: DomRefCell<String>,
|
||||||
/// Incremented whenever tasks associated with this element are cancelled.
|
/// Incremented whenever tasks associated with this element are cancelled.
|
||||||
|
@ -112,6 +115,7 @@ impl HTMLMediaElement {
|
||||||
htmlelement: HTMLElement::new_inherited(tag_name, prefix, document),
|
htmlelement: HTMLElement::new_inherited(tag_name, prefix, document),
|
||||||
network_state: Cell::new(NetworkState::Empty),
|
network_state: Cell::new(NetworkState::Empty),
|
||||||
ready_state: Cell::new(ReadyState::HaveNothing),
|
ready_state: Cell::new(ReadyState::HaveNothing),
|
||||||
|
src_object: Default::default(),
|
||||||
current_src: DomRefCell::new("".to_owned()),
|
current_src: DomRefCell::new("".to_owned()),
|
||||||
generation_id: Cell::new(0),
|
generation_id: Cell::new(0),
|
||||||
fired_loadeddata_event: Cell::new(false),
|
fired_loadeddata_event: Cell::new(false),
|
||||||
|
@ -430,6 +434,7 @@ impl HTMLMediaElement {
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
let task = MediaElementMicrotask::ResourceSelectionTask {
|
let task = MediaElementMicrotask::ResourceSelectionTask {
|
||||||
elem: DomRoot::from_ref(self),
|
elem: DomRoot::from_ref(self),
|
||||||
|
generation_id: self.generation_id.get(),
|
||||||
base_url: doc.base_url()
|
base_url: doc.base_url()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -447,13 +452,14 @@ impl HTMLMediaElement {
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
enum Mode {
|
enum Mode {
|
||||||
// FIXME(nox): Support media object provider.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
Object,
|
Object,
|
||||||
Attribute(String),
|
Attribute(String),
|
||||||
Children(DomRoot<HTMLSourceElement>),
|
Children(DomRoot<HTMLSourceElement>),
|
||||||
}
|
}
|
||||||
fn mode(media: &HTMLMediaElement) -> Option<Mode> {
|
fn mode(media: &HTMLMediaElement) -> Option<Mode> {
|
||||||
|
if media.src_object.get().is_some() {
|
||||||
|
return Some(Mode::Object);
|
||||||
|
}
|
||||||
if let Some(attr) = media.upcast::<Element>().get_attribute(&ns!(), &local_name!("src")) {
|
if let Some(attr) = media.upcast::<Element>().get_attribute(&ns!(), &local_name!("src")) {
|
||||||
return Some(Mode::Attribute(attr.Value().into()));
|
return Some(Mode::Attribute(attr.Value().into()));
|
||||||
}
|
}
|
||||||
|
@ -499,7 +505,6 @@ impl HTMLMediaElement {
|
||||||
// Step 9.obj.3.
|
// Step 9.obj.3.
|
||||||
// Note that the resource fetch algorithm itself takes care
|
// Note that the resource fetch algorithm itself takes care
|
||||||
// of the cleanup in case of failure itself.
|
// of the cleanup in case of failure itself.
|
||||||
// FIXME(nox): Pass the assigned media provider here.
|
|
||||||
self.resource_fetch_algorithm(Resource::Object);
|
self.resource_fetch_algorithm(Resource::Object);
|
||||||
},
|
},
|
||||||
Mode::Attribute(src) => {
|
Mode::Attribute(src) => {
|
||||||
|
@ -612,7 +617,7 @@ impl HTMLMediaElement {
|
||||||
document.loader().fetch_async_background(request, action_sender);
|
document.loader().fetch_async_background(request, action_sender);
|
||||||
},
|
},
|
||||||
Resource::Object => {
|
Resource::Object => {
|
||||||
// FIXME(nox): Use the current media resource.
|
// FIXME(nox): Actually do something with the object.
|
||||||
self.queue_dedicated_media_source_failure_steps();
|
self.queue_dedicated_media_source_failure_steps();
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -672,12 +677,10 @@ impl HTMLMediaElement {
|
||||||
// this invokation of the load algorithm.
|
// this invokation of the load algorithm.
|
||||||
self.fired_loadeddata_event.set(false);
|
self.fired_loadeddata_event.set(false);
|
||||||
|
|
||||||
// Step 1.
|
// Step 1-2.
|
||||||
// FIXME(nox): Abort any already-running instance of the
|
|
||||||
// resource selection algorithm.
|
|
||||||
|
|
||||||
// Steps 2-4.
|
|
||||||
self.generation_id.set(self.generation_id.get() + 1);
|
self.generation_id.set(self.generation_id.get() + 1);
|
||||||
|
|
||||||
|
// Steps 3-4.
|
||||||
while !self.in_flight_play_promises_queue.borrow().is_empty() {
|
while !self.in_flight_play_promises_queue.borrow().is_empty() {
|
||||||
self.fulfill_in_flight_play_promises(|| ());
|
self.fulfill_in_flight_play_promises(|| ());
|
||||||
}
|
}
|
||||||
|
@ -837,6 +840,17 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-media-src
|
// https://html.spec.whatwg.org/multipage/#dom-media-src
|
||||||
make_setter!(SetSrc, "src");
|
make_setter!(SetSrc, "src");
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
|
||||||
|
fn GetSrcObject(&self) -> Option<DomRoot<Blob>> {
|
||||||
|
self.src_object.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/#dom-media-srcobject
|
||||||
|
fn SetSrcObject(&self, value: Option<&Blob>) {
|
||||||
|
self.src_object.set(value);
|
||||||
|
self.media_element_load_algorithm();
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-media-preload
|
// https://html.spec.whatwg.org/multipage/#attr-media-preload
|
||||||
// Missing value default is user-agent defined.
|
// Missing value default is user-agent defined.
|
||||||
make_enumerated_getter!(Preload, "preload", "", "none" | "metadata" | "auto");
|
make_enumerated_getter!(Preload, "preload", "", "none" | "metadata" | "auto");
|
||||||
|
@ -929,7 +943,8 @@ impl VirtualMethods for HTMLMediaElement {
|
||||||
pub enum MediaElementMicrotask {
|
pub enum MediaElementMicrotask {
|
||||||
ResourceSelectionTask {
|
ResourceSelectionTask {
|
||||||
elem: DomRoot<HTMLMediaElement>,
|
elem: DomRoot<HTMLMediaElement>,
|
||||||
base_url: ServoUrl
|
generation_id: u32,
|
||||||
|
base_url: ServoUrl,
|
||||||
},
|
},
|
||||||
PauseIfNotInDocumentTask {
|
PauseIfNotInDocumentTask {
|
||||||
elem: DomRoot<HTMLMediaElement>,
|
elem: DomRoot<HTMLMediaElement>,
|
||||||
|
@ -939,8 +954,10 @@ pub enum MediaElementMicrotask {
|
||||||
impl MicrotaskRunnable for MediaElementMicrotask {
|
impl MicrotaskRunnable for MediaElementMicrotask {
|
||||||
fn handler(&self) {
|
fn handler(&self) {
|
||||||
match self {
|
match self {
|
||||||
&MediaElementMicrotask::ResourceSelectionTask { ref elem, ref base_url } => {
|
&MediaElementMicrotask::ResourceSelectionTask { ref elem, generation_id, ref base_url } => {
|
||||||
elem.resource_selection_algorithm_sync(base_url.clone());
|
if generation_id == elem.generation_id.get() {
|
||||||
|
elem.resource_selection_algorithm_sync(base_url.clone());
|
||||||
|
}
|
||||||
},
|
},
|
||||||
&MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => {
|
&MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => {
|
||||||
if !elem.upcast::<Node>().is_in_doc() {
|
if !elem.upcast::<Node>().is_in_doc() {
|
||||||
|
|
|
@ -3,25 +3,26 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#htmlmediaelement
|
// https://html.spec.whatwg.org/multipage/#htmlmediaelement
|
||||||
|
|
||||||
enum CanPlayTypeResult { "" /* empty string */, "maybe", "probably" };
|
enum CanPlayTypeResult { "" /* empty string */, "maybe", "probably" };
|
||||||
|
typedef /* (MediaStream or MediaSource or */ Blob /* ) */ MediaProvider;
|
||||||
|
|
||||||
[Abstract]
|
[Abstract]
|
||||||
interface HTMLMediaElement : HTMLElement {
|
interface HTMLMediaElement : HTMLElement {
|
||||||
// error state
|
// error state
|
||||||
readonly attribute MediaError? error;
|
readonly attribute MediaError? error;
|
||||||
|
|
||||||
// network state
|
// network state
|
||||||
[CEReactions]
|
[CEReactions] attribute DOMString src;
|
||||||
attribute DOMString src;
|
attribute MediaProvider? srcObject;
|
||||||
readonly attribute DOMString currentSrc;
|
readonly attribute DOMString currentSrc;
|
||||||
// [CEReactions]
|
// [CEReactions] attribute DOMString crossOrigin;
|
||||||
// attribute DOMString crossOrigin;
|
|
||||||
const unsigned short NETWORK_EMPTY = 0;
|
const unsigned short NETWORK_EMPTY = 0;
|
||||||
const unsigned short NETWORK_IDLE = 1;
|
const unsigned short NETWORK_IDLE = 1;
|
||||||
const unsigned short NETWORK_LOADING = 2;
|
const unsigned short NETWORK_LOADING = 2;
|
||||||
const unsigned short NETWORK_NO_SOURCE = 3;
|
const unsigned short NETWORK_NO_SOURCE = 3;
|
||||||
readonly attribute unsigned short networkState;
|
readonly attribute unsigned short networkState;
|
||||||
[CEReactions]
|
[CEReactions] attribute DOMString preload;
|
||||||
attribute DOMString preload;
|
|
||||||
// readonly attribute TimeRanges buffered;
|
// readonly attribute TimeRanges buffered;
|
||||||
void load();
|
void load();
|
||||||
CanPlayTypeResult canPlayType(DOMString type);
|
CanPlayTypeResult canPlayType(DOMString type);
|
||||||
|
@ -36,34 +37,26 @@ interface HTMLMediaElement : HTMLElement {
|
||||||
// readonly attribute boolean seeking;
|
// readonly attribute boolean seeking;
|
||||||
|
|
||||||
// playback state
|
// playback state
|
||||||
// attribute double currentTime;
|
// attribute double currentTime;
|
||||||
// void fastSeek(double time);
|
// void fastSeek(double time);
|
||||||
// readonly attribute unrestricted double duration;
|
// readonly attribute unrestricted double duration;
|
||||||
// Date getStartDate();
|
// Date getStartDate();
|
||||||
readonly attribute boolean paused;
|
readonly attribute boolean paused;
|
||||||
// attribute double defaultPlaybackRate;
|
// attribute double defaultPlaybackRate;
|
||||||
// attribute double playbackRate;
|
// attribute double playbackRate;
|
||||||
// readonly attribute TimeRanges played;
|
// readonly attribute TimeRanges played;
|
||||||
// readonly attribute TimeRanges seekable;
|
// readonly attribute TimeRanges seekable;
|
||||||
// readonly attribute boolean ended;
|
// readonly attribute boolean ended;
|
||||||
[CEReactions]
|
[CEReactions] attribute boolean autoplay;
|
||||||
attribute boolean autoplay;
|
// [CEReactions] attribute boolean loop;
|
||||||
// [CEReactions]
|
|
||||||
// attribute boolean loop;
|
|
||||||
Promise<void> play();
|
Promise<void> play();
|
||||||
void pause();
|
void pause();
|
||||||
|
|
||||||
// media controller
|
|
||||||
// attribute DOMString mediaGroup;
|
|
||||||
// attribute MediaController? controller;
|
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
// [CEReactions]
|
// [CEReactions] attribute boolean controls;
|
||||||
// attribute boolean controls;
|
// attribute double volume;
|
||||||
// attribute double volume;
|
// attribute boolean muted;
|
||||||
// attribute boolean muted;
|
// [CEReactions] attribute boolean defaultMuted;
|
||||||
// [CEReactions]
|
|
||||||
// attribute boolean defaultMuted;
|
|
||||||
|
|
||||||
// tracks
|
// tracks
|
||||||
// readonly attribute AudioTrackList audioTracks;
|
// readonly attribute AudioTrackList audioTracks;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue