Linux 从启动脚本运行应用程序时,ALSA snd_pcm_hw_params_any崩溃

Linux 从启动脚本运行应用程序时,ALSA snd_pcm_hw_params_any崩溃,linux,alsa,libasound,Linux,Alsa,Libasound,我下载了ALSA示例源代码()并在putty窗口下运行测试,它可以正常工作。然而,当将其放入带有或不带有“sudo”的启动脚本(例如rc.local)时,它崩溃了 注意:应用程序只有在开机自动运行后才会崩溃;如果在putty(命令行)中运行脚本,则没有问题 在每个snd_xxx函数调用前添加日志记录后,发现在调用snd_pcm_hw_params_any后应用程序停止,这意味着它在snd_pcm_打开和snd_pcm_hw_params_alloca后崩溃。代码如下: g_pLog-&g

我下载了ALSA示例源代码()并在putty窗口下运行测试,它可以正常工作。然而,当将其放入带有或不带有“sudo”的启动脚本(例如rc.local)时,它崩溃了

注意:应用程序只有在开机自动运行后才会崩溃;如果在putty(命令行)中运行脚本,则没有问题

在每个snd_xxx函数调用前添加日志记录后,发现在调用snd_pcm_hw_params_any后应用程序停止,这意味着它在snd_pcm_打开和snd_pcm_hw_params_alloca后崩溃。代码如下:

    g_pLog->LogInfo(LOG_SYS, "[audio]snd_pcm_open"); /////logged 
    if ((pcm = snd_pcm_open(&pcm_handle, acDev, /////PCM_DEVICE, acDev="default:0"
                    SND_PCM_STREAM_PLAYBACK, 0)) < 0)
    {
        sprintf(acLog, "[audio]Can't open \"%s\" PCM device. %s\n", acDev, snd_strerror(pcm));
        g_pLog->LogInfo(LOG_SYS, acLog);
        return -1;
    }


    g_pLog->LogInfo(LOG_SYS, "[audio]snd_pcm_hw_params_alloca");  /////logged
    /* Allocate parameters object and fill it with default values*/
    snd_pcm_hw_params_alloca(&params);

    g_pLog->LogInfo(LOG_SYS, "[audio]snd_pcm_hw_params_any");  /////logged and is the last line
    snd_pcm_hw_params_any(pcm_handle, params);

    g_pLog->LogInfo(LOG_SYS, "[audio]snd_pcm_hw_params_set_access");
    /* Set parameters */
    if (pcm = snd_pcm_hw_params_set_access(pcm_handle, params,
                    SND_PCM_ACCESS_RW_INTERLEAVED) < 0)
...
g\u pLog->LogInfo(LOG\u SYS,“[audio]snd\u pcm\u open”)/////记录
如果((pcm=snd\u pcm\u打开)(&pcm\u句柄,acDev,///pcm\u设备,acDev=“默认值:0”
SND_PCM_流_播放,0)<0)
{
sprintf(acLog,“[音频]无法打开\%s\”PCM设备。%s\n”,acDev,snd_strerror(PCM));
g_pLog->LogInfo(LOG_SYS,acLog);
返回-1;
}
g_pLog->LogInfo(LOG_SYS,“[audio]snd_pcm_hw_params_alloca”)/////记录
/*分配参数对象并用默认值填充它*/
snd_pcm_hw_params_alloca(¶ms);
g_pLog->LogInfo(LOG_SYS,“[audio]snd_pcm_hw_params_any”)/////已记录,是最后一行
snd_pcm_hw_params_any(pcm_handle,params);
g_pLog->LogInfo(LOG_SYS,“[audio]snd_pcm_hw_params_set_access”);
/*设置参数*/
如果(pcm=snd_pcm_hw_params_set_access(pcm_handle,params,
SND_PCM_访问_RW_交织)<0)
...
收集堆芯转储文件并使用gdb“bt full”检查后,结果为:

root@linaro-ubuntu-desktop:/test# gdb ./AudioPlayer /opt/core.AudioPlayer.6277.1604311455.6
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "arm-linux-gnueabi".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /test/AudioPlayer...(no debugging symbols found)...done.
[New LWP 6277]
[Thread debugging using libthread_db enabled]
Core was generated by `/test/AudioPlayer'.
Program terminated with signal 6, Aborted.
#0  0x2ad8bed6 in ?? () from /lib/arm-linux-gnueabi/libc.so.6
(gdb) bt full
#0  0x2ad8bed6 in ?? () from /lib/arm-linux-gnueabi/libc.so.6
No symbol table info available.
#1  0x2ad9a0da in raise () from /lib/arm-linux-gnueabi/libc.so.6
No symbol table info available.
#2  0x2ad9c506 in abort () from /lib/arm-linux-gnueabi/libc.so.6
No symbol table info available.
#3  0x2ad951ec in __assert_fail () from /lib/arm-linux-gnueabi/libc.so.6
No symbol table info available.
#4  0x2ac6cb72 in snd_pcm_hw_refine () from /usr/lib/arm-linux-gnueabi/libasound.so.2
No symbol table info available.
#5  0x0000aca8 in main ()
No symbol table info available.
root@linaro-ubuntu桌面:/test#gdb./AudioPlayer/opt/core.AudioPlayer.6277.1604311455.6
GNU gdb(Ubuntu/Linaro 7.3-0ubuntu2)7.3-2011.08
版权所有(C)2011免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。键入“显示复制”
和“显示保修”了解详细信息。
此GDB配置为“arm linux gnueabi”。
有关错误报告说明,请参阅:
...
正在从/test/AudioPlayer读取符号…(未找到调试符号)…已完成。
[新LWP 6277]
[已启用使用libthread_db的线程调试]
核心由“/test/AudioPlayer”生成。
程序以信号6终止,中止。
#0 0x2ad8bed6英寸??()来自/lib/arm-linux-gnueabi/libc.so.6
(gdb)英国电信全部
#0 0x2ad8bed6英寸??()来自/lib/arm-linux-gnueabi/libc.so.6
没有可用的符号表信息。
#来自/lib/arm-linux-gnueabi/libc.so.6的提升()中的1 0x2ad9a0da
没有可用的符号表信息。
#来自/lib/arm-linux-gnueabi/libc.so.6的中止()中的2 0x2ad9c506
没有可用的符号表信息。
#3/lib/arm-linux-gnueabi/libc.so.6中的0x2ad951ec中的断言失败()
没有可用的符号表信息。
#来自/usr/lib/arm-linux-gnueabi/libasound.so.2的snd_-pcm_-hw_-refine()中的4 0x2ac6cb72
没有可用的符号表信息。
#5 0x0000aca8主管道()
没有可用的符号表信息。
注意“snd_pcm_hw_refine”不是直接从应用程序调用的


我想知道在putty中运行和在开机启动脚本中运行有什么区别,以及如何解决此故障。如果您能建议……

调用
snd\u pcm\u open()
open失败,将不胜感激。然后错误代码检查失败,因为
pcm
未签名
snd_pcm_hw_params_any()
然后崩溃,因为
pcm_handle
为空

该代码中还有很多其他错误。算了吧。使用类似以下内容:

#包括
#包括
#包括
静态无效alsa_检查(整型结果,常量字符*调用)
{
如果(结果<0){
fprintf(stderr,“%s失败:%s\n”,调用,snd_strerror(结果));
出口(1);
}
}
#定义检查(f)也定义检查(f,#f)
静态无效播放(snd_pcm_t*pcm,整数帧大小)
{
#定义帧50000
void*buf,*数据;
int帧,rest;
buf=malloc(帧*帧大小);
对于(;;){
框架=fread(buf,框架尺寸,框架,标准尺寸);
如果(第0帧){
帧=snd_pcm_writei(pcm、数据、rest);
如果(帧<0)
检查(snd_pcm_recover(pcm,帧,0));
否则{
静止-=框架;
数据+=帧*帧大小;
}
}
}
免费(buf);
}
int main(int argc,char*argv[])
{
const char*device=“默认”;
snd_pcm_format_t format=snd_pcm_format_S16_LE;
snd_pcm_access_t access=snd_pcm_access_RW_交错;
无符号整数通道,速率;
无符号整数延迟=500000;/*0.5秒*/
snd_pcm_t*pcm;
如果(argc!=3){
fprintf(stderr,“用法:%s速率通道
调用
snd\u pcm\u open()
open失败。然后错误代码检查失败,因为
pcm
未签名
snd_pcm_hw_params_any()
然后崩溃,因为
pcm_handle
为空

该代码中还有很多其他错误。算了吧。使用类似以下内容:

#包括
#包括
#包括
静态无效alsa_检查(整型结果,常量字符*调用)
{
如果(结果<0){
fprintf(stderr,“%s失败:%s\n”,调用,snd_strerror(结果));
出口(1);
}
}
#定义检查(f)也定义检查(f,#f)
静态无效播放(snd_pcm_t*pcm,整数帧大小)
{
#定义帧50000
void*buf,*数据;
int帧,rest;
buf=malloc(帧*帧大小);
对于(;;){
框架=fread(buf,框架尺寸,框架,标准尺寸);
如果(第0帧){
帧=snd_pcm_writei(pcm、数据、rest);
如果(帧<0)