From 13859577c7611936165d6b48ca9abcfa272844b2 Mon Sep 17 00:00:00 2001
From: Mark Harmstone <mark@harmstone.com>
Date: Tue, 18 Nov 2014 18:35:31 +0000
Subject: winepulse: implement exclusive mode

---
 dlls/winepulse.drv/mmdevdrv.c | 46 ++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 27 deletions(-)

diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
index 9342762..5c00a88 100644
--- a/dlls/winepulse.drv/mmdevdrv.c
+++ b/dlls/winepulse.drv/mmdevdrv.c
@@ -1446,6 +1446,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface,
         const GUID *sessionguid)
 {
     ACImpl *This = impl_from_IAudioClient(iface);
+    REFERENCE_TIME def, min;
     HRESULT hr = S_OK;
     UINT period_bytes;
 
@@ -1457,8 +1458,6 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface,
 
     if (mode != AUDCLNT_SHAREMODE_SHARED && mode != AUDCLNT_SHAREMODE_EXCLUSIVE)
         return AUDCLNT_E_NOT_INITIALIZED;
-    if (mode == AUDCLNT_SHAREMODE_EXCLUSIVE)
-        return AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED;
 
     if (flags & ~(AUDCLNT_STREAMFLAGS_CROSSPROCESS |
                 AUDCLNT_STREAMFLAGS_LOOPBACK |
@@ -1492,27 +1491,26 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient *iface,
     if (FAILED(hr))
         goto exit;
 
-    if (mode == AUDCLNT_SHAREMODE_SHARED) {
-        REFERENCE_TIME def = pulse_def_period[This->dataflow == eCapture];
-        REFERENCE_TIME min = pulse_min_period[This->dataflow == eCapture];
+    def = pulse_def_period[This->dataflow == eCapture];
+    min = pulse_min_period[This->dataflow == eCapture];
 
-        /* Switch to low latency mode if below 2 default periods,
-         * which is 20 ms by default, this will increase the amount
-         * of interrupts but allows very low latency. In dsound I
-         * managed to get a total latency of ~8ms, which is well below
-         * default
-         */
-        if (duration < 2 * def)
-            period = min;
-        else
-            period = def;
-        if (duration < 2 * period)
-            duration = 2 * period;
+    /* Switch to low latency mode if below 2 default periods,
+     * which is 20 ms by default, this will increase the amount
+     * of interrupts but allows very low latency. In dsound I
+     * managed to get a total latency of ~8ms, which is well below
+     * default
+     */
+    if (duration < 2 * def)
+        period = min;
+    else
+        period = def;
+    if (duration < 2 * period)
+        duration = 2 * period;
+
+    /* Uh oh, really low latency requested.. */
+    if (duration <= 2 * period)
+        period /= 2;
 
-        /* Uh oh, really low latency requested.. */
-        if (duration <= 2 * period)
-            period /= 2;
-    }
     period_bytes = pa_frame_size(&This->ss) * MulDiv(period, This->ss.rate, 10000000);
 
     if (duration < 20000000)
@@ -1817,12 +1815,6 @@ static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient *iface,
     else
         *out = closest;
 
-    /* Winepulse does not currently support exclusive mode, if you know of an
-     * application that uses it, I will correct this..
-     */
-    if (hr == S_OK && exclusive)
-        return This->dataflow == eCapture ? AUDCLNT_E_UNSUPPORTED_FORMAT : AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED;
-
     TRACE("returning: %08x %p\n", hr, out ? *out : NULL);
     return hr;
 }
-- 
2.6.2

