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
150150 return false;
151151 }
152152
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+
153173 static void thread_reset(struct ao *ao)
154174 {
155175 struct wasapi_state *state = ao->priv;
156176 HRESULT hr;
157177 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);
161179
162180 hr = IAudioClient_Reset(state->pAudioClient);
163181 if (FAILED(hr))
@@ -172,12 +190,7 @@ static void thread_resume(struct ao *ao) · 8 unmodified lines
172190 MP_DBG(state, "Thread Resume\n");
173191 thread_reset(ao);
174192 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);
181194 }
182195
183196 static void set_state_and_wakeup_thread(struct ao *ao,
@@ -229,6 +242,12 @@ static DWORD __stdcall AudioThread(void *lpParameter) · 45 unmodified lines
229242 case WASAPI_THREAD_SHUTDOWN:
230243 thread_reset(ao);
231244 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;
232251 default:
233252 MP_ERR(ao, "Unhandled thread state: %d\n", thread_state);
234253 }
@@ -463,6 +482,12 @@ static void audio_resume(struct ao *ao) · 228 unmodified lines
463482 set_state_and_wakeup_thread(ao, WASAPI_THREAD_RESUME);
464483 }
465484
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+
466491 static void hotplug_uninit(struct ao *ao)
467492 {
468493 MP_DBG(ao, "Hotplug uninit\n");
@@ -496,6 +521,7 @@ const struct ao_driver audio_out_wasapi = { · 27 unmodified lines
496521 .control = control,
497522 .reset = audio_reset,
498523 .start = audio_resume,
524+ .set_pause = audio_set_pause,
499525 .list_devs = wasapi_list_devs,
500526 .hotplug_init = hotplug_init,
501527 .hotplug_uninit = hotplug_uninit,
audio/out/ao_wasapi.h+3−1
@@ -51,7 +51,9 @@ enum wasapi_thread_state { · 50 unmodified lines
5151 WASAPI_THREAD_DISPATCH,
5252 WASAPI_THREAD_RESUME,
5353 WASAPI_THREAD_RESET,
54− WASAPI_THREAD_SHUTDOWN
54+ WASAPI_THREAD_SHUTDOWN,
55+ WASAPI_THREAD_PAUSE,
56+ WASAPI_THREAD_UNPAUSE,
5557 };
5658
5759 typedef 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