summaryrefslogtreecommitdiff
path: root/indra/newview/llvoiceclient.cpp
blob: 76cf7ad3ddd4816f491216a31956f79b8f3bb4dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
 /** 
 * @file llvoiceclient.cpp
 * @brief Voice client delegation class implementation.
 *
 * $LicenseInfo:firstyear=2001&license=viewergpl$
 * 
 * Copyright (c) 2001-2009, Linden Research, Inc.
 * 
 * Second Life Viewer Source Code
 * The source code in this file ("Source Code") is provided by Linden Lab
 * to you under the terms of the GNU General Public License, version 2.0
 * ("GPL"), unless you have obtained a separate licensing agreement
 * ("Other License"), formally executed by you and Linden Lab.  Terms of
 * the GPL can be found in doc/GPL-license.txt in this distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
 * 
 * There are special exceptions to the terms and conditions of the GPL as
 * it is applied to this Source Code. View the full text of the exception
 * in the file doc/FLOSS-exception.txt in this software distribution, or
 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
 * 
 * By copying, modifying or distributing this software, you acknowledge
 * that you have read and understood your obligations described above,
 * and agree to abide by those obligations.
 * 
 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
 * COMPLETENESS OR PERFORMANCE.
 * $/LicenseInfo$
 */

#include "llviewerprecompiledheaders.h"
#include "llvoiceclient.h"
#include "llviewercontrol.h"
#include "llviewerwindow.h"
#include "llvoicevivox.h"
#include "llviewernetwork.h"
#include "llcommandhandler.h"
#include "llhttpnode.h"
#include "llnotificationsutil.h"
#include "llsdserialize.h"
#include "llui.h"

const F32 LLVoiceClient::OVERDRIVEN_POWER_LEVEL = 0.7f;

const F32 LLVoiceClient::VOLUME_MIN = 0.f;
const F32 LLVoiceClient::VOLUME_DEFAULT = 0.5f;
const F32 LLVoiceClient::VOLUME_MAX = 1.0f;


// Support for secondlife:///app/voice SLapps
class LLVoiceHandler : public LLCommandHandler
{
public:
	// requests will be throttled from a non-trusted browser
	LLVoiceHandler() : LLCommandHandler("voice", UNTRUSTED_THROTTLE) {}

	bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
	{
		if (params[0].asString() == "effects")
		{
			LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
			// If the voice client doesn't support voice effects, we can't handle effects SLapps
			if (!effect_interface)
			{
				return false;
			}

			// Support secondlife:///app/voice/effects/refresh to update the voice effect list with new effects
			if (params[1].asString() == "refresh")
			{
				effect_interface->refreshVoiceEffectLists(false);
				return true;
			}
		}
		return false;
	}
};
LLVoiceHandler gVoiceHandler;



std::string LLVoiceClientStatusObserver::status2string(LLVoiceClientStatusObserver::EStatusType inStatus)
{
	std::string result = "UNKNOWN";
	
	// Prevent copy-paste errors when updating this list...
#define CASE(x)  case x:  result = #x;  break
	
	switch(inStatus)
	{
			CASE(STATUS_LOGIN_RETRY);
			CASE(STATUS_LOGGED_IN);
			CASE(STATUS_JOINING);
			CASE(STATUS_JOINED);
			CASE(STATUS_LEFT_CHANNEL);
			CASE(STATUS_VOICE_DISABLED);
			CASE(BEGIN_ERROR_STATUS);
			CASE(ERROR_CHANNEL_FULL);
			CASE(ERROR_CHANNEL_LOCKED);
			CASE(ERROR_NOT_AVAILABLE);
			CASE(ERROR_UNKNOWN);
		default:
			break;
	}
	
#undef CASE
	
	return result;
}



///////////////////////////////////////////////////////////////////////////////////////////////

LLVoiceClient::LLVoiceClient()
	:
	mVoiceModule(NULL),
	m_servicePump(NULL),
	mVoiceModule(NULL),
	mVoiceEffectEnabled(LLCachedControl<bool>(gSavedSettings, "VoiceMorphingEnabled")),
	mVoiceEffectDefault(LLCachedControl<std::string>(gSavedPerAccountSettings, "VoiceEffectDefault"))
{
}

