Pipe volume through PlaybackSessionManager/Proxy.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 May 2018 15:50:33 +0000 (15:50 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 May 2018 15:50:33 +0000 (15:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185182

Reviewed by Eric Carlson.

Source/WebCore:

Add support for the volume property to PlaybackSessionModel, and all its clients.

* platform/cocoa/PlaybackSessionModel.h:
(WebCore::PlaybackSessionModelClient::volumeChanged):
* platform/cocoa/PlaybackSessionModelMediaElement.h:
* platform/cocoa/PlaybackSessionModelMediaElement.mm:
(WebCore::PlaybackSessionModelMediaElement::updateForEventName):
(WebCore::PlaybackSessionModelMediaElement::setVolume):
(WebCore::PlaybackSessionModelMediaElement::volume const):
* platform/ios/PlaybackSessionInterfaceAVKit.h:
* platform/ios/PlaybackSessionInterfaceAVKit.mm:
(WebCore::PlaybackSessionInterfaceAVKit::volumeChanged):
* platform/ios/WebAVPlayerController.h:
* platform/ios/WebAVPlayerController.mm:
(-[WebAVPlayerController volume]):
(-[WebAVPlayerController setVolume:]):
(-[WebAVPlayerController volumeChanged:]):
(-[WebAVPlayerController resetMediaState]):
* platform/ios/WebVideoFullscreenControllerAVKit.mm:
(VideoFullscreenControllerContext::volumeChanged):
(VideoFullscreenControllerContext::volume const):
(VideoFullscreenControllerContext::setVolume):

Source/WebKit:

* UIProcess/Cocoa/PlaybackSessionManagerProxy.h:
* UIProcess/Cocoa/PlaybackSessionManagerProxy.messages.in:
* UIProcess/Cocoa/PlaybackSessionManagerProxy.mm:
(WebKit::PlaybackSessionModelContext::setVolume):
(WebKit::PlaybackSessionModelContext::volumeChanged):
(WebKit::PlaybackSessionManagerProxy::volumeChanged):
(WebKit::PlaybackSessionManagerProxy::setVolume):
* WebProcess/cocoa/PlaybackSessionManager.h:
* WebProcess/cocoa/PlaybackSessionManager.messages.in:
* WebProcess/cocoa/PlaybackSessionManager.mm:
(WebKit::PlaybackSessionInterfaceContext::volumeChanged):
(WebKit::PlaybackSessionManager::volumeChanged):
(WebKit::PlaybackSessionManager::setVolume):

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/PlaybackSessionModel.h
Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.h
Source/WebCore/platform/cocoa/PlaybackSessionModelMediaElement.mm
Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.h
Source/WebCore/platform/ios/PlaybackSessionInterfaceAVKit.mm
Source/WebCore/platform/ios/WebAVPlayerController.h
Source/WebCore/platform/ios/WebAVPlayerController.mm
Source/WebCore/platform/ios/WebVideoFullscreenControllerAVKit.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.h
Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.messages.in
Source/WebKit/UIProcess/Cocoa/PlaybackSessionManagerProxy.mm
Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.h
Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.messages.in
Source/WebKit/WebProcess/cocoa/PlaybackSessionManager.mm

index 9c3c01d..15ae406 100644 (file)
@@ -1,3 +1,33 @@
+2018-05-02  Jer Noble  <jer.noble@apple.com>
+
+        Pipe volume through PlaybackSessionManager/Proxy.
+        https://bugs.webkit.org/show_bug.cgi?id=185182
+
+        Reviewed by Eric Carlson.
+
+        Add support for the volume property to PlaybackSessionModel, and all its clients.
+
+        * platform/cocoa/PlaybackSessionModel.h:
+        (WebCore::PlaybackSessionModelClient::volumeChanged):
+        * platform/cocoa/PlaybackSessionModelMediaElement.h:
+        * platform/cocoa/PlaybackSessionModelMediaElement.mm:
+        (WebCore::PlaybackSessionModelMediaElement::updateForEventName):
+        (WebCore::PlaybackSessionModelMediaElement::setVolume):
+        (WebCore::PlaybackSessionModelMediaElement::volume const):
+        * platform/ios/PlaybackSessionInterfaceAVKit.h:
+        * platform/ios/PlaybackSessionInterfaceAVKit.mm:
+        (WebCore::PlaybackSessionInterfaceAVKit::volumeChanged):
+        * platform/ios/WebAVPlayerController.h:
+        * platform/ios/WebAVPlayerController.mm:
+        (-[WebAVPlayerController volume]):
+        (-[WebAVPlayerController setVolume:]):
+        (-[WebAVPlayerController volumeChanged:]):
+        (-[WebAVPlayerController resetMediaState]):
+        * platform/ios/WebVideoFullscreenControllerAVKit.mm:
+        (VideoFullscreenControllerContext::volumeChanged):
+        (VideoFullscreenControllerContext::volume const):
+        (VideoFullscreenControllerContext::setVolume):
+
 2018-05-01  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Unreviewed, fix build in WinCairo
index 747809d..1c4f0e3 100644 (file)
@@ -58,6 +58,7 @@ public:
     virtual void togglePictureInPicture() = 0;
     virtual void toggleMuted() = 0;
     virtual void setMuted(bool) = 0;
+    virtual void setVolume(double) = 0;
 
     enum ExternalPlaybackTargetType { TargetTypeNone, TargetTypeAirPlay, TargetTypeTVOut };
 
@@ -81,6 +82,7 @@ public:
     virtual String externalPlaybackLocalizedDeviceName() const = 0;
     virtual bool wirelessVideoPlaybackDisabled() const = 0;
     virtual bool isMuted() const = 0;
+    virtual double volume() const = 0;
     virtual bool isPictureInPictureActive() const = 0;
 };
 
@@ -101,6 +103,7 @@ public:
     virtual void externalPlaybackChanged(bool /* enabled */, PlaybackSessionModel::ExternalPlaybackTargetType, const String& /* localizedDeviceName */) { }
     virtual void wirelessVideoPlaybackDisabledChanged(bool) { }
     virtual void mutedChanged(bool) { }
+    virtual void volumeChanged(double) { }
     virtual void pictureInPictureActiveChanged(bool) { }
     virtual void ensureControlsManager() { }
 };
