Title: [166312] trunk/Source
Revision
166312
Author
commit-qu...@webkit.org
Date
2014-03-26 13:17:39 -0700 (Wed, 26 Mar 2014)

Log Message

Implement hasLiveStreamingContent property in WebAVPlayerController
https://bugs.webkit.org/show_bug.cgi?id=128684

Patch by Jeremy Jones <jere...@apple.com> on 2014-03-26
Reviewed by Simon Fraser.

Source/WebCore:

* WebCore.exp.in:
Add export for WebVideoFullscreenInterfaceAVKit::setSeekableRanges().

* platform/ios/WebVideoFullscreenInterface.h:
Add setSeekableRanges()

* platform/ios/WebVideoFullscreenInterfaceAVKit.h:
Add setSeekableRanges()

* platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
Remove vestigial playerLayer property. Add seekableTimeRanges property.

(-[WebAVPlayerController dealloc]):
Release _seekableTimeRanges.
Remove references to _playerLayer.

(-[WebAVPlayerController hasLiveStreamingContent]):
Implement based on duration. Live stream has an infinite duration.

(+[WebAVPlayerController keyPathsForValuesAffectingHasLiveStreamingContent]):
Describe dependent keys for computed property hasLiveStreamingContent.

(-[WebAVPlayerController skipBackwardThirtySeconds:]):
Seek back 30 seconds if that time is in the seekable ranges.

(-[WebAVPlayerController gotoEndOfSeekableRanges:]):
Jump to live by going to the of the seekable ranges.

(WebVideoFullscreenInterfaceAVKit::setSeekableRanges):
Convert TimeRange to CMTimeRange.

* platform/ios/WebVideoFullscreenModelMediaElement.mm:
(WebVideoFullscreenModelMediaElement::setMediaElement):
Set initial seekable ranges.

(WebVideoFullscreenModelMediaElement::handleEvent):
Update seekable ranges when time changes.

Source/WebKit2:

Plumb through the seekable ranges to the fullscreen interface.

* UIProcess/ios/WebVideoFullscreenManagerProxy.h:
Add declaration for setSeekableRangesVector()

* UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
Add interface SetSeekableRangesVector()

* UIProcess/ios/WebVideoFullscreenManagerProxy.mm:
(WebKit::WebVideoFullscreenManagerProxy::setSeekableRangesVector):
Add setSeekableRangesVector that translates the vector into a TimeRanges and calls setSeekableRanges()

* WebProcess/ios/WebVideoFullscreenManager.h:
Add setSeekableRanges()

* WebProcess/ios/WebVideoFullscreenManager.mm:
(WebKit::WebVideoFullscreenManager::setSeekableRanges):
setSeekableRanges() converts TimeRanges to Vector and calls SetSeekableRangesVector()

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (166311 => 166312)


--- trunk/Source/WebCore/ChangeLog	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebCore/ChangeLog	2014-03-26 20:17:39 UTC (rev 166312)
@@ -1,3 +1,48 @@
+2014-03-26  Jeremy Jones  <jere...@apple.com>
+
+        Implement hasLiveStreamingContent property in WebAVPlayerController
+        https://bugs.webkit.org/show_bug.cgi?id=128684
+
+        Reviewed by Simon Fraser.
+
+        * WebCore.exp.in:
+        Add export for WebVideoFullscreenInterfaceAVKit::setSeekableRanges().
+
+        * platform/ios/WebVideoFullscreenInterface.h:
+        Add setSeekableRanges()
+
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.h:
+        Add setSeekableRanges()
+
+        * platform/ios/WebVideoFullscreenInterfaceAVKit.mm:
+        Remove vestigial playerLayer property. Add seekableTimeRanges property.
+
+        (-[WebAVPlayerController dealloc]):
+        Release _seekableTimeRanges.
+        Remove references to _playerLayer.
+
+        (-[WebAVPlayerController hasLiveStreamingContent]):
+        Implement based on duration. Live stream has an infinite duration.
+
+        (+[WebAVPlayerController keyPathsForValuesAffectingHasLiveStreamingContent]):
+        Describe dependent keys for computed property hasLiveStreamingContent.
+
+        (-[WebAVPlayerController skipBackwardThirtySeconds:]):
+        Seek back 30 seconds if that time is in the seekable ranges.
+
+        (-[WebAVPlayerController gotoEndOfSeekableRanges:]):
+        Jump to live by going to the of the seekable ranges.
+
+        (WebVideoFullscreenInterfaceAVKit::setSeekableRanges):
+        Convert TimeRange to CMTimeRange.
+
+        * platform/ios/WebVideoFullscreenModelMediaElement.mm:
+        (WebVideoFullscreenModelMediaElement::setMediaElement):
+        Set initial seekable ranges.
+
+        (WebVideoFullscreenModelMediaElement::handleEvent):
+        Update seekable ranges when time changes.
+
 2014-03-26  Brent Fulgham  <bfulg...@apple.com>
 
         Fix OS X build.

