[PATCH 0/3] MR10919: dsound cleanup
This incorporates / supersedes !10882 and !10886. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10919
From: Jon Koops <jonkoops@gmail.com> With device sharing removed, each DirectSoundDevice has exactly one owner and no longer needs reference counting. Replace the ref field with a flag and simplify DirectSoundDevice_Release to free unconditionally. Signed-off-by: Jon Koops <jonkoops@gmail.com> --- dlls/dsound/dsound.c | 13 +++++-------- dlls/dsound/dsound_private.h | 3 +-- dlls/dsound/mixer.c | 33 ++++++++++++++------------------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c index b5c53829a5b..c6b05516d32 100644 --- a/dlls/dsound/dsound.c +++ b/dlls/dsound/dsound.c @@ -134,7 +134,6 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice) return DSERR_OUTOFMEMORY; } - device->ref = 1; device->priolevel = DSSCL_NORMAL; device->stopped = 1; device->speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, DSSPEAKER_GEOMETRY_WIDE); @@ -187,14 +186,14 @@ static HRESULT DirectSoundDevice_Create(DirectSoundDevice ** ppDevice) return DS_OK; } -static ULONG DirectSoundDevice_Release(DirectSoundDevice * device) +static void DirectSoundDevice_destroy(DirectSoundDevice *device) { HRESULT hr; - ULONG ref = InterlockedDecrement(&(device->ref)); - TRACE("(%p) ref %ld\n", device, ref); - if (!ref) { int i; + TRACE("(%p)\n", device); + + InterlockedExchange(&device->terminated, TRUE); SetEvent(device->sleepev); if (device->thread) { WaitForSingleObject(device->thread, INFINITE); @@ -236,8 +235,6 @@ static ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DeleteCriticalSection(&device->mixlock); TRACE("(%p) released\n", device); free(device); - } - return ref; } static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGUID lpcGUID) @@ -611,7 +608,7 @@ void DirectSoundDevice_RemoveBuffer(DirectSoundDevice * device, IDirectSoundBuff static void directsound_destroy(IDirectSoundImpl *This) { if (This->device) - DirectSoundDevice_Release(This->device); + DirectSoundDevice_destroy(This->device); TRACE("(%p) released\n", This); free(This); } diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index 75279dacf87..a728472b7be 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -70,14 +70,13 @@ typedef struct DSFilter { */ struct DirectSoundDevice { - LONG ref; - GUID guid; DSCAPS drvcaps; DWORD priolevel, sleeptime; PWAVEFORMATEX pwfx, primary_pwfx; LPBYTE buffer; DWORD writelead, buflen, ac_frames, frag_frames, playpos, pad, stopped; + LONG terminated; int nrofbuffers; IDirectSoundBufferImpl** buffers; SRWLOCK buffer_list_lock; diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index 45e37c5bcb1..cb01fde468e 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -888,24 +888,19 @@ DWORD CALLBACK DSOUND_mixthread(void *p) SetThreadDescription(GetCurrentThread(), L"wine_dsound_mixer"); _controlfp_s(NULL, _DN_FLUSH, _MCW_DN); - while (dev->ref) { - DWORD ret; - - /* - * Some audio drivers are retarded and won't fire after being - * stopped, add a timeout to handle this. - */ - ret = WaitForSingleObject(dev->sleepev, dev->sleeptime); - if (ret == WAIT_FAILED) - WARN("wait returned error %lu %08lx!\n", GetLastError(), GetLastError()); - else if (ret != WAIT_OBJECT_0) - WARN("wait returned %08lx!\n", ret); - if (!dev->ref) - break; - - AcquireSRWLockShared(&dev->buffer_list_lock); - DSOUND_PerformMix(dev); - ReleaseSRWLockShared(&dev->buffer_list_lock); - } + for (;;) + { + DWORD ret = WaitForSingleObject(dev->sleepev, dev->sleeptime); + if (ret == WAIT_FAILED) + WARN("wait returned error %lu %08lx!\n", GetLastError(), GetLastError()); + else if (ret != WAIT_OBJECT_0) + WARN("wait returned %08lx!\n", ret); + if (dev->terminated) + break; + + AcquireSRWLockShared(&dev->buffer_list_lock); + DSOUND_PerformMix(dev); + ReleaseSRWLockShared(&dev->buffer_list_lock); + } return 0; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10919
From: Jon Koops <jonkoops@gmail.com> With device sharing removed, the global DSOUND_renderers list is no longer used for lookups. Devices were still added to and removed from the list, but nothing read from it. Remove the list, the critical section protecting it, and the entry field from DirectSoundDevice. Signed-off-by: Jon Koops <jonkoops@gmail.com> --- dlls/dsound/dsound.c | 11 ----------- dlls/dsound/dsound_main.c | 12 ------------ dlls/dsound/dsound_private.h | 4 ---- 3 files changed, 27 deletions(-) diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c index c6b05516d32..d4cc0cdb64b 100644 --- a/dlls/dsound/dsound.c +++ b/dlls/dsound/dsound.c @@ -202,10 +202,6 @@ static void DirectSoundDevice_destroy(DirectSoundDevice *device) if (device->mta_cookie) CoDecrementMTAUsage(device->mta_cookie); - EnterCriticalSection(&DSOUND_renderers_lock); - list_remove(&device->entry); - LeaveCriticalSection(&DSOUND_renderers_lock); - /* It is allowed to release this object even when buffers are playing */ if (device->buffers) { WARN("%d secondary buffers not released\n", device->nrofbuffers); @@ -269,13 +265,10 @@ static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGU if(FAILED(hr)) return hr; - EnterCriticalSection(&DSOUND_renderers_lock); - hr = DirectSoundDevice_Create(&device); if(FAILED(hr)){ WARN("DirectSoundDevice_Create failed\n"); IMMDevice_Release(mmdevice); - LeaveCriticalSection(&DSOUND_renderers_lock); return hr; } @@ -288,7 +281,6 @@ static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGU if (FAILED(hr)) { free(device); - LeaveCriticalSection(&DSOUND_renderers_lock); IMMDevice_Release(mmdevice); WARN("DSOUND_ReopenDevice failed: %08lx\n", hr); return hr; @@ -325,9 +317,6 @@ static HRESULT DirectSoundDevice_Initialize(DirectSoundDevice ** ppDevice, LPCGU SetThreadPriority(device->thread, THREAD_PRIORITY_TIME_CRITICAL); *ppDevice = device; - list_add_tail(&DSOUND_renderers, &device->entry); - - LeaveCriticalSection(&DSOUND_renderers_lock); return hr; } diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c index 8936b437ba2..e2b9b81beef 100644 --- a/dlls/dsound/dsound_main.c +++ b/dlls/dsound/dsound_main.c @@ -63,16 +63,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(dsound); -struct list DSOUND_renderers = LIST_INIT(DSOUND_renderers); -CRITICAL_SECTION DSOUND_renderers_lock; -static CRITICAL_SECTION_DEBUG DSOUND_renderers_lock_debug = -{ - 0, 0, &DSOUND_renderers_lock, - { &DSOUND_renderers_lock_debug.ProcessLocksList, &DSOUND_renderers_lock_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": DSOUND_renderers_lock") } -}; -CRITICAL_SECTION DSOUND_renderers_lock = { &DSOUND_renderers_lock_debug, -1, 0, 0, 0, 0 }; - /* Some applications expect the GUID pointers emitted from DirectSoundCaptureEnumerate to remain * valid at least until the next time DirectSoundCaptureEnumerate is called, so we store them in * these dynamically allocated arrays. */ @@ -789,8 +779,6 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved) GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)hInstDLL, &hInstDLL); break; case DLL_PROCESS_DETACH: - if (lpvReserved) break; - DeleteCriticalSection(&DSOUND_renderers_lock); break; } return TRUE; diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h index a728472b7be..244d88f7538 100644 --- a/dlls/dsound/dsound_private.h +++ b/dlls/dsound/dsound_private.h @@ -105,7 +105,6 @@ struct DirectSoundDevice IAudioRenderClient *render; HANDLE sleepev, thread; - struct list entry; }; /* reference counted buffer memory for duplicated buffer memory */ @@ -250,9 +249,6 @@ HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void ** #define STATE_CAPTURING 2 #define STATE_STOPPING 3 -extern CRITICAL_SECTION DSOUND_renderers_lock; -extern struct list DSOUND_renderers; - extern GUID *DSOUND_renderer_guids; extern GUID *DSOUND_capture_guids; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10919
From: Matteo Bruni <mbruni@codeweavers.com> It's unused since 5b0914ece97b0732796313588f69ce1085664498, merged almost exactly 10 years ago. --- dlls/dsound/mixer.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index cb01fde468e..1be5b5a2385 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -703,24 +703,11 @@ static DWORD DSOUND_MixOne(IDirectSoundBufferImpl *dsb, float *mix_buffer, DWORD return primary_done; } -/** - * For a DirectSoundDevice, go through all the currently playing buffers and - * mix them in to the device buffer. - * - * frames = the maximum amount to mix into the primary buffer - * all_stopped = reports back if all buffers have stopped - * - * Returns: the length beyond the writepos that was mixed to. - */ - -static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buffer, DWORD frames, BOOL *all_stopped) +static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buffer, DWORD frames) { INT i; IDirectSoundBufferImpl *dsb; - /* unless we find a running buffer, all have stopped */ - *all_stopped = TRUE; - TRACE("(frames %ld)\n", frames); for (i = 0; i < device->nrofbuffers; i++) { dsb = device->buffers[i]; @@ -738,8 +725,6 @@ static void DSOUND_MixToPrimary(const DirectSoundDevice *device, float *mix_buff /* mix next buffer into the main buffer */ DSOUND_MixOne(dsb, mix_buffer, frames); - - *all_stopped = FALSE; } ReleaseSRWLockShared(&dsb->lock); } @@ -826,7 +811,6 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) frames = device->frag_frames * 3; if (device->priolevel != DSSCL_WRITEPRIMARY) { - BOOL all_stopped = FALSE; int nfiller; void *buffer = NULL; @@ -848,12 +832,12 @@ static void DSOUND_PerformMix(DirectSoundDevice *device) memset(buffer, nfiller, frames * block); if (!device->normfunction) - DSOUND_MixToPrimary(device, buffer, frames, &all_stopped); + DSOUND_MixToPrimary(device, buffer, frames); else { memset(device->buffer, nfiller, device->buflen); /* do the mixing */ - DSOUND_MixToPrimary(device, (float*)device->buffer, frames, &all_stopped); + DSOUND_MixToPrimary(device, (float*)device->buffer, frames); device->normfunction(device->buffer, buffer, frames * device->pwfx->nChannels); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10919
This merge request was approved by Matteo Bruni. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10919
This merge request was approved by Huw Davies. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10919
participants (4)
-
Huw Davies (@huw) -
Jon Koops -
Matteo Bruni -
Matteo Bruni (@Mystral)