[whatwg] Media load algorithm feedback

Chris Pearce chris at pearce.org.nz
Tue Feb 24 15:35:22 PST 2009

I'm updating the new load algorithm for Firefox's <video> 
implementation, I've got some feedback on the recent changes to the load 
algorithm. I think the changes are sensible. It wasn't immediately 
obvious at first, but after thinking through them, I see the logic 
behind them.

We now have three things called load. The "load() method", the "load 
algorithm", and the "resource-load algorithm". It might be clearer if 
they were called the "load() method", the "resource selection 
algorithm", and the "resource fetch algorithm".

 From the "using source elements" load algorithm sub-step:
> /Search loop:/ Run these substeps atomically (so that the DOM cannot 
> change while they are running):
>   1.
>       If the node after pointer is the end of the list, then jump to
>       the step below labeled /waiting/.
> 7. Waiting: Set the error attribute to a new MediaError object whose 
> code attribute is set to MEDIA_ERR_NONE_SUPPORTED.
> 8. Set the element's networkState attribute to the NETWORK_NO_SOURCE value
> 9. Queue a task to fire a progress event called error at the media 
> element.
> 10. Set the element's delaying-the-load-event flag to false. This 
> stops delaying the load event.
> 11. Wait until the node after pointer is a node other than the end of 
> the list. (This step might wait forever.)
There's no step 12; I think the intention is that we return to the 
Search loop, but it's not documented.

Step 1 of the load algorithm:
> 1. While the media element has neither a src attribute nor any source 
> element children, wait. (This steps might wait forever.) 
And further down it says:
> If a media element 
> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#media-element> 
> whose |networkState 
> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-networkstate>| 
> has the value |NETWORK_EMPTY 
> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-network_empty>| 
> is inserted into a document 
> <http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#insert-an-element-into-a-document>, 
> the user agent must asynchronously invoke the media element 
> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#media-element>'s 
> load algorithm 
> <http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#concept-media-load-algorithm>.
I think that should be "invoke the load() method"? If it's "invoke the 
load() method", running load() will cancel any already running instance 
of the load algorithm - e.g. any load which is waiting at step 1 of the 
load algorithm. As it's written, the load /algorithm /will be invoked, 
which will not cancel any waiting loads, and it could in fact it create 
another instance of the load algorithm waiting at step 1 of the load 
algorithm. So we would create two concurrent instances of the load 
algorithm, both waiting at step 1 of the load algorithm by doing the 

var v = document.createVideo();

Setting v.src or adding a <source> child element to v will awaken two 
instances of the load /algorithm.

/Other than that, the media load spec seems sensible.

All the best,
Chris Pearce.

More information about the whatwg mailing list