index 7a0748e..f5927dc 100644 (file)
@@ -72,6 +72,7 @@ public:
     WEBCORE_EXPORT void togglePictureInPicture() final;
     WEBCORE_EXPORT void toggleMuted() final;
     WEBCORE_EXPORT void setMuted(bool) final;
+    WEBCORE_EXPORT void setVolume(double) final;
 
     double duration() const final;
     double currentTime() const final;
@@ -92,6 +93,7 @@ public:
     String externalPlaybackLocalizedDeviceName() const final;
     bool wirelessVideoPlaybackDisabled() const final;
     bool isMuted() const final;
+    double volume() const final;
     bool isPictureInPictureActive() const final;
 
 protected:
index b8610ef..79a030c 100644 (file)
@@ -181,8 +181,10 @@ void PlaybackSessionModelMediaElement::updateForEventName(const WTF::AtomicStrin
 
     if (all
         || eventName == eventNames().volumechangeEvent) {
-        for (auto client : m_clients)
+        for (auto client : m_clients) {
             client->mutedChanged(isMuted());
+            client->volumeChanged(volume());
+        }
     }
 }
 void PlaybackSessionModelMediaElement::addClient(PlaybackSessionModelClient& client)
@@ -299,6 +301,12 @@ void PlaybackSessionModelMediaElement::setMuted(bool muted)
         m_mediaElement->setMuted(muted);
 }
 
