【发布时间】:2014-05-14 20:42:42
【问题描述】:
我正在尝试播放从服务器接收的 pcm 音频缓冲区。我下载了一个示例 alsa 播放文件,将记录的文件作为输入,它工作正常,但我在 SIP 客户端应用程序中添加的相同代码出现了 Operation not allowed 错误。打开设备并为设备设置配置都可以,但尝试获取我配置的参数给了我Operation not permitted error。
谁能告诉我这个错误的原因?
/* Open the PCM device in playback mode */
if (pcm = snd_pcm_open(&pcm_handle, PCM_DEVICE,
SND_PCM_STREAM_PLAYBACK, 0) < 0)
printf("ERROR: Can't open \"%s\" PCM device. %s\n",
PCM_DEVICE, snd_strerror(pcm));
/* Allocate parameters object and fill it with default values*/
snd_pcm_hw_params_alloca(¶ms);
snd_pcm_hw_params_any(pcm_handle, params);
/* Set parameters */
if (pcm = snd_pcm_hw_params_set_access(pcm_handle, params,
SND_PCM_ACCESS_RW_INTERLEAVED) < 0)
printf("ERROR: Can't set interleaved mode. %s\n", snd_strerror(pcm));
if (pcm = snd_pcm_hw_params_set_format(pcm_handle, params,
//SND_PCM_FORMAT_S16_LE) < 0)
SND_PCM_FORMAT_MU_LAW) < 0)
printf("ERROR: Can't set format. %s\n", snd_strerror(pcm));
if (pcm = snd_pcm_hw_params_set_channels(pcm_handle, params, channels) < 0)
printf("ERROR: Can't set channels number. %s\n", snd_strerror(pcm));
if (pcm = snd_pcm_hw_params_set_rate_near(pcm_handle, params, &rate, 0) < 0)
printf("ERROR: Can't set rate. %s\n", snd_strerror(pcm));
/* Write parameters */
if (pcm = snd_pcm_hw_params(pcm_handle, params) < 0)
printf("ERROR: Can't set harware parameters. %s\n", snd_strerror(pcm));
/* Resume information */
printf("PCM name: '%s'\n", snd_pcm_name(pcm_handle));
printf("PCM state: %s\n", snd_pcm_state_name(snd_pcm_state(pcm_handle)));
pcm = snd_pcm_hw_params_get_channels(params, &tmp);
printf("channels: %i %d", tmp, pcm);
if (tmp == 1)
printf("(mono)\n");
else if (tmp == 2)
printf("(stereo)\n");
snd_pcm_hw_params_get_rate(params, &tmp, 0);
printf("rate: %d bps\n", tmp);
printf("seconds: %d\n", seconds);
/* Allocate buffer to hold single period */
snd_pcm_hw_params_get_period_size(params, &frames, 0);
buff_size = frames * channels * 2 /* 2 -> sample size */;
buff = (char *) malloc(buff_size);
printf("buffsize: %d\n", buff_size);
snd_pcm_hw_params_get_period_time(params, &tmp, NULL);
【问题讨论】:
-
您应该检查所有函数调用的返回值。无论如何,哪个功能失败了?
-
感谢回复 snd_pcm_hw_params_get_channels、snd_pcm_hw_params_get_rate 和 snd_pcm_hw_params_get_period_size 所有上述函数都在获取 Operation not allowed 且返回值为 0