summaryrefslogtreecommitdiff
path: root/indra/newview/llvoicewebrtc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llvoicewebrtc.cpp')
-rw-r--r--indra/newview/llvoicewebrtc.cpp234
1 files changed, 121 insertions, 113 deletions
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index 36e998af89..d18a32cb05 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -24,7 +24,6 @@
* $/LicenseInfo$
*/
#include <algorithm>
-#include <format>
#include "llvoicewebrtc.h"
#include "llsdutil.h"
@@ -76,8 +75,7 @@
// for base64 decoding
#include "apr_base64.h"
-#include "json/reader.h"
-#include "json/writer.h"
+#include "boost/json.hpp"
const std::string WEBRTC_VOICE_SERVER_TYPE = "webrtc";
@@ -292,7 +290,7 @@ const LLVoiceVersionInfo& LLWebRTCVoiceClient::getVersion()
void LLWebRTCVoiceClient::updateSettings()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
setVoiceEnabled(LLVoiceClient::getInstance()->voiceEnabled());
static LLCachedControl<S32> sVoiceEarLocation(gSavedSettings, "VoiceEarLocation");
@@ -321,7 +319,7 @@ void LLWebRTCVoiceClient::updateSettings()
config.mNoiseSuppressionLevel = (llwebrtc::LLWebRTCDeviceInterface::AudioConfig::ENoiseSuppressionLevel) (U32)sNoiseSuppressionLevel;
mWebRTCDeviceInterface->setAudioConfig(config);
-
+
}
// Observers
@@ -337,7 +335,7 @@ void LLWebRTCVoiceClient::removeObserver(LLVoiceClientParticipantObserver *obser
void LLWebRTCVoiceClient::notifyParticipantObservers()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
for (observer_set_t::iterator it = mParticipantObservers.begin(); it != mParticipantObservers.end();)
{
LLVoiceClientParticipantObserver *observer = *it;
@@ -359,7 +357,7 @@ void LLWebRTCVoiceClient::removeObserver(LLVoiceClientStatusObserver *observer)
void LLWebRTCVoiceClient::notifyStatusObservers(LLVoiceClientStatusObserver::EStatusType status)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
LL_DEBUGS("Voice") << "( " << LLVoiceClientStatusObserver::status2string(status) << " )"
<< " mSession=" << mSession << LL_ENDL;
@@ -389,7 +387,7 @@ void LLWebRTCVoiceClient::notifyStatusObservers(LLVoiceClientStatusObserver::ESt
if (voice_status)
{
- LLFirstUse::speak(true);
+ LLAppViewer::instance()->postToMainCoro([=]() { LLFirstUse::speak(true); });
}
}
}
@@ -543,7 +541,7 @@ void LLWebRTCVoiceClient::voiceConnectionCoro()
// for cross-region voice.
void LLWebRTCVoiceClient::updateNeighboringRegions()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
static const std::vector<LLVector3d> neighbors {LLVector3d(0.0f, 1.0f, 0.0f), LLVector3d(0.707f, 0.707f, 0.0f),
LLVector3d(1.0f, 0.0f, 0.0f), LLVector3d(0.707f, -0.707f, 0.0f),
@@ -576,7 +574,7 @@ void LLWebRTCVoiceClient::updateNeighboringRegions()
// shut down the current audio session to make room for the next one.
void LLWebRTCVoiceClient::leaveAudioSession()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if(mSession)
{
@@ -621,10 +619,10 @@ void LLWebRTCVoiceClient::setDevicesListUpdated(bool state)
void LLWebRTCVoiceClient::OnDevicesChanged(const llwebrtc::LLWebRTCVoiceDeviceList& render_devices,
const llwebrtc::LLWebRTCVoiceDeviceList& capture_devices)
{
-
+
LL::WorkQueue::postMaybe(mMainQueue,
- [=]
- {
+ [=]
+ {
OnDevicesChangedImpl(render_devices, capture_devices);
});
}
@@ -632,7 +630,7 @@ void LLWebRTCVoiceClient::OnDevicesChanged(const llwebrtc::LLWebRTCVoiceDeviceLi
void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDeviceList &render_devices,
const llwebrtc::LLWebRTCVoiceDeviceList &capture_devices)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
std::string inputDevice = gSavedSettings.getString("VoiceInputAudioDevice");
std::string outputDevice = gSavedSettings.getString("VoiceOutputAudioDevice");
@@ -648,7 +646,7 @@ void LLWebRTCVoiceClient::OnDevicesChangedImpl(const llwebrtc::LLWebRTCVoiceDevi
for (auto &device : capture_devices)
{
LL_DEBUGS("Voice") << "Checking capture device:'" << device.mID << "'" << LL_ENDL;
-
+
addCaptureDevice(LLVoiceDevice(device.mDisplayName, device.mID));
}
setCaptureDevice(inputDevice);
@@ -712,7 +710,7 @@ void LLWebRTCVoiceClient::tuningSetSpeakerVolume(float volume)
if (volume != mTuningSpeakerVolume)
{
- mTuningSpeakerVolume = volume;
+ mTuningSpeakerVolume = (int)volume;
}
}
@@ -720,11 +718,11 @@ float LLWebRTCVoiceClient::getAudioLevel()
{
if (mIsInTuningMode)
{
- return (1.0 - mWebRTCDeviceInterface->getTuningAudioLevel() * LEVEL_SCALE_WEBRTC) * mTuningMicGain / 2.1;
+ return (1.0f - mWebRTCDeviceInterface->getTuningAudioLevel() * LEVEL_SCALE_WEBRTC) * mTuningMicGain / 2.1f;
}
else
{
- return (1.0 - mWebRTCDeviceInterface->getPeerConnectionAudioLevel() * LEVEL_SCALE_WEBRTC) * mMicGain / 2.1;
+ return (1.0f - mWebRTCDeviceInterface->getPeerConnectionAudioLevel() * LEVEL_SCALE_WEBRTC) * mMicGain / 2.1f;
}
}
@@ -799,7 +797,7 @@ void LLWebRTCVoiceClient::setHidden(bool hidden)
// notify the observers.
void LLWebRTCVoiceClient::OnConnectionEstablished(const std::string &channelID, const LLUUID &regionID)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if (gAgent.getRegion()->getRegionID() == regionID)
{
@@ -883,7 +881,7 @@ void LLWebRTCVoiceClient::setEarLocation(S32 loc)
void LLWebRTCVoiceClient::updatePosition(void)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
LLViewerRegion *region = gAgent.getRegion();
if (region && isAgentAvatarValid())
@@ -1012,37 +1010,40 @@ void LLWebRTCVoiceClient::enforceTether()
// standard 50m
void LLWebRTCVoiceClient::sendPositionUpdate(bool force)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
- Json::FastWriter writer;
std::string spatial_data;
if (mSpatialCoordsDirty || force)
{
- Json::Value spatial = Json::objectValue;
-
- spatial["sp"] = Json::objectValue;
- spatial["sp"]["x"] = (int) (mAvatarPosition[0] * 100);
- spatial["sp"]["y"] = (int) (mAvatarPosition[1] * 100);
- spatial["sp"]["z"] = (int) (mAvatarPosition[2] * 100);
- spatial["sh"] = Json::objectValue;
- spatial["sh"]["x"] = (int) (mAvatarRot[0] * 100);
- spatial["sh"]["y"] = (int) (mAvatarRot[1] * 100);
- spatial["sh"]["z"] = (int) (mAvatarRot[2] * 100);
- spatial["sh"]["w"] = (int) (mAvatarRot[3] * 100);
-
- spatial["lp"] = Json::objectValue;
- spatial["lp"]["x"] = (int) (mListenerPosition[0] * 100);
- spatial["lp"]["y"] = (int) (mListenerPosition[1] * 100);
- spatial["lp"]["z"] = (int) (mListenerPosition[2] * 100);
- spatial["lh"] = Json::objectValue;
- spatial["lh"]["x"] = (int) (mListenerRot[0] * 100);
- spatial["lh"]["y"] = (int) (mListenerRot[1] * 100);
- spatial["lh"]["z"] = (int) (mListenerRot[2] * 100);
- spatial["lh"]["w"] = (int) (mListenerRot[3] * 100);
+ boost::json::object spatial;
+
+ spatial["sp"] = {
+ {"x", (int) (mAvatarPosition[0] * 100)},
+ {"y", (int) (mAvatarPosition[1] * 100)},
+ {"z", (int) (mAvatarPosition[2] * 100)}
+ };
+ spatial["sh"] = {
+ {"x", (int) (mAvatarRot[0] * 100)},
+ {"y", (int) (mAvatarRot[1] * 100)},
+ {"z", (int) (mAvatarRot[2] * 100)},
+ {"w", (int) (mAvatarRot[3] * 100)}
+ };
+
+ spatial["lp"] = {
+ {"x", (int) (mListenerPosition[0] * 100)},
+ {"y", (int) (mListenerPosition[1] * 100)},
+ {"z", (int) (mListenerPosition[2] * 100)}
+ };
+
+ spatial["lh"] = {
+ {"x", (int) (mListenerRot[0] * 100)},
+ {"y", (int) (mListenerRot[1] * 100)},
+ {"z", (int) (mListenerRot[2] * 100)},
+ {"w", (int) (mListenerRot[3] * 100)}};
mSpatialCoordsDirty = false;
- spatial_data = writer.write(spatial);
+ spatial_data = boost::json::serialize(spatial);
sessionState::for_each(boost::bind(predSendData, _1, spatial_data));
}
@@ -1066,10 +1067,10 @@ void LLWebRTCVoiceClient::updateOwnVolume() {
// Provider-level participant management
-BOOL LLWebRTCVoiceClient::isParticipantAvatar(const LLUUID &id)
+bool LLWebRTCVoiceClient::isParticipantAvatar(const LLUUID &id)
{
// WebRTC participants are always SL avatars.
- return TRUE;
+ return true;
}
void LLWebRTCVoiceClient::getParticipantList(std::set<LLUUID> &participants)
@@ -1125,7 +1126,7 @@ LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::addParticipantBy
void LLWebRTCVoiceClient::removeParticipantByID(const std::string &channelID, const LLUUID &id, const LLUUID& region)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
participantStatePtr_t result;
LLWebRTCVoiceClient::sessionState::ptr_t session = sessionState::matchSessionByChannelID(channelID);
@@ -1155,7 +1156,7 @@ LLWebRTCVoiceClient::participantState::participantState(const LLUUID& agent_id,
LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::addParticipant(const LLUUID& agent_id, const LLUUID& region)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
participantStatePtr_t result;
@@ -1193,7 +1194,7 @@ LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::ad
LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::findParticipantByID(const LLUUID& id)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
participantStatePtr_t result;
participantUUIDMap::iterator iter = mParticipantsByUUID.find(id);
@@ -1208,7 +1209,7 @@ LLWebRTCVoiceClient::participantStatePtr_t LLWebRTCVoiceClient::sessionState::fi
void LLWebRTCVoiceClient::sessionState::removeParticipant(const LLWebRTCVoiceClient::participantStatePtr_t &participant)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if (participant)
{
@@ -1289,10 +1290,10 @@ bool LLWebRTCVoiceClient::isVoiceWorking() const
// Returns true if calling back the session URI after the session has closed is possible.
// Currently this will be false only for PSTN P2P calls.
-BOOL LLWebRTCVoiceClient::isSessionCallBackPossible(const LLUUID &session_id)
+bool LLWebRTCVoiceClient::isSessionCallBackPossible(const LLUUID &session_id)
{
sessionStatePtr_t session(findP2PSession(session_id));
- return session && session->isCallbackPossible() ? TRUE : FALSE;
+ return session && session->isCallbackPossible();
}
// Channel Management
@@ -1491,7 +1492,7 @@ void LLWebRTCVoiceClient::setMicGain(F32 gain)
void LLWebRTCVoiceClient::setVoiceEnabled(bool enabled)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
LL_DEBUGS("Voice")
<< "( " << (enabled ? "enabled" : "disabled") << " )"
@@ -1558,9 +1559,9 @@ std::string LLWebRTCVoiceClient::getDisplayName(const LLUUID& id)
return result;
}
-BOOL LLWebRTCVoiceClient::getIsSpeaking(const LLUUID& id)
+bool LLWebRTCVoiceClient::getIsSpeaking(const LLUUID& id)
{
- BOOL result = FALSE;
+ bool result = false;
if (mProcessChannels && mSession)
{
participantStatePtr_t participant(mSession->findParticipantByID(id));
@@ -1573,9 +1574,9 @@ BOOL LLWebRTCVoiceClient::getIsSpeaking(const LLUUID& id)
}
// TODO: Need to pull muted status from the webrtc server
-BOOL LLWebRTCVoiceClient::getIsModeratorMuted(const LLUUID& id)
+bool LLWebRTCVoiceClient::getIsModeratorMuted(const LLUUID& id)
{
- BOOL result = FALSE;
+ bool result = false;
if (mProcessChannels && mSession)
{
participantStatePtr_t participant(mSession->findParticipantByID(id));
@@ -1886,7 +1887,7 @@ void LLWebRTCVoiceClient::sessionState::revive()
void LLWebRTCVoiceClient::sessionState::processSessionStates()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
auto iter = mSessions.begin();
while (iter != mSessions.end())
@@ -1907,7 +1908,7 @@ void LLWebRTCVoiceClient::sessionState::processSessionStates()
// process the states on each connection associated with a session.
bool LLWebRTCVoiceClient::sessionState::processConnectionStates()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
std::list<connectionPtr_t>::iterator iter = mWebRTCConnections.begin();
while (iter != mWebRTCConnections.end())
@@ -1931,7 +1932,7 @@ bool LLWebRTCVoiceClient::sessionState::processConnectionStates()
// on our location.
bool LLWebRTCVoiceClient::estateSessionState::processConnectionStates()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if (!mShuttingDown)
{
@@ -2095,7 +2096,7 @@ LLVoiceWebRTCConnection::LLVoiceWebRTCConnection(const LLUUID &regionID, const s
{
// retries wait a short period...randomize it so
// all clients don't try to reconnect at once.
- mRetryWaitSecs = ((F32) rand() / (RAND_MAX)) + 0.5;
+ mRetryWaitSecs = (F32)((F32) rand() / (RAND_MAX)) + 0.5f;
mWebRTCPeerConnectionInterface = llwebrtc::newPeerConnection();
mWebRTCPeerConnectionInterface->setSignalingObserver(this);
@@ -2167,7 +2168,7 @@ void LLVoiceWebRTCConnection::processIceUpdates()
// will make the cap call to the server sending up the ICE candidates.
void LLVoiceWebRTCConnection::processIceUpdatesCoro()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if (mShutDown || LLWebRTCVoiceClient::isShuttingDown())
{
@@ -2268,7 +2269,7 @@ void LLVoiceWebRTCConnection::processIceUpdatesCoro()
void LLVoiceWebRTCConnection::OnOfferAvailable(const std::string &sdp)
{
LL::WorkQueue::postMaybe(mMainQueue,
- [=] {
+ [=] {
if (mShutDown)
{
return;
@@ -2317,7 +2318,7 @@ void LLVoiceWebRTCConnection::OnAudioEstablished(llwebrtc::LLWebRTCAudioInterfac
void LLVoiceWebRTCConnection::OnRenegotiationNeeded()
{
LL::WorkQueue::postMaybe(mMainQueue,
- [=] {
+ [=] {
LL_DEBUGS("Voice") << "Voice channel requires renegotiation." << LL_ENDL;
if (!mShutDown)
{
@@ -2361,12 +2362,8 @@ void LLVoiceWebRTCConnection::setSpeakerVolume(F32 volume)
void LLVoiceWebRTCConnection::setUserVolume(const LLUUID& id, F32 volume)
{
- Json::Value root = Json::objectValue;
- Json::Value user_gain = Json::objectValue;
- user_gain[id.asString()] = (uint32_t)(volume*200); // give it two decimal places with a range from 0-200, where 100 is normal
- root["ug"] = user_gain;
- Json::FastWriter writer;
- std::string json_data = writer.write(root);
+ boost::json::object root = {{"ug", {id.asString(), (uint32_t) (volume * 200)}}};
+ std::string json_data = boost::json::serialize(root);
if (mWebRTCDataInterface)
{
mWebRTCDataInterface->sendData(json_data, false);
@@ -2375,12 +2372,8 @@ void LLVoiceWebRTCConnection::setUserVolume(const LLUUID& id, F32 volume)
void LLVoiceWebRTCConnection::setUserMute(const LLUUID& id, bool mute)
{
- Json::Value root = Json::objectValue;
- Json::Value muted = Json::objectValue;
- muted[id.asString()] = mute;
- root["m"] = muted;
- Json::FastWriter writer;
- std::string json_data = writer.write(root);
+ boost::json::object root = {{"m", {id.asString(), mute}}};
+ std::string json_data = boost::json::serialize(root);
if (mWebRTCDataInterface)
{
mWebRTCDataInterface->sendData(json_data, false);
@@ -2402,7 +2395,7 @@ void LLVoiceWebRTCConnection::sendData(const std::string &data)
// The simulator will pass this on to the Secondlife WebRTC server.
void LLVoiceWebRTCConnection::breakVoiceConnectionCoro()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
LL_DEBUGS("Voice") << "Disconnecting voice." << LL_ENDL;
if (mWebRTCDataInterface)
@@ -2432,7 +2425,7 @@ void LLVoiceWebRTCConnection::breakVoiceConnectionCoro()
LLVoiceWebRTCStats::getInstance()->provisionAttemptStart();
LLSD body;
- body["logout"] = TRUE;
+ body["logout"] = true;
body["viewer_session"] = mViewerSession;
body["voice_server_type"] = WEBRTC_VOICE_SERVER_TYPE;
@@ -2461,7 +2454,7 @@ void LLVoiceWebRTCConnection::breakVoiceConnectionCoro()
// will use the offer and answer to negotiate the session.
void LLVoiceWebRTCSpatialConnection::requestVoiceConnection()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
LLViewerRegion *regionp = LLWorld::instance().getRegionFromID(mRegionID);
@@ -2534,7 +2527,7 @@ void LLVoiceWebRTCSpatialConnection::requestVoiceConnection()
void LLVoiceWebRTCConnection::OnVoiceConnectionRequestSuccess(const LLSD &result)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if (LLWebRTCVoiceClient::isShuttingDown())
{
@@ -2589,7 +2582,7 @@ static llwebrtc::LLWebRTCPeerConnectionInterface::InitOptions getConnectionOptio
// Secondlife WebRTC server.
bool LLVoiceWebRTCConnection::connectionStateMachine()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
processIceUpdates();
@@ -2605,7 +2598,7 @@ bool LLVoiceWebRTCConnection::connectionStateMachine()
}
mIceCompleted = false;
setVoiceConnectionState(VOICE_STATE_WAIT_FOR_SESSION_START);
-
+
// tell the webrtc library that we want a connection. The library will
// respond with an offer on a separate thread, which will cause
// the session state to change.
@@ -2685,7 +2678,7 @@ bool LLVoiceWebRTCConnection::connectionStateMachine()
case VOICE_STATE_SESSION_UP:
{
mRetryWaitPeriod = 0;
- mRetryWaitSecs = ((F32) rand() / (RAND_MAX)) + 0.5;
+ mRetryWaitSecs = (F32)((F32) rand() / (RAND_MAX)) + 0.5f;
// we'll stay here as long as the session remains up.
if (mShutDown)
@@ -2707,7 +2700,7 @@ bool LLVoiceWebRTCConnection::connectionStateMachine()
{
// back off the retry period, and do it by a small random
// bit so all clients don't reconnect at once.
- mRetryWaitSecs += ((F32) rand() / (RAND_MAX)) + 0.5;
+ mRetryWaitSecs += (F32)((F32) rand() / (RAND_MAX)) + 0.5f;
mRetryWaitPeriod = 0;
}
}
@@ -2778,12 +2771,12 @@ void LLVoiceWebRTCConnection::OnDataReceived(const std::string& data, bool binar
//
// The LLWebRTCVoiceConnection object will not be deleted
-// before the webrtc connection itself is shut down, so
+// before the webrtc connection itself is shut down, so
// we shouldn't be getting this callback on a nonexistant
// this pointer.
void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool binary)
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
if (mShutDown)
{
@@ -2796,27 +2789,36 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b
return;
}
- Json::Reader reader;
- Json::Value voice_data;
- if (reader.parse(data, voice_data, false)) // don't collect comments
+ boost::json::error_code ec;
+ boost::json::value voice_data_parsed = boost::json::parse(data, ec);
+ if (!ec) // don't collect comments
{
- if (!voice_data.isObject())
+ if (!voice_data_parsed.is_object())
{
LL_WARNS("Voice") << "Expected object from data channel:" << data << LL_ENDL;
return;
}
+ boost::json::object voice_data = voice_data_parsed.as_object();
bool new_participant = false;
- Json::Value mute = Json::objectValue;
- Json::Value user_gain = Json::objectValue;
- for (auto &participant_id : voice_data.getMemberNames())
+ boost::json::object mute;
+ boost::json::object user_gain;
+ for (auto &participant_elem : voice_data)
{
- LLUUID agent_id(participant_id);
+ boost::json::string participant_id(participant_elem.key());
+ LLUUID agent_id(participant_id.c_str());
if (agent_id.isNull())
{
// probably a test client.
continue;
}
+ if (!participant_elem.value().is_object())
+ {
+ continue;
+ }
+
+ boost::json::object participant_obj = participant_elem.value().as_object();
+
LLWebRTCVoiceClient::participantStatePtr_t participant =
LLWebRTCVoiceClient::getInstance()->findParticipantByID(mChannelID, agent_id);
bool joined = false;
@@ -2826,11 +2828,16 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b
// where a participant on a neighboring region may be
// connected to multiple servers. We don't want to
// add new identical participants from all of those servers.
- if (voice_data[participant_id].isMember("j"))
+ if (participant_obj.contains("j") &&
+ participant_obj["j"].is_object())
{
// a new participant has announced that they're joining.
joined = true;
- primary = voice_data[participant_id]["j"].get("p", Json::Value(false)).asBool();
+ if (participant_elem.value().as_object()["j"].as_object().contains("p") &&
+ participant_elem.value().as_object()["j"].as_object()["p"].is_bool())
+ {
+ primary = participant_elem.value().as_object()["j"].as_object()["p"].as_bool();
+ }
// track incoming participants that are muted so we can mute their connections (or set their volume)
bool isMuted = LLMuteList::getInstance()->isMuted(agent_id, LLMute::flagVoiceChat);
@@ -2853,7 +2860,7 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b
if (participant)
{
- if (voice_data[participant_id].get("l", Json::Value(false)).asBool())
+ if (participant_obj.contains("l") && participant_obj["l"].is_bool() && participant_obj["l"].as_bool())
{
// an existing participant is leaving.
if (agent_id != gAgentID)
@@ -2864,18 +2871,20 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b
else
{
// we got a 'power' update.
- F32 level = (F32) (voice_data[participant_id].get("p", Json::Value(participant->mLevel)).asInt()) / 128;
- // convert to decibles
- participant->mLevel = level;
+ if (participant_obj.contains("p") && participant_obj["p"].is_number())
+ {
+ participant->mLevel = (F32)participant_obj["p"].as_int64();
+ }
- if (voice_data[participant_id].isMember("v"))
+ if (participant_obj.contains("v") && participant_obj["v"].is_bool())
{
- participant->mIsSpeaking = voice_data[participant_id].get("v", Json::Value(false)).asBool();
+ participant->mIsSpeaking = participant_obj["v"].as_bool();
}
- if (voice_data[participant_id].isMember("m"))
+ if (participant_obj.contains("v") && participant_obj["m"].is_bool())
{
- participant->mIsModeratorMuted = voice_data[participant_id].get("m", Json::Value(false)).asBool();
+ participant->mIsModeratorMuted = participant_obj["m"].as_bool();
+ ;
}
}
}
@@ -2883,8 +2892,7 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b
// tell the simulator to set the mute and volume data for this
// participant, if there are any updates.
- Json::FastWriter writer;
- Json::Value root = Json::objectValue;
+ boost::json::object root;
if (mute.size() > 0)
{
root["m"] = mute;
@@ -2895,7 +2903,7 @@ void LLVoiceWebRTCConnection::OnDataReceivedImpl(const std::string &data, bool b
}
if (root.size() > 0)
{
- std::string json_data = writer.write(root);
+ std::string json_data = boost::json::serialize(root);
mWebRTCDataInterface->sendData(json_data, false);
}
}
@@ -2935,18 +2943,18 @@ void LLVoiceWebRTCConnection::OnDataChannelReady(llwebrtc::LLWebRTCDataInterface
// to peers.
void LLVoiceWebRTCConnection::sendJoin()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
+
- Json::FastWriter writer;
- Json::Value root = Json::objectValue;
- Json::Value join_obj = Json::objectValue;
+ boost::json::object root;
+ boost::json::object join_obj;
LLUUID regionID = gAgent.getRegion()->getRegionID();
if ((regionID == mRegionID) || !isSpatial())
{
join_obj["p"] = true;
}
root["j"] = join_obj;
- std::string json_data = writer.write(root);
+ std::string json_data = boost::json::serialize(root);
mWebRTCDataInterface->sendData(json_data, false);
}
@@ -3009,7 +3017,7 @@ LLVoiceWebRTCAdHocConnection::~LLVoiceWebRTCAdHocConnection()
// So, we have a separate requestVoiceConnection call.
void LLVoiceWebRTCAdHocConnection::requestVoiceConnection()
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE
+ LL_PROFILE_ZONE_SCOPED_CATEGORY_VOICE;
LLViewerRegion *regionp = LLWorld::instance().getRegionFromID(mRegionID);