为什么 alSourceUnqueueBuffers 会因 INVALID_OPERATION 失败
代码如下:
ALint cProcessedBuffers = 0;
ALenum alError = AL_NO_ERROR;
alGetSourcei(m_OpenALSourceId, AL_BUFFERS_PROCESSED, &cProcessedBuffers);
if((alError = alGetError()) != AL_NO_ERROR)
{
throw "AudioClip::ProcessPlayedBuffers - error returned from alGetSroucei()";
}
alError = AL_NO_ERROR;
if (cProcessedBuffers > 0)
{
alSourceUnqueueBuffers(m_OpenALSourceId, cProcessedBuffers, arrBuffers);
if((alError = alGetError()) != AL_NO_ERROR)
{
throw "AudioClip::ProcessPlayedBuffers - error returned from alSourceUnqueueBuffers()";
}
}
对 alGetSourcei 的调用返回 cProcessedBuffers > 。 0,但以下对 alSourceUnqueueBuffers 的调用失败并出现 INVALID_OPERATION。这是一个并不总是发生的不稳定错误。包含此示例代码的程序是一个在紧密循环中运行的单线程应用程序(通常会与显示循环同步,但在这种情况下,我不使用任何类型的定时回调)。
Here's the code:
ALint cProcessedBuffers = 0;
ALenum alError = AL_NO_ERROR;
alGetSourcei(m_OpenALSourceId, AL_BUFFERS_PROCESSED, &cProcessedBuffers);
if((alError = alGetError()) != AL_NO_ERROR)
{
throw "AudioClip::ProcessPlayedBuffers - error returned from alGetSroucei()";
}
alError = AL_NO_ERROR;
if (cProcessedBuffers > 0)
{
alSourceUnqueueBuffers(m_OpenALSourceId, cProcessedBuffers, arrBuffers);
if((alError = alGetError()) != AL_NO_ERROR)
{
throw "AudioClip::ProcessPlayedBuffers - error returned from alSourceUnqueueBuffers()";
}
}
The call to alGetSourcei returns with cProcessedBuffers > 0, but the following call to alSourceUnqueueBuffers fails with an INVALID_OPERATION. This in an erratic error that does not always occur. The program containing this sample code is a single-threaded app running in a tight loop (typically would be sync'ed with a display loop, but in this case I'm not using a timed callback of any sort).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先尝试
alSourceStop(m_OpenALSourceId)
。然后是
alUnqueueBuffers()
,之后,通过alSourcePlay(m_OpenALSourceId)
重新开始播放。我通过这种方式解决了同样的问题。但我不知道为什么必须这样做
Try
alSourceStop(m_OpenALSourceId)
first.Then
alUnqueueBuffers()
, and after that, Restart playing byalSourcePlay(m_OpenALSourceId)
.I solved the same problem by this way. But I don't know why have to do so in
此 SO 线程中提到,
如果您在流媒体源上启用了 AL_LOOPING,则取消队列操作将失败。
循环标志在启用时对缓冲区有某种锁定。 @MyMiracle 的答案也暗示了这一点,停止了声音的释放,但这不是必需的。
AL_LOOPING 并不意味着在流媒体源上设置,因为您管理中的源数据队列。继续排队,就会继续播放。队列从数据开始,就会循环。
Mentioned in this SO thread,
If you have AL_LOOPING enabled on a streaming source the unqueue operation will fail.
The looping flag has some sort of lock on the buffers when enabled. The answer by @MyMiracle hints at this as well, stopping the sound releases that hold, but it's not necessary..
AL_LOOPING is not meant to be set on a streaming source, as you manage the source data in the queue. Keep queuing, it will keep playing. Queue from the beginning of the data, it will loop.