[MediaFoundation] Volume controls of different media elements should be independent
[WebKit-https.git] / Source / WebCore / platform / graphics / win / MediaPlayerPrivateMediaFoundation.cpp
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