History

ao_wasapi: support set_pause

Misaki Kasumi committed 2 years ago

Commit d419cc51 parent dbc1e3a2 files · +38 −10Browse files

Unified · Split

2 files
  1. audio/out/ao_wasapi.c +35 −9
  2. audio/out/ao_wasapi.h +3 −1
audio/out/ao_wasapi.c+35−9
@@ -150,14 +150,32 @@ exit_label: · 149 unmodified lines
150 return false;150 return false;
151}151}
152 152
153static 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
162static 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
153static void thread_reset(struct ao *ao)173static void thread_reset(struct ao *ao)
154{174{
155 struct wasapi_state *state = ao->priv;175 struct wasapi_state *state = ao->priv;
156 HRESULT hr;176 HRESULT hr;
157 MP_DBG(state, "Thread Reset\n");177 MP_DBG(state, "Thread Reset\n");
158 hr = IAudioClient_Stop(state->pAudioClient);178 thread_pause(ao);
159 if (FAILED(hr))
160 MP_ERR(state, "IAudioClient_Stop returned: %s\n", mp_HRESULT_to_str(hr));
161 179
162 hr = IAudioClient_Reset(state->pAudioClient);180 hr = IAudioClient_Reset(state->pAudioClient);
163 if (FAILED(hr))181 if (FAILED(hr))
@@ -172,12 +190,7 @@ static void thread_resume(struct ao *ao) · 8 unmodified lines
172 MP_DBG(state, "Thread Resume\n");190 MP_DBG(state, "Thread Resume\n");
173 thread_reset(ao);191 thread_reset(ao);
174 thread_feed(ao);192 thread_feed(ao);
175 193 thread_unpause(ao);
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 }
181}194}
182 195
183static void set_state_and_wakeup_thread(struct ao *ao,196static void set_state_and_wakeup_thread(struct ao *ao,
@@ -229,6 +242,12 @@ static DWORD __stdcall AudioThread(void *lpParameter) · 45 unmodified lines
229 case WASAPI_THREAD_SHUTDOWN:242 case WASAPI_THREAD_SHUTDOWN:
230 thread_reset(ao);243 thread_reset(ao);
231 goto exit_label;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 default:251 default:
233 MP_ERR(ao, "Unhandled thread state: %d\n", thread_state);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 set_state_and_wakeup_thread(ao, WASAPI_THREAD_RESUME);482 set_state_and_wakeup_thread(ao, WASAPI_THREAD_RESUME);
464}483}
465 484
485static 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
466static void hotplug_uninit(struct ao *ao)491static void hotplug_uninit(struct ao *ao)
467{492{
468 MP_DBG(ao, "Hotplug uninit\n");493 MP_DBG(ao, "Hotplug uninit\n");
@@ -496,6 +521,7 @@ const struct ao_driver audio_out_wasapi = { · 27 unmodified lines
496 .control = control,521 .control = control,
497 .reset = audio_reset,522 .reset = audio_reset,
498 .start = audio_resume,523 .start = audio_resume,
524 .set_pause = audio_set_pause,
499 .list_devs = wasapi_list_devs,525 .list_devs = wasapi_list_devs,
500 .hotplug_init = hotplug_init,526 .hotplug_init = hotplug_init,
501 .hotplug_uninit = hotplug_uninit,527 .hotplug_uninit = hotplug_uninit,
audio/out/ao_wasapi.h+3−1
@@ -51,7 +51,9 @@ enum wasapi_thread_state { · 50 unmodified lines
51 WASAPI_THREAD_DISPATCH,51 WASAPI_THREAD_DISPATCH,
52 WASAPI_THREAD_RESUME,52 WASAPI_THREAD_RESUME,
53 WASAPI_THREAD_RESET,53 WASAPI_THREAD_RESET,
54 WASAPI_THREAD_SHUTDOWN54 WASAPI_THREAD_SHUTDOWN,
55 WASAPI_THREAD_PAUSE,
56 WASAPI_THREAD_UNPAUSE,
55};57};
56 58
57typedef struct wasapi_state {59typedef struct wasapi_state {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t