All of lore.kernel.org
 help / color / mirror / Atom feed
* USB disconnect/connect messages
@ 2003-07-20 23:40 James Courtier-Dutton
  2003-07-21 15:25 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: James Courtier-Dutton @ 2003-07-20 23:40 UTC (permalink / raw)
  To: alsa-devel

Hi,

Is there any way to tell if a USB sound card has been disconnected or not?

I would like my application to play sound to a usb sound card, and if 
the usb cable is unplugged, the application pauses, and if the usb cable 
is plugged in again, the application continues.

Example: -
Some in car stereo systems have usb ports.
I could plug a PC into the usb port, and play sound from the PC to the 
car speaker system. If the driver switches off the car stereo (e.g. 
Receives a mobile phone call) I want the PC to pause playback, but when 
the car stereo switches on again, I want the PC to continue playback.
The car stereo switching off looks to the PC as though the usb cable has 
been unplugged.

Cheers
James



-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: USB disconnect/connect messages
  2003-07-20 23:40 USB disconnect/connect messages James Courtier-Dutton
@ 2003-07-21 15:25 ` Takashi Iwai
  2003-07-21 18:03   ` James Courtier-Dutton
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2003-07-21 15:25 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel

At Mon, 21 Jul 2003 00:40:32 +0100,
James Courtier-Dutton wrote:
> 
> Hi,
> 
> Is there any way to tell if a USB sound card has been disconnected or not?
 
IIRC, this is not notified to the application.
the app simply would get an error at the further access.
it sounds not bad to notify the status change to the application by
some way.
perhaps we can add a new control element for this purpose.
and after disconnection, only this element survives to communicate
with the application...


> I would like my application to play sound to a usb sound card, and if 
> the usb cable is unplugged, the application pauses, and if the usb cable 
> is plugged in again, the application continues.
> 
> Example: -
> Some in car stereo systems have usb ports.
> I could plug a PC into the usb port, and play sound from the PC to the 
> car speaker system. If the driver switches off the car stereo (e.g. 
> Receives a mobile phone call) I want the PC to pause playback, but when 
> the car stereo switches on again, I want the PC to continue playback.
> The car stereo switching off looks to the PC as though the usb cable has 
> been unplugged.

from the driver side, i see it's difficult to "resume" from the
disconnection to the disconnection state.  you won't get the same
usb_device record after re-plugging.
of course, it would be possible to handle this in the application side
(or possibly in alsa-lib) "as if" it's reconnected, though.


Takashi


-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: USB disconnect/connect messages
  2003-07-21 15:25 ` Takashi Iwai
@ 2003-07-21 18:03   ` James Courtier-Dutton
  2003-07-21 18:23     ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: James Courtier-Dutton @ 2003-07-21 18:03 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

Takashi Iwai wrote:
> At Mon, 21 Jul 2003 00:40:32 +0100,
> James Courtier-Dutton wrote:
> 
>>Hi,
>>
>>Is there any way to tell if a USB sound card has been disconnected or not?
> 
>  
> IIRC, this is not notified to the application.
> the app simply would get an error at the further access.
> it sounds not bad to notify the status change to the application by
> some way.
> perhaps we can add a new control element for this purpose.
> and after disconnection, only this element survives to communicate
> with the application...
> 
So, the app gets an error. Which error?
How do I test to see if the error is due to a non-existant device, or 
just underrun/overrun etc.
I would be happy if there was a reliable way to tell.
This would only give us the "disconnect" event.
How would one know if the device was connected again?
Maybe a tidy way to do this would be a new alsa events device.
So, we open the "events" device, and it can then inform us of hardware 
changes. I know that USB is the only form of device that 
connects/disconnects via a user action at the moment, but I am sure 
others will come along. E.g. Bluetooth etc.
For USB, usbaudio.c definitely gets informed about usb device 
removal/addition, how can we get that message passed up to the application?

Cheers
James






-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: USB disconnect/connect messages
  2003-07-21 18:03   ` James Courtier-Dutton
@ 2003-07-21 18:23     ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2003-07-21 18:23 UTC (permalink / raw)
  To: James Courtier-Dutton; +Cc: alsa-devel

At Mon, 21 Jul 2003 19:03:29 +0100,
James Courtier-Dutton wrote:
> 
> Takashi Iwai wrote:
> > At Mon, 21 Jul 2003 00:40:32 +0100,
> > James Courtier-Dutton wrote:
> > 
> >>Hi,
> >>
> >>Is there any way to tell if a USB sound card has been disconnected or not?
> > 
> >  
> > IIRC, this is not notified to the application.
> > the app simply would get an error at the further access.
> > it sounds not bad to notify the status change to the application by
> > some way.
> > perhaps we can add a new control element for this purpose.
> > and after disconnection, only this element survives to communicate
> > with the application...
> > 
> So, the app gets an error. Which error?

well, when the disconnection happens, the file ops table is replaced
with the dummy one, which contains only the release and the poll
callbacks.  i'm not sure which errors are returned for the null
entries.  it's defined in the kernel vfs.  IIRC, EINVAL for read/write
and ENOTTY for ioctl.  so, this is not a good way as the identifer.

> How do I test to see if the error is due to a non-existant device, or 
> just underrun/overrun etc.
> 
> I would be happy if there was a reliable way to tell.
> This would only give us the "disconnect" event.
> How would one know if the device was connected again?
> Maybe a tidy way to do this would be a new alsa events device.
> So, we open the "events" device, and it can then inform us of hardware 
> changes. I know that USB is the only form of device that 
> connects/disconnects via a user action at the moment, but I am sure 
> others will come along. E.g. Bluetooth etc.
> For USB, usbaudio.c definitely gets informed about usb device 
> removal/addition, how can we get that message passed up to the application?

in the current scheme, reconnection is difficult, i must say.
since the device instance is kept until all the device files of the
disconnected device are released, if you connect it again, the driver
will try to create another instance.  so, eventually you will have two
different instances...  so the app must close the device anyway when
it's disconnected, and reopen it somehow, then resume the status and
restart.

about the connection notification: it's a good question.
ALSA has no global control device (except for the sequencer). all 
device files are based on the card.

of course, we can create a new device, but is there any other demand
for such a global control?


Takashi


-------------------------------------------------------
This SF.net email is sponsored by: VM Ware
With VMware you can run multiple operating systems on a single machine.
WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
same time. Free trial click here: http://www.vmware.com/wl/offer/345/0

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-07-21 18:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-20 23:40 USB disconnect/connect messages James Courtier-Dutton
2003-07-21 15:25 ` Takashi Iwai
2003-07-21 18:03   ` James Courtier-Dutton
2003-07-21 18:23     ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.