//---------------------------------------------------
// Basic setup/shutdown

LLVoiceClient::~LLVoiceClient()
{
}

void LLVoiceClient::init(LLPumpIO *pump)
{
	// Initialize all of the voice modules
	m_servicePump = pump;
}

void LLVoiceClient::userAuthorized(const std::string& user_id, const LLUUID &agentID)
{
	// In the future, we should change this to allow voice module registration
	// with a table lookup of sorts.
	std::string voice_server = gSavedSettings.getString("VoiceServerType");
	LL_DEBUGS("Voice") << "voice server type " << voice_server << LL_ENDL;
	if(voice_server == "vivox")
	{
		mVoiceModule = (LLVoiceModuleInterface *)LLVivoxVoiceClient::getInstance();
	}
	else
	{
		mVoiceModule = NULL;
		return; 
	}
	mVoiceModule->init(m_servicePump);	
	mVoiceModule->userAuthorized(user_id, agentID);
}


void LLVoiceClient::terminate()
{
	if (mVoiceModule) mVoiceModule->terminate();
	mVoiceModule = NULL;
}

const LLVoiceVersionInfo LLVoiceClient::getVersion()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getVersion();
	}
	else
	{
		LLVoiceVersionInfo result;
		result.serverVersion = std::string();
		result.serverType = std::string();
		return result;
	}
}

void LLVoiceClient::updateSettings()
{
	if (mVoiceModule) mVoiceModule->updateSettings();
}

//--------------------------------------------------
// tuning

void LLVoiceClient::tuningStart()
{
	if (mVoiceModule) mVoiceModule->tuningStart();
}

void LLVoiceClient::tuningStop()
{
	if (mVoiceModule) mVoiceModule->tuningStop();
}

bool LLVoiceClient::inTuningMode()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->inTuningMode();
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::tuningSetMicVolume(float volume)
{
	if (mVoiceModule) mVoiceModule->tuningSetMicVolume(volume);
}

void LLVoiceClient::tuningSetSpeakerVolume(float volume)
{
	if (mVoiceModule) mVoiceModule->tuningSetSpeakerVolume(volume);
}

float LLVoiceClient::tuningGetEnergy(void)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->tuningGetEnergy();
	}
	else
	{
		return 0.0;
	}
}


//------------------------------------------------
// devices

bool LLVoiceClient::deviceSettingsAvailable()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->deviceSettingsAvailable();
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::refreshDeviceLists(bool clearCurrentList)
{
	if (mVoiceModule) mVoiceModule->refreshDeviceLists(clearCurrentList);
}

void LLVoiceClient::setCaptureDevice(const std::string& name)
{
	if (mVoiceModule) mVoiceModule->setCaptureDevice(name);
	
}

void LLVoiceClient::setRenderDevice(const std::string& name)
{
	if (mVoiceModule) mVoiceModule->setRenderDevice(name);	
}

const LLVoiceDeviceList& LLVoiceClient::getCaptureDevices()
{
	static LLVoiceDeviceList nullCaptureDevices;
	if (mVoiceModule) 
	{
		return mVoiceModule->getCaptureDevices();
	}
	else
	{
		return nullCaptureDevices;
	}
}


const LLVoiceDeviceList& LLVoiceClient::getRenderDevices()
{
	static LLVoiceDeviceList nullRenderDevices;	
	if (mVoiceModule) 
	{
		return mVoiceModule->getRenderDevices();
	}
	else
	{
		return nullRenderDevices;
	}
}


//--------------------------------------------------
// participants

void LLVoiceClient::getParticipantList(std::set<LLUUID> &participants)
{
	if (mVoiceModule) 
	{
	  mVoiceModule->getParticipantList(participants);
	}
	else
	{
	  participants = std::set<LLUUID>();
	}
}

bool LLVoiceClient::isParticipant(const LLUUID &speaker_id)
{
  if(mVoiceModule)
    {
      return mVoiceModule->isParticipant(speaker_id);
    }
  return false;
}


//--------------------------------------------------
// text chat


BOOL LLVoiceClient::isSessionTextIMPossible(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->isSessionTextIMPossible(id);
	}
	else
	{
		return FALSE;
	}	
}

BOOL LLVoiceClient::isSessionCallBackPossible(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->isSessionCallBackPossible(id);
	}
	else
	{
		return FALSE;
	}	
}

BOOL LLVoiceClient::sendTextMessage(const LLUUID& participant_id, const std::string& message)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->sendTextMessage(participant_id, message);
	}
	else
	{
		return FALSE;
	}	
}

void LLVoiceClient::endUserIMSession(const LLUUID& participant_id)
{
	if (mVoiceModule) 
	{
		mVoiceModule->endUserIMSession(participant_id);
	}
}

//----------------------------------------------
// channels

bool LLVoiceClient::inProximalChannel()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->inProximalChannel();
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::setNonSpatialChannel(
	const std::string &uri,
	const std::string &credentials)
{
	if (mVoiceModule) mVoiceModule->setNonSpatialChannel(uri, credentials);
}

void LLVoiceClient::setSpatialChannel(
	const std::string &uri,
	const std::string &credentials)
{
	if (mVoiceModule) mVoiceModule->setSpatialChannel(uri, credentials);
}

void LLVoiceClient::leaveNonSpatialChannel()
{
	if (mVoiceModule) mVoiceModule->leaveNonSpatialChannel();
}

void LLVoiceClient::leaveChannel(void)
{
	if (mVoiceModule) mVoiceModule->leaveChannel();
}

std::string LLVoiceClient::getCurrentChannel()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getCurrentChannel();
	}
	else
	{
		return std::string();
	}
}


//---------------------------------------
// invitations

void LLVoiceClient::callUser(const LLUUID &uuid)
{
	if (mVoiceModule) mVoiceModule->callUser(uuid);
}

bool LLVoiceClient::isValidChannel(std::string &session_handle)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->isValidChannel(session_handle);
	}
	else
	{
		return false;
	}
}

bool LLVoiceClient::answerInvite(std::string &channelHandle)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->answerInvite(channelHandle);
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::declineInvite(std::string &channelHandle)
{
	if (mVoiceModule) mVoiceModule->declineInvite(channelHandle);
}


//------------------------------------------
// Volume/gain


void LLVoiceClient::setVoiceVolume(F32 volume)
{
	if (mVoiceModule) mVoiceModule->setVoiceVolume(volume);
}

void LLVoiceClient::setMicGain(F32 volume)
{
	if (mVoiceModule) mVoiceModule->setMicGain(volume);
}


//------------------------------------------
// enable/disable voice features

bool LLVoiceClient::voiceEnabled()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->voiceEnabled();
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::setVoiceEnabled(bool enabled)
{
	if (mVoiceModule) mVoiceModule->setVoiceEnabled(enabled);
}

void LLVoiceClient::setLipSyncEnabled(BOOL enabled)
{
	if (mVoiceModule) mVoiceModule->setLipSyncEnabled(enabled);
}

BOOL LLVoiceClient::lipSyncEnabled()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->lipSyncEnabled();
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::setMuteMic(bool muted)
{
	if (mVoiceModule) mVoiceModule->setMuteMic(muted);
}


// ----------------------------------------------
// PTT

void LLVoiceClient::setUserPTTState(bool ptt)
{
	if (mVoiceModule) mVoiceModule->setUserPTTState(ptt);
}

bool LLVoiceClient::getUserPTTState()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getUserPTTState();
	}
	else
	{
		return false;
	}
}

void LLVoiceClient::setUsePTT(bool usePTT)
{
	if (mVoiceModule) mVoiceModule->setUsePTT(usePTT);
}

void LLVoiceClient::setPTTIsToggle(bool PTTIsToggle)
{
	if (mVoiceModule) mVoiceModule->setPTTIsToggle(PTTIsToggle);
}

