-- v6: winepulse: Use mmdevapi's AudioSessionControl. wineoss: Use mmdevapi's AudioSessionControl. winecoreaudio: Use mmdevapi's AudioSessionControl. winealsa: Use mmdevapi's AudioSessionControl. winepulse: Implement function to (un)lock sessions. wineoss: Implement function to (un)lock sessions. winecoreaudio: Implement function to (un)lock sessions. winealsa: Implement function to (un)lock sessions. mmdevapi: Implement AudioSessionControl. mmdevapi: Implement AudioClient stub.
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/mmdevapi/Makefile.in | 1 + dlls/mmdevapi/audioclient.c | 228 ++++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 dlls/mmdevapi/audioclient.c
diff --git a/dlls/mmdevapi/Makefile.in b/dlls/mmdevapi/Makefile.in index 85a52d87184..30e9079b442 100644 --- a/dlls/mmdevapi/Makefile.in +++ b/dlls/mmdevapi/Makefile.in @@ -2,6 +2,7 @@ MODULE = mmdevapi.dll IMPORTS = uuid ole32 oleaut32 user32 advapi32
C_SRCS = \ + audioclient.c \ audiosessionmanager.c \ audiovolume.c \ devenum.c \ diff --git a/dlls/mmdevapi/audioclient.c b/dlls/mmdevapi/audioclient.c new file mode 100644 index 00000000000..d89b0908e96 --- /dev/null +++ b/dlls/mmdevapi/audioclient.c @@ -0,0 +1,228 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#define COBJMACROS + +#include <audiopolicy.h> +#include <mmdeviceapi.h> + +#include <wine/debug.h> + +#include "mmdevdrv.h" + +WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi); + +static inline struct audio_client *impl_from_IAudioClient3(IAudioClient3 *iface) +{ + return CONTAINING_RECORD(iface, struct audio_client, IAudioClient3_iface); +} + +static HRESULT WINAPI AudioClient_QueryInterface(IAudioClient3 *iface, REFIID riid, void **ppv) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%s, %p) - stub\n", This, debugstr_guid(riid), ppv); + return E_NOTIMPL; +} + +static ULONG WINAPI AudioClient_AddRef(IAudioClient3 *iface) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p) - stub\n", This); + return 0; +} + +static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p) - stub\n", This); + return 0; +} + +static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, AUDCLNT_SHAREMODE mode, + DWORD flags, REFERENCE_TIME duration, + REFERENCE_TIME period, const WAVEFORMATEX *fmt, + const GUID *sessionguid) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%x, %lx, %s, %s, %p, %s) - stub\n", This, mode, flags, + wine_dbgstr_longlong(duration), + wine_dbgstr_longlong(period), fmt, + debugstr_guid(sessionguid)); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetBufferSize(IAudioClient3 *iface, UINT32 *out) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p) - stub\n", This, out); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetStreamLatency(IAudioClient3 *iface, REFERENCE_TIME *latency) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p) - stub\n", This, latency); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetCurrentPadding(IAudioClient3 *iface, UINT32 *out) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p) - stub\n", This, out); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_IsFormatSupported(IAudioClient3 *iface, AUDCLNT_SHAREMODE mode, + const WAVEFORMATEX *fmt, WAVEFORMATEX **out) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%x, %p, %p) - stub\n", This, mode, fmt, out); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetMixFormat(IAudioClient3 *iface, WAVEFORMATEX **pwfx) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p) - stub\n", This, pwfx); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetDevicePeriod(IAudioClient3 *iface, REFERENCE_TIME *defperiod, + REFERENCE_TIME *minperiod) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p, %p) - stub\n", This, defperiod, minperiod); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p) - stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_Stop(IAudioClient3 *iface) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p) - stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_Reset(IAudioClient3 *iface) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p) - stub\n", This); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_SetEventHandle(IAudioClient3 *iface, HANDLE event) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p) - stub\n", This, event); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, void **ppv) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%s, %p) - stub\n", This, debugstr_guid(riid), ppv); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_IsOffloadCapable(IAudioClient3 *iface, + AUDIO_STREAM_CATEGORY category, BOOL *offload_capable) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(0x%x, %p) - stub\n", This, category, offload_capable); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_SetClientProperties(IAudioClient3 *iface, + const AudioClientProperties *prop) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p) - stub\n", This, prop); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetBufferSizeLimits(IAudioClient3 *iface, + const WAVEFORMATEX *format, BOOL event_driven, + REFERENCE_TIME *min_duration, + REFERENCE_TIME *max_duration) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p, %u, %p, %p) - stub\n", This, format, event_driven, min_duration, max_duration); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetSharedModeEnginePeriod(IAudioClient3 *iface, + const WAVEFORMATEX *format, + UINT32 *default_period_frames, + UINT32 *unit_period_frames, + UINT32 *min_period_frames, + UINT32 *max_period_frames) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p, %p, %p, %p, %p) - stub\n", This, format, default_period_frames, + unit_period_frames, min_period_frames, + max_period_frames); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_GetCurrentSharedModeEnginePeriod(IAudioClient3 *iface, + WAVEFORMATEX **cur_format, + UINT32 *cur_period_frames) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(%p, %p) - stub\n", This, cur_format, cur_period_frames); + return E_NOTIMPL; +} + +static HRESULT WINAPI AudioClient_InitializeSharedAudioStream(IAudioClient3 *iface, DWORD flags, + UINT32 period_frames, + const WAVEFORMATEX *format, + const GUID *session_guid) +{ + struct audio_client *This = impl_from_IAudioClient3(iface); + FIXME("(%p)->(0x%lx, %u, %p, %s) - stub\n", This, flags, period_frames, format, debugstr_guid(session_guid)); + return E_NOTIMPL; +} + +const IAudioClient3Vtbl AudioClient3_Vtbl = +{ + AudioClient_QueryInterface, + AudioClient_AddRef, + AudioClient_Release, + AudioClient_Initialize, + AudioClient_GetBufferSize, + AudioClient_GetStreamLatency, + AudioClient_GetCurrentPadding, + AudioClient_IsFormatSupported, + AudioClient_GetMixFormat, + AudioClient_GetDevicePeriod, + AudioClient_Start, + AudioClient_Stop, + AudioClient_Reset, + AudioClient_SetEventHandle, + AudioClient_GetService, + AudioClient_IsOffloadCapable, + AudioClient_SetClientProperties, + AudioClient_GetBufferSizeLimits, + AudioClient_GetSharedModeEnginePeriod, + AudioClient_GetCurrentSharedModeEnginePeriod, + AudioClient_InitializeSharedAudioStream, +};
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/mmdevapi/Makefile.in | 1 + dlls/mmdevapi/audiosession.c | 246 ++++++++++++++++++++++++++++ dlls/mmdevapi/audiosessionmanager.c | 14 ++ dlls/mmdevapi/mmdevdrv.h | 2 + 4 files changed, 263 insertions(+) create mode 100644 dlls/mmdevapi/audiosession.c
diff --git a/dlls/mmdevapi/Makefile.in b/dlls/mmdevapi/Makefile.in index 30e9079b442..8f992f516fa 100644 --- a/dlls/mmdevapi/Makefile.in +++ b/dlls/mmdevapi/Makefile.in @@ -3,6 +3,7 @@ IMPORTS = uuid ole32 oleaut32 user32 advapi32
C_SRCS = \ audioclient.c \ + audiosession.c \ audiosessionmanager.c \ audiovolume.c \ devenum.c \ diff --git a/dlls/mmdevapi/audiosession.c b/dlls/mmdevapi/audiosession.c new file mode 100644 index 00000000000..feb3f957690 --- /dev/null +++ b/dlls/mmdevapi/audiosession.c @@ -0,0 +1,246 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ +#define COBJMACROS + +#include <audiopolicy.h> +#include <mmdeviceapi.h> +#include <winternl.h> + +#include <wine/debug.h> +#include <wine/unixlib.h> + +#include "mmdevdrv.h" +#include "unixlib.h" + +#define NULL_PTR_ERR MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, RPC_X_NULL_REF_POINTER) + +WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi); + +extern const IAudioClient3Vtbl AudioClient3_Vtbl; + +static inline struct audio_session_wrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) +{ + return CONTAINING_RECORD(iface, struct audio_session_wrapper, IAudioSessionControl2_iface); +} + +static HRESULT WINAPI ASC_QueryInterface(IAudioSessionControl2 *iface, REFIID riid, void **ppv) +{ + TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); + + if (!ppv) + return E_POINTER; + + if (IsEqualIID(riid, &IID_IUnknown) || + IsEqualIID(riid, &IID_IAudioSessionControl) || + IsEqualIID(riid, &IID_IAudioSessionControl2)) + *ppv = iface; + else { + *ppv = NULL; + return E_NOINTERFACE; + } + + IUnknown_AddRef((IUnknown *)*ppv); + + return S_OK; +} + +static ULONG WINAPI ASC_AddRef(IAudioSessionControl2 *iface) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + ULONG ref = InterlockedIncrement(&This->ref); + TRACE("(%p) Refcount now %lu\n", This, ref); + return ref; +} + +static ULONG WINAPI ASC_Release(IAudioSessionControl2 *iface) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + ULONG ref = InterlockedDecrement(&This->ref); + TRACE("(%p) Refcount now %lu\n", This, ref); + + if (!ref){ + if (This->client) { + lock_sessions(TRUE); + This->client->session_wrapper = NULL; + lock_sessions(FALSE); + AudioClient3_Vtbl.Release(&This->client->IAudioClient3_iface); + } + + HeapFree(GetProcessHeap(), 0, This); + } + + return ref; +} + +static HRESULT WINAPI ASC_GetState(IAudioSessionControl2 *iface, AudioSessionState *state) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + struct is_started_params params; + struct audio_client *client; + + TRACE("(%p)->(%p)\n", This, state); + + if (!state) + return NULL_PTR_ERR; + + lock_sessions(TRUE); + + if (list_empty(&This->session->clients)) { + *state = AudioSessionStateExpired; + lock_sessions(FALSE); + return S_OK; + } + + LIST_FOR_EACH_ENTRY(client, &This->session->clients, struct audio_client, entry) { + params.stream = client->stream; + WINE_UNIX_CALL(is_started, ¶ms); + if (params.result == S_OK) { + *state = AudioSessionStateActive; + lock_sessions(FALSE); + return S_OK; + } + } + + lock_sessions(FALSE); + + *state = AudioSessionStateInactive; + + return S_OK; +} + +static HRESULT WINAPI ASC_GetDisplayName(IAudioSessionControl2 *iface, WCHAR **name) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, name); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_SetDisplayName(IAudioSessionControl2 *iface, const WCHAR *name, + const GUID *session) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session)); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_GetIconPath(IAudioSessionControl2 *iface, WCHAR **path) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, path); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_SetIconPath(IAudioSessionControl2 *iface, const WCHAR *path, + const GUID *session) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_w(path), debugstr_guid(session)); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_GetGroupingParam(IAudioSessionControl2 *iface, GUID *group) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, group); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_SetGroupingParam(IAudioSessionControl2 *iface, const GUID *group, + const GUID *session) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group), debugstr_guid(session)); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_RegisterAudioSessionNotification(IAudioSessionControl2 *iface, + IAudioSessionEvents *events) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, events); + return S_OK; +} + +static HRESULT WINAPI ASC_UnregisterAudioSessionNotification(IAudioSessionControl2 *iface, + IAudioSessionEvents *events) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, events); + return S_OK; +} + +static HRESULT WINAPI ASC_GetSessionIdentifier(IAudioSessionControl2 *iface, WCHAR **id) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, id); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_GetSessionInstanceIdentifier(IAudioSessionControl2 *iface, WCHAR **id) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + FIXME("(%p)->(%p) - stub\n", This, id); + return E_NOTIMPL; +} + +static HRESULT WINAPI ASC_GetProcessId(IAudioSessionControl2 *iface, DWORD *pid) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + + TRACE("(%p)->(%p)\n", This, pid); + + if (!pid) + return E_POINTER; + + *pid = GetCurrentProcessId(); + + return S_OK; +} + +static HRESULT WINAPI ASC_IsSystemSoundsSession(IAudioSessionControl2 *iface) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + TRACE("(%p)\n", This); + return S_FALSE; +} + +static HRESULT WINAPI ASC_SetDuckingPreference(IAudioSessionControl2 *iface, BOOL optout) +{ + struct audio_session_wrapper *This = impl_from_IAudioSessionControl2(iface); + TRACE("(%p)->(%d)\n", This, optout); + return S_OK; +} + +const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl = +{ + ASC_QueryInterface, + ASC_AddRef, + ASC_Release, + ASC_GetState, + ASC_GetDisplayName, + ASC_SetDisplayName, + ASC_GetIconPath, + ASC_SetIconPath, + ASC_GetGroupingParam, + ASC_SetGroupingParam, + ASC_RegisterAudioSessionNotification, + ASC_UnregisterAudioSessionNotification, + ASC_GetSessionIdentifier, + ASC_GetSessionInstanceIdentifier, + ASC_GetProcessId, + ASC_IsSystemSoundsSession, + ASC_SetDuckingPreference +}; diff --git a/dlls/mmdevapi/audiosessionmanager.c b/dlls/mmdevapi/audiosessionmanager.c index 039b1c264df..36134c8bc77 100644 --- a/dlls/mmdevapi/audiosessionmanager.c +++ b/dlls/mmdevapi/audiosessionmanager.c @@ -28,6 +28,20 @@ WINE_DEFAULT_DEBUG_CHANNEL(mmdevapi);
static struct list g_sessions = LIST_INIT(g_sessions);
+static CRITICAL_SECTION g_sessions_lock; +static CRITICAL_SECTION_DEBUG g_sessions_lock_debug = +{ + 0, 0, &g_sessions_lock, + { &g_sessions_lock_debug.ProcessLocksList, &g_sessions_lock_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": g_sessions_lock") } +}; +static CRITICAL_SECTION g_sessions_lock = { &g_sessions_lock_debug, -1, 0, 0, 0, 0 }; + +void lock_sessions(const BOOLEAN lock) +{ + lock ? EnterCriticalSection(&g_sessions_lock) : LeaveCriticalSection(&g_sessions_lock); +} + static inline struct session_mgr *impl_from_IAudioSessionManager2(IAudioSessionManager2 *iface) { return CONTAINING_RECORD(iface, struct session_mgr, IAudioSessionManager2_iface); diff --git a/dlls/mmdevapi/mmdevdrv.h b/dlls/mmdevapi/mmdevdrv.h index 5c26b1b34d8..7c02fd073da 100644 --- a/dlls/mmdevapi/mmdevdrv.h +++ b/dlls/mmdevapi/mmdevdrv.h @@ -84,3 +84,5 @@ struct audio_client { /* Keep at end */ char device_name[0]; }; + +extern void lock_sessions(const BOOLEAN lock) DECLSPEC_HIDDEN;
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/winealsa.drv/mmdevdrv.c | 81 +++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 38 deletions(-)
diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c index c46ae41f48b..cc6fefc4cc6 100644 --- a/dlls/winealsa.drv/mmdevdrv.c +++ b/dlls/winealsa.drv/mmdevdrv.c @@ -81,6 +81,11 @@ static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl;
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
+void lock_sessions(const BOOLEAN lock) +{ + lock ? EnterCriticalSection(&g_sessions_lock) : LeaveCriticalSection(&g_sessions_lock); +} + static inline ACImpl *impl_from_IAudioClient3(IAudioClient3 *iface) { return CONTAINING_RECORD(iface, ACImpl, IAudioClient3_iface); @@ -480,9 +485,9 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) IMMDevice_Release(This->parent); IUnknown_Release(This->marshal); if(This->session){ - EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE); list_remove(&This->entry); - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); } HeapFree(GetProcessHeap(), 0, This->vols); if (This->stream) @@ -666,10 +671,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, } }
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_ALREADY_INITIALIZED; }
@@ -688,7 +693,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
ALSA_CALL(create_stream, ¶ms); if(FAILED(params.result)){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return params.result; }
@@ -718,7 +723,7 @@ exit: set_stream_volumes(This); }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return params.result; } @@ -876,10 +881,10 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
TRACE("(%p)\n", This);
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(!This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_NOT_INITIALIZED; }
@@ -892,7 +897,7 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface) SetThreadPriority(This->timer_thread, THREAD_PRIORITY_TIME_CRITICAL); }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return params.result; } @@ -964,23 +969,23 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, return E_POINTER; *ppv = NULL;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(!This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_NOT_INITIALIZED; }
if(IsEqualIID(riid, &IID_IAudioRenderClient)){ if(This->dataflow != eRender){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_WRONG_ENDPOINT_TYPE; } IAudioRenderClient_AddRef(&This->IAudioRenderClient_iface); *ppv = &This->IAudioRenderClient_iface; }else if(IsEqualIID(riid, &IID_IAudioCaptureClient)){ if(This->dataflow != eCapture){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_WRONG_ENDPOINT_TYPE; } IAudioCaptureClient_AddRef(&This->IAudioCaptureClient_iface); @@ -995,7 +1000,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->session_wrapper){ This->session_wrapper = AudioSessionWrapper_Create(This); if(!This->session_wrapper){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return E_OUTOFMEMORY; } }else @@ -1006,7 +1011,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->session_wrapper){ This->session_wrapper = AudioSessionWrapper_Create(This); if(!This->session_wrapper){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return E_OUTOFMEMORY; } }else @@ -1017,7 +1022,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->session_wrapper){ This->session_wrapper = AudioSessionWrapper_Create(This); if(!This->session_wrapper){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return E_OUTOFMEMORY; } }else @@ -1027,11 +1032,11 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, }
if(*ppv){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
FIXME("stub %s\n", debugstr_guid(riid)); return E_NOINTERFACE; @@ -1545,9 +1550,9 @@ static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) TRACE("(%p) Refcount now %lu\n", This, ref); if(!ref){ if(This->client){ - EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE); This->client->session_wrapper = NULL; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); AudioClient_Release(&This->client->IAudioClient3_iface); } HeapFree(GetProcessHeap(), 0, This); @@ -1567,11 +1572,11 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, if(!state) return NULL_PTR_ERR;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(list_empty(&This->session->clients)){ *state = AudioSessionStateExpired; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; }
@@ -1580,12 +1585,12 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, ALSA_CALL(is_started, ¶ms); if(params.result == S_OK){ *state = AudioSessionStateActive; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; } }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
*state = AudioSessionStateInactive;
@@ -1799,14 +1804,14 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume(
TRACE("ALSA does not support volume control\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->master_vol = level;
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1839,13 +1844,13 @@ static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface, if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->mute = mute; LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1940,12 +1945,12 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume(
TRACE("ALSA does not support volume control\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
This->vols[index] = level; set_stream_volumes(This);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1984,13 +1989,13 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes(
TRACE("ALSA does not support volume control\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) This->vols[i] = levels[i]; set_stream_volumes(This);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2009,12 +2014,12 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes( if(count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) levels[i] = This->vols[i];
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2102,14 +2107,14 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume(
TRACE("ALSA does not support volume control\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->channel_vols[index] = level;
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2156,7 +2161,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes(
TRACE("ALSA does not support volume control\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) session->channel_vols[i] = levels[i]; @@ -2164,7 +2169,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; }
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/winecoreaudio.drv/mmdevdrv.c | 61 +++++++++++++++++-------------- 1 file changed, 33 insertions(+), 28 deletions(-)
diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c index 21c2528cab1..8225d0ce741 100644 --- a/dlls/winecoreaudio.drv/mmdevdrv.c +++ b/dlls/winecoreaudio.drv/mmdevdrv.c @@ -75,6 +75,11 @@ static struct list g_sessions = LIST_INIT(g_sessions);
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
+void lock_sessions(const BOOLEAN lock) +{ + lock ? EnterCriticalSection(&g_sessions_lock) : LeaveCriticalSection(&g_sessions_lock); +} + static inline ACImpl *impl_from_IAudioClient3(IAudioClient3 *iface) { return CONTAINING_RECORD(iface, ACImpl, IAudioClient3_iface); @@ -452,9 +457,9 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) UNIX_CALL(release_stream, ¶ms); This->stream = 0;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE); list_remove(&This->entry); - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); } HeapFree(GetProcessHeap(), 0, This->vols); IMMDevice_Release(This->parent); @@ -641,10 +646,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, } }
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_ALREADY_INITIALIZED; }
@@ -661,7 +666,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
UNIX_CALL(create_stream, ¶ms); if(FAILED(params.result)){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return params.result; }
@@ -692,7 +697,7 @@ end: set_stream_volumes(This, -1); }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return params.result; } @@ -934,7 +939,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->stream) return AUDCLNT_E_NOT_INITIALIZED;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(IsEqualIID(riid, &IID_IAudioRenderClient)){ if(This->dataflow != eRender){ @@ -998,7 +1003,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, }
end: - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return hr; }
@@ -1492,7 +1497,7 @@ static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); ULONG ref;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
ref = InterlockedDecrement(&This->ref); TRACE("(%p) Refcount now %lu\n", This, ref); @@ -1504,7 +1509,7 @@ static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) HeapFree(GetProcessHeap(), 0, This); }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return ref; }
@@ -1520,11 +1525,11 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, if(!state) return NULL_PTR_ERR;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(list_empty(&This->session->clients)){ *state = AudioSessionStateExpired; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; }
@@ -1533,12 +1538,12 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, UNIX_CALL(is_started, ¶ms); if(params.result == S_OK){ *state = AudioSessionStateActive; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; } }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
*state = AudioSessionStateInactive;
@@ -1750,14 +1755,14 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->master_vol = level;
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client, -1);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1790,14 +1795,14 @@ static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface, if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->mute = mute;
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client, -1);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1890,14 +1895,14 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume( if(index >= This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
This->vols[index] = level;
WARN("CoreAudio doesn't support per-channel volume control\n"); set_stream_volumes(This, index);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1934,14 +1939,14 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes( if(count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) This->vols[i] = levels[i];
set_stream_volumes(This, -1);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1960,12 +1965,12 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes( if(count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) levels[i] = This->vols[i];
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2051,7 +2056,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume( if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->channel_vols[index] = level;
@@ -2059,7 +2064,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume( LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client, index);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2104,7 +2109,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) session->channel_vols[i] = levels[i]; @@ -2112,7 +2117,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client, -1);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; }
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/wineoss.drv/mmdevdrv.c | 81 ++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 38 deletions(-)
diff --git a/dlls/wineoss.drv/mmdevdrv.c b/dlls/wineoss.drv/mmdevdrv.c index 56e619dd163..d543e525036 100644 --- a/dlls/wineoss.drv/mmdevdrv.c +++ b/dlls/wineoss.drv/mmdevdrv.c @@ -87,6 +87,11 @@ static const IAudioClock2Vtbl AudioClock2_Vtbl; static const IAudioStreamVolumeVtbl AudioStreamVolume_Vtbl; static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl;
+void lock_sessions(const BOOLEAN lock) +{ + lock ? EnterCriticalSection(&g_sessions_lock) : LeaveCriticalSection(&g_sessions_lock); +} + static inline ACImpl *impl_from_IAudioClient3(IAudioClient3 *iface) { return CONTAINING_RECORD(iface, ACImpl, IAudioClient3_iface); @@ -452,9 +457,9 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) IMMDevice_Release(This->parent); IUnknown_Release(This->marshal); if(This->session){ - EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE); list_remove(&This->entry); - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); } HeapFree(GetProcessHeap(), 0, This->vols); if(This->stream) @@ -634,10 +639,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, } }
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_ALREADY_INITIALIZED; }
@@ -654,7 +659,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface,
OSS_CALL(create_stream, ¶ms); if(FAILED(params.result)){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return params.result; }
@@ -681,7 +686,7 @@ exit: set_stream_volumes(This); }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return params.result; } @@ -837,10 +842,10 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface)
TRACE("(%p)\n", This);
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(!This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_NOT_INITIALIZED; }
@@ -852,7 +857,7 @@ static HRESULT WINAPI AudioClient_Start(IAudioClient3 *iface) SetThreadPriority(This->timer_thread, THREAD_PRIORITY_TIME_CRITICAL); }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return params.result; } @@ -921,23 +926,23 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, return E_POINTER; *ppv = NULL;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(!This->stream){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_NOT_INITIALIZED; }
if(IsEqualIID(riid, &IID_IAudioRenderClient)){ if(This->dataflow != eRender){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_WRONG_ENDPOINT_TYPE; } IAudioRenderClient_AddRef(&This->IAudioRenderClient_iface); *ppv = &This->IAudioRenderClient_iface; }else if(IsEqualIID(riid, &IID_IAudioCaptureClient)){ if(This->dataflow != eCapture){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return AUDCLNT_E_WRONG_ENDPOINT_TYPE; } IAudioCaptureClient_AddRef(&This->IAudioCaptureClient_iface); @@ -952,7 +957,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->session_wrapper){ This->session_wrapper = AudioSessionWrapper_Create(This); if(!This->session_wrapper){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return E_OUTOFMEMORY; } }else @@ -963,7 +968,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->session_wrapper){ This->session_wrapper = AudioSessionWrapper_Create(This); if(!This->session_wrapper){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return E_OUTOFMEMORY; } }else @@ -974,7 +979,7 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, if(!This->session_wrapper){ This->session_wrapper = AudioSessionWrapper_Create(This); if(!This->session_wrapper){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return E_OUTOFMEMORY; } }else @@ -984,11 +989,11 @@ static HRESULT WINAPI AudioClient_GetService(IAudioClient3 *iface, REFIID riid, }
if(*ppv){ - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
FIXME("stub %s\n", debugstr_guid(riid)); return E_NOINTERFACE; @@ -1494,9 +1499,9 @@ static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) TRACE("(%p) Refcount now %lu\n", This, ref); if(!ref){ if(This->client){ - EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE); This->client->session_wrapper = NULL; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); AudioClient_Release(&This->client->IAudioClient3_iface); } HeapFree(GetProcessHeap(), 0, This); @@ -1516,11 +1521,11 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, if(!state) return NULL_PTR_ERR;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
if(list_empty(&This->session->clients)){ *state = AudioSessionStateExpired; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; }
@@ -1529,12 +1534,12 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, OSS_CALL(is_started, ¶ms); if(params.result == S_OK){ *state = AudioSessionStateActive; - LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE); return S_OK; } }
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
*state = AudioSessionStateInactive;
@@ -1746,7 +1751,7 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->master_vol = level;
@@ -1754,7 +1759,7 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1784,14 +1789,14 @@ static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface,
TRACE("(%p)->(%u, %s)\n", session, mute, debugstr_guid(context));
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->mute = mute;
LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1884,14 +1889,14 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume( if(index >= This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
This->vols[index] = level;
TRACE("OSS doesn't support setting volume\n"); set_stream_volumes(This);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1928,7 +1933,7 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes( if(count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) This->vols[i] = levels[i]; @@ -1936,7 +1941,7 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes( TRACE("OSS doesn't support setting volume\n"); set_stream_volumes(This);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -1955,12 +1960,12 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes( if(count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) levels[i] = This->vols[i];
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2046,7 +2051,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume( if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
session->channel_vols[index] = level;
@@ -2054,7 +2059,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume( LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; } @@ -2099,7 +2104,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( if(context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&g_sessions_lock); + lock_sessions(TRUE);
for(i = 0; i < count; ++i) session->channel_vols[i] = levels[i]; @@ -2108,7 +2113,7 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes( LIST_FOR_EACH_ENTRY(client, &session->clients, ACImpl, entry) set_stream_volumes(client);
- LeaveCriticalSection(&g_sessions_lock); + lock_sessions(FALSE);
return S_OK; }
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/winepulse.drv/mmdevdrv.c | 59 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 27 deletions(-)
diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c index 7f1dbb765cf..fb0b3c46307 100644 --- a/dlls/winepulse.drv/mmdevdrv.c +++ b/dlls/winepulse.drv/mmdevdrv.c @@ -83,6 +83,11 @@ static CRITICAL_SECTION_DEBUG session_cs_debug = { }; static CRITICAL_SECTION session_cs = { &session_cs_debug, -1, 0, 0, 0, 0 };
+void lock_sessions(const BOOLEAN lock) +{ + lock ? EnterCriticalSection(&session_cs) : LeaveCriticalSection(&session_cs); +} + BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) { if (reason == DLL_PROCESS_ATTACH) { @@ -601,9 +606,9 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) if (This->stream) { pulse_release_stream(This->stream, This->timer_thread); This->stream = 0; - EnterCriticalSection(&session_cs); + lock_sessions(TRUE); list_remove(&This->entry); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); } IUnknown_Release(This->marshal); IMMDevice_Release(This->parent); @@ -784,10 +789,10 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, return E_INVALIDARG; }
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE);
if (This->stream) { - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return AUDCLNT_E_ALREADY_INITIALIZED; }
@@ -797,7 +802,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, if (!(pulse_thread = CreateThread(NULL, 0, pulse_mainloop_thread, event, 0, NULL))) { ERR("Failed to create mainloop thread.\n"); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); CloseHandle(event); return E_FAIL; } @@ -820,14 +825,14 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, free(name); if (FAILED(hr = params.result)) { - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return hr; }
if (!(This->vols = malloc(channel_count * sizeof(*This->vols)))) { pulse_release_stream(stream, NULL); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return E_OUTOFMEMORY; } for (i = 0; i < channel_count; i++) @@ -838,7 +843,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, { free(This->vols); This->vols = NULL; - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); pulse_release_stream(stream, NULL); return E_OUTOFMEMORY; } @@ -848,7 +853,7 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, list_add_tail(&This->session->clients, &This->entry); set_stream_volumes(This);
- LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
@@ -1771,12 +1776,12 @@ static HRESULT WINAPI AudioStreamVolume_SetAllVolumes( if (count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); for (i = 0; i < count; ++i) This->vols[i] = levels[i];
set_stream_volumes(This); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
@@ -1796,10 +1801,10 @@ static HRESULT WINAPI AudioStreamVolume_GetAllVolumes( if (count != This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); for (i = 0; i < count; ++i) levels[i] = This->vols[i]; - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
@@ -1818,10 +1823,10 @@ static HRESULT WINAPI AudioStreamVolume_SetChannelVolume( if (index >= This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); This->vols[index] = level; set_stream_volumes(This); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
@@ -1840,9 +1845,9 @@ static HRESULT WINAPI AudioStreamVolume_GetChannelVolume( if (index >= This->channel_count) return E_INVALIDARG;
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); *level = This->vols[index]; - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
@@ -1940,7 +1945,7 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, if (!state) return NULL_PTR_ERR;
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); if (list_empty(&This->session->clients)) { *state = AudioSessionStateExpired; goto out; @@ -1961,7 +1966,7 @@ static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, *state = AudioSessionStateInactive;
out: - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
@@ -2172,11 +2177,11 @@ static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume(
TRACE("PulseAudio does not support session volume control\n");
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); session->master_vol = level; LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) set_stream_volumes(client); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE);
return S_OK; } @@ -2209,11 +2214,11 @@ static HRESULT WINAPI SimpleAudioVolume_SetMute(ISimpleAudioVolume *iface, if (context) FIXME("Notifications not supported yet\n");
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); session->mute = mute; LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) set_stream_volumes(client); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE);
return S_OK; } @@ -2316,11 +2321,11 @@ static HRESULT WINAPI ChannelAudioVolume_SetChannelVolume(
TRACE("PulseAudio does not support session volume control\n");
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); session->channel_vols[index] = level; LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) set_stream_volumes(client); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE);
return S_OK; } @@ -2367,12 +2372,12 @@ static HRESULT WINAPI ChannelAudioVolume_SetAllVolumes(
TRACE("PulseAudio does not support session volume control\n");
- EnterCriticalSection(&session_cs); + lock_sessions(TRUE); for(i = 0; i < count; ++i) session->channel_vols[i] = levels[i]; LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) set_stream_volumes(client); - LeaveCriticalSection(&session_cs); + lock_sessions(FALSE); return S_OK; }
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/winealsa.drv/Makefile.in | 2 + dlls/winealsa.drv/mmdevdrv.c | 262 +--------------------------------- 2 files changed, 9 insertions(+), 255 deletions(-)
diff --git a/dlls/winealsa.drv/Makefile.in b/dlls/winealsa.drv/Makefile.in index 94884bc3c2b..d250de489b3 100644 --- a/dlls/winealsa.drv/Makefile.in +++ b/dlls/winealsa.drv/Makefile.in @@ -1,11 +1,13 @@ MODULE = winealsa.drv UNIXLIB = winealsa.so IMPORTS = uuid ole32 advapi32 +PARENTSRC = ../mmdevapi DELAYIMPORTS = winmm UNIX_LIBS = $(ALSA_LIBS) $(PTHREAD_LIBS)
C_SRCS = \ alsa.c \ alsamidi.c \ + audiosession.c \ midi.c \ mmdevdrv.c diff --git a/dlls/winealsa.drv/mmdevdrv.c b/dlls/winealsa.drv/mmdevdrv.c index cc6fefc4cc6..4c83a1aff36 100644 --- a/dlls/winealsa.drv/mmdevdrv.c +++ b/dlls/winealsa.drv/mmdevdrv.c @@ -69,10 +69,10 @@ static struct list g_sessions = LIST_INIT(g_sessions); static WCHAR drv_key_devicesW[256]; static const WCHAR guidW[] = {'g','u','i','d',0};
-static const IAudioClient3Vtbl AudioClient3_Vtbl; +const IAudioClient3Vtbl AudioClient3_Vtbl; static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; +extern const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl; static const IAudioClockVtbl AudioClock_Vtbl; static const IAudioClock2Vtbl AudioClock2_Vtbl; @@ -101,11 +101,6 @@ static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); }
-static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) -{ - return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface); -} - static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface) { return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface); @@ -1133,7 +1128,7 @@ static HRESULT WINAPI AudioClient_InitializeSharedAudioStream(IAudioClient3 *ifa return E_NOTIMPL; }
-static const IAudioClient3Vtbl AudioClient3_Vtbl = +const IAudioClient3Vtbl AudioClient3_Vtbl = { AudioClient_QueryInterface, AudioClient_AddRef, @@ -1511,249 +1506,6 @@ static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client) return ret; }
-static HRESULT WINAPI AudioSessionControl_QueryInterface( - IAudioSessionControl2 *iface, REFIID riid, void **ppv) -{ - TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); - - if(!ppv) - return E_POINTER; - *ppv = NULL; - - if(IsEqualIID(riid, &IID_IUnknown) || - IsEqualIID(riid, &IID_IAudioSessionControl) || - IsEqualIID(riid, &IID_IAudioSessionControl2)) - *ppv = iface; - if(*ppv){ - IUnknown_AddRef((IUnknown*)*ppv); - return S_OK; - } - - WARN("Unknown interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedIncrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - return ref; -} - -static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedDecrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - if(!ref){ - if(This->client){ - lock_sessions(TRUE); - This->client->session_wrapper = NULL; - lock_sessions(FALSE); - AudioClient_Release(&This->client->IAudioClient3_iface); - } - HeapFree(GetProcessHeap(), 0, This); - } - return ref; -} - -static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, - AudioSessionState *state) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - struct is_started_params params; - ACImpl *client; - - TRACE("(%p)->(%p)\n", This, state); - - if(!state) - return NULL_PTR_ERR; - - lock_sessions(TRUE); - - if(list_empty(&This->session->clients)){ - *state = AudioSessionStateExpired; - lock_sessions(FALSE); - return S_OK; - } - - LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry){ - params.stream = client->stream; - ALSA_CALL(is_started, ¶ms); - if(params.result == S_OK){ - *state = AudioSessionStateActive; - lock_sessions(FALSE); - return S_OK; - } - } - - lock_sessions(FALSE); - - *state = AudioSessionStateInactive; - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetDisplayName( - IAudioSessionControl2 *iface, WCHAR **name) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, name); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetDisplayName( - IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetIconPath( - IAudioSessionControl2 *iface, WCHAR **path) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, path); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetIconPath( - IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetGroupingParam( - IAudioSessionControl2 *iface, GUID *group) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, group); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetGroupingParam( - IAudioSessionControl2 *iface, const GUID *group, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group), - debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetProcessId( - IAudioSessionControl2 *iface, DWORD *pid) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%p)\n", This, pid); - - if(!pid) - return E_POINTER; - - *pid = GetCurrentProcessId(); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession( - IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)\n", This); - - return S_FALSE; -} - -static HRESULT WINAPI AudioSessionControl_SetDuckingPreference( - IAudioSessionControl2 *iface, BOOL optout) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%d)\n", This, optout); - - return S_OK; -} - -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl = -{ - AudioSessionControl_QueryInterface, - AudioSessionControl_AddRef, - AudioSessionControl_Release, - AudioSessionControl_GetState, - AudioSessionControl_GetDisplayName, - AudioSessionControl_SetDisplayName, - AudioSessionControl_GetIconPath, - AudioSessionControl_SetIconPath, - AudioSessionControl_GetGroupingParam, - AudioSessionControl_SetGroupingParam, - AudioSessionControl_RegisterAudioSessionNotification, - AudioSessionControl_UnregisterAudioSessionNotification, - AudioSessionControl_GetSessionIdentifier, - AudioSessionControl_GetSessionInstanceIdentifier, - AudioSessionControl_GetProcessId, - AudioSessionControl_IsSystemSoundsSession, - AudioSessionControl_SetDuckingPreference -}; - static HRESULT WINAPI SimpleAudioVolume_QueryInterface( ISimpleAudioVolume *iface, REFIID riid, void **ppv) { @@ -1778,13 +1530,13 @@ static HRESULT WINAPI SimpleAudioVolume_QueryInterface( static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( @@ -2060,13 +1812,13 @@ static HRESULT WINAPI ChannelAudioVolume_QueryInterface( static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/winecoreaudio.drv/Makefile.in | 2 + dlls/winecoreaudio.drv/mmdevdrv.c | 265 +---------------------------- 2 files changed, 9 insertions(+), 258 deletions(-)
diff --git a/dlls/winecoreaudio.drv/Makefile.in b/dlls/winecoreaudio.drv/Makefile.in index 28998a4bbf8..50be70794af 100644 --- a/dlls/winecoreaudio.drv/Makefile.in +++ b/dlls/winecoreaudio.drv/Makefile.in @@ -1,10 +1,12 @@ MODULE = winecoreaudio.drv UNIXLIB = winecoreaudio.so IMPORTS = uuid ole32 user32 advapi32 +PARENTSRC = ../mmdevapi DELAYIMPORTS = winmm UNIX_LIBS = $(COREAUDIO_LIBS)
C_SRCS = \ + audiosession.c \ coreaudio.c \ coremidi.c \ midi.c \ diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c index 8225d0ce741..ac3d32e4071 100644 --- a/dlls/winecoreaudio.drv/mmdevdrv.c +++ b/dlls/winecoreaudio.drv/mmdevdrv.c @@ -51,10 +51,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(coreaudio); static const REFERENCE_TIME DefaultPeriod = 100000; static const REFERENCE_TIME MinimumPeriod = 50000;
-static const IAudioClient3Vtbl AudioClient3_Vtbl; +const IAudioClient3Vtbl AudioClient3_Vtbl; static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; +extern const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl; static const IAudioClockVtbl AudioClock_Vtbl; static const IAudioClock2Vtbl AudioClock2_Vtbl; @@ -95,11 +95,6 @@ static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); }
-static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) -{ - return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface); -} - static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface) { return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface); @@ -1098,7 +1093,7 @@ static HRESULT WINAPI AudioClient_InitializeSharedAudioStream(IAudioClient3 *ifa return E_NOTIMPL; }
-static const IAudioClient3Vtbl AudioClient3_Vtbl = +const IAudioClient3Vtbl AudioClient3_Vtbl = { AudioClient_QueryInterface, AudioClient_AddRef, @@ -1461,252 +1456,6 @@ static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client) return ret; }
-static HRESULT WINAPI AudioSessionControl_QueryInterface( - IAudioSessionControl2 *iface, REFIID riid, void **ppv) -{ - TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); - - if(!ppv) - return E_POINTER; - *ppv = NULL; - - if(IsEqualIID(riid, &IID_IUnknown) || - IsEqualIID(riid, &IID_IAudioSessionControl) || - IsEqualIID(riid, &IID_IAudioSessionControl2)) - *ppv = iface; - if(*ppv){ - IUnknown_AddRef((IUnknown*)*ppv); - return S_OK; - } - - WARN("Unknown interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedIncrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - return ref; -} - -static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - - lock_sessions(TRUE); - - ref = InterlockedDecrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - if(!ref){ - if(This->client){ - This->client->session_wrapper = NULL; - AudioClient_Release(&This->client->IAudioClient3_iface); - } - HeapFree(GetProcessHeap(), 0, This); - } - - lock_sessions(FALSE); - return ref; -} - -static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, - AudioSessionState *state) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - struct is_started_params params; - ACImpl *client; - - TRACE("(%p)->(%p)\n", This, state); - - if(!state) - return NULL_PTR_ERR; - - lock_sessions(TRUE); - - if(list_empty(&This->session->clients)){ - *state = AudioSessionStateExpired; - lock_sessions(FALSE); - return S_OK; - } - - LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry){ - params.stream = client->stream; - UNIX_CALL(is_started, ¶ms); - if(params.result == S_OK){ - *state = AudioSessionStateActive; - lock_sessions(FALSE); - return S_OK; - } - } - - lock_sessions(FALSE); - - *state = AudioSessionStateInactive; - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetDisplayName( - IAudioSessionControl2 *iface, WCHAR **name) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, name); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetDisplayName( - IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetIconPath( - IAudioSessionControl2 *iface, WCHAR **path) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, path); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetIconPath( - IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetGroupingParam( - IAudioSessionControl2 *iface, GUID *group) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, group); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetGroupingParam( - IAudioSessionControl2 *iface, const GUID *group, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group), - debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetProcessId( - IAudioSessionControl2 *iface, DWORD *pid) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%p)\n", This, pid); - - if(!pid) - return E_POINTER; - - *pid = GetCurrentProcessId(); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession( - IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)\n", This); - - return S_FALSE; -} - -static HRESULT WINAPI AudioSessionControl_SetDuckingPreference( - IAudioSessionControl2 *iface, BOOL optout) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%d)\n", This, optout); - - return S_OK; -} - -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl = -{ - AudioSessionControl_QueryInterface, - AudioSessionControl_AddRef, - AudioSessionControl_Release, - AudioSessionControl_GetState, - AudioSessionControl_GetDisplayName, - AudioSessionControl_SetDisplayName, - AudioSessionControl_GetIconPath, - AudioSessionControl_SetIconPath, - AudioSessionControl_GetGroupingParam, - AudioSessionControl_SetGroupingParam, - AudioSessionControl_RegisterAudioSessionNotification, - AudioSessionControl_UnregisterAudioSessionNotification, - AudioSessionControl_GetSessionIdentifier, - AudioSessionControl_GetSessionInstanceIdentifier, - AudioSessionControl_GetProcessId, - AudioSessionControl_IsSystemSoundsSession, - AudioSessionControl_SetDuckingPreference -}; - static HRESULT WINAPI SimpleAudioVolume_QueryInterface( ISimpleAudioVolume *iface, REFIID riid, void **ppv) { @@ -1731,13 +1480,13 @@ static HRESULT WINAPI SimpleAudioVolume_QueryInterface( static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( @@ -2011,13 +1760,13 @@ static HRESULT WINAPI ChannelAudioVolume_QueryInterface( static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/wineoss.drv/Makefile.in | 2 + dlls/wineoss.drv/mmdevdrv.c | 262 +---------------------------------- 2 files changed, 9 insertions(+), 255 deletions(-)
diff --git a/dlls/wineoss.drv/Makefile.in b/dlls/wineoss.drv/Makefile.in index a1771e14e2a..3cefb67951f 100644 --- a/dlls/wineoss.drv/Makefile.in +++ b/dlls/wineoss.drv/Makefile.in @@ -1,11 +1,13 @@ MODULE = wineoss.drv UNIXLIB = wineoss.so IMPORTS = uuid ole32 user32 advapi32 +PARENTSRC = ../mmdevapi DELAYIMPORTS = winmm UNIX_LIBS = $(OSS4_LIBS) $(PTHREAD_LIBS) UNIX_CFLAGS = $(OSS4_CFLAGS)
C_SRCS = \ + audiosession.c \ midi.c \ midipatch.c \ mmaux.c \ diff --git a/dlls/wineoss.drv/mmdevdrv.c b/dlls/wineoss.drv/mmdevdrv.c index d543e525036..85f28b3788a 100644 --- a/dlls/wineoss.drv/mmdevdrv.c +++ b/dlls/wineoss.drv/mmdevdrv.c @@ -77,10 +77,10 @@ static struct list g_sessions = LIST_INIT(g_sessions);
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
-static const IAudioClient3Vtbl AudioClient3_Vtbl; +const IAudioClient3Vtbl AudioClient3_Vtbl; static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; +extern const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl; static const IAudioClockVtbl AudioClock_Vtbl; static const IAudioClock2Vtbl AudioClock2_Vtbl; @@ -107,11 +107,6 @@ static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); }
-static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) -{ - return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface); -} - static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface) { return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface); @@ -1090,7 +1085,7 @@ static HRESULT WINAPI AudioClient_InitializeSharedAudioStream(IAudioClient3 *ifa return E_NOTIMPL; }
-static const IAudioClient3Vtbl AudioClient3_Vtbl = +const IAudioClient3Vtbl AudioClient3_Vtbl = { AudioClient_QueryInterface, AudioClient_AddRef, @@ -1460,249 +1455,6 @@ static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client) return ret; }
-static HRESULT WINAPI AudioSessionControl_QueryInterface( - IAudioSessionControl2 *iface, REFIID riid, void **ppv) -{ - TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); - - if(!ppv) - return E_POINTER; - *ppv = NULL; - - if(IsEqualIID(riid, &IID_IUnknown) || - IsEqualIID(riid, &IID_IAudioSessionControl) || - IsEqualIID(riid, &IID_IAudioSessionControl2)) - *ppv = iface; - if(*ppv){ - IUnknown_AddRef((IUnknown*)*ppv); - return S_OK; - } - - WARN("Unknown interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedIncrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - return ref; -} - -static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedDecrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - if(!ref){ - if(This->client){ - lock_sessions(TRUE); - This->client->session_wrapper = NULL; - lock_sessions(FALSE); - AudioClient_Release(&This->client->IAudioClient3_iface); - } - HeapFree(GetProcessHeap(), 0, This); - } - return ref; -} - -static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, - AudioSessionState *state) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - struct is_started_params params; - ACImpl *client; - - TRACE("(%p)->(%p)\n", This, state); - - if(!state) - return NULL_PTR_ERR; - - lock_sessions(TRUE); - - if(list_empty(&This->session->clients)){ - *state = AudioSessionStateExpired; - lock_sessions(FALSE); - return S_OK; - } - - LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry){ - params.stream = client->stream; - OSS_CALL(is_started, ¶ms); - if(params.result == S_OK){ - *state = AudioSessionStateActive; - lock_sessions(FALSE); - return S_OK; - } - } - - lock_sessions(FALSE); - - *state = AudioSessionStateInactive; - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetDisplayName( - IAudioSessionControl2 *iface, WCHAR **name) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, name); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetDisplayName( - IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetIconPath( - IAudioSessionControl2 *iface, WCHAR **path) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, path); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetIconPath( - IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetGroupingParam( - IAudioSessionControl2 *iface, GUID *group) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, group); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetGroupingParam( - IAudioSessionControl2 *iface, const GUID *group, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group), - debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetProcessId( - IAudioSessionControl2 *iface, DWORD *pid) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%p)\n", This, pid); - - if(!pid) - return E_POINTER; - - *pid = GetCurrentProcessId(); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession( - IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)\n", This); - - return S_FALSE; -} - -static HRESULT WINAPI AudioSessionControl_SetDuckingPreference( - IAudioSessionControl2 *iface, BOOL optout) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%d)\n", This, optout); - - return S_OK; -} - -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl = -{ - AudioSessionControl_QueryInterface, - AudioSessionControl_AddRef, - AudioSessionControl_Release, - AudioSessionControl_GetState, - AudioSessionControl_GetDisplayName, - AudioSessionControl_SetDisplayName, - AudioSessionControl_GetIconPath, - AudioSessionControl_SetIconPath, - AudioSessionControl_GetGroupingParam, - AudioSessionControl_SetGroupingParam, - AudioSessionControl_RegisterAudioSessionNotification, - AudioSessionControl_UnregisterAudioSessionNotification, - AudioSessionControl_GetSessionIdentifier, - AudioSessionControl_GetSessionInstanceIdentifier, - AudioSessionControl_GetProcessId, - AudioSessionControl_IsSystemSoundsSession, - AudioSessionControl_SetDuckingPreference -}; - static HRESULT WINAPI SimpleAudioVolume_QueryInterface( ISimpleAudioVolume *iface, REFIID riid, void **ppv) { @@ -1727,13 +1479,13 @@ static HRESULT WINAPI SimpleAudioVolume_QueryInterface( static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( @@ -2006,13 +1758,13 @@ static HRESULT WINAPI ChannelAudioVolume_QueryInterface( static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
From: Davide Beatrici git@davidebeatrici.dev
--- dlls/winepulse.drv/Makefile.in | 2 + dlls/winepulse.drv/mmdevdrv.c | 259 +-------------------------------- 2 files changed, 9 insertions(+), 252 deletions(-)
diff --git a/dlls/winepulse.drv/Makefile.in b/dlls/winepulse.drv/Makefile.in index 7a78f4e854e..0fa703ab5ed 100644 --- a/dlls/winepulse.drv/Makefile.in +++ b/dlls/winepulse.drv/Makefile.in @@ -1,9 +1,11 @@ MODULE = winepulse.drv UNIXLIB = winepulse.so IMPORTS = dxguid uuid winmm user32 advapi32 ole32 version +PARENTSRC = ../mmdevapi UNIX_LIBS = $(PULSE_LIBS) $(PTHREAD_LIBS) -lm UNIX_CFLAGS = $(PULSE_CFLAGS)
C_SRCS = \ + audiosession.c \ mmdevdrv.c \ pulse.c diff --git a/dlls/winepulse.drv/mmdevdrv.c b/dlls/winepulse.drv/mmdevdrv.c index fb0b3c46307..abcf3ecd60c 100644 --- a/dlls/winepulse.drv/mmdevdrv.c +++ b/dlls/winepulse.drv/mmdevdrv.c @@ -119,10 +119,10 @@ BOOL WINAPI DllMain(HINSTANCE dll, DWORD reason, void *reserved) return TRUE; }
-static const IAudioClient3Vtbl AudioClient3_Vtbl; +const IAudioClient3Vtbl AudioClient3_Vtbl; static const IAudioRenderClientVtbl AudioRenderClient_Vtbl; static const IAudioCaptureClientVtbl AudioCaptureClient_Vtbl; -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; +extern const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl; static const ISimpleAudioVolumeVtbl SimpleAudioVolume_Vtbl; static const IChannelAudioVolumeVtbl ChannelAudioVolume_Vtbl; static const IAudioClockVtbl AudioClock_Vtbl; @@ -146,11 +146,6 @@ static inline ACImpl *impl_from_IAudioCaptureClient(IAudioCaptureClient *iface) return CONTAINING_RECORD(iface, ACImpl, IAudioCaptureClient_iface); }
-static inline AudioSessionWrapper *impl_from_IAudioSessionControl2(IAudioSessionControl2 *iface) -{ - return CONTAINING_RECORD(iface, AudioSessionWrapper, IAudioSessionControl2_iface); -} - static inline AudioSessionWrapper *impl_from_ISimpleAudioVolume(ISimpleAudioVolume *iface) { return CONTAINING_RECORD(iface, AudioSessionWrapper, ISimpleAudioVolume_iface); @@ -1333,7 +1328,7 @@ static HRESULT WINAPI AudioClient_InitializeSharedAudioStream(IAudioClient3 *ifa return E_NOTIMPL; }
-static const IAudioClient3Vtbl AudioClient3_Vtbl = +const IAudioClient3Vtbl AudioClient3_Vtbl = { AudioClient_QueryInterface, AudioClient_AddRef, @@ -1887,246 +1882,6 @@ static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client) return ret; }
-static HRESULT WINAPI AudioSessionControl_QueryInterface( - IAudioSessionControl2 *iface, REFIID riid, void **ppv) -{ - TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), ppv); - - if (!ppv) - return E_POINTER; - *ppv = NULL; - - if (IsEqualIID(riid, &IID_IUnknown) || - IsEqualIID(riid, &IID_IAudioSessionControl) || - IsEqualIID(riid, &IID_IAudioSessionControl2)) - *ppv = iface; - if (*ppv) { - IUnknown_AddRef((IUnknown*)*ppv); - return S_OK; - } - - WARN("Unknown interface %s\n", debugstr_guid(riid)); - return E_NOINTERFACE; -} - -static ULONG WINAPI AudioSessionControl_AddRef(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedIncrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - return ref; -} - -static ULONG WINAPI AudioSessionControl_Release(IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ULONG ref; - ref = InterlockedDecrement(&This->ref); - TRACE("(%p) Refcount now %lu\n", This, ref); - if (!ref) { - if (This->client) { - This->client->session_wrapper = NULL; - AudioClient_Release(&This->client->IAudioClient3_iface); - } - HeapFree(GetProcessHeap(), 0, This); - } - return ref; -} - -static HRESULT WINAPI AudioSessionControl_GetState(IAudioSessionControl2 *iface, - AudioSessionState *state) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - ACImpl *client; - - TRACE("(%p)->(%p)\n", This, state); - - if (!state) - return NULL_PTR_ERR; - - lock_sessions(TRUE); - if (list_empty(&This->session->clients)) { - *state = AudioSessionStateExpired; - goto out; - } - LIST_FOR_EACH_ENTRY(client, &This->session->clients, ACImpl, entry) { - struct is_started_params params; - - if (!client->stream) - continue; - - params.stream = client->stream; - pulse_call(is_started, ¶ms); - if (params.result == S_OK) { - *state = AudioSessionStateActive; - goto out; - } - } - *state = AudioSessionStateInactive; - -out: - lock_sessions(FALSE); - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetDisplayName( - IAudioSessionControl2 *iface, WCHAR **name) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, name); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetDisplayName( - IAudioSessionControl2 *iface, const WCHAR *name, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, name, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetIconPath( - IAudioSessionControl2 *iface, WCHAR **path) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, path); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetIconPath( - IAudioSessionControl2 *iface, const WCHAR *path, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p, %s) - stub\n", This, path, debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetGroupingParam( - IAudioSessionControl2 *iface, GUID *group) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, group); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_SetGroupingParam( - IAudioSessionControl2 *iface, const GUID *group, const GUID *session) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%s, %s) - stub\n", This, debugstr_guid(group), - debugstr_guid(session)); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_RegisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_UnregisterAudioSessionNotification( - IAudioSessionControl2 *iface, IAudioSessionEvents *events) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, events); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetSessionInstanceIdentifier( - IAudioSessionControl2 *iface, WCHAR **id) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - FIXME("(%p)->(%p) - stub\n", This, id); - - return E_NOTIMPL; -} - -static HRESULT WINAPI AudioSessionControl_GetProcessId( - IAudioSessionControl2 *iface, DWORD *pid) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%p)\n", This, pid); - - if (!pid) - return E_POINTER; - - *pid = GetCurrentProcessId(); - - return S_OK; -} - -static HRESULT WINAPI AudioSessionControl_IsSystemSoundsSession( - IAudioSessionControl2 *iface) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)\n", This); - - return S_FALSE; -} - -static HRESULT WINAPI AudioSessionControl_SetDuckingPreference( - IAudioSessionControl2 *iface, BOOL optout) -{ - AudioSessionWrapper *This = impl_from_IAudioSessionControl2(iface); - - TRACE("(%p)->(%d)\n", This, optout); - - return S_OK; -} - -static const IAudioSessionControl2Vtbl AudioSessionControl2_Vtbl = -{ - AudioSessionControl_QueryInterface, - AudioSessionControl_AddRef, - AudioSessionControl_Release, - AudioSessionControl_GetState, - AudioSessionControl_GetDisplayName, - AudioSessionControl_SetDisplayName, - AudioSessionControl_GetIconPath, - AudioSessionControl_SetIconPath, - AudioSessionControl_GetGroupingParam, - AudioSessionControl_SetGroupingParam, - AudioSessionControl_RegisterAudioSessionNotification, - AudioSessionControl_UnregisterAudioSessionNotification, - AudioSessionControl_GetSessionIdentifier, - AudioSessionControl_GetSessionInstanceIdentifier, - AudioSessionControl_GetProcessId, - AudioSessionControl_IsSystemSoundsSession, - AudioSessionControl_SetDuckingPreference -}; - static HRESULT WINAPI SimpleAudioVolume_QueryInterface( ISimpleAudioVolume *iface, REFIID riid, void **ppv) { @@ -2151,13 +1906,13 @@ static HRESULT WINAPI SimpleAudioVolume_QueryInterface( static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI SimpleAudioVolume_Release(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI SimpleAudioVolume_SetMasterVolume( @@ -2274,13 +2029,13 @@ static HRESULT WINAPI ChannelAudioVolume_QueryInterface( static ULONG WINAPI ChannelAudioVolume_AddRef(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface); }
static ULONG WINAPI ChannelAudioVolume_Release(IChannelAudioVolume *iface) { AudioSessionWrapper *This = impl_from_IChannelAudioVolume(iface); - return AudioSessionControl_Release(&This->IAudioSessionControl2_iface); + return AudioSessionControl2_Vtbl.Release(&This->IAudioSessionControl2_iface); }
static HRESULT WINAPI ChannelAudioVolume_GetChannelCount(
I apologize for the many CI failures. Everything should be in order now.
On a separate note, I checked the exported symbols using `nm` to make sure I specified `DECLSPEC_HIDDEN` when required and I noticed the presence of `alsa_wow64_midi_in_message()` and `alsa_wow64_midi_notify_wait()`. Should I fix that in another merge request?
Huw Davies (@huw) commented about dlls/mmdevapi/audioclient.c:
- AudioClient_GetCurrentPadding,
- AudioClient_IsFormatSupported,
- AudioClient_GetMixFormat,
- AudioClient_GetDevicePeriod,
- AudioClient_Start,
- AudioClient_Stop,
- AudioClient_Reset,
- AudioClient_SetEventHandle,
- AudioClient_GetService,
- AudioClient_IsOffloadCapable,
- AudioClient_SetClientProperties,
- AudioClient_GetBufferSizeLimits,
- AudioClient_GetSharedModeEnginePeriod,
- AudioClient_GetCurrentSharedModeEnginePeriod,
- AudioClient_InitializeSharedAudioStream,
+};
This is introducing a load of dead-code again - it should be added when its first used.
In this case, you just need `AudioClient3_Vtbl` so that `mmdevapi.dll` compiles. So you could just add a zero-inited struct (in the appropriate commit). Leave filling out functions until you move the audio client handling to `mmdevapi`.
Huw Davies (@huw) commented about dlls/mmdevapi/audiosession.c:
- ASC_Release,
- ASC_GetState,
- ASC_GetDisplayName,
- ASC_SetDisplayName,
- ASC_GetIconPath,
- ASC_SetIconPath,
- ASC_GetGroupingParam,
- ASC_SetGroupingParam,
- ASC_RegisterAudioSessionNotification,
- ASC_UnregisterAudioSessionNotification,
- ASC_GetSessionIdentifier,
- ASC_GetSessionInstanceIdentifier,
- ASC_GetProcessId,
- ASC_IsSystemSoundsSession,
- ASC_SetDuckingPreference
+};
Dead code again. Add when first used.
Also note, I'm not sure we want `audiosession.c`, `audiosessionmanger.c`, `audiosessionwrapper.c`, etc. (I should have pointed this out before we added the manager). Ideally all of this would live in `audiosession.c` (if it's really too much to go in `audioclient.c`). If you need to separate them to make the transistion easier then that's ok, but any additional files that you can avoid creating at this stage would be good.
Huw Davies (@huw) commented about dlls/mmdevapi/audiosessionmanager.c:
static struct list g_sessions = LIST_INIT(g_sessions);
+static CRITICAL_SECTION g_sessions_lock; +static CRITICAL_SECTION_DEBUG g_sessions_lock_debug = +{
- 0, 0, &g_sessions_lock,
- { &g_sessions_lock_debug.ProcessLocksList, &g_sessions_lock_debug.ProcessLocksList },
- 0, 0, { (DWORD_PTR)(__FILE__ ": g_sessions_lock") }
+}; +static CRITICAL_SECTION g_sessions_lock = { &g_sessions_lock_debug, -1, 0, 0, 0, 0 };
+void lock_sessions(const BOOLEAN lock) +{
- lock ? EnterCriticalSection(&g_sessions_lock) : LeaveCriticalSection(&g_sessions_lock);
+}
I'd prefer two functions `sessions_lock()` and `sessions_unlock()` (cf. `pulse_lock()` and `pulse_unlock()`).
Huw Davies (@huw) commented about dlls/winealsa.drv/mmdevdrv.c:
static AudioSessionWrapper *AudioSessionWrapper_Create(ACImpl *client);
+void lock_sessions(const BOOLEAN lock) +{
- lock ? EnterCriticalSection(&g_sessions_lock) : LeaveCriticalSection(&g_sessions_lock);
+}
This, and the next three commits, could be pulled out to a separate MR.
Huw Davies (@huw) commented about dlls/winealsa.drv/mmdevdrv.c:
static ULONG WINAPI SimpleAudioVolume_AddRef(ISimpleAudioVolume *iface) { AudioSessionWrapper *This = impl_from_ISimpleAudioVolume(iface);
- return AudioSessionControl_AddRef(&This->IAudioSessionControl2_iface);
- return AudioSessionControl2_Vtbl.AddRef(&This->IAudioSessionControl2_iface);
This (and similar changes below and in the next three commits) should use the `IAudioSessionControl2_AddRef()` macro (or similar). These macro changes could be done in advance in a separate MR.
On Fri Apr 21 09:02:33 2023 +0000, Huw Davies wrote:
This is introducing a load of dead-code again - it should be added when its first used. In this case, you just need `AudioClient3_Vtbl` so that `mmdevapi.dll` compiles. So you could just add a zero-inited struct (in the appropriate commit). Leave filling out functions until you move the audio client handling to `mmdevapi`.
No problem, I'm going to save the no-op functions for later and replace all of this with an empty object.
On Fri Apr 21 09:02:33 2023 +0000, Huw Davies wrote:
Dead code again. Add when first used. Also note, I'm not sure we want `audiosession.c`, `audiosessionmanger.c`, `audiosessionwrapper.c`, etc. (I should have pointed this out before we added the manager). Ideally all of this would live in `audiosession.c` (if it's really too much to go in `audioclient.c`). If you need to separate them to make the transistion easier then that's ok, but any additional files that you can avoid creating at this stage would be good.
The idea is to have one file per struct (not including `audio_session_wrapper`, which is shared):
- `audioclient.c` - `audiosession.c` - `audiosessionmanager.c`
On Fri Apr 21 09:02:34 2023 +0000, Huw Davies wrote:
I'd prefer two functions `sessions_lock()` and `sessions_unlock()` (cf. `pulse_lock()` and `pulse_unlock()`).
!2694
On Fri Apr 21 09:02:35 2023 +0000, Huw Davies wrote:
This, and the next three commits, could be pulled out to a separate MR.
!2694
On Fri Apr 21 09:02:35 2023 +0000, Huw Davies wrote:
This (and similar changes below and in the next three commits) should use the `IAudioSessionControl2_AddRef()` macro (or similar). These macro changes could be done in advance in a separate MR.
!2695
On Fri Apr 21 18:56:48 2023 +0000, Davide Beatrici wrote:
The idea is to have one file per struct (not including `audio_session_wrapper`, which is shared):
- `audioclient.c`
- `audiosession.c`
- `audiosessionmanager.c`
That's probably ok.