Commit b6ea0d4a authored by jer.noble@apple.com's avatar jer.noble@apple.com

TimeRanges::nearest() returns incorrect results.

https://bugs.webkit.org/show_bug.cgi?id=114483

Reviewed by Eric Carlson.

.:

Add symbols needed by WebCoreTestSupport to exports list.

* Source/autotools/symbols.filter:

Source/WebCore:

Test: media/timeranges-nearest.html

TimeRanges::nearest() has had an incorrect algorithm since its
addition, which has gone unnoticed because no media engine supports
seekable ranges with greater than one entry, and no media engine
seekable ranges with startTime values > 0.

Fix the algorithm used to walk a TimeRanges object; return the closest
time, not the smallest delta between range and target time.
* html/TimeRanges.cpp:
(TimeRanges::nearest):

Add some internal functions to allow us to write LayoutTests for
TimeRanges objects:
* WebCore.exp.in:
* testing/Internals.cpp:
(WebCore::Internals::createTimeRanges):
(WebCore::Internals::closestTimeToTimeRanges):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Add symbols needed by WebCoreTestSupport to the exports list.

* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in:

Source/WebKit/win:

Add symbols needed by WebCoreTestSupport to the exports list.

* WebKit.vcproj/WebKitExports.def.in:

LayoutTests:

