Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/winecoreaudio.drv/mmdevdrv.c | 28 ++++++++++++++++++++-------- dlls/winecoreaudio.drv/unixlib.h | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c index 1e37a2a9026..642610b4b60 100644 --- a/dlls/winecoreaudio.drv/mmdevdrv.c +++ b/dlls/winecoreaudio.drv/mmdevdrv.c @@ -653,9 +653,13 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) LeaveCriticalSection(&g_sessions_lock); } HeapFree(GetProcessHeap(), 0, This->vols); - HeapFree(GetProcessHeap(), 0, This->stream->tmp_buffer); HeapFree(GetProcessHeap(), 0, This->stream->cap_buffer); - HeapFree(GetProcessHeap(), 0, This->stream->local_buffer); + if(This->stream->local_buffer) + NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->local_buffer, + &This->stream->local_buffer_size, MEM_RELEASE); + if(This->stream->tmp_buffer) + NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, + &This->stream->tmp_buffer_size, MEM_RELEASE); free(This->stream->wrap_buffer); HeapFree(GetProcessHeap(), 0, This->stream->resamp_buffer); CoTaskMemFree(This->stream->fmt); @@ -1335,7 +1339,9 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, return osstatus_to_hresult(sc); }
- This->stream->local_buffer = HeapAlloc(GetProcessHeap(), 0, This->stream->bufsize_frames * fmt->nBlockAlign); + This->stream->local_buffer_size = This->stream->bufsize_frames * fmt->nBlockAlign; + NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->local_buffer, 0, + &This->stream->local_buffer_size, MEM_COMMIT, PAGE_READWRITE); silence_buffer(This, This->stream->local_buffer, This->stream->bufsize_frames);
if(This->dataflow == eCapture){ @@ -2292,9 +2298,12 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
if(This->stream->wri_offs_frames + frames > This->stream->bufsize_frames){ if(This->stream->tmp_buffer_frames < frames){ - HeapFree(GetProcessHeap(), 0, This->stream->tmp_buffer); - This->stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, frames * This->stream->fmt->nBlockAlign); - if(!This->stream->tmp_buffer){ + NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, + &This->stream->tmp_buffer_size, MEM_RELEASE); + This->stream->tmp_buffer_size = frames * This->stream->fmt->nBlockAlign; + if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, 0, + &This->stream->tmp_buffer_size, MEM_COMMIT, PAGE_READWRITE)){ + This->stream->tmp_buffer_frames = 0; OSSpinLockUnlock(&This->stream->lock); return E_OUTOFMEMORY; } @@ -2449,8 +2458,11 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface, chunk_frames = This->stream->bufsize_frames - This->stream->lcl_offs_frames; if(chunk_frames < This->stream->period_frames){ chunk_bytes = chunk_frames * This->stream->fmt->nBlockAlign; - if(!This->stream->tmp_buffer) - This->stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, This->stream->period_frames * This->stream->fmt->nBlockAlign); + if(!This->stream->tmp_buffer){ + This->stream->tmp_buffer_size = This->stream->period_frames * This->stream->fmt->nBlockAlign; + NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, 0, + &This->stream->tmp_buffer_size, MEM_COMMIT, PAGE_READWRITE); + } *data = This->stream->tmp_buffer; memcpy(*data, This->stream->local_buffer + This->stream->lcl_offs_frames * This->stream->fmt->nBlockAlign, chunk_bytes); memcpy((*data) + chunk_bytes, This->stream->local_buffer, This->stream->period_frames * This->stream->fmt->nBlockAlign - chunk_bytes); diff --git a/dlls/winecoreaudio.drv/unixlib.h b/dlls/winecoreaudio.drv/unixlib.h index 6a991f1de98..1b773b7f820 100644 --- a/dlls/winecoreaudio.drv/unixlib.h +++ b/dlls/winecoreaudio.drv/unixlib.h @@ -29,7 +29,6 @@ struct coreaudio_stream /* To be made private */ AUDCLNT_SHAREMODE share;
BOOL playing; - SIZE_T local_buffer_size, tmp_buffer_size; UINT32 period_ms, period_frames; UINT32 bufsize_frames, resamp_bufsize_frames; UINT32 lcl_offs_frames, held_frames, wri_offs_frames, tmp_buffer_frames; @@ -39,6 +38,7 @@ struct coreaudio_stream /* To be made private */ INT32 getbuf_last; WAVEFORMATEX *fmt; BYTE *local_buffer, *cap_buffer, *wrap_buffer, *resamp_buffer, *tmp_buffer; + SIZE_T local_buffer_size, tmp_buffer_size; };
struct endpoint
Signed-off-by: Andrew Eikum aeikum@codeweavers.com
On Thu, Nov 18, 2021 at 07:52:32AM +0000, Huw Davies wrote:
Signed-off-by: Huw Davies huw@codeweavers.com
dlls/winecoreaudio.drv/mmdevdrv.c | 28 ++++++++++++++++++++-------- dlls/winecoreaudio.drv/unixlib.h | 2 +- 2 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/dlls/winecoreaudio.drv/mmdevdrv.c b/dlls/winecoreaudio.drv/mmdevdrv.c index 1e37a2a9026..642610b4b60 100644 --- a/dlls/winecoreaudio.drv/mmdevdrv.c +++ b/dlls/winecoreaudio.drv/mmdevdrv.c @@ -653,9 +653,13 @@ static ULONG WINAPI AudioClient_Release(IAudioClient3 *iface) LeaveCriticalSection(&g_sessions_lock); } HeapFree(GetProcessHeap(), 0, This->vols);
HeapFree(GetProcessHeap(), 0, This->stream->tmp_buffer); HeapFree(GetProcessHeap(), 0, This->stream->cap_buffer);
HeapFree(GetProcessHeap(), 0, This->stream->local_buffer);
if(This->stream->local_buffer)
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->local_buffer,
&This->stream->local_buffer_size, MEM_RELEASE);
if(This->stream->tmp_buffer)
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer,
&This->stream->tmp_buffer_size, MEM_RELEASE); free(This->stream->wrap_buffer); HeapFree(GetProcessHeap(), 0, This->stream->resamp_buffer); CoTaskMemFree(This->stream->fmt);
@@ -1335,7 +1339,9 @@ static HRESULT WINAPI AudioClient_Initialize(IAudioClient3 *iface, return osstatus_to_hresult(sc); }
- This->stream->local_buffer = HeapAlloc(GetProcessHeap(), 0, This->stream->bufsize_frames * fmt->nBlockAlign);
This->stream->local_buffer_size = This->stream->bufsize_frames * fmt->nBlockAlign;
NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->local_buffer, 0,
&This->stream->local_buffer_size, MEM_COMMIT, PAGE_READWRITE);
silence_buffer(This, This->stream->local_buffer, This->stream->bufsize_frames);
if(This->dataflow == eCapture){
@@ -2292,9 +2298,12 @@ static HRESULT WINAPI AudioRenderClient_GetBuffer(IAudioRenderClient *iface,
if(This->stream->wri_offs_frames + frames > This->stream->bufsize_frames){ if(This->stream->tmp_buffer_frames < frames){
HeapFree(GetProcessHeap(), 0, This->stream->tmp_buffer);
This->stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, frames * This->stream->fmt->nBlockAlign);
if(!This->stream->tmp_buffer){
NtFreeVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer,
&This->stream->tmp_buffer_size, MEM_RELEASE);
This->stream->tmp_buffer_size = frames * This->stream->fmt->nBlockAlign;
if(NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, 0,
&This->stream->tmp_buffer_size, MEM_COMMIT, PAGE_READWRITE)){
This->stream->tmp_buffer_frames = 0; OSSpinLockUnlock(&This->stream->lock); return E_OUTOFMEMORY; }
@@ -2449,8 +2458,11 @@ static HRESULT WINAPI AudioCaptureClient_GetBuffer(IAudioCaptureClient *iface, chunk_frames = This->stream->bufsize_frames - This->stream->lcl_offs_frames; if(chunk_frames < This->stream->period_frames){ chunk_bytes = chunk_frames * This->stream->fmt->nBlockAlign;
if(!This->stream->tmp_buffer)
This->stream->tmp_buffer = HeapAlloc(GetProcessHeap(), 0, This->stream->period_frames * This->stream->fmt->nBlockAlign);
if(!This->stream->tmp_buffer){
This->stream->tmp_buffer_size = This->stream->period_frames * This->stream->fmt->nBlockAlign;
NtAllocateVirtualMemory(GetCurrentProcess(), (void **)&This->stream->tmp_buffer, 0,
&This->stream->tmp_buffer_size, MEM_COMMIT, PAGE_READWRITE);
} *data = This->stream->tmp_buffer; memcpy(*data, This->stream->local_buffer + This->stream->lcl_offs_frames * This->stream->fmt->nBlockAlign, chunk_bytes); memcpy((*data) + chunk_bytes, This->stream->local_buffer, This->stream->period_frames * This->stream->fmt->nBlockAlign - chunk_bytes);
diff --git a/dlls/winecoreaudio.drv/unixlib.h b/dlls/winecoreaudio.drv/unixlib.h index 6a991f1de98..1b773b7f820 100644 --- a/dlls/winecoreaudio.drv/unixlib.h +++ b/dlls/winecoreaudio.drv/unixlib.h @@ -29,7 +29,6 @@ struct coreaudio_stream /* To be made private */ AUDCLNT_SHAREMODE share;
BOOL playing;
- SIZE_T local_buffer_size, tmp_buffer_size; UINT32 period_ms, period_frames; UINT32 bufsize_frames, resamp_bufsize_frames; UINT32 lcl_offs_frames, held_frames, wri_offs_frames, tmp_buffer_frames;
@@ -39,6 +38,7 @@ struct coreaudio_stream /* To be made private */ INT32 getbuf_last; WAVEFORMATEX *fmt; BYTE *local_buffer, *cap_buffer, *wrap_buffer, *resamp_buffer, *tmp_buffer;
- SIZE_T local_buffer_size, tmp_buffer_size;
};
struct endpoint
2.23.0