| @@ -150,14 +150,32 @@ exit_label: · 149 unmodified lines |
| 150 | 150 | return false; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | +static void thread_pause(struct ao *ao) |
| 154 | +{ |
| 155 | + struct wasapi_state *state = ao->priv; |
| 156 | + MP_DBG(state, "Thread Pause\n"); |
| 157 | + HRESULT hr = IAudioClient_Stop(state->pAudioClient); |
| 158 | + if (FAILED(hr)) |
| 159 | + MP_ERR(state, "IAudioClient_Stop returned: %s\n", mp_HRESULT_to_str(hr)); |
| 160 | +} |
| 161 | + |
| 162 | +static void thread_unpause(struct ao *ao) |
| 163 | +{ |
| 164 | + struct wasapi_state *state = ao->priv; |
| 165 | + MP_DBG(state, "Thread Unpause\n"); |
| 166 | + HRESULT hr = IAudioClient_Start(state->pAudioClient); |
| 167 | + if (FAILED(hr)) { |
| 168 | + MP_ERR(state, "IAudioClient_Start returned %s\n", |
| 169 | + mp_HRESULT_to_str(hr)); |
| 170 | + } |
| 171 | +} |
| 172 | + |
| 153 | 173 | static void thread_reset(struct ao *ao) |
| 154 | 174 | { |
| 155 | 175 | struct wasapi_state *state = ao->priv; |
| 156 | 176 | HRESULT hr; |
| 157 | 177 | MP_DBG(state, "Thread Reset\n"); |
| 158 | | − hr = IAudioClient_Stop(state->pAudioClient); |
| 159 | | − if (FAILED(hr)) |
| 160 | | − MP_ERR(state, "IAudioClient_Stop returned: %s\n", mp_HRESULT_to_str(hr)); |
| 178 | + thread_pause(ao); |
| 161 | 179 | |
| 162 | 180 | hr = IAudioClient_Reset(state->pAudioClient); |
| 163 | 181 | if (FAILED(hr)) |
| @@ -172,12 +190,7 @@ static void thread_resume(struct ao *ao) · 8 unmodified lines |
| 172 | 190 | MP_DBG(state, "Thread Resume\n"); |
| 173 | 191 | thread_reset(ao); |
| 174 | 192 | thread_feed(ao); |
| 175 | | − |
| 176 | | − HRESULT hr = IAudioClient_Start(state->pAudioClient); |
| 177 | | − if (FAILED(hr)) { |
| 178 | | − MP_ERR(state, "IAudioClient_Start returned %s\n", |
| 179 | | − mp_HRESULT_to_str(hr)); |
| 180 | | − } |
| 193 | + thread_unpause(ao); |
| 181 | 194 | } |
| 182 | 195 | |
| 183 | 196 | static void set_state_and_wakeup_thread(struct ao *ao, |
| @@ -229,6 +242,12 @@ static DWORD __stdcall AudioThread(void *lpParameter) · 45 unmodified lines |
| 229 | 242 | case WASAPI_THREAD_SHUTDOWN: |
| 230 | 243 | thread_reset(ao); |
| 231 | 244 | goto exit_label; |
| 245 | + case WASAPI_THREAD_PAUSE: |
| 246 | + thread_pause(ao); |
| 247 | + break; |
| 248 | + case WASAPI_THREAD_UNPAUSE: |
| 249 | + thread_unpause(ao); |
| 250 | + break; |
| 232 | 251 | default: |
| 233 | 252 | MP_ERR(ao, "Unhandled thread state: %d\n", thread_state); |
| 234 | 253 | } |
| @@ -463,6 +482,12 @@ static void audio_resume(struct ao *ao) · 228 unmodified lines |
| 463 | 482 | set_state_and_wakeup_thread(ao, WASAPI_THREAD_RESUME); |
| 464 | 483 | } |
| 465 | 484 | |
| 485 | +static bool audio_set_pause(struct ao *ao, bool paused) |
| 486 | +{ |
| 487 | + set_state_and_wakeup_thread(ao, paused ? WASAPI_THREAD_PAUSE : WASAPI_THREAD_UNPAUSE); |
| 488 | + return true; |
| 489 | +} |
| 490 | + |
| 466 | 491 | static void hotplug_uninit(struct ao *ao) |
| 467 | 492 | { |
| 468 | 493 | MP_DBG(ao, "Hotplug uninit\n"); |
| @@ -496,6 +521,7 @@ const struct ao_driver audio_out_wasapi = { · 27 unmodified lines |
| 496 | 521 | .control = control, |
| 497 | 522 | .reset = audio_reset, |
| 498 | 523 | .start = audio_resume, |
| 524 | + .set_pause = audio_set_pause, |
| 499 | 525 | .list_devs = wasapi_list_devs, |
| 500 | 526 | .hotplug_init = hotplug_init, |
| 501 | 527 | .hotplug_uninit = hotplug_uninit, |