+void PlaybackSessionModelMediaElement::setVolume(double volume)
+{
+    if (m_mediaElement)
+        m_mediaElement->setVolume(volume);
+}
+
 void PlaybackSessionModelMediaElement::updateMediaSelectionOptions()
 {
     if (!m_mediaElement)
@@ -538,6 +546,11 @@ bool PlaybackSessionModelMediaElement::isMuted() const
     return m_mediaElement ? m_mediaElement->muted() : false;
 }
 
+double PlaybackSessionModelMediaElement::volume() const
+{
+    return m_mediaElement ? m_mediaElement->volume() : 0;
+}
+
 bool PlaybackSessionModelMediaElement::isPictureInPictureActive() const
 {
     if (!m_mediaElement)
index ece7715..8580191 100644 (file)
@@ -79,6 +79,7 @@ public:
     WEBCORE_EXPORT void externalPlaybackChanged(bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) override;
     WEBCORE_EXPORT void wirelessVideoPlaybackDisabledChanged(bool) override;
     WEBCORE_EXPORT void mutedChanged(bool) override;
+    WEBCORE_EXPORT void volumeChanged(double) override;
 
     WEBCORE_EXPORT virtual void invalidate();
 
index 3f1dcda..a8fd3b0 100644 (file)
@@ -201,6 +201,11 @@ void PlaybackSessionInterfaceAVKit::mutedChanged(bool muted)
     [m_playerController setMuted:muted];
 }
 
+void PlaybackSessionInterfaceAVKit::volumeChanged(double volume)
+{
+    [m_playerController volumeChanged:volume];
+}
+
 void PlaybackSessionInterfaceAVKit::invalidate()
 {
     if (!m_playbackSessionModel)
index 1e03205..38d7dae 100644 (file)
@@ -71,6 +71,8 @@ class PlaybackSessionInterfaceAVKit;
 @property (retain) AVValueTiming *timing;
 @property (retain) NSArray *seekableTimeRanges;
 @property (getter=isMuted) BOOL muted;
+@property double volume;
+- (void)volumeChanged:(double)volume;
 
 @property (readonly) BOOL hasMediaSelectionOptions;
 @property (readonly) BOOL hasAudioMediaSelectionOptions;
index fc9baad..0d0173e 100644 (file)
@@ -511,6 +511,24 @@ static double WebAVPlayerControllerLiveStreamSeekableTimeRangeMinimumDuration =
         self.delegate->toggleMuted();
 }
 
+- (double)volume
+{
+    return self.delegate ? self.delegate->volume() : 0;
+}
+
+- (void)setVolume:(double)volume
+{
+    if (self.delegate)
+        self.delegate->setVolume(volume);
+}
+
+- (void)volumeChanged:(double)volume
+{
+    UNUSED_PARAM(volume);
+    [self willChangeValueForKey:@"volume"];
+    [self didChangeValueForKey:@"volume"];
+}
+
 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
 {
     using namespace PAL;
@@ -616,6 +634,7 @@ static double WebAVPlayerControllerLiveStreamSeekableTimeRangeMinimumDuration =
     self.maxTiming = nil;
     self.timing = nil;
     self.rate = 0;
+    self.volume = 0;
 
     self.seekableTimeRanges = [NSMutableArray array];
 
index 255914f..ea30f89 100644 (file)
@@ -173,6 +173,7 @@ private:
     void togglePictureInPicture() override { }
     void toggleMuted() override;
     void setMuted(bool) final;
+    void setVolume(double) final;
 
     // PlaybackSessionModelClient
     void durationChanged(double) override;
@@ -186,6 +187,7 @@ private:
     void externalPlaybackChanged(bool enabled, PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) override;
     void wirelessVideoPlaybackDisabledChanged(bool) override;
     void mutedChanged(bool) override;
+    void volumeChanged(double) override;
 
     // VideoFullscreenModel
     void addClient(VideoFullscreenModelClient&) override;
@@ -198,6 +200,7 @@ private:
     bool hasVideo() const override;
     FloatSize videoDimensions() const override;
     bool isMuted() const override;
+    double volume() const override;
     bool isPictureInPictureActive() const override;
 
     HashSet<PlaybackSessionModelClient*> m_playbackClients;
@@ -520,6 +523,18 @@ void VideoFullscreenControllerContext::mutedChanged(bool muted)
         client->mutedChanged(muted);
 }
 
