1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-29 11:12:56 +00:00

ao_wasapi: remove volume "restore" on exit

It was complicated and not even very intuitive to the user.
If you are controlling the master volume, you just have to be
prepared to deal with the consequences.
This commit is contained in:
Kevin Mitchell 2015-12-18 21:11:42 -08:00
parent aa5f04c7a0
commit d1cbff37be
3 changed files with 10 additions and 48 deletions

View File

@ -288,6 +288,7 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
{
struct wasapi_state *state = ao->priv;
ao_control_vol_t *vol = arg;
float volume;
BOOL mute;
if (state->opt_exclusive) {
@ -295,22 +296,13 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
switch (cmd) {
case AOCONTROL_GET_VOLUME:
IAudioEndpointVolume_GetMasterVolumeLevelScalar(state->pEndpointVolumeProxy,
&state->audio_volume);
/* check to see if user manually changed volume through mixer;
this information is used in exclusive mode for restoring the mixer volume on uninit */
if (state->audio_volume != state->previous_volume) {
MP_VERBOSE(state, "Mixer difference: %.2g now, expected %.2g\n",
state->audio_volume, state->previous_volume);
state->initial_volume = state->audio_volume;
}
vol->left = vol->right = 100.0f * state->audio_volume;
&volume);
vol->left = vol->right = 100.0f * volume;
return CONTROL_OK;
case AOCONTROL_SET_VOLUME:
state->audio_volume = vol->left / 100.f;
volume = vol->left / 100.f;
IAudioEndpointVolume_SetMasterVolumeLevelScalar(state->pEndpointVolumeProxy,
state->audio_volume, NULL);
state->previous_volume = state->audio_volume;
volume, NULL);
return CONTROL_OK;
case AOCONTROL_GET_MUTE:
IAudioEndpointVolume_GetMute(state->pEndpointVolumeProxy, &mute);
@ -328,24 +320,13 @@ static int control(struct ao *ao, enum aocontrol cmd, void *arg)
switch (cmd) {
case AOCONTROL_GET_VOLUME:
ISimpleAudioVolume_GetMasterVolume(state->pAudioVolumeProxy,
&state->audio_volume);
/* check to see if user manually changed volume through mixer;
this information is used in exclusive mode for restoring the mixer volume on uninit */
if (state->audio_volume != state->previous_volume) {
MP_VERBOSE(state, "Mixer difference: %.2g now, expected %.2g\n",
state->audio_volume, state->previous_volume);
state->initial_volume = state->audio_volume;
}
vol->left = vol->right = 100.0f * state->audio_volume;
&volume);
vol->left = vol->right = 100.0f * volume;
return CONTROL_OK;
case AOCONTROL_SET_VOLUME:
state->audio_volume = vol->left / 100.f;
volume = vol->left / 100.f;
ISimpleAudioVolume_SetMasterVolume(state->pAudioVolumeProxy,
state->audio_volume, NULL);
state->previous_volume = state->audio_volume;
volume, NULL);
return CONTROL_OK;
case AOCONTROL_GET_MUTE:
ISimpleAudioVolume_GetMute(state->pAudioVolumeProxy, &mute);

View File

@ -59,9 +59,6 @@ typedef struct wasapi_state {
/* volume control */
DWORD vol_hw_support;
float audio_volume;
float previous_volume;
float initial_volume;
/* WASAPI handles, owned by audio thread */
IMMDevice *pDevice;

View File

@ -1057,8 +1057,7 @@ HRESULT wasapi_thread_init(struct ao *ao)
struct wasapi_state *state = ao->priv;
MP_DBG(ao, "Init wasapi thread\n");
int64_t retry_wait = 1;
retry:
state->initial_volume = -1.0;
retry: ;
HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
&IID_IMMDeviceEnumerator, (void **)&state->pEnumerator);
@ -1122,16 +1121,6 @@ retry:
hr = create_proxies(state);
EXIT_ON_ERROR(hr);
MP_DBG(ao, "Read volume levels\n");
if (state->opt_exclusive) {
IAudioEndpointVolume_GetMasterVolumeLevelScalar(state->pEndpointVolume,
&state->initial_volume);
} else {
ISimpleAudioVolume_GetMasterVolume(state->pAudioVolume,
&state->initial_volume);
}
state->previous_volume = state->initial_volume;
wasapi_change_init(ao, false);
MP_DBG(ao, "Init wasapi thread done\n");
@ -1151,11 +1140,6 @@ void wasapi_thread_uninit(struct ao *ao)
IAudioClient_Stop(state->pAudioClient);
wasapi_change_uninit(ao);
if (state->opt_exclusive && state->pEndpointVolume && state->initial_volume > 0 ) {
IAudioEndpointVolume_SetMasterVolumeLevelScalar(state->pEndpointVolume,
state->initial_volume, NULL);
}
destroy_proxies(state);
SAFE_RELEASE(state->pRenderClient, IAudioRenderClient_Release(state->pRenderClient));