OpenAL - ogg vorbis streaming error right after alBufferData()
Well, I'll try to put it simple. Let me know if it is too much simple. This is Windows XP, c++, MinGW and OpenAL/Ogg libraries for it. I'm streaming an ogg file from a separate thread and I'm getting an AL_INVALID_VALUE error right after alBufferData() is called. I think this happen when some other process is taking much CPU time, but I'm not sure. I can make this error happen, for example, if I scroll a web page up and down very quickly in IE while my program is playing the ogg file. Any idea about why this could be happening? Is there a way to restore this error state and continue streaming the file? If I ignore this error the streaming get stuck repeating a little fragment of the audio. Any help will be appreciated.
[size="2"]I like the Walrus best.
char pcm[m_iBufferSize]; int size = 0; int section; int result; while(size < m_iBufferSize) { result = ov_read(&m_OggStream, pcm + size, m_iBufferSize - size, 0, 2, 1, §ion); if(result > 0) size += result; else if(result < 0) return false; else break; } if(size <= 0) return false; alBufferData(buffer, m_Format, pcm, size, m_VorbisInfo->rate); int error = alGetError(); // display error. I'm getting (sometimes) AL_INVALID_VALUE here. return true;
[size="2"]I like the Walrus best.
Just checking: Are you *sure* that the alBufferData call causes the error, and not some other AL call?
I take it the value of m_Format and m_VorbisInfo->rate remain constant throughout the streaming, so the only reason I can think of what would cause this problem is that some other part of your code causes buffer to become invalid. Try logging the values of buffer and see if those turn out to be invalid numbers.
I take it the value of m_Format and m_VorbisInfo->rate remain constant throughout the streaming, so the only reason I can think of what would cause this problem is that some other part of your code causes buffer to become invalid. Try logging the values of buffer and see if those turn out to be invalid numbers.
I wish it was that. Running the code single threaded also raises this error in the same circumstances.
[size="2"]I like the Walrus best.
ok, still have a look at the buffer id's that are given though. And what does the rest of your streaming look like? Because I think this isn't all of it.
it's mostly a sample code I took from devmaster, this is the complete source code I'm using:
#include <windows.h>#include <al/alut.c>#include "cstream.h"using namespace owl;CStream::CStream(){ log.Open("log.txt",false); m_iBufferSize = 4096 * 10;}CStream::~CStream(){ Release();}bool CStream::Open(string path){ int result; if(!(m_OggFile = fopen(path.c_str(), "rb"))) { return false; } if((result = ov_open(m_OggFile, &m_OggStream, NULL, 0)) < 0) { fclose(m_OggFile); return false; } m_VorbisInfo = ov_info(&m_OggStream, -1); m_VorbisComment = ov_comment(&m_OggStream, -1); if(m_VorbisInfo->channels == 1) m_Format = AL_FORMAT_MONO16; else m_Format = AL_FORMAT_STEREO16; alGenBuffers(2, m_Buffers); if (!Check()) return false; alGenSources(1, &m_Source); if (!Check()) return false; alSource3f(m_Source, AL_POSITION, 0.0, 0.0, 0.0); alSource3f(m_Source, AL_VELOCITY, 0.0, 0.0, 0.0); alSource3f(m_Source, AL_DIRECTION, 0.0, 0.0, 0.0); alSourcef (m_Source, AL_ROLLOFF_FACTOR, 0.0 ); alSourcei (m_Source, AL_SOURCE_RELATIVE, AL_TRUE ); return true;}void CStream::Release(){ alSourceStop(m_Source); Empty(); alDeleteSources(1, &m_Source); Check(); alDeleteBuffers(1, m_Buffers); Check(); ov_clear(&m_OggStream);}bool CStream::Playback(){ if(Playing()) return true; if(!Stream(m_Buffers[0])) return false; if(!Stream(m_Buffers[1])) return false; alSourceQueueBuffers(m_Source, 2, m_Buffers); alSourcePlay(m_Source); return true;}bool CStream::Playing(){ ALenum state; alGetSourcei(m_Source, AL_SOURCE_STATE, &state); return (state == AL_PLAYING);}bool CStream::Update(){ int processed; bool active = true; alGetSourcei(m_Source, AL_BUFFERS_PROCESSED, &processed); while((processed--)>0) { ALuint buffer; alSourceUnqueueBuffers(m_Source, 1, &buffer); log << "CStream::Update()->buffer = " << (int)buffer <<endl; if (!Check()) { MessageBox(0,"Update()->UnqueueBuffers error","Error",0); return false; } active = Stream(buffer); alSourceQueueBuffers(m_Source, 1, &buffer); log << "CStream::Update()->buffer = " << (int)buffer <<endl; if (!Check()) { MessageBox(0,"QueueBuffers Error","Error",0); return false; } } return active;}bool CStream::Stream(ALuint buffer){ char pcm[m_iBufferSize]; int size = 0; int section; int result; while(size < m_iBufferSize) { result = ov_read(&m_OggStream, pcm + size, m_iBufferSize - size, 0, 2, 1, §ion); if(result > 0) size += result; else if(result < 0) { switch(result) { case OV_EREAD: MessageBox(0,"Read from media.","",0); case OV_ENOTVORBIS: MessageBox(0,"Not Vorbis data.","",0); case OV_EVERSION: MessageBox(0,"Vorbis version mismatch.","",0); case OV_EBADHEADER: MessageBox(0,"Invalid Vorbis header.","",0); case OV_EFAULT: MessageBox(0,"Internal logic fault (bug or heap/stack corruption.","",0); default: MessageBox(0,"Unknown Ogg error.","",0); } return false; } else break; } if(size <= 0) return false; alBufferData(buffer, m_Format, pcm, size, m_VorbisInfo->rate); log << "CStream::Stream()->buffer = " << (int)buffer <<endl; int error = alGetError(); switch(error) { case AL_NO_ERROR: return true; break; case AL_INVALID_VALUE: { log << "CStream::Stream()->buffer = " << (int)buffer <<endl; return false; } break; default: MessageBox(0,"Stream()->alBufferData Error","Error",0); return false; break; } return true;}void CStream::Empty(){ int queued; alGetSourcei(m_Source, AL_BUFFERS_QUEUED, &queued); while(queued--) { ALuint buffer; alSourceUnqueueBuffers(m_Source, 1, &buffer); }}bool CStream::Check(){ int error = alGetError(); if(error != AL_NO_ERROR) { switch(error) { case AL_NO_ERROR: MessageBox(0,"AL_NO_ERROR","error",0); break; case AL_INVALID_NAME: MessageBox(0,"AL_INVALID_NAME","error",0); break; case AL_INVALID_ENUM: MessageBox(0,"AL_INVALID_ENUM","error",0); break; case AL_INVALID_VALUE: MessageBox(0,"AL_INVALID_VALUE","error",0); break; case AL_INVALID_OPERATION: MessageBox(0,"AL_INVALID_OPERATION","error",0); break; case AL_OUT_OF_MEMORY: MessageBox(0,"AL_OUT_OF_MEMORY","error",0); break; }; MessageBox(0,"OpenAL error occured","error",0); return false; } return true;}void CStream::Run(){ alutInit(0, 0); if(!Playback()) { MessageBox(0,"Ogg refused to play","error",0); return; //Ogg refused to play } while(Update()) { if(!Playing()) { if(!Playback()) { MessageBox(0,"Ogg abruptly stopped","error",0); //Ogg abruptly stopped return; } else {// MessageBox(0,"Ogg stream was interrupted","error",0); //Ogg stream was interrupted } } Sleep(10); }}
[size="2"]I like the Walrus best.
well, I incremented the size of the buffer to (4096 * 100) and it doesn't stop anymore. Anyway I wonder how will this code behave in other systems...
[size="2"]I like the Walrus best.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement