PageRenderTime 32ms CodeModel.GetById 11ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llspeakers.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 338 lines | 168 code | 52 blank | 118 comment | 0 complexity | 01752ecfaccd1836aa7c639102632350 MD5 | raw file
  1/** 
  2 * @file llspeakers.h
  3 * @brief Management interface for muting and controlling volume of residents currently speaking
  4 *
  5 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LLSPEAKERS_H
 28#define LL_LLSPEAKERS_H
 29
 30#include "llevent.h"
 31#include "lleventtimer.h"
 32#include "llspeakers.h"
 33#include "llvoicechannel.h"
 34
 35class LLSpeakerMgr;
 36
 37// data for a given participant in a voice channel
 38class LLSpeaker : public LLRefCount, public LLOldEvents::LLObservable, public LLHandleProvider<LLSpeaker>, public boost::signals2::trackable
 39{
 40public:
 41	typedef enum e_speaker_type
 42	{
 43		SPEAKER_AGENT,
 44		SPEAKER_OBJECT,
 45		SPEAKER_EXTERNAL	// Speaker that doesn't map to an avatar or object (i.e. PSTN caller in a group)
 46	} ESpeakerType;
 47
 48	typedef enum e_speaker_status
 49	{
 50		STATUS_SPEAKING,
 51		STATUS_HAS_SPOKEN,
 52		STATUS_VOICE_ACTIVE,
 53		STATUS_TEXT_ONLY,
 54		STATUS_NOT_IN_CHANNEL,
 55		STATUS_MUTED
 56	} ESpeakerStatus;
 57
 58
 59	LLSpeaker(const LLUUID& id, const std::string& name = LLStringUtil::null, const ESpeakerType type = SPEAKER_AGENT);
 60	~LLSpeaker() {};
 61	void lookupName();
 62
 63	void onNameCache(const LLUUID& id, const std::string& full_name, bool is_group);
 64
 65	bool isInVoiceChannel();
 66
 67	ESpeakerStatus	mStatus;			// current activity status in speech group
 68	F32				mLastSpokeTime;		// timestamp when this speaker last spoke
 69	F32				mSpeechVolume;		// current speech amplitude (timea average rms amplitude?)
 70	std::string		mDisplayName;		// cache user name for this speaker
 71	BOOL			mHasSpoken;			// has this speaker said anything this session?
 72	BOOL			mHasLeftCurrentCall;	// has this speaker left the current voice call?
 73	LLColor4		mDotColor;
 74	LLUUID			mID;
 75	BOOL			mTyping;
 76	S32				mSortIndex;
 77	ESpeakerType	mType;
 78	BOOL			mIsModerator;
 79	BOOL			mModeratorMutedVoice;
 80	BOOL			mModeratorMutedText;
 81};
 82
 83class LLSpeakerUpdateModeratorEvent : public LLOldEvents::LLEvent
 84{
 85public:
 86	LLSpeakerUpdateModeratorEvent(LLSpeaker* source);
 87	/*virtual*/ LLSD getValue();
 88private:
 89	const LLUUID& mSpeakerID;
 90	BOOL mIsModerator;
 91};
 92
 93class LLSpeakerTextModerationEvent : public LLOldEvents::LLEvent
 94{
 95public:
 96	LLSpeakerTextModerationEvent(LLSpeaker* source);
 97	/*virtual*/ LLSD getValue();
 98};
 99
