Title: [186020] trunk
Revision
186020
Author
commit-qu...@webkit.org
Date
2015-06-26 18:43:17 -0700 (Fri, 26 Jun 2015)

Log Message

Supporting getStartDate and added tests
https://bugs.webkit.org/show_bug.cgi?id=145676
<rdar://problem/20876076>

Patch by Matt Daiter <mdai...@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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (186019 => 186020)


--- trunk/LayoutTests/ChangeLog	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/LayoutTests/ChangeLog	2015-06-27 01:43:17 UTC (rev 186020)
@@ -1,3 +1,15 @@
+2015-06-26  Matt Daiter  <mdai...@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  <d...@apple.com>
 
         No audio on animated page with the attached fixed layout epub

Added: trunk/LayoutTests/http/tests/media/hls/video-controller-getStartDate-expected.txt (0 => 186020)


--- trunk/LayoutTests/http/tests/media/hls/video-controller-getStartDate-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/hls/video-controller-getStartDate-expected.txt	2015-06-27 01:43:17 UTC (rev 186020)
@@ -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
+

Added: trunk/LayoutTests/http/tests/media/hls/video-controller-getStartDate.html (0 => 186020)


--- trunk/LayoutTests/http/tests/media/hls/video-controller-getStartDate.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/hls/video-controller-getStartDate.html	2015-06-27 01:43:17 UTC (rev 186020)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src=""
+        <script src=""
+        <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 = ""
+                video.addEventListener('canplaythrough', canPlayThrough, true);
+
+                video = document.getElementById('source_with_start_date');
+                video.src = ""
+                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>

Added: trunk/LayoutTests/http/tests/media/resources/hls/test-vod-date-time.m3u8 (0 => 186020)


--- trunk/LayoutTests/http/tests/media/resources/hls/test-vod-date-time.m3u8	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/resources/hls/test-vod-date-time.m3u8	2015-06-27 01:43:17 UTC (rev 186020)
@@ -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

Modified: trunk/Source/WebCore/ChangeLog (186019 => 186020)


--- trunk/Source/WebCore/ChangeLog	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/ChangeLog	2015-06-27 01:43:17 UTC (rev 186020)
@@ -1,3 +1,35 @@
+2015-06-26  Matt Daiter  <mdai...@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  <bda...@apple.com>
 
         WebPage::getPositionInformation() should not copy an image that is larger than the  

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp (186019 => 186020)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp	2015-06-27 01:43:17 UTC (rev 186020)
@@ -113,6 +113,13 @@
     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))

Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (186019 => 186020)


--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h	2015-06-27 01:43:17 UTC (rev 186020)
@@ -314,6 +314,8 @@
 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.

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm (186019 => 186020)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm	2015-06-27 01:43:17 UTC (rev 186020)
@@ -366,6 +366,10 @@
         return 1;
     }
 
+    if ($function->signature->type eq "Date") {
+        return 1;
+    }
+
     return 0;
 }
 

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (186019 => 186020)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-06-27 01:43:17 UTC (rev 186020)
@@ -3934,6 +3934,13 @@
 
     # 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)";
     }
 

Modified: trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt (186019 => 186020)


--- trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/bindings/scripts/IDLAttributes.txt	2015-06-27 01:43:17 UTC (rev 186020)
@@ -111,6 +111,7 @@
 StrictTypeChecking
 SuppressToJSObject
 TreatNullAs=NullString
+TreatReturnedNaNDateAs=Null|NaN
 TreatReturnedNullStringAs=Null|Undefined
 TreatUndefinedAs=NullString
 TypedArray=*

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (186019 => 186020)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2015-06-27 01:43:17 UTC (rev 186020)
@@ -882,6 +882,11 @@
     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.

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (186019 => 186020)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2015-06-27 01:43:17 UTC (rev 186020)
@@ -178,6 +178,7 @@
     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;

Modified: trunk/Source/WebCore/html/HTMLMediaElement.idl (186019 => 186020)


--- trunk/Source/WebCore/html/HTMLMediaElement.idl	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/html/HTMLMediaElement.idl	2015-06-27 01:43:17 UTC (rev 186020)
@@ -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;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (186019 => 186020)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2015-06-27 01:43:17 UTC (rev 186020)
@@ -534,6 +534,11 @@
     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);

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (186019 => 186020)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h	2015-06-27 01:43:17 UTC (rev 186020)
@@ -380,6 +380,8 @@
     MediaTime startTime() const;
     MediaTime initialTime() const;
 
+    MediaTime getStartDate() const;
+
     double rate() const;
     void setRate(double);
     double requestedRate() const;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (186019 => 186020)


--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h	2015-06-27 01:43:17 UTC (rev 186020)
@@ -94,6 +94,8 @@
     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()); }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (186019 => 186020)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2015-06-27 01:43:17 UTC (rev 186020)
@@ -207,6 +207,8 @@
 
     virtual bool hasSingleSecurityOrigin() const override;
 
+    MediaTime getStartDate() const override;
+
 #if ENABLE(VIDEO_TRACK)
     virtual bool requiresTextTrackRepresentation() const override;
     virtual void setTextTrackRepresentation(TextTrackRepresentation*) override;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (186019 => 186020)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2015-06-26 23:50:25 UTC (rev 186019)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2015-06-27 01:43:17 UTC (rev 186020)
@@ -719,6 +719,21 @@
     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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to