Modified: trunk/Source/WebCore/WebCore.exp.in (166311 => 166312)


--- trunk/Source/WebCore/WebCore.exp.in	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-03-26 20:17:39 UTC (rev 166312)
@@ -3279,6 +3279,7 @@
 __ZN7WebCore32WebVideoFullscreenInterfaceAVKit14exitFullscreenEv
 __ZN7WebCore32WebVideoFullscreenInterfaceAVKit14setCurrentTimeEdd
 __ZN7WebCore32WebVideoFullscreenInterfaceAVKit15enterFullscreenER7CALayer
+__ZN7WebCore32WebVideoFullscreenInterfaceAVKit17setSeekableRangesERKNS_10TimeRangesE
 __ZN7WebCore32WebVideoFullscreenInterfaceAVKit18setVideoDimensionsEbff
 __ZN7WebCore32WebVideoFullscreenInterfaceAVKit26setWebVideoFullscreenModelEPNS_23WebVideoFullscreenModelE
 __ZN7WebCore32WebVideoFullscreenInterfaceAVKit35setWebVideoFullscreenChangeObserverEPNS_32WebVideoFullscreenChangeObserverE

Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterface.h (166311 => 166312)


--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterface.h	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterface.h	2014-03-26 20:17:39 UTC (rev 166312)
@@ -29,10 +29,10 @@
 
 #if PLATFORM(IOS)
 
-#import <WebCore/PlatformLayer.h>
-
 namespace WebCore {
     
+class TimeRanges;
+
 class WebVideoFullscreenInterface {
 public:
     virtual ~WebVideoFullscreenInterface() { };
@@ -40,6 +40,7 @@
     virtual void setCurrentTime(double currentTime, double anchorTime) = 0;
     virtual void setRate(bool isPlaying, float playbackRate) = 0;
     virtual void setVideoDimensions(bool hasVideo, float width, float height) = 0;
+    virtual void setSeekableRanges(const TimeRanges&) = 0;
 };
 
 }

Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h (166311 => 166312)


--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.h	2014-03-26 20:17:39 UTC (rev 166312)
@@ -80,6 +80,7 @@
     virtual void setCurrentTime(double currentTime, double anchorTime) override;
     virtual void setRate(bool isPlaying, float playbackRate) override;
     virtual void setVideoDimensions(bool hasVideo, float width, float height) override;
+    virtual void setSeekableRanges(const TimeRanges&) override;
 
     virtual void enterFullscreen(PlatformLayer&);
     virtual void exitFullscreen();

Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm (166311 => 166312)


--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenInterfaceAVKit.mm	2014-03-26 20:17:39 UTC (rev 166312)
@@ -32,6 +32,7 @@
 
 #import "Logging.h"
 #import "WebVideoFullscreenModel.h"
+#import <AVFoundation/AVTime.h>
 #import <AVKit/AVKit.h>
 #import <AVKit/AVPlayerController.h>
 #import <AVKit/AVPlayerViewController_Private.h>
@@ -41,6 +42,7 @@
 #import <CoreMedia/CMTime.h>
 #import <UIKit/UIKit.h>
 #import <WebCore/SoftLinking.h>
+#import <WebCore/TimeRanges.h>
 #import <WebCore/WebCoreThreadRun.h>
 #import <wtf/RetainPtr.h>
 
@@ -64,11 +66,14 @@
 SOFT_LINK_FRAMEWORK(CoreMedia)
 SOFT_LINK(CoreMedia, CMTimeMakeWithSeconds, CMTime, (Float64 seconds, int32_t preferredTimeScale), (seconds, preferredTimeScale))
 SOFT_LINK(CoreMedia, CMTimeGetSeconds, Float64, (CMTime time), (time))
