summaryrefslogtreecommitdiff
path: root/indra/newview/llvoicevivox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llvoicevivox.cpp')
-rw-r--r--indra/newview/llvoicevivox.cpp105
1 files changed, 64 insertions, 41 deletions
diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp
index c73f96da2d..1b9aef193c 100644
--- a/indra/newview/llvoicevivox.cpp
+++ b/indra/newview/llvoicevivox.cpp
@@ -276,13 +276,13 @@ static void killGateway()
///////////////////////////////////////////////////////////////////////////////////////////////
bool LLVivoxVoiceClient::sShuttingDown = false;
+bool LLVivoxVoiceClient::sConnected = false;
+LLPumpIO *LLVivoxVoiceClient::sPump = nullptr;
LLVivoxVoiceClient::LLVivoxVoiceClient() :
mSessionTerminateRequested(false),
mRelogRequested(false),
- mConnected(false),
mTerminateDaemon(false),
- mPump(NULL),
mSpatialJoiningNum(0),
mTuningMode(false),
@@ -350,7 +350,11 @@ LLVivoxVoiceClient::LLVivoxVoiceClient() :
mIsProcessingChannels(false),
mIsCoroutineActive(false),
mVivoxPump("vivoxClientPump")
-{
+{
+ sShuttingDown = false;
+ sConnected = false;
+ sPump = nullptr;
+
mSpeakerVolume = scale_speaker_volume(0);
mVoiceVersion.serverVersion = "";
@@ -392,7 +396,7 @@ LLVivoxVoiceClient::~LLVivoxVoiceClient()
void LLVivoxVoiceClient::init(LLPumpIO *pump)
{
// constructor will set up LLVoiceClient::getInstance()
- mPump = pump;
+ sPump = pump;
// LLCoros::instance().launch("LLVivoxVoiceClient::voiceControlCoro",
// boost::bind(&LLVivoxVoiceClient::voiceControlCoro, LLVivoxVoiceClient::getInstance()));
@@ -413,10 +417,10 @@ void LLVivoxVoiceClient::terminate()
logoutOfVivox(false);
}
- if(mConnected)
+ if(sConnected)
{
breakVoiceConnection(false);
- mConnected = false;
+ sConnected = false;
}
else
{
@@ -425,7 +429,7 @@ void LLVivoxVoiceClient::terminate()
}
sShuttingDown = true;
- mPump = NULL;
+ sPump = NULL;
}
//---------------------------------------------------
@@ -471,7 +475,7 @@ bool LLVivoxVoiceClient::writeString(const std::string &str)
bool result = false;
LL_DEBUGS("LowVoice") << "sending:\n" << str << LL_ENDL;
- if(mConnected)
+ if(sConnected)
{
apr_status_t err;
apr_size_t size = (apr_size_t)str.size();
@@ -947,32 +951,52 @@ bool LLVivoxVoiceClient::startAndLaunchDaemon()
// cause SLVoice's bind() call to fail with EADDRINUSE. We expect
// that eventually the OS will time out previous ports, which is
// why we cycle instead of incrementing indefinitely.
- U32 portbase = gSavedSettings.getU32("VivoxVoicePort");
- static U32 portoffset = 0;
+
+ static LLCachedControl<U32> portbase(gSavedSettings, "VivoxVoicePort");
+ static LLCachedControl<std::string> host(gSavedSettings, "VivoxVoiceHost");
+ static LLCachedControl<std::string> loglevel(gSavedSettings, "VivoxDebugLevel");
+ static LLCachedControl<std::string> log_folder(gSavedSettings, "VivoxLogDirectory");
+ static LLCachedControl<std::string> shutdown_timeout(gSavedSettings, "VivoxShutdownTimeout");
static const U32 portrange = 100;
- std::string host(gSavedSettings.getString("VivoxVoiceHost"));
- U32 port = portbase + portoffset;
+ static U32 portoffset = 0;
+ U32 port = 0;
+
+ if (LLAppViewer::instance()->isSecondInstance())
+ {
+ // Ideally need to know amount of instances and
+ // to increment instance_offset on EADDRINUSE.
+ // But for now just use rand
+ static U32 instance_offset = portrange * ll_rand(20);
+ port = portbase + portoffset + instance_offset;
+ }
+ else
+ {
+ // leave main thread with exclusive port set
+ port = portbase + portoffset;
+ }
portoffset = (portoffset + 1) % portrange;
params.args.add("-i");
- params.args.add(STRINGIZE(host << ':' << port));
+ params.args.add(STRINGIZE(host() << ':' << port));
- std::string loglevel = gSavedSettings.getString("VivoxDebugLevel");
- if (loglevel.empty())
+ params.args.add("-ll");
+ if (loglevel().empty())
{
- loglevel = "0";
+ params.args.add("0");
}
- params.args.add("-ll");
- params.args.add(loglevel);
-
- std::string log_folder = gSavedSettings.getString("VivoxLogDirectory");
-
- if (log_folder.empty())
+ else
{
- log_folder = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "");
+ params.args.add(loglevel);
}
params.args.add("-lf");
- params.args.add(log_folder);
+ if (log_folder().empty())
+ {
+ params.args.add(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ""));
+ }
+ else
+ {
+ params.args.add(log_folder);
+ }
// set log file basename and .log
params.args.add("-lp");
@@ -988,8 +1012,7 @@ bool LLVivoxVoiceClient::startAndLaunchDaemon()
LLFile::rename(new_log, old_log);
}
- std::string shutdown_timeout = gSavedSettings.getString("VivoxShutdownTimeout");
- if (!shutdown_timeout.empty())
+ if (!shutdown_timeout().empty())
{
params.args.add("-st");
params.args.add(shutdown_timeout);
@@ -1012,7 +1035,7 @@ bool LLVivoxVoiceClient::startAndLaunchDaemon()
sGatewayPtr = LLProcess::create(params);
- mDaemonHost = LLHost(host.c_str(), port);
+ mDaemonHost = LLHost(host().c_str(), port);
}
else
{
@@ -1051,7 +1074,7 @@ bool LLVivoxVoiceClient::startAndLaunchDaemon()
int retryCount(0);
LLVoiceVivoxStats::getInstance()->reset();
- while (!mConnected && !sShuttingDown && retryCount++ <= DAEMON_CONNECT_RETRY_MAX)
+ while (!sConnected && !sShuttingDown && retryCount++ <= DAEMON_CONNECT_RETRY_MAX)
{
LLVoiceVivoxStats::getInstance()->connectionAttemptStart();
LL_DEBUGS("Voice") << "Attempting to connect to vivox daemon: " << mDaemonHost << LL_ENDL;
@@ -1061,23 +1084,23 @@ bool LLVivoxVoiceClient::startAndLaunchDaemon()
mSocket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
}
- mConnected = mSocket->blockingConnect(mDaemonHost);
- LLVoiceVivoxStats::getInstance()->connectionAttemptEnd(mConnected);
- if (!mConnected)
+ sConnected = mSocket->blockingConnect(mDaemonHost);
+ LLVoiceVivoxStats::getInstance()->connectionAttemptEnd(sConnected);
+ if (!sConnected)
{
llcoro::suspendUntilTimeout(DAEMON_CONNECT_THROTTLE_SECONDS);
}
}
//---------------------------------------------------------------------
- if (sShuttingDown && !mConnected)
+ if (sShuttingDown && !sConnected)
{
return false;
}
llcoro::suspendUntilTimeout(UPDATE_THROTTLE_SECONDS);
- while (!mPump && !sShuttingDown)
+ while (!sPump && !sShuttingDown)
{ // Can't use the pump until we have it available.
llcoro::suspend();
}
@@ -1099,7 +1122,7 @@ bool LLVivoxVoiceClient::startAndLaunchDaemon()
readChain.push_back(LLIOPipe::ptr_t(new LLVivoxProtocolParser()));
- mPump->addChain(readChain, NEVER_CHAIN_EXPIRY_SECS);
+ sPump->addChain(readChain, NEVER_CHAIN_EXPIRY_SECS);
//---------------------------------------------------------------------
@@ -1321,9 +1344,9 @@ bool LLVivoxVoiceClient::breakVoiceConnection(bool corowait)
// the message, yet we need to receive "connector shutdown response".
// Either wait a bit and emulate it or check gMessageSystem for specific message
_sleep(1000);
- if (mConnected)
+ if (sConnected)
{
- mConnected = false;
+ sConnected = false;
LLSD vivoxevent(LLSDMap("connector", LLSD::Boolean(false)));
mVivoxPump.post(vivoxevent);
}
@@ -1335,7 +1358,7 @@ bool LLVivoxVoiceClient::breakVoiceConnection(bool corowait)
LL_DEBUGS("Voice") << "closing SLVoice socket" << LL_ENDL;
closeSocket(); // Need to do this now -- bad things happen if the destructor does it later.
cleanUp();
- mConnected = false;
+ sConnected = false;
return retval;
}
@@ -2516,7 +2539,7 @@ bool LLVivoxVoiceClient::performMicTuning()
void LLVivoxVoiceClient::closeSocket(void)
{
mSocket.reset();
- mConnected = false;
+ sConnected = false;
mConnectorEstablished = false;
mAccountLoggedIn = false;
}
@@ -3017,7 +3040,7 @@ bool LLVivoxVoiceClient::deviceSettingsAvailable()
{
bool result = true;
- if(!mConnected)
+ if(!sConnected)
result = false;
if(mRenderDevices.empty())
@@ -3816,7 +3839,7 @@ void LLVivoxVoiceClient::connectorShutdownResponse(int statusCode, std::string &
// Should this ever fail? do we care if it does?
}
- mConnected = false;
+ sConnected = false;
mShutdownComplete = true;
LLSD vivoxevent(LLSDMap("connector", LLSD::Boolean(false)));
@@ -7389,7 +7412,7 @@ LLIOPipe::EStatus LLVivoxProtocolParser::process_impl(
LL_DEBUGS("VivoxProtocolParser") << "at end, mInput is: " << mInput << LL_ENDL;
- if(!LLVivoxVoiceClient::getInstance()->mConnected)
+ if(!LLVivoxVoiceClient::sConnected)
{
// If voice has been disabled, we just want to close the socket. This does so.
LL_INFOS("Voice") << "returning STATUS_STOP" << LL_ENDL;