mozilla / cubeb

Cross platform audio library
ISC License
443 stars 127 forks source link

Jack backend needs work - remove mutexes #608

Open zamaudio opened 4 years ago

zamaudio commented 4 years ago

The current jack backend code is broken because it has trylocks in the realtime thread. This PR (#391) was an attempt to fix it, but as @szanni describes, it uses booleans in place of a mutex instead of a lockless ring buffer mechanism. I urge anyone who knows how to fix this to do so. I have not written code like this before and I also don't have time to spend on it further. PR #607 should fix the sporadic crashing thanks to @szanni, but the backend may still play periods of silence on underperformant machines when the mutex path is locked.

richard-uk1 commented 4 years ago

I see a lock-free ringbuffer as part of the source code for cubeb, why not just use that?

tanertas commented 4 years ago

When Jackd restarts or usb sound card disconnects, Firefox can't use Jack anymore. I have to quit Firefox. I switched Jack backend recently but this issue a bit frustrating.

Instead of opening new issue, I thought it is better to comment here.

zamaudio commented 4 years ago

@tanertas you're not supposed to kill jackd server while clients are connected, what do you expect will happen?

tanertas commented 4 years ago

When USB dac disconnects for some reason, I have to restart Jackd. Firefox can't reclaim the Jackd connection without restart. For example, MPD can reconnect new Jackd instance without a restart.

I don't expect Firefox able to connect for a non existent Jackd instance but I think I have a valid reason to expect it to reclaim a new connection.

zamaudio commented 4 years ago

@tanertas my usb sound card has been attached for many days without reconnect and jackd has been also running without any xruns for that long. If yours is disconnecting, I suggest you try to resolve that problem first.

tanertas commented 4 years ago

Thank you for that brilliant suggestion. So, what about reclaiming for new Jackd instance? Firefox audio backed shouldn't have a polling mechanism for Jack? If you think that current situation is optimal.. then I'm asking wrong person.

zamaudio commented 4 years ago

@tanertas I believe this problem is not related specifically to the jack backend for firefox, it probably applies to all backends when the sound driver/device simply disappears, it's just that the other sound servers don't suddenly cease to exist. Maybe you could ask jack developers to make it continue running as a dummy device when the carpet is pulled out from under jack instead of crashing jack?

tanertas commented 4 years ago

I guess you are not willing to spend enough effort to understand the real situation. This is entirely out of scope of how Jack deals with the underlying hardware. It is about how Firefox audio backend deals with a particular Jackd session. For any reason I may restart a Jackd session.. You can't argue with that. I mean you just can't say that "Why you are restarting Jack?" or " Just don't restart Jackd!".

Firefox's audio backend's job is to poll current Jackd session and try to reclaim it if it stopped or restarted for some reason. It is not backend developer's job to discuss about the reason of the stop/restart. This is a highly valid condition and you may have prepared for that.

MPD's audio backend always reclaims stopped or restarted Jackd session.. so I guess there's no any underlying technical reason to defend current situation of Firefox for can't doing same thing.