pjproject icon indicating copy to clipboard operation
pjproject copied to clipboard

improved status checking in audiodev.c

Open jurica opened this issue 3 years ago • 3 comments

I wanted to contribute this improvement to audiodev.c. The problem here was that, if devices where removed pjmedia caused crashes in the application. Debug builds triggered the removed assertion and release builds caused crashes later on as device id's of devices that where removed where referenced.

As I'm quite unfamiliar with pjprojects codebase itself so I'm not sure if my changes can be adopted without changes, but I hope at least you can implement some improvements here based on my suggestion. At least for our application we use that patch for a few weeks already and are not experiencing any issues with it, but it successfully prevents the crashes we experienced.

As far as I have seen videodev.c implements the same pattern and most likely causes the same issues, but I can't tell for sure as I haven't tested that part.

jurica avatar May 31 '22 07:05 jurica

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 31 '22 07:05 CLAassistant

Can you explain what the scenario is here? Is there a race between the device removal and application trying to access the device?

In case that you don't know, we have a FAQ here that touches a similar subject: https://trac.pjsip.org/repos/wiki/FAQ#snd-hot-plug although there it discusses about the addition of a new device, instead of a removal, but the concept is the same.

sauwming avatar Jun 06 '22 10:06 sauwming

Hi @sauwming, I wasn't aware of that FAQ you linked, but that's pretty much what we do. We listen to OS'es device change events and then refresh PJMEDIA devices, but without calling pjsua_set_no_snd_dev() before. This then caused in a special setup reproducible crashes. As the FAQ states, I guess calling pjsua_set_no_snd_dev() before the refresh would prevent the issue. When debugging this issue I didn't think of that, so I looked for the cause and worked out the change I submitted. I will try calling pjsua_set_no_snd_dev()before refreshing the devices, but it might take some time until I can provide feedback wether it works or not.

jurica avatar Jun 07 '22 07:06 jurica

Closing due to no further update. Please reopen/recreate whenever you have managed to test it.

sauwming avatar Jan 21 '23 07:01 sauwming