bool LLVoiceClient::getPTTIsToggle()
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getPTTIsToggle();
	}
	else {
		return false;
	}

}

void LLVoiceClient::inputUserControlState(bool down)
{
	if (mVoiceModule) mVoiceModule->inputUserControlState(down);	
}

void LLVoiceClient::toggleUserPTTState(void)
{
	if (mVoiceModule) mVoiceModule->toggleUserPTTState();
}

void LLVoiceClient::keyDown(KEY key, MASK mask)
{	
	if (mVoiceModule) mVoiceModule->keyDown(key, mask);
}
void LLVoiceClient::keyUp(KEY key, MASK mask)
{
	if (mVoiceModule) mVoiceModule->keyUp(key, mask);
}
void LLVoiceClient::middleMouseState(bool down)
{
	if (mVoiceModule) mVoiceModule->middleMouseState(down);
}


//-------------------------------------------
// nearby speaker accessors

BOOL LLVoiceClient::getVoiceEnabled(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getVoiceEnabled(id);
	} 
	else
	{
		return FALSE;
	}
}

std::string LLVoiceClient::getDisplayName(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getDisplayName(id);
	}
	else
	{
	  return std::string();
	}
}

bool LLVoiceClient::isVoiceWorking() const
{
	if (mVoiceModule) 
	{
		return mVoiceModule->isVoiceWorking();
	}
	return false;
}

BOOL LLVoiceClient::isParticipantAvatar(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->isParticipantAvatar(id);
	}
	else
	{
		return FALSE;
	}
}

BOOL LLVoiceClient::isOnlineSIP(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->isOnlineSIP(id);
	}
	else
	{
		return FALSE;
	}
}

BOOL LLVoiceClient::getIsSpeaking(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getIsSpeaking(id);
	}
	else
	{
		return FALSE;
	}
}

BOOL LLVoiceClient::getIsModeratorMuted(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getIsModeratorMuted(id);
	}
	else
	{
		return FALSE;
	}
}

F32 LLVoiceClient::getCurrentPower(const LLUUID& id)
{		
	if (mVoiceModule) 
	{
		return mVoiceModule->getCurrentPower(id);
	}
	else
	{
		return 0.0;
	}
}

BOOL LLVoiceClient::getOnMuteList(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getOnMuteList(id);
	}
	else
	{
		return FALSE;
	}
}

F32 LLVoiceClient::getUserVolume(const LLUUID& id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->getUserVolume(id);
	}
	else
	{
		return 0.0;
	}
}

void LLVoiceClient::setUserVolume(const LLUUID& id, F32 volume)
{
	if (mVoiceModule) mVoiceModule->setUserVolume(id, volume);
}

//--------------------------------------------------
// status observers

void LLVoiceClient::addObserver(LLVoiceClientStatusObserver* observer)
{
	if (mVoiceModule) mVoiceModule->addObserver(observer);
}

void LLVoiceClient::removeObserver(LLVoiceClientStatusObserver* observer)
{
	if (mVoiceModule) mVoiceModule->removeObserver(observer);
}

void LLVoiceClient::addObserver(LLFriendObserver* observer)
{
	if (mVoiceModule) mVoiceModule->addObserver(observer);
}

void LLVoiceClient::removeObserver(LLFriendObserver* observer)
{
	if (mVoiceModule) mVoiceModule->removeObserver(observer);
}

void LLVoiceClient::addObserver(LLVoiceClientParticipantObserver* observer)
{
	if (mVoiceModule) mVoiceModule->addObserver(observer);
}

void LLVoiceClient::removeObserver(LLVoiceClientParticipantObserver* observer)
{
	if (mVoiceModule) mVoiceModule->removeObserver(observer);
}

std::string LLVoiceClient::sipURIFromID(const LLUUID &id)
{
	if (mVoiceModule) 
	{
		return mVoiceModule->sipURIFromID(id);
	}
	else
	{
		return std::string();
	}
}

LLVoiceEffectInterface* LLVoiceClient::getVoiceEffectInterface() const
{
	return getVoiceEffectEnabled() ? dynamic_cast<LLVoiceEffectInterface*>(mVoiceModule) : NULL;
}

