From 5cf5dc73eadaa6ba1ebc92aa67c622e600926f24 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Fri, 24 Jun 2011 17:53:33 -0700 Subject: Tiny bit of coding standards changes for llaudioengine_openal and moved audio engine cleanup later during shutdown to prevent conflicts --- linden/indra/llaudio/llaudioengine_openal.cpp | 43 +++++++++++-------- linden/indra/llaudio/llaudioengine_openal.h | 6 +-- linden/indra/newview/llappviewer.cpp | 59 ++++++++++++++------------- 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/linden/indra/llaudio/llaudioengine_openal.cpp b/linden/indra/llaudio/llaudioengine_openal.cpp index 08ec464..90dffc6 100644 --- a/linden/indra/llaudio/llaudioengine_openal.cpp +++ b/linden/indra/llaudio/llaudioengine_openal.cpp @@ -38,7 +38,7 @@ #include "lllistener_openal.h" -static const float WIND_BUFFER_SIZE_SEC = 0.05f; // 1/20th sec +static const F32 WIND_BUFFER_SIZE_SEC = 0.05f; // 1/20th sec std::string convertALErrorToString(ALenum error) { @@ -94,7 +94,7 @@ bool LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata) mWindGen = NULL; LLAudioEngine::init(num_channels, userdata); - if(!alutInit(NULL, NULL)) + if (!alutInit(NULL, NULL)) { llwarns << "LLAudioEngine_OpenAL::init() ALUT initialization failed: " << alutGetErrorString (alutGetError ()) << llendl; return false; @@ -230,7 +230,7 @@ std::string LLAudioEngine_OpenAL::getDriverName(bool verbose) void LLAudioEngine_OpenAL::allocateListener() { mListenerp = (LLListener *) new LLListener_OpenAL(); - if(!mListenerp) + if (!mListenerp) { llwarns << "LLAudioEngine_OpenAL::allocateListener() Listener creation failed" << llendl; } @@ -239,18 +239,19 @@ void LLAudioEngine_OpenAL::allocateListener() // virtual void LLAudioEngine_OpenAL::shutdown() { - llinfos << "About to LLAudioEngine::shutdown()" << llendl; + llinfos << "Entering LLAudioEngine::shutdown()" << llendl; LLAudioEngine::shutdown(); - llinfos << "About to alutExit()" << llendl; - if(!alutExit()) + llinfos << "Entering alutExit()" << llendl; + if (!alutExit()) { - llwarns << "Nuts." << llendl; llwarns << "LLAudioEngine_OpenAL::shutdown() ALUT shutdown failed: " << alutGetErrorString(alutGetError()) << llendl; } - - llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; + else + { + llinfos << "LLAudioEngine_OpenAL::shutdown() OpenAL successfully shut down" << llendl; + } delete mListenerp; mListenerp = NULL; @@ -270,6 +271,10 @@ void LLAudioEngine_OpenAL::shutdown() { llinfos << "AL error: " << convertALErrorToString(error) << ". Could not destroy context!" << llendl; } + else + { + mContext = NULL; + } alcCloseDevice(mDevice); error = alGetError(); @@ -277,6 +282,10 @@ void LLAudioEngine_OpenAL::shutdown() { llinfos << "AL error: " << convertALErrorToString(error) << ". Could not close device!" << llendl; } + else + { + mDevice = NULL; + } } LLAudioBuffer *LLAudioEngine_OpenAL::createBuffer() @@ -306,7 +315,7 @@ LLAudioChannelOpenAL::LLAudioChannelOpenAL() LLAudioChannelOpenAL::~LLAudioChannelOpenAL() { cleanup(); - if (mALSource != AL_NONE) //MC + if (mALSource != AL_NONE) { alDeleteSources(1, &mALSource); mALSource = AL_NONE; @@ -327,7 +336,7 @@ void LLAudioChannelOpenAL::play() return; } - if(!isPlaying()) + if (!isPlaying()) { alSourcePlay(mALSource); getSource()->setPlayedOnce(true); @@ -453,7 +462,7 @@ LLAudioBufferOpenAL::~LLAudioBufferOpenAL() void LLAudioBufferOpenAL::cleanup() { - if(mALBuffer != AL_NONE) + if (mALBuffer != AL_NONE) { alDeleteBuffers(1, &mALBuffer); mALBuffer = AL_NONE; @@ -464,7 +473,7 @@ bool LLAudioBufferOpenAL::loadWAV(const std::string& filename) { cleanup(); mALBuffer = alutCreateBufferFromFile(filename.c_str()); - if(mALBuffer == AL_NONE) + if (mALBuffer == AL_NONE) { ALenum error = alutGetError(); if (gDirUtilp->fileExists(filename)) @@ -492,7 +501,7 @@ bool LLAudioBufferOpenAL::loadWAV(const std::string& filename) U32 LLAudioBufferOpenAL::getLength() { - if(mALBuffer == AL_NONE) + if (mALBuffer == AL_NONE) { return 0; } @@ -514,7 +523,7 @@ void LLAudioEngine_OpenAL::initWind() alGenSources(1,&mWindSource); - if((error=alGetError()) != AL_NO_ERROR) + if ((error=alGetError()) != AL_NO_ERROR) { llwarns << "LLAudioEngine_OpenAL::initWind() Error creating wind sources: " << convertALErrorToString(error) << llendl; } @@ -527,7 +536,7 @@ void LLAudioEngine_OpenAL::initWind() mWindBuf = new WIND_SAMPLE_T [mWindBufSamples * 2 /*stereo*/]; - if(mWindBuf==NULL) + if (mWindBuf == NULL) { llerrs << "LLAudioEngine_OpenAL::initWind() Error creating wind memory buffer" << llendl; mEnableWind=false; @@ -576,7 +585,7 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) if (!mEnableWind) return; - if(!mWindBuf) + if (!mWindBuf) return; if (mWindUpdateTimer.checkExpirationAndReset(LL_WIND_UPDATE_INTERVAL)) diff --git a/linden/indra/llaudio/llaudioengine_openal.h b/linden/indra/llaudio/llaudioengine_openal.h index df32e13..47748c3 100644 --- a/linden/indra/llaudio/llaudioengine_openal.h +++ b/linden/indra/llaudio/llaudioengine_openal.h @@ -70,9 +70,9 @@ class LLAudioEngine_OpenAL : public LLAudioEngine U32 mWindBufSamples; U32 mWindBufBytes; ALuint mWindSource; - int mNumEmptyWindALBuffers; + S32 mNumEmptyWindALBuffers; - static const int MAX_NUM_WIND_BUFFERS = 80; + static const S32 MAX_NUM_WIND_BUFFERS = 80; ALCcontext* mContext; ALCdevice* mDevice; @@ -109,7 +109,7 @@ class LLAudioBufferOpenAL : public LLAudioBuffer friend class LLAudioChannelOpenAL; protected: void cleanup(); - ALuint getBuffer() {return mALBuffer;} + ALuint getBuffer() { return mALBuffer; } ALuint mALBuffer; }; diff --git a/linden/indra/newview/llappviewer.cpp b/linden/indra/newview/llappviewer.cpp index aeb52a2..c9ab291 100644 --- a/linden/indra/newview/llappviewer.cpp +++ b/linden/indra/newview/llappviewer.cpp @@ -1284,35 +1284,6 @@ bool LLAppViewer::cleanup() llinfos << "Global stuff deleted" << llendflush; - if (gAudioStream) - { - // shut down the streaming audio sub-subsystem first, in case it relies on not outliving the general audio subsystem. - - delete gAudioStream; - gAudioStream = NULL; - } - - if (gAudiop) - { - // shut down the audio subsystem - - bool want_longname = false; - if (gAudiop->getDriverName(want_longname) == "FMOD") - { - // This hack exists because fmod likes to occasionally - // crash or hang forever when shutting down, for no - // apparent reason. - llwarns << "Hack, skipping FMOD audio engine cleanup" << llendflush; - } - else - { - gAudiop->shutdown(); - } - - delete gAudiop; - gAudiop = NULL; - } - // Note: this is where LLFeatureManager::getInstance()-> used to be deleted. // Patch up settings for next time @@ -1548,6 +1519,36 @@ bool LLAppViewer::cleanup() end_messaging_system(); llinfos << "Message system deleted." << llendflush; + if (gAudioStream) + { + // shut down the streaming audio sub-subsystem first, in case it relies on not outliving the general audio subsystem. + + delete gAudioStream; + gAudioStream = NULL; + } + + if (gAudiop) + { + // shut down the audio subsystem + + bool want_longname = false; + if (gAudiop->getDriverName(want_longname) == "FMOD") + { + // This hack exists because fmod likes to occasionally + // crash or hang forever when shutting down, for no + // apparent reason. + llwarns << "Hack, skipping FMOD audio engine cleanup" << llendflush; + } + else + { + gAudiop->shutdown(); + } + + delete gAudiop; + gAudiop = NULL; + } + llinfos << "Audio system deleted" << llendl; + // *NOTE:Mani - The following call is not thread safe. LLCurl::cleanupClass(); llinfos << "LLCurl cleaned up." << llendflush; -- cgit v1.1