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 --- doc/contributions.txt | 2 + indra/newview/app_settings/settings.xml | 22 ++ indra/newview/lloverlaybar.cpp | 378 -------------------------------- indra/newview/lloverlaybar.h | 95 -------- indra/newview/llpanelnearbymedia.cpp | 24 +- indra/newview/llpanelnearbymedia.h | 1 - indra/newview/llvieweraudio.cpp | 211 +++++++++++++++++- indra/newview/llvieweraudio.h | 41 ++++ indra/newview/llviewermedia.cpp | 22 +- indra/newview/llviewerparcelmgr.cpp | 55 +++-- 10 files changed, 322 insertions(+), 529 deletions(-) delete mode 100644 indra/newview/lloverlaybar.cpp delete mode 100644 indra/newview/lloverlaybar.h diff --git a/doc/contributions.txt b/doc/contributions.txt index 988410701b..0f7f458a81 100644 --- a/doc/contributions.txt +++ b/doc/contributions.txt @@ -581,6 +581,7 @@ Jonathan Yap STORM-1639 STORM-910 STORM-1642 + STORM-591 Kadah Coba STORM-1060 Jondan Lundquist @@ -913,6 +914,7 @@ Robin Cornelius SNOW-599 SNOW-747 STORM-422 + STORM-591 STORM-960 STORM-1019 STORM-1095 diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 3c53a9d44c..c7300cc1bb 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -192,6 +192,28 @@ Value 1 + AudioMusicFadeIn + + Comment + Fade in time in seconds for music streams + Persist + 1 + Type + F32 + Value + 5.0 + + AudioMusicFadeOut + + Comment + Fade out time in seconds for music streams + Persist + 1 + Type + F32 + Value + 5.0 + AudioLevelAmbient Comment diff --git a/indra/newview/lloverlaybar.cpp b/indra/newview/lloverlaybar.cpp deleted file mode 100644 index c2bbec0470..0000000000 --- a/indra/newview/lloverlaybar.cpp +++ /dev/null @@ -1,378 +0,0 @@ -/** - * @file lloverlaybar.cpp - * @brief LLOverlayBar class implementation - * - * $LicenseInfo:firstyear=2002&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -// Temporary buttons that appear at the bottom of the screen when you -// are in a mode. - -#include "llviewerprecompiledheaders.h" - -#include "lloverlaybar.h" - -#include "llaudioengine.h" -#include "llrender.h" -#include "llagent.h" -#include "llbutton.h" -#include "llfocusmgr.h" -#include "llimview.h" -#include "llmediaremotectrl.h" -#include "llparcel.h" -#include "lltextbox.h" -#include "llui.h" -#include "llviewercontrol.h" -#include "llviewertexturelist.h" -#include "llviewerjoystick.h" -#include "llviewermedia.h" -#include "llviewermenu.h" // handle_reset_view() -#include "llviewermedia.h" -#include "llviewerparcelmedia.h" -#include "llviewerparcelmgr.h" -#include "lluictrlfactory.h" -#include "llviewerwindow.h" -#include "llvoiceclient.h" -#include "llvoavatarself.h" -#include "llvoiceremotectrl.h" -#include "llmediactrl.h" -#include "llselectmgr.h" - -// -// Globals -// - -LLOverlayBar *gOverlayBar = NULL; - -extern S32 MENU_BAR_HEIGHT; - -// -// Functions -// - - - -void* LLOverlayBar::createMediaRemote(void* userdata) -{ - LLOverlayBar *self = (LLOverlayBar*)userdata; - self->mMediaRemote = new LLMediaRemoteCtrl (); - return self->mMediaRemote; -} - -void* LLOverlayBar::createVoiceRemote(void* userdata) -{ - LLOverlayBar *self = (LLOverlayBar*)userdata; - self->mVoiceRemote = new LLVoiceRemoteCtrl(); - return self->mVoiceRemote; -} - -LLOverlayBar::LLOverlayBar() - : LLPanel(), - mMediaRemote(NULL), - mVoiceRemote(NULL), - mMusicState(STOPPED) -{ - setMouseOpaque(FALSE); - setIsChrome(TRUE); - - mBuilt = false; - - mFactoryMap["media_remote"] = LLCallbackMap(LLOverlayBar::createMediaRemote, this); - mFactoryMap["voice_remote"] = LLCallbackMap(LLOverlayBar::createVoiceRemote, this); - - LLUICtrlFactory::getInstance()->buildPanel(this, "panel_overlaybar.xml"); -} - -BOOL LLOverlayBar::postBuild() -{ - childSetAction("Set Not Busy",onClickSetNotBusy,this); - childSetAction("Mouselook",onClickMouselook,this); - childSetAction("Stand Up",onClickStandUp,this); - childSetAction("Flycam",onClickFlycam,this); - childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible")); - - mVoiceRemote->expandOrCollapse(); - mMediaRemote->expandOrCollapse(); - - setFocusRoot(TRUE); - mBuilt = true; - - layoutButtons(); - return TRUE; -} - -LLOverlayBar::~LLOverlayBar() -{ - // LLView destructor cleans up children -} - -// virtual -void LLOverlayBar::reshape(S32 width, S32 height, BOOL called_from_parent) -{ - LLView::reshape(width, height, called_from_parent); - - if (mBuilt) - { - layoutButtons(); - } -} - -void LLOverlayBar::layoutButtons() -{ - LLView* state_buttons_panel = getChildView("state_buttons"); - - if (state_buttons_panel->getVisible()) - { - LLViewQuery query; - LLWidgetTypeFilter widget_filter; - query.addPreFilter(LLEnabledFilter::getInstance()); - query.addPreFilter(&widget_filter); - - child_list_t button_list = query(state_buttons_panel); - - const S32 MAX_BAR_WIDTH = 600; - S32 bar_width = llclamp(state_buttons_panel->getRect().getWidth(), 0, MAX_BAR_WIDTH); - - // calculate button widths - const S32 MAX_BUTTON_WIDTH = 150; - const S32 STATUS_BAR_PAD = 10; - S32 segment_width = llclamp(lltrunc((F32)(bar_width) / (F32)button_list.size()), 0, MAX_BUTTON_WIDTH); - S32 btn_width = segment_width - STATUS_BAR_PAD; - - // Evenly space all buttons, starting from left - S32 left = 0; - S32 bottom = 1; - - for (child_list_reverse_iter_t child_iter = button_list.rbegin(); - child_iter != button_list.rend(); ++child_iter) - { - LLView *view = *child_iter; - LLRect r = view->getRect(); - r.setOriginAndSize(left, bottom, btn_width, r.getHeight()); - view->setRect(r); - left += segment_width; - } - } -} - -// Per-frame updates of visibility -void LLOverlayBar::refresh() -{ - BOOL buttons_changed = FALSE; - - BOOL im_received = gIMMgr->getIMReceived(); - LLButton* button = getChild("IM Received"); - if (button && button->getVisible() != im_received) - { - button->setVisible(im_received); - sendChildToFront(button); - moveChildToBackOfTabGroup(button); - buttons_changed = TRUE; - } - - BOOL busy = gAgent.getBusy(); - button = getChild("Set Not Busy"); - if (button && button->getVisible() != busy) - { - button->setVisible(busy); - sendChildToFront(button); - moveChildToBackOfTabGroup(button); - buttons_changed = TRUE; - } - - BOOL flycam = LLViewerJoystick::getInstance()->getOverrideCamera(); - button = getChild("Flycam"); - if (button && button->getVisible() != flycam) - { - button->setVisible(flycam); - sendChildToFront(button); - moveChildToBackOfTabGroup(button); - buttons_changed = TRUE; - } - - BOOL mouselook_grabbed; - mouselook_grabbed = gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_DOWN_INDEX) - || gAgent.isControlGrabbed(CONTROL_ML_LBUTTON_UP_INDEX); - button = getChild("Mouselook"); - - if (button && button->getVisible() != mouselook_grabbed) - { - button->setVisible(mouselook_grabbed); - sendChildToFront(button); - moveChildToBackOfTabGroup(button); - buttons_changed = TRUE; - } - - BOOL sitting = FALSE; - if (gAgent.getAvatarObject()) - { - sitting = gAgent.getAvatarObject()->isSitting(); - } - button = getChild("Stand Up"); - - if (button && button->getVisible() != sitting) - { - button->setVisible(sitting); - sendChildToFront(button); - moveChildToBackOfTabGroup(button); - buttons_changed = TRUE; - } - - - moveChildToBackOfTabGroup(mMediaRemote); - moveChildToBackOfTabGroup(mVoiceRemote); - - // turn off the whole bar in mouselook - if (gAgent.cameraMouselook()) - { - childSetVisible("media_remote_container", FALSE); - childSetVisible("voice_remote_container", FALSE); - childSetVisible("state_buttons", FALSE); - } - else - { - // update "remotes" - childSetVisible("media_remote_container", TRUE); - childSetVisible("voice_remote_container", LLVoiceClient::getInstance()->voiceEnabled()); - childSetVisible("state_buttons", TRUE); - } - - // always let user toggle into and out of chatbar - childSetVisible("chat_bar", gSavedSettings.getBOOL("ChatVisible")); - - if (buttons_changed) - { - layoutButtons(); - } -} - -//----------------------------------------------------------------------- -// Static functions -//----------------------------------------------------------------------- - -// static -void LLOverlayBar::onClickSetNotBusy(void*) -{ - gAgent.clearBusy(); -} - - -// static -void LLOverlayBar::onClickFlycam(void*) -{ - LLViewerJoystick::getInstance()->toggleFlycam(); -} - -// static -void LLOverlayBar::onClickResetView(void* data) -{ - handle_reset_view(); -} - -//static -void LLOverlayBar::onClickMouselook(void*) -{ - gAgent.changeCameraToMouselook(); -} - -//static -void LLOverlayBar::onClickStandUp(void*) -{ - LLSelectMgr::getInstance()->deselectAllForStandingUp(); - gAgent.setControlFlags(AGENT_CONTROL_STAND_UP); -} - -//////////////////////////////////////////////////////////////////////////////// -// static media helpers -// *TODO: Move this into an audio manager abstraction -//static -void LLOverlayBar::mediaStop(void*) -{ - if (!gOverlayBar) - { - // return; - } - LLViewerParcelMedia::stop(); -} -//static -void LLOverlayBar::toggleMediaPlay(void*) -{ - if (!gOverlayBar) - { - // return; - } - - - if (LLViewerParcelMedia::getStatus() == LLViewerMediaImpl::MEDIA_PAUSED) - { - LLViewerParcelMedia::start(); - } - else if(LLViewerParcelMedia::getStatus() == LLViewerMediaImpl::MEDIA_PLAYING) - { - LLViewerParcelMedia::pause(); - } - else - { - LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); - if (parcel) - { - LLViewerParcelMedia::play(parcel); - } - } -} - -//static -void LLOverlayBar::toggleMusicPlay(void*) -{ - if (gAudiop->isInternetStreamPlaying() != 1) - { - if (gAudiop) - { - LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); - if ( parcel ) - { - // this doesn't work properly when crossing parcel boundaries - even when the - // stream is stopped, it doesn't return the right thing - commenting out for now. - // if ( gAudiop->isInternetStreamPlaying() == 0 ) - { - gAudiop->startInternetStream(parcel->getMusicURL()); - } - } - } - } - //else - //{ - // gOverlayBar->mMusicState = PAUSED; // desired state - // if (gAudiop) - // { - // gAudiop->pauseInternetStream(1); - // } - //} - else - { - if (gAudiop) - { - gAudiop->stopInternetStream(); - } - } -} - diff --git a/indra/newview/lloverlaybar.h b/indra/newview/lloverlaybar.h deleted file mode 100644 index b36f5ebb73..0000000000 --- a/indra/newview/lloverlaybar.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - * @file lloverlaybar.h - * @brief LLOverlayBar class definition - * - * $LicenseInfo:firstyear=2002&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLOVERLAYBAR_H -#define LL_LLOVERLAYBAR_H - -#include "llpanel.h" - -// "Constants" loaded from settings.xml at start time -extern S32 STATUS_BAR_HEIGHT; - -class LLButton; -class LLLineEditor; -class LLMediaRemoteCtrl; -class LLMessageSystem; -class LLTextBox; -class LLTextEditor; -class LLUICtrl; -class LLUUID; -class LLFrameTimer; -class LLStatGraph; -class LLSlider; -class LLVoiceRemoteCtrl; - -class LLOverlayBar -: public LLPanel -{ -public: - LLOverlayBar(); - ~LLOverlayBar(); - - /*virtual*/ void refresh(); - /*virtual*/ void reshape(S32 width, S32 height, BOOL called_from_parent = TRUE); - /*virtual*/ BOOL postBuild(); - - void layoutButtons(); - - // helpers for returning desired state - BOOL musicPlaying() { return mMusicState == PLAYING; } - - static void onClickSetNotBusy(void* data); - static void onClickMouselook(void* data); - static void onClickStandUp(void* data); - static void onClickResetView(void* data); - static void onClickFlycam(void* data); - - //static media helper functions - static void toggleMediaPlay(void*); - static void toggleMusicPlay(void*); - static void musicPause(void*); - static void musicStop(void*); - static void mediaStop(void*); - - static void toggleAudioVolumeFloater(void*); - -protected: - static void* createMediaRemote(void* userdata); - static void* createVoiceRemote(void* userdata); - - void enableMediaButtons(); - -protected: - LLMediaRemoteCtrl* mMediaRemote; - LLVoiceRemoteCtrl* mVoiceRemote; - bool mBuilt; // dialog constructed yet? - enum { STOPPED=0, PLAYING=1, PAUSED=2 }; - S32 mMusicState; -}; - -extern LLOverlayBar* gOverlayBar; - -#endif diff --git a/indra/newview/llpanelnearbymedia.cpp b/indra/newview/llpanelnearbymedia.cpp index 2bbd15ae11..53fc64f089 100644 --- a/indra/newview/llpanelnearbymedia.cpp +++ b/indra/newview/llpanelnearbymedia.cpp @@ -52,6 +52,7 @@ #include "llvovolume.h" #include "llstatusbar.h" #include "llsdutil.h" +#include "llvieweraudio.h" #include "llfloaterreg.h" #include "llfloaterpreference.h" // for the gear icon @@ -808,7 +809,7 @@ bool LLPanelNearByMedia::setDisabled(const LLUUID &row_id, bool disabled) if (row_id == PARCEL_AUDIO_LIST_ITEM_UUID) { if (disabled) onClickParcelAudioStop(); - else onClickParcelAudioStart(); + else onClickParcelAudioPlay(); return true; } else if (row_id == PARCEL_MEDIA_LIST_ITEM_UUID) @@ -857,24 +858,11 @@ void LLPanelNearByMedia::onClickParcelMediaPause() LLViewerParcelMedia::pause(); } -void LLPanelNearByMedia::onClickParcelAudioStart() -{ - // User *explicitly* started the internet stream, so keep the stream - // playing and updated as they cross to other parcels etc. - mParcelAudioAutoStart = true; - - if (!gAudiop) - return; - - gAudiop->startInternetStream(LLViewerMedia::getParcelAudioURL()); -} - void LLPanelNearByMedia::onClickParcelAudioPlay() { // User *explicitly* started the internet stream, so keep the stream // playing and updated as they cross to other parcels etc. mParcelAudioAutoStart = true; - if (!gAudiop) return; @@ -883,8 +871,9 @@ void LLPanelNearByMedia::onClickParcelAudioPlay() // 'false' means unpause gAudiop->pauseInternetStream(false); } - else { - gAudiop->startInternetStream(LLViewerMedia::getParcelAudioURL()); + else + { + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(LLViewerMedia::getParcelAudioURL()); } } @@ -894,11 +883,10 @@ void LLPanelNearByMedia::onClickParcelAudioStop() // re-start audio when i.e. they move to another parcel, until // they explicitly start it again. mParcelAudioAutoStart = false; - if (!gAudiop) return; - gAudiop->stopInternetStream(); + LLViewerAudio::getInstance()->stopInternetStreamWithAutoFade(); } void LLPanelNearByMedia::onClickParcelAudioPause() diff --git a/indra/newview/llpanelnearbymedia.h b/indra/newview/llpanelnearbymedia.h index be4d313743..c3634de9b4 100644 --- a/indra/newview/llpanelnearbymedia.h +++ b/indra/newview/llpanelnearbymedia.h @@ -115,7 +115,6 @@ private: void onClickParcelMediaPause(); void onClickParcelAudioPlay(); void onClickParcelAudioStop(); - void onClickParcelAudioStart(); void onClickParcelAudioPause(); void onCheckAutoPlay(); void onAdvancedButtonClick(); 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 diff --git a/indra/newview/llvieweraudio.h b/indra/newview/llvieweraudio.h index e5916285fb..316d7b32d2 100644 --- a/indra/newview/llvieweraudio.h +++ b/indra/newview/llvieweraudio.h @@ -27,6 +27,10 @@ #ifndef LL_VIEWERAUDIO_H #define LL_VIEWERAUDIO_H +#include "llframetimer.h" +#include "llthread.h" +#include "llsingleton.h" + // comment out to turn off wind #define kAUDIO_ENABLE_WIND //#define kAUDIO_ENABLE_WATER 1 // comment out to turn off water @@ -38,4 +42,41 @@ void audio_update_volume(bool force_update = true); void audio_update_listener(); void audio_update_wind(bool force_update = true); +class LLViewerAudio : public LLSingleton +{ +public: + + enum EFadeState + { + FADE_IDLE, + FADE_IN, + FADE_OUT, + }; + + LLViewerAudio(); + virtual ~LLViewerAudio(); + + void startInternetStreamWithAutoFade(std::string streamURI); + void stopInternetStreamWithAutoFade(); + + bool LLViewerAudio::onIdleUpdate(); + + EFadeState getFadeState() { return mFadeState; } + bool isDone() { return mDone; }; + F32 getFadeVolume(); + +private: + + bool mDone; + F32 mFadeTime; + std::string mNextStreamURI; + EFadeState mFadeState; + LLFrameTimer stream_fade_timer; + bool mIdleListnerActive; + + void registerIdleListener(); + void deregisterIdleListener() { mIdleListnerActive = false; }; + void startFading(); +}; + #endif //LL_VIEWER_H diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp index 41b4dc01e8..148bfbf080 100644 --- a/indra/newview/llviewermedia.cpp +++ b/indra/newview/llviewermedia.cpp @@ -66,7 +66,7 @@ //#include "llfirstuse.h" #include "llviewernetwork.h" #include "llwindow.h" - +#include "llvieweraudio.h" #include "llfloatermediabrowser.h" // for handling window close requests and geometry change requests in media browser windows. #include "llfloaterwebcontent.h" // for handling window close requests and geometry change requests in media browser windows. @@ -967,7 +967,7 @@ void LLViewerMedia::updateMedia(void *dummy_arg) { if(LLViewerMedia::isParcelAudioPlaying() && gAudiop && LLViewerMedia::hasParcelAudio()) { - gAudiop->stopInternetStream(); + LLViewerAudio::getInstance()->stopInternetStreamWithAutoFade(); } } pimpl->setPriority(new_priority); @@ -1069,13 +1069,24 @@ void LLViewerMedia::setAllMediaEnabled(bool val) gAudiop && LLViewerMedia::hasParcelAudio()) { - gAudiop->startInternetStream(LLViewerMedia::getParcelAudioURL()); + if (LLAudioEngine::AUDIO_PAUSED == gAudiop->isInternetStreamPlaying()) + { + // 'false' means unpause + gAudiop->pauseInternetStream(false); + } + else + { + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(LLViewerMedia::getParcelAudioURL()); + } } } else { // This actually unloads the impl, as opposed to "stop"ping the media LLViewerParcelMedia::stop(); - if (gAudiop) gAudiop->stopInternetStream(); + if (gAudiop) + { + LLViewerAudio::getInstance()->stopInternetStreamWithAutoFade(); + } } } @@ -1488,8 +1499,7 @@ void LLViewerMedia::setOpenIDCookie() new LLViewerMediaWebProfileResponder(raw_profile_url.getAuthority()), headers); - // FUI: No longer perform the user_status query - //doOnetimeEarlyHTTPRequests(); + doOnetimeEarlyHTTPRequests(); } } diff --git a/indra/newview/llviewerparcelmgr.cpp b/indra/newview/llviewerparcelmgr.cpp index 8db72da1ee..928a84e7eb 100644 --- a/indra/newview/llviewerparcelmgr.cpp +++ b/indra/newview/llviewerparcelmgr.cpp @@ -67,6 +67,7 @@ #include "llworld.h" #include "roles_constants.h" #include "llweb.h" +#include "llvieweraudio.h" const F32 PARCEL_COLLISION_DRAW_SECS = 1.f; @@ -1725,7 +1726,11 @@ void LLViewerParcelMgr::processParcelProperties(LLMessageSystem *msg, void **use } else { - // look for music. + // Check for video + LLViewerParcelMedia::update( parcel ); + + // Then check for music. Do this last, as there may be a delay waiting for + // the stream fading thread to finish. if (gAudiop) { if (parcel) @@ -1736,46 +1741,36 @@ void LLViewerParcelMgr::processParcelProperties(LLMessageSystem *msg, void **use std::string music_url = music_url_raw; LLStringUtil::trim(music_url); - // On entering a new parcel, stop the last stream if the - // new parcel has a different music url. (Empty URL counts - // as different.) const std::string& stream_url = gAudiop->getInternetStreamURL(); - if (music_url.empty() || music_url != stream_url) + // If there is a new music URL and it's valid, play it. + if (music_url.size() > 12) { - // URL is different from one currently playing. - gAudiop->stopInternetStream(); - - // If there is a new music URL and it's valid, play it. - if (music_url.size() > 12) + if (music_url.substr(0,7) == "http://") { - if (music_url.substr(0,7) == "http://") - { - optionally_start_music(music_url); - } - else - { - llinfos << "Stopping parcel music (invalid audio stream URL)" << llendl; - // clears the URL - gAudiop->startInternetStream(LLStringUtil::null); - } + optionally_start_music(music_url); } - else if (!gAudiop->getInternetStreamURL().empty()) + else { - llinfos << "Stopping parcel music (parcel stream URL is empty)" << llendl; - gAudiop->startInternetStream(LLStringUtil::null); + llinfos << "Stopping parcel music (invalid audio stream URL)" << llendl; + // clears the URL + // null value causes fade out + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(LLStringUtil::null); } } + else if (!gAudiop->getInternetStreamURL().empty()) + { + llinfos << "Stopping parcel music (parcel stream URL is empty)" << llendl; + // null value causes fade out + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(LLStringUtil::null); + } } else { // Public land has no music - gAudiop->stopInternetStream(); + LLViewerAudio::getInstance()->stopInternetStreamWithAutoFade(); } }//if gAudiop - - // now check for video - LLViewerParcelMedia::update( parcel ); }; } @@ -1794,7 +1789,11 @@ void optionally_start_music(const std::string& music_url) gSavedSettings.getBOOL("MediaTentativeAutoPlay"))) { llinfos << "Starting parcel music " << music_url << llendl; - gAudiop->startInternetStream(music_url); + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(music_url); + } + else + { + LLViewerAudio::getInstance()->startInternetStreamWithAutoFade(LLStringUtil::null); } } } -- cgit v1.2.3 From 5663f41a7a3dafb4650b49ebc0c86140136239cd Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Fri, 28 Oct 2011 17:54:42 -0400 Subject: STORM-591 Fix minor merge error regression --- indra/newview/llviewermedia.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp index 148bfbf080..a85f70b599 100644 --- a/indra/newview/llviewermedia.cpp +++ b/indra/newview/llviewermedia.cpp @@ -1499,7 +1499,8 @@ void LLViewerMedia::setOpenIDCookie() new LLViewerMediaWebProfileResponder(raw_profile_url.getAuthority()), headers); - doOnetimeEarlyHTTPRequests(); + // FUI: No longer perform the user_status query + //doOnetimeEarlyHTTPRequests(); } } -- 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(-) 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 3aaaae15034b1c0e3099662023bc90d5e447d1ac Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Tue, 8 Nov 2011 15:23:56 -0500 Subject: STORM-591 Audio fading Hopefully fix error in llvieweraudio.h that caused mac and linux compile failure --- indra/newview/llvieweraudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/newview/llvieweraudio.h b/indra/newview/llvieweraudio.h index 316d7b32d2..1663f77f4a 100644 --- a/indra/newview/llvieweraudio.h +++ b/indra/newview/llvieweraudio.h @@ -59,7 +59,7 @@ public: void startInternetStreamWithAutoFade(std::string streamURI); void stopInternetStreamWithAutoFade(); - bool LLViewerAudio::onIdleUpdate(); + bool onIdleUpdate(); EFadeState getFadeState() { return mFadeState; } bool isDone() { return mDone; }; -- cgit v1.2.3 From 57b8da6b4926435f92f0a8568c6ac725774bbbd2 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Fri, 11 Nov 2011 12:22:48 -0500 Subject: STORM-591 Remove dead line of code to fix mac/linux compile error. --- indra/newview/llviewerparcelmgr.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/indra/newview/llviewerparcelmgr.cpp b/indra/newview/llviewerparcelmgr.cpp index 928a84e7eb..ada89cc7aa 100644 --- a/indra/newview/llviewerparcelmgr.cpp +++ b/indra/newview/llviewerparcelmgr.cpp @@ -1741,8 +1741,6 @@ void LLViewerParcelMgr::processParcelProperties(LLMessageSystem *msg, void **use std::string music_url = music_url_raw; LLStringUtil::trim(music_url); - const std::string& stream_url = gAudiop->getInternetStreamURL(); - // If there is a new music URL and it's valid, play it. if (music_url.size() > 12) { -- 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(-) 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/app_settings/settings.xml | 22 ---------------------- indra/newview/llvieweraudio.cpp | 7 +++++-- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index c7300cc1bb..3c53a9d44c 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -192,28 +192,6 @@ Value 1 - AudioMusicFadeIn - - Comment - Fade in time in seconds for music streams - Persist - 1 - Type - F32 - Value - 5.0 - - AudioMusicFadeOut - - Comment - Fade out time in seconds for music streams - Persist - 1 - Type - F32 - Value - 5.0 - AudioLevelAmbient Comment 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 a4cb08ae5d20416e21bbc70540527097495af887 Mon Sep 17 00:00:00 2001 From: Jonathan Yap Date: Wed, 23 Nov 2011 08:42:42 -0500 Subject: STORM-591 Trivial code cleanup --- indra/newview/llvieweraudio.h | 1 - indra/newview/llviewerparcelmgr.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/indra/newview/llvieweraudio.h b/indra/newview/llvieweraudio.h index 1663f77f4a..26062a2818 100644 --- a/indra/newview/llvieweraudio.h +++ b/indra/newview/llvieweraudio.h @@ -28,7 +28,6 @@ #define LL_VIEWERAUDIO_H #include "llframetimer.h" -#include "llthread.h" #include "llsingleton.h" // comment out to turn off wind diff --git a/indra/newview/llviewerparcelmgr.cpp b/indra/newview/llviewerparcelmgr.cpp index ada89cc7aa..c18665a3c3 100644 --- a/indra/newview/llviewerparcelmgr.cpp +++ b/indra/newview/llviewerparcelmgr.cpp @@ -1727,7 +1727,7 @@ void LLViewerParcelMgr::processParcelProperties(LLMessageSystem *msg, void **use else { // Check for video - LLViewerParcelMedia::update( parcel ); + LLViewerParcelMedia::update(parcel); // Then check for music. Do this last, as there may be a delay waiting for // the stream fading thread to finish. -- 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/llpanelnearbymedia.cpp | 20 ++++++++++++--- indra/newview/llvieweraudio.cpp | 50 +++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/indra/newview/llpanelnearbymedia.cpp b/indra/newview/llpanelnearbymedia.cpp index 53fc64f089..c01adc3c35 100644 --- a/indra/newview/llpanelnearbymedia.cpp +++ b/indra/newview/llpanelnearbymedia.cpp @@ -808,14 +808,26 @@ bool LLPanelNearByMedia::setDisabled(const LLUUID &row_id, bool disabled) { if (row_id == PARCEL_AUDIO_LIST_ITEM_UUID) { - if (disabled) onClickParcelAudioStop(); - else onClickParcelAudioPlay(); + if (disabled) + { + onClickParcelAudioStop(); + } + else + { + onClickParcelAudioPlay(); + } return true; } else if (row_id == PARCEL_MEDIA_LIST_ITEM_UUID) { - if (disabled) onClickDisableParcelMedia(); - else onClickEnableParcelMedia(); + if (disabled) + { + onClickDisableParcelMedia(); + } + else + { + onClickEnableParcelMedia(); + } return true; } else { 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 +++++++++++++++++++++++++++++++++---- indra/newview/llvieweraudio.h | 7 ++++++ indra/newview/llviewerparcelmgr.cpp | 3 +-- 3 files changed, 50 insertions(+), 6 deletions(-) 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(); diff --git a/indra/newview/llvieweraudio.h b/indra/newview/llvieweraudio.h index 26062a2818..a3da9fc6b8 100644 --- a/indra/newview/llvieweraudio.h +++ b/indra/newview/llvieweraudio.h @@ -63,6 +63,9 @@ public: EFadeState getFadeState() { return mFadeState; } bool isDone() { return mDone; }; F32 getFadeVolume(); + bool getForcedTeleportFade() { return mForcedTeleportFade; }; + void setForcedTeleportFade(bool fade) { mForcedTeleportFade = fade;} ; + void setNextStreamURI(std::string stream) { mNextStreamURI = stream; } ; private: @@ -72,10 +75,14 @@ private: EFadeState mFadeState; LLFrameTimer stream_fade_timer; bool mIdleListnerActive; + bool mForcedTeleportFade; + boost::signals2::connection mTeleportFailedConnection; void registerIdleListener(); void deregisterIdleListener() { mIdleListnerActive = false; }; void startFading(); + void onTeleportFailed(); + }; #endif //LL_VIEWER_H diff --git a/indra/newview/llviewerparcelmgr.cpp b/indra/newview/llviewerparcelmgr.cpp index c18665a3c3..7ce9672299 100644 --- a/indra/newview/llviewerparcelmgr.cpp +++ b/indra/newview/llviewerparcelmgr.cpp @@ -1729,8 +1729,7 @@ void LLViewerParcelMgr::processParcelProperties(LLMessageSystem *msg, void **use // Check for video LLViewerParcelMedia::update(parcel); - // Then check for music. Do this last, as there may be a delay waiting for - // the stream fading thread to finish. + // Then check for music if (gAudiop) { if (parcel) -- cgit v1.2.3