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