Jacek Caban : winepulse: Move pulse_get_position to unix lib.

Alexandre Julliard julliard at winehq.org
Tue May 25 16:08:15 CDT 2021


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon May 24 18:21:49 2021 +0200

winepulse: Move pulse_get_position 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 | 46 +++++++++++--------------------------------
 dlls/winepulse.drv/pulse.c    | 34 ++++++++++++++++++++++++++++++++
 dlls/winepulse.drv/unixlib.h  |  1 +
 3 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c
index 1fe0d0bd50e..0178cdb9e7b 100644
--- a/dlls/winepulse.drv/mmdevdrv.c
+++ b/dlls/winepulse.drv/mmdevdrv.c
@@ -1296,42 +1296,15 @@ static HRESULT WINAPI AudioClock_GetPosition(IAudioClock *iface, UINT64 *pos,
         UINT64 *qpctime)
 {
     ACImpl *This = impl_from_IAudioClock(iface);
-    HRESULT hr;
 
     TRACE("(%p)->(%p, %p)\n", This, pos, qpctime);
 
     if (!pos)
         return E_POINTER;
+    if (!This->pulse_stream)
+        return AUDCLNT_E_NOT_INITIALIZED;
 
-    pulse->lock();
-    hr = pulse_stream_valid(This);
-    if (FAILED(hr)) {
-        pulse->unlock();
-        return hr;
-    }
-
-    *pos = This->pulse_stream->clock_written - This->pulse_stream->held_bytes;
-
-    if (This->pulse_stream->share == AUDCLNT_SHAREMODE_EXCLUSIVE)
-        *pos /= pa_frame_size(&This->pulse_stream->ss);
-
-    /* Make time never go backwards */
-    if (*pos < This->pulse_stream->clock_lastpos)
-        *pos = This->pulse_stream->clock_lastpos;
-    else
-        This->pulse_stream->clock_lastpos = *pos;
-    pulse->unlock();
-
-    TRACE("%p Position: %u\n", This, (unsigned)*pos);
-
-    if (qpctime) {
-        LARGE_INTEGER stamp, freq;
-        QueryPerformanceCounter(&stamp);
-        QueryPerformanceFrequency(&freq);
-        *qpctime = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
-    }
-
-    return S_OK;
+    return pulse->get_position(This->pulse_stream, FALSE, pos, qpctime);
 }
 
 static HRESULT WINAPI AudioClock_GetCharacteristics(IAudioClock *iface,
@@ -1382,10 +1355,15 @@ static HRESULT WINAPI AudioClock2_GetDevicePosition(IAudioClock2 *iface,
         UINT64 *pos, UINT64 *qpctime)
 {
     ACImpl *This = impl_from_IAudioClock2(iface);
-    HRESULT hr = AudioClock_GetPosition(&This->IAudioClock_iface, pos, qpctime);
-    if (SUCCEEDED(hr) && This->pulse_stream->share == AUDCLNT_SHAREMODE_SHARED)
-        *pos /= pa_frame_size(&This->pulse_stream->ss);
-    return hr;
+
+    TRACE("(%p)->(%p, %p)\n", This, pos, qpctime);
+
+    if (!pos)
+        return E_POINTER;
+    if (!This->pulse_stream)
+        return AUDCLNT_E_NOT_INITIALIZED;
+
+    return pulse->get_position(This->pulse_stream, TRUE, pos, qpctime);
 }
 
 static const IAudioClock2Vtbl AudioClock2_Vtbl =
diff --git a/dlls/winepulse.drv/pulse.c b/dlls/winepulse.drv/pulse.c
index b9dceb911d0..063c92605b6 100644
--- a/dlls/winepulse.drv/pulse.c
+++ b/dlls/winepulse.drv/pulse.c
@@ -1710,6 +1710,39 @@ static HRESULT WINAPI pulse_get_frequency(struct pulse_stream *stream, UINT64 *f
     return S_OK;
 }
 
+static HRESULT WINAPI pulse_get_position(struct pulse_stream *stream, BOOL device, UINT64 *pos, UINT64 *qpctime)
+{
+    pulse_lock();
+    if (!pulse_stream_valid(stream))
+    {
+        pulse_unlock();
+        return AUDCLNT_E_DEVICE_INVALIDATED;
+    }
+
+    *pos = stream->clock_written - stream->held_bytes;
+
+    if (stream->share == AUDCLNT_SHAREMODE_EXCLUSIVE || device)
+        *pos /= pa_frame_size(&stream->ss);
+
+    /* Make time never go backwards */
+    if (*pos < stream->clock_lastpos)
+        *pos = stream->clock_lastpos;
+    else
+        stream->clock_lastpos = *pos;
+    pulse_unlock();
+
+    TRACE("%p Position: %u\n", stream, (unsigned)*pos);
+
+    if (qpctime)
+    {
+        LARGE_INTEGER stamp, freq;
+        NtQueryPerformanceCounter(&stamp, &freq);
+        *qpctime = (stamp.QuadPart * (INT64)10000000) / freq.QuadPart;
+    }
+
+    return S_OK;
+}
+
 static void WINAPI pulse_set_volumes(struct pulse_stream *stream, float master_volume,
                                      const float *volumes, const float *session_volumes)
 {
@@ -1758,6 +1791,7 @@ static const struct unix_funcs unix_funcs =
     pulse_get_current_padding,
     pulse_get_next_packet_size,
     pulse_get_frequency,
+    pulse_get_position,
     pulse_set_volumes,
     pulse_set_event_handle,
     pulse_test_connect,
diff --git a/dlls/winepulse.drv/unixlib.h b/dlls/winepulse.drv/unixlib.h
index d9c6ef057bb..f1546d42d76 100644
--- a/dlls/winepulse.drv/unixlib.h
+++ b/dlls/winepulse.drv/unixlib.h
@@ -84,6 +84,7 @@ struct unix_funcs
     HRESULT (WINAPI *get_current_padding)(struct pulse_stream *stream, UINT32 *out);
     HRESULT (WINAPI *get_next_packet_size)(struct pulse_stream *stream, UINT32 *frames);
     HRESULT (WINAPI *get_frequency)(struct pulse_stream *stream, UINT64 *freq);
+    HRESULT (WINAPI *get_position)(struct pulse_stream *stream, BOOL device, UINT64 *pos, UINT64 *qpctime);
     void (WINAPI *set_volumes)(struct pulse_stream *stream, float master_volume,
                                const float *volumes, const float *session_volumes);
     HRESULT (WINAPI *set_event_handle)(struct pulse_stream *stream, HANDLE event);




More information about the wine-cvs mailing list