Dmix plugin does not update state when sound card is removed.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



alsa-project/alsa-lib issue #137 was opened from MHoyer12345678:

Playing sound using snd_pcm_writei in a dmix setup might result in an infinite loop when sound card is removed.

**Setup:**

- dmix setup
- pcm dmix device opened non blocking
- snd_pcm_writei used with poll (POLLERR is not evaluated)

**Trigger:**
- usb sound card is removed (e.g. by  "echo 0 > /sys/bus/usb/x-x/authorized")

**Observation:**
- snd_pcm_writei returns -EAGAIN on each call
- snd_pcm_state report state RUNNING

**Expected:**
- snd_pcm_writei returns -ENODEV (as happening in case a pure hw configuration is used without dmix plugin)
- snd_pcm_state report state DISCONNECTED (as happening in case a pure hw configuration is used without dmix plugin)

**Root Cause:**
- snd_pcm_writei calls snd_pcm_write_areas
- snd_pcm_write_areas requests state of dmix pcm device (state = __snd_pcm_state(pcm);)
- dmix implementation of snd_pcm_state requests state from slave hw device (state = snd_pcm_state(dmix->spcm);)
- hw implementation of snd_pcm_state executes an ioctl (query_status -> sync_ptr1)
- the ioctl call fails with -ENODEV (after the device has been  removed)
- pcm_hw returns -ENODEV as state
- dmix implementation of snd_pcm_state ends in default section of the switch block
- this leads to the unchanged dmix->state returned
- this way, the -ENODEV from the slave device is finally ignored in dmix plugin

**Potential Fix:**
- Add the following three lines to snd_pcm_hw_state in pcm_hw.c after query_status_data 

```
//disconnected HW is reported via a failed IOCTL return -ENODEV
if (err == -ENODEV)
	return SND_PCM_STATE_DISCONNECTED;
```
- The fix takes -ENODEV as trigger to return state DISCONNECTED

Hope this helps ...

Issue URL     : https://github.com/alsa-project/alsa-lib/issues/137
Repository URL: https://github.com/alsa-project/alsa-lib



[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux