summaryrefslogtreecommitdiff
path: root/indra/newview/llvoicewebrtc.cpp
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2024-07-27 15:17:57 +0800
committerErik Kundiman <erik@megapahit.org>2024-07-28 08:24:59 +0800
commit96a81b5ecbe3bffb582ded930752c0523df5e80a (patch)
treea87a0bd09fd980562e88150dbfea3819d28d9f12 /indra/newview/llvoicewebrtc.cpp
parent06e8f0c443c1ba7858d000c6d695b7e988e02053 (diff)
parented73208eb96b862b97fa285036edea1e792ca3c6 (diff)
Merge remote-tracking branch 'secondlife/release/2024.06-atlasaurus' into 2024.06-atlasaurus
Diffstat (limited to 'indra/newview/llvoicewebrtc.cpp')
-rw-r--r--indra/newview/llvoicewebrtc.cpp171
1 files changed, 90 insertions, 81 deletions
diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp
index f3ab52736e..1d729dcd35 100644
--- a/indra/newview/llvoicewebrtc.cpp
+++ b/indra/newview/llvoicewebrtc.cpp
@@ -78,8 +78,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";
@@ -323,7 +322,7 @@ void LLWebRTCVoiceClient::updateSettings()
config.mNoiseSuppressionLevel = (llwebrtc::LLWebRTCDeviceInterface::AudioConfig::ENoiseSuppressionLevel) (U32)sNoiseSuppressionLevel;
mWebRTCDeviceInterface->setAudioConfig(config);
-
+
}
// Observers
@@ -391,7 +390,7 @@ void LLWebRTCVoiceClient::notifyStatusObservers(LLVoiceClientStatusObserver::ESt
if (voice_status)
{
- LLFirstUse::speak(true);
+ LLAppViewer::instance()->postToMainCoro([=]() { LLFirstUse::speak(true); });
}
}
}
@@ -623,10 +622,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);
});
}
@@ -650,7 +649,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);
@@ -1016,35 +1015,38 @@ void LLWebRTCVoiceClient::sendPositionUpdate(bool force)
{
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));
}
@@ -1068,10 +1070,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)
@@ -1291,10 +1293,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
@@ -1560,9 +1562,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));
@@ -1575,9 +1577,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));
@@ -2270,7 +2272,7 @@ void LLVoiceWebRTCConnection::processIceUpdatesCoro()
void LLVoiceWebRTCConnection::OnOfferAvailable(const std::string &sdp)
{
LL::WorkQueue::postMaybe(mMainQueue,
- [=] {
+ [=] {
if (mShutDown)
{
return;
@@ -2319,7 +2321,7 @@ void LLVoiceWebRTCConnection::OnAudioEstablished(llwebrtc::LLWebRTCAudioInterfac
void LLVoiceWebRTCConnection::OnRenegotiationNeeded()
{
LL::WorkQueue::postMaybe(mMainQueue,
- [=] {
+ [=] {
LL_DEBUGS("Voice") << "Voice channel requires renegotiation." << LL_ENDL;
if (!mShutDown)
{
@@ -2363,12 +2365,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);
@@ -2377,12 +2375,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);
@@ -2434,7 +2428,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;
@@ -2607,7 +2601,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.
@@ -2780,7 +2774,7 @@ 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)
@@ -2798,27 +2792,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;
@@ -2828,11 +2831,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);
@@ -2855,7 +2863,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)
@@ -2866,18 +2874,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();
+ ;
}
}
}
@@ -2885,8 +2895,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;
@@ -2897,7 +2906,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);
}
}
@@ -2939,16 +2948,16 @@ void LLVoiceWebRTCConnection::sendJoin()
{
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);
}