[PATCH 2/3] winealsa: Move get_latency to the unixlib.

Huw Davies huw at codeweavers.com
Wed Feb 23 03:08:22 CST 2022


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/winealsa.drv/alsa.c     | 22 ++++++++++++++++++++++
 dlls/winealsa.drv/mmdevdrv.c | 20 +++++---------------
 dlls/winealsa.drv/unixlib.h  |  8 ++++++++
 3 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/dlls/winealsa.drv/alsa.c b/dlls/winealsa.drv/alsa.c
index cc0f9166d1a..c40c87bca31 100644
--- a/dlls/winealsa.drv/alsa.c
+++ b/dlls/winealsa.drv/alsa.c
@@ -1250,6 +1250,27 @@ static NTSTATUS get_buffer_size(void *args)
     return alsa_unlock_result(stream, &params->result, S_OK);
 }
 
+static NTSTATUS get_latency(void *args)
+{
+    struct get_latency_params *params = args;
+    struct alsa_stream *stream = params->stream;
+
+    alsa_lock(stream);
+
+    /* Hide some frames in the ALSA buffer. Allows us to return GetCurrentPadding=0
+     * yet have enough data left to play (as if it were in native's mixer). Add:
+     * + mmdevapi_period such that at the end of it, ALSA still has data;
+     * + EXTRA_SAFE (~4ms) to allow for late callback invocation / fluctuation;
+     * + alsa_period such that ALSA always has at least one period to play. */
+    if(stream->flow == eRender)
+        *params->latency = muldiv(stream->hidden_frames, 10000000, stream->fmt->nSamplesPerSec);
+    else
+        *params->latency = muldiv(stream->alsa_period_frames, 10000000, stream->fmt->nSamplesPerSec)
+            + stream->mmdev_period_rt;
+
+    return alsa_unlock_result(stream, &params->result, S_OK);
+}
+
 unixlib_entry_t __wine_unix_call_funcs[] =
 {
     get_endpoint_ids,
@@ -1258,4 +1279,5 @@ unixlib_entry_t __wine_unix_call_funcs[] =
     is_format_supported,
     get_mix_format,
     get_buffer_size,
+    get_latency,
 };
diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c
index 46fd2b3aef5..b8fc6802e28 100644
--- a/dlls/winealsa.drv/mmdevdrv.c
+++ b/dlls/winealsa.drv/mmdevdrv.c
@@ -849,7 +849,7 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
         REFERENCE_TIME *latency)
 {
     ACImpl *This = impl_from_IAudioClient3(iface);
-    struct alsa_stream *stream = This->stream;
+    struct get_latency_params params;
 
     TRACE("(%p)->(%p)\n", This, latency);
 
@@ -859,22 +859,12 @@ static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface,
     if(!This->stream)
         return AUDCLNT_E_NOT_INITIALIZED;
 
-    alsa_lock(stream);
-
-    /* Hide some frames in the ALSA buffer. Allows us to return GetCurrentPadding=0
-     * yet have enough data left to play (as if it were in native's mixer). Add:
-     * + mmdevapi_period such that at the end of it, ALSA still has data;
-     * + EXTRA_SAFE (~4ms) to allow for late callback invocation / fluctuation;
-     * + alsa_period such that ALSA always has at least one period to play. */
-    if(stream->flow == eRender)
-        *latency = MulDiv(stream->hidden_frames, 10000000, stream->fmt->nSamplesPerSec);
-    else
-        *latency = MulDiv(stream->alsa_period_frames, 10000000, stream->fmt->nSamplesPerSec)
-                 + stream->mmdev_period_rt;
+    params.stream = This->stream;
+    params.latency = latency;
 
-    alsa_unlock(stream);
+    ALSA_CALL(get_latency, &params);
 
-    return S_OK;
+    return params.result;
 }
 
 static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface,
diff --git a/dlls/winealsa.drv/unixlib.h b/dlls/winealsa.drv/unixlib.h
index e079b88cbde..e51d3d3d510 100644
--- a/dlls/winealsa.drv/unixlib.h
+++ b/dlls/winealsa.drv/unixlib.h
@@ -115,6 +115,13 @@ struct get_buffer_size_params
     UINT32 *size;
 };
 
+struct get_latency_params
+{
+    struct alsa_stream *stream;
+    HRESULT result;
+    REFERENCE_TIME *latency;
+};
+
 enum alsa_funcs
 {
     alsa_get_endpoint_ids,
@@ -123,6 +130,7 @@ enum alsa_funcs
     alsa_is_format_supported,
     alsa_get_mix_format,
     alsa_get_buffer_size,
+    alsa_get_latency,
 };
 
 extern unixlib_handle_t alsa_handle;
-- 
2.25.1




More information about the wine-devel mailing list