+SOFT_LINK(CoreMedia, CMTimeMake, CMTime, (int64_t value, int32_t timescale), (value, timescale))
+SOFT_LINK(CoreMedia, CMTimeRangeContainsTime, Boolean, (CMTimeRange range, CMTime time), (range, time))
+SOFT_LINK(CoreMedia, CMTimeRangeMake, CMTimeRange, (CMTime start, CMTime duration), (start, duration))
+SOFT_LINK(CoreMedia, CMTimeSubtract, CMTime, (CMTime minuend, CMTime subtrahend), (minuend, subtrahend))
 
 @interface WebAVPlayerController : NSObject <AVPlayerViewControllerDelegate>
 
 @property(retain) AVPlayerController* playerControllerProxy;
-@property(retain) CALayer<AVVideoLayer> *playerLayer;
 @property(assign) WebVideoFullscreenModel* delegate;
 
 @property BOOL canPlay;
@@ -87,6 +92,7 @@
 @property(retain) NSArray *loadedTimeRanges;
 @property AVPlayerControllerStatus status;
 @property(retain) AVValueTiming *timing;
+@property(retain) NSArray *seekableTimeRanges;
 
 - (BOOL)playerViewController:(AVPlayerViewController *)playerViewController shouldDismissWithReason:(AVPlayerViewControllerDismissalReason)reason;
 @end
@@ -106,8 +112,8 @@
 - (void)dealloc
 {
     [_playerControllerProxy release];
-    [_playerLayer release];
     [_loadedTimeRanges release];
+    [_seekableTimeRanges release];
     [_timing release];
     [super dealloc];
 }
@@ -174,6 +180,52 @@
     self.delegate->seekToTime(time);
 }
 
+- (BOOL)hasLiveStreamingContent
+{
+    if ([self status] == AVPlayerControllerStatusReadyToPlay)
+        return [self contentDuration] == std::numeric_limits<float>::infinity();
+    return NO;
+}
+
++ (NSSet *)keyPathsForValuesAffectingHasLiveStreamingContent
+{
+    return [NSSet setWithObjects:@"contentDuration", @"status", nil];
+}
+
+- (void)skipBackwardThirtySeconds:(id)sender
+{
+    UNUSED_PARAM(sender);
+    BOOL isTimeWithinSeekableTimeRanges = NO;
+    CMTime currentTime = CMTimeMakeWithSeconds([[self timing] currentValue], 1000);
+    CMTime thirtySecondsBeforeCurrentTime = CMTimeSubtract(currentTime, CMTimeMake(30, 1));
+    
+    for (NSValue *seekableTimeRangeValue in [self seekableTimeRanges]) {
+        if (CMTimeRangeContainsTime([seekableTimeRangeValue CMTimeRangeValue], thirtySecondsBeforeCurrentTime)) {
+            isTimeWithinSeekableTimeRanges = YES;
+            break;
+        }
+    }
+    
+    if (isTimeWithinSeekableTimeRanges)
+        [self seekToTime:CMTimeGetSeconds(thirtySecondsBeforeCurrentTime)];
+}
+
+- (void)gotoEndOfSeekableRanges:(id)sender
+{
+    UNUSED_PARAM(sender);
+    NSTimeInterval timeAtEndOfSeekableTimeRanges = NAN;
+    
+    for (NSValue *seekableTimeRangeValue in [self seekableTimeRanges]) {
+        CMTimeRange seekableTimeRange = [seekableTimeRangeValue CMTimeRangeValue];
+        NSTimeInterval endOfSeekableTimeRange = CMTimeGetSeconds(CMTimeRangeGetEnd(seekableTimeRange));
+        if (isnan(timeAtEndOfSeekableTimeRanges) || endOfSeekableTimeRange > timeAtEndOfSeekableTimeRanges)
+            timeAtEndOfSeekableTimeRanges = endOfSeekableTimeRange;
+    }
+    
+    if (!isnan(timeAtEndOfSeekableTimeRanges))
+        [self seekToTime:timeAtEndOfSeekableTimeRanges];
+}
+
 @end
 
 @interface WebAVVideoLayer : CALayer <AVVideoLayer>
@@ -311,6 +363,22 @@
     playerController().contentDimensions = CGSizeMake(width, height);
 }
 
