WMF: each media player now has its own volume.

Instead of setting the volume on the audio session, which is shared by
all QMediaPlayers, we now set the volume on the media player's own audio
stream. This results in all QMediaPlayers correctly having independent
volumes.

[ChangeLog][QtMultimedia][Windows] QMediaPlayer::setVolume() does not
affect the volume of other QMediaPlayers anymore.

Task-number: QTBUG-30317
Change-Id: I8ea8ec47fc86127da01dc5c8247fb6f72c834630
Reviewed-by: Wouter Huysentruit <wouter_huysentruit@hotmail.com>
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
This commit is contained in:
Yoann Lopes
2014-03-04 17:22:47 +01:00
committed by The Qt Project
parent a07530d606
commit 7d894ca0aa
2 changed files with 26 additions and 28 deletions

View File

@@ -1325,8 +1325,10 @@ void MFPlayerSession::setVolume(int volume)
if (m_volume == volume) if (m_volume == volume)
return; return;
m_volume = volume; m_volume = volume;
if (m_volumeControl)
m_volumeControl->SetMasterVolume(m_volume * 0.01f); if (!m_muted)
setVolumeInternal(volume);
emit volumeChanged(m_volume); emit volumeChanged(m_volume);
} }
@@ -1340,11 +1342,26 @@ void MFPlayerSession::setMuted(bool muted)
if (m_muted == muted) if (m_muted == muted)
return; return;
m_muted = muted; m_muted = muted;
if (m_volumeControl)
m_volumeControl->SetMute(BOOL(m_muted)); setVolumeInternal(muted ? 0 : m_volume);
emit mutedChanged(m_muted); emit mutedChanged(m_muted);
} }
void MFPlayerSession::setVolumeInternal(int volume)
{
if (m_volumeControl) {
quint32 channelCount = 0;
if (!SUCCEEDED(m_volumeControl->GetChannelCount(&channelCount))
|| channelCount == 0)
return;
float scaled = volume * 0.01f;
for (quint32 i = 0; i < channelCount; ++i)
m_volumeControl->SetChannelVolume(i, scaled);
}
}
int MFPlayerSession::bufferStatus() int MFPlayerSession::bufferStatus()
{ {
if (!m_netsourceStatistics) if (!m_netsourceStatistics)
@@ -1570,10 +1587,8 @@ void MFPlayerSession::handleSessionEvent(IMFMediaEvent *sessionEvent)
} }
} }
if (SUCCEEDED(MFGetService(m_session, MR_POLICY_VOLUME_SERVICE, IID_PPV_ARGS(&m_volumeControl)))) { if (SUCCEEDED(MFGetService(m_session, MR_STREAM_VOLUME_SERVICE, IID_PPV_ARGS(&m_volumeControl))))
m_volumeControl->SetMasterVolume(m_volume * 0.01f); setVolumeInternal(m_muted ? 0 : m_volume);
m_volumeControl->SetMute(m_muted);
}
DWORD dwCharacteristics = 0; DWORD dwCharacteristics = 0;
m_sourceResolver->mediaSource()->GetCharacteristics(&dwCharacteristics); m_sourceResolver->mediaSource()->GetCharacteristics(&dwCharacteristics);
@@ -1619,25 +1634,6 @@ void MFPlayerSession::handleSessionEvent(IMFMediaEvent *sessionEvent)
break; break;
case MEEndOfPresentationSegment: case MEEndOfPresentationSegment:
break; break;
case MEAudioSessionVolumeChanged:
if (m_volumeControl) {
float currentVolume = 1;
if (SUCCEEDED(m_volumeControl->GetMasterVolume(&currentVolume))) {
int scaledVolume = currentVolume * 100;
if (scaledVolume != m_volume) {
m_volume = scaledVolume;
emit volumeChanged(scaledVolume);
}
}
BOOL currentMuted = FALSE;
if (SUCCEEDED(m_volumeControl->GetMute(&currentMuted))) {
if (currentMuted != BOOL(m_muted)) {
m_muted = bool(currentMuted);
emit mutedChanged(m_muted);
}
}
}
break;
case MESessionTopologyStatus: { case MESessionTopologyStatus: {
UINT32 status; UINT32 status;
if (SUCCEEDED(sessionEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, &status))) { if (SUCCEEDED(sessionEvent->GetUINT32(MF_EVENT_TOPOLOGY_STATUS, &status))) {

View File

@@ -152,7 +152,7 @@ private:
IMFPresentationClock *m_presentationClock; IMFPresentationClock *m_presentationClock;
IMFRateControl *m_rateControl; IMFRateControl *m_rateControl;
IMFRateSupport *m_rateSupport; IMFRateSupport *m_rateSupport;
IMFSimpleAudioVolume *m_volumeControl; IMFAudioStreamVolume *m_volumeControl;
IPropertyStore *m_netsourceStatistics; IPropertyStore *m_netsourceStatistics;
PROPVARIANT m_varStart; PROPVARIANT m_varStart;
UINT64 m_duration; UINT64 m_duration;
@@ -218,6 +218,8 @@ private:
int m_volume; int m_volume;
bool m_muted; bool m_muted;
void setVolumeInternal(int volume);
void createSession(); void createSession();
void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD); void setupPlaybackTopology(IMFMediaSource *source, IMFPresentationDescriptor *sourcePD);
IMFTopologyNode* addSourceNode(IMFTopology* topology, IMFMediaSource* source, IMFTopologyNode* addSourceNode(IMFTopology* topology, IMFMediaSource* source,