+void VideoFullscreenControllerContext::volumeChanged(double volume)
+{
+    if (WebThreadIsCurrent()) {
+        dispatch_async(dispatch_get_main_queue(), [protectedThis = makeRefPtr(this), volume] {
+            protectedThis->volumeChanged(volume);
+        });
+        return;
+    }
+
+    for (auto& client : m_playbackClients)
+        client->volumeChanged(volume);
+}
 #pragma mark VideoFullscreenModel
 
 void VideoFullscreenControllerContext::addClient(VideoFullscreenModelClient& client)
@@ -600,6 +615,12 @@ bool VideoFullscreenControllerContext::isMuted() const
     return m_playbackModel ? m_playbackModel->isMuted() : false;
 }
 
+double VideoFullscreenControllerContext::volume() const
+{
+    ASSERT(isUIThread());
+    return m_playbackModel ? m_playbackModel->volume() : false;
+}
+
 bool VideoFullscreenControllerContext::isPictureInPictureActive() const
 {
     ASSERT(isUIThread());
@@ -671,6 +692,15 @@ void VideoFullscreenControllerContext::setMuted(bool muted)
     });
 }
 
+void VideoFullscreenControllerContext::setVolume(double volume)
+{
+    ASSERT(isUIThread());
+    WebThreadRun([protectedThis = makeRefPtr(this), this, volume] {
+        if (m_playbackModel)
+            m_playbackModel->setVolume(volume);
+    });
+}
+
 void VideoFullscreenControllerContext::beginScrubbing()
 {
     ASSERT(isUIThread());
index 999639d..95f454b 100644 (file)
@@ -1,3 +1,24 @@
+2018-05-02  Jer Noble  <jer.noble@apple.com>
+
+        Pipe volume through PlaybackSessionManager/Proxy.
+        https://bugs.webkit.org/show_bug.cgi?id=185182
+
+        Reviewed by Eric Carlson.
+
+        * UIProcess/Cocoa/PlaybackSessionManagerProxy.h:
+        * UIProcess/Cocoa/PlaybackSessionManagerProxy.messages.in:
+        * UIProcess/Cocoa/PlaybackSessionManagerProxy.mm:
+        (WebKit::PlaybackSessionModelContext::setVolume):
+        (WebKit::PlaybackSessionModelContext::volumeChanged):
+        (WebKit::PlaybackSessionManagerProxy::volumeChanged):
+        (WebKit::PlaybackSessionManagerProxy::setVolume):
+        * WebProcess/cocoa/PlaybackSessionManager.h:
+        * WebProcess/cocoa/PlaybackSessionManager.messages.in:
+        * WebProcess/cocoa/PlaybackSessionManager.mm:
+        (WebKit::PlaybackSessionInterfaceContext::volumeChanged):
+        (WebKit::PlaybackSessionManager::volumeChanged):
+        (WebKit::PlaybackSessionManager::setVolume):
+
 2018-05-01  Yusuke Suzuki  <utatane.tea@gmail.com>
 
         Use default std::optional if it is provided
index d901ea7..e5d6a49 100644 (file)
@@ -84,6 +84,7 @@ public:
     void externalPlaybackChanged(bool, PlaybackSessionModel::ExternalPlaybackTargetType, const String&);
     void wirelessVideoPlaybackDisabledChanged(bool);
     void mutedChanged(bool);
+    void volumeChanged(double);
     void pictureInPictureActiveChanged(bool);
 
 private:
@@ -111,6 +112,7 @@ private:
     void togglePictureInPicture() final;
     void toggleMuted() final;
     void setMuted(bool) final;
+    void setVolume(double) final;
 
     double playbackStartedTime() const final { return m_playbackStartedTime; }
     double duration() const final { return m_duration; }
@@ -132,6 +134,7 @@ private:
     String externalPlaybackLocalizedDeviceName() const final { return m_externalPlaybackLocalizedDeviceName; }
     bool wirelessVideoPlaybackDisabled() const final { return m_wirelessVideoPlaybackDisabled; }
     bool isMuted() const final { return m_muted; }
+    double volume() const final { return m_volume; }
     bool isPictureInPictureActive() const final { return m_pictureInPictureActive; }
 
     PlaybackSessionManagerProxy* m_manager;
@@ -158,6 +161,7 @@ private:
     String m_externalPlaybackLocalizedDeviceName;
     bool m_wirelessVideoPlaybackDisabled { false };
     bool m_muted { false };
+    double m_volume { 0 };
     bool m_pictureInPictureActive { false };
 };
 
