Discussion:
[Portaudio] Patch to rescan audio device while launched
Yann Biancheri
2007-01-09 09:56:02 UTC
Permalink
Hello,

I have worked in adding audio device detection in IAXClient while the
application is launched, and I end up adding this feature in PortAudio.
Looking at your track entries it seems that it corresponds to ticket#11
(http://www.portaudio.com/trac/ticket/11).
My implementation is quite basic and offers the opportunity to rescan
audio devices by an API call.
There is no callback if a device is inserted or removed, but the new
audio device information could be accessed through standard API calls.
I've done only two hostApi's implementation so far, one for CoreAudio on
mac and one for Wmme on windows which are the only ones I need in my
appication. It's certainly not the best way to handle those problems but
it is by far (in my opinion) the simpler way to do it.
Please found the patch here
http://yannbiancheri.free.fr/rescanDevicePortAudio.patch.

Sincerly,
Yann Biancheri
Bjorn Roche
2007-01-10 20:20:01 UTC
Permalink
Post by Yann Biancheri
Hello,
I have worked in adding audio device detection in IAXClient while
the application is launched, and I end up adding this feature in
PortAudio. Looking at your track entries it seems that it
corresponds to ticket#11 (http://www.portaudio.com/trac/ticket/11).
My implementation is quite basic and offers the opportunity to
rescan audio devices by an API call.
There is no callback if a device is inserted or removed, but the
new audio device information could be accessed through standard API
calls. I've done only two hostApi's implementation so far, one for
CoreAudio on mac and one for Wmme on windows which are the only
ones I need in my appication. It's certainly not the best way to
handle those problems but it is by far (in my opinion) the simpler
way to do it.
Please found the patch here http://yannbiancheri.free.fr/
rescanDevicePortAudio.patch.
Yann,

thank you for the patch. I'd like to see this integrated into
PortAudio, but, at the same time, I think it would be unwise to
introduce an API change. One possibility might be to make calls like
this platform specific. Are there any other thoughts on if/how/when
we could introduce this change?

bjorn

-----------------------------
Bjorn Roche
XO Wave
Digital Audio Production and Post-Production Software
http://www.xowave.com
http://blog.bjornroche.com
http://myspace.com/xowave
bapartridge
2007-01-11 04:28:01 UTC
Permalink
Post by Bjorn Roche
Post by Yann Biancheri
Hello,
I have worked in adding audio device detection in IAXClient while
the application is launched, and I end up adding this feature in
PortAudio. Looking at your track entries it seems that it
corresponds to ticket#11 (http://www.portaudio.com/trac/ticket/11).
My implementation is quite basic and offers the opportunity to
rescan audio devices by an API call.
There is no callback if a device is inserted or removed, but the
new audio device information could be accessed through standard
API calls. I've done only two hostApi's implementation so far, one
for CoreAudio on mac and one for Wmme on windows which are the
only ones I need in my appication. It's certainly not the best way
to handle those problems but it is by far (in my opinion) the
simpler way to do it.
Please found the patch here http://yannbiancheri.free.fr/
rescanDevicePortAudio.patch.
Yann,
thank you for the patch. I'd like to see this integrated into
PortAudio, but, at the same time, I think it would be unwise to
introduce an API change. One possibility might be to make calls
like this platform specific. Are there any other thoughts on if/how/
when we could introduce this change?
bjorn
The patch is great, but it could be problematic if an application
expects that, between calls to Initialize and Terminate, the list of
devices will not change. It would be better, in my opinion, to break
up the function into two different functions. One would just query
whether the device list is still valid (i.e. no devices removed), and
the other would actually modify the device list to reflect the
changes (as your code does). That way, the client could choose to
exit gracefully if a device has been removed, instead of following an
all-or-nothing approach that could potentially make every single
previously cached PaDeviceIndex invalid without ANY warning (or even
a valid error code). This is a great starting point to implement the
two functions, though, and I hope that the community can come to an
agreement that at least the query function be added to the API.

Sincerely,
B. P.
Yann Biancheri
2007-01-11 14:08:02 UTC
Permalink
Post by bapartridge
The patch is great, but it could be problematic if an application
expects that, between calls to Initialize and Terminate, the list of
devices will not change.
If he doesn't expect the list of device to change then he will just not
call the RescanDevice method. Device won't be automatically
added/removed then.
Post by bapartridge
It would be better, in my opinion, to break up the function into two
different functions. One would just query whether the device list is
still valid (i.e. no devices removed), and the other would actually
modify the device list to reflect the changes (as your code does).
That way, the client could choose to exit gracefully if a device has
been removed, instead of following an all-or-nothing approach that
could potentially make every single previously cached PaDeviceIndex
invalid without ANY warning (or even a valid error code). This is a
great starting point to implement the two functions, though, and I
hope that the community can come to an agreement that at least the
query function be added to the API.
If the user doesn't expect the list to change then he won't make the
call. But it's true that it'll be nice if the rescan device inform the
user if new devices has been detected. This could be done simply in the
return value.
Device Index seems to be an issue. The rescan function can try to ensure
that device index doesn't change through a rescan.


Sincerly,
-Yann
Reed Hedges
2007-01-11 23:36:01 UTC
Permalink
I wouldn't mind if it only added devices, and invalidated old devices but never
reassigned their IDs to any new devices, until Pa_Terminate(). It would be
great for PA to do this mostly automatically, but I guess you still need a way
to notify the client program if a device was removed so it can stop trying to
use it.

Reed
Ross Bencina
2007-01-11 13:12:02 UTC
Permalink
Hi Yann

I Could be missing something here. But why can't you just call
Pa_Terminate(); Pa_Initialize(); to refresh the device list? That's what I
do. What does the patch do beyond that? What are the benefits?

On a slightly separate topic: I think a more important patch would be to fix
problems where PortAudio gets out of sync with the host API when devices are
connected/disconnected. Ideally it should be able to resolve portAudio
devices even if the underlying device indexes have changed...

Best wishes

Ross.




----- Original Message -----
From: "Yann Biancheri" <***@horizonwimba.com>
To: <***@music.columbia.edu>
Sent: Tuesday, January 09, 2007 7:55 PM
Subject: [Portaudio] Patch to rescan audio device while launched
Post by Yann Biancheri
Hello,
I have worked in adding audio device detection in IAXClient while the
application is launched, and I end up adding this feature in PortAudio.
Looking at your track entries it seems that it corresponds to ticket#11
(http://www.portaudio.com/trac/ticket/11).
My implementation is quite basic and offers the opportunity to rescan
audio devices by an API call.
There is no callback if a device is inserted or removed, but the new audio
device information could be accessed through standard API calls. I've done
only two hostApi's implementation so far, one for CoreAudio on mac and one
for Wmme on windows which are the only ones I need in my appication. It's
certainly not the best way to handle those problems but it is by far (in
my opinion) the simpler way to do it.
Please found the patch here
http://yannbiancheri.free.fr/rescanDevicePortAudio.patch.
Sincerly,
Yann Biancheri
_______________________________________________
Portaudio mailing list
http://music.columbia.edu/mailman/listinfo/portaudio
Yann Biancheri
2007-01-11 13:58:01 UTC
Permalink
This post might be inappropriate. Click to display it.
Yann Biancheri
2007-02-22 09:44:02 UTC
Permalink
Hello,

I know it's been a while since I've originally sent this patch to this
list, but I have finally been able to found time and a USB headset to
test the Pa_Terminate(); Pa_Initialize(); method to rescan audio
devices. And when plugging, unplugging the headset while using audio it
causes my application to crash. So I'll keep my current implementation
for now. Do you plan integrating this feature to portaudio?

-Yann
Post by Yann Biancheri
Hello,
I've tried the solution of calling Pa_Terminate(); Pa_Initialize();
before starting implementation and it was causing my application to crash.
I beleive that one benefit of my solution is that it can detect
audio devices while having some opened streams. In fact, it is just
rescanning audio devices and not going all the way through
destrotying, reconsrtucting the hostApis. In case no device are
detected (which is really likely) nothing is destroyed or rebuilt and
make my solution lighter since I'm calling this method every 10
seconds. I use PortAudio in a VoIP application and I'm able to detect
newly inserted device and auto-select them while on the phone.
Do you beleive your hack can handle this use-case? If yes, then this
patch just make the process lighter.
I've tried replacing my Pa_RescanDevice() implementation by
Pa_Terminate(); Pa_Initialize(); and it doesn't crash my app while on
the phone. It has one nice side effect of cutting the echo each time I
do a rescan. Therefore, I didn't have any USB headset right now to
test if the detection of a newly inserted device will crash the
system. I'll test with an USB headset as soon as I can get one and
will post the result in the mailing list.
At least it will be helpful to create an API call, or document
somewhere how we can rescandevice if this method is retained.
-Yann
Post by Ross Bencina
Hi Yann
I Could be missing something here. But why can't you just call
Pa_Terminate(); Pa_Initialize(); to refresh the device list? That's
what I do. What does the patch do beyond that? What are the benefits?
On a slightly separate topic: I think a more important patch would be
to fix problems where PortAudio gets out of sync with the host API
when devices are connected/disconnected. Ideally it should be able to
resolve portAudio devices even if the underlying device indexes have
changed...
Best wishes
Ross.
----- Original Message ----- From: "Yann Biancheri"
Sent: Tuesday, January 09, 2007 7:55 PM
Subject: [Portaudio] Patch to rescan audio device while launched
Post by Yann Biancheri
Hello,
I have worked in adding audio device detection in IAXClient while
the application is launched, and I end up adding this feature in
PortAudio. Looking at your track entries it seems that it
corresponds to ticket#11 (http://www.portaudio.com/trac/ticket/11).
My implementation is quite basic and offers the opportunity to
rescan audio devices by an API call.
There is no callback if a device is inserted or removed, but the new
audio device information could be accessed through standard API
calls. I've done only two hostApi's implementation so far, one for
CoreAudio on mac and one for Wmme on windows which are the only ones
I need in my appication. It's certainly not the best way to handle
those problems but it is by far (in my opinion) the simpler way to
do it.
Please found the patch here
http://yannbiancheri.free.fr/rescanDevicePortAudio.patch.
Sincerly,
Yann Biancheri
_______________________________________________
Portaudio mailing list
http://music.columbia.edu/mailman/listinfo/portaudio
_______________________________________________
Portaudio mailing list
http://music.columbia.edu/mailman/listinfo/portaudio
Ross Bencina
2007-02-22 14:06:01 UTC
Permalink
Hi Yann

I'm a bit unsure about the crash you describe, and how your patch fixes it.
I am guessing that whatever prevents the crash is separate from the device
load/restore functionality. What do you think?

Overall, although I agree that the functionality is desirable, I am
reluctant to introduce such a significant API change at the moment since it
obviously impacts all implementations and significantly increases
implementation complexity... what do others think?

Ross.



----- Original Message -----
From: "Yann Biancheri" <***@horizonwimba.com>
To: "Yann Biancheri" <***@horizonwimba.com>
Cc: "Ross Bencina" <rossb-***@audiomulch.com>; <***@music.columbia.edu>
Sent: Thursday, February 22, 2007 7:42 PM
Subject: Re: [Portaudio] Patch to rescan audio device while launched
Post by Yann Biancheri
Hello,
I know it's been a while since I've originally sent this patch to this
list, but I have finally been able to found time and a USB headset to test
the Pa_Terminate(); Pa_Initialize(); method to rescan audio devices. And
when plugging, unplugging the headset while using audio it causes my
application to crash. So I'll keep my current implementation for now. Do
you plan integrating this feature to portaudio?
-Yann
Post by Yann Biancheri
Hello,
I've tried the solution of calling Pa_Terminate(); Pa_Initialize();
before starting implementation and it was causing my application to crash.
I beleive that one benefit of my solution is that it can detect audio
devices while having some opened streams. In fact, it is just rescanning
audio devices and not going all the way through destrotying,
reconsrtucting the hostApis. In case no device are detected (which is
really likely) nothing is destroyed or rebuilt and make my solution
lighter since I'm calling this method every 10 seconds. I use PortAudio
in a VoIP application and I'm able to detect newly inserted device and
auto-select them while on the phone.
Do you beleive your hack can handle this use-case? If yes, then this
patch just make the process lighter.
I've tried replacing my Pa_RescanDevice() implementation by
Pa_Terminate(); Pa_Initialize(); and it doesn't crash my app while on the
phone. It has one nice side effect of cutting the echo each time I do a
rescan. Therefore, I didn't have any USB headset right now to test if the
detection of a newly inserted device will crash the system. I'll test
with an USB headset as soon as I can get one and will post the result in
the mailing list.
At least it will be helpful to create an API call, or document
somewhere how we can rescandevice if this method is retained.
-Yann
Post by Ross Bencina
Hi Yann
I Could be missing something here. But why can't you just call
Pa_Terminate(); Pa_Initialize(); to refresh the device list? That's what
I do. What does the patch do beyond that? What are the benefits?
On a slightly separate topic: I think a more important patch would be to
fix problems where PortAudio gets out of sync with the host API when
devices are connected/disconnected. Ideally it should be able to resolve
portAudio devices even if the underlying device indexes have changed...
Best wishes
Ross.
----- Original Message ----- From: "Yann Biancheri"
Sent: Tuesday, January 09, 2007 7:55 PM
Subject: [Portaudio] Patch to rescan audio device while launched
Post by Yann Biancheri
Hello,
I have worked in adding audio device detection in IAXClient while the
application is launched, and I end up adding this feature in PortAudio.
Looking at your track entries it seems that it corresponds to ticket#11
(http://www.portaudio.com/trac/ticket/11).
My implementation is quite basic and offers the opportunity to rescan
audio devices by an API call.
There is no callback if a device is inserted or removed, but the new
audio device information could be accessed through standard API calls.
I've done only two hostApi's implementation so far, one for CoreAudio
on mac and one for Wmme on windows which are the only ones I need in my
appication. It's certainly not the best way to handle those problems
but it is by far (in my opinion) the simpler way to do it.
Please found the patch here
http://yannbiancheri.free.fr/rescanDevicePortAudio.patch.
Sincerly,
Yann Biancheri
_______________________________________________
Portaudio mailing list
http://music.columbia.edu/mailman/listinfo/portaudio
_______________________________________________
Portaudio mailing list
http://music.columbia.edu/mailman/listinfo/portaudio
Bjorn Roche
2007-02-22 19:17:34 UTC
Permalink
Post by Ross Bencina
Hi Yann
I'm a bit unsure about the crash you describe, and how your patch
fixes it. I am guessing that whatever prevents the crash is
separate from the device load/restore functionality. What do you
think?
Overall, although I agree that the functionality is desirable, I am
reluctant to introduce such a significant API change at the moment
since it obviously impacts all implementations and significantly
increases implementation complexity... what do others think?
It's certainly a feature I'd like to see. When and how is, of course,
another matter. If the host provides a callback for notifications of
changes, and there was a good infrastructure for this in PortAudio, I
think it would be relatively easy to implement on any given platform,
but, I'm not sure what such an infrastructure would look like.

bjorn

-----------------------------
Bjorn Roche
XO Wave
Digital Audio Production and Post-Production Software
http://www.xowave.com
http://blog.bjornroche.com
http://myspace.com/xowave
Yann Biancheri
2007-02-27 15:36:52 UTC
Permalink
This post might be inappropriate. Click to display it.
Ross Bencina
2007-02-28 06:35:42 UTC
Permalink
Hi Yann
In addition calling terminate and initiliaze seems strange to me since I
don't want to stop audio while on the phone, I just want to automatically
select/unselect the inserted/removed device.
Ok, that makes sense. It's not a use-case I encounter, since I usually plug
my hardware in before I start performing, but I can see the benefit.
From the implementation point of view it's not too hard to rescan device.
It's basically the same thing as on initialisation. And if a developper
doesn't want to implement this method you can just leave it empty and just
not support this feature. It's a nice to have but definitively not a MUST
have.
I can imagine that there will be problems with some APIs where you can't
really rescan/reinitialise while a device is running (so that needs to be
avoided). And as I've said before, the infrastructure also needs to be
improved so that plugging a new device doesn't render the old device lists
invalid until Pa_RescanDevices() (or whatever) is called, plus there needs
to be a callback to notify when devices have changed (if possible).

I'd like to just have a callback which says "something's changed, PortAudio
is going to crash if you don't rescan" but I'm not sure we can make that
work for all APIs...

I think we should develop this into a new enhancement proposal and once
we're happy with what "it" is, then we can work out when it will be
implemented.

Thoughts?

Ross.

Loading...