summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2014-11-18 07:26:11 -0800
committerKevin Mitchell <kevmitch@gmail.com>2014-11-18 07:26:11 -0800
commitcaf2fbf68896c36b4c4d20d3fd37327b5187dc01 (patch)
tree0a875a64c74f648c93d2fef29a4115d0d2702356
parentda03334a731ad25c0c048c0df7aa757e7dd2ecdd (diff)
downloadmpv-caf2fbf68896c36b4c4d20d3fd37327b5187dc01.tar.bz2
mpv-caf2fbf68896c36b4c4d20d3fd37327b5187dc01.tar.xz
ao/wasapi: only retry resizing the buffer once
like the MSDN example: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370875%28v=vs.85%29.aspx
-rwxr-xr-xaudio/out/ao_wasapi_utils.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c
index 657a98aae3..7923f3cb56 100755
--- a/audio/out/ao_wasapi_utils.c
+++ b/audio/out/ao_wasapi_utils.c
@@ -456,7 +456,6 @@ static HRESULT fix_format(struct ao *ao)
{
struct wasapi_state *state = (struct wasapi_state *)ao->priv;
HRESULT hr;
- double offset = 0.5;
REFERENCE_TIME devicePeriod, bufferDuration, bufferPeriod;
MP_DBG(state, "IAudioClient::GetDevicePeriod\n");
@@ -468,9 +467,11 @@ static HRESULT fix_format(struct ao *ao)
if (state->share_mode == AUDCLNT_SHAREMODE_SHARED)
bufferPeriod = 0;
- /* cargo cult code to negotiate buffer block size, affected by hardware/drivers combinations,
- gradually grow it to 10s, by 0.5s, consider failure if it still doesn't work
- */
+ /* handle unsupported buffer size */
+ /* hopefully this shouldn't happen because of the above integer device period */
+ /* http://msdn.microsoft.com/en-us/library/windows/desktop/dd370875%28v=vs.85%29.aspx */
+ int retries=0;
+
reinit:
MP_DBG(state, "IAudioClient::Initialize\n");
hr = IAudioClient_Initialize(state->pAudioClient,
@@ -484,18 +485,20 @@ reinit:
if (hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED) {
MP_VERBOSE(state, "IAudioClient::Initialize negotiation failed with %s (0x%"PRIx32"), used %lld * 100ns\n",
wasapi_explain_err(hr), (uint32_t)hr, bufferDuration);
- if (offset > 10.0) {
+ if (retries > 1) {
hr = E_FAIL;
EXIT_ON_ERROR(hr);
+ } else {
+ retries ++;
}
+
IAudioClient_GetBufferSize(state->pAudioClient, &state->bufferFrameCount);
bufferPeriod = bufferDuration =
(REFERENCE_TIME)((10000.0 * 1000 / state->format.Format.nSamplesPerSec *
- state->bufferFrameCount) + offset);
+ state->bufferFrameCount) + 0.5);
if (state->share_mode == AUDCLNT_SHAREMODE_SHARED)
bufferPeriod = 0;
- offset += 0.5;
IAudioClient_Release(state->pAudioClient);
state->pAudioClient = NULL;
hr = IMMDeviceActivator_Activate(state->pDevice,
@@ -532,7 +535,7 @@ reinit:
state->bufferFrameCount;
bufferDuration =
(REFERENCE_TIME)((10000.0 * 1000 / state->format.Format.nSamplesPerSec *
- state->bufferFrameCount) + offset);
+ state->bufferFrameCount) + 0.5);
MP_VERBOSE(state, "Buffer frame count: %"PRIu32" (%.2g ms)\n",
state->bufferFrameCount, (double) bufferDuration / 10000.0 );