Skip to content

Commit

Permalink
Fix WebRTC logging so that logs from libpeerconnection make it to the…
Browse files Browse the repository at this point in the history
… log.

BUG=319166

Review URL: https://codereview.chromium.org/71353010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235123 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
grunell@chromium.org committed Nov 14, 2013
1 parent 724d9e7 commit d9d7cc7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
11 changes: 9 additions & 2 deletions third_party/libjingle/overrides/init_webrtc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/native_library.h"
#include "base/path_service.h"
#include "talk/base/basictypes.h"
#include "third_party/libjingle/overrides/talk/base/logging.h"

const unsigned char* GetCategoryGroupEnabled(const char* category_group) {
return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group);
Expand Down Expand Up @@ -95,13 +96,19 @@ bool InitializeWebRtcModule() {
// the alloc/dealloc functions.
// PS: This function is actually implemented in allocator_proxy.cc with the
// new/delete overrides.
return initialize_module(*CommandLine::ForCurrentProcess(),
InitDiagnosticLoggingDelegateFunctionFunction init_diagnostic_logging = NULL;
bool init_ok = initialize_module(*CommandLine::ForCurrentProcess(),
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
&Allocate, &Dellocate,
#endif
logging::GetLogMessageHandler(),
&GetCategoryGroupEnabled, &AddTraceEvent,
&g_create_webrtc_media_engine, &g_destroy_webrtc_media_engine);
&g_create_webrtc_media_engine, &g_destroy_webrtc_media_engine,
&init_diagnostic_logging);

if (init_ok)
talk_base::SetExtraLoggingInit(init_diagnostic_logging);
return init_ok;
}

cricket::MediaEngineInterface* CreateWebRtcMediaEngine(
Expand Down
6 changes: 5 additions & 1 deletion third_party/libjingle/overrides/init_webrtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ typedef cricket::MediaEngineInterface* (*CreateWebRtcMediaEngineFunction)(
typedef void (*DestroyWebRtcMediaEngineFunction)(
cricket::MediaEngineInterface* media_engine);

typedef void (*InitDiagnosticLoggingDelegateFunctionFunction)(
void (*DelegateFunction)(const std::string&));

// A typedef for the main initialize function in libpeerconnection.
// This will initialize logging in the module with the proper arguments
// as well as provide pointers back to a couple webrtc factory functions.
Expand All @@ -45,7 +48,8 @@ typedef bool (*InitializeModuleFunction)(
webrtc::GetCategoryEnabledPtr trace_get_category_enabled,
webrtc::AddTraceEventPtr trace_add_trace_event,
CreateWebRtcMediaEngineFunction* create_media_engine,
DestroyWebRtcMediaEngineFunction* destroy_media_engine);
DestroyWebRtcMediaEngineFunction* destroy_media_engine,
InitDiagnosticLoggingDelegateFunctionFunction* init_diagnostic_logging);

#if !defined(LIBPEERCONNECTION_IMPLEMENTATION)
// Load and initialize the shared WebRTC module (libpeerconnection).
Expand Down
6 changes: 5 additions & 1 deletion third_party/libjingle/overrides/initialize_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "init_webrtc.h"
#include "talk/base/basictypes.h"
#include "talk/media/webrtc/webrtcmediaengine.h"
#include "third_party/libjingle/overrides/talk/base/logging.h"

#if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
#error "Only compile the allocator proxy with the shared_library implementation"
Expand Down Expand Up @@ -52,14 +53,17 @@ bool InitializeModule(const CommandLine& command_line,
webrtc::GetCategoryEnabledPtr trace_get_category_enabled,
webrtc::AddTraceEventPtr trace_add_trace_event,
CreateWebRtcMediaEngineFunction* create_media_engine,
DestroyWebRtcMediaEngineFunction* destroy_media_engine) {
DestroyWebRtcMediaEngineFunction* destroy_media_engine,
InitDiagnosticLoggingDelegateFunctionFunction*
init_diagnostic_logging) {
#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
g_alloc = alloc;
g_dealloc = dealloc;
#endif

*create_media_engine = &CreateWebRtcMediaEngine;
*destroy_media_engine = &DestroyWebRtcMediaEngine;
*init_diagnostic_logging = &talk_base::InitDiagnosticLoggingDelegateFunction;

if (CommandLine::Init(0, NULL)) {
#if !defined(OS_WIN)
Expand Down
12 changes: 12 additions & 0 deletions third_party/libjingle/overrides/talk/base/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
namespace talk_base {

void (*g_logging_delegate_function)(const std::string&) = NULL;
void (*g_extra_logging_init_function)(
void (*logging_delegate_function)(const std::string&)) = NULL;
#ifndef NDEBUG
COMPILE_ASSERT(sizeof(base::subtle::Atomic32) == sizeof(base::PlatformThreadId),
atomic32_not_same_size_as_platformthreadid);
Expand Down Expand Up @@ -308,6 +310,16 @@ void InitDiagnosticLoggingDelegateFunction(
IPAddress::set_strip_sensitive(true);
#endif
g_logging_delegate_function = delegate;

if (g_extra_logging_init_function)
g_extra_logging_init_function(delegate);
}

void SetExtraLoggingInit(
void (*function)(void (*delegate)(const std::string&))) {
CHECK(function);
CHECK(!g_extra_logging_init_function);
g_extra_logging_init_function = function;
}

} // namespace talk_base
5 changes: 5 additions & 0 deletions third_party/libjingle/overrides/talk/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,14 @@ void LogMultiline(LoggingSeverity level, const char* label, bool input,
const void* data, size_t len, bool hex_mode,
LogMultilineState* state);

// TODO(grunell): Change name to InitDiagnosticLoggingDelegate or
// InitDiagnosticLogging. Change also in init_webrtc.h/cc.
// TODO(grunell): typedef the delegate function.
void InitDiagnosticLoggingDelegateFunction(
void (*delegate)(const std::string&));

void SetExtraLoggingInit(
void (*function)(void (*delegate)(const std::string&)));
} // namespace talk_base

//////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit d9d7cc7

Please sign in to comment.