Supporting getStartDate and added tests
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Jun 2015 01:43:17 +0000 (01:43 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 27 Jun 2015 01:43:17 +0000 (01:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145676
<rdar://problem/20876076>

Patch by Matt Daiter <mdaiter@apple.com> on 2015-06-26
Reviewed by Brent Fulgham.

Source/WebCore:

Test: http/tests/media/hls/video-controller-getStartDate.html

* bindings/js/JSDOMBinding.cpp:
(WebCore::jsDateOrNaN):
* bindings/js/JSDOMBinding.h:
* bindings/scripts/CodeGeneratorJS.pm: Added features to return
NaN for Date
* bindings/scripts/CodeGeneratorGObject.pm: Needed to add
type checking code for GObject (no date)
(NativeToJSValue):
* bindings/scripts/IDLAttributes.txt:
* html/HTMLMediaElement.cpp: Added getStartDate function
(WebCore::HTMLMediaElement::getStartDate):
* html/HTMLMediaElement.h: Needed to add declarations
* html/HTMLMediaElement.idl: Needed to modify for returning NaN
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::getStartDate):
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h: Added in Mac-specific platform
(WebCore::MediaPlayerPrivateInterface::getStartDate):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::getStartDate):

LayoutTests:

* http/tests/media/hls/video-controller-getStartDate-expected.txt: Added.
* http/tests/media/hls/video-controller-getStartDate.html: Added.
* http/tests/media/resources/hls/test-vod-date-time.m3u8: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@186020 268f45cc-cd09-0410-ab3c-d52691b4dbfc

18 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/media/hls/video-controller-getStartDate-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/media/hls/video-controller-getStartDate.html [new file with mode: 0644]
LayoutTests/http/tests/media/resources/hls/test-vod-date-time.m3u8 [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/IDLAttributes.txt
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLMediaElement.idl
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

index 889d7b4..4f30be1 100644 (file)
@@ -1,3 +1,15 @@
+2015-06-26  Matt Daiter  <mdaiter@apple.com>
+
+        Supporting getStartDate and added tests
+        https://bugs.webkit.org/show_bug.cgi?id=145676
+        <rdar://problem/20876076>
+
+        Reviewed by Brent Fulgham.
+
+        * http/tests/media/hls/video-controller-getStartDate-expected.txt: Added.
+        * http/tests/media/hls/video-controller-getStartDate.html: Added.
+        * http/tests/media/resources/hls/test-vod-date-time.m3u8: Added.
+
 2015-06-26  Dean Jackson  <dino@apple.com>
 
         No audio on animated page with the attached fixed layout epub
diff --git a/LayoutTests/http/tests/media/hls/video-controller-getStartDate-expected.txt b/LayoutTests/http/tests/media/hls/video-controller-getStartDate-expected.txt
new file mode 100644 (file)
index 0000000..ec6f2a7
--- /dev/null
@@ -0,0 +1,9 @@
+Test that getStartDate() returns appropriate NaN or date.
+
+EVENT(canplaythrough)
+EVENT(canplaythrough)
+EXPECTED (isNaN(video.getStartDate()) == 'true') OK
+EXPECTED (video.getStartDate() == 'Wed Nov 03 2010 01:00:00 GMT-0700 (PDT)') OK
+END OF TEST
+
diff --git a/LayoutTests/http/tests/media/hls/video-controller-getStartDate.html b/LayoutTests/http/tests/media/hls/video-controller-getStartDate.html
new file mode 100644 (file)
index 0000000..6a9fe5d
--- /dev/null
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src=../../media-resources/media-file.js></script>
+        <script src=../../media-resources/video-test.js></script>
+        <script>
+            var canPlayThroughCount = 0;
+
+            function canPlayThrough()
+            {
+                consoleWrite("EVENT(canplaythrough)");
+                if (++canPlayThroughCount == 2)
+                    testGetStartDate()
+            }
+
+            function start()
+            {
+                findMediaElement();
+                video = document.getElementById("source_without_start_date");
+                video.src = "../resources/hls/test-vod.m3u8";
+                video.addEventListener('canplaythrough', canPlayThrough, true);
+
+                video = document.getElementById('source_with_start_date');
+                video.src = "../resources/hls/test-vod-date-time.m3u8";
+                video.addEventListener('canplaythrough', canPlayThrough, true);
+            }
+    
+            function testGetStartDate()
+            {
+                video = document.getElementById("source_without_start_date");
+                testExpected("isNaN(video.getStartDate())", true );
+                video = document.getElementById('source_with_start_date');
+                testExpected("video.getStartDate()", "Wed Nov 03 2010 01:00:00 GMT-0700 (PDT)");
+
+                endTest();
+            }
+        </script>
+    </head>
+    <body onload="start()">
+        <video id="source_with_start_date" autoplay="autoplay" width="640" height="480"></video>
+        <video id="source_without_start_date" autoplay="autoplay" width="640" height="480"></video>
+        <p>Test that getStartDate() returns appropriate NaN or date.</p>
+    </body>
+</html>
diff --git a/LayoutTests/http/tests/media/resources/hls/test-vod-date-time.m3u8 b/LayoutTests/http/tests/media/resources/hls/test-vod-date-time.m3u8
new file mode 100644 (file)
index 0000000..86ebd8f
--- /dev/null
@@ -0,0 +1,9 @@
+#EXTM3U
+#EXT-X-TARGETDURATION:6
+#EXT-X-PROGRAM-DATE-TIME:2010-11-03T00:00:00-08:00
+#EXT-X-VERSION:4
+#EXT-X-MEDIA-SEQUENCE:0
+#EXT-X-PLAYLIST-TYPE:VOD
+#EXTINF:6.0272,
+test.ts
+#EXT-X-ENDLIST
index e205c5f..d2f0b61 100644 (file)
@@ -1,3 +1,35 @@
+2015-06-26  Matt Daiter  <mdaiter@apple.com>
+
+        Supporting getStartDate and added tests
+        https://bugs.webkit.org/show_bug.cgi?id=145676
+        <rdar://problem/20876076>
+
+        Reviewed by Brent Fulgham.
+
+        Test: http/tests/media/hls/video-controller-getStartDate.html
+
+        * bindings/js/JSDOMBinding.cpp:
+        (WebCore::jsDateOrNaN):
+        * bindings/js/JSDOMBinding.h:
+        * bindings/scripts/CodeGeneratorJS.pm: Added features to return 
+        NaN for Date
+        * bindings/scripts/CodeGeneratorGObject.pm: Needed to add
+        type checking code for GObject (no date)
+        (NativeToJSValue):
+        * bindings/scripts/IDLAttributes.txt: 
+        * html/HTMLMediaElement.cpp: Added getStartDate function
+        (WebCore::HTMLMediaElement::getStartDate):
+        * html/HTMLMediaElement.h: Needed to add declarations
+        * html/HTMLMediaElement.idl: Needed to modify for returning NaN
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::getStartDate):
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h: Added in Mac-specific platform
+        (WebCore::MediaPlayerPrivateInterface::getStartDate):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::getStartDate):
+
 2015-06-26  Beth Dakin  <bdakin@apple.com>
 
         WebPage::getPositionInformation() should not copy an image that is larger than the  
