Commit 15e0df6c authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

mmdevice: merge volume/mute update code and fix initial volume

parent 9577406b
...@@ -287,8 +287,9 @@ vlc_AudioSessionEvents_OnSimpleVolumeChanged(IAudioSessionEvents *this, ...@@ -287,8 +287,9 @@ vlc_AudioSessionEvents_OnSimpleVolumeChanged(IAudioSessionEvents *this,
msg_Dbg(aout, "simple volume changed: %f, muting %sabled", vol, msg_Dbg(aout, "simple volume changed: %f, muting %sabled", vol,
mute ? "en" : "dis"); mute ? "en" : "dis");
aout_VolumeReport(aout, cbrtf(vol)); EnterCriticalSection(&sys->lock);
aout_MuteReport(aout, mute == TRUE); WakeConditionVariable(&sys->work); /* implicit state: vol & mute */
LeaveCriticalSection(&sys->lock);
(void) ctx; (void) ctx;
return S_OK; return S_OK;
} }
...@@ -772,24 +773,7 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it) ...@@ -772,24 +773,7 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
hr = IAudioSessionManager_GetSimpleAudioVolume(manager, guid, FALSE, hr = IAudioSessionManager_GetSimpleAudioVolume(manager, guid, FALSE,
&volume); &volume);
if (SUCCEEDED(hr)) if (FAILED(hr))
{ /* Get current values _after_ registering for notification */
BOOL mute;
float level;
hr = ISimpleAudioVolume_GetMute(volume, &mute);
if (SUCCEEDED(hr))
aout_MuteReport(aout, mute != FALSE);
else
msg_Err(aout, "cannot get mute (error 0x%lx)", hr);
hr = ISimpleAudioVolume_GetMasterVolume(volume, &level);
if (SUCCEEDED(hr))
aout_VolumeReport(aout, level);
else
msg_Err(aout, "cannot get mute (error 0x%lx)", hr);
}
else
msg_Err(aout, "cannot get simple volume (error 0x%lx)", hr); msg_Err(aout, "cannot get simple volume (error 0x%lx)", hr);
} }
else else
...@@ -802,32 +786,54 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it) ...@@ -802,32 +786,54 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
/* Main loop (adjust volume as long as device is unchanged) */ /* Main loop (adjust volume as long as device is unchanged) */
while (sys->device == NULL) while (sys->device == NULL)
{ {
if (volume != NULL && sys->volume >= 0.f) if (volume != NULL)
{
float level;
hr = ISimpleAudioVolume_GetMasterVolume(volume, &level);
if (SUCCEEDED(hr))
aout_VolumeReport(aout, cbrtf(level));
else
msg_Err(aout, "cannot get master volume (error 0x%lx)", hr);
level = sys->volume;
if (level >= 0.f)
{ {
if (sys->volume > 1.f) if (level > 1.f)
sys->volume = 1.f; level = 1.f;
hr = ISimpleAudioVolume_SetMasterVolume(volume, sys->volume, NULL); hr = ISimpleAudioVolume_SetMasterVolume(volume, level, NULL);
if (FAILED(hr)) if (FAILED(hr))
msg_Err(aout, "cannot set master volume (error 0x%lx)", hr); msg_Err(aout, "cannot set master volume (error 0x%lx)",
sys->volume = -1.f; hr);
} }
sys->volume = -1.f;
if (volume != NULL && sys->mute >= 0) BOOL mute;
hr = ISimpleAudioVolume_GetMute(volume, &mute);
if (SUCCEEDED(hr))
aout_MuteReport(aout, mute != FALSE);
else
msg_Err(aout, "cannot get mute (error 0x%lx)", hr);
if (sys->mute >= 0)
{ {
hr = ISimpleAudioVolume_SetMute(volume, mute = sys->mute ? TRUE : FALSE;
sys->mute ? TRUE : FALSE, NULL);
hr = ISimpleAudioVolume_SetMute(volume, mute, NULL);
if (FAILED(hr)) if (FAILED(hr))
msg_Err(aout, "cannot set mute (error 0x%lx)", hr); msg_Err(aout, "cannot set mute (error 0x%lx)", hr);
}
sys->mute = -1; sys->mute = -1;
} }
SleepConditionVariableCS(&sys->work, &sys->lock, INFINITE); SleepConditionVariableCS(&sys->work, &sys->lock, INFINITE);
} }
LeaveCriticalSection(&sys->lock);
if (manager != NULL) if (manager != NULL)
{ { /* Deregister callbacks *without* the lock */
/* Deregister session control */
if (volume != NULL) if (volume != NULL)
ISimpleAudioVolume_Release(volume); ISimpleAudioVolume_Release(volume);
...@@ -841,6 +847,7 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it) ...@@ -841,6 +847,7 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
IAudioSessionManager_Release(manager); IAudioSessionManager_Release(manager);
} }
EnterCriticalSection(&sys->lock);
IMMDevice_Release(sys->dev); IMMDevice_Release(sys->dev);
sys->dev = NULL; sys->dev = NULL;
return S_OK; return S_OK;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment