diff options
author | Roxanne Skelly <roxie@lindenlab.com> | 2024-05-02 22:24:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 22:24:59 -0700 |
commit | cce51e98b188371fa864291f943452188d0e0a94 (patch) | |
tree | 75bf206410bff1c655a15dd80ca05abdab81f581 /indra/newview | |
parent | 7cdc327de9df4773f933e1e558eb79c9aabfa787 (diff) | |
parent | 05b2dd913fcb1c5485ce19885e4e60f26752e6b0 (diff) |
Merge pull request #1390 from secondlife/roxie/webrtc-voice
[WebRTC] Remove old region's participants when transiting to a new region.
Diffstat (limited to 'indra/newview')
-rw-r--r-- | indra/newview/llvoicewebrtc.cpp | 87 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.h | 15 |
2 files changed, 66 insertions, 36 deletions
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp index 87106ba6d5..ddbe2eb552 100644 --- a/indra/newview/llvoicewebrtc.cpp +++ b/indra/newview/llvoicewebrtc.cpp @@ -553,6 +553,7 @@ void LLWebRTCVoiceClient::updateNeighboringRegions() // Estate voice requires connection to neighboring regions. mNeighboringRegions.clear(); + // add current region. mNeighboringRegions.insert(gAgent.getRegion()->getRegionID()); // base off of speaker position as it'll move more slowly than camera position. @@ -810,9 +811,12 @@ void LLWebRTCVoiceClient::OnConnectionEstablished(const std::string &channelID, } mSession = mNextSession; mNextSession.reset(); + } + if (mSession) + { // Add ourselves as a participant. - mSession->addParticipant(gAgentID); + mSession->addParticipant(gAgentID, gAgent.getRegion()->getRegionID()); } // The current session was established. @@ -833,14 +837,19 @@ void LLWebRTCVoiceClient::OnConnectionEstablished(const std::string &channelID, void LLWebRTCVoiceClient::OnConnectionShutDown(const std::string &channelID, const LLUUID ®ionID) { - if (gAgent.getRegion()->getRegionID() == regionID) + if (mSession && (mSession->mChannelID == channelID)) { - if (mSession && mSession->mChannelID == channelID) + if (gAgent.getRegion()->getRegionID() == regionID) { - LL_DEBUGS("Voice") << "Main WebRTC Connection Shut Down." << LL_ENDL; + if (mSession && mSession->mChannelID == channelID) + { + LL_DEBUGS("Voice") << "Main WebRTC Connection Shut Down." << LL_ENDL; + } } + mSession->removeAllParticipants(regionID); } } + void LLWebRTCVoiceClient::OnConnectionFailure(const std::string &channelID, const LLUUID ®ionID, LLVoiceClientStatusObserver::EStatusType status_type) @@ -916,6 +925,13 @@ void LLWebRTCVoiceClient::updatePosition(void) enforceTether(); updateNeighboringRegions(); + + // update own region id to be the region id avatar is currently in. + LLWebRTCVoiceClient::participantStatePtr_t participant = findParticipantByID("Estate", gAgentID); + if(participant) + { + participant->mRegion = gAgent.getRegion()->getRegionID(); + } } } @@ -1092,13 +1108,13 @@ LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::findParticipantB return result; } -LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::addParticipantByID(const std::string &channelID, const LLUUID &id) +LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::addParticipantByID(const std::string &channelID, const LLUUID &id, const LLUUID& region) { participantStatePtr_t result; LLWebRTCVoiceClient::sessionState::ptr_t session = sessionState::matchSessionByChannelID(channelID); if (session) { - result = session->addParticipant(id); + result = session->addParticipant(id, region); if (session->mNotifyOnFirstJoin && (id != gAgentID)) { notifyStatusObservers(LLVoiceClientStatusObserver::STATUS_JOINED); @@ -1107,7 +1123,7 @@ LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::addParticipantBy return result; } -void LLWebRTCVoiceClient::removeParticipantByID(const std::string &channelID, const LLUUID &id) +void LLWebRTCVoiceClient::removeParticipantByID(const std::string &channelID, const LLUUID &id, const LLUUID& region) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE @@ -1116,7 +1132,7 @@ void LLWebRTCVoiceClient::removeParticipantByID(const std::string &channelID, co if (session) { participantStatePtr_t participant = session->findParticipantByID(id); - if (participant) + if (participant && (participant->mRegion == region)) { session->removeParticipant(participant); } @@ -1125,17 +1141,18 @@ void LLWebRTCVoiceClient::removeParticipantByID(const std::string &channelID, co // participantState level participant management -LLWebRTCVoiceClient::participantState::participantState(const LLUUID& agent_id) : +LLWebRTCVoiceClient::participantState::participantState(const LLUUID& agent_id, const LLUUID& region) : mURI(agent_id.asString()), mAvatarID(agent_id), mIsSpeaking(false), mIsModeratorMuted(false), mLevel(0.f), - mVolume(LLVoiceClient::VOLUME_DEFAULT) + mVolume(LLVoiceClient::VOLUME_DEFAULT), + mRegion(region) { } -LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::addParticipant(const LLUUID& agent_id) +LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::addParticipant(const LLUUID& agent_id, const LLUUID& region) { LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE @@ -1147,26 +1164,27 @@ LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::ad if (iter != mParticipantsByUUID.end()) { result = iter->second; + result->mRegion = region; } - if(!result) + if (!result) { // participant isn't already in one list or the other. - result.reset(new participantState(agent_id)); + result.reset(new participantState(agent_id, region)); mParticipantsByUUID.insert(participantUUIDMap::value_type(agent_id, result)); - result->mAvatarID = agent_id; + result->mAvatarID = agent_id; + } - LLWebRTCVoiceClient::getInstance()->lookupName(agent_id); + LLWebRTCVoiceClient::getInstance()->lookupName(agent_id); - LLSpeakerVolumeStorage::getInstance()->getSpeakerVolume(result->mAvatarID, result->mVolume); - if (!LLWebRTCVoiceClient::sShuttingDown) - { - LLWebRTCVoiceClient::getInstance()->notifyParticipantObservers(); - } - - LL_DEBUGS("Voice") << "Participant \"" << result->mURI << "\" added." << LL_ENDL; + LLSpeakerVolumeStorage::getInstance()->getSpeakerVolume(result->mAvatarID, result->mVolume); + if (!LLWebRTCVoiceClient::sShuttingDown) + { + LLWebRTCVoiceClient::getInstance()->notifyParticipantObservers(); } + LL_DEBUGS("Voice") << "Participant \"" << result->mURI << "\" added." << LL_ENDL; + return result; } @@ -1218,13 +1236,20 @@ void LLWebRTCVoiceClient::sessionState::removeParticipant(const LLWebRTCVoiceCli } } -void LLWebRTCVoiceClient::sessionState::removeAllParticipants() +void LLWebRTCVoiceClient::sessionState::removeAllParticipants(const LLUUID ®ion) { - LL_DEBUGS("Voice") << "called" << LL_ENDL; + std::vector<participantStatePtr_t> participantsToRemove; - while (!mParticipantsByUUID.empty()) + for (auto& participantEntry : mParticipantsByUUID) { - removeParticipant(mParticipantsByUUID.begin()->second); + if (region.isNull() || (participantEntry.second->mRegion == region)) + { + participantsToRemove.push_back(participantEntry.second); + } + } + for (auto& participant : participantsToRemove) + { + removeParticipant(participant); } } @@ -2671,7 +2696,11 @@ bool LLVoiceWebRTCConnection::connectionStateMachine() { sendJoin(); // tell the Secondlife WebRTC server that we're here via the data channel. setVoiceConnectionState(VOICE_STATE_SESSION_UP); - LLWebRTCVoiceClient::getInstance()->sendPositionUpdate(true); + if (isSpatial()) + { + LLWebRTCVoiceClient::getInstance()->updatePosition(); + LLWebRTCVoiceClient::getInstance()->sendPositionUpdate(true); + } } break; } @@ -2836,7 +2865,7 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b new_participant |= joined; if (!participant && joined && (primary || !isSpatial())) { - participant = LLWebRTCVoiceClient::getInstance()->addParticipantByID(mChannelID, agent_id); + participant = LLWebRTCVoiceClient::getInstance()->addParticipantByID(mChannelID, agent_id, mRegionID); } if (participant) @@ -2846,7 +2875,7 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b // an existing participant is leaving. if (agent_id != gAgentID) { - LLWebRTCVoiceClient::getInstance()->removeParticipantByID(mChannelID, agent_id); + LLWebRTCVoiceClient::getInstance()->removeParticipantByID(mChannelID, agent_id, mRegionID); } } else diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h index 67e4a4ea6f..c417dfe329 100644 --- a/indra/newview/llvoicewebrtc.h +++ b/indra/newview/llvoicewebrtc.h @@ -201,7 +201,8 @@ public: void OnConnectionFailure(const std::string &channelID, const LLUUID ®ionID, LLVoiceClientStatusObserver::EStatusType status_type = LLVoiceClientStatusObserver::ERROR_UNKNOWN); - void sendPositionUpdate(bool force); + void updatePosition(void); // update the internal position state + void sendPositionUpdate(bool force); // send the position to the voice server. void updateOwnVolume(); ////////////////////////////// @@ -228,7 +229,7 @@ public: struct participantState { public: - participantState(const LLUUID& agent_id); + participantState(const LLUUID& agent_id, const LLUUID& region); bool isAvatar(); @@ -240,12 +241,13 @@ public: F32 mVolume; // the gain applied to the participant bool mIsSpeaking; bool mIsModeratorMuted; + LLUUID mRegion; }; typedef boost::shared_ptr<participantState> participantStatePtr_t; participantStatePtr_t findParticipantByID(const std::string &channelID, const LLUUID &id); - participantStatePtr_t addParticipantByID(const std::string& channelID, const LLUUID &id); - void removeParticipantByID(const std::string& channelID, const LLUUID &id); + participantStatePtr_t addParticipantByID(const std::string& channelID, const LLUUID &id, const LLUUID& region); + void removeParticipantByID(const std::string& channelID, const LLUUID &id, const LLUUID& region); protected: @@ -262,9 +264,9 @@ public: static void addSession(const std::string &channelID, ptr_t& session); virtual ~sessionState(); - participantStatePtr_t addParticipant(const LLUUID& agent_id); + participantStatePtr_t addParticipant(const LLUUID& agent_id, const LLUUID& region); void removeParticipant(const participantStatePtr_t &participant); - void removeAllParticipants(); + void removeAllParticipants(const LLUUID& region = LLUUID()); participantStatePtr_t findParticipantByID(const LLUUID& id); @@ -397,7 +399,6 @@ public: ///////////////////////////// // Sending updates of current state - void updatePosition(void); void setListenerPosition(const LLVector3d &position, const LLVector3 &velocity, const LLQuaternion &rot); void setAvatarPosition(const LLVector3d &position, const LLVector3 &velocity, const LLQuaternion &rot); |