From 4cdf3961253b49093bf3e2fceda0099cedef4295 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Fri, 28 Oct 2011 17:48:24 -0400 Subject: STORM-591 As a music fan, I want audio to fade in gently so my immersion is increased Co-written with Robin Cornelius --- indra/newview/llvieweraudio.cpp | 211 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 208 insertions(+), 3 deletions(-) (limited to 'indra/newview/llvieweraudio.cpp') diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp index f7fa5690d6..8fd1ca3807 100644 --- a/indra/newview/llvieweraudio.cpp +++ b/indra/newview/llvieweraudio.cpp @@ -37,9 +37,212 @@ #include "llvoiceclient.h" #include "llviewermedia.h" #include "llprogressview.h" +#include "llcallbacklist.h" ///////////////////////////////////////////////////////// +LLViewerAudio::LLViewerAudio() : + mDone(true), + mFadeState(FADE_IDLE), + mFadeTime(), + mIdleListnerActive(false) +{ +} + +LLViewerAudio::~LLViewerAudio() +{ +} + +void LLViewerAudio::registerIdleListener() +{ + if(mIdleListnerActive==false) + { + mIdleListnerActive = true; + doOnIdleRepeating(boost::bind(boost::bind(&LLViewerAudio::onIdleUpdate, this))); + } + +} + +void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) +{ + llinfos << "DBG streamURI: " << streamURI << llendl; + llinfos << "DBG mNextStreamURI: " << mNextStreamURI << llendl; + if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} + if (mFadeState == FADE_IN) {llinfos << "DBG mFadeState: FADE_IN " << llendl;} + if (mFadeState == FADE_IDLE) {llinfos << "DBG mFadeState: FADE_IDLE " << llendl;} + + // Old and new stream are identical + if (mNextStreamURI == streamURI) + { + return; + } + + // Record the URI we are going to be switching to + mNextStreamURI = streamURI; + + if (mFadeState == FADE_IDLE) + { + // If a stream is playing fade it out first + if (!gAudiop->getInternetStreamURL().empty()) + { + mFadeState = FADE_OUT; +llinfos << "DBG new mFadeState: OUT" << llendl; + } + // Otherwise the new stream can be faded in + else + { + mFadeState = FADE_IN; +llinfos << "DBG new mFadeState: IN" << llendl; + + gAudiop->startInternetStream(mNextStreamURI); + startFading(); + registerIdleListener(); + return; + } + } + + if (mFadeState == FADE_OUT) + { + startFading(); + registerIdleListener(); + return; + } + + if (mFadeState == FADE_IN) + { + registerIdleListener(); + return; + } +} + +// We want onIdleUpdate callback to keep firing whilst we are fading out. Once we have completed the fade +// out, we switch the stream and start a fade in, and we don't care about idle updates anymore. +// A return of false from onIdleUpdate means it will be called again next idle update. +// A return of true means we have finished with it and the callback will be deleted. +bool LLViewerAudio::onIdleUpdate() +{ + if (mDone) + { + if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} + if (mFadeState == FADE_IN) {llinfos << "DBG mFadeState: FADE_IN " << llendl;} + if (mFadeState == FADE_IDLE) {llinfos << "DBG mFadeState: FADE_IDLE " << llendl;} + + // This should be a rare or never occurring state. + if (mFadeState == FADE_IDLE) + { + deregisterIdleListener(); + return true; // Stop calling onIdleUpdate + } + + // we have finished the current fade operation + if (mFadeState == FADE_OUT) + { + // Clear URI + gAudiop->startInternetStream(LLStringUtil::null); + gAudiop->stopInternetStream(); + + if (!mNextStreamURI.empty()) + { + mFadeState = FADE_IN; +llinfos << "DBG new mFadeState: IN" << llendl; + gAudiop->startInternetStream(mNextStreamURI); + startFading(); + return false; + } + else + { + mFadeState = FADE_IDLE; +llinfos << "DBG new mFadeState: IDLE" << llendl; + deregisterIdleListener(); + return true; // Stop calling onIdleUpdate + } + } + else if (mFadeState == FADE_IN) + { + if (mNextStreamURI != gAudiop->getInternetStreamURL()) + { + mFadeState = FADE_OUT; + startFading(); + return false; +llinfos << "DBG new mFadeState: OUT" << llendl; + } + else + { + mFadeState = FADE_IDLE; +llinfos << "DBG new mFadeState: IDLE" << llendl; + deregisterIdleListener(); + return true; // Stop calling onIdleUpdate + } + } + } + + return false; +} + +void LLViewerAudio::stopInternetStreamWithAutoFade() +{ +llinfos << "DBG stopping stream" << llendl; + mFadeState = FADE_IDLE; +llinfos << "DBG new mFadeState: IDLE" << llendl; + mNextStreamURI = LLStringUtil::null; + mDone = true; +llinfos << "DBG mDone: true" << llendl; + + gAudiop->startInternetStream(LLStringUtil::null); + gAudiop->stopInternetStream(); +} + +void LLViewerAudio::startFading() +{ +llinfos << "DBG startFading" << llendl; + + if(mDone) + { + // The fade state here should only be one of FADE_IN or FADE_OUT, but, in case it is not, + // rather than check for both states assume a fade in and check for the fade out case. + mFadeTime = llmax(0.0f, gSavedSettings.getF32("AudioMusicFadeIn")); + if (LLViewerAudio::getInstance()->getFadeState() == LLViewerAudio::FADE_OUT) + { + mFadeTime = llmax(0.0f, gSavedSettings.getF32("AudioMusicFadeOut")); + } + stream_fade_timer.reset(); + stream_fade_timer.setTimerExpirySec(mFadeTime); + mDone = false; +llinfos << "DBG mDone: false" << llendl; + } +} + +F32 LLViewerAudio::getFadeVolume() +{ + F32 fade_volume = 1.0f; + + if (stream_fade_timer.hasExpired()) + { + mDone = true; + // If we have been fading out set volume to 0 until the next fade state occurs to prevent + // an audio transient. + if (LLViewerAudio::getInstance()->getFadeState() == LLViewerAudio::FADE_OUT) + { + fade_volume = 0.0f; + } + } + + if (!mDone) + { + // Calculate how far we are into the fade time + fade_volume = stream_fade_timer.getElapsedTimeF32() / mFadeTime; + + if (LLViewerAudio::getInstance()->getFadeState() == LLViewerAudio::FADE_OUT) + { + // If we are not fading in then we are fading out, so invert the fade + // direction; start loud and move towards zero volume. + fade_volume = 1.0f - fade_volume; + } + } + + return fade_volume; +} + void init_audio() { if (!gAudiop) @@ -145,9 +348,11 @@ void audio_update_volume(bool force_update) { F32 music_volume = gSavedSettings.getF32("AudioLevelMusic"); BOOL music_muted = gSavedSettings.getBOOL("MuteMusic"); - music_volume = mute_volume * master_volume * music_volume; - gAudiop->setInternetStreamGain ( music_muted || progress_view_visible ? 0.f : music_volume ); - + F32 fade_volume = LLViewerAudio::getInstance()->getFadeVolume(); +llinfos << "DBG fade_volume:" << fade_volume << llendl; + + music_volume = mute_volume * master_volume * music_volume * fade_volume; + gAudiop->setInternetStreamGain (music_muted ? 0.f : music_volume); } // Streaming Media -- cgit v1.2.3 From 526f71053a9fb18e95993343a0fd826023bda683 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Sat, 29 Oct 2011 05:01:23 -0400 Subject: STORM-591 Comment out debugging llinfos lines --- indra/newview/llvieweraudio.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'indra/newview/llvieweraudio.cpp') diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp index 8fd1ca3807..10ba54356c 100644 --- a/indra/newview/llvieweraudio.cpp +++ b/indra/newview/llvieweraudio.cpp @@ -65,12 +65,12 @@ void LLViewerAudio::registerIdleListener() void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) { - llinfos << "DBG streamURI: " << streamURI << llendl; +/* llinfos << "DBG streamURI: " << streamURI << llendl; llinfos << "DBG mNextStreamURI: " << mNextStreamURI << llendl; if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} if (mFadeState == FADE_IN) {llinfos << "DBG mFadeState: FADE_IN " << llendl;} if (mFadeState == FADE_IDLE) {llinfos << "DBG mFadeState: FADE_IDLE " << llendl;} - +*/ // Old and new stream are identical if (mNextStreamURI == streamURI) { @@ -86,13 +86,13 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) if (!gAudiop->getInternetStreamURL().empty()) { mFadeState = FADE_OUT; -llinfos << "DBG new mFadeState: OUT" << llendl; +//llinfos << "DBG new mFadeState: OUT" << llendl; } // Otherwise the new stream can be faded in else { mFadeState = FADE_IN; -llinfos << "DBG new mFadeState: IN" << llendl; +//llinfos << "DBG new mFadeState: IN" << llendl; gAudiop->startInternetStream(mNextStreamURI); startFading(); @@ -123,10 +123,10 @@ bool LLViewerAudio::onIdleUpdate() { if (mDone) { - if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} +/* if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} if (mFadeState == FADE_IN) {llinfos << "DBG mFadeState: FADE_IN " << llendl;} if (mFadeState == FADE_IDLE) {llinfos << "DBG mFadeState: FADE_IDLE " << llendl;} - +*/ // This should be a rare or never occurring state. if (mFadeState == FADE_IDLE) { @@ -144,7 +144,7 @@ bool LLViewerAudio::onIdleUpdate() if (!mNextStreamURI.empty()) { mFadeState = FADE_IN; -llinfos << "DBG new mFadeState: IN" << llendl; +//llinfos << "DBG new mFadeState: IN" << llendl; gAudiop->startInternetStream(mNextStreamURI); startFading(); return false; @@ -152,7 +152,7 @@ llinfos << "DBG new mFadeState: IN" << llendl; else { mFadeState = FADE_IDLE; -llinfos << "DBG new mFadeState: IDLE" << llendl; +//llinfos << "DBG new mFadeState: IDLE" << llendl; deregisterIdleListener(); return true; // Stop calling onIdleUpdate } @@ -164,12 +164,12 @@ llinfos << "DBG new mFadeState: IDLE" << llendl; mFadeState = FADE_OUT; startFading(); return false; -llinfos << "DBG new mFadeState: OUT" << llendl; +//llinfos << "DBG new mFadeState: OUT" << llendl; } else { mFadeState = FADE_IDLE; -llinfos << "DBG new mFadeState: IDLE" << llendl; +//llinfos << "DBG new mFadeState: IDLE" << llendl; deregisterIdleListener(); return true; // Stop calling onIdleUpdate } @@ -181,12 +181,12 @@ llinfos << "DBG new mFadeState: IDLE" << llendl; void LLViewerAudio::stopInternetStreamWithAutoFade() { -llinfos << "DBG stopping stream" << llendl; +//llinfos << "DBG stopping stream" << llendl; mFadeState = FADE_IDLE; -llinfos << "DBG new mFadeState: IDLE" << llendl; +//llinfos << "DBG new mFadeState: IDLE" << llendl; mNextStreamURI = LLStringUtil::null; mDone = true; -llinfos << "DBG mDone: true" << llendl; +//llinfos << "DBG mDone: true" << llendl; gAudiop->startInternetStream(LLStringUtil::null); gAudiop->stopInternetStream(); @@ -194,7 +194,7 @@ llinfos << "DBG mDone: true" << llendl; void LLViewerAudio::startFading() { -llinfos << "DBG startFading" << llendl; +//llinfos << "DBG startFading" << llendl; if(mDone) { @@ -208,7 +208,7 @@ llinfos << "DBG startFading" << llendl; stream_fade_timer.reset(); stream_fade_timer.setTimerExpirySec(mFadeTime); mDone = false; -llinfos << "DBG mDone: false" << llendl; +//llinfos << "DBG mDone: false" << llendl; } } @@ -349,7 +349,7 @@ void audio_update_volume(bool force_update) F32 music_volume = gSavedSettings.getF32("AudioLevelMusic"); BOOL music_muted = gSavedSettings.getBOOL("MuteMusic"); F32 fade_volume = LLViewerAudio::getInstance()->getFadeVolume(); -llinfos << "DBG fade_volume:" << fade_volume << llendl; +//llinfos << "DBG fade_volume:" << fade_volume << llendl; music_volume = mute_volume * master_volume * music_volume * fade_volume; gAudiop->setInternetStreamGain (music_muted ? 0.f : music_volume); -- cgit v1.2.3 From ed596077c4eb5b1ba6be4a71824ef220c086d436 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Fri, 18 Nov 2011 09:47:55 -0500 Subject: STORM-591 Removed commented out debugging lines --- indra/newview/llvieweraudio.cpp | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'indra/newview/llvieweraudio.cpp') diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp index 10ba54356c..0262da4dee 100644 --- a/indra/newview/llvieweraudio.cpp +++ b/indra/newview/llvieweraudio.cpp @@ -65,12 +65,6 @@ void LLViewerAudio::registerIdleListener() void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) { -/* llinfos << "DBG streamURI: " << streamURI << llendl; - llinfos << "DBG mNextStreamURI: " << mNextStreamURI << llendl; - if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} - if (mFadeState == FADE_IN) {llinfos << "DBG mFadeState: FADE_IN " << llendl;} - if (mFadeState == FADE_IDLE) {llinfos << "DBG mFadeState: FADE_IDLE " << llendl;} -*/ // Old and new stream are identical if (mNextStreamURI == streamURI) { @@ -86,14 +80,11 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) if (!gAudiop->getInternetStreamURL().empty()) { mFadeState = FADE_OUT; -//llinfos << "DBG new mFadeState: OUT" << llendl; } // Otherwise the new stream can be faded in else { mFadeState = FADE_IN; -//llinfos << "DBG new mFadeState: IN" << llendl; - gAudiop->startInternetStream(mNextStreamURI); startFading(); registerIdleListener(); @@ -123,10 +114,6 @@ bool LLViewerAudio::onIdleUpdate() { if (mDone) { -/* if (mFadeState == FADE_OUT) {llinfos << "DBG mFadeState: FADE_OUT " << llendl;} - if (mFadeState == FADE_IN) {llinfos << "DBG mFadeState: FADE_IN " << llendl;} - if (mFadeState == FADE_IDLE) {llinfos << "DBG mFadeState: FADE_IDLE " << llendl;} -*/ // This should be a rare or never occurring state. if (mFadeState == FADE_IDLE) { @@ -144,7 +131,6 @@ bool LLViewerAudio::onIdleUpdate() if (!mNextStreamURI.empty()) { mFadeState = FADE_IN; -//llinfos << "DBG new mFadeState: IN" << llendl; gAudiop->startInternetStream(mNextStreamURI); startFading(); return false; @@ -152,7 +138,6 @@ bool LLViewerAudio::onIdleUpdate() else { mFadeState = FADE_IDLE; -//llinfos << "DBG new mFadeState: IDLE" << llendl; deregisterIdleListener(); return true; // Stop calling onIdleUpdate } @@ -164,12 +149,10 @@ bool LLViewerAudio::onIdleUpdate() mFadeState = FADE_OUT; startFading(); return false; -//llinfos << "DBG new mFadeState: OUT" << llendl; } else { mFadeState = FADE_IDLE; -//llinfos << "DBG new mFadeState: IDLE" << llendl; deregisterIdleListener(); return true; // Stop calling onIdleUpdate } @@ -181,12 +164,9 @@ bool LLViewerAudio::onIdleUpdate() void LLViewerAudio::stopInternetStreamWithAutoFade() { -//llinfos << "DBG stopping stream" << llendl; mFadeState = FADE_IDLE; -//llinfos << "DBG new mFadeState: IDLE" << llendl; mNextStreamURI = LLStringUtil::null; mDone = true; -//llinfos << "DBG mDone: true" << llendl; gAudiop->startInternetStream(LLStringUtil::null); gAudiop->stopInternetStream(); @@ -194,8 +174,6 @@ void LLViewerAudio::stopInternetStreamWithAutoFade() void LLViewerAudio::startFading() { -//llinfos << "DBG startFading" << llendl; - if(mDone) { // The fade state here should only be one of FADE_IN or FADE_OUT, but, in case it is not, @@ -208,7 +186,6 @@ void LLViewerAudio::startFading() stream_fade_timer.reset(); stream_fade_timer.setTimerExpirySec(mFadeTime); mDone = false; -//llinfos << "DBG mDone: false" << llendl; } } @@ -349,7 +326,6 @@ void audio_update_volume(bool force_update) F32 music_volume = gSavedSettings.getF32("AudioLevelMusic"); BOOL music_muted = gSavedSettings.getBOOL("MuteMusic"); F32 fade_volume = LLViewerAudio::getInstance()->getFadeVolume(); -//llinfos << "DBG fade_volume:" << fade_volume << llendl; music_volume = mute_volume * master_volume * music_volume * fade_volume; gAudiop->setInternetStreamGain (music_muted ? 0.f : music_volume); -- cgit v1.2.3 From 2b43a6b8c9b22d02373ac70193fa85f2bfb77b19 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Tue, 22 Nov 2011 13:13:51 -0500 Subject: STORM-591 Remove 2 development debug settings and replace them with constants --- indra/newview/llvieweraudio.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'indra/newview/llvieweraudio.cpp') diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp index 0262da4dee..1e5c742cf9 100644 --- a/indra/newview/llvieweraudio.cpp +++ b/indra/newview/llvieweraudio.cpp @@ -174,14 +174,17 @@ void LLViewerAudio::stopInternetStreamWithAutoFade() void LLViewerAudio::startFading() { + const F32 AUDIO_MUSIC_FADE_IN_TIME = 3.0; + const F32 AUDIO_MUSIC_FADE_OUT_TIME = 2.0; + if(mDone) { // The fade state here should only be one of FADE_IN or FADE_OUT, but, in case it is not, // rather than check for both states assume a fade in and check for the fade out case. - mFadeTime = llmax(0.0f, gSavedSettings.getF32("AudioMusicFadeIn")); + mFadeTime = AUDIO_MUSIC_FADE_IN_TIME; if (LLViewerAudio::getInstance()->getFadeState() == LLViewerAudio::FADE_OUT) { - mFadeTime = llmax(0.0f, gSavedSettings.getF32("AudioMusicFadeOut")); + mFadeTime = AUDIO_MUSIC_FADE_OUT_TIME; } stream_fade_timer.reset(); stream_fade_timer.setTimerExpirySec(mFadeTime); -- cgit v1.2.3 From 7226b23366805ae259000df25a622fc98a722d14 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Fri, 2 Dec 2011 09:22:27 -0500 Subject: STORM-591 Made mininum fade time 0.01 seconds to prevent divide by zero and negative fade times. Rewrote two blocks of code to eliminate early returns. --- indra/newview/llvieweraudio.cpp | 50 ++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'indra/newview/llvieweraudio.cpp') diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp index 1e5c742cf9..f01fe174a4 100644 --- a/indra/newview/llvieweraudio.cpp +++ b/indra/newview/llvieweraudio.cpp @@ -74,11 +74,13 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) // Record the URI we are going to be switching to mNextStreamURI = streamURI; - if (mFadeState == FADE_IDLE) + switch (mFadeState) { + case FADE_IDLE: // If a stream is playing fade it out first if (!gAudiop->getInternetStreamURL().empty()) { + // The order of these tests is important, state FADE_OUT will be processed below mFadeState = FADE_OUT; } // Otherwise the new stream can be faded in @@ -88,21 +90,21 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) gAudiop->startInternetStream(mNextStreamURI); startFading(); registerIdleListener(); - return; + break; } - } - if (mFadeState == FADE_OUT) - { - startFading(); - registerIdleListener(); - return; - } + case FADE_OUT: + startFading(); + registerIdleListener(); + break; - if (mFadeState == FADE_IN) - { - registerIdleListener(); - return; + case FADE_IN: + registerIdleListener(); + break; + + default: + llwarns << "Unknown fading state: " << mFadeState << llendl; + break; } } @@ -112,13 +114,15 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) // A return of true means we have finished with it and the callback will be deleted. bool LLViewerAudio::onIdleUpdate() { + bool fadeIsFinished = false; + if (mDone) { // This should be a rare or never occurring state. if (mFadeState == FADE_IDLE) { deregisterIdleListener(); - return true; // Stop calling onIdleUpdate + fadeIsFinished = true; // Stop calling onIdleUpdate } // we have finished the current fade operation @@ -133,13 +137,12 @@ bool LLViewerAudio::onIdleUpdate() mFadeState = FADE_IN; gAudiop->startInternetStream(mNextStreamURI); startFading(); - return false; } else { mFadeState = FADE_IDLE; deregisterIdleListener(); - return true; // Stop calling onIdleUpdate + fadeIsFinished = true; // Stop calling onIdleUpdate } } else if (mFadeState == FADE_IN) @@ -148,18 +151,17 @@ bool LLViewerAudio::onIdleUpdate() { mFadeState = FADE_OUT; startFading(); - return false; } else { mFadeState = FADE_IDLE; deregisterIdleListener(); - return true; // Stop calling onIdleUpdate + fadeIsFinished = true; // Stop calling onIdleUpdate } } } - return false; + return fadeIsFinished; } void LLViewerAudio::stopInternetStreamWithAutoFade() @@ -174,8 +176,10 @@ void LLViewerAudio::stopInternetStreamWithAutoFade() void LLViewerAudio::startFading() { - const F32 AUDIO_MUSIC_FADE_IN_TIME = 3.0; - const F32 AUDIO_MUSIC_FADE_OUT_TIME = 2.0; + const F32 AUDIO_MUSIC_FADE_IN_TIME = 3.0f; + const F32 AUDIO_MUSIC_FADE_OUT_TIME = 2.0f; + // This minimum fade time prevents divide by zero and negative times + const F32 AUDIO_MUSIC_MINIMUM_FADE_TIME = 0.01f; if(mDone) { @@ -186,6 +190,10 @@ void LLViewerAudio::startFading() { mFadeTime = AUDIO_MUSIC_FADE_OUT_TIME; } + + // Prevent invalid fade time + mFadeTime = llmax(mFadeTime, AUDIO_MUSIC_MINIMUM_FADE_TIME); + stream_fade_timer.reset(); stream_fade_timer.setTimerExpirySec(mFadeTime); mDone = false; -- cgit v1.2.3 From 3193170850ddc0fc3db57d40e9636ec77908dd70 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Mon, 5 Dec 2011 05:01:38 -0500 Subject: STORM-591 Made change per code review request: disable audio when teleport progress bar is present Added code to start counting the fade in time on login when STATE_STARTED is set --- indra/newview/llvieweraudio.cpp | 46 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'indra/newview/llvieweraudio.cpp') diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp index f01fe174a4..2447f5dea8 100644 --- a/indra/newview/llvieweraudio.cpp +++ b/indra/newview/llvieweraudio.cpp @@ -38,6 +38,9 @@ #include "llviewermedia.h" #include "llprogressview.h" #include "llcallbacklist.h" +#include "llstartup.h" +#include "llviewerparcelmgr.h" +#include "llparcel.h" ///////////////////////////////////////////////////////// @@ -45,12 +48,16 @@ LLViewerAudio::LLViewerAudio() : mDone(true), mFadeState(FADE_IDLE), mFadeTime(), - mIdleListnerActive(false) + mIdleListnerActive(false), + mForcedTeleportFade(false) { + mTeleportFailedConnection = LLViewerParcelMgr::getInstance()-> + setTeleportFailedCallback(boost::bind(&LLViewerAudio::onTeleportFailed, this)); } LLViewerAudio::~LLViewerAudio() { + mTeleportFailedConnection.disconnect(); } void LLViewerAudio::registerIdleListener() @@ -108,14 +115,21 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI) } } -// We want onIdleUpdate callback to keep firing whilst we are fading out. Once we have completed the fade -// out, we switch the stream and start a fade in, and we don't care about idle updates anymore. // A return of false from onIdleUpdate means it will be called again next idle update. // A return of true means we have finished with it and the callback will be deleted. bool LLViewerAudio::onIdleUpdate() { bool fadeIsFinished = false; + // There is a delay in the login sequence between when the parcel information has + // arrived and the music stream is started and when the audio system is called to set + // initial volume levels. This code extends the fade time so you hear a full fade in. + if ((LLStartUp::getStartupState() < STATE_STARTED)) + { + stream_fade_timer.reset(); + stream_fade_timer.setTimerExpirySec(mFadeTime); + } + if (mDone) { // This should be a rare or never occurring state. @@ -231,6 +245,18 @@ F32 LLViewerAudio::getFadeVolume() return fade_volume; } +void LLViewerAudio::onTeleportFailed() +{ + if (gAudiop) + { + LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); + if (parcel) + { + mNextStreamURI = parcel->getMusicURL(); + } + } +} + void init_audio() { if (!gAudiop) @@ -333,7 +359,19 @@ void audio_update_volume(bool force_update) // Streaming Music if (gAudiop) - { + { + if (progress_view_visible && !LLViewerAudio::getInstance()->getForcedTeleportFade()) + { + LLViewerAudio::getInstance()->setForcedTeleportFade(true); + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(LLStringUtil::null); + LLViewerAudio::getInstance()->setNextStreamURI(LLStringUtil::null); + } + + if (!progress_view_visible && LLViewerAudio::getInstance()->getForcedTeleportFade() == true) + { + LLViewerAudio::getInstance()->setForcedTeleportFade(false); + } + F32 music_volume = gSavedSettings.getF32("AudioLevelMusic"); BOOL music_muted = gSavedSettings.getBOOL("MuteMusic"); F32 fade_volume = LLViewerAudio::getInstance()->getFadeVolume(); -- cgit v1.2.3