@@ -205,6 +209,7 @@ private:
     void rateChanged(uint64_t contextId, bool isPlaying, double rate);
     void handleControlledElementIDResponse(uint64_t, String) const;
     void mutedChanged(uint64_t contextId, bool muted);
+    void volumeChanged(uint64_t contextId, double volume);
     void pictureInPictureActiveChanged(uint64_t contextId, bool pictureInPictureActive);
 
     // Messages to PlaybackSessionManager
@@ -223,6 +228,7 @@ private:
     void togglePictureInPicture(uint64_t contextId);
     void toggleMuted(uint64_t contextId);
     void setMuted(uint64_t contextId, bool);
+    void setVolume(uint64_t contextId, double);
 
     WebPageProxy* m_page;
     HashMap<uint64_t, ModelInterfaceTuple> m_contextMap;
index 5c0b68e..b151c9c 100644 (file)
@@ -37,6 +37,7 @@ messages -> PlaybackSessionManagerProxy {
     PlaybackStartedTimeChanged(uint64_t contextId, double playbackStartedTime)
     RateChanged(uint64_t contextId, bool isPlaying, double rate)
     MutedChanged(uint64_t contextId, bool muted);
+    VolumeChanged(uint64_t contextId, double volume);
     PictureInPictureActiveChanged(uint64_t contextId, bool pictureInPictureActive)
     SetUpPlaybackControlsManagerWithID(uint64_t contextId)
     ClearPlaybackControlsManager()
index c59953d..adb8e63 100644 (file)
@@ -146,6 +146,12 @@ void PlaybackSessionModelContext::setMuted(bool muted)
         m_manager->setMuted(m_contextId, muted);
 }
 
+void PlaybackSessionModelContext::setVolume(double volume)
+{
+    if (m_manager)
+        m_manager->setVolume(m_contextId, volume);
+}
+
 void PlaybackSessionModelContext::playbackStartedTimeChanged(double playbackStartedTime)
 {
     m_playbackStartedTime = playbackStartedTime;
@@ -258,6 +264,13 @@ void PlaybackSessionModelContext::mutedChanged(bool muted)
         client->mutedChanged(muted);
 }
 
+void PlaybackSessionModelContext::volumeChanged(double volume)
+{
+    m_volume = volume;
+    for (auto* client : m_clients)
+        client->volumeChanged(volume);
+}
+
 void PlaybackSessionModelContext::pictureInPictureActiveChanged(bool active)
 {
     m_pictureInPictureActive = active;
@@ -440,6 +453,11 @@ void PlaybackSessionManagerProxy::mutedChanged(uint64_t contextId, bool muted)
     ensureModel(contextId).mutedChanged(muted);
 }
 
+void PlaybackSessionManagerProxy::volumeChanged(uint64_t contextId, double volume)
+{
+    ensureModel(contextId).volumeChanged(volume);
+}
+
 void PlaybackSessionManagerProxy::durationChanged(uint64_t contextId, double duration)
 {
     ensureModel(contextId).durationChanged(duration);
@@ -549,6 +567,11 @@ void PlaybackSessionManagerProxy::setMuted(uint64_t contextId, bool muted)
     m_page->send(Messages::PlaybackSessionManager::SetMuted(contextId, muted), m_page->pageID());
 }
 
