diff options
author | Misaki Kasumi <misakikasumi@outlook.com> | 2024-03-27 00:56:47 +0800 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2024-04-03 23:40:05 +0200 |
commit | d419cc562db140d302a7d32d40d67a543d0fbec4 (patch) | |
tree | 8475af657f7c56359c2e2eb087072f42c4f04307 /audio | |
parent | dbc1e3a4597f8740e4885c879ebbe390d3ef72af (diff) | |
download | mpv-d419cc562db140d302a7d32d40d67a543d0fbec4.tar.bz2 mpv-d419cc562db140d302a7d32d40d67a543d0fbec4.tar.xz |
ao_wasapi: support set_pause
Diffstat (limited to 'audio')
-rw-r--r-- | audio/out/ao_wasapi.c | 44 | ||||
-rw-r--r-- | audio/out/ao_wasapi.h | 4 |
2 files changed, 38 insertions, 10 deletions
diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c index ce9581649f..d986d80226 100644 --- a/audio/out/ao_wasapi.c +++ b/audio/out/ao_wasapi.c @@ -150,14 +150,32 @@ exit_label: return false; } +static void thread_pause(struct ao *ao) +{ + struct wasapi_state *state = ao->priv; + MP_DBG(state, "Thread Pause\n"); + HRESULT hr = IAudioClient_Stop(state->pAudioClient); + if (FAILED(hr)) + MP_ERR(state, "IAudioClient_Stop returned: %s\n", mp_HRESULT_to_str(hr)); +} + +static void thread_unpause(struct ao *ao) +{ + struct wasapi_state *state = ao->priv; + MP_DBG(state, "Thread Unpause\n"); + HRESULT hr = IAudioClient_Start(state->pAudioClient); + if (FAILED(hr)) { + MP_ERR(state, "IAudioClient_Start returned %s\n", + mp_HRESULT_to_str(hr)); + } +} + static void thread_reset(struct ao *ao) { struct wasapi_state *state = ao->priv; HRESULT hr; MP_DBG(state, "Thread Reset\n"); - hr = IAudioClient_Stop(state->pAudioClient); - if (FAILED(hr)) - MP_ERR(state, "IAudioClient_Stop returned: %s\n", mp_HRESULT_to_str(hr)); + thread_pause(ao); hr = IAudioClient_Reset(state->pAudioClient); if (FAILED(hr)) @@ -172,12 +190,7 @@ static void thread_resume(struct ao *ao) MP_DBG(state, "Thread Resume\n"); thread_reset(ao); thread_feed(ao); - - HRESULT hr = IAudioClient_Start(state->pAudioClient); - if (FAILED(hr)) { - MP_ERR(state, "IAudioClient_Start returned %s\n", - mp_HRESULT_to_str(hr)); - } + thread_unpause(ao); } static void set_state_and_wakeup_thread(struct ao *ao, @@ -229,6 +242,12 @@ static DWORD __stdcall AudioThread(void *lpParameter) case WASAPI_THREAD_SHUTDOWN: thread_reset(ao); goto exit_label; + case WASAPI_THREAD_PAUSE: + thread_pause(ao); + break; + case WASAPI_THREAD_UNPAUSE: + thread_unpause(ao); + break; default: MP_ERR(ao, "Unhandled thread state: %d\n", thread_state); } @@ -463,6 +482,12 @@ static void audio_resume(struct ao *ao) set_state_and_wakeup_thread(ao, WASAPI_THREAD_RESUME); } +static bool audio_set_pause(struct ao *ao, bool paused) +{ + set_state_and_wakeup_thread(ao, paused ? WASAPI_THREAD_PAUSE : WASAPI_THREAD_UNPAUSE); + return true; +} + static void hotplug_uninit(struct ao *ao) { MP_DBG(ao, "Hotplug uninit\n"); @@ -496,6 +521,7 @@ const struct ao_driver audio_out_wasapi = { .control = control, .reset = audio_reset, .start = audio_resume, + .set_pause = audio_set_pause, .list_devs = wasapi_list_devs, .hotplug_init = hotplug_init, .hotplug_uninit = hotplug_uninit, diff --git a/audio/out/ao_wasapi.h b/audio/out/ao_wasapi.h index fc3a1ef5f3..4e5e9c8a67 100644 --- a/audio/out/ao_wasapi.h +++ b/audio/out/ao_wasapi.h @@ -51,7 +51,9 @@ enum wasapi_thread_state { WASAPI_THREAD_DISPATCH, WASAPI_THREAD_RESUME, WASAPI_THREAD_RESET, - WASAPI_THREAD_SHUTDOWN + WASAPI_THREAD_SHUTDOWN, + WASAPI_THREAD_PAUSE, + WASAPI_THREAD_UNPAUSE, }; typedef struct wasapi_state { |