Handle fmodex internal channel release by registering channel callbacks. Harden channel<->source associations. Assign console output for audio system "AudioEngine" and "AudioImpl" tags. Added base LLAudioChannel::cleanup() vfunc to handle non-impl-related variable cleanup. Killed some redundant code.

This commit is contained in:
Shyotl
2013-06-04 03:46:26 -05:00
parent 9c8cfcfd0a
commit 821fd1f7d6
6 changed files with 89 additions and 106 deletions

View File

@@ -126,7 +126,7 @@ bool LLAudioEngine::init(const S32 num_channels, void* userdata)
// Initialize the decode manager
gAudioDecodeMgrp = new LLAudioDecodeMgr;
llinfos << "LLAudioEngine::init() AudioEngine successfully initialized" << llendl;
LL_INFOS("AudioEngine") << "LLAudioEngine::init() AudioEngine successfully initialized" << llendl;
return true;
}
@@ -311,8 +311,7 @@ void LLAudioEngine::idle(F32 max_decode_time)
LLAudioChannel *channelp = getFreeChannel(max_priority);
if (channelp)
{
//llinfos << "Replacing source in channel due to priority!" << llendl;
max_sourcep->setChannel(channelp);
LL_DEBUGS("AudioEngine") << "Replacing source in channel due to priority!" << llendl;
channelp->setSource(max_sourcep);
if (max_sourcep->isSyncSlave())
{
@@ -348,18 +347,22 @@ void LLAudioEngine::idle(F32 max_decode_time)
}
LLAudioChannel *channelp = sourcep->getChannel();
if (!channelp)
bool is_stopped = channelp && channelp->isPlaying();
if (is_stopped || (sourcep->isLoop() && channelp->mLoopedThisFrame))
{
// This sound isn't playing, so we just process move the queue
sourcep->mCurrentDatap = sourcep->mQueuedDatap;
sourcep->mQueuedDatap = NULL;
// Reset the timer so the source doesn't die.
sourcep->mAgeTimer.reset();
// Make sure we have the buffer set up if we just decoded the data
if (sourcep->mCurrentDatap)
if(is_stopped)
{
updateBufferForData(sourcep->mCurrentDatap);
// Reset the timer so the source doesn't die.
sourcep->mAgeTimer.reset();
// Make sure we have the buffer set up if we just decoded the data
if (sourcep->mCurrentDatap)
{
updateBufferForData(sourcep->mCurrentDatap);
}
}
// Actually play the associated data.
@@ -372,52 +375,6 @@ void LLAudioEngine::idle(F32 max_decode_time)
}
continue;
}
else
{
// Check to see if the current sound is done playing, or looped.
if (!channelp->isPlaying())
{
sourcep->mCurrentDatap = sourcep->mQueuedDatap;
sourcep->mQueuedDatap = NULL;
// Reset the timer so the source doesn't die.
sourcep->mAgeTimer.reset();
// Make sure we have the buffer set up if we just decoded the data
if (sourcep->mCurrentDatap)
{
updateBufferForData(sourcep->mCurrentDatap);
}
// Actually play the associated data.
sourcep->setupChannel();
channelp = sourcep->getChannel();
if (channelp)
{
channelp->updateBuffer();
channelp->play();
}
}
else if (sourcep->isLoop())
{
// It's a loop, we need to check and see if we're done with it.
if (channelp->mLoopedThisFrame)
{
sourcep->mCurrentDatap = sourcep->mQueuedDatap;
sourcep->mQueuedDatap = NULL;
// Actually, should do a time sync so if we're a loop master/slave
// we don't drift away.
sourcep->setupChannel();
channelp = sourcep->getChannel();
if (channelp)
{
channelp->updateBuffer();
channelp->play();
}
}
}
}
}
// Lame, update the channels AGAIN.
@@ -491,7 +448,7 @@ void LLAudioEngine::idle(F32 max_decode_time)
{
if (!mBuffers[i]->mInUse && mBuffers[i]->mLastUseTimer.getElapsedTimeF32() > 30.f)
{
//llinfos << "Flushing unused buffer!" << llendl;
LL_DEBUGS("AudioEngine") << "Flushing unused buffer!" << llendl;
mBuffers[i]->mAudioDatap->mBufferp = NULL;
delete mBuffers[i];
mBuffers[i] = NULL;
@@ -603,8 +560,7 @@ LLAudioBuffer * LLAudioEngine::getFreeBuffer()
if (buffer_id >= 0)
{
lldebugs << "Taking over unused buffer " << buffer_id << llendl;
//llinfos << "Flushing unused buffer!" << llendl;
LL_DEBUGS("AudioEngine") << "Taking over unused buffer! max_age=" << max_age << llendl;
mBuffers[buffer_id]->mAudioDatap->mBufferp = NULL;
for (U32 i = 0; i < MAX_CHANNELS; i++)
{
@@ -638,6 +594,7 @@ LLAudioChannel * LLAudioEngine::getFreeChannel(const F32 priority)
// Channel is allocated but not playing right now, use it.
if (!mChannels[i]->isPlaying() && !mChannels[i]->isWaiting())
{
LL_DEBUGS("AudioEngine") << "Replacing unused channel" << llendl;
mChannels[i]->cleanup();
if (mChannels[i]->getSource())
{
@@ -670,9 +627,9 @@ LLAudioChannel * LLAudioEngine::getFreeChannel(const F32 priority)
return NULL;
}
LL_DEBUGS("AudioEngine") << "Flushing min channel" << llendl;
// Flush the minimum priority channel, and return it.
min_channelp->cleanup();
min_channelp->getSource()->setChannel(NULL);
return min_channelp;
}
@@ -1006,10 +963,13 @@ LLAudioData * LLAudioEngine::getAudioData(const LLUUID &audio_uuid)
if( sourcep && sourcep->getCurrentData() && sourcep->getCurrentData()->getID() == audio_uuid )
{
LLAudioChannel* chan=sourcep->getChannel();
delete sourcep;
if(chan)
{
LL_DEBUGS("AudioEngine") << "removeAudioData" << llendl;
chan->cleanup();
mAllSources.erase(iter2++);
}
delete sourcep;
mAllSources.erase(iter2++);
}
else
++iter2;
@@ -1043,7 +1003,7 @@ void LLAudioEngine::cleanupAudioSource(LLAudioSource *asp)
iter = mAllSources.find(asp->getID());
if (iter == mAllSources.end())
{
llwarns << "Cleaning up unknown audio source!" << llendl;
LL_WARNS("AudioEngine") << "Cleaning up unknown audio source!" << llendl;
return;
}
delete asp;
@@ -1264,7 +1224,7 @@ void LLAudioEngine::startNextTransfer()
if (asset_id.notNull())
{
llinfos << "Getting asset data for: " << asset_id << llendl;
LL_DEBUGS("AudioEngine") << "Getting asset data for: " << asset_id << llendl;
gAudiop->mCurrentTransfer = asset_id;
gAudiop->mCurrentTransferTimer.reset();
gAssetStorage->getAssetData(asset_id, LLAssetType::AT_SOUND,
@@ -1282,7 +1242,7 @@ void LLAudioEngine::assetCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::E
{
if (result_code)
{
llinfos << "Boom, error in audio file transfer: " << LLAssetStorage::getErrorString( result_code ) << " (" << result_code << ")" << llendl;
LL_INFOS("AudioEngine") << "Boom, error in audio file transfer: " << LLAssetStorage::getErrorString( result_code ) << " (" << result_code << ")" << llendl;
// Need to mark data as bad to avoid constant rerequests.
LLAudioData *adp = gAudiop->getAudioData(uuid);
if (adp)
@@ -1299,7 +1259,7 @@ void LLAudioEngine::assetCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::E
if (!adp)
{
// Should never happen
llwarns << "Got asset callback without audio data for " << uuid << llendl;
LL_WARNS("AudioEngine") << "Got asset callback without audio data for " << uuid << llendl;
}
else
{
@@ -1360,8 +1320,7 @@ LLAudioSource::~LLAudioSource()
if (mChannelp)
{
// Stop playback of this sound
mChannelp->setSource(NULL);
setChannel(NULL);
mChannelp->cleanup();
}
}
@@ -1404,7 +1363,7 @@ void LLAudioSource::update()
}
else if (adp->hasCompletedDecode()) // Only mark corrupted after decode is done
{
llwarns << "Marking LLAudioSource corrupted for " << adp->getID() << llendl;
LL_WARNS("AudioEngine") << "Marking LLAudioSource corrupted for " << adp->getID() << llendl;
mCorrupted = true ;
}
}
@@ -1475,7 +1434,6 @@ bool LLAudioSource::play(const LLUUID &audio_uuid)
if (getChannel())
{
getChannel()->setSource(NULL);
setChannel(NULL);
if (!isMuted())
{
mCurrentDatap = NULL;
@@ -1729,11 +1687,16 @@ LLAudioChannel::~LLAudioChannel()
{
// Need to disconnect any sources which are using this channel.
//llinfos << "Cleaning up audio channel" << llendl;
if (mCurrentSourcep)
{
cleanup();
}
void LLAudioChannel::cleanup()
{
if(mCurrentSourcep)
mCurrentSourcep->setChannel(NULL);
}
mCurrentBufferp = NULL;
mCurrentSourcep = NULL;
mWaiting = false;
}
@@ -1744,22 +1707,21 @@ void LLAudioChannel::setSource(LLAudioSource *sourcep)
if (!sourcep)
{
// Clearing the source for this channel, don't need to do anything.
//llinfos << "Clearing source for channel" << llendl;
LL_DEBUGS("AudioEngine") << "Clearing source for channel" << llendl;
cleanup();
mCurrentSourcep = NULL;
mWaiting = false;
return;
}
if (sourcep == mCurrentSourcep)
{
// Don't reallocate the channel, this will make FMOD goofy.
//llinfos << "Calling setSource with same source!" << llendl;
LL_DEBUGS("AudioEngine") << "Calling setSource with same source!" << llendl;
}
cleanup();
mCurrentSourcep = sourcep;
mCurrentSourcep->setChannel(this);
updateBuffer();
update3DPosition();
}
@@ -1796,7 +1758,10 @@ bool LLAudioChannel::updateBuffer()
// The source changed what buffer it's playing. We need to clean up
// the existing channel
//
LLAudioSource* source = mCurrentSourcep;
cleanup();
mCurrentSourcep = source;
mCurrentSourcep->setChannel(this);
mCurrentBufferp = bufferp;
if (bufferp)
@@ -1856,7 +1821,7 @@ bool LLAudioData::load()
if (mBufferp)
{
// We already have this sound in a buffer, don't do anything.
llinfos << "Already have a buffer for this sound, don't bother loading!" << llendl;
LL_INFOS("AudioEngine") << "Already have a buffer for this sound, don't bother loading!" << llendl;
return true;
}
@@ -1864,7 +1829,7 @@ bool LLAudioData::load()
if (!mBufferp)
{
// No free buffers, abort.
lldebugs << "Not able to allocate a new audio buffer, aborting." << llendl;
LL_DEBUGS("AudioEngine") << "Not able to allocate a new audio buffer, aborting." << llendl;
return false;
}