diff options
author | Roxie Linden <roxie@lindenlab.com> | 2024-07-31 21:23:30 -0600 |
---|---|---|
committer | Roxie Linden <roxie@lindenlab.com> | 2024-07-31 21:23:30 -0600 |
commit | b9c222dfaeb4531f91f6e0bb02bb4b0da599d08b (patch) | |
tree | 1f88fac45393977ec286e2635f2ff08ab608e830 /indra | |
parent | 2582e4a47a83a201668495a956a766a1dd58967c (diff) |
Implement a Logging Sink for WebRTC
WebRTC logs now pass out of the webrtc library into a logging sink,
which converts them into SecondLife.log compatable logging calls.
This includes fatal errors and asserts, which are now logged into
SecondLife.log, and should be available in the crash logger.
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llwebrtc/llwebrtc.cpp | 9 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc.h | 16 | ||||
-rw-r--r-- | indra/llwebrtc/llwebrtc_impl.h | 57 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.cpp | 25 | ||||
-rw-r--r-- | indra/newview/llvoicewebrtc.h | 9 |
5 files changed, 108 insertions, 8 deletions
diff --git a/indra/llwebrtc/llwebrtc.cpp b/indra/llwebrtc/llwebrtc.cpp index 6dc632aba4..2c890acbdb 100644 --- a/indra/llwebrtc/llwebrtc.cpp +++ b/indra/llwebrtc/llwebrtc.cpp @@ -154,7 +154,8 @@ void LLCustomProcessor::Process(webrtc::AudioBuffer *audio_in) // LLWebRTCImpl implementation // -LLWebRTCImpl::LLWebRTCImpl() : +LLWebRTCImpl::LLWebRTCImpl(LLWebRTCLogCallback* logCallback) : + mLogSink(new LLWebRTCLogSink(logCallback)), mPeerCustomProcessor(nullptr), mMute(true), mTuningMode(false), @@ -173,6 +174,7 @@ void LLWebRTCImpl::init() // Normal logging is rather spammy, so turn it off. rtc::LogMessage::LogToDebug(rtc::LS_NONE); rtc::LogMessage::SetLogToStderr(true); + rtc::LogMessage::AddLogToStream(mLogSink, rtc::LS_VERBOSE); mTaskQueueFactory = webrtc::CreateDefaultTaskQueueFactory(); @@ -312,6 +314,7 @@ void LLWebRTCImpl::terminate() mPeerDeviceModule = nullptr; mTaskQueueFactory = nullptr; }); + rtc::LogMessage::RemoveLogToStream(mLogSink); } // @@ -1327,9 +1330,9 @@ void freePeerConnection(LLWebRTCPeerConnectionInterface* peer_connection) } -void init() +void init(LLWebRTCLogCallback* logCallback) { - gWebRTCImpl = new LLWebRTCImpl(); + gWebRTCImpl = new LLWebRTCImpl(logCallback); gWebRTCImpl->init(); } diff --git a/indra/llwebrtc/llwebrtc.h b/indra/llwebrtc/llwebrtc.h index 54eefc8554..c6fdb909dd 100644 --- a/indra/llwebrtc/llwebrtc.h +++ b/indra/llwebrtc/llwebrtc.h @@ -56,6 +56,20 @@ namespace llwebrtc { +class LLWebRTCLogCallback +{ +public: + typedef enum { + LOG_LEVEL_VERBOSE = 0, + LOG_LEVEL_INFO, + LOG_LEVEL_WARNING, + LOG_LEVEL_ERROR + } LogLevel; + + virtual void LogMessage(LogLevel level, const std::string& message) = 0; +}; + + // LLWebRTCVoiceDevice is a simple representation of the // components of a device, used to communicate this // information to the viewer. @@ -262,7 +276,7 @@ class LLWebRTCPeerConnectionInterface // exports. // This library must be initialized before use. -LLSYMEXPORT void init(); +LLSYMEXPORT void init(LLWebRTCLogCallback* logSink); // And should be terminated as part of shutdown. LLSYMEXPORT void terminate(); diff --git a/indra/llwebrtc/llwebrtc_impl.h b/indra/llwebrtc/llwebrtc_impl.h index 2fb5525519..c5b32123eb 100644 --- a/indra/llwebrtc/llwebrtc_impl.h +++ b/indra/llwebrtc/llwebrtc_impl.h @@ -69,6 +69,54 @@ namespace llwebrtc class LLWebRTCPeerConnectionImpl; +class LLWebRTCLogSink : public rtc::LogSink { +public: + LLWebRTCLogSink(LLWebRTCLogCallback* callback) : + mCallback(callback) + { + } + + // Destructor: close the log file + ~LLWebRTCLogSink() override + { + } + + void OnLogMessage(const std::string& msg, + rtc::LoggingSeverity severity) override + { + if (mCallback) + { + switch(severity) + { + case rtc::LS_VERBOSE: + mCallback->LogMessage(LLWebRTCLogCallback::LOG_LEVEL_VERBOSE, msg); + break; + case rtc::LS_INFO: + mCallback->LogMessage(LLWebRTCLogCallback::LOG_LEVEL_VERBOSE, msg); + break; + case rtc::LS_WARNING: + mCallback->LogMessage(LLWebRTCLogCallback::LOG_LEVEL_VERBOSE, msg); + break; + case rtc::LS_ERROR: + mCallback->LogMessage(LLWebRTCLogCallback::LOG_LEVEL_VERBOSE, msg); + break; + default: + break; + } + } + } + + void OnLogMessage(const std::string& message) override + { + if (mCallback) + { + mCallback->LogMessage(LLWebRTCLogCallback::LOG_LEVEL_VERBOSE, message); + } + } + +private: + LLWebRTCLogCallback* mCallback; +}; // Implements a class allowing capture of audio data // to determine audio level of the microphone. @@ -139,8 +187,11 @@ class LLCustomProcessor : public webrtc::CustomProcessing class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceSink { public: - LLWebRTCImpl(); - ~LLWebRTCImpl() {} + LLWebRTCImpl(LLWebRTCLogCallback* logCallback); + ~LLWebRTCImpl() + { + delete mLogSink; + } void init(); void terminate(); @@ -228,6 +279,8 @@ class LLWebRTCImpl : public LLWebRTCDeviceInterface, public webrtc::AudioDeviceS void setRecording(bool recording); protected: + LLWebRTCLogSink* mLogSink; + // The native webrtc threads std::unique_ptr<rtc::Thread> mNetworkThread; std::unique_ptr<rtc::Thread> mWorkerThread; diff --git a/indra/newview/llvoicewebrtc.cpp b/indra/newview/llvoicewebrtc.cpp index c6cc2a053a..3164886494 100644 --- a/indra/newview/llvoicewebrtc.cpp +++ b/indra/newview/llvoicewebrtc.cpp @@ -250,7 +250,7 @@ LLWebRTCVoiceClient::~LLWebRTCVoiceClient() void LLWebRTCVoiceClient::init(LLPumpIO* pump) { // constructor will set up LLVoiceClient::getInstance() - llwebrtc::init(); + llwebrtc::init(this); mWebRTCDeviceInterface = llwebrtc::getDeviceInterface(); mWebRTCDeviceInterface->setDevicesObserver(this); @@ -281,6 +281,29 @@ void LLWebRTCVoiceClient::cleanUp() LL_DEBUGS("Voice") << "Exiting" << LL_ENDL; } +void LLWebRTCVoiceClient::LogMessage(llwebrtc::LLWebRTCLogCallback::LogLevel level, const std::string& message) +{ + switch (level) + { + case llwebrtc::LLWebRTCLogCallback::LOG_LEVEL_VERBOSE: + LL_DEBUGS("Voice") << message << LL_ENDL; + break; + case llwebrtc::LLWebRTCLogCallback::LOG_LEVEL_INFO: + LL_INFOS("Voice") << message << LL_ENDL; + break; + case llwebrtc::LLWebRTCLogCallback::LOG_LEVEL_WARNING: + LL_WARNS("Voice") << message << LL_ENDL; + break; + case llwebrtc::LLWebRTCLogCallback::LOG_LEVEL_ERROR: + // use WARN so that we don't crash on a webrtc error. + // webrtc will force a crash on a fatal error. + LL_WARNS("Voice") << message << LL_ENDL; + break; + default: + break; + } +} + // -------------------------------------------------- const LLVoiceVersionInfo& LLWebRTCVoiceClient::getVersion() diff --git a/indra/newview/llvoicewebrtc.h b/indra/newview/llvoicewebrtc.h index 624b1b9bd2..8a65ef667c 100644 --- a/indra/newview/llvoicewebrtc.h +++ b/indra/newview/llvoicewebrtc.h @@ -62,7 +62,8 @@ extern const std::string WEBRTC_VOICE_SERVER_TYPE; class LLWebRTCVoiceClient : public LLSingleton<LLWebRTCVoiceClient>, virtual public LLVoiceModuleInterface, public llwebrtc::LLWebRTCDevicesObserver, - public LLMuteListObserver + public LLMuteListObserver, + public llwebrtc::LLWebRTCLogCallback { LLSINGLETON_C11(LLWebRTCVoiceClient); LOG_CLASS(LLWebRTCVoiceClient); @@ -88,6 +89,12 @@ public: LLSD getP2PChannelInfoTemplate(const LLUUID& id) const override; + /////////////////// + /// @name Logging + /// @{ + void LogMessage(llwebrtc::LLWebRTCLogCallback::LogLevel level, const std::string& message) override; + //@} + ///////////////////// /// @name Tuning //@{ |