Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
1acbd524
Commit
1acbd524
authored
Jan 26, 2021
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WASAPI: Fix a potential deadlock with exclusive + duplex mode.
parent
e3536a1c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
177 additions
and
189 deletions
+177
-189
miniaudio.h
miniaudio.h
+177
-189
No files found.
miniaudio.h
View file @
1acbd524
...
@@ -15254,13 +15254,6 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
...
@@ -15254,13 +15254,6 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
/* The process is to map the playback buffer and fill it as quickly as possible from input data. */
/* The process is to map the playback buffer and fill it as quickly as possible from input data. */
if (pMappedDeviceBufferPlayback == NULL) {
if (pMappedDeviceBufferPlayback == NULL) {
/* WASAPI is weird with exclusive mode. You need to wait on the event _before_ querying the available frames. */
if (pDevice->playback.shareMode == ma_share_mode_exclusive) {
if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
return MA_ERROR; /* Wait failed. */
}
}
result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback);
result = ma_device__get_available_frames__wasapi(pDevice, (ma_IAudioClient*)pDevice->wasapi.pAudioClientPlayback, &framesAvailablePlayback);
if (result != MA_SUCCESS) {
if (result != MA_SUCCESS) {
return result;
return result;
...
@@ -15276,18 +15269,6 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
...
@@ -15276,18 +15269,6 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
}
}
}
}
/* If there's no frames available in the playback device we need to wait for more. */
if (framesAvailablePlayback == 0) {
/* In exclusive mode we waited at the top. */
if (pDevice->playback.shareMode != ma_share_mode_exclusive) {
if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
return MA_ERROR; /* Wait failed. */
}
}
continue;
}
/* We're ready to map the playback device's buffer. We don't release this until it's been entirely filled. */
/* We're ready to map the playback device's buffer. We don't release this until it's been entirely filled. */
hr = ma_IAudioRenderClient_GetBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedDeviceBufferPlayback);
hr = ma_IAudioRenderClient_GetBuffer((ma_IAudioRenderClient*)pDevice->wasapi.pRenderClient, framesAvailablePlayback, &pMappedDeviceBufferPlayback);
if (FAILED(hr)) {
if (FAILED(hr)) {
...
@@ -15300,6 +15281,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
...
@@ -15300,6 +15281,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
mappedDeviceBufferFramesRemainingPlayback = framesAvailablePlayback;
mappedDeviceBufferFramesRemainingPlayback = framesAvailablePlayback;
}
}
if (mappedDeviceBufferFramesRemainingPlayback > 0) {
/* At this point we should have a buffer available for output. We need to keep writing input samples to it. */
/* At this point we should have a buffer available for output. We need to keep writing input samples to it. */
for (;;) {
for (;;) {
/* Try grabbing some captured data if we haven't already got a mapped buffer. */
/* Try grabbing some captured data if we haven't already got a mapped buffer. */
...
@@ -15517,6 +15499,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
...
@@ -15517,6 +15499,7 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
break;
break;
}
}
}
}
}
/* If at this point we've run out of data we need to release the buffer. */
/* If at this point we've run out of data we need to release the buffer. */
...
@@ -15554,6 +15537,11 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
...
@@ -15554,6 +15537,11 @@ static ma_result ma_device_audio_thread__wasapi(ma_device* pDevice)
c89atomic_exchange_8(&pDevice->wasapi.isStartedPlayback, MA_TRUE);
c89atomic_exchange_8(&pDevice->wasapi.isStartedPlayback, MA_TRUE);
}
}
}
}
/* Make sure the device has started before waiting. */
if (WaitForSingleObject(pDevice->wasapi.hEventPlayback, MA_WASAPI_WAIT_TIMEOUT_MILLISECONDS) != WAIT_OBJECT_0) {
return MA_ERROR; /* Wait failed. */
}
} break;
} break;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment