Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio: Pipewire cleanups and fixes #4250

Closed
wants to merge 4 commits into from

Conversation

Kontrabant
Copy link
Contributor

@Kontrabant Kontrabant commented Mar 28, 2021

A few Pipewire fixes and cleanups, including a fix for a race condition.

Since Pipewire starts it's own processing threads, we can wind up in the processing callbacks before all of the members of SDL_AudioDevice (callbackspec, work_buffer and stream) are actually allocated/initialized, as they aren't initialized until after the call to the driver's OpenDevice() function returns. We don't want to touch any of these until the device state is set to unpaused, which can only happen once initialization is fully complete.

Other than that, some redundant locks were removed and stream creation now blocks instead of spinning until the stream state is ready or failed, as creating streams can sometimes take quite a bit of time and busy waiting for many milliseconds isn't ideal.

Add a function to erase the first len bytes of the data queue.
Some of the SDL_AudioDevice struct members aren't initialized until after returning from the OpenDevice function.  Since Pipewire uses it's own processing threads, the callbacks can be entered before members such as work_buffer, callbackspec and the processing stream are initialized, which creates a race condition.  Don't use these members when in the paused state to avoid potentially using uninitialized values and memory.
The pw_thread_loop already locks and unlocks the thread mutex at the start and end of each loop iteration, so these locks are unnecessary.
Initializing streams, particularly capture streams, can take many milliseconds, which is a bit much for a busy wait.  Use a blocking wait instead.
@Kontrabant Kontrabant closed this Mar 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant