aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llaudio/audioengine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llaudio/audioengine.cpp')
-rw-r--r--linden/indra/llaudio/audioengine.cpp323
1 files changed, 228 insertions, 95 deletions
diff --git a/linden/indra/llaudio/audioengine.cpp b/linden/indra/llaudio/audioengine.cpp
index 5dd5b28..0a450e9 100644
--- a/linden/indra/llaudio/audioengine.cpp
+++ b/linden/indra/llaudio/audioengine.cpp
@@ -44,14 +44,13 @@
44#include "llaudiodecodemgr.h" 44#include "llaudiodecodemgr.h"
45#include "llassetstorage.h" 45#include "llassetstorage.h"
46 46
47#include "llmediamanager.h"
48
47// necessary for grabbing sounds from sim (implemented in viewer) 49// necessary for grabbing sounds from sim (implemented in viewer)
48extern void request_sound(const LLUUID &sound_guid); 50extern void request_sound(const LLUUID &sound_guid);
49 51
50LLAudioEngine* gAudiop = NULL; 52LLAudioEngine* gAudiop = NULL;
51 53
52// Maximum amount of time we wait for a transfer to complete before starting
53// off another one.
54const F32 MAX_CURRENT_TRANSFER_TIME = 60.f;
55 54
56// 55//
57// LLAudioEngine implementation 56// LLAudioEngine implementation
@@ -75,13 +74,13 @@ void LLAudioEngine::setDefaults()
75 74
76 mListenerp = NULL; 75 mListenerp = NULL;
77 76
78 mMuted = FALSE; 77 mMuted = false;
79 mUserData = NULL; 78 mUserData = NULL;
80 79
81 mLastStatus = 0; 80 mLastStatus = 0;
82 81
83 mNumChannels = 0; 82 mNumChannels = 0;
84 mEnableWind = FALSE; 83 mEnableWind = false;
85 84
86 S32 i; 85 S32 i;
87 for (i = 0; i < MAX_CHANNELS; i++) 86 for (i = 0; i < MAX_CHANNELS; i++)
@@ -91,15 +90,18 @@ void LLAudioEngine::setDefaults()
91 for (i = 0; i < MAX_BUFFERS; i++) 90 for (i = 0; i < MAX_BUFFERS; i++)
92 { 91 {
93 mBuffers[i] = NULL; 92 mBuffers[i] = NULL;
94 } 93 }
95 94
96 mMasterGain = 1.f; 95 mMasterGain = 1.f;
97 mInternetStreamGain = 0.125f; 96 mInternetStreamGain = 0.125f;
98 mNextWindUpdate = 0.f; 97 mNextWindUpdate = 0.f;
98
99 mInternetStreamMedia = NULL;
100 mInternetStreamURL.clear();
99} 101}
100 102
101 103
102BOOL LLAudioEngine::init(const S32 num_channels, void* userdata) 104bool LLAudioEngine::init(const S32 num_channels, void* userdata)
103{ 105{
104 setDefaults(); 106 setDefaults();
105 107
@@ -111,7 +113,9 @@ BOOL LLAudioEngine::init(const S32 num_channels, void* userdata)
111 // Initialize the decode manager 113 // Initialize the decode manager
112 gAudioDecodeMgrp = new LLAudioDecodeMgr; 114 gAudioDecodeMgrp = new LLAudioDecodeMgr;
113 115
114 return TRUE; 116 llinfos << "LLAudioEngine::init() AudioEngine successfully initialized" << llendl;
117
118 return true;
115} 119}
116 120
117 121
@@ -141,22 +145,146 @@ void LLAudioEngine::shutdown()
141 S32 i; 145 S32 i;
142 for (i = 0; i < MAX_CHANNELS; i++) 146 for (i = 0; i < MAX_CHANNELS; i++)
143 { 147 {
144 if (mChannels[i]) 148 delete mChannels[i];
145 { 149 mChannels[i] = NULL;
146 delete mChannels[i];
147 mChannels[i] = NULL;
148 }
149 } 150 }
150 151
151 // Clean up buffers 152 // Clean up buffers
152 for (i = 0; i < MAX_BUFFERS; i++) 153 for (i = 0; i < MAX_BUFFERS; i++)
153 { 154 {
154 if (mBuffers[i]) 155 delete mBuffers[i];
156 mBuffers[i] = NULL;
157 }
158
159 delete mInternetStreamMedia;
160 mInternetStreamMedia = NULL;
161 mInternetStreamURL.clear();
162}
163
164
165// virtual
166void LLAudioEngine::startInternetStream(const std::string& url)
167{
168 llinfos << "entered startInternetStream()" << llendl;
169
170 if (!mInternetStreamMedia)
171 {
172 LLMediaManager* mgr = LLMediaManager::getInstance();
173 if (mgr)
155 { 174 {
156 delete mBuffers[i]; 175 mInternetStreamMedia = mgr->createSourceFromMimeType(LLURI(url).scheme(), "audio/mpeg"); // assumes that whatever media implementation supports mp3 also supports vorbis.
157 mBuffers[i] = NULL; 176 llinfos << "mInternetStreamMedia is now " << mInternetStreamMedia << llendl;
177 }
178 }
179
180 if(!mInternetStreamMedia)
181 return;
182
183 if (!url.empty()) {
184 llinfos << "Starting internet stream: " << url << llendl;
185 mInternetStreamURL = url;
186 mInternetStreamMedia->navigateTo ( url );
187 llinfos << "Playing....." << llendl;
188 mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START);
189 mInternetStreamMedia->updateMedia();
190 } else {
191 llinfos << "setting stream to NULL"<< llendl;
192 mInternetStreamURL.clear();
193 mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP);
194 mInternetStreamMedia->updateMedia();
195 }
196 //#endif
197}
198
199// virtual
200void LLAudioEngine::stopInternetStream()
201{
202 llinfos << "entered stopInternetStream()" << llendl;
203
204 if(mInternetStreamMedia)
205 {
206 if( ! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_STOP)){
207 llinfos << "attempting to stop stream failed!" << llendl;
158 } 208 }
209 mInternetStreamMedia->updateMedia();
159 } 210 }
211
212 mInternetStreamURL.clear();
213}
214
215// virtual
216void LLAudioEngine::pauseInternetStream(int pause)
217{
218 llinfos << "entered pauseInternetStream()" << llendl;
219
220 if(!mInternetStreamMedia)
221 return;
222
223 if(pause)
224 {
225 if(! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_PAUSE))
226 {
227 llinfos << "attempting to pause stream failed!" << llendl;
228 }
229 } else {
230 if(! mInternetStreamMedia->addCommand(LLMediaBase::COMMAND_START))
231 {
232 llinfos << "attempting to unpause stream failed!" << llendl;
233 }
234 }
235 mInternetStreamMedia->updateMedia();
236}
237
238// virtual
239void LLAudioEngine::updateInternetStream()
240{
241 if (mInternetStreamMedia)
242 mInternetStreamMedia->updateMedia();
243}
244
245// virtual
246int LLAudioEngine::isInternetStreamPlaying()
247{
248 if (!mInternetStreamMedia)
249 return 0;
250
251 if (mInternetStreamMedia->getStatus() == LLMediaBase::STATUS_STARTED)
252 {
253 return 1; // Active and playing
254 }
255
256 if (mInternetStreamMedia->getStatus() == LLMediaBase::STATUS_PAUSED)
257 {
258 return 2; // paused
259 }
260
261 return 0; // Stopped
262}
263
264// virtual
265void LLAudioEngine::getInternetStreamInfo(char* artist, char* title)
266{
267 artist[0] = 0;
268 title[0] = 0;
269}
270
271// virtual
272void LLAudioEngine::setInternetStreamGain(F32 vol)
273{
274 mInternetStreamGain = vol;
275
276 if(!mInternetStreamMedia)
277 return;
278
279 vol = llclamp(vol, 0.f, 1.f);
280 mInternetStreamMedia->setVolume(vol);
281 mInternetStreamMedia->updateMedia();
282}
283
284// virtual
285const std::string& LLAudioEngine::getInternetStreamURL()
286{
287 return mInternetStreamURL;
160} 288}
161 289
162 290
@@ -200,7 +328,7 @@ void LLAudioEngine::idle(F32 max_decode_time)
200 { 328 {
201 if (mBuffers[i]) 329 if (mBuffers[i])
202 { 330 {
203 mBuffers[i]->mInUse = FALSE; 331 mBuffers[i]->mInUse = false;
204 } 332 }
205 } 333 }
206 334
@@ -252,11 +380,11 @@ void LLAudioEngine::idle(F32 max_decode_time)
252 { 380 {
253 // A sync slave, it doesn't start playing until it's synced up with the master. 381 // A sync slave, it doesn't start playing until it's synced up with the master.
254 // Flag this channel as waiting for sync, and return true. 382 // Flag this channel as waiting for sync, and return true.
255 channelp->setWaiting(TRUE); 383 channelp->setWaiting(true);
256 } 384 }
257 else 385 else
258 { 386 {
259 channelp->setWaiting(FALSE); 387 channelp->setWaiting(false);
260 channelp->play(); 388 channelp->play();
261 } 389 }
262 } 390 }
@@ -396,7 +524,7 @@ void LLAudioEngine::idle(F32 max_decode_time)
396 if (sync_masterp->getChannel()) 524 if (sync_masterp->getChannel())
397 { 525 {
398 channelp->playSynced(master_channelp); 526 channelp->playSynced(master_channelp);
399 channelp->setWaiting(FALSE); 527 channelp->setWaiting(false);
400 } 528 }
401 } 529 }
402 } 530 }
@@ -426,7 +554,7 @@ void LLAudioEngine::idle(F32 max_decode_time)
426 { 554 {
427 if (mChannels[i]) 555 if (mChannels[i])
428 { 556 {
429 mChannels[i]->mLoopedThisFrame = FALSE; 557 mChannels[i]->mLoopedThisFrame = false;
430 } 558 }
431 } 559 }
432 560
@@ -437,13 +565,17 @@ void LLAudioEngine::idle(F32 max_decode_time)
437 // missed picking it up in all the places that can add 565 // missed picking it up in all the places that can add
438 // or request new data. 566 // or request new data.
439 startNextTransfer(); 567 startNextTransfer();
568
569 updateInternetStream();
440} 570}
441 571
442BOOL LLAudioEngine::updateBufferForData(LLAudioData *adp, const LLUUID &audio_uuid) 572
573
574bool LLAudioEngine::updateBufferForData(LLAudioData *adp, const LLUUID &audio_uuid)
443{ 575{
444 if (!adp) 576 if (!adp)
445 { 577 {
446 return FALSE; 578 return false;
447 } 579 }
448 580
449 // Update the audio buffer first - load a sound if we have it. 581 // Update the audio buffer first - load a sound if we have it.
@@ -466,14 +598,14 @@ BOOL LLAudioEngine::updateBufferForData(LLAudioData *adp, const LLUUID &audio_uu
466 } 598 }
467 else 599 else
468 { 600 {
469 return FALSE; 601 return false;
470 } 602 }
471 } 603 }
472 return TRUE; 604 return true;
473} 605}
474 606
475 607
476void LLAudioEngine::enableWind(BOOL enable) 608void LLAudioEngine::enableWind(bool enable)
477{ 609{
478 if (enable && (!mEnableWind)) 610 if (enable && (!mEnableWind))
479 { 611 {
@@ -601,7 +733,7 @@ void LLAudioEngine::cleanupBuffer(LLAudioBuffer *bufferp)
601} 733}
602 734
603 735
604BOOL LLAudioEngine::preloadSound(const LLUUID &uuid) 736bool LLAudioEngine::preloadSound(const LLUUID &uuid)
605{ 737{
606 gAudiop->getAudioData(uuid); // We don't care about the return value, this is just to make sure 738 gAudiop->getAudioData(uuid); // We don't care about the return value, this is just to make sure
607 // that we have an entry, which will mean that the audio engine knows about this 739 // that we have an entry, which will mean that the audio engine knows about this
@@ -609,23 +741,23 @@ BOOL LLAudioEngine::preloadSound(const LLUUID &uuid)
609 if (gAudioDecodeMgrp->addDecodeRequest(uuid)) 741 if (gAudioDecodeMgrp->addDecodeRequest(uuid))
610 { 742 {
611 // This means that we do have a local copy, and we're working on decoding it. 743 // This means that we do have a local copy, and we're working on decoding it.
612 return TRUE; 744 return true;
613 } 745 }
614 746
615 // At some point we need to have the audio/asset system check the static VFS 747 // At some point we need to have the audio/asset system check the static VFS
616 // before it goes off and fetches stuff from the server. 748 // before it goes off and fetches stuff from the server.
617 //llwarns << "Used internal preload for non-local sound" << llendl; 749 //llwarns << "Used internal preload for non-local sound" << llendl;
618 return FALSE; 750 return false;
619} 751}
620 752
621 753
622BOOL LLAudioEngine::isWindEnabled() 754bool LLAudioEngine::isWindEnabled()
623{ 755{
624 return mEnableWind; 756 return mEnableWind;
625} 757}
626 758
627 759
628void LLAudioEngine::setMuted(BOOL muted) 760void LLAudioEngine::setMuted(bool muted)
629{ 761{
630 mMuted = muted; 762 mMuted = muted;
631 enableWind(!mMuted); 763 enableWind(!mMuted);
@@ -735,7 +867,7 @@ void LLAudioEngine::triggerSound(const LLUUID &audio_uuid, const LLUUID& owner_i
735 gAudiop->addAudioSource(asp); 867 gAudiop->addAudioSource(asp);
736 if (pos_global.isExactlyZero()) 868 if (pos_global.isExactlyZero())
737 { 869 {
738 asp->setAmbient(TRUE); 870 asp->setAmbient(true);
739 } 871 }
740 else 872 else
741 { 873 {
@@ -914,7 +1046,7 @@ void LLAudioEngine::cleanupAudioSource(LLAudioSource *asp)
914} 1046}
915 1047
916 1048
917BOOL LLAudioEngine::hasDecodedFile(const LLUUID &uuid) 1049bool LLAudioEngine::hasDecodedFile(const LLUUID &uuid)
918{ 1050{
919 std::string uuid_str; 1051 std::string uuid_str;
920 uuid.toString(uuid_str); 1052 uuid.toString(uuid_str);
@@ -925,16 +1057,16 @@ BOOL LLAudioEngine::hasDecodedFile(const LLUUID &uuid)
925 1057
926 if (gDirUtilp->fileExists(wav_path)) 1058 if (gDirUtilp->fileExists(wav_path))
927 { 1059 {
928 return TRUE; 1060 return true;
929 } 1061 }
930 else 1062 else
931 { 1063 {
932 return FALSE; 1064 return false;
933 } 1065 }
934} 1066}
935 1067
936 1068
937BOOL LLAudioEngine::hasLocalFile(const LLUUID &uuid) 1069bool LLAudioEngine::hasLocalFile(const LLUUID &uuid)
938{ 1070{
939 // See if it's in the VFS. 1071 // See if it's in the VFS.
940 return gVFS->getExists(uuid, LLAssetType::AT_SOUND); 1072 return gVFS->getExists(uuid, LLAssetType::AT_SOUND);
@@ -1150,9 +1282,9 @@ void LLAudioEngine::assetCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::E
1150 LLAudioData *adp = gAudiop->getAudioData(uuid); 1282 LLAudioData *adp = gAudiop->getAudioData(uuid);
1151 if (adp) 1283 if (adp)
1152 { 1284 {
1153 adp->setHasValidData(FALSE); 1285 adp->setHasValidData(false);
1154 adp->setHasLocalData(FALSE); 1286 adp->setHasLocalData(false);
1155 adp->setHasDecodedData(FALSE); 1287 adp->setHasDecodedData(false);
1156 } 1288 }
1157 } 1289 }
1158 else 1290 else
@@ -1165,8 +1297,8 @@ void LLAudioEngine::assetCallback(LLVFS *vfs, const LLUUID &uuid, LLAssetType::E
1165 } 1297 }
1166 else 1298 else
1167 { 1299 {
1168 adp->setHasValidData(TRUE); 1300 adp->setHasValidData(true);
1169 adp->setHasLocalData(TRUE); 1301 adp->setHasLocalData(true);
1170 gAudioDecodeMgrp->addDecodeRequest(uuid); 1302 gAudioDecodeMgrp->addDecodeRequest(uuid);
1171 } 1303 }
1172 } 1304 }
@@ -1185,12 +1317,12 @@ LLAudioSource::LLAudioSource(const LLUUID& id, const LLUUID& owner_id, const F32
1185 mOwnerID(owner_id), 1317 mOwnerID(owner_id),
1186 mPriority(0.f), 1318 mPriority(0.f),
1187 mGain(gain), 1319 mGain(gain),
1188 mAmbient(FALSE), 1320 mAmbient(false),
1189 mLoop(FALSE), 1321 mLoop(false),
1190 mSyncMaster(FALSE), 1322 mSyncMaster(false),
1191 mSyncSlave(FALSE), 1323 mSyncSlave(false),
1192 mQueueSounds(FALSE), 1324 mQueueSounds(false),
1193 mPlayedOnce(FALSE), 1325 mPlayedOnce(false),
1194 mChannelp(NULL), 1326 mChannelp(NULL),
1195 mCurrentDatap(NULL), 1327 mCurrentDatap(NULL),
1196 mQueuedDatap(NULL) 1328 mQueuedDatap(NULL)
@@ -1254,7 +1386,7 @@ void LLAudioSource::updatePriority()
1254 } 1386 }
1255} 1387}
1256 1388
1257BOOL LLAudioSource::setupChannel() 1389bool LLAudioSource::setupChannel()
1258{ 1390{
1259 LLAudioData *adp = getCurrentData(); 1391 LLAudioData *adp = getCurrentData();
1260 1392
@@ -1262,7 +1394,7 @@ BOOL LLAudioSource::setupChannel()
1262 { 1394 {
1263 // We're not ready to play back the sound yet, so don't try and allocate a channel for it. 1395 // We're not ready to play back the sound yet, so don't try and allocate a channel for it.
1264 //llwarns << "Aborting, no buffer" << llendl; 1396 //llwarns << "Aborting, no buffer" << llendl;
1265 return FALSE; 1397 return false;
1266 } 1398 }
1267 1399
1268 1400
@@ -1280,15 +1412,15 @@ BOOL LLAudioSource::setupChannel()
1280 // Now we have to reprioritize. 1412 // Now we have to reprioritize.
1281 // For now, just don't play the sound. 1413 // For now, just don't play the sound.
1282 //llwarns << "Aborting, no free channels" << llendl; 1414 //llwarns << "Aborting, no free channels" << llendl;
1283 return FALSE; 1415 return false;
1284 } 1416 }
1285 1417
1286 mChannelp->setSource(this); 1418 mChannelp->setSource(this);
1287 return TRUE; 1419 return true;
1288} 1420}
1289 1421
1290 1422
1291BOOL LLAudioSource::play(const LLUUID &audio_uuid) 1423bool LLAudioSource::play(const LLUUID &audio_uuid)
1292{ 1424{
1293 if (audio_uuid.isNull()) 1425 if (audio_uuid.isNull())
1294 { 1426 {
@@ -1296,7 +1428,7 @@ BOOL LLAudioSource::play(const LLUUID &audio_uuid)
1296 { 1428 {
1297 getChannel()->setSource(NULL); 1429 getChannel()->setSource(NULL);
1298 setChannel(NULL); 1430 setChannel(NULL);
1299 addAudioData(NULL, TRUE); 1431 addAudioData(NULL, true);
1300 } 1432 }
1301 } 1433 }
1302 // Reset our age timeout if someone attempts to play the source. 1434 // Reset our age timeout if someone attempts to play the source.
@@ -1304,7 +1436,7 @@ BOOL LLAudioSource::play(const LLUUID &audio_uuid)
1304 1436
1305 LLAudioData *adp = gAudiop->getAudioData(audio_uuid); 1437 LLAudioData *adp = gAudiop->getAudioData(audio_uuid);
1306 1438
1307 BOOL has_buffer = gAudiop->updateBufferForData(adp, audio_uuid); 1439 bool has_buffer = gAudiop->updateBufferForData(adp, audio_uuid);
1308 1440
1309 1441
1310 addAudioData(adp); 1442 addAudioData(adp);
@@ -1312,47 +1444,48 @@ BOOL LLAudioSource::play(const LLUUID &audio_uuid)
1312 if (!has_buffer) 1444 if (!has_buffer)
1313 { 1445 {
1314 // Don't bother trying to set up a channel or anything, we don't have an audio buffer. 1446 // Don't bother trying to set up a channel or anything, we don't have an audio buffer.
1315 return FALSE; 1447 return false;
1316 } 1448 }
1317 1449
1318 if (!setupChannel()) 1450 if (!setupChannel())
1319 { 1451 {
1320 return FALSE; 1452 return false;
1321 } 1453 }
1322 1454
1323 if (isSyncSlave()) 1455 if (isSyncSlave())
1324 { 1456 {
1325 // A sync slave, it doesn't start playing until it's synced up with the master. 1457 // A sync slave, it doesn't start playing until it's synced up with the master.
1326 // Flag this channel as waiting for sync, and return true. 1458 // Flag this channel as waiting for sync, and return true.
1327 getChannel()->setWaiting(TRUE); 1459 getChannel()->setWaiting(true);
1328 return TRUE; 1460 return true;
1329 } 1461 }
1330 1462
1331 getChannel()->play(); 1463 getChannel()->play();
1332 return TRUE; 1464 return true;
1333} 1465}
1334 1466
1335 1467
1336BOOL LLAudioSource::isDone() 1468bool LLAudioSource::isDone()
1337{ 1469{
1338 const F32 MAX_AGE = 60.f; 1470 const F32 MAX_AGE = 60.f;
1339 const F32 MAX_UNPLAYED_AGE = 15.f; 1471 const F32 MAX_UNPLAYED_AGE = 15.f;
1472
1340 if (isLoop()) 1473 if (isLoop())
1341 { 1474 {
1342 // Looped sources never die on their own. 1475 // Looped sources never die on their own.
1343 return FALSE; 1476 return false;
1344 } 1477 }
1345 1478
1346 1479
1347 if (hasPendingPreloads()) 1480 if (hasPendingPreloads())
1348 { 1481 {
1349 return FALSE; 1482 return false;
1350 } 1483 }
1351 1484
1352 if (mQueuedDatap) 1485 if (mQueuedDatap)
1353 { 1486 {
1354 // Don't kill this sound if we've got something queued up to play. 1487 // Don't kill this sound if we've got something queued up to play.
1355 return FALSE; 1488 return false;
1356 } 1489 }
1357 1490
1358 F32 elapsed = mAgeTimer.getElapsedTimeF32(); 1491 F32 elapsed = mAgeTimer.getElapsedTimeF32();
@@ -1365,11 +1498,11 @@ BOOL LLAudioSource::isDone()
1365 // We don't have a channel assigned, and it's been 1498 // We don't have a channel assigned, and it's been
1366 // over 5 seconds since we tried to play it. Don't bother. 1499 // over 5 seconds since we tried to play it. Don't bother.
1367 //llinfos << "No channel assigned, source is done" << llendl; 1500 //llinfos << "No channel assigned, source is done" << llendl;
1368 return TRUE; 1501 return true;
1369 } 1502 }
1370 else 1503 else
1371 { 1504 {
1372 return FALSE; 1505 return false;
1373 } 1506 }
1374 } 1507 }
1375 1508
@@ -1377,27 +1510,27 @@ BOOL LLAudioSource::isDone()
1377 { 1510 {
1378 if (elapsed > MAX_AGE) 1511 if (elapsed > MAX_AGE)
1379 { 1512 {
1380 // Arbitarily cut off non-looped sounds when they're 20 seconds old. 1513 // Arbitarily cut off non-looped sounds when they're old.
1381 return TRUE; 1514 return true;
1382 } 1515 }
1383 else 1516 else
1384 { 1517 {
1385 // Sound is still playing and we haven't timed out, don't kill it. 1518 // Sound is still playing and we haven't timed out, don't kill it.
1386 return FALSE; 1519 return false;
1387 } 1520 }
1388 } 1521 }
1389 1522
1390 if ((elapsed > MAX_UNPLAYED_AGE) || mPlayedOnce) 1523 if ((elapsed > MAX_UNPLAYED_AGE) || mPlayedOnce)
1391 { 1524 {
1392 // The sound isn't playing back after 5 seconds or we're already done playing it, kill it. 1525 // The sound isn't playing back after 5 seconds or we're already done playing it, kill it.
1393 return TRUE; 1526 return true;
1394 } 1527 }
1395 1528
1396 return FALSE; 1529 return false;
1397} 1530}
1398 1531
1399 1532
1400void LLAudioSource::addAudioData(LLAudioData *adp, const BOOL set_current) 1533void LLAudioSource::addAudioData(LLAudioData *adp, const bool set_current)
1401{ 1534{
1402 // Only handle a single piece of audio data associated with a source right now, 1535 // Only handle a single piece of audio data associated with a source right now,
1403 // until I implement prefetch. 1536 // until I implement prefetch.
@@ -1465,7 +1598,7 @@ void LLAudioSource::addAudioData(LLAudioData *adp, const BOOL set_current)
1465} 1598}
1466 1599
1467 1600
1468BOOL LLAudioSource::hasPendingPreloads() const 1601bool LLAudioSource::hasPendingPreloads() const
1469{ 1602{
1470 // Check to see if we've got any preloads on deck for this source 1603 // Check to see if we've got any preloads on deck for this source
1471 data_map::const_iterator iter; 1604 data_map::const_iterator iter;
@@ -1475,11 +1608,11 @@ BOOL LLAudioSource::hasPendingPreloads() const
1475 if (!adp->hasDecodedData()) 1608 if (!adp->hasDecodedData())
1476 { 1609 {
1477 // This source is still waiting for a preload 1610 // This source is still waiting for a preload
1478 return TRUE; 1611 return true;
1479 } 1612 }
1480 } 1613 }
1481 1614
1482 return FALSE; 1615 return false;
1483} 1616}
1484 1617
1485 1618
@@ -1514,8 +1647,8 @@ LLAudioBuffer *LLAudioSource::getCurrentBuffer()
1514LLAudioChannel::LLAudioChannel() : 1647LLAudioChannel::LLAudioChannel() :
1515 mCurrentSourcep(NULL), 1648 mCurrentSourcep(NULL),
1516 mCurrentBufferp(NULL), 1649 mCurrentBufferp(NULL),
1517 mLoopedThisFrame(FALSE), 1650 mLoopedThisFrame(false),
1518 mWaiting(FALSE) 1651 mWaiting(false)
1519{ 1652{
1520} 1653}
1521 1654
@@ -1542,7 +1675,7 @@ void LLAudioChannel::setSource(LLAudioSource *sourcep)
1542 //llinfos << "Clearing source for channel" << llendl; 1675 //llinfos << "Clearing source for channel" << llendl;
1543 cleanup(); 1676 cleanup();
1544 mCurrentSourcep = NULL; 1677 mCurrentSourcep = NULL;
1545 mWaiting = FALSE; 1678 mWaiting = false;
1546 return; 1679 return;
1547 } 1680 }
1548 1681
@@ -1558,13 +1691,13 @@ void LLAudioChannel::setSource(LLAudioSource *sourcep)
1558} 1691}
1559 1692
1560 1693
1561BOOL LLAudioChannel::updateBuffer() 1694bool LLAudioChannel::updateBuffer()
1562{ 1695{
1563 if (!mCurrentSourcep) 1696 if (!mCurrentSourcep)
1564 { 1697 {
1565 // This channel isn't associated with any source, nothing 1698 // This channel isn't associated with any source, nothing
1566 // to be updated 1699 // to be updated
1567 return FALSE; 1700 return false;
1568 } 1701 }
1569 1702
1570 LLAudioBuffer *bufferp = mCurrentSourcep->getCurrentBuffer(); 1703 LLAudioBuffer *bufferp = mCurrentSourcep->getCurrentBuffer();
@@ -1574,9 +1707,9 @@ BOOL LLAudioChannel::updateBuffer()
1574 { 1707 {
1575 // The source hasn't changed what buffer it's playing 1708 // The source hasn't changed what buffer it's playing
1576 bufferp->mLastUseTimer.reset(); 1709 bufferp->mLastUseTimer.reset();
1577 bufferp->mInUse = TRUE; 1710 bufferp->mInUse = true;
1578 } 1711 }
1579 return FALSE; 1712 return false;
1580 } 1713 }
1581 1714
1582 // 1715 //
@@ -1589,16 +1722,16 @@ BOOL LLAudioChannel::updateBuffer()
1589 if (bufferp) 1722 if (bufferp)
1590 { 1723 {
1591 bufferp->mLastUseTimer.reset(); 1724 bufferp->mLastUseTimer.reset();
1592 bufferp->mInUse = TRUE; 1725 bufferp->mInUse = true;
1593 } 1726 }
1594 1727
1595 if (!mCurrentBufferp) 1728 if (!mCurrentBufferp)
1596 { 1729 {
1597 // There's no new buffer to be played, so we just abort. 1730 // There's no new buffer to be played, so we just abort.
1598 return FALSE; 1731 return false;
1599 } 1732 }
1600 1733
1601 return TRUE; 1734 return true;
1602} 1735}
1603 1736
1604 1737
@@ -1612,9 +1745,9 @@ BOOL LLAudioChannel::updateBuffer()
1612LLAudioData::LLAudioData(const LLUUID &uuid) : 1745LLAudioData::LLAudioData(const LLUUID &uuid) :
1613 mID(uuid), 1746 mID(uuid),
1614 mBufferp(NULL), 1747 mBufferp(NULL),
1615 mHasLocalData(FALSE), 1748 mHasLocalData(false),
1616 mHasDecodedData(FALSE), 1749 mHasDecodedData(false),
1617 mHasValidData(TRUE) 1750 mHasValidData(true)
1618{ 1751{
1619 if (uuid.isNull()) 1752 if (uuid.isNull())
1620 { 1753 {
@@ -1625,24 +1758,24 @@ LLAudioData::LLAudioData(const LLUUID &uuid) :
1625 if (gAudiop && gAudiop->hasDecodedFile(uuid)) 1758 if (gAudiop && gAudiop->hasDecodedFile(uuid))
1626 { 1759 {
1627 // Already have a decoded version, don't need to decode it. 1760 // Already have a decoded version, don't need to decode it.
1628 mHasLocalData = TRUE; 1761 mHasLocalData = true;
1629 mHasDecodedData = TRUE; 1762 mHasDecodedData = true;
1630 } 1763 }
1631 else if (gAssetStorage && gAssetStorage->hasLocalAsset(uuid, LLAssetType::AT_SOUND)) 1764 else if (gAssetStorage && gAssetStorage->hasLocalAsset(uuid, LLAssetType::AT_SOUND))
1632 { 1765 {
1633 mHasLocalData = TRUE; 1766 mHasLocalData = true;
1634 } 1767 }
1635} 1768}
1636 1769
1637 1770
1638BOOL LLAudioData::load() 1771bool LLAudioData::load()
1639{ 1772{
1640 // For now, just assume we're going to use one buffer per audiodata. 1773 // For now, just assume we're going to use one buffer per audiodata.
1641 if (mBufferp) 1774 if (mBufferp)
1642 { 1775 {
1643 // We already have this sound in a buffer, don't do anything. 1776 // We already have this sound in a buffer, don't do anything.
1644 llinfos << "Already have a buffer for this sound, don't bother loading!" << llendl; 1777 llinfos << "Already have a buffer for this sound, don't bother loading!" << llendl;
1645 return TRUE; 1778 return true;
1646 } 1779 }
1647 1780
1648 mBufferp = gAudiop->getFreeBuffer(); 1781 mBufferp = gAudiop->getFreeBuffer();
@@ -1650,7 +1783,7 @@ BOOL LLAudioData::load()
1650 { 1783 {
1651 // No free buffers, abort. 1784 // No free buffers, abort.
1652 llinfos << "Not able to allocate a new audio buffer, aborting." << llendl; 1785 llinfos << "Not able to allocate a new audio buffer, aborting." << llendl;
1653 return FALSE; 1786 return false;
1654 } 1787 }
1655 1788
1656 std::string uuid_str; 1789 std::string uuid_str;
@@ -1664,10 +1797,10 @@ BOOL LLAudioData::load()
1664 gAudiop->cleanupBuffer(mBufferp); 1797 gAudiop->cleanupBuffer(mBufferp);
1665 mBufferp = NULL; 1798 mBufferp = NULL;
1666 1799
1667 return FALSE; 1800 return false;
1668 } 1801 }
1669 mBufferp->mAudioDatap = this; 1802 mBufferp->mAudioDatap = this;
1670 return TRUE; 1803 return true;
1671} 1804}
1672 1805
1673 1806