-
Notifications
You must be signed in to change notification settings - Fork 320
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
pulseaudio: Rework some initialization code and have better error reporting #863
pulseaudio: Rework some initialization code and have better error reporting #863
Conversation
8e0568e
to
ff30689
Compare
ff30689
to
2f48888
Compare
Please review the documentation for |
Just gave this pull request a test and it doesn't work at all, at least on Ubuntu 20.04.6-LTS. Playback in callback mode just hangs, with the paCallback not ever getting called. Capture dies with "Assertion 's' failed at pulse/stream.c:335, function pa_stream_get_state(). Aborting." Backtrace in the capture abort:
It kind of looks as if the same problem as in PR #857 exists, but I don't have time to debug your new changes. See my proposal in that PR though for something that I think might solve that problem in a simple manner. Sorry for not bringing more pleasant feedback as a christmas present :/. I still hope that a Portaudio release with the pulseaudio backend could make it into the next big Ubuntu 24.04-LTS release. That would be splendid, but would require new portaudio packages to land in Debian unstable before February 29 2024, which is when Ubuntu stops importing packages from Debian. Have nice christmas and happy new year! |
@illuusio please integrate changes from the master to make CI work/succeed. |
9d65c17
to
5b9ce72
Compare
Thank you for fixing some not working stuff on master. I've updated to this PR to current HEAD. |
Thank you for testing. I've little bit reworked code and hopefully now it works. |
@kleinerm is it working for you now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the two changes I've suggested are accepted, and @kleinerm says it works (in either order) then I'm ready to approve this.
Apart from my review comments, the problem persists, with exactly the same symptoms as mentioned before: Hangs when trying to start playback, callback never called.
|
The additional needed fix on top of the suggestions i made is to change lines 681 - 682 in pa_linux_pulseaudio_cb.c
as follows:
The stream isActive and isStopped must start marked as active and not stopped at the beginning of that function. It must only be turned into a failure (ie. not isActive but isStopped) if an error happens, ie. as part of the Otherwise various checks that are called as part of the Pulseaudio processing thread will trigger and cause an abort of All this is a race condition between the Pulseaudio processing thread and the main Portaudio client thread where My description of the original problem can be found here #857 (comment). With all my proposed changes applied, it works again. |
@RossBencina and @kleinerm thank you for reviewing this. I'll update the suggestion as I have some time to what's them thru. They seem to all to good stuff.. |
Please fix the whitespace issues flagged by CI:
|
7dfd844
to
17c06dc
Compare
Yes I've noted that and didn't got time to fix. It had unfinished things anyway so was not so biggie anyway. I've little bit cleaned up things as I by myself could not remember why I added |
They are not necessarily the same thing, see: https://www.portaudio.com/docs/proposals/010-ClarifyStreamStateMachine.html |
93a89a9
to
96f1235
Compare
Ok, I retested and also reviewed your latest chances. The changes you made to starting are a variation of what I proposed and therefore should work. And indeed, my testing with Psychtoolbox-3 on my Ubuntu 20.04.6-LTS laptop now works again for all tests with half-duplex playback, capture, and full-duplex modes 👍. As far as I'm concerned, this would be ready for pulling "as is". I did leave one comment for a cosmetic code fix - removing a now redundant if-statement. I don't care if it is left or not. Wrt. the change in suggestedLatency handling, I'll leave this to @RossBencina and @philburk , as it doesn't affect my software in any way - I don't ever pass in negative or zero suggestedLatency values. But treating a zero suggestedLatency as DEFAULT_MIN_LATENCY is not strictly what the developers docs for Portaudio recommend - See https://github.com/PortAudio/portaudio/wiki/BufferingLatencyAndTimingImplementationGuidelines#user-model-latency-fields-and-parameters and the new issue #856 as a result of previous discussions we had here a few months ago. So I'm not sure if working around application bugs by mapping a requested latency of zero to 15 msecs is really the proper thing to do. But I personally don't care. It is a bit curious why in the old code, a suggestedLatency of zero which maps to a requested latency of 1 microsecond would cause the behaviour you observed though. pa_usec_to_bytes() will map that to 0 Bytes in tlength or fragsize, so maybe that is a value Pulseaudio doesn't like here, and it would make more sense to make sure that tlength and fragsize in PaPulseAudio_StartStreamCb() gets always clamped to be at least 1 Bytes or some other small reasonable value? Anyhow, I'm ok with this. |
Yes this one thing that I've though when implemented. It's not proper thing to do but as 0 latency works incorrect this lesser bad than un working audio but if there is some other advice it would help a lot.. |
Thanks for persevering with this host implementation. It sounds like you are close. Clipping zero requested latency to a minimum value is a good thing. |
Suggested latency handling is covered in #99 |
I don't think the zero suggested latency handling is correct but we plan to merge it next week anyhow since the main issue is resolved and the suggested latency handling can be addressed in a separate PR. |
Ok I'll revert my changes and let latency stuff be merged. Then I'll can figure this out if needed or fix this straight to pure data as latency they determine in |
Rework Pulseaudio stream starting and initialization code little bit more readable form. Make also sure that errors are detected and better handled.
pulseaudio: Make sure that using correct stream which is input Input initialization had incorrect stream (output). Commit changes for correct stream. Co-authored-by: kleinerm <[email protected]>
Portaudio last error should have some return value not just 0 which is now. Co-authored-by: Ross Bencina <[email protected]>
Add unclock to make sure mainloop is unclocked and does not get stuck Co-authored-by: kleinerm <[email protected]>
If not unlocked mainloop can be stuck. Commit adds unlock to make sure that does not happen Co-authored-by: kleinerm <[email protected]>
Now PaPulseAudio_CheckConnection return -1 when it waits something to happen (it's kind of no error nor there is something to wait) then there is PA_OK which is when connection is on wire. Then if it returns PA_ERR_ACCESS which is when ACCESS is denied.
Fix some commenting and add some comments that to make sure everyone get reasoning behind decisions
Make callbacks for record and callback start after everything been tested to work. Make some minor tunings to stopping also
d387136
to
38f098c
Compare
Make some changes that came up in review. These make sure that pulseaudio will start.
38f098c
to
366eeb9
Compare
As now it's working again I'm starting to hope this will be merged soon but let's see if there's something to fix still.. |
Retested on Ubuntu 20.04.6-LTS to be still fine. Fwiw, I looked at some pulseaudio server code, and lines like these ... Other code fragments, e.g., https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/master/src/pulsecore/memblockq.c?ref_type=heads#L852 in combination with https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/master/src/pulsecore/memblockq.c?ref_type=heads#L81 suggest that the lowest implementable value may be one audio frame size, ie. So what could be worth trying is making sure that This way 0 usecs or too small usecs would result in an assignment of at least pa_frame_size() bytes. |
Sounds good to me. Is there anything remaining for this PR before we merge it? Are we ok to merge this in 7 days? |
@RossBencina From my side and testing, merging is fine. |
Same to me. I'll address these latency problems in other PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me we've done enough hopefully we didn't miss anything.
Thank you everyone :) |
Rework Pulseaudio stream starting and initialization code little bit more readable form. Commit also reworks stream starting to work more reliable.
PR reworks also error reporting as it should be first class citizen if there is better stream handling and initialization.
This should overcome problems from PR #857