Massive commit, beefed up the audio crash prevention, made a blacklist for assets, added sound explorer, fixed import, added item button to vfs explorer.

JELLY ROLL
This commit is contained in:
phr0z3nt04st
2010-07-08 00:20:37 -05:00
parent 30f5ce7491
commit 82aef8fa4c
27 changed files with 1232 additions and 61 deletions

View File

@@ -226,7 +226,7 @@ BOOL LLVorbisDecodeState::initDecode()
size_guess += 2048;
bool abort_decode = false;
// <edit>
// This magic value is equivilent to 150MiB of data.
// Prevents griffers from utilizin a huge xbox sound the size of god to instafry the viewer
if(size_guess >= 157286400)
@@ -235,7 +235,7 @@ BOOL LLVorbisDecodeState::initDecode()
abort_decode = true;
}
else if( vi->channels < 1 || vi->channels > LLVORBIS_CLIP_MAX_CHANNELS )
else /* </edit> */if( vi->channels < 1 || vi->channels > LLVORBIS_CLIP_MAX_CHANNELS )
{
abort_decode = true;
llwarns << "Bad channel count: " << vi->channels << llendl;
@@ -251,8 +251,25 @@ BOOL LLVorbisDecodeState::initDecode()
return FALSE;
}
mWAVBuffer.reserve(size_guess);
mWAVBuffer.resize(WAV_HEADER_SIZE);
// <edit>
try
{
// </edit>
mWAVBuffer.reserve(size_guess);
mWAVBuffer.resize(WAV_HEADER_SIZE);
// <edit>
}
catch(std::bad_alloc)
{
llwarns << "bad_alloc" << llendl;
if(mInFilep)
{
delete mInFilep;
mInFilep = NULL;
}
return FALSE;
}
// </edit>
{
// write the .wav format header
@@ -425,7 +442,10 @@ BOOL LLVorbisDecodeState::finishDecode()
char pcmout[4096]; /*Flawfinder: ignore*/
fade_length = llmin((S32)128,(S32)(data_length-36)/8);
if((S32)mWAVBuffer.size() >= (WAV_HEADER_SIZE + 2* fade_length))
// <edit>
//if((S32)mWAVBuffer.size() >= (WAV_HEADER_SIZE + 2* fade_length))
if((S32)mWAVBuffer.size() > (WAV_HEADER_SIZE + 2* fade_length))
// </edit>
{
memcpy(pcmout, &mWAVBuffer[WAV_HEADER_SIZE], (2 * fade_length)); /*Flawfinder: ignore*/
}
@@ -444,7 +464,10 @@ BOOL LLVorbisDecodeState::finishDecode()
memcpy(&mWAVBuffer[WAV_HEADER_SIZE], pcmout, (2 * fade_length)); /*Flawfinder: ignore*/
}
S32 near_end = mWAVBuffer.size() - (2 * fade_length);
if ((S32)mWAVBuffer.size() >= ( near_end + 2* fade_length))
// <edit>
//if ((S32)mWAVBuffer.size() >= ( near_end + 2* fade_length))
if ((S32)mWAVBuffer.size() > ( near_end + 2* fade_length))
// </edit>
{
memcpy(pcmout, &mWAVBuffer[near_end], (2 * fade_length)); /*Flawfinder: ignore*/
}
@@ -543,13 +566,18 @@ void LLAudioDecodeMgr::Impl::processQueue(const F32 num_secs)
{
if (mCurrentDecodep)
{
BOOL res;
// <edit> rawrning
//BOOL res;
BOOL res = false;
// </edit>
// Decode in a loop until we're done or have run out of time.
while(!(res = mCurrentDecodep->decodeSection()) && (decode_timer.getElapsedTimeF32() < num_secs))
{
// decodeSection does all of the work above
}
/* <edit> */ try{ /* </edit> */
while(!(res = mCurrentDecodep->decodeSection()) && (decode_timer.getElapsedTimeF32() < num_secs))
{
// decodeSection does all of the work above
}
/* <edit> */ }catch(std::bad_alloc){llerrs<<"bad_alloc whilst decoding"<<llendl;} /* </edit> */
if (mCurrentDecodep->isDone() && !mCurrentDecodep->isValid())
{

View File

@@ -814,7 +814,10 @@ F64 LLAudioEngine::mapWindVecToPan(LLVector3 wind_vec)
void LLAudioEngine::triggerSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain,
const S32 type, const LLVector3d &pos_global)
// <edit>
//const S32 type, const LLVector3d &pos_global)
const S32 type, const LLVector3d &pos_global, const LLUUID source_object)
// </edit>
{
// Create a new source (since this can't be associated with an existing source.
//llinfos << "Localized: " << audio_uuid << llendl;
@@ -827,7 +830,10 @@ void LLAudioEngine::triggerSound(const LLUUID &audio_uuid, const LLUUID& owner_i
LLUUID source_id;
source_id.generate();
LLAudioSource *asp = new LLAudioSource(source_id, owner_id, gain, type);
// <edit>
//LLAudioSource *asp = new LLAudioSource(source_id, owner_id, gain, type);
LLAudioSource *asp = new LLAudioSource(source_id, owner_id, gain, type, source_object, true);
// </edit>
gAudiop->addAudioSource(asp);
if (pos_global.isExactlyZero())
{
@@ -1254,7 +1260,10 @@ void LLAudioEngine::assetCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::E
//
LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32 gain, const S32 type)
// <edit>
//LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32 gain, const S32 type)
LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32 gain, const S32 type, const LLUUID source_id, const bool isTrigger)
// </edit>
: mID(id),
mOwnerID(owner_id),
mPriority(0.f),
@@ -1267,10 +1276,17 @@ LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32
mQueueSounds(false),
mPlayedOnce(false),
mType(type),
// <edit>
mSourceID(source_id),
mIsTrigger(isTrigger),
// </edit>
mChannelp(NULL),
mCurrentDatap(NULL),
mQueuedDatap(NULL)
{
// <edit>
mLogID.generate();
// </edit>
}
@@ -1282,6 +1298,10 @@ LLAudioSource::~LLAudioSource()
mChannelp->setSource(NULL);
mChannelp = NULL;
}
// <edit>
if(mType != LLAudioEngine::AUDIO_TYPE_UI) // && mSourceID.notNull())
logSoundStop(mLogID);
// </edit>
}
@@ -1370,6 +1390,10 @@ bool LLAudioSource::setupChannel()
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.
if (audio_uuid.isNull())
{
@@ -1770,4 +1794,65 @@ bool LLAudioData::load()
return true;
}
// <edit>
std::map<LLUUID, LLSoundHistoryItem> gSoundHistory;
// static
void logSoundPlay(LLUUID id, LLAudioSource* audio_source, LLVector3d position, S32 type, LLUUID assetid, LLUUID ownerid, LLUUID sourceid, bool is_trigger, bool is_looped)
{
LLSoundHistoryItem item;
item.mID = id;
item.mAudioSource = audio_source;
item.mPosition = position;
item.mType = type;
item.mAssetID = assetid;
item.mOwnerID = ownerid;
item.mSourceID = sourceid;
item.mPlaying = true;
item.mTimeStarted = LLTimer::getElapsedSeconds();
item.mTimeStopped = F64_MAX;
item.mIsTrigger = is_trigger;
item.mIsLooped = is_looped;
item.mReviewed = false;
item.mReviewedCollision = false;
gSoundHistory[id] = item;
}
static void logSoundStop(LLUUID id)
{
if(gSoundHistory.find(id) != gSoundHistory.end())
{
gSoundHistory[id].mPlaying = false;
gSoundHistory[id].mTimeStopped = LLTimer::getElapsedSeconds();
gSoundHistory[id].mAudioSource = NULL; // just in case
pruneSoundLog();
}
}
static void pruneSoundLog()
{
if(++gSoundHistoryPruneCounter >= 64)
{
gSoundHistoryPruneCounter = 0;
while(gSoundHistory.size() > 256)
{
std::map<LLUUID, LLSoundHistoryItem>::iterator iter = gSoundHistory.begin();
std::map<LLUUID, LLSoundHistoryItem>::iterator end = gSoundHistory.end();
U64 lowest_time = (*iter).second.mTimeStopped;
LLUUID lowest_id = (*iter).first;
for( ; iter != end; ++iter)
{
if((*iter).second.mTimeStopped < lowest_time)
{
lowest_time = (*iter).second.mTimeStopped;
lowest_id = (*iter).first;
}
}
gSoundHistory.erase(lowest_id);
}
}
}
// </edit>

View File

@@ -139,7 +139,11 @@ public:
// Owner ID is the owner of the object making the request
void triggerSound(const LLUUID &sound_id, const LLUUID& owner_id, const F32 gain,
const S32 type = LLAudioEngine::AUDIO_TYPE_NONE,
const LLVector3d &pos_global = LLVector3d::zero);
// <edit>
//const LLVector3d &pos_global = LLVector3d::zero);
const LLVector3d &pos_global = LLVector3d::zero,
const LLUUID source_object = LLUUID::null);
// </edit>
bool preloadSound(const LLUUID &id);
void addAudioSource(LLAudioSource *asp);
@@ -261,7 +265,10 @@ class LLAudioSource
public:
// owner_id is the id of the agent responsible for making this sound
// play, for example, the owner of the object currently playing it
LLAudioSource(const LLUUID &id, const LLUUID& owner_id, const F32 gain, const S32 type = LLAudioEngine::AUDIO_TYPE_NONE);
// <edit>
//LLAudioSource(const LLUUID &id, const LLUUID& owner_id, const F32 gain, const S32 type = LLAudioEngine::AUDIO_TYPE_NONE);
LLAudioSource(const LLUUID &id, const LLUUID& owner_id, const F32 gain, const S32 type = LLAudioEngine::AUDIO_TYPE_NONE, const LLUUID source_id = LLUUID::null, const bool isTrigger = true);
// </edit>
virtual ~LLAudioSource();
virtual void update(); // Update this audio source
@@ -301,6 +308,9 @@ public:
virtual void setGain(const F32 gain) { mGain = llclamp(gain, 0.f, 1.f); }
const LLUUID &getID() const { return mID; }
// <edit>
const LLUUID &getLogID() const { return mLogID; }
// </edit>
bool isDone() const;
bool isMuted() const { return mSourceMuted; }
@@ -334,6 +344,11 @@ protected:
S32 mType;
LLVector3d mPositionGlobal;
LLVector3 mVelocity;
// <edit>
LLUUID mLogID;
LLUUID mSourceID;
bool mIsTrigger;
// </edit>
//LLAudioSource *mSyncMasterp; // If we're a slave, the source that we're synced to.
LLAudioChannel *mChannelp; // If we're currently playing back, this is the channel that we're assigned to.
@@ -452,4 +467,32 @@ protected:
extern LLAudioEngine* gAudiop;
// <edit>
typedef struct
{
LLUUID mID;
LLVector3d mPosition;
S32 mType;
bool mPlaying;
LLUUID mAssetID;
LLUUID mOwnerID;
LLUUID mSourceID;
bool mIsTrigger;
bool mIsLooped;
F64 mTimeStarted;
F64 mTimeStopped;
bool mReviewed;
bool mReviewedCollision;
LLAudioSource* mAudioSource;
} LLSoundHistoryItem;
extern std::map<LLUUID, LLSoundHistoryItem> gSoundHistory;
static void logSoundPlay(LLUUID id, LLAudioSource* audio_source, LLVector3d position, S32 type, LLUUID assetid, LLUUID ownerid, LLUUID sourceid, bool is_trigger, bool is_looped);
static void logSoundStop(LLUUID id);
static void pruneSoundLog();
static int gSoundHistoryPruneCounter;
// </edit>
#endif