Playback states

Let's consider the state transitions for a PCM device during playback.

Figure 1. State diagram for PCM devices during playback.

In the figure above, the oval groups the Underrun, Error, and Unsecure states together to indicate that each state can transition to the Prepared state

The transition between SND_PCM_STATUS_* states is the result of executing an API call, or the result of conditions that occur in the hardware:

From To Cause
NOTREADY READY Calling snd_pcm_channel_params() or snd_pcm_plugin_params()
READY PREPARED Calling snd_pcm_channel_prepare(), snd_pcm_playback_prepare(), or snd_pcm_plugin_prepare()
PREPARED RUNNING Calling snd_pcm_channel_flush(), snd_pcm_playback_flush(), snd_pcm_plugin_flush(), snd_pcm_playback_go(), snd_pcm_channel_go(), snd_pcm_write() or snd_pcm_plugin_write()
PREPARED SUSPENDED When forced ducking is enabled via a call to snd_pcm_channel_audio_ducking(), the state change occurs when the audio concurrency management policy in place has ducked the audio stream that's currently in the PREPARED (SND_PCM_STATUS_PREPARED) state. If forced ducking isn't enabled, this state change doesn't occur.
RUNNING PAUSED Calling snd_pcm_channel_pause() or snd_pcm_playback_pause()
PAUSED RUNNING Calling snd_pcm_channel_flush(), snd_pcm_playback_flush(), snd_pcm_plugin_flush(), snd_pcm_channel_resume() or snd_pcm_playback_resume()
PAUSED SUSPENDED While the subchannel was paused, a higher priority or same priority subchannel preempted the paused subchannel (volume was ducked to zero). For that reason, the stream moves to the suspended (SND_PCM_STATUS_SUSPENDED) state.
PAUSED READY One of the following:
  • While the subchannel was paused, if you call snd_pcm_*_params() or snd_pcm_*_drain(), the stream moves to the READY state.
  • While the subchannel was paused, if you call snd_pcm_*_flush(), the playback resumes, and then the stream moves to the READY state after the buffered data is fully consumed.
RUNNING READY One of the following:
RUNNING UNDERRUN The hardware buffer became empty during playback
RUNNING UNSECURE The application marked the stream as protected, the hardware level supports a secure transport (e.g., HDCP for HDMI), and authentication was lost
RUNNING CHANGED The stream parameters have changed
RUNNING ERROR A hardware error occurred
RUNNING SUSPENDED Audio concurrency management has suspended the subchannel because a higher or same priority subchannel has run.
SUSPENDED RUNNING Audio concurrency management has moved the previously suspended subchannel back to the running (SND_PCM_STATUS_RUNNING) state and the subchannel starts to play again. The application must start writing data, otherwise an underrun condition can occur.

This transition may also occur if a subchannel is in a soft suspended (SND_PCM_STATUS_SUSPENDED) state and calls snd_pcm_channel_resume() or snd_pcm_playback_resume(). For more information, see Understanding preemption section in the Audio Concurrency Management chapter of this guide.

SUSPENDED PAUSED The state occurred because the audio concurrency management policy in place is configured to pause, which means when audio concurrency management clears the suspension, a transition was made to the PAUSED (SND_PCM_STATUS_PAUSED) state rather the RUNNING (SND_PCM_STATUS_RUNNING) state.

If you were previously in the PAUSED state before the suspension occurs, after suspension is lifted, you return to the PAUSED state.

While in the SUSPENDED state, if a snd_pcm_*_pause() call was made, you would transition to the PAUSED state when the suspension is lifted.

SUSPENDED PREPARED If forced ducking was enabled via a call to snd_pcm_channel_audio_ducking(), then audio concurrency management changes from the SUSPENDED state to the PREPARED (SND_PCM_STATUS_PREPARED) when the suspension condition has been lifted.
SUSPENDED READY While the subchannel was suspended, if you call snd_pcm_*_drain(), the stream moves to the READY state.
UNDERRUN, UNSECURE, or ERROR PREPARED Calling snd_pcm_channel_prepare(), snd_pcm_playback_prepare(), or snd_pcm_plugin_prepare()
RUNNING PREEMPTED Audio is blocked because another libasound session has initiated playback, but there aren't enough system resources available; the audio driver has determined that the new session has higher priority and as a result, this session has been preempted.

For more details on these transitions, see the description of each function in the Audio Library chapter.