Fix sound explorer.

Looping sounds were always showing as 'Looping', even after they
stopped. Detection of stopped sounds is much better now.
Instead of only logging a sound as stopped when the audio source
is destroyed, we now detect whether or not it is associated with
an audio channel or not (the normal way to stop a sound is to set
the channel to NULL). This is still a bit fuzzy, since an
audio channel doesn't necessarily have to be playing, but states
where an audio source is associated with a non-playing audio channel
are only short temporary states that don't affect the usefulness
of the sound explorer.
This commit is contained in:
Aleric Inglewood
2011-06-03 22:51:46 +02:00
parent e3742734f0
commit 613c6755e9
3 changed files with 61 additions and 48 deletions

View File

@@ -1336,16 +1336,17 @@ LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32
LLAudioSource::~LLAudioSource() LLAudioSource::~LLAudioSource()
{ {
// <edit>
// Record destruction of LLAudioSource object.
if(mType != LLAudioEngine::AUDIO_TYPE_UI)
logSoundStop(mLogID, true);
// </edit>
if (mChannelp) if (mChannelp)
{ {
// Stop playback of this sound // Stop playback of this sound
mChannelp->setSource(NULL); mChannelp->setSource(NULL);
mChannelp = NULL; setChannel(NULL);
} }
// <edit>
if(mType != LLAudioEngine::AUDIO_TYPE_UI) // && mSourceID.notNull())
logSoundStop(mLogID);
// </edit>
} }
@@ -1356,10 +1357,17 @@ void LLAudioSource::setChannel(LLAudioChannel *channelp)
return; return;
} }
// <edit>
if (!channelp)
{
if(mType != LLAudioEngine::AUDIO_TYPE_UI)
logSoundStop(mLogID, false);
}
// </edit>
mChannelp = channelp; mChannelp = channelp;
} }
void LLAudioSource::update() void LLAudioSource::update()
{ {
if (!getCurrentBuffer()) if (!getCurrentBuffer())
@@ -1434,10 +1442,6 @@ bool LLAudioSource::setupChannel()
bool LLAudioSource::play(const LLUUID &audio_uuid) bool LLAudioSource::play(const LLUUID &audio_uuid)
{ {
// <edit>
if(mType != LLAudioEngine::AUDIO_TYPE_UI) //&& mSourceID.notNull())
logSoundPlay(mLogID, this, mPositionGlobal, mType, audio_uuid, mOwnerID, mSourceID, mIsTrigger, mLoop); // is mID okay for source id?
// </edit>
// Special abuse of play(); don't play a sound, but kill it. // Special abuse of play(); don't play a sound, but kill it.
if (audio_uuid.isNull()) if (audio_uuid.isNull())
{ {
@@ -1453,6 +1457,11 @@ bool LLAudioSource::play(const LLUUID &audio_uuid)
return false; return false;
} }
// <edit>
if(mType != LLAudioEngine::AUDIO_TYPE_UI) //&& mSourceID.notNull())
logSoundPlay(this, audio_uuid);
// </edit>
// Reset our age timeout if someone attempts to play the source. // Reset our age timeout if someone attempts to play the source.
mAgeTimer.reset(); mAgeTimer.reset();
@@ -1846,36 +1855,38 @@ bool LLAudioData::load()
std::map<LLUUID, LLSoundHistoryItem> gSoundHistory; std::map<LLUUID, LLSoundHistoryItem> gSoundHistory;
// static // static
void logSoundPlay(LLUUID id, LLAudioSource* audio_source, LLVector3d position, S32 type, LLUUID assetid, LLUUID ownerid, LLUUID sourceid, bool is_trigger, bool is_looped) void logSoundPlay(LLAudioSource* audio_source, LLUUID const& assetid)
{ {
LLSoundHistoryItem item; LLSoundHistoryItem item;
item.mID = id; item.mID = audio_source->getLogID();
item.mAudioSource = audio_source; item.mAudioSource = audio_source;
item.mPosition = position; item.mPosition = audio_source->getPositionGlobal();
item.mType = type; item.mType = audio_source->getType();
item.mAssetID = assetid; item.mAssetID = assetid;
item.mOwnerID = ownerid; item.mOwnerID = audio_source->getOwnerID();
item.mSourceID = sourceid; item.mSourceID = audio_source->getSourceID();
item.mPlaying = true; item.mPlaying = true;
item.mTimeStarted = LLTimer::getElapsedSeconds(); item.mTimeStarted = LLTimer::getElapsedSeconds();
item.mTimeStopped = F64_MAX; item.mTimeStopped = F64_MAX;
item.mIsTrigger = is_trigger; item.mIsTrigger = audio_source->getIsTrigger();
item.mIsLooped = is_looped; item.mIsLooped = audio_source->isLoop();
item.mReviewed = false; item.mReviewed = false;
item.mReviewedCollision = false; item.mReviewedCollision = false;
gSoundHistory[id] = item; gSoundHistory[item.mID] = item;
} }
//static //static
void logSoundStop(LLUUID id) void logSoundStop(LLUUID const& id, bool destructed)
{ {
if(gSoundHistory.find(id) != gSoundHistory.end()) std::map<LLUUID, LLSoundHistoryItem>::iterator iter = gSoundHistory.find(id);
if(iter != gSoundHistory.end() && iter->second.mAudioSource)
{ {
gSoundHistory[id].mPlaying = false; iter->second.mPlaying = false;
gSoundHistory[id].mTimeStopped = LLTimer::getElapsedSeconds(); iter->second.mTimeStopped = LLTimer::getElapsedSeconds();
gSoundHistory[id].mAudioSource = NULL; // just in case if (destructed)
iter->second.mAudioSource = NULL;
pruneSoundLog(); pruneSoundLog();
} }
} }

View File

@@ -306,7 +306,11 @@ public:
void setPlayedOnce(const bool played_once) { mPlayedOnce = played_once; } void setPlayedOnce(const bool played_once) { mPlayedOnce = played_once; }
void setType(S32 type) { mType = type; } void setType(S32 type) { mType = type; }
S32 getType() { return mType; } S32 getType(void) const { return mType; }
LLUUID const& getOwnerID(void) const { return mOwnerID; }
LLUUID const& getSourceID(void) const { return mSourceID; }
bool getIsTrigger(void) const { return mIsTrigger; }
void setPositionGlobal(const LLVector3d &position_global) { mPositionGlobal = position_global; } void setPositionGlobal(const LLVector3d &position_global) { mPositionGlobal = position_global; }
LLVector3d getPositionGlobal() const { return mPositionGlobal; } LLVector3d getPositionGlobal() const { return mPositionGlobal; }
@@ -504,12 +508,23 @@ struct LLSoundHistoryItem
LLSoundHistoryItem() : mType(0), mPlaying(false), mIsTrigger(false), LLSoundHistoryItem() : mType(0), mPlaying(false), mIsTrigger(false),
mIsLooped(false), mReviewed(false), mReviewedCollision(false), mIsLooped(false), mReviewed(false), mReviewedCollision(false),
mTimeStarted(0), mTimeStopped(0), mAudioSource(0) {} mTimeStarted(0), mTimeStopped(0), mAudioSource(0) {}
bool isPlaying(void) const
{
return mPlaying && mAudioSource && mAudioSource->getChannel()
// It's only REALLY playing if the following also returns true,
// but it's too hard detect when that part is starting/stopping,
// so in the sound explorer we call "playing" (or "looping")
// those audio source that have a channel assigned and call
// it a day.
/*&& mAudioSource->getChannel()->isPlaying()*/ ;
}
}; };
extern std::map<LLUUID, LLSoundHistoryItem> gSoundHistory; extern std::map<LLUUID, LLSoundHistoryItem> gSoundHistory;
extern void logSoundPlay(LLUUID id, LLAudioSource* audio_source, LLVector3d position, S32 type, LLUUID assetid, LLUUID ownerid, LLUUID sourceid, bool is_trigger, bool is_looped); extern void logSoundPlay(LLAudioSource* audio_source, LLUUID const& assetid);
extern void logSoundStop(LLUUID id); extern void logSoundStop(LLUUID const& id, bool destructed);
extern void pruneSoundLog(); extern void pruneSoundLog();
extern int gSoundHistoryPruneCounter; extern int gSoundHistoryPruneCounter;

View File

@@ -110,9 +110,9 @@ class LLSoundHistoryItemCompare
public: public:
bool operator() (LLSoundHistoryItem first, LLSoundHistoryItem second) bool operator() (LLSoundHistoryItem first, LLSoundHistoryItem second)
{ {
if(first.mPlaying) if(first.isPlaying())
{ {
if(second.mPlaying) if(second.isPlaying())
{ {
return (first.mTimeStarted > second.mTimeStarted); return (first.mTimeStarted > second.mTimeStarted);
} }
@@ -121,7 +121,7 @@ public:
return true; return true;
} }
} }
else if(second.mPlaying) else if(second.isPlaying())
{ {
return false; return false;
} }
@@ -205,17 +205,12 @@ BOOL LLFloaterExploreSounds::tick()
LLSD& playing_column = element["columns"][0]; LLSD& playing_column = element["columns"][0];
playing_column["column"] = "playing"; playing_column["column"] = "playing";
if (item.mIsLooped) if(item.isPlaying())
{ {
playing_column["value"] = " Looping"; playing_column["value"] = item.mIsLooped ? " Looping" : " Playing";
}
else if(item.mPlaying)
{
playing_column["value"] = " Playing";
} }
else else
{ {
S32 time = (LLTimer::getElapsedSeconds() - item.mTimeStopped); S32 time = (LLTimer::getElapsedSeconds() - item.mTimeStopped);
S32 hours = time / 3600; S32 hours = time / 3600;
S32 mins = time / 60; S32 mins = time / 60;
@@ -358,23 +353,15 @@ void LLFloaterExploreSounds::handle_stop(void* user_data)
{ {
LLSoundHistoryItem item = floater->getItem((*selection_iter)->getValue()); LLSoundHistoryItem item = floater->getItem((*selection_iter)->getValue());
if(item.mID.isNull()) continue; if(item.mID.isNull()) continue;
if(item.mPlaying) if(item.isPlaying())
{ {
if(item.mAudioSource) item.mAudioSource->play(LLUUID::null);
{
S32 type = item.mType;
item.mAudioSource->setType(LLAudioEngine::AUDIO_TYPE_UI);
if(item.mAudioSource)
item.mAudioSource->play(LLUUID::null);
if(item.mAudioSource)
item.mAudioSource->setType(type);
}
} }
} }
} }
void LLFloaterExploreSounds::blacklistSound(void* user_data) void LLFloaterExploreSounds::blacklistSound(void* user_data)
{ {
LLFloaterBlacklist::show(); LLFloaterBlacklist::show();
LLFloaterExploreSounds* floater = (LLFloaterExploreSounds*)user_data; LLFloaterExploreSounds* floater = (LLFloaterExploreSounds*)user_data;
LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("sound_list"); LLScrollListCtrl* list = floater->getChild<LLScrollListCtrl>("sound_list");