[Previous] [Contents] [Next]

snd_pcm_channel_status()

Get current PCM runtime status

Synopsis:

#include <sys/asoundlib.h>

int snd_pcm_channel_status( 
                  snd_pcm_t * handle, 
                  snd_pcm_channel_status_t * status );

Library:

libasound.so

Description:

The snd_pcm_channel_status() function fills the status structure with data about the PCM channel runtime status selected by handle. The channel member specifies the direction. Other members are read-only.

typedef struct snd_pcm_channel_status
{
    int32_t         channel;        /* channel information */
    int32_t         mode;           /* transfer mode */
    int32_t         status;         /* channel status-SND_PCM_STATUS_XXXX */
    uint32_t        scount;         /* number of bytes processed from playback/capture start */
    struct timeval  stime;          /* time when playback/capture was started */
    uint64_t        ust_stime;      /* UST time when playback/capture was started */
    int32_t         frag;           /* current fragment */
    int32_t         count;          /* number of bytes in queue/buffer */
    int32_t         free;           /* bytes in queue still free */
    int32_t         underrun;       /* count of underruns (playback) from last status */
    int32_t         overrun;        /* count of overruns (capture) from last status */
    int32_t         overrange;      /* count of ADC (capture) overrange detections from last status */
    uint8_t         reserved[128];  /* must be filled with zero */
}       snd_pcm_channel_status_t;

where:

channel
Specifies channel direction. One of SND_PCM_CHANNEL_PLAYBACK or SND_PCM_CHANNEL_CAPTURE.
mode
Shows transfer mode. One of SND_PCM_MODE_STREAM or SND_PCM_MODE_BLOCK.
status
Shows channel status. Valid values are:
SND_PCM_STATUS_NOTREADY
The driver isn't prepared for any operation. After a successful snd_pcm_channel_params() call the state's changed to SND_PCM_STATUS_READY.
SND_PCM_STATUS_READY
The driver is ready for operation. The audio buffer may be mmap()ed only at this moment, but the samples can't be still transferred. After successful snd_pcm_channel_prepare() call the state's changed to SND_PCM_STATUS_PREPARED.
SND_PCM_STATUS_PREPARED
The driver is prepared for operation. The samples may be transferred at this moment.
SND_PCM_STATUS_RUNNING
The driver manages running stream. The samples may be transferred at this moment.
SND_PCM_STATUS_UNDERRUN
The playback direction is in underrun state. It means that the driver didn't get the data in right time. Only snd_pcm_playback_drain() may change this state.
SND_PCM_STATUS_OVERRUN
The capture direction is in overrun state. It means that hardware hasn't received the data in right time.
SND_PCM_STATUS_PAUSED
The playback is paused.
scount
Shows the count of bytes processed from the playback/capture start. This value is clipped when reaches the SND_PCM_BOUNDARY value.
stime
Shows the playback/capture start time in gettimeofday format. This member is valid only when the time flags was active in the snd_pcm_channel_params_t structure.
ust_stime
Shows the playback/capture start time in UST format. This member is valid only when the ust_time flags was active in the snd_pcm_channel_params_t structure.
frag
Shows the current fragment number (available only in the block mode).
count
Number of bytes in queue/buffer.
free
Bytes in queue still free.
underrun
Count of playback underruns from last status.
overrun
Count of capture overruns from last status.
overrange
Count of ADC capture overrange detections from last status.

Returns:

Zero on success, or an error code.

Errors:

-EBADFD
The pcm device state isn't ready.
-EFAULT
Failed to copy data.
-EINVAL
Invalid handle or data pointer is NULL.

Examples:

See the Handling Writes example in the Playing Audio Data chapter.

Classification:

ALSA

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

snd_pcm_plugin_status()


[Previous] [Contents] [Next]