From adfb4287962f908ea35d9fed29729a95fc03f75a Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 20 May 2021 09:43:18 +1200 Subject: [PATCH] Distinguish use of WebRTC features - audio versus data channel --- libraries/audio-client/src/AudioClient.cpp | 11 ++++++----- libraries/audio-client/src/AudioClient.h | 8 +++++++- libraries/shared/src/shared/WebRTC.h | 22 +++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/libraries/audio-client/src/AudioClient.cpp b/libraries/audio-client/src/AudioClient.cpp index 38635870fd..c03f37576d 100644 --- a/libraries/audio-client/src/AudioClient.cpp +++ b/libraries/audio-client/src/AudioClient.cpp @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 1/22/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -363,7 +364,7 @@ AudioClient::AudioClient() { configureReverb(); -#if defined(WEBRTC_ENABLED) +#if defined(WEBRTC_AUDIO) configureWebrtc(); #endif @@ -1142,7 +1143,7 @@ void AudioClient::setReverbOptions(const AudioEffectOptions* options) { } } -#if defined(WEBRTC_ENABLED) +#if defined(WEBRTC_AUDIO) static void deinterleaveToFloat(const int16_t* src, float* const* dst, int numFrames, int numChannels) { for (int i = 0; i < numFrames; i++) { @@ -1261,7 +1262,7 @@ void AudioClient::processWebrtcNearEnd(int16_t* samples, int numFrames, int numC } } -#endif // WEBRTC_ENABLED +#endif // WEBRTC_AUDIO void AudioClient::handleLocalEchoAndReverb(QByteArray& inputByteArray) { // If there is server echo, reverb will be applied to the recieved audio stream so no need to have it here. @@ -1462,7 +1463,7 @@ void AudioClient::handleMicAudioInput() { } isClipping = (_timeSinceLastClip >= 0.0f) && (_timeSinceLastClip < 2.0f); // 2 second hold time -#if defined(WEBRTC_ENABLED) +#if defined(WEBRTC_AUDIO) if (_isAECEnabled) { processWebrtcNearEnd(inputAudioSamples.get(), inputSamplesRequired / _inputFormat.channelCount(), _inputFormat.channelCount(), _inputFormat.sampleRate()); @@ -2420,7 +2421,7 @@ qint64 AudioClient::AudioOutputIODevice::readData(char * data, qint64 maxSize) { // limit the audio _audio->_audioLimiter.render(mixBuffer, scratchBuffer, framesPopped); -#if defined(WEBRTC_ENABLED) +#if defined(WEBRTC_AUDIO) if (_audio->_isAECEnabled) { _audio->processWebrtcFarEnd(scratchBuffer, framesPopped, OUTPUT_CHANNEL_COUNT, _audio->_outputFormat.sampleRate()); } diff --git a/libraries/audio-client/src/AudioClient.h b/libraries/audio-client/src/AudioClient.h index a5de9bd4ca..19ccb587a4 100644 --- a/libraries/audio-client/src/AudioClient.h +++ b/libraries/audio-client/src/AudioClient.h @@ -4,6 +4,7 @@ // // Created by Stephen Birarda on 1/22/13. // Copyright 2013 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -56,6 +57,11 @@ #include "AudioFileWav.h" #include "HifiAudioDeviceInfo.h" +#if defined(WEBRTC_AUDIO) +# include +# include "modules/audio_processing/audio_processing_impl.h" +#endif + #ifdef _WIN32 #pragma warning( push ) #pragma warning( disable : 4273 ) @@ -450,7 +456,7 @@ private: void updateReverbOptions(); void handleLocalEchoAndReverb(QByteArray& inputByteArray); -#if defined(WEBRTC_ENABLED) +#if defined(WEBRTC_AUDIO) static const int WEBRTC_SAMPLE_RATE_MAX = 96000; static const int WEBRTC_CHANNELS_MAX = 2; static const int WEBRTC_FRAMES_MAX = webrtc::AudioProcessing::kChunkSizeMs * WEBRTC_SAMPLE_RATE_MAX / 1000; diff --git a/libraries/shared/src/shared/WebRTC.h b/libraries/shared/src/shared/WebRTC.h index 2f0e444bff..e99c643045 100644 --- a/libraries/shared/src/shared/WebRTC.h +++ b/libraries/shared/src/shared/WebRTC.h @@ -3,6 +3,7 @@ // libraries/shared/src/shared/ // // Copyright 2019 High Fidelity, Inc. +// Copyright 2021 Vircadia contributors. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -11,26 +12,29 @@ #ifndef hifi_WebRTC_h #define hifi_WebRTC_h +#ifndef QSYSTEMDETECTION_H +#include +#endif + +// WEBRTC_AUDIO: WebRTC audio features, e.g., echo canceling. +// WEBRTC_DATA_CHANNEL: WebRTC client-server connections in parallel with UDP. + #if defined(Q_OS_MAC) -# define WEBRTC_ENABLED 1 +# define WEBRTC_AUDIO 1 # define WEBRTC_POSIX 1 #elif defined(Q_OS_WIN) -# define WEBRTC_ENABLED 1 +# define WEBRTC_AUDIO 1 +# define WEBRTC_DATA_CHANNEL 1 # define WEBRTC_WIN 1 # define NOMINMAX 1 # define WIN32_LEAN_AND_MEAN 1 #elif defined(Q_OS_ANDROID) // I don't yet have a working libwebrtc for android -// # define WEBRTC_ENABLED 1 +// # define WEBRTC_AUDIO 1 // # define WEBRTC_POSIX 1 #elif defined(Q_OS_LINUX) -# define WEBRTC_ENABLED 1 +# define WEBRTC_AUDIO 1 # define WEBRTC_POSIX 1 #endif -#if defined(WEBRTC_ENABLED) -# include -# include "modules/audio_processing/audio_processing_impl.h" -#endif - #endif // hifi_WebRTC_h