///////////////////
// version checking

class LLViewerRequiredVoiceVersion : public LLHTTPNode
{
	static BOOL sAlertedUser;
	virtual void post(
					  LLHTTPNode::ResponsePtr response,
					  const LLSD& context,
					  const LLSD& input) const
	{
		//You received this messsage (most likely on region cross or
		//teleport)
		if ( input.has("body") && input["body"].has("major_version") )
		{
			int major_voice_version =
			input["body"]["major_version"].asInteger();
			// 			int minor_voice_version =
			// 				input["body"]["minor_version"].asInteger();
			LLVoiceVersionInfo versionInfo = LLVoiceClient::getInstance()->getVersion();
			
			if (major_voice_version > 1)
			{
				if (!sAlertedUser)
				{
					//sAlertedUser = TRUE;
					LLNotificationsUtil::add("VoiceVersionMismatch");
					gSavedSettings.setBOOL("EnableVoiceChat", FALSE); // toggles listener
				}
			}
		}
	}
};

class LLViewerParcelVoiceInfo : public LLHTTPNode
{
	virtual void post(
					  LLHTTPNode::ResponsePtr response,
					  const LLSD& context,
					  const LLSD& input) const
	{
		//the parcel you are in has changed something about its
		//voice information
		
		//this is a misnomer, as it can also be when you are not in
		//a parcel at all.  Should really be something like
		//LLViewerVoiceInfoChanged.....
		if ( input.has("body") )
		{
			LLSD body = input["body"];
			
			//body has "region_name" (str), "parcel_local_id"(int),
			//"voice_credentials" (map).
			
			//body["voice_credentials"] has "channel_uri" (str),
			//body["voice_credentials"] has "channel_credentials" (str)
			
			//if we really wanted to be extra careful,
			//we'd check the supplied
			//local parcel id to make sure it's for the same parcel
			//we believe we're in
			if ( body.has("voice_credentials") )
			{
				LLSD voice_credentials = body["voice_credentials"];
				std::string uri;
				std::string credentials;
				
				if ( voice_credentials.has("channel_uri") )
				{
					uri = voice_credentials["channel_uri"].asString();
				}
				if ( voice_credentials.has("channel_credentials") )
				{
					credentials =
					voice_credentials["channel_credentials"].asString();
				}
				
				LLVoiceClient::getInstance()->setSpatialChannel(uri, credentials);
			}
		}
	}
};

const std::string LLSpeakerVolumeStorage::SETTINGS_FILE_NAME = "volume_settings.xml";

LLSpeakerVolumeStorage::LLSpeakerVolumeStorage()
{
	load();
}

LLSpeakerVolumeStorage::~LLSpeakerVolumeStorage()
{
	save();
}

void LLSpeakerVolumeStorage::storeSpeakerVolume(const LLUUID& speaker_id, F32 volume)
{
	if ((volume >= LLVoiceClient::VOLUME_MIN) && (volume <= LLVoiceClient::VOLUME_MAX))
	{
		mSpeakersData[speaker_id] = volume;

		// Enable this when debugging voice slider issues.  It's way to spammy even for debug-level logging.
		// LL_DEBUGS("Voice") << "Stored volume = " << volume <<  " for " << id << LL_ENDL;
	}
	else
	{
		LL_WARNS("Voice") << "Attempted to store out of range volume " << volume << " for " << speaker_id << LL_ENDL;
		llassert(0);
	}
}

bool LLSpeakerVolumeStorage::getSpeakerVolume(const LLUUID& speaker_id, F32& volume)
{
	speaker_data_map_t::const_iterator it = mSpeakersData.find(speaker_id);
	
	if (it != mSpeakersData.end())
	{
		volume = it->second;

		// Enable this when debugging voice slider issues.  It's way to spammy even for debug-level logging.
		// LL_DEBUGS("Voice") << "Retrieved stored volume = " << volume <<  " for " << id << LL_ENDL;

		return true;
	}

	return false;
}

void LLSpeakerVolumeStorage::removeSpeakerVolume(const LLUUID& speaker_id)
{
	mSpeakersData.erase(speaker_id);

	// Enable this when debugging voice slider issues.  It's way to spammy even for debug-level logging.
	// LL_DEBUGS("Voice") << "Removing stored volume for  " << id << LL_ENDL;
}

/* static */ F32 LLSpeakerVolumeStorage::transformFromLegacyVolume(F32 volume_in)
{
	// Convert to linear-logarithmic [0.0..1.0] with 0.5 = 0dB
	// from legacy characteristic composed of two square-curves
	// that intersect at volume_in = 0.5, volume_out = 0.56

	F32 volume_out = 0.f;
	volume_in = llclamp(volume_in, 0.f, 1.0f);

	if (volume_in <= 0.5f)
	{
		volume_out = volume_in * volume_in * 4.f * 0.56f;
	}
	else
	{
		volume_out = (1.f - 0.56f) * (4.f * volume_in * volume_in - 1.f) / 3.f + 0.56f;
	}

	return volume_out;
}

/* static */ F32 LLSpeakerVolumeStorage::transformToLegacyVolume(F32 volume_in)
{
	// Convert from linear-logarithmic [0.0..1.0] with 0.5 = 0dB
	// to legacy characteristic composed of two square-curves
	// that intersect at volume_in = 0.56, volume_out = 0.5

	F32 volume_out = 0.f;
	volume_in = llclamp(volume_in, 0.f, 1.0f);

	if (volume_in <= 0.56f)
	{
		volume_out = sqrt(volume_in / (4.f * 0.56f));
	}
	else
	{
		volume_out = sqrt((3.f * (volume_in - 0.56f) / (1.f - 0.56f) + 1.f) / 4.f);
	}

	return volume_out;
}

void LLSpeakerVolumeStorage::load()
{
	// load per-resident voice volume information
	std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SETTINGS_FILE_NAME);

	LL_INFOS("Voice") << "Loading stored speaker volumes from: " << filename << LL_ENDL;

	LLSD settings_llsd;
	llifstream file;
	file.open(filename);
	if (file.is_open())
	{
		LLSDSerialize::fromXML(settings_llsd, file);
	}

	for (LLSD::map_const_iterator iter = settings_llsd.beginMap();
		iter != settings_llsd.endMap(); ++iter)
	{
		// Maintain compatibility with 1.23 non-linear saved volume levels
		F32 volume = transformFromLegacyVolume((F32)iter->second.asReal());

		storeSpeakerVolume(LLUUID(iter->first), volume);
	}
}

void LLSpeakerVolumeStorage::save()
{
	// If we quit from the login screen we will not have an SL account
	// name.  Don't try to save, otherwise we'll dump a file in
	// C:\Program Files\SecondLife\ or similar. JC
	std::string user_dir = gDirUtilp->getLindenUserDir();
	if (!user_dir.empty())
	{
		std::string filename = gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, SETTINGS_FILE_NAME);
		LLSD settings_llsd;

		LL_INFOS("Voice") << "Saving stored speaker volumes to: " << filename << LL_ENDL;

		for(speaker_data_map_t::const_iterator iter = mSpeakersData.begin(); iter != mSpeakersData.end(); ++iter)
		{
			// Maintain compatibility with 1.23 non-linear saved volume levels
			F32 volume = transformToLegacyVolume(iter->second);

			settings_llsd[iter->first.asString()] = volume;
		}

		llofstream file;
		file.open(filename);
		LLSDSerialize::toPrettyXML(settings_llsd, file);
	}
}

BOOL LLViewerRequiredVoiceVersion::sAlertedUser = FALSE;

LLHTTPRegistration<LLViewerParcelVoiceInfo>
gHTTPRegistrationMessageParcelVoiceInfo(
										"/message/ParcelVoiceInfo");

LLHTTPRegistration<LLViewerRequiredVoiceVersion>
gHTTPRegistrationMessageRequiredVoiceVersion(
											 "/message/RequiredVoiceVersion");