brave / brave-browser

Brave browser for Android, iOS, Linux, macOS, Windows.
https://brave.com
Mozilla Public License 2.0
17.91k stars 2.34k forks source link

reconnect microphone on pulseaudio crash #13030

Open marc1uk opened 3 years ago

marc1uk commented 3 years ago

Description

Very often when I try to connect to conference calls brave is unable to find any microphones on my device. On initial startup (at least, for now...) it's detecting everything ok, but nearly always by the time a meeting comes around all websites report no audio devices found (https://test.webrtc.org/, https://www.onlinemictest.com/, MS teams, google hangouts, discord, slack... ). My best guess (i'd appreciate some suggestions on debugging) is that pulseaudio is crashing, and brave is failing to reconnect afterwards - I get the same behaviour after issuing pulseaudio -k, which kills and restarts the pulseaudio deamon.

The issue here is that as far as i'm aware there ought to be automatic reconnection once the service is restarted - indeed, playback of audio works just fine, it's only recording audio that doesn't.

Steps to Reproduce

Potentially a bit artificial (as i'm speculating on the cause) but run brave, do pulseaudio -k, and then check audio detection on https://test.webrtc.org/ or any of the others listed above.

Actual result:

No audio devices found.

Expected result:

Audio devices are re-detected as necessary.

Reproduces how often:

Always.

Brave version (info found on brave://version)

Brave | 1.16.76 Chromium: 86.0.4240.198 (Official Build) (64-bit)
-- | --
Revision | d8a506935fc2273cfbac5e5b629d74917d9119c7-refs/branch-heads/4240@{#1431}
OS | Linux

Version/Channel Information:

Seen this on all brave versions as long as I can remember....

Other Additional Information:

Other

This definitely seems possible, as within firefox I'm able to kill and re-connect microphone usage.... albeit in a very bizarre way. Initially after killing pulseaudio onlinemictest.com shows the same error: unable to find microphone. But re-freshing https://test.webrtc.org/ seems to force a re-detection of audio input devices. After doing this, onlinemictest.com works again (as do all other sites using audio devices). This workaround works in firefox, but not brave. Bizarre, possibly not useful information, but it shows it can be done.

guest271314 commented 3 years ago

Are you certain microphones are connected to the machine?

indeed, playback of audio works just fine, it's only recording audio that doesn't.

Are you trying to record the default microphone input,or do you attempt to select a different device to record?

marc1uk commented 3 years ago

Hi. Yep, there are definitely microphones connected - internal microphones on a laptop, aux-in microphone on laptop and desktop, and a usb microphone on a desktop, none show up. All are working fine outside the browser. I'm trying to record any microphone. There are no devices to select from. No microphones even show up in the brave settings menu.

Working: working Now working: not_working

Both of these are taken on the same machine, one before, one after pulseaudio crash.

marc1uk commented 3 years ago

When i run brave from the terminal and kill pulseaudio, thereafter attemps to access my audio devices emit errors along the lines of pa_operation is nullptr.

guest271314 commented 3 years ago

I will try to install Brave to reproduce the issue. On Chromium or Chrome the closest that I have experienced to that issue is trying to capture a monitor device, which throws a DOMException error, see https://bugs.chromium.org/p/chromium/issues/detail?id=1155954.

What does .catch(e => console.error(e)) log chained to navigator.mediaDevices.getUserMedia({audio: true})?

Try something like this

navigator.mediaDevices.getUserMedia({audio: true})
.then(stream => {
  return stream
})
.catch(e => {
  console.error(e);
  return navigator.mediaDevices.enumerateDevices();
})
.then(stream_or_devices => {
  console.log(stream_or_devices);
});

what is logged at console?

guest271314 commented 3 years ago

@marc1uk Re

what is logged at console?

printing the devices and labels here is not necessary. I do not need to know your device specifics. If devices are the fulfilled Promise are the devices of kind "audioinput" and are the objects InputDeviceInfo or MediaDeviceInfo.

guest271314 commented 3 years ago

Cannot reproduce at 1.17.75 Chromium: 87.0.4280.88 (Official Build) (64-bit) Revision | 89e2380a3e36c3464b5dd1302349b1382549290d-refs/branch-heads/4280@{#1761}.

When i run brave from the terminal

Are you trying to access the same microphone and camera at two separate instances of Brave?

marc1uk commented 3 years ago

No, just one instance of Brave. I'm afraid I'm not familiar with development / debugging of chrome or brave, so i'd need some more explicit instructions to try to check the kind of objects fulfilling the promise. If i'm reading it right, this is now moot, but would the code in your previous comment have been pasted into the Developer Tools -> Console? On the specific website when audio devices are not found? Thanks for looking into this.

guest271314 commented 3 years ago

but would the code in your previous comment have been pasted into the Developer Tools -> Console?

Yes.

marc1uk commented 3 years ago

When audio devices are working i get:

Promise {<pending>}
__proto__: Promise
catch: ƒ catch()
constructor: ƒ Promise()
finally: ƒ finally()
then: ƒ then()
Symbol(Symbol.toStringTag): "Promise"
__proto__: Object
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: undefined

MediaStream {id: "LsaVMEbH49dRkJV1XXXwKlhEOuBPXHwMC7mB", active: true, onaddtrack: null, onremovetrack: null, onactive: null, …}
active: true
id: "LsaVMEbH49dRkJV1XXXwKlhEOuBPXHwMC7mB"
onactive: null
onaddtrack: null
oninactive: null
onremovetrack: null
__proto__: MediaStream

but after pulseaudio crash i get:

Promise {<pending>}__proto__: Promise[[PromiseState]]: "fulfilled"[[PromiseResult]]: undefined
VM556:6 DOMException: Requested device not found
(anonymous) @ VM556:6
Promise.catch (async)
(anonymous) @ VM556:5
VM556:10 []

seems like an endless option to expand members here so let me know if there's something specific to look for

guest271314 commented 3 years ago

I do not why pulseaudio is crashing. Are you sure to call MediaStreamTrack.stop() before trying to access microphone again? Does pavucontrol list the microphone?

marc1uk commented 3 years ago

I believe pulseaudio is crashing for other reasons (related to LADSPA plugins, although in this case I'm manually "replicating" it by running pulseaudio -k). I understand this may be a bit of a false issue as the underlying problem is elsewhere (pulseaudio shouldn't crash), but pulseaudio immediately restarts on crash and other applications seem able to recover afterwards, whereas brave does not.

paco3346 commented 3 years ago

I experience a very similar issue. I'm running pipewire with pipewire-pulse on Arch and I too have times where Brave will no longer properly use input devices but playback works perfectly. This happens any time pulse goes away (in my case, pipewire-pulse).

This happens on all of the following which leads me to believe it's an upstream issue.

Brave: 1.23.73 Chromium: 90.0.4430.85 (Official Build) (64-bit) Chrome: 90.0.4430.85 (Official Build) (64-bit) Chromium: 90.0.4430.85 (Official Build) Arch Linux (64-bit)

I also get the same ERROR:pulse_util.cc(343)] pa_operation is nullptr. message in all 3 browsers.

For all 3 the only fix is to restart the browser.

paco3346 commented 3 years ago

A bit more googling and I have an answer:

This is a known issue with chromium (and chromium based browsers).

https://bugs.chromium.org/p/chromium/issues/detail?id=1085744#c3

The only current workaround without restarting is to restart the browser audio service.

Press Shift + Esc. In the Task Manager window that opens find Utility: Audio Service (it's usually the very bottom for me) and click End Process. Refresh your page and voila.

I think this can be closed as an upstream issue.

marc1uk commented 3 years ago

Interesting! Thanks for posting the workaround, that's far preferable to a complete restart.