00001
00031 #ifndef LL_VOICE_CLIENT_H
00032 #define LL_VOICE_CLIENT_H
00033
00034
00035
00036 class LLVOAvatar;
00037 class LLVivoxProtocolParser;
00038
00039 #include "lliopipe.h"
00040 #include "llpumpio.h"
00041 #include "llchainio.h"
00042 #include "lliosocket.h"
00043 #include "v3math.h"
00044 #include "llframetimer.h"
00045 #include "llviewerregion.h"
00046
00047 class LLVoiceClientParticipantObserver
00048 {
00049 public:
00050 virtual ~LLVoiceClientParticipantObserver() { }
00051 virtual void onChange() = 0;
00052 };
00053
00054 class LLVoiceClientStatusObserver
00055 {
00056 public:
00057 typedef enum e_voice_status_type
00058 {
00059
00060
00061 STATUS_LOGIN_RETRY,
00062 STATUS_LOGGED_IN,
00063 STATUS_JOINING,
00064 STATUS_JOINED,
00065 STATUS_LEFT_CHANNEL,
00066 STATUS_VOICE_DISABLED,
00067 BEGIN_ERROR_STATUS,
00068 ERROR_CHANNEL_FULL,
00069 ERROR_CHANNEL_LOCKED,
00070 ERROR_NOT_AVAILABLE,
00071 ERROR_UNKNOWN
00072 } EStatusType;
00073
00074 virtual ~LLVoiceClientStatusObserver() { }
00075 virtual void onChange(EStatusType status, const std::string &channelURI, bool proximal) = 0;
00076
00077 static const char *status2string(EStatusType inStatus);
00078 };
00079
00080 class LLVoiceClient: public LLSingleton<LLVoiceClient>
00081 {
00082 LOG_CLASS(LLVoiceClient);
00083 public:
00084 LLVoiceClient();
00085 ~LLVoiceClient();
00086
00087 public:
00088 static void init(LLPumpIO *pump);
00089 static void terminate();
00090
00091 protected:
00092 bool writeString(const std::string &str);
00093
00094 public:
00095
00096 enum serviceType
00097 {
00098 serviceTypeUnknown,
00099 serviceTypeA,
00100 serviceTypeB,
00101 serviceTypeC
00102 };
00103 static F32 OVERDRIVEN_POWER_LEVEL;
00104
00106
00107 void connect();
00108
00109 void connectorCreate();
00110 void connectorShutdown();
00111
00112 void requestVoiceAccountProvision(S32 retries = 3);
00113 void userAuthorized(
00114 const std::string& firstName,
00115 const std::string& lastName,
00116 const LLUUID &agentID);
00117 void login(const std::string& accountName, const std::string &password);
00118 void loginSendMessage();
00119 void logout();
00120 void logoutSendMessage();
00121
00122 void channelGetListSendMessage();
00123 void sessionCreateSendMessage();
00124 void sessionConnectSendMessage();
00125 void sessionTerminate();
00126 void sessionTerminateSendMessage();
00127 void sessionTerminateByHandle(std::string &sessionHandle);
00128
00129 void getCaptureDevicesSendMessage();
00130 void getRenderDevicesSendMessage();
00131
00132 void clearCaptureDevices();
00133 void addCaptureDevice(const std::string& name);
00134 void setCaptureDevice(const std::string& name);
00135
00136 void clearRenderDevices();
00137 void addRenderDevice(const std::string& name);
00138 void setRenderDevice(const std::string& name);
00139
00140 void tuningStart();
00141 void tuningStop();
00142 bool inTuningMode();
00143 bool inTuningStates();
00144
00145 void tuningRenderStartSendMessage(const std::string& name, bool loop);
00146 void tuningRenderStopSendMessage();
00147
00148 void tuningCaptureStartSendMessage(int duration);
00149 void tuningCaptureStopSendMessage();
00150
00151 void tuningSetMicVolume(float volume);
00152 void tuningSetSpeakerVolume(float volume);
00153 float tuningGetEnergy(void);
00154
00155
00156
00157 bool deviceSettingsAvailable();
00158
00159
00160
00161
00162
00163 void refreshDeviceLists(bool clearCurrentList = true);
00164
00165
00166 void daemonDied();
00167
00168
00169 void giveUp();
00170
00172
00173 void connectorCreateResponse(int statusCode, std::string &statusString, std::string &connectorHandle);
00174 void loginResponse(int statusCode, std::string &statusString, std::string &accountHandle);
00175 void channelGetListResponse(int statusCode, std::string &statusString);
00176 void sessionCreateResponse(int statusCode, std::string &statusString, std::string &sessionHandle);
00177 void sessionConnectResponse(int statusCode, std::string &statusString);
00178 void sessionTerminateResponse(int statusCode, std::string &statusString);
00179 void logoutResponse(int statusCode, std::string &statusString);
00180 void connectorShutdownResponse(int statusCode, std::string &statusString);
00181
00182 void loginStateChangeEvent(std::string &accountHandle, int statusCode, std::string &statusString, int state);
00183 void sessionNewEvent(std::string &accountHandle, std::string &eventSessionHandle, int state, std::string &nameString, std::string &uriString);
00184 void sessionStateChangeEvent(std::string &uriString, int statusCode, std::string &statusString, std::string &sessionHandle, int state, bool isChannel, std::string &nameString);
00185 void participantStateChangeEvent(std::string &uriString, int statusCode, std::string &statusString, int state, std::string &nameString, std::string &displayNameString, int participantType);
00186 void participantPropertiesEvent(std::string &uriString, int statusCode, std::string &statusString, bool isLocallyMuted, bool isModeratorMuted, bool isSpeaking, int volume, F32 energy);
00187 void auxAudioPropertiesEvent(F32 energy);
00188
00189 void muteListChanged();
00190
00192
00193 void setCameraPosition(const LLVector3d &position, const LLVector3 &velocity, const LLMatrix3 &rot);
00194 void setAvatarPosition(const LLVector3d &position, const LLVector3 &velocity, const LLMatrix3 &rot);
00195 bool channelFromRegion(LLViewerRegion *region, std::string &name);
00196 void leaveChannel(void);
00197
00198
00199 void setMuteMic(bool muted);
00200 void setUserPTTState(bool ptt);
00201 bool getUserPTTState();
00202 void toggleUserPTTState(void);
00203 void setVoiceEnabled(bool enabled);
00204 static bool voiceEnabled();
00205 void setUsePTT(bool usePTT);
00206 void setPTTIsToggle(bool PTTIsToggle);
00207 void setPTTKey(std::string &key);
00208 void setEarLocation(S32 loc);
00209 void setVoiceVolume(F32 volume);
00210 void setMicGain(F32 volume);
00211 void setUserVolume(const LLUUID& id, F32 volume);
00212 void setVivoxDebugServerName(std::string &serverName);
00213 void setLipSyncEnabled(U32 enabled);
00214 U32 lipSyncEnabled();
00215
00216
00217 void keyDown(KEY key, MASK mask);
00218 void keyUp(KEY key, MASK mask);
00219 void middleMouseState(bool down);
00220
00222
00223 BOOL getVoiceEnabled(const LLUUID& id);
00224 BOOL getIsSpeaking(const LLUUID& id);
00225 BOOL getIsModeratorMuted(const LLUUID& id);
00226 F32 getCurrentPower(const LLUUID& id);
00227 BOOL getPTTPressed(const LLUUID& id);
00228 BOOL getOnMuteList(const LLUUID& id);
00229 F32 getUserVolume(const LLUUID& id);
00230 LLString getDisplayName(const LLUUID& id);
00231
00232
00233 BOOL getUsingPTT(const LLUUID& id);
00234 serviceType getServiceType(const LLUUID& id);
00235 std::string getGroupID(const LLUUID& id);
00236
00238 BOOL getAreaVoiceDisabled();
00239
00240
00241 struct participantState
00242 {
00243 public:
00244 participantState(const std::string &uri);
00245 std::string mURI;
00246 std::string mName;
00247 std::string mDisplayName;
00248 bool mPTT;
00249 bool mIsSpeaking;
00250 bool mIsModeratorMuted;
00251 LLFrameTimer mSpeakingTimeout;
00252 F32 mLastSpokeTimestamp;
00253 F32 mPower;
00254 int mVolume;
00255 serviceType mServiceType;
00256 std::string mGroupID;
00257 bool mOnMuteList;
00258 int mUserVolume;
00259 bool mVolumeDirty;
00260 bool mAvatarIDValid;
00261 LLUUID mAvatarID;
00262 };
00263 typedef std::map<std::string, participantState*> participantMap;
00264
00265 participantState *findParticipant(const std::string &uri);
00266 participantState *findParticipantByAvatar(LLVOAvatar *avatar);
00267 participantState *findParticipantByID(const LLUUID& id);
00268
00269 participantMap *getParticipantList(void);
00270
00271 void addObserver(LLVoiceClientParticipantObserver* observer);
00272 void removeObserver(LLVoiceClientParticipantObserver* observer);
00273
00274 void addStatusObserver(LLVoiceClientStatusObserver* observer);
00275 void removeStatusObserver(LLVoiceClientStatusObserver* observer);
00276
00277 static void onAvatarNameLookup(const LLUUID& id, const char* first, const char* last, BOOL is_group, void* user_data);
00278 typedef std::vector<std::string> deviceList;
00279
00280 deviceList *getCaptureDevices();
00281 deviceList *getRenderDevices();
00282
00283 void setNonSpatialChannel(
00284 const std::string &uri,
00285 const std::string &credentials);
00286 void setSpatialChannel(
00287 const std::string &uri,
00288 const std::string &credentials);
00289 void callUser(LLUUID &uuid);
00290 void answerInvite(std::string &sessionHandle, LLUUID& other_user_id);
00291 void declineInvite(std::string &sessionHandle);
00292 void leaveNonSpatialChannel();
00293
00294
00295
00296 std::string getCurrentChannel();
00297
00298
00299
00300 bool inProximalChannel();
00301
00302 std::string sipURIFromID(const LLUUID &id);
00303
00304 private:
00305
00306
00307
00308 enum state
00309 {
00310 stateDisabled,
00311 stateStart,
00312 stateDaemonLaunched,
00313 stateConnecting,
00314 stateIdle,
00315 stateConnectorStart,
00316 stateConnectorStarting,
00317 stateConnectorStarted,
00318 stateMicTuningNoLogin,
00319 stateLoginRetry,
00320 stateLoginRetryWait,
00321 stateNeedsLogin,
00322 stateLoggingIn,
00323 stateLoggedIn,
00324 stateNoChannel,
00325 stateMicTuningStart,
00326 stateMicTuningRunning,
00327 stateMicTuningStop,
00328 stateSessionCreate,
00329 stateSessionConnect,
00330 stateJoiningSession,
00331 stateSessionJoined,
00332 stateRunning,
00333 stateLeavingSession,
00334 stateSessionTerminated,
00335
00336 stateLoggingOut,
00337 stateLoggedOut,
00338 stateConnectorStopping,
00339 stateConnectorStopped,
00340
00341
00342
00343
00344 stateConnectorFailed,
00345 stateConnectorFailedWaiting,
00346 stateLoginFailed,
00347 stateLoginFailedWaiting,
00348 stateJoinSessionFailed,
00349 stateJoinSessionFailedWaiting,
00350
00351 stateJail
00352 };
00353
00354 state mState;
00355 bool mSessionTerminateRequested;
00356 bool mNonSpatialChannel;
00357
00358 void setState(state inState);
00359 state getState(void) { return mState; };
00360 static const char *state2string(state inState);
00361
00362 void stateMachine();
00363 static void idle(void *user_data);
00364
00365 LLHost mDaemonHost;
00366 LLSocket::ptr_t mSocket;
00367 bool mConnected;
00368
00369 void closeSocket(void);
00370
00371 LLPumpIO *mPump;
00372 friend class LLVivoxProtocolParser;
00373
00374 std::string mAccountName;
00375 std::string mAccountPassword;
00376 std::string mAccountDisplayName;
00377 std::string mAccountFirstName;
00378 std::string mAccountLastName;
00379
00380 std::string mNextP2PSessionURI;
00381 std::string mNextSessionURI;
00382 std::string mNextSessionHandle;
00383 std::string mNextSessionHash;
00384 bool mNextSessionSpatial;
00385 bool mNextSessionNoReconnect;
00386 bool mNextSessionResetOnClose;
00387
00388 std::string mSessionStateEventHandle;
00389 std::string mSessionStateEventURI;
00390
00391 bool mTuningMode;
00392 float mTuningEnergy;
00393 std::string mTuningAudioFile;
00394 int mTuningMicVolume;
00395 bool mTuningMicVolumeDirty;
00396 int mTuningSpeakerVolume;
00397 bool mTuningSpeakerVolumeDirty;
00398 state mTuningExitState;
00399
00400 std::string mSpatialSessionURI;
00401
00402 bool mSessionResetOnClose;
00403
00404 int mVivoxErrorStatusCode;
00405 std::string mVivoxErrorStatusString;
00406
00407 std::string mChannelName;
00408 bool mAreaVoiceDisabled;
00409 std::string mSessionURI;
00410 bool mSessionP2P;
00411
00412 S32 mCurrentParcelLocalID;
00413 std::string mCurrentRegionName;
00414
00415 std::string mConnectorHandle;
00416 std::string mAccountHandle;
00417 std::string mSessionHandle;
00418 U32 mCommandCookie;
00419
00420 std::string mAccountServerName;
00421 std::string mAccountServerURI;
00422
00423 int mLoginRetryCount;
00424
00425 participantMap mParticipantMap;
00426 bool mParticipantMapChanged;
00427
00428 deviceList mCaptureDevices;
00429 deviceList mRenderDevices;
00430
00431 std::string mCaptureDevice;
00432 std::string mRenderDevice;
00433 bool mCaptureDeviceDirty;
00434 bool mRenderDeviceDirty;
00435
00436 participantState *addParticipant(const std::string &uri);
00437
00438
00439 void removeParticipant(participantState *participant);
00440 void removeAllParticipants();
00441
00442 void updateMuteState(participantState *participant);
00443
00444 typedef std::map<std::string, std::string> channelMap;
00445 channelMap mChannelMap;
00446
00447
00448 void clearChannelMap(void);
00449 void addChannelMapEntry(std::string &name, std::string &uri);
00450 std::string findChannelURI(std::string &name);
00451
00452
00453
00454 void parcelChanged();
00455
00456 void switchChannel(std::string uri = std::string(), bool spatial = true, bool noReconnect = false, std::string hash = "");
00457 void joinSession(std::string handle, std::string uri);
00458
00459 std::string nameFromAvatar(LLVOAvatar *avatar);
00460 std::string nameFromID(const LLUUID &id);
00461 bool IDFromName(const std::string name, LLUUID &uuid);
00462 std::string displayNameFromAvatar(LLVOAvatar *avatar);
00463 std::string sipURIFromAvatar(LLVOAvatar *avatar);
00464 std::string sipURIFromName(std::string &name);
00465
00466 void sendPositionalUpdate(void);
00467
00468 void buildSetCaptureDevice(std::ostringstream &stream);
00469 void buildSetRenderDevice(std::ostringstream &stream);
00470
00471 void enforceTether(void);
00472
00473 bool mSpatialCoordsDirty;
00474
00475 LLVector3d mCameraPosition;
00476 LLVector3d mCameraRequestedPosition;
00477 LLVector3 mCameraVelocity;
00478 LLMatrix3 mCameraRot;
00479
00480 LLVector3d mAvatarPosition;
00481 LLVector3 mAvatarVelocity;
00482 LLMatrix3 mAvatarRot;
00483
00484 bool mPTTDirty;
00485 bool mPTT;
00486
00487 bool mUsePTT;
00488 bool mPTTIsMiddleMouse;
00489 KEY mPTTKey;
00490 bool mPTTIsToggle;
00491 bool mUserPTTState;
00492 bool mMuteMic;
00493
00494
00495
00496 bool mVolumeDirty;
00497
00498 enum
00499 {
00500 earLocCamera = 0,
00501 earLocAvatar,
00502 earLocMixed
00503 };
00504
00505 S32 mEarLocation;
00506
00507 bool mSpeakerVolumeDirty;
00508 bool mSpeakerMuteDirty;
00509 int mSpeakerVolume;
00510
00511 int mMicVolume;
00512 bool mMicVolumeDirty;
00513
00514 bool mVoiceEnabled;
00515 bool mWriteInProgress;
00516 std::string mWriteString;
00517 size_t mWriteOffset;
00518
00519 LLTimer mUpdateTimer;
00520
00521 U32 mLipSyncEnabled;
00522
00523 typedef std::set<LLVoiceClientParticipantObserver*> observer_set_t;
00524 observer_set_t mObservers;
00525
00526 void notifyObservers();
00527
00528 typedef std::set<LLVoiceClientStatusObserver*> status_observer_set_t;
00529 status_observer_set_t mStatusObservers;
00530
00531 void notifyStatusObservers(LLVoiceClientStatusObserver::EStatusType status);
00532 };
00533
00534 extern LLVoiceClient *gVoiceClient;
00535
00536 #endif //LL_VOICE_CLIENT_H
00537
00538
00539