Bug 135814 - [Mac, iOS] Some media content never reaches full 'loaded' state
Summary: [Mac, iOS] Some media content never reaches full 'loaded' state
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac All
: P2 Normal
Assignee: Brent Fulgham
Keywords: InRadar
Depends on:
Reported: 2014-08-11 14:21 PDT by Brent Fulgham
Modified: 2014-08-12 00:29 PDT (History)
5 users (show)

See Also:

Patch (14.38 KB, patch)
2014-08-11 17:51 PDT, Brent Fulgham
jer.noble: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brent Fulgham 2014-08-11 14:21:34 PDT
Some <media> sources, including certain advertisements, cause pages to get stuck loading because they never achieve a full loaded state.
Comment 1 Brent Fulgham 2014-08-11 14:24:09 PDT
This bug is difficult to reproduce, because it is highly reliant on the media being served.

The bug happens because the duration returned by the AVFoundation media engine is getting truncated while being relayed from AVFoundation up to the HTMLMediaElement. This causes the value to be slightly different from the "end point" timestamp registered by AVFoundation for the media in question.

When the rounding conditions are just right, the truncated value is rounded down and we never reach 100% loaded.
Comment 2 Brent Fulgham 2014-08-11 14:24:25 PDT
Comment 3 Brent Fulgham 2014-08-11 14:24:51 PDT
This seems to have been introduced in <http://trac.webkit.org/changeset/169568>
Comment 4 Brent Fulgham 2014-08-11 14:37:05 PDT
The correct solution to this problem is already available in <https://bugs.webkit.org/show_bug.cgi?id=133579>, but is on hold for the time being.

To work around the issue, we will do the following:

1. Check if the last played time range value, when cast to a float, matches the duration.
2. If it does, return the duration as this value instead of the slightly-different rounded version.

Once completed, instead of this failure case:

> v=$0
< <video controls autoplay name=​"media" style=​"max-width:​ 100%;​ max-height:​ 100%;​">​…​</video>​
> v.duration
< 25.066667556762695
> v.buffered.end(0)
< 25.066666666666666

... we should see
> v.duration
< 25.066667556762695
> v.buffered.end(0)
< 25.066667556762695
Comment 5 Brent Fulgham 2014-08-11 17:34:12 PDT
It turns out it's a little easier. We simply have some truncation happening in the MediaPlayerPrivate layer for AVFoundation. Things were already ready to hook up to the double version of these methods, so we can simply start using them and avoid this problem.
Comment 6 Brent Fulgham 2014-08-11 17:51:36 PDT
Created attachment 236419 [details]
Comment 7 Jer Noble 2014-08-11 18:09:22 PDT
Comment on attachment 236419 [details]

View in context: https://bugs.webkit.org/attachment.cgi?id=236419&action=review

Looks good! r=me.  It's good to see all those narrowPrecisionToFloat() calls gone.

> LayoutTests/platform/mac/media/video-seek-past-end-paused-expected.txt:15
> -EXPECTED (mediaElement.currentTime == 'mediaElement.duration'), OBSERVED '6.026666641235352' FAIL
> +EXPECTED (mediaElement.currentTime == 'mediaElement.duration'), OBSERVED '6.026666666666666' FAIL

Ahh, this is how you know it's working. ;)
Comment 8 Brent Fulgham 2014-08-11 18:12:37 PDT
Committed r172425: <http://trac.webkit.org/changeset/172425>
Comment 9 Jon Lee 2014-08-11 18:21:42 PDT
Should we revert this change once the patch for 113579 goes in?
Comment 10 Brent Fulgham 2014-08-11 22:12:16 PDT
(In reply to comment #9)
> Should we revert this change once the patch for 113579 goes in?

No. I think the changes in that bug cover a lot of the same code, using MediaTime instead of float or double. Once we switch to that version, these changes will be removed as part of that merge.
Comment 11 Csaba Osztrogonác 2014-08-12 00:29:58 PDT
(In reply to comment #8)
> Committed r172425: <http://trac.webkit.org/changeset/172425>

It broke the Apple Windows build:

    1>WebCore.lib(MediaPlayerPrivateAVFoundationCF.obj) : error LNK2001: unresolved external symbol "private: virtual float __thiscall WebCore::MediaPlayerPrivateAVFoundationCF::currentTime(void)const " (?currentTime@MediaPlayerPrivateAVFoundationCF@WebCore@@EBEMXZ)
     1>C:\cygwin\home\buildbot\slave\win-release\build\WebKitBuild\Release\bin32\WebKit.dll : fatal error LNK1120: 1 unresolved externals
     1>Done Building Project "C:\cygwin\home\buildbot\slave\win-release\build\Source\WebKit\WebKit.vcxproj\WebKit\WebKit.vcxproj" (Build target(s)) -- FAILED.