+void PlaybackSessionManagerProxy::setVolume(uint64_t contextId, double volume)
+{
+    m_page->send(Messages::PlaybackSessionManager::SetVolume(contextId, volume), m_page->pageID());
+}
+
 void PlaybackSessionManagerProxy::requestControlledElementID()
 {
     if (m_controlsManagerContextId)
index a844f0e..7f40685 100644 (file)
@@ -88,6 +88,7 @@ private:
     void externalPlaybackChanged(bool enabled, WebCore::PlaybackSessionModel::ExternalPlaybackTargetType, const String& localizedDeviceName) final;
     void wirelessVideoPlaybackDisabledChanged(bool) final;
     void mutedChanged(bool) final;
+    void volumeChanged(double) final;
 
     PlaybackSessionInterfaceContext(PlaybackSessionManager&, uint64_t contextId);
 
@@ -139,6 +140,7 @@ protected:
     void externalPlaybackChanged(uint64_t contextId, bool enabled, WebCore::PlaybackSessionModel::ExternalPlaybackTargetType, String localizedDeviceName);
     void wirelessVideoPlaybackDisabledChanged(uint64_t contextId, bool);
     void mutedChanged(uint64_t contextId, bool);
+    void volumeChanged(uint64_t contextId, double);
 
     // Messages from PlaybackSessionManagerProxy
     void play(uint64_t contextId);
@@ -157,6 +159,7 @@ protected:
     void togglePictureInPicture(uint64_t contextId);
     void toggleMuted(uint64_t contextId);
     void setMuted(uint64_t contextId, bool muted);
+    void setVolume(uint64_t contextId, double volume);
 
     WebPage* m_page;
     HashMap<WebCore::HTMLMediaElement*, uint64_t> m_mediaElements;
index b6e166f..4d2a786 100644 (file)
@@ -39,5 +39,6 @@ messages -> PlaybackSessionManager {
     TogglePictureInPicture(uint64_t contextId)
     ToggleMuted(uint64_t contextId)
     SetMuted(uint64_t contextId, bool muted)
+    SetVolume(uint64_t contextId, double volume)
 }
 #endif
index acf52f6..c5df31e 100644 (file)
@@ -155,6 +155,12 @@ void PlaybackSessionInterfaceContext::mutedChanged(bool muted)
         m_manager->mutedChanged(m_contextId, muted);
 }
 
+void PlaybackSessionInterfaceContext::volumeChanged(double volume)
+{
+    if (m_manager)
+        m_manager->volumeChanged(m_contextId, volume);
+}
+
 #pragma mark - PlaybackSessionManager
 
 Ref<PlaybackSessionManager> PlaybackSessionManager::create(WebPage& page)
@@ -378,6 +384,11 @@ void PlaybackSessionManager::mutedChanged(uint64_t contextId, bool muted)
     m_page->send(Messages::PlaybackSessionManagerProxy::MutedChanged(contextId, muted));
 }
 
+void PlaybackSessionManager::volumeChanged(uint64_t contextId, double volume)
+{
+    m_page->send(Messages::PlaybackSessionManagerProxy::VolumeChanged(contextId, volume));
+}
+
 #pragma mark Messages from PlaybackSessionManagerProxy:
 
 void PlaybackSessionManager::play(uint64_t contextId)
@@ -477,6 +488,12 @@ void PlaybackSessionManager::setMuted(uint64_t contextId, bool muted)
     ensureModel(contextId).setMuted(muted);
 }
 
+void PlaybackSessionManager::setVolume(uint64_t contextId, double volume)
+{
+    UserGestureIndicator indicator(ProcessingUserGesture);
+    ensureModel(contextId).setVolume(volume);
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS) || (PLATFORM(MAC) && ENABLE(VIDEO_PRESENTATION_MODE))