PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.45k stars 303 forks source link

Crash when connecting or disconnecting device #750

Open fredvs opened 1 year ago

fredvs commented 1 year ago

Describe the bug When a new sound card is plugged or a blue tooth mic is connected, it crash the application.

To Reproduce See bug description.

Expected behavior It should be "plug and play".

Actual behavior See bug description.

Desktop

Additional context OK, you will say it s not the problem of PortAudio but the OS. By chance, do you see a solution how to get a change in audio devices and so, have the opportunity to reinitialize PortAudio ?

Thanks.

Fre;D

RossBencina commented 1 year ago

If PortAudio is crashing in this situation then it is a bug. Please provide the following information:

For now your only option is to call Pa_Terminate(); Pa_Initialize(); to get an updated device list.

fredvs commented 1 year ago

Hello and many thanks for answering.

About the "crash" it comes for example it a song file is playing and using a default device (main soundcard) and if the user plug a bluetooth loudspeaker and assign this one as default.

For now your only option is to call Pa_Terminate(); Pa_Initialize(); to get an updated device list.

Yes, it is what I use at the moment ( but at init of play, once playing, there is a ""hotplug/callback-method" needed to notify that a change has be done).

There has been work on a "hotplug" enhancement that would give callbacks upon device connection/disconnection but it is incomplete.

Ho that would be great!

Many thanks and have perfect days and nights.

Fre;D

RossBencina commented 1 year ago

Separate from hotplug, we would like to fix the crashes. Could you please confirm:

PortAudio version: all

What is the most recent version that you have tried on each platform?

Host API: wasapi, alsa, pulseaudio.

Does it crash on all of these host APIs? Could you possible provide stack traces please?

Thank you.

fredvs commented 1 year ago

Hello.

I am maintainer of a audio library for the fpc Pascal compiler: https://github.com/fredvs/uos Last week a user complained about a crash when changing a soundcard: http://uos-forum.108.s1.nabble.com/Updates-devices-in-uos-GetInfoDevice-td984.html

anyway, the behavior when connecting and disconnecting devices of any orientation is inadequate. simplerecorder ( the demo in uos library ) launching the program, connecting the microphone, pressing the start button -> access violation similar with the simpleplayer, ( the demo in uos library ) launching the program, pressing the play button, turning off the headphones -> the program is frozen (no msg about err). even though there is still an output point, which automatically became the default.

But sadly I did not have at that moment a external usb sound card to test it.

So, today I did find a usb sound card to do the test and explain what is the problem and what OS is concerned.

Huh, here on Linux tests, no problem, if a song is playing there is indeed a short moment of silence when the new sound-card is assigned, but I did not get any crash. (or I did not get how the user did, it was on Windows and i dont have a Windows machine now.)

I apologize to have used the word "bug", it is not a bug but a "feature wanted" to have "hotplug".

Fre;D

RossBencina commented 1 year ago

Hi, with the user who is seeing crashes on Windows 10, do you know which host API they would have been using (WASAPI? WMME? ...) maybe it's whatever is the default in your build of PortAudio, do you know?

RossBencina commented 1 year ago

"hotplug" is being tracked by ticket #11, but we would like to keep this issue open to understand any crashes when a device is connected/disconnected, because that would be a bug.