diff options
author | Roxie Linden <roxie@lindenlab.com> | 2023-09-26 16:37:24 -0700 |
---|---|---|
committer | Roxie Linden <roxie@lindenlab.com> | 2024-02-22 23:11:34 -0800 |
commit | f6becec955bc673c7e0014eb89197fef9128a405 (patch) | |
tree | 9aa91b44e48dcc3cd7f69e653c3fc2552df467f8 | |
parent | d9ec32b1c3878dfa7f34b474d8278e13f2d7ece4 (diff) |
sdd stereo support to client
-rw-r--r-- | indra/llwebrtc/llwebrtc.cpp | 43 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.cpp | 15 |
2 files changed, 38 insertions, 20 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 7b5ca7fb16..e3fd68d35b 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -26,6 +26,7 @@ #include "llwebrtc_impl.h" #include <algorithm> +#include <format> #include "api/audio_codecs/audio_decoder_factory.h" #include "api/audio_codecs/audio_encoder_factory.h" @@ -394,13 +395,28 @@ bool LLWebRTCImpl::initializeConnectionThreaded() codecparam.name = "opus"; codecparam.kind = cricket::MEDIA_TYPE_AUDIO; codecparam.clock_rate = 48000; - codecparam.num_channels = 1; - codecparam.parameters["stereo"] = "0"; - codecparam.parameters["sprop-stereo"] = "0"; + codecparam.num_channels = 2; + codecparam.parameters["stereo"] = "1"; + codecparam.parameters["sprop-stereo"] = "1"; params.codecs.push_back(codecparam); sender->SetParameters(params); } + auto receivers = mPeerConnection->GetReceivers(); + for (auto& receiver : receivers) + { + webrtc::RtpParameters params; + webrtc::RtpCodecParameters codecparam; + codecparam.name = "opus"; + codecparam.kind = cricket::MEDIA_TYPE_AUDIO; + codecparam.clock_rate = 48000; + codecparam.num_channels = 2; + codecparam.parameters["stereo"] = "1"; + codecparam.parameters["sprop-stereo"] = "1"; + params.codecs.push_back(codecparam); + receiver->SetParameters(params); + } + mPeerConnection->SetLocalDescription(rtc::scoped_refptr<webrtc::SetLocalDescriptionObserverInterface>(this)); RTC_LOG(LS_INFO) << __FUNCTION__ << " " << mPeerConnection->signaling_state(); @@ -416,12 +432,9 @@ void LLWebRTCImpl::shutdownConnection() void LLWebRTCImpl::AnswerAvailable(const std::string &sdp) { - std::istringstream sdp_stream(sdp); - std::string sdp_line; - while (std::getline(sdp_stream, sdp_line)) - { - RTC_LOG(LS_INFO) << __FUNCTION__ << " Remote SDP: " << sdp_line; - } + + RTC_LOG(LS_INFO) << __FUNCTION__ << " Remote SDP: " << sdp; + mSignalingThread->PostTask( [this, sdp]() { @@ -661,20 +674,28 @@ void LLWebRTCImpl::OnSetLocalDescriptionComplete(webrtc::RTCError error) std::istringstream sdp_stream(sdp); std::ostringstream sdp_mangled_stream; std::string sdp_line; + int opus_payload = 0; while (std::getline(sdp_stream, sdp_line)) { int bandwidth = 0; int payload_id = 0; - RTC_LOG(LS_INFO) << __FUNCTION__ << " Local SDP: " << sdp_line; - // force mono + // force mono down, stereo up if (std::sscanf(sdp_line.c_str(), "a=rtpmap:%i opus/%i/2", &payload_id, &bandwidth) == 2) { sdp_mangled_stream << sdp_line << "\n"; + opus_payload = payload_id; + } + else if (sdp_line.rfind(std::format("a=fmtp:{}", opus_payload)) == 0) + { + sdp_mangled_stream << sdp_line << "a=fmtp:" << opus_payload + << " stereo=1;sprop-stereo=0;minptime=10;useinbandfec=1;maxplaybackrate=48000\n"; } else { sdp_mangled_stream << sdp_line << "\n"; } } + RTC_LOG(LS_INFO) << __FUNCTION__ << " Local SDP: " << sdp_mangled_stream.str(); + ; for (auto &observer : mSignalingObserverList) { observer->OnOfferAvailable(sdp_mangled_stream.str()); diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp index 4c687b5807..a1e63c29cf 100644 --- a/indra/newview/llvoicewebrtc.cpp +++ b/indra/newview/llvoicewebrtc.cpp @@ -2208,10 +2208,10 @@ void LLWebRTCVoiceClient::sendPositionAndVolumeUpdate(void) { audio_level = (F32) mWebRTCDeviceInterface->getAudioLevel(); } - uint32_t uint_audio_level = (uint32_t) (audio_level * 256); + uint32_t uint_audio_level = mMuteMic ? 0 : (uint32_t) (audio_level * 128); if (uint_audio_level != mAudioLevel) { - root["p"] = uint_audio_level; + root["p"] = uint_audio_level; mAudioLevel = uint_audio_level; participantStatePtr_t participant = findParticipantByID(gAgentID); if (participant) @@ -2530,7 +2530,7 @@ void LLWebRTCVoiceClient::OnDataReceived(const std::string& data, bool binary) { removeParticipantByID(agent_id); } - F32 energyRMS = (F32) (voice_data[participant_id].get("p", Json::Value(participant->mPower)).asInt()) / 256; + F32 energyRMS = (F32) (voice_data[participant_id].get("p", Json::Value(participant->mPower)).asInt()) / 128; // convert to decibles participant->mPower = energyRMS; /* WebRTC appears to have deprecated VAD, but it's still in the Audio Processing Module so maybe we @@ -4487,13 +4487,10 @@ BOOL LLWebRTCVoiceClient::getIsModeratorMuted(const LLUUID& id) F32 LLWebRTCVoiceClient::getCurrentPower(const LLUUID &id) { F32 result = 0; - if (!mMuteMic) + participantStatePtr_t participant(findParticipantByID(id)); + if (participant) { - participantStatePtr_t participant(findParticipantByID(id)); - if (participant) - { - result = participant->mPower * 4; - } + result = participant->mPower * 3.5; } return result; } |