New WebRTC with echo cancellation fix.

Also, start/stop recording depending on whether WebRTC has negotiated.
master
Roxie Linden 2024-01-09 11:57:01 -08:00
parent 23b065b0f1
commit 7246f55290
3 changed files with 65 additions and 17 deletions

View File

@ -7,7 +7,7 @@ if (WINDOWS)
FetchContent_Declare(
webrtc
URL "https://webrtc-build-releases.s3.us-west-2.amazonaws.com/webrtc.windows_x86.tar.bz2"
URL_HASH "MD5=0d55e58efceed3fb48085a5f0c58881c"
URL_HASH "MD5=cefbd446b1b152ac08217fc78648fb99"
FIND_PACKAGE_ARGS NAMES webrtc
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
DOWNLOAD_DIR "${LIBS_PREBUILT_DIR}/webrtc/"
@ -16,7 +16,7 @@ if (WINDOWS)
FetchContent_Declare(
webrtc
URL "https://webrtc-build-releases.s3.us-west-2.amazonaws.com/webrtc.windows_x86_64.tar.bz2"
URL_HASH "MD5=dfb692562770dc8c877ebfe4302e2881"
URL_HASH "MD5=b7a93b111e51ebcda21701c009c0676c"
FIND_PACKAGE_ARGS NAMES webrtc
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
DOWNLOAD_DIR "${LIBS_PREBUILT_DIR}/webrtc/"
@ -26,7 +26,7 @@ elseif (DARWIN)
FetchContent_Declare(
webrtc
URL "https://webrtc-build-releases.s3.us-west-2.amazonaws.com/webrtc.macos_x86_64.tar.bz2"
URL_HASH "MD5=cfbcac7da897a862f9791ea29330b814"
URL_HASH "MD5=a965974e1d9fc7f55b852a8ff8ccf9a9"
FIND_PACKAGE_ARGS NAMES webrtc
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
DOWNLOAD_DIR "${LIBS_PREBUILT_DIR}/webrtc/"

View File

@ -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)
{

View File

@ -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;