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/llwebrtc | |
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/llwebrtc')
-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 |
3 files changed, 76 insertions, 6 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; |