100class LLSpeakerVoiceModerationEvent : public LLOldEvents::LLEvent
101{
102public:
103	LLSpeakerVoiceModerationEvent(LLSpeaker* source);
104	/*virtual*/ LLSD getValue();
105};
106
107class LLSpeakerListChangeEvent : public LLOldEvents::LLEvent
108{
109public:
110	LLSpeakerListChangeEvent(LLSpeakerMgr* source, const LLUUID& speaker_id);
111	/*virtual*/ LLSD getValue();
112
113private:
114	const LLUUID& mSpeakerID;
115};
116
117/**
118 * class LLSpeakerActionTimer
119 * 
120 * Implements a timer that calls stored callback action for stored speaker after passed period.
121 *
122 * Action is called until callback returns "true".
123 * In this case the timer will be removed via LLEventTimer::updateClass().
124 * Otherwise it should be deleted manually in place where it is used.
125 * If action callback is not set timer will tick only once and deleted.
126 */
127class LLSpeakerActionTimer : public LLEventTimer
128{
129public:
130	typedef boost::function<bool(const LLUUID&)>	action_callback_t;
131	typedef std::map<LLUUID, LLSpeakerActionTimer*> action_timers_map_t;
132	typedef action_timers_map_t::value_type			action_value_t;
133	typedef action_timers_map_t::const_iterator		action_timer_const_iter_t;
134	typedef action_timers_map_t::iterator			action_timer_iter_t;
135
136	/**
137	 * Constructor.
138	 *
139	 * @param action_cb - callback which will be called each time after passed action period.
140	 * @param action_period - time in seconds timer should tick.
141	 * @param speaker_id - LLUUID of speaker which will be passed into action callback.
142	 */
143	LLSpeakerActionTimer(action_callback_t action_cb, F32 action_period, const LLUUID& speaker_id);
144	virtual ~LLSpeakerActionTimer() {};
145
146	/**
147	 * Implements timer "tick".
148	 *
149	 * If action callback is not specified returns true. Instance will be deleted by LLEventTimer::updateClass().
150	 */
151	virtual BOOL tick();
152
153	/**
154	 * Clears the callback.
155	 *
156	 * Use this instead of deleteing this object. 
157	 * The next call to tick() will return true and that will destroy this object.
158	 */
159	void unset();
160private:
161	action_callback_t	mActionCallback;
162	LLUUID				mSpeakerId;
163};
164
165/**
166 * Represents a functionality to store actions for speakers with delay.
167 * Is based on LLSpeakerActionTimer.
168 */
169class LLSpeakersDelayActionsStorage
170{
171public:
172	LLSpeakersDelayActionsStorage(LLSpeakerActionTimer::action_callback_t action_cb, F32 action_delay);
173	~LLSpeakersDelayActionsStorage();
174
175	/**
176	 * Sets new LLSpeakerActionTimer with passed speaker UUID.
177	 */
178	void setActionTimer(const LLUUID& speaker_id);
179
180	/**
181	 * Removes stored LLSpeakerActionTimer for passed speaker UUID from internal map and optionally deletes it.
182	 *
183	 * @see onTimerActionCallback()
184	 */
185	void unsetActionTimer(const LLUUID& speaker_id);
186
187	void removeAllTimers();
188private:
189	/**
190	 * Callback of the each instance of LLSpeakerActionTimer.
191	 *
192	 * Unsets an appropriate timer instance and calls action callback for specified speacker_id.
193	 *
194	 * @see unsetActionTimer()
195	 */
196	bool onTimerActionCallback(const LLUUID& speaker_id);
197
198	LLSpeakerActionTimer::action_timers_map_t	mActionTimersMap;
199	LLSpeakerActionTimer::action_callback_t		mActionCallback;
200
201	/**
202	 * Delay to call action callback for speakers after timer was set.
203	 */
204	F32	mActionDelay;
205
206};
207
208
209class LLSpeakerMgr : public LLOldEvents::LLObservable
210{
211public:
212	LLSpeakerMgr(LLVoiceChannel* channelp);
213	virtual ~LLSpeakerMgr();
214
215	LLPointer<LLSpeaker> findSpeaker(const LLUUID& avatar_id);
216	void update(BOOL resort_ok);
217	void setSpeakerTyping(const LLUUID& speaker_id, BOOL typing);
218	void speakerChatted(const LLUUID& speaker_id);
219	LLPointer<LLSpeaker> setSpeaker(const LLUUID& id, 
220					const std::string& name = LLStringUtil::null, 
221					LLSpeaker::ESpeakerStatus status = LLSpeaker::STATUS_TEXT_ONLY, 
222					LLSpeaker::ESpeakerType = LLSpeaker::SPEAKER_AGENT);
223
224	BOOL isVoiceActive();
225
226	typedef std::vector<LLPointer<LLSpeaker> > speaker_list_t;
227	void getSpeakerList(speaker_list_t* speaker_list, BOOL include_text);
228	LLVoiceChannel* getVoiceChannel() { return mVoiceChannel; }
229	const LLUUID getSessionID();
230
231	/**
232	 * Removes avaline speaker.
233	 *
234	 * This is a HACK due to server does not send information that Avaline caller ends call.
235	 * It can be removed when server is updated. See EXT-4301 for details
236	 */
237	bool removeAvalineSpeaker(const LLUUID& speaker_id) { return removeSpeaker(speaker_id); }
238
239	/**
240	 * Initializes mVoiceModerated depend on LLSpeaker::mModeratorMutedVoice of agent's participant.
241	 *
242	 * Is used only to implement workaround to initialize mVoiceModerated on first join to group chat. See EXT-6937
243	 */
244	void initVoiceModerateMode();
245
246protected:
247	virtual void updateSpeakerList();
248	void setSpeakerNotInChannel(LLSpeaker* speackerp);
249	bool removeSpeaker(const LLUUID& speaker_id);
250
251	typedef std::map<LLUUID, LLPointer<LLSpeaker> > speaker_map_t;
252	speaker_map_t		mSpeakers;
253
254	speaker_list_t		mSpeakersSorted;
255	LLFrameTimer		mSpeechTimer;
256	LLVoiceChannel*		mVoiceChannel;
257
258	/**
259	 * time out speakers when they are not part of current session
260	 */
261	LLSpeakersDelayActionsStorage* mSpeakerDelayRemover;
262
263	// *TODO: should be moved back into LLIMSpeakerMgr when a way to request the current voice channel
264	// moderation mode is implemented: See EXT-6937
265	bool mVoiceModerated;
266
267	// *TODO: To be removed when a way to request the current voice channel
268	// moderation mode is implemented: See EXT-6937
269	bool mModerateModeHandledFirstTime;
270};
271
272class LLIMSpeakerMgr : public LLSpeakerMgr
273{
274public:
275	LLIMSpeakerMgr(LLVoiceChannel* channel);
276	
277	void updateSpeakers(const LLSD& update);
278	void setSpeakers(const LLSD& speakers);
279
280	void toggleAllowTextChat(const LLUUID& speaker_id);
281
282	/**
283	 * Mutes/Unmutes avatar for current group voice chat.
284	 *
285	 * It only marks avatar as muted for session and does not use local Agent's Block list.
286	 * It does not mute Agent itself.
287	 *
288	 * @param[in] avatar_id UUID of avatar to be processed
289	 * @param[in] unmute if false - specified avatar will be muted, otherwise - unmuted.
290	 *
291	 * @see moderateVoiceAllParticipants()
292	 */
293	void moderateVoiceParticipant(const LLUUID& avatar_id, bool unmute);
294
295	/**
296	 * Mutes/Unmutes all avatars for current group voice chat.
297	 *
298	 * It only marks avatars as muted for session and does not use local Agent's Block list.
299	 * It calls forceVoiceModeratedMode() in case of session is already in requested state.
300	 *
301	 * @param[in] unmute_everyone if false - avatars will be muted, otherwise - unmuted.
302	 *
303	 * @see moderateVoiceParticipant()
304	 */
305	void moderateVoiceAllParticipants(bool unmute_everyone);
306
307	void processSessionUpdate(const LLSD& session_update);
308
309protected:
310	virtual void updateSpeakerList();
311
312	void moderateVoiceSession(const LLUUID& session_id, bool disallow_voice);
313
314	/**
315	 * Process all participants to mute/unmute them according to passed voice session state.
316	 */
317	void forceVoiceModeratedMode(bool should_be_muted);
318
319};
320
321class LLActiveSpeakerMgr : public LLSpeakerMgr, public LLSingleton<LLActiveSpeakerMgr>
322{
323public:
324	LLActiveSpeakerMgr();
325protected:
326	virtual void updateSpeakerList();
327};
328
329class LLLocalSpeakerMgr : public LLSpeakerMgr, public LLSingleton<LLLocalSpeakerMgr>
330{
331public:
332	LLLocalSpeakerMgr();
333	~LLLocalSpeakerMgr ();
334protected:
335	virtual void updateSpeakerList();
336};
337
338#endif // LL_LLSPEAKERS_H