Alsa pcm接口使用方法pcm status反馈

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
}
  • 14
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
snd_pcm_info函数是ALSA库中用于获取PCM设备信息的函数。它可以获取PCM设备的名称、类型、支持的采样格式、通道数、采样率范围等信息。 该函数的原型如下: ```c int snd_pcm_info(snd_pcm_t *pcm, snd_pcm_info_t *info) ``` 其中,pcm参数是PCM设备的句柄,可以通过snd_pcm_open函数获取;info参数是一个指向snd_pcm_info_t结构体的指针。调用该函数时,需要先初始化snd_pcm_info_t结构体的version、subname和stream字段,然后再将该结构体作为参数传入snd_pcm_info函数。 snd_pcm_info_t结构体的定义如下: ```c typedef struct snd_pcm_info { unsigned int device; int stream; unsigned char id[64]; unsigned char name[80]; unsigned int subdevices_count; unsigned int subdevices_avail; unsigned int subdevices_avail_min; snd_pcm_access_t access; snd_pcm_format_mask_t format_mask; snd_pcm_subformat_t subformat; unsigned int formats; unsigned int rates; unsigned int rate_min; unsigned int rate_max; unsigned int channels; unsigned int min_channels; unsigned int max_channels; snd_pcm_chmap_query_t chmap_query; } snd_pcm_info_t; ``` 通过调用snd_pcm_info函数,可以获取PCM设备的名称、类型、支持的采样格式、通道数、采样率范围等信息,填充到snd_pcm_info_t结构体中。函数返回值为0表示成功获取设备信息,返回负数则表示获取失败。 需要注意的是,snd_pcm_info函数只能获取PCM设备的静态信息,即在设备打开之前获取的信息。如果需要获取实时信息,可以使用snd_pcm_status函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值