1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "allocator_shim/allocator_stub.h"
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "init_webrtc.h"
10 #include "talk/base/basictypes.h"
11 #include "talk/media/webrtc/webrtcmediaengine.h"
12 #include "third_party/libjingle/overrides/talk/base/logging.h"
14 #if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
15 #error "Only compile the allocator proxy with the shared_library implementation"
19 #define ALLOC_EXPORT __declspec(dllexport)
21 #define ALLOC_EXPORT __attribute__((visibility("default")))
24 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
25 // These are used by our new/delete overrides in
26 // allocator_shim/allocator_proxy.cc
27 AllocateFunction g_alloc
= NULL
;
28 DellocateFunction g_dealloc
= NULL
;
31 // Forward declare of the libjingle internal factory and destroy methods for the
32 // WebRTC media engine.
33 cricket::MediaEngineInterface
* CreateWebRtcMediaEngine(
34 webrtc::AudioDeviceModule
* adm
,
35 webrtc::AudioDeviceModule
* adm_sc
,
36 cricket::WebRtcVideoEncoderFactory
* encoder_factory
,
37 cricket::WebRtcVideoDecoderFactory
* decoder_factory
);
39 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface
* media_engine
);
43 // Initialize logging, set the forward allocator functions (not on mac), and
44 // return pointers to libjingle's WebRTC factory methods.
45 // Called from init_webrtc.cc.
47 bool InitializeModule(const CommandLine
& command_line
,
48 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
49 AllocateFunction alloc
,
50 DellocateFunction dealloc
,
52 logging::LogMessageHandlerFunction log_handler
,
53 webrtc::GetCategoryEnabledPtr trace_get_category_enabled
,
54 webrtc::AddTraceEventPtr trace_add_trace_event
,
55 CreateWebRtcMediaEngineFunction
* create_media_engine
,
56 DestroyWebRtcMediaEngineFunction
* destroy_media_engine
,
57 InitDiagnosticLoggingDelegateFunctionFunction
*
58 init_diagnostic_logging
) {
59 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
64 *create_media_engine
= &CreateWebRtcMediaEngine
;
65 *destroy_media_engine
= &DestroyWebRtcMediaEngine
;
66 *init_diagnostic_logging
= &talk_base::InitDiagnosticLoggingDelegateFunction
;
68 if (CommandLine::Init(0, NULL
)) {
70 // This is not needed on Windows since CommandLine::Init has already
71 // done the equivalent thing via the GetCommandLine() API.
72 CommandLine::ForCurrentProcess()->AppendArguments(command_line
, true);
74 logging::LoggingSettings settings
;
75 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
76 logging::InitLogging(settings
);
78 // Override the log message handler to forward logs to chrome's handler.
79 logging::SetLogMessageHandler(log_handler
);
80 webrtc::SetupEventTracer(trace_get_category_enabled
,
81 trace_add_trace_event
);