[MediaFoundation] Volume controls of different media elements should be independent
authorannulen@yandex.ru <annulen@yandex.ru@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 18:42:44 +0000 (18:42 +0000)
committerannulen@yandex.ru <annulen@yandex.ru@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 9 Jun 2017 18:42:44 +0000 (18:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172967

Based on patch by Vitaly Slobodin <vitaliy.slobodin@gmail.com>
Reviewed by Alex Christensen.

IMFSimpleAudioVolume interface controls master volume of the
application. We should use IMFAudioStreamVolume interface instead.

No new tests needed.

* platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
(WebCore::MediaPlayerPrivateMediaFoundation::MediaPlayerPrivateMediaFoundation):
(WebCore::MediaPlayerPrivateMediaFoundation::setAllChannelVolumes):
(WebCore::MediaPlayerPrivateMediaFoundation::setVolume):
(WebCore::MediaPlayerPrivateMediaFoundation::setMuted):
* platform/graphics/win/MediaPlayerPrivateMediaFoundation.h:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.h

index 3d8d2f9..c136c39 100644 (file)
@@ -1,3 +1,23 @@
+2017-06-06 Konstantin Tokarev  <annulen@yandex.ru>
+
+        [MediaFoundation] Volume controls of different media elements should be independent
+        https://bugs.webkit.org/show_bug.cgi?id=172967
+
+        Based on patch by Vitaly Slobodin <vitaliy.slobodin@gmail.com>
+        Reviewed by Alex Christensen.
+
+        IMFSimpleAudioVolume interface controls master volume of the
+        application. We should use IMFAudioStreamVolume interface instead.
+
+        No new tests needed.
+
+        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
+        (WebCore::MediaPlayerPrivateMediaFoundation::MediaPlayerPrivateMediaFoundation):
+        (WebCore::MediaPlayerPrivateMediaFoundation::setAllChannelVolumes):
+        (WebCore::MediaPlayerPrivateMediaFoundation::setVolume):
+        (WebCore::MediaPlayerPrivateMediaFoundation::setMuted):
+        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.h:
+
 2017-06-09  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Image should clear its ImageObserver* when CachedImage releases the last reference to its RefCounted<ImageObserver>
index d996505..ba58c11 100644 (file)
@@ -94,6 +94,7 @@ MediaPlayerPrivateMediaFoundation::MediaPlayerPrivateMediaFoundation(MediaPlayer
     , m_hasVideo(false)
     , m_preparingToPlay(false)
     , m_hwndVideo(nullptr)
+    , m_volume(1.0)
     , m_networkState(MediaPlayer::Empty)
     , m_readyState(MediaPlayer::HaveNothing)
     , m_weakPtrFactory(this)
@@ -301,16 +302,27 @@ bool MediaPlayerPrivateMediaFoundation::paused() const
     return m_paused;
 }
 
-void MediaPlayerPrivateMediaFoundation::setVolume(float volume)
+bool MediaPlayerPrivateMediaFoundation::setAllChannelVolumes(float volume)
 {
     if (!MFGetServicePtr())
-        return;
+        return false;
 
-    COMPtr<IMFSimpleAudioVolume> audioVolume;
-    if (SUCCEEDED(MFGetServicePtr()(m_mediaSession.get(), MR_POLICY_VOLUME_SERVICE, __uuidof(IMFSimpleAudioVolume), (void **)&audioVolume))) {
-        HRESULT hr = audioVolume->SetMasterVolume(volume);
-        ASSERT(SUCCEEDED(hr));
-    }
+    COMPtr<IMFAudioStreamVolume> audioVolume;
+    if (!SUCCEEDED(MFGetServicePtr()(m_mediaSession.get(), MR_STREAM_VOLUME_SERVICE, __uuidof(IMFAudioStreamVolume), (void **)&audioVolume)))
+        return false;
+
+    UINT32 channelsCount;
+    HRESULT hr = audioVolume->GetChannelCount(&channelsCount);
+    ASSERT(SUCCEEDED(hr));
+
+    Vector<float> volumes(channelsCount, volume);
+    return SUCCEEDED(audioVolume->SetAllVolumes(channelsCount, volumes.data()));
+}
+
+void MediaPlayerPrivateMediaFoundation::setVolume(float volume)
+{
+    if (setAllChannelVolumes(volume))
+        m_volume = volume;
 }
 
 bool MediaPlayerPrivateMediaFoundation::supportsMuting() const
@@ -320,14 +332,7 @@ bool MediaPlayerPrivateMediaFoundation::supportsMuting() const
 
 void MediaPlayerPrivateMediaFoundation::setMuted(bool muted)
 {
-    if (!MFGetServicePtr())
-        return;
-
-    COMPtr<IMFSimpleAudioVolume> audioVolume;
-    if (SUCCEEDED(MFGetServicePtr()(m_mediaSession.get(), MR_POLICY_VOLUME_SERVICE, __uuidof(IMFSimpleAudioVolume), (void **)&audioVolume))) {
-        HRESULT hr = audioVolume->SetMute(muted ? TRUE : FALSE);
-        ASSERT(SUCCEEDED(hr));
-    }
+    setAllChannelVolumes(muted ? 0.0 : m_volume);
 }
 
 MediaPlayer::NetworkState MediaPlayerPrivateMediaFoundation::networkState() const
index 9b0f1cd..93541f5 100644 (file)
@@ -111,6 +111,7 @@ private:
     bool m_hasAudio;
     bool m_hasVideo;
     bool m_preparingToPlay;
+    float m_volume;
     HWND m_hwndVideo;
     MediaPlayer::NetworkState m_networkState;
     MediaPlayer::ReadyState m_readyState;
@@ -165,6 +166,8 @@ private:
 
     static LRESULT CALLBACK VideoViewWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
 
+    bool setAllChannelVolumes(float);
+
     class MediaPlayerListener {
     public:
         MediaPlayerListener() { }