Closed Bug 548523 Opened 14 years ago Closed 14 years ago

HTML 5 media attribute 'autobuffer' has been renamed to 'preload'

Categories

(Core :: Audio/Video, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
blocking2.0 --- betaN+

People

(Reporter: cajbir, Assigned: cpearce)

References

Details

(Keywords: dev-doc-complete, html5, Whiteboard: [parity-webkit])

Attachments

(4 files, 3 obsolete files)

See:

http://html5.org/tools/web-apps-tracker?from=4810&to=4811
http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#dom-media-preload
http://www.whatwg.org/specs/web-apps/current-work/multipage/video.html#attr-media-preload

It has also changed behavior. It now has four options rather than being an HTML boolean attribute.

We need to remove 'autobuffer' and implement 'preload'. This will probably affect existing sites that use autobuffer.
Do we actually want to remove autobuffer, or keep it for now for backwards compat and implement preload alongside?
Keep it plz.
I'd say drop it, like WebKit did.
Whiteboard: [parity-webkit]
Since the default should now be buffering, removing autobuffer="" support should be simple and safe.
I agree with Anne.

However, making buffering be the default is a bit of a problem. There are existing pages with lots of media elements with no attributes.

"Hints to the user agent that the user agent can put the user's needs first without risk to the server, up to and including optimistically downloading the entire resource." doesn't seem like something that should be the default for authors who don't know what they're doing. I'll bring this up on the list.
I started a thread on public-html. Maybe I should have filed a bug instead, oh well.

The spec bug where 'preload' was discussed is here:
http://www.w3.org/Bugs/Public/show_bug.cgi?id=8731

I think for now we should just implement the spec except make the default be "metadata". I think we can drop "autobuffer". We'll need to update our tests.
Attached patch Patch attempt 1 (obsolete) — Splinter Review
The attached patch is a first step toward supporting the 'preload' hint. I'd really appreciate getting a bit of feedback before I continue. (Chris: Rob said you might be able to help here!)

The updated spec changes the attribute name from 'autobuffer' to 'preload'. The spec introduces different values for the attribute, including a way to avoid preloading entirely. Here's a quick summary of how the changes relate to the patch.

The spec defines behaviour for five different states of the 'preload' attribute. These states are:
1. no attribute present,
2. attribute set to "",
3. attribute set to "none",
4. attribute set to "metadata", or
5. attribute set to "auto".

State 1 is simply represented by an element without a 'preload' attribute. States 2-5 are represented by attributes with one of the values from the PreloadAttrValue enumeration.

Each state drives a certain preloading behaviour. The unpatched code supports two types of behaviour: loading metadata only and loading "enough" content to support uninterrupted playback. To support preload="none" we need to introduce another preloading behaviour: loading no content at all.

These different behaviours are represented in the code by the PreloadAction enumeration.

Here are the mappings that the spec gives from attribute state to each preloading behaviour.
1. (no attr)    -> preload metadata
2. ("")         -> preload enough data
3. ("none")     -> preload no data
4. ("metadata") -> preload metadata
5. ("auto")     -> preload enough data

The mapping from attribute state to preload behaviour is handled by the PreloadAttributeUpdated() method. At the moment the method doesn't actually implement all these behaviours. I will handle them in a future version of the patch. It does handle one case---loading "enough" data---because code for doing this had already be implemented.

Next steps:

1. Stopping load when preload="none": Split LoadResource() into two parts so that we can suspend before actually starting any load actions. We would stash the current URI into a member variable so that we can restart the load later on.

2. Resuming load: maybe generalising mSuspendedAfterFirstFrame, mAllowSuspendAfterFirstFrame and StopSuspendingAfterFirstFrame() to support resuming from PRELOAD_NONE in addition to PRELOAD_METADATA. As an alternative to generalising this, I could introduce duplicate variables and methods. i.e. mSuspendedBeforeLoad, mAllowSuspendBeforeLoad, StopSuspendingBeforeLoad().

3. By this stage we will have support for all preload values and behaviours. However there is a question about whether we support all preload behaviour *transitions*. For example the existing (unpatched) code supports the transition from "metadata" to "enough" but ignores transitions in the other direction. In other words, it supports *increases* in the amount of preloading, but not *decreases*. I discussed this with Rob and the reason is that the use case for decreasing the amount of preloading doesn't seem very important, when compared to the extra complexity of the code that would need to be written to support it. At the moment I'm planning on taking the same approach (i.e. only supporting increases), but I'd welcome comments.

4. Add tests for new attribute values and preload behaviours. I've already patched the existing tests where it was easy to do so. But I haven't written any tests for the new values and behaviours.
Attachment #444340 - Flags: review?(chris)
Comment on attachment 444340 [details] [diff] [review]
Patch attempt 1

(In reply to comment #9)
> Created an attachment (id=444340) [details]
> Patch attempt 1

Looks like you've got a good handle on how to approach this.

> Next steps:
> 
> 1. Stopping load when preload="none": Split LoadResource() into two parts so
> that we can suspend before actually starting any load actions. We would stash
> the current URI into a member variable so that we can restart the load later
> on.

As discussed, when script or the user requests a load, we should just do a complete load, ignoring preload. The preload attribute should only affect the implicit loads which start when a we add a media element to a document. With preload:none we should stop the load once we reach resource fetch algorithm step 2.

> 
> 2. Resuming load: maybe generalising mSuspendedAfterFirstFrame,
> mAllowSuspendAfterFirstFrame and StopSuspendingAfterFirstFrame() to support
> resuming from PRELOAD_NONE in addition to PRELOAD_METADATA. As an alternative
> to generalising this, I could introduce duplicate variables and methods. i.e.
> mSuspendedBeforeLoad, mAllowSuspendBeforeLoad, StopSuspendingBeforeLoad().
> 

Do whichever you feel is cleaner.

> 3. By this stage we will have support for all preload values and behaviours.
> However there is a question about whether we support all preload behaviour
> *transitions*. 

Decreasing values don't seem that important to me; a script should really set the value of preload before starting a load.

> 
> 4. Add tests for new attribute values and preload behaviours. I've already
> patched the existing tests where it was easy to do so. But I haven't written
> any tests for the new values and behaviours.

Backend independent tests please, so that it covers both the wav and ogg backends, similar to the approach taken in test_playback.html.
Attachment #444340 - Flags: review?(chris)
blocking2.0: --- → ?
Keywords: html5
I'll take this and finish it off. Rich, thanks very much for getting us started on this!
Assignee: nobody → chris
Attached patch Patch 1 v2: preload attribute (obsolete) — Splinter Review
Rich's patch finished up, with tests. We preload:metadata by default, and support preload attribute changes during loads which cause us to preload more data, but not less.
Attachment #444340 - Attachment is obsolete: true
Attachment #460371 - Flags: review?(roc)
When we're loading a preload:none video, or if a video element with controls is added to a document, we'll show the throbber in the controls. This is misleading, as we're not actively loading the video. This patch changes the controls so that we only show the throbber upon video element bind to document or loadstart if we've got a resource and we're actively loading it.
Attachment #460374 - Flags: review?(dolske)
Comment on attachment 460371 [details] [diff] [review]
Patch 1 v2: preload attribute

Shouldn't there be a call to UpdatePreloadAction() when there's an attribute change with aName == nsGkAtoms::autoplay? Otherwise looks good.
Attachment #460371 - Flags: review?(roc) → review+
(In reply to comment #14)
> Shouldn't there be a call to UpdatePreloadAction() when there's an attribute
> change with aName == nsGkAtoms::autoplay? Otherwise looks good.

Yeah, I think there needs to be. I'll add a test for this too.

Can this block2.0?
With UpdatePreloadAction() in setattr autoplay case, and with test for this case.
Attachment #460371 - Attachment is obsolete: true
Attachment #461377 - Flags: review+
Comment on attachment 460374 [details] [diff] [review]
Patch 2 v1: Don't show video controls throbber when not loading resource

Setting the statusIcon type doesn't control its display, just which icon (throbber or error "X") should be displayed... Instead, I think you want to update the logic in setupStatusFader() to suppress display of the statusOverlay (which includes the icon as a child). [The status overlay is a semitransparent black, so I suspect this patch was just breaking the icon and not the overlay display?]
Attachment #460374 - Flags: review?(dolske) → review-
Hmm, my first sentence it probably confusing. It's better rephrased as: Setting the statusIcon type doesn't control its display, just which icon is used when the statusOverlay is being shown.
Patch attempt 2. Changes setupStatusFader() so that we only show the status overlay in the non-seeking and non-error cases when networkState is NETWORK_LOADING. So only show the status overlay if we're actually loading a resource in these cases.

I had to also change the media element so that it goes back into NETWORK_LOADING network state when it resumes a load; the spec and this controls change requires this, I missed it in the previous patch.
Attachment #460374 - Attachment is obsolete: true
Attachment #461460 - Flags: review?(dolske)
Whilde developing another patch on top of this one, I noticed that test_preload_actions, testcase 9 often times out because the canplaythrough event doesn't always fire. We have bug 568402 on file for this. This patch disables testcase 9, so that we don't inject a new random orange when this lands. We should re-enable that testcase once bug 568402 is fixed. a=test-fix.
We should land 'Patch 1 v3' and 'Patch disable test_preload_actions case 9' ASAP, and follow up with Patch 2 once it gets review.
Keywords: checkin-needed
Whiteboard: [parity-webkit] → [parity-webkit][needs-landing]
Comment on attachment 461460 [details] [diff] [review]
Patch 2 v2: Don't show status overlay when not loading resource

Well, I feel dumb. Now that I finally sat down to rewrap my head around how setupStatusFader() works, I see that this is actually a fairly simple change. Sorry for the delay. :(
Attachment #461460 - Flags: review?(dolske) → review+
http://hg.mozilla.org/mozilla-central/rev/42c8cd0e1a65
http://hg.mozilla.org/mozilla-central/rev/f88258e1ddbe
http://hg.mozilla.org/mozilla-central/rev/137f0ce0e0ca
Status: NEW → RESOLVED
Closed: 14 years ago
Keywords: checkin-needed
Resolution: --- → FIXED
Whiteboard: [parity-webkit][needs-landing] → [parity-webkit]
+  PRBool wasPreloadNone = mPreloadAction == PRELOAD_NONE;

This appears to be an unused variable:

content/src/nsHTMLMediaElement.cpp:749: warning: unused variable‘wasPreloadNone’

Also an order of constructor warning:

nsHTMLMediaElement.h: In constructor ‘nsHTMLMediaElement::nsHTMLMediaElement(already_AddRefed<nsINodeInfo>, PRUint32)’:
nsHTMLMediaElement.h:632: warning: ‘nsHTMLMediaElement::mShuttingDown’ will be initialized after
nsHTMLMediaElement.h:539: warning:   ‘nsHTMLMediaElement::PreloadAction nsHTMLMediaElement::mPreloadAction’
The reason we had test hangs when I landed was that I hadn't replaced some of the uses of the autobuffer attribute with preload='auto'.

This patch replaces all remaining uses of "autobuffer" with "preload='auto'". I grepped my file local tree, and there are no other uses of autobuffer. a/r=test-fix.
Updated <https://developer.mozilla.org/En/HTML/Element/Video>, I expect more will need to be done.
You need to log in before you can comment on or make changes to this bug.