/indra/newview/llvoicevivox.h

https://bitbucket.org/lindenlab/viewer-beta/ · C Header · 1035 lines · 643 code · 209 blank · 183 comment · 0 complexity · 6c9b15d3162a0a4c00200b6f913f8abf MD5 · raw file

  1. /**
  2. * @file llvoicevivox.h
  3. * @brief Declaration of LLDiamondwareVoiceClient 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_VIVOX_H
  27. #define LL_VOICE_VIVOX_H
  28. class LLVOAvatar;
  29. class LLVivoxProtocolParser;
  30. #include "lliopipe.h"
  31. #include "llpumpio.h"
  32. #include "llchainio.h"
  33. #include "lliosocket.h"
  34. #include "v3math.h"
  35. #include "llframetimer.h"
  36. #include "llviewerregion.h"
  37. #include "llcallingcard.h" // for LLFriendObserver
  38. #ifdef LL_STANDALONE
  39. # include "expat.h"
  40. #else
  41. # include "expat/expat.h"
  42. #endif
  43. #include "llvoiceclient.h"
  44. class LLAvatarName;
  45. class LLVivoxVoiceAccountProvisionResponder;
  46. class LLVivoxVoiceClientMuteListObserver;
  47. class LLVivoxVoiceClientFriendsObserver;
  48. class LLVivoxVoiceClient : public LLSingleton<LLVivoxVoiceClient>,
  49. virtual public LLVoiceModuleInterface,
  50. virtual public LLVoiceEffectInterface
  51. {
  52. LOG_CLASS(LLVivoxVoiceClient);
  53. public:
  54. LLVivoxVoiceClient();
  55. virtual ~LLVivoxVoiceClient();
  56. /// @name LLVoiceModuleInterface virtual implementations
  57. /// @see LLVoiceModuleInterface
  58. //@{
  59. virtual void init(LLPumpIO *pump); // Call this once at application startup (creates connector)
  60. virtual void terminate(); // Call this to clean up during shutdown
  61. virtual const LLVoiceVersionInfo& getVersion();
  62. virtual void updateSettings(); // call after loading settings and whenever they change
  63. // Returns true if vivox has successfully logged in and is not in error state
  64. virtual bool isVoiceWorking() const;
  65. /////////////////////
  66. /// @name Tuning
  67. //@{
  68. virtual void tuningStart();
  69. virtual void tuningStop();
  70. virtual bool inTuningMode();
  71. virtual void tuningSetMicVolume(float volume);
  72. virtual void tuningSetSpeakerVolume(float volume);
  73. virtual float tuningGetEnergy(void);
  74. //@}
  75. /////////////////////
  76. /// @name Devices
  77. //@{
  78. // This returns true when it's safe to bring up the "device settings" dialog in the prefs.
  79. // i.e. when the daemon is running and connected, and the device lists are populated.
  80. virtual bool deviceSettingsAvailable();
  81. // Requery the vivox daemon for the current list of input/output devices.
  82. // If you pass true for clearCurrentList, deviceSettingsAvailable() will be false until the query has completed
  83. // (use this if you want to know when it's done).
  84. // 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.
  85. virtual void refreshDeviceLists(bool clearCurrentList = true);
  86. virtual void setCaptureDevice(const std::string& name);
  87. virtual void setRenderDevice(const std::string& name);
  88. virtual LLVoiceDeviceList& getCaptureDevices();
  89. virtual LLVoiceDeviceList& getRenderDevices();
  90. //@}
  91. virtual void getParticipantList(std::set<LLUUID> &participants);
  92. virtual bool isParticipant(const LLUUID& speaker_id);
  93. // Send a text message to the specified user, initiating the session if necessary.
  94. virtual BOOL sendTextMessage(const LLUUID& participant_id, const std::string& message);
  95. // close any existing text IM session with the specified user
  96. virtual void endUserIMSession(const LLUUID &uuid);
  97. // Returns true if calling back the session URI after the session has closed is possible.
  98. // Currently this will be false only for PSTN P2P calls.
  99. // NOTE: this will return true if the session can't be found.
  100. virtual BOOL isSessionCallBackPossible(const LLUUID &session_id);
  101. // Returns true if the session can accepte text IM's.
  102. // Currently this will be false only for PSTN P2P calls.
  103. // NOTE: this will return true if the session can't be found.
  104. virtual BOOL isSessionTextIMPossible(const LLUUID &session_id);
  105. ////////////////////////////
  106. /// @name Channel stuff
  107. //@{
  108. // returns true iff the user is currently in a proximal (local spatial) channel.
  109. // Note that gestures should only fire if this returns true.
  110. virtual bool inProximalChannel();
  111. virtual void setNonSpatialChannel(const std::string &uri,
  112. const std::string &credentials);
  113. virtual void setSpatialChannel(const std::string &uri,
  114. const std::string &credentials);
  115. virtual void leaveNonSpatialChannel();
  116. virtual void leaveChannel(void);
  117. // Returns the URI of the current channel, or an empty string if not currently in a channel.
  118. // NOTE that it will return an empty string if it's in the process of joining a channel.
  119. virtual std::string getCurrentChannel();
  120. //@}
  121. //////////////////////////
  122. /// @name invitations
  123. //@{
  124. // start a voice channel with the specified user
  125. virtual void callUser(const LLUUID &uuid);
  126. virtual bool isValidChannel(std::string &channelHandle);
  127. virtual bool answerInvite(std::string &channelHandle);
  128. virtual void declineInvite(std::string &channelHandle);
  129. //@}
  130. /////////////////////////
  131. /// @name Volume/gain
  132. //@{
  133. virtual void setVoiceVolume(F32 volume);
  134. virtual void setMicGain(F32 volume);
  135. //@}
  136. /////////////////////////
  137. /// @name enable disable voice and features
  138. //@{
  139. virtual bool voiceEnabled();
  140. virtual void setVoiceEnabled(bool enabled);
  141. virtual BOOL lipSyncEnabled();
  142. virtual void setLipSyncEnabled(BOOL enabled);
  143. virtual void setMuteMic(bool muted); // Set the mute state of the local mic.
  144. //@}
  145. //////////////////////////
  146. /// @name nearby speaker accessors
  147. //@{
  148. virtual BOOL getVoiceEnabled(const LLUUID& id); // true if we've received data for this avatar
  149. virtual std::string getDisplayName(const LLUUID& id);
  150. virtual BOOL isOnlineSIP(const LLUUID &id);
  151. virtual BOOL isParticipantAvatar(const LLUUID &id);
  152. virtual BOOL getIsSpeaking(const LLUUID& id);
  153. virtual BOOL getIsModeratorMuted(const LLUUID& id);
  154. virtual F32 getCurrentPower(const LLUUID& id); // "power" is related to "amplitude" in a defined way. I'm just not sure what the formula is...
  155. virtual BOOL getOnMuteList(const LLUUID& id);
  156. virtual F32 getUserVolume(const LLUUID& id);
  157. virtual void setUserVolume(const LLUUID& id, F32 volume); // set's volume for specified agent, from 0-1 (where .5 is nominal)
  158. //@}
  159. // authorize the user
  160. virtual void userAuthorized(const std::string& user_id,
  161. const LLUUID &agentID);
  162. //////////////////////////////
  163. /// @name Status notification
  164. //@{
  165. virtual void addObserver(LLVoiceClientStatusObserver* observer);
  166. virtual void removeObserver(LLVoiceClientStatusObserver* observer);
  167. virtual void addObserver(LLFriendObserver* observer);
  168. virtual void removeObserver(LLFriendObserver* observer);
  169. virtual void addObserver(LLVoiceClientParticipantObserver* observer);
  170. virtual void removeObserver(LLVoiceClientParticipantObserver* observer);
  171. //@}
  172. virtual std::string sipURIFromID(const LLUUID &id);
  173. //@}
  174. /// @name LLVoiceEffectInterface virtual implementations
  175. /// @see LLVoiceEffectInterface
  176. //@{
  177. //////////////////////////
  178. /// @name Accessors
  179. //@{
  180. virtual bool setVoiceEffect(const LLUUID& id);
  181. virtual const LLUUID getVoiceEffect();
  182. virtual LLSD getVoiceEffectProperties(const LLUUID& id);
  183. virtual void refreshVoiceEffectLists(bool clear_lists);
  184. virtual const voice_effect_list_t& getVoiceEffectList() const;
  185. virtual const voice_effect_list_t& getVoiceEffectTemplateList() const;
  186. //@}
  187. //////////////////////////////
  188. /// @name Status notification
  189. //@{
  190. virtual void addObserver(LLVoiceEffectObserver* observer);
  191. virtual void removeObserver(LLVoiceEffectObserver* observer);
  192. //@}
  193. //////////////////////////////
  194. /// @name Effect preview buffer
  195. //@{
  196. virtual void enablePreviewBuffer(bool enable);
  197. virtual void recordPreviewBuffer();
  198. virtual void playPreviewBuffer(const LLUUID& effect_id = LLUUID::null);
  199. virtual void stopPreviewBuffer();
  200. virtual bool isPreviewRecording();
  201. virtual bool isPreviewPlaying();
  202. //@}
  203. //@}
  204. protected:
  205. //////////////////////
  206. // Vivox Specific definitions
  207. friend class LLVivoxVoiceAccountProvisionResponder;
  208. friend class LLVivoxVoiceClientMuteListObserver;
  209. friend class LLVivoxVoiceClientFriendsObserver;
  210. enum streamState
  211. {
  212. streamStateUnknown = 0,
  213. streamStateIdle = 1,
  214. streamStateConnected = 2,
  215. streamStateRinging = 3,
  216. };
  217. struct participantState
  218. {
  219. public:
  220. participantState(const std::string &uri);
  221. bool updateMuteState(); // true if mute state has changed
  222. bool isAvatar();
  223. std::string mURI;
  224. LLUUID mAvatarID;
  225. std::string mAccountName;
  226. std::string mDisplayName;
  227. LLFrameTimer mSpeakingTimeout;
  228. F32 mLastSpokeTimestamp;
  229. F32 mPower;
  230. F32 mVolume;
  231. std::string mGroupID;
  232. int mUserVolume;
  233. bool mPTT;
  234. bool mIsSpeaking;
  235. bool mIsModeratorMuted;
  236. bool mOnMuteList; // true if this avatar is on the user's mute list (and should be muted)
  237. bool mVolumeSet; // true if incoming volume messages should not change the volume
  238. bool mVolumeDirty; // true if this participant needs a volume command sent (either mOnMuteList or mUserVolume has changed)
  239. bool mAvatarIDValid;
  240. bool mIsSelf;
  241. };
  242. typedef std::map<const std::string, participantState*> participantMap;
  243. typedef std::map<const LLUUID, participantState*> participantUUIDMap;
  244. struct sessionState
  245. {
  246. public:
  247. sessionState();
  248. ~sessionState();
  249. participantState *addParticipant(const std::string &uri);
  250. // Note: after removeParticipant returns, the participant* that was passed to it will have been deleted.
  251. // Take care not to use the pointer again after that.
  252. void removeParticipant(participantState *participant);
  253. void removeAllParticipants();
  254. participantState *findParticipant(const std::string &uri);
  255. participantState *findParticipantByID(const LLUUID& id);
  256. bool isCallBackPossible();
  257. bool isTextIMPossible();
  258. std::string mHandle;
  259. std::string mGroupHandle;
  260. std::string mSIPURI;
  261. std::string mAlias;
  262. std::string mName;
  263. std::string mAlternateSIPURI;
  264. std::string mHash; // Channel password
  265. std::string mErrorStatusString;
  266. std::queue<std::string> mTextMsgQueue;
  267. LLUUID mIMSessionID;
  268. LLUUID mCallerID;
  269. int mErrorStatusCode;
  270. int mMediaStreamState;
  271. int mTextStreamState;
  272. bool mCreateInProgress; // True if a Session.Create has been sent for this session and no response has been received yet.
  273. bool mMediaConnectInProgress; // True if a Session.MediaConnect has been sent for this session and no response has been received yet.
  274. bool mVoiceInvitePending; // True if a voice invite is pending for this session (usually waiting on a name lookup)
  275. bool mTextInvitePending; // True if a text invite is pending for this session (usually waiting on a name lookup)
  276. bool mSynthesizedCallerID; // True if the caller ID is a hash of the SIP URI -- this means we shouldn't do a name lookup.
  277. bool mIsChannel; // True for both group and spatial channels (false for p2p, PSTN)
  278. bool mIsSpatial; // True for spatial channels
  279. bool mIsP2P;
  280. bool mIncoming;
  281. bool mVoiceEnabled;
  282. bool mReconnect; // Whether we should try to reconnect to this session if it's dropped
  283. // Set to true when the volume/mute state of someone in the participant list changes.
  284. // The code will have to walk the list to find the changed participant(s).
  285. bool mVolumeDirty;
  286. bool mMuteDirty;
  287. bool mParticipantsChanged;
  288. participantMap mParticipantsByURI;
  289. participantUUIDMap mParticipantsByUUID;
  290. LLUUID mVoiceFontID;
  291. };
  292. // internal state for a simple state machine. This is used to deal with the asynchronous nature of some of the messages.
  293. // Note: if you change this list, please make corresponding changes to LLVivoxVoiceClient::state2string().
  294. enum state
  295. {
  296. stateDisableCleanup,
  297. stateDisabled, // Voice is turned off.
  298. stateStart, // Class is initialized, socket is created
  299. stateDaemonLaunched, // Daemon has been launched
  300. stateConnecting, // connect() call has been issued
  301. stateConnected, // connection to the daemon has been made, send some initial setup commands.
  302. stateIdle, // socket is connected, ready for messaging
  303. stateMicTuningStart,
  304. stateMicTuningRunning,
  305. stateMicTuningStop,
  306. stateCaptureBufferPaused,
  307. stateCaptureBufferRecStart,
  308. stateCaptureBufferRecording,
  309. stateCaptureBufferPlayStart,
  310. stateCaptureBufferPlaying,
  311. stateConnectorStart, // connector needs to be started
  312. stateConnectorStarting, // waiting for connector handle
  313. stateConnectorStarted, // connector handle received
  314. stateLoginRetry, // need to retry login (failed due to changing password)
  315. stateLoginRetryWait, // waiting for retry timer
  316. stateNeedsLogin, // send login request
  317. stateLoggingIn, // waiting for account handle
  318. stateLoggedIn, // account handle received
  319. stateVoiceFontsWait, // Awaiting the list of voice fonts
  320. stateVoiceFontsReceived, // List of voice fonts received
  321. stateCreatingSessionGroup, // Creating the main session group
  322. stateNoChannel, // Need to join a channel
  323. stateRetrievingParcelVoiceInfo, // waiting for parcel voice info request to return with spatial credentials
  324. stateJoiningSession, // waiting for session handle
  325. stateSessionJoined, // session handle received
  326. stateRunning, // in session, steady state
  327. stateLeavingSession, // waiting for terminate session response
  328. stateSessionTerminated, // waiting for terminate session response
  329. stateLoggingOut, // waiting for logout response
  330. stateLoggedOut, // logout response received
  331. stateConnectorStopping, // waiting for connector stop
  332. stateConnectorStopped, // connector stop received
  333. // We go to this state if the login fails because the account needs to be provisioned.
  334. // error states. No way to recover from these yet.
  335. stateConnectorFailed,
  336. stateConnectorFailedWaiting,
  337. stateLoginFailed,
  338. stateLoginFailedWaiting,
  339. stateJoinSessionFailed,
  340. stateJoinSessionFailedWaiting,
  341. stateJail // Go here when all else has failed. Nothing will be retried, we're done.
  342. };
  343. typedef std::map<std::string, sessionState*> sessionMap;
  344. ///////////////////////////////////////////////////////
  345. // Private Member Functions
  346. //////////////////////////////////////////////////////
  347. //////////////////////////////
  348. /// @name TVC/Server management and communication
  349. //@{
  350. // Call this if the connection to the daemon terminates unexpectedly. It will attempt to reset everything and relaunch.
  351. void daemonDied();
  352. // Call this if we're just giving up on voice (can't provision an account, etc.). It will clean up and go away.
  353. void giveUp();
  354. // write to the tvc
  355. bool writeString(const std::string &str);
  356. void connectorCreate();
  357. void connectorShutdown();
  358. void closeSocket(void);
  359. void requestVoiceAccountProvision(S32 retries = 3);
  360. void login(
  361. const std::string& account_name,
  362. const std::string& password,
  363. const std::string& voice_sip_uri_hostname,
  364. const std::string& voice_account_server_uri);
  365. void loginSendMessage();
  366. void logout();
  367. void logoutSendMessage();
  368. //@}
  369. //------------------------------------
  370. // tuning
  371. void tuningRenderStartSendMessage(const std::string& name, bool loop);
  372. void tuningRenderStopSendMessage();
  373. void tuningCaptureStartSendMessage(int duration);
  374. void tuningCaptureStopSendMessage();
  375. //----------------------------------
  376. // devices
  377. void clearCaptureDevices();
  378. void addCaptureDevice(const std::string& name);
  379. void clearRenderDevices();
  380. void addRenderDevice(const std::string& name);
  381. void buildSetAudioDevices(std::ostringstream &stream);
  382. void getCaptureDevicesSendMessage();
  383. void getRenderDevicesSendMessage();
  384. // local audio updates
  385. void buildLocalAudioUpdates(std::ostringstream &stream);
  386. /////////////////////////////
  387. // Response/Event handlers
  388. void connectorCreateResponse(int statusCode, std::string &statusString, std::string &connectorHandle, std::string &versionID);
  389. void loginResponse(int statusCode, std::string &statusString, std::string &accountHandle, int numberOfAliases);
  390. void sessionCreateResponse(std::string &requestId, int statusCode, std::string &statusString, std::string &sessionHandle);
  391. void sessionGroupAddSessionResponse(std::string &requestId, int statusCode, std::string &statusString, std::string &sessionHandle);
  392. void sessionConnectResponse(std::string &requestId, int statusCode, std::string &statusString);
  393. void logoutResponse(int statusCode, std::string &statusString);
  394. void connectorShutdownResponse(int statusCode, std::string &statusString);
  395. void accountLoginStateChangeEvent(std::string &accountHandle, int statusCode, std::string &statusString, int state);
  396. void mediaCompletionEvent(std::string &sessionGroupHandle, std::string &mediaCompletionType);
  397. void mediaStreamUpdatedEvent(std::string &sessionHandle, std::string &sessionGroupHandle, int statusCode, std::string &statusString, int state, bool incoming);
  398. void textStreamUpdatedEvent(std::string &sessionHandle, std::string &sessionGroupHandle, bool enabled, int state, bool incoming);
  399. void sessionAddedEvent(std::string &uriString, std::string &alias, std::string &sessionHandle, std::string &sessionGroupHandle, bool isChannel, bool incoming, std::string &nameString, std::string &applicationString);
  400. void sessionGroupAddedEvent(std::string &sessionGroupHandle);
  401. void sessionRemovedEvent(std::string &sessionHandle, std::string &sessionGroupHandle);
  402. void participantAddedEvent(std::string &sessionHandle, std::string &sessionGroupHandle, std::string &uriString, std::string &alias, std::string &nameString, std::string &displayNameString, int participantType);
  403. void participantRemovedEvent(std::string &sessionHandle, std::string &sessionGroupHandle, std::string &uriString, std::string &alias, std::string &nameString);
  404. void participantUpdatedEvent(std::string &sessionHandle, std::string &sessionGroupHandle, std::string &uriString, std::string &alias, bool isModeratorMuted, bool isSpeaking, int volume, F32 energy);
  405. void auxAudioPropertiesEvent(F32 energy);
  406. void buddyPresenceEvent(std::string &uriString, std::string &alias, std::string &statusString, std::string &applicationString);
  407. void messageEvent(std::string &sessionHandle, std::string &uriString, std::string &alias, std::string &messageHeader, std::string &messageBody, std::string &applicationString);
  408. void sessionNotificationEvent(std::string &sessionHandle, std::string &uriString, std::string &notificationType);
  409. void subscriptionEvent(std::string &buddyURI, std::string &subscriptionHandle, std::string &alias, std::string &displayName, std::string &applicationString, std::string &subscriptionType);
  410. void buddyListChanged();
  411. void muteListChanged();
  412. void updateFriends(U32 mask);
  413. /////////////////////////////
  414. // Sending updates of current state
  415. void updatePosition(void);
  416. void setCameraPosition(const LLVector3d &position, const LLVector3 &velocity, const LLMatrix3 &rot);
  417. void setAvatarPosition(const LLVector3d &position, const LLVector3 &velocity, const LLMatrix3 &rot);
  418. bool channelFromRegion(LLViewerRegion *region, std::string &name);
  419. void setEarLocation(S32 loc);
  420. /////////////////////////////
  421. // Accessors for data related to nearby speakers
  422. // MBW -- XXX -- Not sure how to get this data out of the TVC
  423. BOOL getUsingPTT(const LLUUID& id);
  424. std::string getGroupID(const LLUUID& id); // group ID if the user is in group chat (empty string if not applicable)
  425. /////////////////////////////
  426. BOOL getAreaVoiceDisabled(); // returns true if the area the avatar is in is speech-disabled.
  427. // Use this to determine whether to show a "no speech" icon in the menu bar.
  428. /////////////////////////////
  429. // Recording controls
  430. void recordingLoopStart(int seconds = 3600, int deltaFramesPerControlFrame = 200);
  431. void recordingLoopSave(const std::string& filename);
  432. void recordingStop();
  433. // Playback controls
  434. void filePlaybackStart(const std::string& filename);
  435. void filePlaybackStop();
  436. void filePlaybackSetPaused(bool paused);
  437. void filePlaybackSetMode(bool vox = false, float speed = 1.0f);
  438. participantState *findParticipantByID(const LLUUID& id);
  439. ////////////////////////////////////////
  440. // voice sessions.
  441. typedef std::set<sessionState*> sessionSet;
  442. typedef sessionSet::iterator sessionIterator;
  443. sessionIterator sessionsBegin(void);
  444. sessionIterator sessionsEnd(void);
  445. sessionState *findSession(const std::string &handle);
  446. sessionState *findSessionBeingCreatedByURI(const std::string &uri);
  447. sessionState *findSession(const LLUUID &participant_id);
  448. sessionState *findSessionByCreateID(const std::string &create_id);
  449. sessionState *addSession(const std::string &uri, const std::string &handle = LLStringUtil::null);
  450. void setSessionHandle(sessionState *session, const std::string &handle = LLStringUtil::null);
  451. void setSessionURI(sessionState *session, const std::string &uri);
  452. void deleteSession(sessionState *session);
  453. void deleteAllSessions(void);
  454. void verifySessionState(void);
  455. void joinedAudioSession(sessionState *session);
  456. void leftAudioSession(sessionState *session);
  457. // This is called in several places where the session _may_ need to be deleted.
  458. // It contains logic for whether to delete the session or keep it around.
  459. void reapSession(sessionState *session);
  460. // Returns true if the session seems to indicate we've moved to a region on a different voice server
  461. bool sessionNeedsRelog(sessionState *session);
  462. //////////////////////////////////////
  463. // buddy list stuff, needed for SLIM later
  464. struct buddyListEntry
  465. {
  466. buddyListEntry(const std::string &uri);
  467. std::string mURI;
  468. std::string mDisplayName;
  469. LLUUID mUUID;
  470. bool mOnlineSL;
  471. bool mOnlineSLim;
  472. bool mCanSeeMeOnline;
  473. bool mHasBlockListEntry;
  474. bool mHasAutoAcceptListEntry;
  475. bool mNameResolved;
  476. bool mInSLFriends;
  477. bool mInVivoxBuddies;
  478. bool mNeedsNameUpdate;
  479. };
  480. typedef std::map<std::string, buddyListEntry*> buddyListMap;
  481. // This should be called when parsing a buddy list entry sent by SLVoice.
  482. void processBuddyListEntry(const std::string &uri, const std::string &displayName);
  483. buddyListEntry *addBuddy(const std::string &uri);
  484. buddyListEntry *addBuddy(const std::string &uri, const std::string &displayName);
  485. buddyListEntry *findBuddy(const std::string &uri);
  486. buddyListEntry *findBuddy(const LLUUID &id);
  487. buddyListEntry *findBuddyByDisplayName(const std::string &name);
  488. void deleteBuddy(const std::string &uri);
  489. void deleteAllBuddies(void);
  490. void deleteAllBlockRules(void);
  491. void addBlockRule(const std::string &blockMask, const std::string &presenceOnly);
  492. void deleteAllAutoAcceptRules(void);
  493. void addAutoAcceptRule(const std::string &autoAcceptMask, const std::string &autoAddAsBuddy);
  494. void accountListBlockRulesResponse(int statusCode, const std::string &statusString);
  495. void accountListAutoAcceptRulesResponse(int statusCode, const std::string &statusString);
  496. /////////////////////////////
  497. // session control messages
  498. void accountListBlockRulesSendMessage();
  499. void accountListAutoAcceptRulesSendMessage();
  500. void sessionGroupCreateSendMessage();
  501. void sessionCreateSendMessage(sessionState *session, bool startAudio = true, bool startText = false);
  502. void sessionGroupAddSessionSendMessage(sessionState *session, bool startAudio = true, bool startText = false);
  503. void sessionMediaConnectSendMessage(sessionState *session); // just joins the audio session
  504. void sessionTextConnectSendMessage(sessionState *session); // just joins the text session
  505. void sessionTerminateSendMessage(sessionState *session);
  506. void sessionGroupTerminateSendMessage(sessionState *session);
  507. void sessionMediaDisconnectSendMessage(sessionState *session);
  508. void sessionTextDisconnectSendMessage(sessionState *session);
  509. // Pokes the state machine to leave the audio session next time around.
  510. void sessionTerminate();
  511. // Pokes the state machine to shut down the connector and restart it.
  512. void requestRelog();
  513. // Does the actual work to get out of the audio session
  514. void leaveAudioSession();
  515. // notifies the voice client that we've received parcel voice info
  516. bool parcelVoiceInfoReceived(state requesting_state);
  517. friend class LLVivoxVoiceClientCapResponder;
  518. void lookupName(const LLUUID &id);
  519. void onAvatarNameCache(const LLUUID& id, const LLAvatarName& av_name);
  520. void avatarNameResolved(const LLUUID &id, const std::string &name);
  521. /////////////////////////////
  522. // Voice fonts
  523. void addVoiceFont(const S32 id,
  524. const std::string &name,
  525. const std::string &description,
  526. const LLDate &expiration_date,
  527. bool has_expired,
  528. const S32 font_type,
  529. const S32 font_status,
  530. const bool template_font = false);
  531. void accountGetSessionFontsResponse(int statusCode, const std::string &statusString);
  532. void accountGetTemplateFontsResponse(int statusCode, const std::string &statusString);
  533. private:
  534. LLVoiceVersionInfo mVoiceVersion;
  535. /// Clean up objects created during a voice session.
  536. void cleanUp();
  537. state mState;
  538. bool mSessionTerminateRequested;
  539. bool mRelogRequested;
  540. // Number of times (in a row) "stateJoiningSession" case for spatial channel is reached in stateMachine().
  541. // The larger it is the greater is possibility there is a problem with connection to voice server.
  542. // Introduced while fixing EXT-4313.
  543. int mSpatialJoiningNum;
  544. void setState(state inState);
  545. state getState(void) { return mState; };
  546. std::string state2string(state inState);
  547. void stateMachine();
  548. static void idle(void *user_data);
  549. LLHost mDaemonHost;
  550. LLSocket::ptr_t mSocket;
  551. bool mConnected;
  552. LLPumpIO *mPump;
  553. friend class LLVivoxProtocolParser;
  554. std::string mAccountName;
  555. std::string mAccountPassword;
  556. std::string mAccountDisplayName;
  557. bool mTuningMode;
  558. float mTuningEnergy;
  559. std::string mTuningAudioFile;
  560. int mTuningMicVolume;
  561. bool mTuningMicVolumeDirty;
  562. int mTuningSpeakerVolume;
  563. bool mTuningSpeakerVolumeDirty;
  564. state mTuningExitState; // state to return to when we leave tuning mode.
  565. std::string mSpatialSessionURI;
  566. std::string mSpatialSessionCredentials;
  567. std::string mMainSessionGroupHandle; // handle of the "main" session group.
  568. std::string mChannelName; // Name of the channel to be looked up
  569. bool mAreaVoiceDisabled;
  570. sessionState *mAudioSession; // Session state for the current audio session
  571. bool mAudioSessionChanged; // set to true when the above pointer gets changed, so observers can be notified.
  572. sessionState *mNextAudioSession; // Session state for the audio session we're trying to join
  573. // std::string mSessionURI; // URI of the session we're in.
  574. // std::string mSessionHandle; // returned by ?
  575. S32 mCurrentParcelLocalID; // Used to detect parcel boundary crossings
  576. std::string mCurrentRegionName; // Used to detect parcel boundary crossings
  577. std::string mConnectorHandle; // returned by "Create Connector" message
  578. std::string mAccountHandle; // returned by login message
  579. int mNumberOfAliases;
  580. U32 mCommandCookie;
  581. std::string mVoiceAccountServerURI;
  582. std::string mVoiceSIPURIHostName;
  583. int mLoginRetryCount;
  584. sessionMap mSessionsByHandle; // Active sessions, indexed by session handle. Sessions which are being initiated may not be in this map.
  585. sessionSet mSessions; // All sessions, not indexed. This is the canonical session list.
  586. bool mBuddyListMapPopulated;
  587. bool mBlockRulesListReceived;
  588. bool mAutoAcceptRulesListReceived;
  589. buddyListMap mBuddyListMap;
  590. LLVoiceDeviceList mCaptureDevices;
  591. LLVoiceDeviceList mRenderDevices;
  592. std::string mCaptureDevice;
  593. std::string mRenderDevice;
  594. bool mCaptureDeviceDirty;
  595. bool mRenderDeviceDirty;
  596. bool checkParcelChanged(bool update = false);
  597. // This should be called when the code detects we have changed parcels.
  598. // It initiates the call to the server that gets the parcel channel.
  599. bool requestParcelVoiceInfo();
  600. void switchChannel(std::string uri = std::string(), bool spatial = true, bool no_reconnect = false, bool is_p2p = false, std::string hash = "");
  601. void joinSession(sessionState *session);
  602. std::string nameFromAvatar(LLVOAvatar *avatar);
  603. std::string nameFromID(const LLUUID &id);
  604. bool IDFromName(const std::string name, LLUUID &uuid);
  605. std::string displayNameFromAvatar(LLVOAvatar *avatar);
  606. std::string sipURIFromAvatar(LLVOAvatar *avatar);
  607. std::string sipURIFromName(std::string &name);
  608. // Returns the name portion of the SIP URI if the string looks vaguely like a SIP URI, or an empty string if not.
  609. std::string nameFromsipURI(const std::string &uri);
  610. bool inSpatialChannel(void);
  611. std::string getAudioSessionURI();
  612. std::string getAudioSessionHandle();
  613. void sendPositionalUpdate(void);
  614. void buildSetCaptureDevice(std::ostringstream &stream);
  615. void buildSetRenderDevice(std::ostringstream &stream);
  616. void clearAllLists();
  617. void checkFriend(const LLUUID& id);
  618. void sendFriendsListUpdates();
  619. // start a text IM session with the specified user
  620. // This will be asynchronous, the session may be established at a future time.
  621. sessionState* startUserIMSession(const LLUUID& uuid);
  622. void sendQueuedTextMessages(sessionState *session);
  623. void enforceTether(void);
  624. bool mSpatialCoordsDirty;
  625. LLVector3d mCameraPosition;
  626. LLVector3d mCameraRequestedPosition;
  627. LLVector3 mCameraVelocity;
  628. LLMatrix3 mCameraRot;
  629. LLVector3d mAvatarPosition;
  630. LLVector3 mAvatarVelocity;
  631. LLMatrix3 mAvatarRot;
  632. bool mMuteMic;
  633. bool mMuteMicDirty;
  634. // Set to true when the friends list is known to have changed.
  635. bool mFriendsListDirty;
  636. enum
  637. {
  638. earLocCamera = 0, // ear at camera
  639. earLocAvatar, // ear at avatar
  640. earLocMixed // ear at avatar location/camera direction
  641. };
  642. S32 mEarLocation;
  643. bool mSpeakerVolumeDirty;
  644. bool mSpeakerMuteDirty;
  645. int mSpeakerVolume;
  646. int mMicVolume;
  647. bool mMicVolumeDirty;
  648. bool mVoiceEnabled;
  649. bool mWriteInProgress;
  650. std::string mWriteString;
  651. size_t mWriteOffset;
  652. LLTimer mUpdateTimer;
  653. BOOL mLipSyncEnabled;
  654. typedef std::set<LLVoiceClientParticipantObserver*> observer_set_t;
  655. observer_set_t mParticipantObservers;
  656. void notifyParticipantObservers();
  657. typedef std::set<LLVoiceClientStatusObserver*> status_observer_set_t;
  658. status_observer_set_t mStatusObservers;
  659. void notifyStatusObservers(LLVoiceClientStatusObserver::EStatusType status);
  660. typedef std::set<LLFriendObserver*> friend_observer_set_t;
  661. friend_observer_set_t mFriendObservers;
  662. void notifyFriendObservers();
  663. // Voice Fonts
  664. void expireVoiceFonts();
  665. void deleteVoiceFont(const LLUUID& id);
  666. void deleteAllVoiceFonts();
  667. void deleteVoiceFontTemplates();
  668. S32 getVoiceFontIndex(const LLUUID& id) const;
  669. S32 getVoiceFontTemplateIndex(const LLUUID& id) const;
  670. void accountGetSessionFontsSendMessage();
  671. void accountGetTemplateFontsSendMessage();
  672. void sessionSetVoiceFontSendMessage(sessionState *session);
  673. void notifyVoiceFontObservers();
  674. typedef enum e_voice_font_type
  675. {
  676. VOICE_FONT_TYPE_NONE = 0,
  677. VOICE_FONT_TYPE_ROOT = 1,
  678. VOICE_FONT_TYPE_USER = 2,
  679. VOICE_FONT_TYPE_UNKNOWN
  680. } EVoiceFontType;
  681. typedef enum e_voice_font_status
  682. {
  683. VOICE_FONT_STATUS_NONE = 0,
  684. VOICE_FONT_STATUS_FREE = 1,
  685. VOICE_FONT_STATUS_NOT_FREE = 2,
  686. VOICE_FONT_STATUS_UNKNOWN
  687. } EVoiceFontStatus;
  688. struct voiceFontEntry
  689. {
  690. voiceFontEntry(LLUUID& id);
  691. ~voiceFontEntry();
  692. LLUUID mID;
  693. S32 mFontIndex;
  694. std::string mName;
  695. LLDate mExpirationDate;
  696. S32 mFontType;
  697. S32 mFontStatus;
  698. bool mIsNew;
  699. LLFrameTimer mExpiryTimer;
  700. LLFrameTimer mExpiryWarningTimer;
  701. };
  702. bool mVoiceFontsReceived;
  703. bool mVoiceFontsNew;
  704. bool mVoiceFontListDirty;
  705. voice_effect_list_t mVoiceFontList;
  706. voice_effect_list_t mVoiceFontTemplateList;
  707. typedef std::map<const LLUUID, voiceFontEntry*> voice_font_map_t;
  708. voice_font_map_t mVoiceFontMap;
  709. voice_font_map_t mVoiceFontTemplateMap;
  710. typedef std::set<LLVoiceEffectObserver*> voice_font_observer_set_t;
  711. voice_font_observer_set_t mVoiceFontObservers;
  712. LLFrameTimer mVoiceFontExpiryTimer;
  713. // Audio capture buffer
  714. void captureBufferRecordStartSendMessage();
  715. void captureBufferRecordStopSendMessage();
  716. void captureBufferPlayStartSendMessage(const LLUUID& voice_font_id = LLUUID::null);
  717. void captureBufferPlayStopSendMessage();
  718. bool mCaptureBufferMode; // Disconnected from voice channels while using the capture buffer.
  719. bool mCaptureBufferRecording; // A voice sample is being captured.
  720. bool mCaptureBufferRecorded; // A voice sample is captured in the buffer ready to play.
  721. bool mCaptureBufferPlaying; // A voice sample is being played.
  722. LLTimer mCaptureTimer;
  723. LLUUID mPreviewVoiceFont;
  724. LLUUID mPreviewVoiceFontLast;
  725. S32 mPlayRequestCount;
  726. };
  727. /**
  728. * @class LLVivoxProtocolParser
  729. * @brief This class helps construct new LLIOPipe specializations
  730. * @see LLIOPipe
  731. *
  732. * THOROUGH_DESCRIPTION
  733. */
  734. class LLVivoxProtocolParser : public LLIOPipe
  735. {
  736. LOG_CLASS(LLVivoxProtocolParser);
  737. public:
  738. LLVivoxProtocolParser();
  739. virtual ~LLVivoxProtocolParser();
  740. protected:
  741. /* @name LLIOPipe virtual implementations
  742. */
  743. //@{
  744. /**
  745. * @brief Process the data in buffer
  746. */
  747. virtual EStatus process_impl(
  748. const LLChannelDescriptors& channels,
  749. buffer_ptr_t& buffer,
  750. bool& eos,
  751. LLSD& context,
  752. LLPumpIO* pump);
  753. //@}
  754. std::string mInput;
  755. // Expat control members
  756. XML_Parser parser;
  757. int responseDepth;
  758. bool ignoringTags;
  759. bool isEvent;
  760. int ignoreDepth;
  761. // Members for processing responses. The values are transient and only valid within a call to processResponse().
  762. bool squelchDebugOutput;
  763. int returnCode;
  764. int statusCode;
  765. std::string statusString;
  766. std::string requestId;
  767. std::string actionString;
  768. std::string connectorHandle;
  769. std::string versionID;
  770. std::string accountHandle;
  771. std::string sessionHandle;
  772. std::string sessionGroupHandle;
  773. std::string alias;
  774. std::string applicationString;
  775. // Members for processing events. The values are transient and only valid within a call to processResponse().
  776. std::string eventTypeString;
  777. int state;
  778. std::string uriString;
  779. bool isChannel;
  780. bool incoming;
  781. bool enabled;
  782. std::string nameString;
  783. std::string audioMediaString;
  784. std::string deviceString;
  785. std::string displayNameString;
  786. int participantType;
  787. bool isLocallyMuted;
  788. bool isModeratorMuted;
  789. bool isSpeaking;
  790. int volume;
  791. F32 energy;
  792. std::string messageHeader;
  793. std::string messageBody;
  794. std::string notificationType;
  795. bool hasText;
  796. bool hasAudio;
  797. bool hasVideo;
  798. bool terminated;
  799. std::string blockMask;
  800. std::string presenceOnly;
  801. std::string autoAcceptMask;
  802. std::string autoAddAsBuddy;
  803. int numberOfAliases;
  804. std::string subscriptionHandle;
  805. std::string subscriptionType;
  806. S32 id;
  807. std::string descriptionString;
  808. LLDate expirationDate;
  809. bool hasExpired;
  810. S32 fontType;
  811. S32 fontStatus;
  812. std::string mediaCompletionType;
  813. // Members for processing text between tags
  814. std::string textBuffer;
  815. bool accumulateText;
  816. void reset();
  817. void processResponse(std::string tag);
  818. static void XMLCALL ExpatStartTag(void *data, const char *el, const char **attr);
  819. static void XMLCALL ExpatEndTag(void *data, const char *el);
  820. static void XMLCALL ExpatCharHandler(void *data, const XML_Char *s, int len);
  821. void StartTag(const char *tag, const char **attr);
  822. void EndTag(const char *tag);
  823. void CharData(const char *buffer, int length);
  824. LLDate expiryTimeStampToLLDate(const std::string& vivox_ts);
  825. };
  826. #endif //LL_VIVOX_VOICE_CLIENT_H