1,PCM接口和状态的关系图
2,Error恢复
分析Error Code,根据error Code做不同的处理
-EBADFD(77) | PCM is not in the right state (SND_PCM_STATE_PREPARED or SND_PCM_STATE_RUNNING) |
-EPIPE(32) | an underrun or overrun occurred |
-ESTRPIPE(86) | a suspend event occurred (stream is suspended and waiting for an application recovery) |
3,PCM STATE具体介绍
SND_PCM_STATE_OPEN
The PCM device is in the open state. After the snd_pcm_open() open call, the device is in this state. Also, when snd_pcm_hw_params() call fails, then this state is entered to force application calling snd_pcm_hw_params() function to set right communication parameters.
SND_PCM_STATE_SETUP
The PCM device has accepted communication parameters and it is waiting for snd_pcm_prepare() call to prepare the hardware for selected operation (playback or capture).
SND_PCM_STATE_PREPARED
The PCM device is prepared for operation. Application can use snd_pcm_start() call, write or read data to start the operation.
SND_PCM_STATE_RUNNING
The PCM device has been started and is running. It processes the samples. The stream can be stopped using the snd_pcm_drop() or snd_pcm_drain() calls.
SND_PCM_STATE_XRUN
The PCM device reached overrun (capture) or underrun (playback). You can use the -EPIPE return code from I/O functions (snd_pcm_writei(), snd_pcm_writen(), snd_pcm_readi(), snd_pcm_readn()) to determine this state without checking the actual state via snd_pcm_state() call. It is recommended to use the helper function snd_pcm_recover() to recover from this state, but you can also use snd_pcm_prepare(), snd_pcm_drop() or snd_pcm_drain() calls.
SND_PCM_STATE_DRAINING
The device is in this state when application using the capture mode called snd_pcm_drain() function. Until all data are read from the internal ring buffer using I/O routines (snd_pcm_readi(), snd_pcm_readn()), then the device stays in this state.
SND_PCM_STATE_PAUSED
The device is in this state when application called the snd_pcm_pause() function until the pause is released. Not all hardware supports this feature. Application should check the capability with the snd_pcm_hw_params_can_pause().
SND_PCM_STATE_SUSPENDED
The device is in the suspend state provoked with the power management system. The stream can be resumed using snd_pcm_resume() call, but not all hardware supports this feature. Application should check the capability with the snd_pcm_hw_params_can_resume(). In other case, the calls snd_pcm_prepare(), snd_pcm_drop(), snd_pcm_drain() can be used to leave this state.
SND_PCM_STATE_DISCONNECTED
The device is physicaly disconnected. It does not accept any I/O calls in this state.
4,PCM State值
enum | snd_pcm_state_t { SND_PCM_STATE_OPEN = 0 , SND_PCM_STATE_SETUP , SND_PCM_STATE_PREPARED , SND_PCM_STATE_RUNNING , SND_PCM_STATE_XRUN , SND_PCM_STATE_DRAINING , SND_PCM_STATE_PAUSED , SND_PCM_STATE_SUSPENDED , SND_PCM_STATE_DISCONNECTED , SND_PCM_STATE_LAST = SND_PCM_STATE_DISCONNECTED , SND_PCM_STATE_PRIVATE1 = 1024 } |