mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 743703: allow mirroring of trace logs to NSPR; fix backwards lazy allocation defines r=pkerr
This commit is contained in:
parent
84308dafb0
commit
917bc3029a
@ -27,6 +27,15 @@ GetUserMediaLog()
|
||||
}
|
||||
#endif
|
||||
|
||||
static PRLogModuleInfo*
|
||||
GetWebrtcTraceLog()
|
||||
{
|
||||
static PRLogModuleInfo *sLog;
|
||||
if (!sLog)
|
||||
sLog = PR_NewLogModule("webrtc_trace");
|
||||
return sLog;
|
||||
}
|
||||
|
||||
#include "MediaEngineWebRTC.h"
|
||||
#include "ImageContainer.h"
|
||||
#include "nsIComponentRegistrar.h"
|
||||
@ -65,6 +74,14 @@ MediaEngineWebRTC::MediaEngineWebRTC(MediaEnginePrefs &aPrefs)
|
||||
gFarendObserver = new AudioOutputObserver();
|
||||
}
|
||||
|
||||
void
|
||||
MediaEngineWebRTC::Print(webrtc::TraceLevel level, const char* message, int length)
|
||||
{
|
||||
PRLogModuleInfo *log = GetWebrtcTraceLog();
|
||||
// XXX look at log level?
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("%s", message));
|
||||
}
|
||||
|
||||
void
|
||||
MediaEngineWebRTC::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >* aVSources)
|
||||
{
|
||||
@ -130,7 +147,7 @@ MediaEngineWebRTC::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSourc
|
||||
}
|
||||
}
|
||||
|
||||
PRLogModuleInfo *logs = GetWebRTCLogInfo();
|
||||
PRLogModuleInfo *logs = GetWebrtcTraceLog();
|
||||
if (!gWebrtcTraceLoggingOn && logs && logs->level > 0) {
|
||||
// no need to a critical section or lock here
|
||||
gWebrtcTraceLoggingOn = 1;
|
||||
@ -143,7 +160,11 @@ MediaEngineWebRTC::EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSourc
|
||||
LOG(("%s Logging webrtc to %s level %d", __FUNCTION__, file, logs->level));
|
||||
|
||||
mVideoEngine->SetTraceFilter(logs->level);
|
||||
mVideoEngine->SetTraceFile(file);
|
||||
if (strcmp(file, "nspr") == 0) {
|
||||
mVideoEngine->SetTraceCallback(this);
|
||||
} else {
|
||||
mVideoEngine->SetTraceFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
ptrViEBase = webrtc::ViEBase::GetInterface(mVideoEngine);
|
||||
@ -263,7 +284,7 @@ MediaEngineWebRTC::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSourc
|
||||
}
|
||||
}
|
||||
|
||||
PRLogModuleInfo *logs = GetWebRTCLogInfo();
|
||||
PRLogModuleInfo *logs = GetWebrtcTraceLog();
|
||||
if (!gWebrtcTraceLoggingOn && logs && logs->level > 0) {
|
||||
// no need to a critical section or lock here
|
||||
gWebrtcTraceLoggingOn = 1;
|
||||
@ -276,7 +297,11 @@ MediaEngineWebRTC::EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSourc
|
||||
LOG(("Logging webrtc to %s level %d", __FUNCTION__, file, logs->level));
|
||||
|
||||
mVoiceEngine->SetTraceFilter(logs->level);
|
||||
mVoiceEngine->SetTraceFile(file);
|
||||
if (strcmp(file, "nspr") == 0) {
|
||||
mVoiceEngine->SetTraceCallback(this);
|
||||
} else {
|
||||
mVoiceEngine->SetTraceFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
ptrVoEBase = webrtc::VoEBase::GetInterface(mVoiceEngine);
|
||||
@ -340,13 +365,16 @@ MediaEngineWebRTC::Shutdown()
|
||||
// This is likely paranoia
|
||||
MutexAutoLock lock(mMutex);
|
||||
|
||||
// Clear callbacks before we go away since the engines may outlive us
|
||||
if (mVideoEngine) {
|
||||
mVideoSources.Clear();
|
||||
mVideoEngine->SetTraceCallback(nullptr);
|
||||
webrtc::VideoEngine::Delete(mVideoEngine);
|
||||
}
|
||||
|
||||
if (mVoiceEngine) {
|
||||
mAudioSources.Clear();
|
||||
mVoiceEngine->SetTraceCallback(nullptr);
|
||||
webrtc::VoiceEngine::Delete(mVoiceEngine);
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,8 @@ private:
|
||||
NullTransport *mNullTransport;
|
||||
};
|
||||
|
||||
class MediaEngineWebRTC : public MediaEngine
|
||||
class MediaEngineWebRTC : public MediaEngine,
|
||||
public webrtc::TraceCallback
|
||||
{
|
||||
public:
|
||||
MediaEngineWebRTC(MediaEnginePrefs &aPrefs);
|
||||
@ -368,6 +369,9 @@ public:
|
||||
virtual void EnumerateVideoDevices(nsTArray<nsRefPtr<MediaEngineVideoSource> >*);
|
||||
virtual void EnumerateAudioDevices(nsTArray<nsRefPtr<MediaEngineAudioSource> >*);
|
||||
|
||||
// Webrtc trace callbacks for proxying to NSPR
|
||||
virtual void Print(webrtc::TraceLevel level, const char* message, int length);
|
||||
|
||||
private:
|
||||
~MediaEngineWebRTC() {
|
||||
Shutdown();
|
||||
|
@ -130,7 +130,7 @@
|
||||
'trace_win.h',
|
||||
],
|
||||
}],
|
||||
['enable_lazy_trace_alloc==0', {
|
||||
['enable_lazy_trace_alloc==1', {
|
||||
'defines': [
|
||||
'WEBRTC_LAZY_TRACE_ALLOC',
|
||||
],
|
||||
|
@ -87,14 +87,12 @@ TraceImpl::TraceImpl()
|
||||
|
||||
for (int m = 0; m < WEBRTC_TRACE_NUM_ARRAY; ++m) {
|
||||
for (int n = 0; n < WEBRTC_TRACE_MAX_QUEUE; ++n) {
|
||||
#if defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
message_queue_[m][n] = new
|
||||
char[WEBRTC_TRACE_MAX_MESSAGE_SIZE];
|
||||
#else
|
||||
message_queue_[m][n] = NULL;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if !defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
AllocateTraceBuffers();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool TraceImpl::StopThread() {
|
||||
@ -341,21 +339,28 @@ int32_t TraceImpl::AddModuleAndId(char* trace_message,
|
||||
return kMessageLength;
|
||||
}
|
||||
|
||||
int32_t TraceImpl::SetTraceFileImpl(const char* file_name_utf8,
|
||||
const bool add_file_counter) {
|
||||
#if !defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
if (file_name_utf8) {
|
||||
// Lazy-allocate trace buffers to save memory.
|
||||
// Avoid locking issues by not holding both critsects at once.
|
||||
// Do this before we can return true from .Open().
|
||||
CriticalSectionScoped lock(critsect_array_);
|
||||
void TraceImpl::AllocateTraceBuffers()
|
||||
{
|
||||
// Lazy-allocate trace buffers to save memory.
|
||||
// Avoid locking issues by not holding both critsects at once.
|
||||
// Do this before we can return true from .Open().
|
||||
CriticalSectionScoped lock(critsect_array_);
|
||||
|
||||
if (!message_queue_[0][0]) {
|
||||
for (int m = 0; m < WEBRTC_TRACE_NUM_ARRAY; ++m) {
|
||||
for (int n = 0; n < WEBRTC_TRACE_MAX_QUEUE; ++n) {
|
||||
message_queue_[m][n] = new char[WEBRTC_TRACE_MAX_MESSAGE_SIZE];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t TraceImpl::SetTraceFileImpl(const char* file_name_utf8,
|
||||
const bool add_file_counter) {
|
||||
#if defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
if (file_name_utf8) {
|
||||
AllocateTraceBuffers();
|
||||
}
|
||||
#endif
|
||||
|
||||
CriticalSectionScoped lock(critsect_interface_);
|
||||
@ -392,6 +397,11 @@ int32_t TraceImpl::TraceFileImpl(
|
||||
}
|
||||
|
||||
int32_t TraceImpl::SetTraceCallbackImpl(TraceCallback* callback) {
|
||||
#if defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
if (callback) {
|
||||
AllocateTraceBuffers();
|
||||
}
|
||||
#endif
|
||||
CriticalSectionScoped lock(critsect_interface_);
|
||||
callback_ = callback;
|
||||
return 0;
|
||||
@ -444,7 +454,7 @@ void TraceImpl::AddMessageToList(
|
||||
|
||||
uint16_t idx = next_free_idx_[active_queue_];
|
||||
|
||||
#if !defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
#if defined(WEBRTC_LAZY_TRACE_ALLOC)
|
||||
// Avoid grabbing another lock just to check Open(); use
|
||||
// the fact we've allocated buffers to decide whether to save
|
||||
// the message in the buffer. Use the indexing as this minimizes
|
||||
|
@ -48,6 +48,7 @@ class TraceImpl : public Trace {
|
||||
static TraceImpl* CreateInstance();
|
||||
static TraceImpl* GetTrace(const TraceLevel level = kTraceAll);
|
||||
|
||||
void AllocateTraceBuffers();
|
||||
int32_t SetTraceFileImpl(const char* file_name, const bool add_file_counter);
|
||||
int32_t TraceFileImpl(char file_name[FileWrapper::kMaxFileNameSize]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user