diff options
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llwebrtc/llwebrtc.cpp | 72 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc.h | 6 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc_impl.h | 42 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.cpp | 24 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.h | 1 |
5 files changed, 70 insertions, 75 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index dc746b7629..a3dadd696c 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -39,6 +39,34 @@ namespace llwebrtc const float VOLUME_SCALE_WEBRTC = 3.0f; + +double LLAudioDeviceObserver::getMicrophoneEnergy() { return mMicrophoneEnergy; } + +void LLAudioDeviceObserver::OnCaptureData(const void *audio_samples, + const size_t num_samples, + const size_t bytes_per_sample, + const size_t num_channels, + const uint32_t samples_per_sec) +{ + double energy = 0; + const short *samples = (const short *) audio_samples; + for (size_t index = 0; index < num_samples * num_channels; index++) + { + double sample = (static_cast<double>(samples[index]) / (double) 32768); + energy += sample * sample; + } + mMicrophoneEnergy = std::sqrt(energy); +} + +void LLAudioDeviceObserver::OnRenderData(const void *audio_samples, + const size_t num_samples, + const size_t bytes_per_sample, + const size_t num_channels, + const uint32_t samples_per_sec) +{ +} + + void LLWebRTCImpl::init() { mAnswerReceived = false; @@ -58,9 +86,10 @@ void LLWebRTCImpl::init() mWorkerThread->PostTask( [this]() { + mAudioDeviceObserver = new LLAudioDeviceObserver; mDeviceModule = webrtc::CreateAudioDeviceWithDataObserver(webrtc::AudioDeviceModule::AudioLayer::kPlatformDefaultAudio, mTaskQueueFactory.get(), - std::unique_ptr<webrtc::AudioDeviceDataObserver>(this)); + std::unique_ptr<webrtc::AudioDeviceDataObserver>(mAudioDeviceObserver)); mDeviceModule->Init(); mDeviceModule->SetStereoRecording(false); mDeviceModule->EnableBuiltInAEC(false); @@ -83,6 +112,10 @@ void LLWebRTCImpl::terminate() mWorkerThread->BlockingCall( [this]() { + if (mDeviceModule) + { + mDeviceModule->Terminate(); + } mDeviceModule = nullptr; mTaskQueueFactory = nullptr; @@ -231,32 +264,6 @@ void LLWebRTCImpl::setTuningMode(bool enable) }); } -double LLWebRTCImpl::getTuningMicrophoneEnergy() { return mTuningEnergy; } - -void LLWebRTCImpl::OnCaptureData(const void *audio_samples, - const size_t num_samples, - const size_t bytes_per_sample, - const size_t num_channels, - const uint32_t samples_per_sec) -{ - double energy = 0; - const short *samples = (const short *) audio_samples; - for (size_t index = 0; index < num_samples * num_channels; index++) - { - double sample = (static_cast<double>(samples[index]) / (double) 32768); - energy += sample * sample; - } - mTuningEnergy = std::sqrt(energy); -} - -void LLWebRTCImpl::OnRenderData(const void *audio_samples, - const size_t num_samples, - const size_t bytes_per_sample, - const size_t num_channels, - const uint32_t samples_per_sec) -{ -} - // // LLWebRTCSignalInterface // @@ -470,16 +477,9 @@ void LLWebRTCImpl::setSpeakerVolume(float volume) }); } -void LLWebRTCImpl::requestAudioLevel() +double LLWebRTCImpl::getAudioLevel() { - mWorkerThread->PostTask( - [this]() - { - for (auto &observer : mAudioObserverList) - { - observer->OnAudioLevel((float)mTuningEnergy); - } - }); + return mAudioDeviceObserver->getMicrophoneEnergy(); } // diff --git a/indra/llwebrtc/llwebrtc.h b/indra/llwebrtc/llwebrtc.h index d0d2834e3c..30c0d63c55 100644 --- a/indra/llwebrtc/llwebrtc.h +++ b/indra/llwebrtc/llwebrtc.h @@ -86,13 +86,12 @@ class LLWebRTCDeviceInterface virtual void unsetDevicesObserver(LLWebRTCDevicesObserver *observer) = 0; virtual void setTuningMode(bool enable) = 0; - virtual double getTuningMicrophoneEnergy() = 0; + virtual double getAudioLevel() = 0; }; class LLWebRTCAudioObserver { public: - virtual void OnAudioLevel(float level) = 0; }; class LLWebRTCAudioInterface @@ -101,8 +100,7 @@ class LLWebRTCAudioInterface virtual void setAudioObserver(LLWebRTCAudioObserver *observer) = 0; virtual void unsetAudioObserver(LLWebRTCAudioObserver *observer) = 0; virtual void setMute(bool mute) = 0; - virtual void setSpeakerVolume(float volume) = 0; // volume between 0.0 and 1.0 - virtual void requestAudioLevel() = 0; + virtual void setSpeakerVolume(float volume) = 0; // volume between 0.0 and 1.0 = 0; }; class LLWebRTCDataObserver diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h index 1670d10705..da829e52af 100644 --- a/indra/llwebrtc/llwebrtc_impl.h +++ b/indra/llwebrtc/llwebrtc_impl.h @@ -63,11 +63,31 @@ namespace llwebrtc { +class LLAudioDeviceObserver : public webrtc::AudioDeviceDataObserver +{ + public: + double getMicrophoneEnergy(); + + void OnCaptureData(const void *audio_samples, + const size_t num_samples, + const size_t bytes_per_sample, + const size_t num_channels, + const uint32_t samples_per_sec) override; + + void OnRenderData(const void *audio_samples, + const size_t num_samples, + const size_t bytes_per_sample, + const size_t num_channels, + const uint32_t samples_per_sec) override; + + protected: + double mMicrophoneEnergy; +}; + class LLWebRTCImpl : public LLWebRTCDeviceInterface, public LLWebRTCSignalInterface, public LLWebRTCAudioInterface, public LLWebRTCDataInterface, - public webrtc::AudioDeviceDataObserver, public webrtc::PeerConnectionObserver, public webrtc::CreateSessionDescriptionObserver, public webrtc::SetRemoteDescriptionObserverInterface, @@ -77,7 +97,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, { public: LLWebRTCImpl() : - mTuningEnergy(0.0) + mAudioDeviceObserver(nullptr) { } ~LLWebRTCImpl() {} @@ -98,20 +118,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, void setRenderDevice(const std::string& id) override; void setTuningMode(bool enable) override; - double getTuningMicrophoneEnergy() override; - - - void OnCaptureData(const void *audio_samples, - const size_t num_samples, - const size_t bytes_per_sample, - const size_t num_channels, - const uint32_t samples_per_sec) override; - - void OnRenderData(const void *audio_samples, - const size_t num_samples, - const size_t bytes_per_sample, - const size_t num_channels, - const uint32_t samples_per_sec) override; + double getAudioLevel() override; // // LLWebRTCSignalInterface @@ -131,7 +138,6 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, void unsetAudioObserver(LLWebRTCAudioObserver *observer) override; void setMute(bool mute) override; void setSpeakerVolume(float folume) override; // range 0.0-1.0 - void requestAudioLevel() override; // // LLWebRTCDataInterface @@ -195,7 +201,7 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, rtc::scoped_refptr<webrtc::AudioDeviceModule> mDeviceModule; std::vector<LLWebRTCDevicesObserver *> mVoiceDevicesObserverList; - double mTuningEnergy; + LLAudioDeviceObserver * mAudioDeviceObserver; // signaling std::vector<LLWebRTCSignalingObserver *> mSignalingObserverList; diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp index b621f5ee92..e6877063b5 100644 --- a/indra/newview/llvoicewebrtc.cpp +++ b/indra/newview/llvoicewebrtc.cpp @@ -2100,7 +2100,7 @@ void LLWebRTCVoiceClient::tuningSetSpeakerVolume(float volume) float LLWebRTCVoiceClient::tuningGetEnergy(void) { - return mWebRTCDeviceInterface->getTuningMicrophoneEnergy(); + return mWebRTCDeviceInterface->getAudioLevel(); } bool LLWebRTCVoiceClient::deviceSettingsAvailable() @@ -2357,9 +2357,14 @@ void LLWebRTCVoiceClient::sendPositionAndVolumeUpdate(void) } } - if (mWebRTCAudioInterface) + if (mWebRTCDataInterface && mWebRTCAudioInterface) { - mWebRTCAudioInterface->requestAudioLevel(); + Json::FastWriter writer; + Json::Value root; + root["p"] = (uint32_t) ((F32)mWebRTCDeviceInterface->getAudioLevel() * 256); + std::string json_data = writer.write(root); + + mWebRTCDataInterface->sendData(json_data, false); } @@ -2613,19 +2618,6 @@ void LLWebRTCVoiceClient::OnAudioEstablished(llwebrtc::LLWebRTCAudioInterface * setVoiceControlStateUnless(VOICE_STATE_SESSION_ESTABLISHED, VOICE_STATE_SESSION_RETRY); } -void LLWebRTCVoiceClient::OnAudioLevel(float level) -{ - if (mWebRTCDataInterface) - { - Json::FastWriter writer; - Json::Value root; - root["p"] = (uint32_t) (level * 256); - std::string json_data = writer.write(root); - - mWebRTCDataInterface->sendData(json_data, false); - } -} - void LLWebRTCVoiceClient::OnDataReceived(const std::string& data, bool binary) { // incoming data will be a json structure (if it's not binary.) We may pack diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h index bc858dcb32..518fee53ef 100644 --- a/indra/newview/llvoicewebrtc.h +++ b/indra/newview/llvoicewebrtc.h @@ -263,7 +263,6 @@ public: /// @name Signaling notification // LLWebRTCAudioObserver //@{ - void OnAudioLevel(float level) override; //@} ///////////////////////// |