PageRenderTime 29ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llvoiceclient.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 526 lines | 265 code | 103 blank | 158 comment | 0 complexity | 83563a41235b4f0c4637e081ad8c7e9a MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llvoiceclient.h
  3. * @brief Declaration of LLVoiceClient class which is the interface to the voice client process.
  4. *
  5. * $LicenseInfo:firstyear=2001&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_VOICE_CLIENT_H
  27. #define LL_VOICE_CLIENT_H
  28. class LLVOAvatar;
  29. #include "lliopipe.h"
  30. #include "llpumpio.h"
  31. #include "llchainio.h"
  32. #include "lliosocket.h"
  33. #include "v3math.h"
  34. #include "llframetimer.h"
  35. #include "llviewerregion.h"
  36. #include "llcallingcard.h" // for LLFriendObserver
  37. #include "llsecapi.h"
  38. #include "llcontrol.h"
  39. // devices
  40. typedef std::vector<std::string> LLVoiceDeviceList;
  41. class LLVoiceClientParticipantObserver
  42. {
  43. public:
  44. virtual ~LLVoiceClientParticipantObserver() { }
  45. virtual void onParticipantsChanged() = 0;
  46. };
  47. ///////////////////////////////////
  48. /// @class LLVoiceClientStatusObserver
  49. class LLVoiceClientStatusObserver
  50. {
  51. public:
  52. typedef enum e_voice_status_type
  53. {
  54. // NOTE: when updating this enum, please also update the switch in
  55. // LLVoiceClientStatusObserver::status2string().
  56. STATUS_LOGIN_RETRY,
  57. STATUS_LOGGED_IN,
  58. STATUS_JOINING,
  59. STATUS_JOINED,
  60. STATUS_LEFT_CHANNEL,
  61. STATUS_VOICE_DISABLED,
  62. STATUS_VOICE_ENABLED,
  63. BEGIN_ERROR_STATUS,
  64. ERROR_CHANNEL_FULL,
  65. ERROR_CHANNEL_LOCKED,
  66. ERROR_NOT_AVAILABLE,
  67. ERROR_UNKNOWN
  68. } EStatusType;
  69. virtual ~LLVoiceClientStatusObserver() { }
  70. virtual void onChange(EStatusType status, const std::string &channelURI, bool proximal) = 0;
  71. static std::string status2string(EStatusType inStatus);
  72. };
  73. struct LLVoiceVersionInfo
  74. {
  75. std::string serverType;
  76. std::string serverVersion;
  77. };
  78. //////////////////////////////////
  79. /// @class LLVoiceModuleInterface
  80. /// @brief Voice module interface
  81. ///
  82. /// Voice modules should provide an implementation for this interface.
  83. /////////////////////////////////
  84. class LLVoiceModuleInterface
  85. {
  86. public:
  87. LLVoiceModuleInterface() {}
  88. virtual ~LLVoiceModuleInterface() {}
  89. virtual void init(LLPumpIO *pump)=0; // Call this once at application startup (creates connector)
  90. virtual void terminate()=0; // Call this to clean up during shutdown
  91. virtual void updateSettings()=0; // call after loading settings and whenever they change
  92. virtual bool isVoiceWorking() const = 0; // connected to a voice server and voice channel
  93. virtual const LLVoiceVersionInfo& getVersion()=0;
  94. /////////////////////
  95. /// @name Tuning
  96. //@{
  97. virtual void tuningStart()=0;
  98. virtual void tuningStop()=0;
  99. virtual bool inTuningMode()=0;
  100. virtual void tuningSetMicVolume(float volume)=0;
  101. virtual void tuningSetSpeakerVolume(float volume)=0;
  102. virtual float tuningGetEnergy(void)=0;
  103. //@}
  104. /////////////////////
  105. /// @name Devices
  106. //@{
  107. // This returns true when it's safe to bring up the "device settings" dialog in the prefs.
  108. // i.e. when the daemon is running and connected, and the device lists are populated.
  109. virtual bool deviceSettingsAvailable()=0;
  110. // Requery the vivox daemon for the current list of input/output devices.
  111. // If you pass true for clearCurrentList, deviceSettingsAvailable() will be false until the query has completed
  112. // (use this if you want to know when it's done).
  113. // If you pass false, you'll have no way to know when the query finishes, but the device lists will not appear empty in the interim.
  114. virtual void refreshDeviceLists(bool clearCurrentList = true)=0;
  115. virtual void setCaptureDevice(const std::string& name)=0;
  116. virtual void setRenderDevice(const std::string& name)=0;
  117. virtual LLVoiceDeviceList& getCaptureDevices()=0;
  118. virtual LLVoiceDeviceList& getRenderDevices()=0;
  119. virtual void getParticipantList(std::set<LLUUID> &participants)=0;
  120. virtual bool isParticipant(const LLUUID& speaker_id)=0;
  121. //@}
  122. ////////////////////////////
  123. /// @ name Channel stuff
  124. //@{
  125. // returns true iff the user is currently in a proximal (local spatial) channel.
  126. // Note that gestures should only fire if this returns true.
  127. virtual bool inProximalChannel()=0;
  128. virtual void setNonSpatialChannel(const std::string &uri,
  129. const std::string &credentials)=0;
  130. virtual void setSpatialChannel(const std::string &uri,
  131. const std::string &credentials)=0;
  132. virtual void leaveNonSpatialChannel()=0;
  133. virtual void leaveChannel(void)=0;
  134. // Returns the URI of the current channel, or an empty string if not currently in a channel.
  135. // NOTE that it will return an empty string if it's in the process of joining a channel.
  136. virtual std::string getCurrentChannel()=0;
  137. //@}
  138. //////////////////////////
  139. /// @name invitations
  140. //@{
  141. // start a voice channel with the specified user
  142. virtual void callUser(const LLUUID &uuid)=0;
  143. virtual bool isValidChannel(std::string& channelHandle)=0;
  144. virtual bool answerInvite(std::string &channelHandle)=0;
  145. virtual void declineInvite(std::string &channelHandle)=0;
  146. //@}
  147. /////////////////////////
  148. /// @name Volume/gain
  149. //@{
  150. virtual void setVoiceVolume(F32 volume)=0;
  151. virtual void setMicGain(F32 volume)=0;
  152. //@}
  153. /////////////////////////
  154. /// @name enable disable voice and features
  155. //@{
  156. virtual bool voiceEnabled()=0;
  157. virtual void setVoiceEnabled(bool enabled)=0;
  158. virtual void setLipSyncEnabled(BOOL enabled)=0;
  159. virtual BOOL lipSyncEnabled()=0;
  160. virtual void setMuteMic(bool muted)=0; // Set the mute state of the local mic.
  161. //@}
  162. //////////////////////////
  163. /// @name nearby speaker accessors
  164. //@{
  165. virtual BOOL getVoiceEnabled(const LLUUID& id)=0; // true if we've received data for this avatar
  166. virtual std::string getDisplayName(const LLUUID& id)=0;
  167. virtual BOOL isOnlineSIP(const LLUUID &id)=0;
  168. virtual BOOL isParticipantAvatar(const LLUUID &id)=0;
  169. virtual BOOL getIsSpeaking(const LLUUID& id)=0;
  170. virtual BOOL getIsModeratorMuted(const LLUUID& id)=0;
  171. virtual F32 getCurrentPower(const LLUUID& id)=0; // "power" is related to "amplitude" in a defined way. I'm just not sure what the formula is...
  172. virtual BOOL getOnMuteList(const LLUUID& id)=0;
  173. virtual F32 getUserVolume(const LLUUID& id)=0;
  174. virtual void setUserVolume(const LLUUID& id, F32 volume)=0; // set's volume for specified agent, from 0-1 (where .5 is nominal)
  175. //@}
  176. //////////////////////////
  177. /// @name text chat
  178. //@{
  179. virtual BOOL isSessionTextIMPossible(const LLUUID& id)=0;
  180. virtual BOOL isSessionCallBackPossible(const LLUUID& id)=0;
  181. virtual BOOL sendTextMessage(const LLUUID& participant_id, const std::string& message)=0;
  182. virtual void endUserIMSession(const LLUUID &uuid)=0;
  183. //@}
  184. // authorize the user
  185. virtual void userAuthorized(const std::string& user_id,
  186. const LLUUID &agentID)=0;
  187. //////////////////////////////
  188. /// @name Status notification
  189. //@{
  190. virtual void addObserver(LLVoiceClientStatusObserver* observer)=0;
  191. virtual void removeObserver(LLVoiceClientStatusObserver* observer)=0;
  192. virtual void addObserver(LLFriendObserver* observer)=0;
  193. virtual void removeObserver(LLFriendObserver* observer)=0;
  194. virtual void addObserver(LLVoiceClientParticipantObserver* observer)=0;
  195. virtual void removeObserver(LLVoiceClientParticipantObserver* observer)=0;
  196. //@}
  197. virtual std::string sipURIFromID(const LLUUID &id)=0;
  198. //@}
  199. };
  200. //////////////////////////////////
  201. /// @class LLVoiceEffectObserver
  202. class LLVoiceEffectObserver
  203. {
  204. public:
  205. virtual ~LLVoiceEffectObserver() { }
  206. virtual void onVoiceEffectChanged(bool effect_list_updated) = 0;
  207. };
  208. typedef std::multimap<const std::string, const LLUUID, LLDictionaryLess> voice_effect_list_t;
  209. //////////////////////////////////
  210. /// @class LLVoiceEffectInterface
  211. /// @brief Voice effect module interface
  212. ///
  213. /// Voice effect modules should provide an implementation for this interface.
  214. /////////////////////////////////
  215. class LLVoiceEffectInterface
  216. {
  217. public:
  218. LLVoiceEffectInterface() {}
  219. virtual ~LLVoiceEffectInterface() {}
  220. //////////////////////////
  221. /// @name Accessors
  222. //@{
  223. virtual bool setVoiceEffect(const LLUUID& id) = 0;
  224. virtual const LLUUID getVoiceEffect() = 0;
  225. virtual LLSD getVoiceEffectProperties(const LLUUID& id) = 0;
  226. virtual void refreshVoiceEffectLists(bool clear_lists) = 0;
  227. virtual const voice_effect_list_t &getVoiceEffectList() const = 0;
  228. virtual const voice_effect_list_t &getVoiceEffectTemplateList() const = 0;
  229. //@}
  230. //////////////////////////////
  231. /// @name Status notification
  232. //@{
  233. virtual void addObserver(LLVoiceEffectObserver* observer) = 0;
  234. virtual void removeObserver(LLVoiceEffectObserver* observer) = 0;
  235. //@}
  236. //////////////////////////////
  237. /// @name Preview buffer
  238. //@{
  239. virtual void enablePreviewBuffer(bool enable) = 0;
  240. virtual void recordPreviewBuffer() = 0;
  241. virtual void playPreviewBuffer(const LLUUID& effect_id = LLUUID::null) = 0;
  242. virtual void stopPreviewBuffer() = 0;
  243. virtual bool isPreviewRecording() = 0;
  244. virtual bool isPreviewPlaying() = 0;
  245. //@}
  246. };
  247. class LLVoiceClient: public LLSingleton<LLVoiceClient>
  248. {
  249. LOG_CLASS(LLVoiceClient);
  250. public:
  251. LLVoiceClient();
  252. ~LLVoiceClient();
  253. void init(LLPumpIO *pump); // Call this once at application startup (creates connector)
  254. void terminate(); // Call this to clean up during shutdown
  255. const LLVoiceVersionInfo getVersion();
  256. static const F32 OVERDRIVEN_POWER_LEVEL;
  257. static const F32 VOLUME_MIN;
  258. static const F32 VOLUME_DEFAULT;
  259. static const F32 VOLUME_MAX;
  260. void updateSettings(); // call after loading settings and whenever they change
  261. bool isVoiceWorking() const; // connected to a voice server and voice channel
  262. // tuning
  263. void tuningStart();
  264. void tuningStop();
  265. bool inTuningMode();
  266. void tuningSetMicVolume(float volume);
  267. void tuningSetSpeakerVolume(float volume);
  268. float tuningGetEnergy(void);
  269. // devices
  270. // This returns true when it's safe to bring up the "device settings" dialog in the prefs.
  271. // i.e. when the daemon is running and connected, and the device lists are populated.
  272. bool deviceSettingsAvailable();
  273. // Requery the vivox daemon for the current list of input/output devices.
  274. // If you pass true for clearCurrentList, deviceSettingsAvailable() will be false until the query has completed
  275. // (use this if you want to know when it's done).
  276. // If you pass false, you'll have no way to know when the query finishes, but the device lists will not appear empty in the interim.
  277. void refreshDeviceLists(bool clearCurrentList = true);
  278. void setCaptureDevice(const std::string& name);
  279. void setRenderDevice(const std::string& name);
  280. const LLVoiceDeviceList& getCaptureDevices();
  281. const LLVoiceDeviceList& getRenderDevices();
  282. ////////////////////////////
  283. // Channel stuff
  284. //
  285. // returns true iff the user is currently in a proximal (local spatial) channel.
  286. // Note that gestures should only fire if this returns true.
  287. bool inProximalChannel();
  288. void setNonSpatialChannel(
  289. const std::string &uri,
  290. const std::string &credentials);
  291. void setSpatialChannel(
  292. const std::string &uri,
  293. const std::string &credentials);
  294. void leaveNonSpatialChannel();
  295. // Returns the URI of the current channel, or an empty string if not currently in a channel.
  296. // NOTE that it will return an empty string if it's in the process of joining a channel.
  297. std::string getCurrentChannel();
  298. // start a voice channel with the specified user
  299. void callUser(const LLUUID &uuid);
  300. bool isValidChannel(std::string& channelHandle);
  301. bool answerInvite(std::string &channelHandle);
  302. void declineInvite(std::string &channelHandle);
  303. void leaveChannel(void); // call this on logout or teleport begin
  304. /////////////////////////////
  305. // Sending updates of current state
  306. void setVoiceVolume(F32 volume);
  307. void setMicGain(F32 volume);
  308. void setUserVolume(const LLUUID& id, F32 volume); // set's volume for specified agent, from 0-1 (where .5 is nominal)
  309. bool voiceEnabled();
  310. void setLipSyncEnabled(BOOL enabled);
  311. void setMuteMic(bool muted); // Use this to mute the local mic (for when the client is minimized, etc), ignoring user PTT state.
  312. void setUserPTTState(bool ptt);
  313. bool getUserPTTState();
  314. void toggleUserPTTState(void);
  315. void inputUserControlState(bool down); // interpret any sort of up-down mic-open control input according to ptt-toggle prefs
  316. void setVoiceEnabled(bool enabled);
  317. void setUsePTT(bool usePTT);
  318. void setPTTIsToggle(bool PTTIsToggle);
  319. bool getPTTIsToggle();
  320. void setPTTKey(std::string &key);
  321. void updateMicMuteLogic();
  322. BOOL lipSyncEnabled();
  323. // PTT key triggering
  324. void keyDown(KEY key, MASK mask);
  325. void keyUp(KEY key, MASK mask);
  326. void middleMouseState(bool down);
  327. /////////////////////////////
  328. // Accessors for data related to nearby speakers
  329. BOOL getVoiceEnabled(const LLUUID& id); // true if we've received data for this avatar
  330. std::string getDisplayName(const LLUUID& id);
  331. BOOL isOnlineSIP(const LLUUID &id);
  332. BOOL isParticipantAvatar(const LLUUID &id);
  333. BOOL getIsSpeaking(const LLUUID& id);
  334. BOOL getIsModeratorMuted(const LLUUID& id);
  335. F32 getCurrentPower(const LLUUID& id); // "power" is related to "amplitude" in a defined way. I'm just not sure what the formula is...
  336. BOOL getOnMuteList(const LLUUID& id);
  337. F32 getUserVolume(const LLUUID& id);
  338. /////////////////////////////
  339. BOOL getAreaVoiceDisabled(); // returns true if the area the avatar is in is speech-disabled.
  340. // Use this to determine whether to show a "no speech" icon in the menu bar.
  341. void getParticipantList(std::set<LLUUID> &participants);
  342. bool isParticipant(const LLUUID& speaker_id);
  343. //////////////////////////
  344. /// @name text chat
  345. //@{
  346. BOOL isSessionTextIMPossible(const LLUUID& id);
  347. BOOL isSessionCallBackPossible(const LLUUID& id);
  348. BOOL sendTextMessage(const LLUUID& participant_id, const std::string& message);
  349. void endUserIMSession(const LLUUID &uuid);
  350. //@}
  351. void userAuthorized(const std::string& user_id,
  352. const LLUUID &agentID);
  353. void addObserver(LLVoiceClientStatusObserver* observer);
  354. void removeObserver(LLVoiceClientStatusObserver* observer);
  355. void addObserver(LLFriendObserver* observer);
  356. void removeObserver(LLFriendObserver* observer);
  357. void addObserver(LLVoiceClientParticipantObserver* observer);
  358. void removeObserver(LLVoiceClientParticipantObserver* observer);
  359. std::string sipURIFromID(const LLUUID &id);
  360. //////////////////////////
  361. /// @name Voice effects
  362. //@{
  363. bool getVoiceEffectEnabled() const { return mVoiceEffectEnabled; };
  364. LLUUID getVoiceEffectDefault() const { return LLUUID(mVoiceEffectDefault); };
  365. // Returns NULL if voice effects are not supported, or not enabled.
  366. LLVoiceEffectInterface* getVoiceEffectInterface() const;
  367. //@}
  368. protected:
  369. LLVoiceModuleInterface* mVoiceModule;
  370. LLPumpIO *m_servicePump;
  371. LLCachedControl<bool> mVoiceEffectEnabled;
  372. LLCachedControl<std::string> mVoiceEffectDefault;
  373. bool mPTTDirty;
  374. bool mPTT;
  375. bool mUsePTT;
  376. bool mPTTIsMiddleMouse;
  377. KEY mPTTKey;
  378. bool mPTTIsToggle;
  379. bool mUserPTTState;
  380. bool mMuteMic;
  381. bool mDisableMic;
  382. };
  383. /**
  384. * Speaker volume storage helper class
  385. **/
  386. class LLSpeakerVolumeStorage : public LLSingleton<LLSpeakerVolumeStorage>
  387. {
  388. LOG_CLASS(LLSpeakerVolumeStorage);
  389. public:
  390. /**
  391. * Stores volume level for specified user.
  392. *
  393. * @param[in] speaker_id - LLUUID of user to store volume level for.
  394. * @param[in] volume - volume level to be stored for user.
  395. */
  396. void storeSpeakerVolume(const LLUUID& speaker_id, F32 volume);
  397. /**
  398. * Gets stored volume level for specified speaker
  399. *
  400. * @param[in] speaker_id - LLUUID of user to retrieve volume level for.
  401. * @param[out] volume - set to stored volume if found, otherwise unmodified.
  402. * @return - true if a stored volume is found.
  403. */
  404. bool getSpeakerVolume(const LLUUID& speaker_id, F32& volume);
  405. /**
  406. * Removes stored volume level for specified user.
  407. *
  408. * @param[in] speaker_id - LLUUID of user to remove.
  409. */
  410. void removeSpeakerVolume(const LLUUID& speaker_id);
  411. private:
  412. friend class LLSingleton<LLSpeakerVolumeStorage>;
  413. LLSpeakerVolumeStorage();
  414. ~LLSpeakerVolumeStorage();
  415. const static std::string SETTINGS_FILE_NAME;
  416. void load();
  417. void save();
  418. static F32 transformFromLegacyVolume(F32 volume_in);
  419. static F32 transformToLegacyVolume(F32 volume_in);
  420. typedef std::map<LLUUID, F32> speaker_data_map_t;
  421. speaker_data_map_t mSpeakersData;
  422. };
  423. #endif //LL_VOICE_CLIENT_H