summaryrefslogtreecommitdiff
path: root/indra/newview/llspeakingindicatormanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llspeakingindicatormanager.cpp')
-rw-r--r--indra/newview/llspeakingindicatormanager.cpp289
1 files changed, 289 insertions, 0 deletions
diff --git a/indra/newview/llspeakingindicatormanager.cpp b/indra/newview/llspeakingindicatormanager.cpp
new file mode 100644
index 0000000000..1c8fc6ac9d
--- /dev/null
+++ b/indra/newview/llspeakingindicatormanager.cpp
@@ -0,0 +1,289 @@
+/**
+ * @file llspeakingindicatormanager.cpp
+ * @author Mike Antipov
+ * @brief Implementation of SpeackerIndicatorManager class to process registered LLSpeackerIndicator
+ * depend on avatars are in the same voice channel.
+ *
+ * $LicenseInfo:firstyear=2010&license=viewergpl$
+ *
+ * Copyright (c) 2010, Linden Research, Inc.
+ *
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab. Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
+ *
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at
+ * http://secondlifegrid.net/programs/open_source/licensing/flossexception
+ *
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ *
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+#include "llviewerprecompiledheaders.h"
+#include "llspeakingindicatormanager.h"
+
+
+#include "llagentdata.h"
+#include "llvoicechannel.h"
+#include "llvoiceclient.h"
+
+/**
+ * This class intended to control visibility of avatar speaking indicators depend on whether avatars
+ * are in the same voice channel.
+ *
+ * Speaking indicator should be visible for avatars in the same voice channel. See EXT-3976.
+ *
+ * It stores passed instances of LLOutputMonitorCtrl in a multimap by avatar LLUUID.
+ * It observes changing of voice channel and changing of participant list in voice channel.
+ * When voice channel or voice participant list is changed it updates visibility of an appropriate
+ * speaking indicator.
+ *
+ * Several indicators can be registered for the same avatar.
+ */
+class SpeakingIndicatorManager : public LLSingleton<SpeakingIndicatorManager>, LLVoiceClientParticipantObserver
+{
+ LOG_CLASS(SpeakingIndicatorManager);
+public:
+
+ /**
+ * Stores passed speaking indicator to control its visibility.
+ *
+ * Registered indicator is set visible if an appropriate avatar is in the same voice channel with Agent.
+ * It ignores instances of Agent's indicator.
+ *
+ * @param speaker_id LLUUID of an avatar whose speaking indicator is registered.
+ * @param speaking_indicator instance of the speaking indicator to be registered.
+ */
+ void registerSpeakingIndicator(const LLUUID& speaker_id, LLSpeakingIndicator* const speaking_indicator);
+
+ /**
+ * Removes passed speaking indicator from observing.
+ *
+ * @param speaker_id LLUUID of an avatar whose speaking indicator should be unregistered.
+ * @param speaking_indicator instance of the speaking indicator to be unregistered.
+ */
+ void unregisterSpeakingIndicator(const LLUUID& speaker_id, const LLSpeakingIndicator* const speaking_indicator);
+
+private:
+ typedef std::vector<LLUUID> speaker_ids_t;
+ typedef std::multimap<LLUUID, LLSpeakingIndicator*> speaking_indicators_mmap_t;
+ typedef speaking_indicators_mmap_t::value_type speaking_indicator_value_t;
+ typedef speaking_indicators_mmap_t::const_iterator indicator_const_iterator;
+ typedef std::pair<indicator_const_iterator, indicator_const_iterator> indicator_range_t;
+
+ friend class LLSingleton<SpeakingIndicatorManager>;
+ SpeakingIndicatorManager();
+ ~SpeakingIndicatorManager();
+
+ /**
+ * Callback to determine when voice channel is changed.
+ *
+ * It switches all registered speaking indicators off.
+ * To reduce overheads only switched on indicators are processed.
+ */
+ void sOnCurrentChannelChanged(const LLUUID& session_id);
+
+ /**
+ * Callback of changing voice participant list (from LLVoiceClientParticipantObserver).
+ *
+ * Switches off indicators had been switched on and switches on indicators of current participants list.
+ * There is only a few indicators in lists should be switched off/on.
+ * So, method does not calculate difference between these list it only switches off already
+ * switched on indicators and switches on indicators of voice channel participants
+ */
+ void onChange();
+
+ /**
+ * Changes state of indicators specified by LLUUIDs
+ *
+ * @param speakers_uuids - avatars' LLUUIDs whose speaking indicators should be switched
+ * @param switch_on - if TRUE specified indicator will be switched on, off otherwise.
+ */
+ void switchSpeakerIndicators(const speaker_ids_t& speakers_uuids, BOOL switch_on);
+
+ /**
+ * Multimap with all registered speaking indicators
+ */
+ speaking_indicators_mmap_t mSpeakingIndicators;
+
+ /**
+ * LUUIDs of avatar for which we have speaking indicators switched on.
+ *
+ * Is used to switch off all previously ON indicators when voice participant list is changed.
+ *
+ * @see onChange()
+ */
+ speaker_ids_t mSwitchedIndicatorsOn;
+};
+
+//////////////////////////////////////////////////////////////////////////
+// PUBLIC SECTION
+//////////////////////////////////////////////////////////////////////////
+void SpeakingIndicatorManager::registerSpeakingIndicator(const LLUUID& speaker_id, LLSpeakingIndicator* const speaking_indicator)
+{
+ if (speaker_id == gAgentID) return;
+
+ LL_DEBUGS("SpeakingIndicator") << "Registering indicator: " << speaker_id << LL_ENDL;
+ speaking_indicator_value_t value_type(speaker_id, speaking_indicator);
+ mSpeakingIndicators.insert(value_type);
+
+ BOOL is_in_same_voice = FALSE;
+
+ // search passed speaker id among a list of voice participants
+ LLVoiceClient::participantMap *voice_map = LLVoiceClient::getInstance()->getParticipantList();
+ if (voice_map)
+ {
+ for (LLVoiceClient::participantMap::const_iterator iter = voice_map->begin();
+ iter != voice_map->end(); ++iter)
+ {
+ const LLUUID id = (*iter).second->mAvatarID;
+
+ if (speaker_id == id)
+ {
+ is_in_same_voice = TRUE;
+ break;
+ }
+
+ }
+ }
+
+ speaker_ids_t speakers_uuids;
+ speakers_uuids.push_back(speaker_id);
+ switchSpeakerIndicators(speakers_uuids, is_in_same_voice);
+}
+
+void SpeakingIndicatorManager::unregisterSpeakingIndicator(const LLUUID& speaker_id, const LLSpeakingIndicator* const speaking_indicator)
+{
+ speaking_indicators_mmap_t::iterator it;
+ it = mSpeakingIndicators.find(speaker_id);
+ for (;it != mSpeakingIndicators.end(); ++it)
+ {
+ if (it->second == speaking_indicator)
+ {
+ mSpeakingIndicators.erase(it);
+ break;
+ }
+ }
+}
+
+//////////////////////////////////////////////////////////////////////////
+// PRIVATE SECTION
+//////////////////////////////////////////////////////////////////////////
+SpeakingIndicatorManager::SpeakingIndicatorManager()
+{
+ LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&SpeakingIndicatorManager::sOnCurrentChannelChanged, this, _1));
+ LLVoiceClient::getInstance()->addObserver(this);
+}
+
+SpeakingIndicatorManager::~SpeakingIndicatorManager()
+{
+ // Don't use LLVoiceClient::getInstance() here without check
+ // singleton MAY have already been destroyed.
+ if(LLVoiceClient::instanceExists())
+ {
+ LLVoiceClient::getInstance()->removeObserver(this);
+ }
+}
+
+void SpeakingIndicatorManager::sOnCurrentChannelChanged(const LLUUID& /*session_id*/)
+{
+ switchSpeakerIndicators(mSwitchedIndicatorsOn, FALSE);
+ mSwitchedIndicatorsOn.clear();
+}
+
+void SpeakingIndicatorManager::onChange()
+{
+ LL_DEBUGS("SpeakingIndicator") << "Voice participant list was changed, updating indicators" << LL_ENDL;
+
+ speaker_ids_t speakers_uuids;
+ // Get a list of participants from VoiceClient
+ LLVoiceClient::participantMap *voice_map = gVoiceClient->getParticipantList();
+ if (voice_map)
+ {
+ for (LLVoiceClient::participantMap::const_iterator iter = voice_map->begin();
+ iter != voice_map->end(); ++iter)
+ {
+ LLUUID id = (*iter).second->mAvatarID;
+
+ if (id == gAgentID) continue;
+
+ speakers_uuids.push_back(id);
+ }
+ }
+
+ LL_DEBUGS("SpeakingIndicator") << "Switching all OFF, count: " << mSwitchedIndicatorsOn.size() << LL_ENDL;
+
+ // switch all indicators off
+ switchSpeakerIndicators(mSwitchedIndicatorsOn, FALSE);
+ mSwitchedIndicatorsOn.clear();
+
+ LL_DEBUGS("SpeakingIndicator") << "Switching all ON, count: " << speakers_uuids.size() << LL_ENDL;
+ // then switch current voice participants indicators on
+ switchSpeakerIndicators(speakers_uuids, TRUE);
+}
+
+void SpeakingIndicatorManager::switchSpeakerIndicators(const speaker_ids_t& speakers_uuids, BOOL switch_on)
+{
+ speaker_ids_t::const_iterator it_uuid = speakers_uuids.begin();
+ for (; it_uuid != speakers_uuids.end(); ++it_uuid)
+ {
+ LL_DEBUGS("SpeakingIndicator") << "Looking for indicator: " << *it_uuid << LL_ENDL;
+ indicator_range_t it_range = mSpeakingIndicators.equal_range(*it_uuid);
+ indicator_const_iterator it_indicator = it_range.first;
+ bool was_found = false;
+ for (; it_indicator != it_range.second; ++it_indicator)
+ {
+ was_found = true;
+ LLSpeakingIndicator* indicator = (*it_indicator).second;
+ indicator->switchIndicator(switch_on);
+ }
+
+ if (was_found)
+ {
+ LL_DEBUGS("SpeakingIndicator") << mSpeakingIndicators.count(*it_uuid) << " indicators where found" << LL_ENDL;
+
+ if (switch_on)
+ {
+ // TODO: probably std::set will be better
+ // if (mSwitchedIndicatorsOn.find(*it_uuid) == mSwitchedIndicatorsOn.end())
+ {
+ mSwitchedIndicatorsOn.push_back(*it_uuid);
+ }
+ }
+ }
+ else
+ {
+ LL_WARNS("SpeakingIndicator") << "indicator was not found among registered: " << *it_uuid << LL_ENDL;
+ }
+ }
+}
+
+/************************************************************************/
+/* LLSpeakingIndicatorManager namespace implementation */
+/************************************************************************/
+
+void LLSpeakingIndicatorManager::registerSpeakingIndicator(const LLUUID& speaker_id, LLSpeakingIndicator* const speaking_indicator)
+{
+ SpeakingIndicatorManager::instance().registerSpeakingIndicator(speaker_id, speaking_indicator);
+}
+
+void LLSpeakingIndicatorManager::unregisterSpeakingIndicator(const LLUUID& speaker_id, const LLSpeakingIndicator* const speaking_indicator)
+{
+ SpeakingIndicatorManager::instance().unregisterSpeakingIndicator(speaker_id, speaking_indicator);
+}
+
+// EOF
+