ALSA子系统(十四)------snd_pcm_drain和snd_pcm_drop

你好!这里是风筝的博客,
欢迎和我一起交流。

最近同事问我snd_pcm_drain和snd_pcm_drop的区别和使用场景,我去文档里翻了下:PCM Interface


int snd_pcm_drain(snd_pcm_t *pcm) 	

Stop a PCM preserving pending frames.

Parameters:
pcm 	PCM handle
Returns:
0 on success otherwise a negative error code
Return values:
-ESTRPIPE 	a suspend event occurred
For playback wait for all pending frames to be played and then stop the PCM. For capture stop PCM permitting to retrieve residual frames.

For stopping the PCM stream immediately, use ::snd_pcm_drop() instead.

Examples:
/test/latency.c.
int snd_pcm_drop(snd_pcm_t *pcm) 	

Stop a PCM dropping pending frames.

Parameters:
pcm 	PCM handle
Returns:
0 on success otherwise a negative error code
This function stops the PCM immediately. The pending samples on the buffer are ignored.

For processing all pending samples, use ::snd_pcm_drain() instead.

Examples:
/test/latency.c.

可以看出,
snd_pcm_drain:对于播放,会先等待所有挂起没有传输完的数据帧先播完,才会去关闭PCM。
snd_pcm_drop:对于播放,会立即停止PCM,剩余的数据帧则直接丢弃不要。

在alsa-lib/test/pcm_mian.c文件里有个实例:

/* pass the remaining samples, otherwise they're dropped in close */
	err = snd_pcm_drain(handle);
	if (err < 0)
		printf("snd_pcm_drain failed: %s\n", snd_strerror(err));
	snd_pcm_close(handle);

在关闭pcm之前,先调用snd_pcm_drain将剩余当数据帧播完。

  • 1
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
snd_pcm_hw_params是一个函数,用于获取音频设备的硬件参数。在动态链接时,该函数的调用堆栈如下: - init()函数调用snd_pcm_hw_params_get_rate()函数,传入参数params和&actualSampleRate。 - snd_pcm_hw_params_get_rate()函数在pcm.c文件中,通过调用__old_snd_pcm_hw_params_get_rate()函数获取实际采样率actualSampleRate。 - __old_snd_pcm_hw_params_get_rate()函数在pcm.c文件中,通过调用__snd_pcm_hw_params_get_rate()函数来获取采样率。 而在静态链接时,snd_pcm_hw_params_get_rate()函数的调用堆栈如下: - init()函数调用snd_pcm_hw_params_get_rate()函数,传入参数params和&actualSampleRate。 - snd_pcm_hw_params_get_rate()函数直接调用__snd_pcm_hw_params_get_rate()函数来获取采样率。 综上所述,snd_pcm_hw_params_get_rate()函数在动态链接和静态链接下的调用堆栈是不同的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [动态库调用snd_pcm_hw_params_get_rate失败](https://blog.csdn.net/u010687717/article/details/103704419)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ALSA音频架构 -- snd_pcm_open函数分析](https://blog.csdn.net/liang_zhaocong/article/details/126202864)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值