index 5229747..1b6454d 100644 (file)
@@ -113,6 +113,13 @@ String valueToStringWithUndefinedOrNullCheck(ExecState* exec, JSValue value)
     return value.toString(exec)->value(exec);
 }
 
+JSValue jsDateOrNaN(ExecState* exec, double value)
+{
+    if (std::isnan(value))
+        return jsDoubleNumber(value);
+    return jsDateOrNull(exec, value);
+}
+
 JSValue jsDateOrNull(ExecState* exec, double value)
 {
     if (!std::isfinite(value))
index 660dbb2..a62930a 100644 (file)
@@ -314,6 +314,8 @@ inline uint32_t toUInt32(JSC::ExecState* exec, JSC::JSValue value, IntegerConver
 WEBCORE_EXPORT int64_t toInt64(JSC::ExecState*, JSC::JSValue, IntegerConversionConfiguration);
 WEBCORE_EXPORT uint64_t toUInt64(JSC::ExecState*, JSC::JSValue, IntegerConversionConfiguration);
 
+// Returns a Date instnace for the specified value, or NaN if the date is not a number.
+JSC::JSValue jsDateOrNaN(JSC::ExecState*, double);
 // Returns a Date instance for the specified value, or null if the value is NaN or infinity.
 JSC::JSValue jsDateOrNull(JSC::ExecState*, double);
 // NaN if the value can't be converted to a date.
index 6cfa516..ff5b178 100644 (file)
@@ -366,6 +366,10 @@ sub SkipFunction {
         return 1;
     }
 
+    if ($function->signature->type eq "Date") {
+        return 1;
+    }
+
     return 0;
 }
 
index b0f85a4..3d3c83a 100644 (file)
@@ -3934,6 +3934,13 @@ sub NativeToJSValue
 
     # Need to check Date type before IsPrimitiveType().
     if ($type eq "Date") {
+        my $conv = $signature->extendedAttributes->{"TreatReturnedNaNDateAs"};
+        if (defined $conv) {
+            return "jsDateOrNull(exec, $value)" if $conv eq "Null";
+            return "jsDateOrNaN(exec, $value)" if $conv eq "NaN";
+            
+            die "Unknown value for TreatReturnedNaNDateAs extended attribute";
+        }
         return "jsDateOrNull(exec, $value)";
     }
 
index 7badb13..29c23ce 100644 (file)
@@ -111,6 +111,7 @@ SkipVTableValidation
 StrictTypeChecking
 SuppressToJSObject
 TreatNullAs=NullString
+TreatReturnedNaNDateAs=Null|NaN
 TreatReturnedNullStringAs=Null|Undefined
 TreatUndefinedAs=NullString
 TypedArray=*
index 0f7c0c8..3658e46 100644 (file)
@@ -882,6 +882,11 @@ String HTMLMediaElement::canPlayType(const String& mimeType, const String& keySy
     return canPlay;
 }
 
+double HTMLMediaElement::getStartDate() const
+{
+    return m_player->getStartDate().toDouble();
+}
+
 void HTMLMediaElement::load()
 {
     Ref<HTMLMediaElement> protect(*this); // loadInternal may result in a 'beforeload' event, which can make arbitrary DOM mutations.
index d4b9db8..495c22f 100644 (file)
@@ -178,6 +178,7 @@ public:
     WEBCORE_EXPORT virtual double currentTime() const override;
     virtual void setCurrentTime(double) override;
     virtual void setCurrentTime(double, ExceptionCode&);
+    virtual double getStartDate() const;
     WEBCORE_EXPORT virtual double duration() const override;
     WEBCORE_EXPORT virtual bool paused() const override;
     virtual double defaultPlaybackRate() const override;
index 5309b2e..26cfc8b 100644 (file)
@@ -65,6 +65,7 @@
     // playback state
     [SetterRaisesException] attribute unrestricted double currentTime;
     readonly attribute unrestricted double duration;
+    [TreatReturnedNaNDateAs=NaN] Date getStartDate();
     readonly attribute boolean paused;
     attribute unrestricted double defaultPlaybackRate;
     attribute unrestricted double playbackRate;
index d939d67..294a76d 100644 (file)
@@ -534,6 +534,11 @@ MediaTime MediaPlayer::currentTime() const
     return m_private->currentMediaTime();
 }
 
+MediaTime MediaPlayer::getStartDate() const
+{
+    return m_private->getStartDate();
+}
+
 void MediaPlayer::seekWithTolerance(const MediaTime& time, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance)
 {
     m_private->seekWithTolerance(time, negativeTolerance, positiveTolerance);
index 1665130..df0bcd8 100644 (file)
@@ -380,6 +380,8 @@ public:
     MediaTime startTime() const;
     MediaTime initialTime() const;
 
+    MediaTime getStartDate() const;
+
     double rate() const;
     void setRate(double);
     double requestedRate() const;
index 03caae1..a16b053 100644 (file)
@@ -94,6 +94,8 @@ public:
     virtual double currentTimeDouble() const { return currentTime(); }
     virtual MediaTime currentMediaTime() const { return MediaTime::createWithDouble(currentTimeDouble()); }
 
+    virtual MediaTime getStartDate() const { return MediaTime::createWithDouble(std::numeric_limits<double>::quiet_NaN()); }
+
     virtual void seek(float) { }
     virtual void seekDouble(double time) { seek(time); }
     virtual void seek(const MediaTime& time) { seekDouble(time.toDouble()); }
index d6a04c3..9f581ed 100644 (file)
@@ -207,6 +207,8 @@ private:
 
     virtual bool hasSingleSecurityOrigin() const override;
 
+    MediaTime getStartDate() const override;
+
 #if ENABLE(VIDEO_TRACK)
     virtual bool requiresTextTrackRepresentation() const override;
     virtual void setTextTrackRepresentation(TextTrackRepresentation*) override;
index 5b7da08..c86441c 100644 (file)
@@ -719,6 +719,21 @@ void MediaPlayerPrivateAVFoundationObjC::destroyVideoLayer()
     m_videoLayer = nil;
 }
 
+MediaTime MediaPlayerPrivateAVFoundationObjC::getStartDate() const
+{
+    // Date changes as the track's playback position changes. Must subtract currentTime (offset in seconds) from date offset to get date beginning
+    double date = [[m_avPlayerItem currentDate] timeIntervalSince1970] * 1000;
+
+    // No live streams were made during the epoch (1970). AVFoundation returns 0 if the media file doesn't have a start date
+    if (!date)
+        return MediaTime::invalidTime();
+
+    double currentTime = CMTimeGetSeconds([m_avPlayerItem currentTime]) * 1000;
+
+    // Rounding due to second offset error when subtracting.
+    return MediaTime::createWithDouble(round(date - currentTime));
+}
+
 bool MediaPlayerPrivateAVFoundationObjC::hasAvailableVideoFrame() const
 {
     if (currentRenderingMode() == MediaRenderingToLayer)