PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): LGPL-2.1
  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. #ifndef LL_LLSPEAKERS_H
  27. #define LL_LLSPEAKERS_H
  28. #include "llevent.h"
  29. #include "lleventtimer.h"
  30. #include "llspeakers.h"
  31. #include "llvoicechannel.h"
  32. class LLSpeakerMgr;
  33. // data for a given participant in a voice channel
  34. class LLSpeaker : public LLRefCount, public LLOldEvents::LLObservable, public LLHandleProvider<LLSpeaker>, public boost::signals2::trackable
  35. {
  36. public:
  37. typedef enum e_speaker_type
  38. {
  39. SPEAKER_AGENT,
  40. SPEAKER_OBJECT,
  41. SPEAKER_EXTERNAL // Speaker that doesn't map to an avatar or object (i.e. PSTN caller in a group)
  42. } ESpeakerType;
  43. typedef enum e_speaker_status
  44. {
  45. STATUS_SPEAKING,
  46. STATUS_HAS_SPOKEN,
  47. STATUS_VOICE_ACTIVE,
  48. STATUS_TEXT_ONLY,
  49. STATUS_NOT_IN_CHANNEL,
  50. STATUS_MUTED
  51. } ESpeakerStatus;
  52. LLSpeaker(const LLUUID& id, const std::string& name = LLStringUtil::null, const ESpeakerType type = SPEAKER_AGENT);
  53. ~LLSpeaker() {};
  54. void lookupName();
  55. void onNameCache(const LLUUID& id, const std::string& full_name, bool is_group);
  56. bool isInVoiceChannel();
  57. ESpeakerStatus mStatus; // current activity status in speech group
  58. F32 mLastSpokeTime; // timestamp when this speaker last spoke
  59. F32 mSpeechVolume; // current speech amplitude (timea average rms amplitude?)
  60. std::string mDisplayName; // cache user name for this speaker
  61. BOOL mHasSpoken; // has this speaker said anything this session?
  62. BOOL mHasLeftCurrentCall; // has this speaker left the current voice call?
  63. LLColor4 mDotColor;
  64. LLUUID mID;
  65. BOOL mTyping;
  66. S32 mSortIndex;
  67. ESpeakerType mType;
  68. BOOL mIsModerator;
  69. BOOL mModeratorMutedVoice;
  70. BOOL mModeratorMutedText;
  71. };
  72. class LLSpeakerUpdateModeratorEvent : public LLOldEvents::LLEvent
  73. {
  74. public:
  75. LLSpeakerUpdateModeratorEvent(LLSpeaker* source);
  76. /*virtual*/ LLSD getValue();
  77. private:
  78. const LLUUID& mSpeakerID;
  79. BOOL mIsModerator;
  80. };
  81. class LLSpeakerTextModerationEvent : public LLOldEvents::LLEvent
  82. {
  83. public:
  84. LLSpeakerTextModerationEvent(LLSpeaker* source);
  85. /*virtual*/ LLSD getValue();
  86. };
  87. class LLSpeakerVoiceModerationEvent : public LLOldEvents::LLEvent
  88. {
  89. public:
  90. LLSpeakerVoiceModerationEvent(LLSpeaker* source);
  91. /*virtual*/ LLSD getValue();
  92. };
  93. class LLSpeakerListChangeEvent : public LLOldEvents::LLEvent
  94. {
  95. public:
  96. LLSpeakerListChangeEvent(LLSpeakerMgr* source, const LLUUID& speaker_id);
  97. /*virtual*/ LLSD getValue();
  98. private:
  99. const LLUUID& mSpeakerID;
  100. };
  101. /**
  102. * class LLSpeakerActionTimer
  103. *
  104. * Implements a timer that calls stored callback action for stored speaker after passed period.
  105. *
  106. * Action is called until callback returns "true".
  107. * In this case the timer will be removed via LLEventTimer::updateClass().
  108. * Otherwise it should be deleted manually in place where it is used.
  109. * If action callback is not set timer will tick only once and deleted.
  110. */
  111. class LLSpeakerActionTimer : public LLEventTimer
  112. {
  113. public:
  114. typedef boost::function<bool(const LLUUID&)> action_callback_t;
  115. typedef std::map<LLUUID, LLSpeakerActionTimer*> action_timers_map_t;
  116. typedef action_timers_map_t::value_type action_value_t;
  117. typedef action_timers_map_t::const_iterator action_timer_const_iter_t;
  118. typedef action_timers_map_t::iterator action_timer_iter_t;
  119. /**
  120. * Constructor.
  121. *
  122. * @param action_cb - callback which will be called each time after passed action period.
  123. * @param action_period - time in seconds timer should tick.
  124. * @param speaker_id - LLUUID of speaker which will be passed into action callback.
  125. */
  126. LLSpeakerActionTimer(action_callback_t action_cb, F32 action_period, const LLUUID& speaker_id);
  127. virtual ~LLSpeakerActionTimer() {};
  128. /**
  129. * Implements timer "tick".
  130. *
  131. * If action callback is not specified returns true. Instance will be deleted by LLEventTimer::updateClass().
  132. */
  133. virtual BOOL tick();
  134. /**
  135. * Clears the callback.
  136. *
  137. * Use this instead of deleteing this object.
  138. * The next call to tick() will return true and that will destroy this object.
  139. */
  140. void unset();
  141. private:
  142. action_callback_t mActionCallback;
  143. LLUUID mSpeakerId;
  144. };
  145. /**
  146. * Represents a functionality to store actions for speakers with delay.
  147. * Is based on LLSpeakerActionTimer.
  148. */
  149. class LLSpeakersDelayActionsStorage
  150. {
  151. public:
  152. LLSpeakersDelayActionsStorage(LLSpeakerActionTimer::action_callback_t action_cb, F32 action_delay);
  153. ~LLSpeakersDelayActionsStorage();
  154. /**
  155. * Sets new LLSpeakerActionTimer with passed speaker UUID.
  156. */
  157. void setActionTimer(const LLUUID& speaker_id);
  158. /**
  159. * Removes stored LLSpeakerActionTimer for passed speaker UUID from internal map and optionally deletes it.
  160. *
  161. * @see onTimerActionCallback()
  162. */
  163. void unsetActionTimer(const LLUUID& speaker_id);
  164. void removeAllTimers();
  165. private:
  166. /**
  167. * Callback of the each instance of LLSpeakerActionTimer.
  168. *
  169. * Unsets an appropriate timer instance and calls action callback for specified speacker_id.
  170. *
  171. * @see unsetActionTimer()
  172. */
  173. bool onTimerActionCallback(const LLUUID& speaker_id);
  174. LLSpeakerActionTimer::action_timers_map_t mActionTimersMap;
  175. LLSpeakerActionTimer::action_callback_t mActionCallback;
  176. /**
  177. * Delay to call action callback for speakers after timer was set.
  178. */
  179. F32 mActionDelay;
  180. };
  181. class LLSpeakerMgr : public LLOldEvents::LLObservable
  182. {
  183. public:
  184. LLSpeakerMgr(LLVoiceChannel* channelp);
  185. virtual ~LLSpeakerMgr();
  186. LLPointer<LLSpeaker> findSpeaker(const LLUUID& avatar_id);
  187. void update(BOOL resort_ok);
  188. void setSpeakerTyping(const LLUUID& speaker_id, BOOL typing);
  189. void speakerChatted(const LLUUID& speaker_id);
  190. LLPointer<LLSpeaker> setSpeaker(const LLUUID& id,
  191. const std::string& name = LLStringUtil::null,
  192. LLSpeaker::ESpeakerStatus status = LLSpeaker::STATUS_TEXT_ONLY,
  193. LLSpeaker::ESpeakerType = LLSpeaker::SPEAKER_AGENT);
  194. BOOL isVoiceActive();
  195. typedef std::vector<LLPointer<LLSpeaker> > speaker_list_t;
  196. void getSpeakerList(speaker_list_t* speaker_list, BOOL include_text);
  197. LLVoiceChannel* getVoiceChannel() { return mVoiceChannel; }
  198. const LLUUID getSessionID();
  199. /**
  200. * Removes avaline speaker.
  201. *
  202. * This is a HACK due to server does not send information that Avaline caller ends call.
  203. * It can be removed when server is updated. See EXT-4301 for details
  204. */
  205. bool removeAvalineSpeaker(const LLUUID& speaker_id) { return removeSpeaker(speaker_id); }
  206. /**
  207. * Initializes mVoiceModerated depend on LLSpeaker::mModeratorMutedVoice of agent's participant.
  208. *
  209. * Is used only to implement workaround to initialize mVoiceModerated on first join to group chat. See EXT-6937
  210. */
  211. void initVoiceModerateMode();
  212. protected:
  213. virtual void updateSpeakerList();
  214. void setSpeakerNotInChannel(LLSpeaker* speackerp);
  215. bool removeSpeaker(const LLUUID& speaker_id);
  216. typedef std::map<LLUUID, LLPointer<LLSpeaker> > speaker_map_t;
  217. speaker_map_t mSpeakers;
  218. speaker_list_t mSpeakersSorted;
  219. LLFrameTimer mSpeechTimer;
  220. LLVoiceChannel* mVoiceChannel;
  221. /**
  222. * time out speakers when they are not part of current session
  223. */
  224. LLSpeakersDelayActionsStorage* mSpeakerDelayRemover;
  225. // *TODO: should be moved back into LLIMSpeakerMgr when a way to request the current voice channel
  226. // moderation mode is implemented: See EXT-6937
  227. bool mVoiceModerated;
  228. // *TODO: To be removed when a way to request the current voice channel
  229. // moderation mode is implemented: See EXT-6937
  230. bool mModerateModeHandledFirstTime;
  231. };
  232. class LLIMSpeakerMgr : public LLSpeakerMgr
  233. {
  234. public:
  235. LLIMSpeakerMgr(LLVoiceChannel* channel);
  236. void updateSpeakers(const LLSD& update);
  237. void setSpeakers(const LLSD& speakers);
  238. void toggleAllowTextChat(const LLUUID& speaker_id);
  239. /**
  240. * Mutes/Unmutes avatar for current group voice chat.
  241. *
  242. * It only marks avatar as muted for session and does not use local Agent's Block list.
  243. * It does not mute Agent itself.
  244. *
  245. * @param[in] avatar_id UUID of avatar to be processed
  246. * @param[in] unmute if false - specified avatar will be muted, otherwise - unmuted.
  247. *
  248. * @see moderateVoiceAllParticipants()
  249. */
  250. void moderateVoiceParticipant(const LLUUID& avatar_id, bool unmute);
  251. /**
  252. * Mutes/Unmutes all avatars for current group voice chat.
  253. *
  254. * It only marks avatars as muted for session and does not use local Agent's Block list.
  255. * It calls forceVoiceModeratedMode() in case of session is already in requested state.
  256. *
  257. * @param[in] unmute_everyone if false - avatars will be muted, otherwise - unmuted.
  258. *
  259. * @see moderateVoiceParticipant()
  260. */
  261. void moderateVoiceAllParticipants(bool unmute_everyone);
  262. void processSessionUpdate(const LLSD& session_update);
  263. protected:
  264. virtual void updateSpeakerList();
  265. void moderateVoiceSession(const LLUUID& session_id, bool disallow_voice);
  266. /**
  267. * Process all participants to mute/unmute them according to passed voice session state.
  268. */
  269. void forceVoiceModeratedMode(bool should_be_muted);
  270. };
  271. class LLActiveSpeakerMgr : public LLSpeakerMgr, public LLSingleton<LLActiveSpeakerMgr>
  272. {
  273. public:
  274. LLActiveSpeakerMgr();
  275. protected:
  276. virtual void updateSpeakerList();
  277. };
  278. class LLLocalSpeakerMgr : public LLSpeakerMgr, public LLSingleton<LLLocalSpeakerMgr>
  279. {
  280. public:
  281. LLLocalSpeakerMgr();
  282. ~LLLocalSpeakerMgr ();
  283. protected:
  284. virtual void updateSpeakerList();
  285. };
  286. #endif // LL_LLSPEAKERS_H