Jacek Caban : winepulse: Move pulse_get_render_buffer to unix lib.

Alexandre Julliard julliard at winehq.org
Wed May 19 14:55:12 CDT 2021


Module: wine
Branch: master
Commit: 8cb88173d87efedce8c345beea05641f5617d857
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=8cb88173d87efedce8c345beea05641f5617d857

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue May 18 16:58:55 2021 +0200

winepulse: Move pulse_get_render_buffer to unix lib.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/winepulse.drv/mmdevdrv.c | 47 +++-----------------------------
 dlls/winepulse.drv/pulse.c    | 62 +++++++++++++++++++++++++++++++++++++++++++
 dlls/winepulse.drv/unixlib.h  |  1 +
 3 files changed, 66 insertions(+), 44 deletions(-)

diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
index 0cfb1106d2c..63c14b0ae68 100644
--- a/dlls/winepulse.drv/mmdevdrv.c
+++ b/dlls/winepulse.drv/mmdevdrv.c
@@ -1180,61 +1180,20 @@ static ULONG WINAPI AudioRenderClient_Release(IAudioRenderClient *iface)
     return AudioClient_Release(&This->IAudioClient3_iface);
 }
 
-static void alloc_tmp_buffer(ACImpl *This, UINT32 bytes)
-{
-    if(This->pulse_stream->tmp_buffer_bytes >= bytes)
-        return;
-
-    HeapFree(GetProcessHeap(), 0, This->pulse_stream->tmp_buffer);
-    This->pulse_stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, bytes);
-    This->pulse_stream->tmp_buffer_bytes = bytes;
-}
-
 static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
         UINT32 frames, BYTE **data)
 {
     ACImpl *This = impl_from_IAudioRenderClient(iface);
-    size_t bytes = frames * pa_frame_size(&This->pulse_stream->ss);
-    HRESULT hr = S_OK;
-    UINT32 wri_offs_bytes;
 
     TRACE("(%p)->(%u, %p)\n", This, frames, data);
 
     if (!data)
         return E_POINTER;
+    if (!This->pulse_stream)
+        return AUDCLNT_E_NOT_INITIALIZED;
     *data = NULL;
 
-    pulse->lock();
-    hr = pulse_stream_valid(This);
-    if (FAILED(hr) || This->pulse_stream->locked) {
-        pulse->unlock();
-        return FAILED(hr) ? hr : AUDCLNT_E_OUT_OF_ORDER;
-    }
-    if (!frames) {
-        pulse->unlock();
-        return S_OK;
-    }
-
-    if(This->pulse_stream->held_bytes / pa_frame_size(&This->pulse_stream->ss) + frames > This->pulse_stream->bufsize_frames){
-        pulse->unlock();
-        return AUDCLNT_E_BUFFER_TOO_LARGE;
-    }
-
-    wri_offs_bytes = (This->pulse_stream->lcl_offs_bytes + This->pulse_stream->held_bytes) % This->pulse_stream->real_bufsize_bytes;
-    if(wri_offs_bytes + bytes > This->pulse_stream->real_bufsize_bytes){
-        alloc_tmp_buffer(This, bytes);
-        *data = This->pulse_stream->tmp_buffer;
-        This->pulse_stream->locked = -bytes;
-    }else{
-        *data = This->pulse_stream->local_buffer + wri_offs_bytes;
-        This->pulse_stream->locked = bytes;
-    }
-
-    silence_buffer(This->pulse_stream->ss.format, *data, bytes);
-
-    pulse->unlock();
-
-    return hr;
+    return pulse->get_render_buffer(This->pulse_stream, frames, data);
 }
 
 static void pulse_wrap_buffer(ACImpl *This, BYTE *buffer, UINT32 written_bytes)
diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c
index dbdf94b2672..767e555017f 100644
--- a/dlls/winepulse.drv/pulse.c
+++ b/dlls/winepulse.drv/pulse.c
@@ -1406,6 +1406,67 @@ static HRESULT WINAPI pulse_reset(struct pulse_stream *stream)
     return S_OK;
 }
 
+static void alloc_tmp_buffer(struct pulse_stream *stream, UINT32 bytes)
+{
+    if (stream->tmp_buffer_bytes >= bytes)
+        return;
+
+    RtlFreeHeap(GetProcessHeap(), 0, stream->tmp_buffer);
+    stream->tmp_buffer = RtlAllocateHeap(GetProcessHeap(), 0, bytes);
+    stream->tmp_buffer_bytes = bytes;
+}
+
+static HRESULT WINAPI pulse_get_render_buffer(struct pulse_stream *stream, UINT32 frames, BYTE **data)
+{
+    size_t bytes;
+    UINT32 wri_offs_bytes;
+
+    pulse_lock();
+    if (!pulse_stream_valid(stream))
+    {
+        pulse_unlock();
+        return AUDCLNT_E_DEVICE_INVALIDATED;
+    }
+
+    if (stream->locked)
+    {
+        pulse_unlock();
+        return AUDCLNT_E_OUT_OF_ORDER;
+    }
+
+    if (!frames)
+    {
+        pulse_unlock();
+        *data = NULL;
+        return S_OK;
+    }
+
+    if (stream->held_bytes / pa_frame_size(&stream->ss) + frames > stream->bufsize_frames)
+    {
+        pulse_unlock();
+        return AUDCLNT_E_BUFFER_TOO_LARGE;
+    }
+
+    bytes = frames * pa_frame_size(&stream->ss);
+    wri_offs_bytes = (stream->lcl_offs_bytes + stream->held_bytes) % stream->real_bufsize_bytes;
+    if (wri_offs_bytes + bytes > stream->real_bufsize_bytes)
+    {
+        alloc_tmp_buffer(stream, bytes);
+        *data = stream->tmp_buffer;
+        stream->locked = -bytes;
+    }
+    else
+    {
+        *data = stream->local_buffer + wri_offs_bytes;
+        stream->locked = bytes;
+    }
+
+    silence_buffer(stream->ss.format, *data, bytes);
+
+    pulse_unlock();
+    return S_OK;
+}
+
 static void WINAPI pulse_set_volumes(struct pulse_stream *stream, float master_volume,
                                      const float *volumes, const float *session_volumes)
 {
@@ -1427,6 +1488,7 @@ static const struct unix_funcs unix_funcs =
     pulse_stop,
     pulse_reset,
     pulse_timer_loop,
+    pulse_get_render_buffer,
     pulse_set_volumes,
     pulse_test_connect,
 };
diff --git a/dlls/winepulse.drv/unixlib.h b/dlls/winepulse.drv/unixlib.h
index f6ecf778558..f1f5d7ee66d 100644
--- a/dlls/winepulse.drv/unixlib.h
+++ b/dlls/winepulse.drv/unixlib.h
@@ -81,6 +81,7 @@ struct unix_funcs
     HRESULT (WINAPI *stop)(struct pulse_stream *stream);
     HRESULT (WINAPI *reset)(struct pulse_stream *stream);
     void (WINAPI *timer_loop)(struct pulse_stream *stream);
+    HRESULT (WINAPI *get_render_buffer)(struct pulse_stream *stream, UINT32 frames, BYTE **data);
     void (WINAPI *set_volumes)(struct pulse_stream *stream, float master_volume,
                                const float *volumes, const float *session_volumes);
     HRESULT (WINAPI *test_connect)(const char *name, struct pulse_config *config);




More information about the wine-cvs mailing list