summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2014-11-14 05:59:22 -0800
committerKevin Mitchell <kevmitch@gmail.com>2014-11-17 04:31:22 -0800
commit9371990bd14c74815babdd45ed3dd007087f60bc (patch)
tree9524f615aa00347e5c0c3d85b5345d7fb3bd53ab /audio
parent6c512892d4691e004c453af5f0c7f3837d87b7fb (diff)
downloadmpv-9371990bd14c74815babdd45ed3dd007087f60bc.tar.bz2
mpv-9371990bd14c74815babdd45ed3dd007087f60bc.tar.xz
ao/wasapi: add retry loop on AUDCLNT_E_DEVICE_IN_USE
this works around reinitializing too fast on device property changes
Diffstat (limited to 'audio')
-rwxr-xr-xaudio/out/ao_wasapi_utils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index 937c144650..681c32ecde 100755
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -30,6 +30,7 @@
#include "audio/format.h"
#include "osdep/io.h"
+#include "osdep/timer.h"
#define MIXER_DEFAULT_LABEL L"mpv - video player"
@@ -943,6 +944,8 @@ HRESULT wasapi_thread_init(struct ao *ao)
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
HRESULT hr;
MP_DBG(ao, "Init wasapi thread\n");
+ int64_t retry_wait = 1;
+retry:
state->initial_volume = -1.0;
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
@@ -990,6 +993,15 @@ HRESULT wasapi_thread_init(struct ao *ao)
MP_DBG(ao, "Fixing format\n");
hr = fix_format(state);
+ if ( (hr == AUDCLNT_E_DEVICE_IN_USE ||
+ hr == AUDCLNT_E_DEVICE_INVALIDATED) &&
+ retry_wait <= 8 ) {
+ wasapi_thread_uninit(ao);
+ MP_WARN(ao, "Retrying in %ld us\n", retry_wait);
+ mp_sleep_us(retry_wait);
+ retry_wait *= 2;
+ goto retry;
+ }
EXIT_ON_ERROR(hr);
MP_DBG(ao, "Creating proxies\n");