summaryrefslogtreecommitdiff
path: root/indra/newview/llvoicewebrtc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llvoicewebrtc.cpp')
-rw-r--r--indra/newview/llvoicewebrtc.cpp83
1 files changed, 68 insertions, 15 deletions
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index ff3c0eccd2..06baea4ba2 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -238,11 +238,26 @@ LLWebRTCVoiceClient::LLWebRTCVoiceClient() :
LLWebRTCVoiceClient::~LLWebRTCVoiceClient()
{
+}
+
+void LLWebRTCVoiceClient::cleanupSingleton()
+{
if (mAvatarNameCacheConnection.connected())
{
mAvatarNameCacheConnection.disconnect();
}
+
sShuttingDown = true;
+ if (mSession)
+ {
+ mSession->shutdownAllConnections();
+ }
+ if (mNextSession)
+ {
+ mNextSession->shutdownAllConnections();
+ }
+ cleanUp();
+ sessionState::clearSessions();
}
//---------------------------------------------------
@@ -656,6 +671,10 @@ void LLWebRTCVoiceClient::OnDevicesChanged(const llwebrtc::LLWebRTCVoiceDeviceLi
void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDeviceList &render_devices,
const llwebrtc::LLWebRTCVoiceDeviceList &capture_devices)
{
+ if (sShuttingDown)
+ {
+ return;
+ }
LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
std::string inputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
std::string outputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
@@ -1704,7 +1723,7 @@ void LLWebRTCVoiceClient::predSetUserMute(const LLWebRTCVoiceClient::sessionStat
//------------------------------------------------------------------------
// Sessions
-std::map<std::string, LLWebRTCVoiceClient::sessionState::ptr_t> LLWebRTCVoiceClient::sessionState::mSessions;
+std::map<std::string, LLWebRTCVoiceClient::sessionState::ptr_t> LLWebRTCVoiceClient::sessionState::sSessions;
LLWebRTCVoiceClient::sessionState::sessionState() :
@@ -1791,13 +1810,19 @@ void LLWebRTCVoiceClient::sessionState::addSession(
const std::string & channelID,
LLWebRTCVoiceClient::sessionState::ptr_t& session)
{
- mSessions[channelID] = session;
+ sSessions[channelID] = session;
}
LLWebRTCVoiceClient::sessionState::~sessionState()
{
LL_DEBUGS("Voice") << "Destroying session CHANNEL=" << mChannelID << LL_ENDL;
+ if (!mShuttingDown)
+ {
+ shutdownAllConnections();
+ }
+ mWebRTCConnections.clear();
+
removeAllParticipants();
}
@@ -1807,8 +1832,8 @@ LLWebRTCVoiceClient::sessionState::ptr_t LLWebRTCVoiceClient::sessionState::matc
sessionStatePtr_t result;
// *TODO: My kingdom for a lambda!
- std::map<std::string, ptr_t>::iterator it = mSessions.find(channel_id);
- if (it != mSessions.end())
+ std::map<std::string, ptr_t>::iterator it = sSessions.find(channel_id);
+ if (it != sSessions.end())
{
result = (*it).second;
}
@@ -1817,17 +1842,17 @@ LLWebRTCVoiceClient::sessionState::ptr_t LLWebRTCVoiceClient::sessionState::matc
void LLWebRTCVoiceClient::sessionState::for_each(sessionFunc_t func)
{
- std::for_each(mSessions.begin(), mSessions.end(), boost::bind(for_eachPredicate, _1, func));
+ std::for_each(sSessions.begin(), sSessions.end(), boost::bind(for_eachPredicate, _1, func));
}
void LLWebRTCVoiceClient::sessionState::reapEmptySessions()
{
std::map<std::string, ptr_t>::iterator iter;
- for (iter = mSessions.begin(); iter != mSessions.end();)
+ for (iter = sSessions.begin(); iter != sSessions.end();)
{
if (iter->second->isEmpty())
{
- iter = mSessions.erase(iter);
+ iter = sSessions.erase(iter);
}
else
{
@@ -1873,6 +1898,11 @@ LLWebRTCVoiceClient::sessionStatePtr_t LLWebRTCVoiceClient::addSession(const std
}
}
+void LLWebRTCVoiceClient::sessionState::clearSessions()
+{
+ sSessions.clear();
+}
+
LLWebRTCVoiceClient::sessionStatePtr_t LLWebRTCVoiceClient::findP2PSession(const LLUUID &agent_id)
{
sessionStatePtr_t result = sessionState::matchSessionByChannelID(agent_id.asString());
@@ -1912,14 +1942,14 @@ void LLWebRTCVoiceClient::sessionState::processSessionStates()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
- auto iter = mSessions.begin();
- while (iter != mSessions.end())
+ auto iter = sSessions.begin();
+ while (iter != sSessions.end())
{
if (!iter->second->processConnectionStates() && iter->second->mShuttingDown)
{
// if the connections associated with a session are gone,
// and this session is shutting down, remove it.
- iter = mSessions.erase(iter);
+ iter = sSessions.erase(iter);
}
else
{
@@ -2367,6 +2397,12 @@ void LLVoiceWebRTCConnection::OnPeerConnectionClosed()
setVoiceConnectionState(VOICE_STATE_CLOSED);
mOutstandingRequests--;
}
+ else if (LLWebRTCVoiceClient::isShuttingDown())
+ {
+ // disconnect was initialized by llwebrtc::terminate() instead of connectionStateMachine
+ LL_INFOS("Voice") << "Peer connection has closed, but state is " << mVoiceConnectionState << LL_ENDL;
+ setVoiceConnectionState(VOICE_STATE_CLOSED);
+ }
});
}
@@ -2481,7 +2517,11 @@ void LLVoiceWebRTCConnection::breakVoiceConnectionCoro(connectionPtr_t connectio
LLSD result = httpAdapter->postAndSuspend(httpRequest, url, body, httpOpts);
connection->mOutstandingRequests--;
- connection->setVoiceConnectionState(VOICE_STATE_SESSION_EXIT);
+
+ if (connection->getVoiceConnectionState() == VOICE_STATE_WAIT_FOR_EXIT)
+ {
+ connection->setVoiceConnectionState(VOICE_STATE_SESSION_EXIT);
+ }
}
// Tell the simulator to tell the Secondlife WebRTC server that we want a voice
@@ -2743,9 +2783,18 @@ bool LLVoiceWebRTCConnection::connectionStateMachine()
break;
case VOICE_STATE_DISCONNECT:
- setVoiceConnectionState(VOICE_STATE_WAIT_FOR_EXIT);
- LLCoros::instance().launch("LLVoiceWebRTCConnection::breakVoiceConnectionCoro",
- boost::bind(&LLVoiceWebRTCConnection::breakVoiceConnectionCoro, this->shared_from_this()));
+ if (!LLWebRTCVoiceClient::isShuttingDown())
+ {
+ setVoiceConnectionState(VOICE_STATE_WAIT_FOR_EXIT);
+ LLCoros::instance().launch("LLVoiceWebRTCConnection::breakVoiceConnectionCoro",
+ boost::bind(&LLVoiceWebRTCConnection::breakVoiceConnectionCoro, this->shared_from_this()));
+ }
+ else
+ {
+ // llwebrtc::terminate() is already shuting down the connection.
+ setVoiceConnectionState(VOICE_STATE_WAIT_FOR_CLOSE);
+ mOutstandingRequests++;
+ }
break;
case VOICE_STATE_WAIT_FOR_EXIT:
@@ -2755,7 +2804,11 @@ bool LLVoiceWebRTCConnection::connectionStateMachine()
{
setVoiceConnectionState(VOICE_STATE_WAIT_FOR_CLOSE);
mOutstandingRequests++;
- mWebRTCPeerConnectionInterface->shutdownConnection();
+ if (!LLWebRTCVoiceClient::isShuttingDown())
+ {
+ mWebRTCPeerConnectionInterface->shutdownConnection();
+ }
+ // else was already posted by llwebrtc::terminate().
break;
case VOICE_STATE_WAIT_FOR_CLOSE:
break;