summaryrefslogtreecommitdiff
path: root/indra/llwebrtc
diff options
context:
space:
mode:
authorRoxie Linden <roxie@lindenlab.com>2024-01-09 11:57:01 -0800
committerRoxie Linden <roxie@lindenlab.com>2024-02-08 18:35:21 -0800
commit7246f55290abda53c211b335e01f9a9182c7513f (patch)
treedd5bbaa9fe690b2c533a98b20e529e4bc90c7d3e /indra/llwebrtc
parent23b065b0f1f8620e91a41f5538dfc1ff3077037e (diff)
New WebRTC with echo cancellation fix.
Also, start/stop recording depending on whether WebRTC has negotiated.
Diffstat (limited to 'indra/llwebrtc')
-rw-r--r--indra/llwebrtc/llwebrtc.cpp74
-rw-r--r--indra/llwebrtc/llwebrtc_impl.h2
2 files changed, 62 insertions, 14 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp
index 8e56f9c222..fca490e8c2 100644
--- a/indra/llwebrtc/llwebrtc.cpp
+++ b/indra/llwebrtc/llwebrtc.cpp
@@ -150,7 +150,34 @@ void LLWebRTCImpl::init()
mPeerDeviceModule->InitPlayout();
});
- apm->ApplyConfig(apm_config);
+ rtc::scoped_refptr<webrtc::AudioProcessing> apm = webrtc::AudioProcessingBuilder().Create();
+ webrtc::AudioProcessing::Config apm_config;
+ apm_config.echo_canceller.enabled = true;
+ apm_config.echo_canceller.mobile_mode = false;
+ apm_config.gain_controller1.enabled = true;
+ apm_config.gain_controller1.mode = webrtc::AudioProcessing::Config::GainController1::kAdaptiveAnalog;
+ apm_config.gain_controller2.enabled = true;
+ apm_config.high_pass_filter.enabled = true;
+ apm_config.noise_suppression.enabled = true;
+ apm_config.noise_suppression.level = webrtc::AudioProcessing::Config::NoiseSuppression::kVeryHigh;
+ apm_config.transient_suppression.enabled = true;
+ apm_config.pipeline.multi_channel_render = true;
+ apm_config.pipeline.multi_channel_capture = true;
+ apm_config.pipeline.multi_channel_capture = true;
+
+ webrtc::ProcessingConfig processing_config;
+ processing_config.input_stream().set_num_channels(2);
+ processing_config.input_stream().set_sample_rate_hz(8000);
+ processing_config.output_stream().set_num_channels(2);
+ processing_config.output_stream().set_sample_rate_hz(8000);
+ processing_config.reverse_input_stream().set_num_channels(2);
+ processing_config.reverse_input_stream().set_sample_rate_hz(48000);
+ processing_config.reverse_output_stream().set_num_channels(2);
+ processing_config.reverse_output_stream().set_sample_rate_hz(48000);
+
+ apm->Initialize(processing_config);
+ apm->ApplyConfig(apm_config);
+
mPeerConnectionFactory = webrtc::CreatePeerConnectionFactory(mNetworkThread.get(),
mWorkerThread.get(),
mSignalingThread.get(),
@@ -161,11 +188,28 @@ void LLWebRTCImpl::init()
nullptr /* video_decoder_factory */,
nullptr /* audio_mixer */,
apm);
+
+
mWorkerThread->BlockingCall(
[this]()
{
mPeerDeviceModule->StartPlayout();
- mPeerDeviceModule->StartRecording();
+ });
+}
+
+void LLWebRTCImpl::setRecording(bool recording)
+{
+ mWorkerThread->PostTask(
+ [this, recording]()
+ {
+ if (recording)
+ {
+ mPeerDeviceModule->StartRecording();
+ }
+ else
+ {
+ mPeerDeviceModule->StopRecording();
+ }
});
}
@@ -263,8 +307,6 @@ void LLWebRTCImpl::setCaptureDevice(const std::string &id)
{
mPeerDeviceModule->StopRecording();
}
-
- mPeerDeviceModule->StopRecording();
mPeerDeviceModule->SetRecordingDevice(mRecordingDevice);
mPeerDeviceModule->InitMicrophone();
mPeerDeviceModule->InitRecording();
@@ -427,6 +469,10 @@ void LLWebRTCImpl::freePeerConnection(LLWebRTCPeerConnection * peer_connection)
(*it)->terminate();
mPeerConnections.erase(it);
}
+ if (mPeerConnections.empty())
+ {
+ setRecording(false);
+ }
}
//
@@ -519,6 +565,7 @@ bool LLWebRTCPeerConnectionImpl::initializeConnection()
audioOptions.noise_suppression = true;
mLocalStream = mPeerConnectionFactory->CreateLocalMediaStream("SLStream");
+
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
mPeerConnectionFactory->CreateAudioTrack("SLAudio", mPeerConnectionFactory->CreateAudioSource(audioOptions).get()));
audio_track->set_enabled(true);
@@ -750,15 +797,14 @@ void LLWebRTCPeerConnectionImpl::OnConnectionChange(webrtc::PeerConnectionInterf
{
case webrtc::PeerConnectionInterface::PeerConnectionState::kConnected:
{
- if (new_state == webrtc::PeerConnectionInterface::PeerConnectionState::kConnected)
- {
- mWebRTCImpl->PostWorkerTask([this]() {
- for (auto &observer : mSignalingObserverList)
- {
- observer->OnAudioEstablished(this);
- }
- });
- }
+ mWebRTCImpl->setRecording(true);
+
+ mWebRTCImpl->PostWorkerTask([this]() {
+ for (auto &observer : mSignalingObserverList)
+ {
+ observer->OnAudioEstablished(this);
+ }
+ });
break;
}
case webrtc::PeerConnectionInterface::PeerConnectionState::kFailed:
@@ -872,8 +918,8 @@ void LLWebRTCPeerConnectionImpl::OnSuccess(webrtc::SessionDescriptionInterface *
// 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 = std::to_string(payload_id);
+ sdp_mangled_stream << "a=rtpmap:" << opus_payload << " opus/48000/2" << "\n";
}
else if (sdp_line.find("a=fmtp:" + opus_payload) == 0)
{
diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h
index 6a84f67ef5..884e107527 100644
--- a/indra/llwebrtc/llwebrtc_impl.h
+++ b/indra/llwebrtc/llwebrtc_impl.h
@@ -162,6 +162,8 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface
LLWebRTCPeerConnection * newPeerConnection();
void freePeerConnection(LLWebRTCPeerConnection * peer_connection);
+ void setRecording(bool recording);
+
protected:
std::unique_ptr<rtc::Thread> mNetworkThread;