+void WebVideoFullscreenInterfaceAVKit::setSeekableRanges(const TimeRanges& timeRanges)
+{
+    NSMutableArray* seekableRanges = [NSMutableArray array];
+    ExceptionCode exceptionCode;
+
+    for (unsigned i = 0; i < timeRanges.length(); i++) {
+        double start = timeRanges.start(i, exceptionCode);
+        double end = timeRanges.end(i, exceptionCode);
+        
+        CMTimeRange range = CMTimeRangeMake(CMTimeMakeWithSeconds(start, 1000), CMTimeMakeWithSeconds(end-start, 1000));
+        [seekableRanges addObject:[NSValue valueWithCMTimeRange:range]];
+    }
+    
+    playerController().seekableTimeRanges = seekableRanges;
+}
+
 void WebVideoFullscreenInterfaceAVKit::enterFullscreen(PlatformLayer& videoLayer)
 {
     __block RefPtr<WebVideoFullscreenInterfaceAVKit> protect(this);

Modified: trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelMediaElement.mm (166311 => 166312)


--- trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelMediaElement.mm	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebCore/platform/ios/WebVideoFullscreenModelMediaElement.mm	2014-03-26 20:17:39 UTC (rev 166312)
@@ -40,6 +40,7 @@
 #import <WebCore/HTMLMediaElement.h>
 #import <WebCore/HTMLVideoElement.h>
 #import <WebCore/SoftLinking.h>
+#import <WebCore/TimeRanges.h>
 #import <WebCore/WebCoreThreadRun.h>
 #import <QuartzCore/CoreAnimation.h>
 #import <wtf/RetainPtr.h>
@@ -83,6 +84,7 @@
     m_isListening = true;
 
     m_videoFullscreenInterface->setDuration(m_mediaElement->duration());
+    m_videoFullscreenInterface->setSeekableRanges(*m_mediaElement->seekable());
     m_videoFullscreenInterface->setRate(m_mediaElement->isPlaying(), m_mediaElement->playbackRate());
 
     m_videoFullscreenInterface->setCurrentTime(m_mediaElement->currentTime(), [[NSProcessInfo processInfo] systemUptime]);
@@ -107,8 +109,11 @@
         || event->type() == eventNames().playEvent
         || event->type() == eventNames().ratechangeEvent)
         m_videoFullscreenInterface->setRate(m_mediaElement->isPlaying(), m_mediaElement->playbackRate());
-    else if (event->type() == eventNames().timeupdateEvent)
+    else if (event->type() == eventNames().timeupdateEvent) {
         m_videoFullscreenInterface->setCurrentTime(m_mediaElement->currentTime(), [[NSProcessInfo processInfo] systemUptime]);
+        // FIXME: 130788 - find a better event to update seekable ranges from.
+        m_videoFullscreenInterface->setSeekableRanges(*m_mediaElement->seekable());
+    }
 }
 
 void WebVideoFullscreenModelMediaElement::setVideoFullscreenLayer(PlatformLayer* videoLayer)

Modified: trunk/Source/WebKit2/ChangeLog (166311 => 166312)


--- trunk/Source/WebKit2/ChangeLog	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebKit2/ChangeLog	2014-03-26 20:17:39 UTC (rev 166312)
@@ -1,3 +1,29 @@
+2014-03-26  Jeremy Jones  <jere...@apple.com>
+
+        Implement hasLiveStreamingContent property in WebAVPlayerController
+        https://bugs.webkit.org/show_bug.cgi?id=128684
+
+        Reviewed by Simon Fraser.
+
+        Plumb through the seekable ranges to the fullscreen interface.
+
+        * UIProcess/ios/WebVideoFullscreenManagerProxy.h:
+        Add declaration for setSeekableRangesVector()
+
+        * UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in:
+        Add interface SetSeekableRangesVector()
+
+        * UIProcess/ios/WebVideoFullscreenManagerProxy.mm:
+        (WebKit::WebVideoFullscreenManagerProxy::setSeekableRangesVector):
+        Add setSeekableRangesVector that translates the vector into a TimeRanges and calls setSeekableRanges()
+
+        * WebProcess/ios/WebVideoFullscreenManager.h:
+        Add setSeekableRanges()
+
+        * WebProcess/ios/WebVideoFullscreenManager.mm:
+        (WebKit::WebVideoFullscreenManager::setSeekableRanges):
+        setSeekableRanges() converts TimeRanges to Vector and calls SetSeekableRangesVector()
+
 2014-03-26  Simon Fraser  <simon.fra...@apple.com>
 
         Add a custom behavior flag to GraphicsLayer, piped down to PlatformCALayer, for scrolling layers

Modified: trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h (166311 => 166312)


--- trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.h	2014-03-26 20:17:39 UTC (rev 166312)
@@ -53,6 +53,7 @@
 
     // Translate to FullscreenInterface
     virtual void enterFullscreenWithID(uint32_t);
+    virtual void setSeekableRangesVector(Vector<std::pair<double, double>>&);
 
     // Fullscreen Observer
     virtual void requestExitFullscreen() override;

Modified: trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in (166311 => 166312)


--- trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.messages.in	2014-03-26 20:17:39 UTC (rev 166312)
@@ -24,6 +24,7 @@
 messages -> WebVideoFullscreenManagerProxy {
     SetCurrentTime(double currentTime, double hostTime)
     SetVideoDimensions(bool hasVideo, unsigned width, unsigned height)
+    SetSeekableRangesVector(Vector<std::pair<double, double>> ranges);
     SetDuration(double duration)
     SetRate(bool isPlaying, double rate)
     EnterFullscreenWithID(uint32_t videoLayerID)

Modified: trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm (166311 => 166312)


--- trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebKit2/UIProcess/ios/WebVideoFullscreenManagerProxy.mm	2014-03-26 20:17:39 UTC (rev 166312)
@@ -34,6 +34,7 @@
 #include "WebVideoFullscreenManagerProxyMessages.h"
 #include <QuartzCore/CoreAnimation.h>
 #include <WebKitSystemInterface.h>
+#include <WebCore/TimeRanges.h>
 
 using namespace WebCore;
 
@@ -63,7 +64,21 @@
     m_layerHost = WKMakeRenderLayer(videoLayerID);
     enterFullscreen(*m_layerHost.get());
 }
+    
+void WebVideoFullscreenManagerProxy::setSeekableRangesVector(Vector<std::pair<double, double>>& ranges)
+{
+    RefPtr<TimeRanges> timeRanges = TimeRanges::create();
+    for (const auto& range : ranges)
+    {
+        ASSERT(isfinite(range.first));
+        ASSERT(isfinite(range.second));
+        ASSERT(range.second >= range.first);
+        timeRanges->add(range.first, range.second);
+    }
 
+    setSeekableRanges(*timeRanges);
+}
+
 void WebVideoFullscreenManagerProxy::requestExitFullscreen()
 {
     m_page->send(Messages::WebVideoFullscreenManager::RequestExitFullscreen(), m_page->pageID());

Modified: trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h (166311 => 166312)


--- trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.h	2014-03-26 20:17:39 UTC (rev 166312)
@@ -70,6 +70,7 @@
     virtual void setCurrentTime(double currentTime, double anchorTime) override;
     virtual void setRate(bool isPlaying, float playbackRate) override;
     virtual void setVideoDimensions(bool hasVideo, float width, float height) override;
+    virtual void setSeekableRanges(const WebCore::TimeRanges&) override;
     
     // additional incoming
     virtual void didEnterFullscreen();

Modified: trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm (166311 => 166312)


--- trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm	2014-03-26 19:52:07 UTC (rev 166311)
+++ trunk/Source/WebKit2/WebProcess/ios/WebVideoFullscreenManager.mm	2014-03-26 20:17:39 UTC (rev 166312)
@@ -37,6 +37,7 @@
 #include <WebCore/HTMLVideoElement.h>
 #include <WebCore/PlatformCALayer.h>
 #include <WebCore/Settings.h>
+#include <WebCore/TimeRanges.h>
 #include <WebCore/WebCoreThreadRun.h>
 
 using namespace WebCore;
@@ -119,7 +120,21 @@
 {
     m_page->send(Messages::WebVideoFullscreenManagerProxy::SetVideoDimensions(hasVideo, width, height), m_page->pageID());
 }
+    
+void WebVideoFullscreenManager::setSeekableRanges(const WebCore::TimeRanges& timeRanges)
+{
+    Vector<std::pair<double, double>> rangesVector;
+    
+    for (unsigned i = 0; i < timeRanges.length(); i++) {
+        ExceptionCode exceptionCode;
+        double start = timeRanges.start(i, exceptionCode);
+        double end = timeRanges.end(i, exceptionCode);
+        rangesVector.append(std::pair<double,double>(start, end));
+    }
 
+    m_page->send(Messages::WebVideoFullscreenManagerProxy::SetSeekableRangesVector(std::move(rangesVector)), m_page->pageID());
+}
+
 void WebVideoFullscreenManager::didEnterFullscreen()
 {
     m_isAnimating = false;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to