* media/timeranges-nearest-expected.txt: Added.
* media/timeranges-nearest.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148288 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 6a333f33
2013-04-12 Jer Noble <jer.noble@apple.com>
TimeRanges::nearest() returns incorrect results.
https://bugs.webkit.org/show_bug.cgi?id=114483
Reviewed by Eric Carlson.
Add symbols needed by WebCoreTestSupport to exports list.
* Source/autotools/symbols.filter:
2013-04-12 Commit Queue <rniwa@webkit.org>
Unreviewed, rolling out r148262.
......
2013-04-12 Jer Noble <jer.noble@apple.com>
TimeRanges::nearest() returns incorrect results.
https://bugs.webkit.org/show_bug.cgi?id=114483
Reviewed by Eric Carlson.
* media/timeranges-nearest-expected.txt: Added.
* media/timeranges-nearest.html: Added.
2013-04-12 Eric Carlson <eric.carlson@apple.com>
Support "forced" subtitles
This tests the ability of a TimeRanges object to return the time nearest its constituent ranges given a target time.
EXPECTED (internals.closestTimeToTimeRanges( .5, timeRanges) == '1') OK
EXPECTED (internals.closestTimeToTimeRanges(1.5, timeRanges) == '1.5') OK
EXPECTED (internals.closestTimeToTimeRanges(2.1, timeRanges) == '2') OK
EXPECTED (internals.closestTimeToTimeRanges(3.0, timeRanges) == '2') OK
EXPECTED (internals.closestTimeToTimeRanges(3.9, timeRanges) == '4') OK
EXPECTED (internals.closestTimeToTimeRanges(5.5, timeRanges) == '5') OK
END OF TEST
<!DOCTYPE html>
<head>
<title>timeranges-nearest</title>
<script src="video-test.js"></script>
<script>
var timeRanges;
function runTest() {
if (!window.internals) {
failTest('This test requires window.internals.');
return;
}
var startTimes = new Float32Array([1, 4]);
var endTimes = new Float32Array([2, 5]);
timeRanges = internals.createTimeRanges(startTimes, endTimes);
testExpected("internals.closestTimeToTimeRanges( .5, timeRanges)", 1);
testExpected("internals.closestTimeToTimeRanges(1.5, timeRanges)", 1.5);
testExpected("internals.closestTimeToTimeRanges(2.1, timeRanges)", 2);
testExpected("internals.closestTimeToTimeRanges(3.0, timeRanges)", 2);
testExpected("internals.closestTimeToTimeRanges(3.9, timeRanges)", 4);
testExpected("internals.closestTimeToTimeRanges(5.5, timeRanges)", 5);
endTest();
}
</script>
</head>
<body onload="runTest()">
<div>This tests the ability of a TimeRanges object to return the time nearest its constituent ranges given a target time.</div>
</body>
2013-04-12 Jer Noble <jer.noble@apple.com>
TimeRanges::nearest() returns incorrect results.
https://bugs.webkit.org/show_bug.cgi?id=114483
Reviewed by Eric Carlson.
Test: media/timeranges-nearest.html
TimeRanges::nearest() has had an incorrect algorithm since its
addition, which has gone unnoticed because no media engine supports
seekable ranges with greater than one entry, and no media engine
seekable ranges with startTime values > 0.
Fix the algorithm used to walk a TimeRanges object; return the closest
time, not the smallest delta between range and target time.
* html/TimeRanges.cpp:
(TimeRanges::nearest):
Add some internal functions to allow us to write LayoutTests for
TimeRanges objects:
* WebCore.exp.in:
* testing/Internals.cpp:
(WebCore::Internals::createTimeRanges):
(WebCore::Internals::closestTimeToTimeRanges):
* testing/Internals.h:
* testing/Internals.idl:
2013-04-12 Eric Carlson <eric.carlson@apple.com>
Support "forced" subtitles
......@@ -2695,6 +2695,11 @@ __ZNK7WebCore16HTMLMediaElement12playbackRateEv
__ZNK7WebCore16HTMLMediaElement8durationEv
__ZN7WebCore16HTMLMediaElement16returnToRealtimeEv
__ZNK7WebCore16HTMLMediaElement12isFullscreenEv
__ZN7WebCore10TimeRanges3addEdd
__ZN7WebCore12toTimeRangesEN3JSC7JSValueE
__ZN7WebCore14toFloat32ArrayEN3JSC7JSValueE
__ZN7WebCore4toJSEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_10TimeRangesE
__ZNK7WebCore10TimeRanges7nearestEd
#endif
#if ENABLE(VIDEO) && !PLATFORM(IOS)
......
......@@ -167,17 +167,22 @@ bool TimeRanges::contain(double time) const
double TimeRanges::nearest(double time) const
{
double closest = 0;
double closestDelta = std::numeric_limits<double>::infinity();
double closestTime = 0;
unsigned count = length();
for (unsigned ndx = 0; ndx < count; ndx++) {
double startTime = start(ndx, IGNORE_EXCEPTION);
double endTime = end(ndx, IGNORE_EXCEPTION);
if (time >= startTime && time <= endTime)
return time;
if (fabs(startTime - time) < closest)
closest = fabsf(startTime - time);
else if (fabs(endTime - time) < closest)
closest = fabsf(endTime - time);
if (fabs(startTime - time) < closestDelta) {
closestTime = startTime;
closestDelta = fabsf(startTime - time);
}
if (fabs(endTime - time) < closestDelta) {
closestTime = endTime;
closestDelta = fabsf(endTime - time);
}
}
return closest;
return closestTime;
}
......@@ -51,9 +51,6 @@
#include "FrameView.h"
#include "HTMLContentElement.h"
#include "HTMLInputElement.h"
#if ENABLE(VIDEO)
#include "HTMLMediaElement.h"
#endif
#include "HTMLNames.h"
#include "HTMLSelectElement.h"
#include "HTMLTextAreaElement.h"
......@@ -137,6 +134,11 @@
#include "PageGroup.h"
#endif
#if ENABLE(VIDEO)
#include "HTMLMediaElement.h"
#include "TimeRanges.h"
#endif
#if ENABLE(SPEECH_SYNTHESIS)
#include "DOMWindowSpeechSynthesis.h"
#include "PlatformSpeechSynthesizerMock.h"
......@@ -2241,4 +2243,23 @@ void Internals::setCaptionDisplayMode(const String& mode, ExceptionCode& ec)
#endif
}
#if ENABLE(VIDEO)
PassRefPtr<TimeRanges> Internals::createTimeRanges(Float32Array* startTimes, Float32Array* endTimes)
{
ASSERT(startTimes && endTimes);
ASSERT(startTimes->length() == endTimes->length());
RefPtr<TimeRanges> ranges = TimeRanges::create();
unsigned count = std::min(startTimes->length(), endTimes->length());
for (unsigned i = 0; i < count; ++i)
ranges->add(startTimes->item(i), endTimes->item(i));
return ranges;
}
double Internals::closestTimeToTimeRanges(double time, TimeRanges* ranges)
{
return ranges->nearest(time);
}
#endif
}
......@@ -32,6 +32,7 @@
#include "ExceptionCodePlaceholder.h"
#include "NodeList.h"
#include <wtf/ArrayBuffer.h>
#include <wtf/Float32Array.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
......@@ -57,6 +58,7 @@ class ShadowRoot;
class WebKitPoint;
class MallocStatistics;
class SerializedScriptValue;
class TimeRanges;
class TypeConversions;
typedef int ExceptionCode;
......@@ -321,6 +323,11 @@ public:
void setPrimaryAudioTrackLanguageOverride(const String&, ExceptionCode&);
void setCaptionDisplayMode(const String&, ExceptionCode&);
#if ENABLE(VIDEO)
PassRefPtr<TimeRanges> createTimeRanges(Float32Array* startTimes, Float32Array* endTimes);
double closestTimeToTimeRanges(double time, TimeRanges*);
#endif
private:
explicit Internals(Document*);
Document* contextDocument() const;
......
......@@ -282,5 +282,9 @@
[Conditional=VIDEO_TRACK] void setPrimaryAudioTrackLanguageOverride(in DOMString language) raises(DOMException);
[Conditional=VIDEO_TRACK] void setCaptionDisplayMode(in DOMString mode) raises (DOMException);
[Conditional=VIDEO] TimeRanges createTimeRanges(in Float32Array startTimes, in Float32Array
endTimes);
[Conditional=VIDEO] double closestTimeToTimeRanges(in double time, in TimeRanges ranges);
boolean isSelectPopupVisible(in Node node);
};
2013-04-12 Jer Noble <jer.noble@apple.com>
TimeRanges::nearest() returns incorrect results.
https://bugs.webkit.org/show_bug.cgi?id=114483
Reviewed by Eric Carlson.
Add symbols needed by WebCoreTestSupport to the exports list.
* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in:
2013-04-11 Rune Lillesveen <rune@opera.com>
Incorrect evaluation of resolution media queries
......
......@@ -427,3 +427,12 @@ EXPORTS
#if ENABLE(WORKERS)
?workerThreadCount@WorkerThread@WebCore@@SAIXZ
#endif
#if ENABLE(VIDEO)
?toTimeRanges@WebCore@@YAPAVTimeRanges@1@VJSValue@JSC@@@Z
?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVTimeRanges@1@@Z
?toFloat32Array@WebCore@@YAPAVFloat32Array@WTF@@VJSValue@JSC@@@Z
?nearest@TimeRanges@WebCore@@QBENN@Z
?add@TimeRanges@WebCore@@QAEXNN@Z
#endif
2013-04-12 Jer Noble <jer.noble@apple.com>
TimeRanges::nearest() returns incorrect results.
https://bugs.webkit.org/show_bug.cgi?id=114483
Reviewed by Eric Carlson.
Add symbols needed by WebCoreTestSupport to the exports list.
* WebKit.vcproj/WebKitExports.def.in:
2013-04-11 Rune Lillesveen <rune@opera.com>
Incorrect evaluation of resolution media queries
......
......@@ -427,3 +427,11 @@ EXPORTS
#if ENABLE(WORKERS)
?workerThreadCount@WorkerThread@WebCore@@SAIXZ
#endif
#if ENABLE(VIDEO)
?toTimeRanges@WebCore@@YAPAVTimeRanges@1@VJSValue@JSC@@@Z
?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVTimeRanges@1@@Z
?toFloat32Array@WebCore@@YAPAVFloat32Array@WTF@@VJSValue@JSC@@@Z
?nearest@TimeRanges@WebCore@@QBENN@Z
?add@TimeRanges@WebCore@@QAEXNN@Z
#endif
......@@ -297,6 +297,11 @@ _ZN7WebCore21SerializedScriptValueC1ERN3WTF6VectorIhLm0ENS1_15CrashOnOverflowEEE
_ZN7WebCore21SerializedScriptValueC1ERN3WTF6VectorIhLj0ENS1_15CrashOnOverflowEEE;
_ZN7WebCore14ClientRectListC1ERKN3WTF6VectorINS_9FloatQuadELm0ENS1_15CrashOnOverflowEEE;
_ZN7WebCore14ClientRectListC1ERKN3WTF6VectorINS_9FloatQuadELj0ENS1_15CrashOnOverflowEEE;
_ZN7WebCore10TimeRanges3addEdd;
_ZN7WebCore12toTimeRangesEN3JSC7JSValueE;
_ZN7WebCore14toFloat32ArrayEN3JSC7JSValueE;
_ZN7WebCore4toJSEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_10TimeRangesE;
_ZNK7WebCore10TimeRanges7nearestEd;
local:
_Z*;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment