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"
13 #if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
14 #error "Only compile the allocator proxy with the shared_library implementation"
18 #define ALLOC_EXPORT __declspec(dllexport)
20 #define ALLOC_EXPORT __attribute__((visibility("default")))
23 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
24 // These are used by our new/delete overrides in
25 // allocator_shim/allocator_proxy.cc
26 AllocateFunction g_alloc
= NULL
;
27 DellocateFunction g_dealloc
= NULL
;
30 // Forward declare of the libjingle internal factory and destroy methods for the
31 // WebRTC media engine.
32 cricket::MediaEngineInterface
* CreateWebRtcMediaEngine(
33 webrtc::AudioDeviceModule
* adm
,
34 webrtc::AudioDeviceModule
* adm_sc
,
35 cricket::WebRtcVideoEncoderFactory
* encoder_factory
,
36 cricket::WebRtcVideoDecoderFactory
* decoder_factory
);
38 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface
* media_engine
);
42 // Initialize logging, set the forward allocator functions (not on mac), and
43 // return pointers to libjingle's WebRTC factory methods.
44 // Called from init_webrtc.cc.
46 bool InitializeModule(const CommandLine
& command_line
,
47 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
48 AllocateFunction alloc
,
49 DellocateFunction dealloc
,
51 logging::LogMessageHandlerFunction log_handler
,
52 webrtc::GetCategoryEnabledPtr trace_get_category_enabled
,
53 webrtc::AddTraceEventPtr trace_add_trace_event
,
54 CreateWebRtcMediaEngineFunction
* create_media_engine
,
55 DestroyWebRtcMediaEngineFunction
* destroy_media_engine
) {
56 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
61 *create_media_engine
= &CreateWebRtcMediaEngine
;
62 *destroy_media_engine
= &DestroyWebRtcMediaEngine
;
64 if (CommandLine::Init(0, NULL
)) {
66 // This is not needed on Windows since CommandLine::Init has already
67 // done the equivalent thing via the GetCommandLine() API.
68 CommandLine::ForCurrentProcess()->AppendArguments(command_line
, true);
70 logging::LoggingSettings settings
;
71 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
72 logging::InitLogging(settings
);
74 // Override the log message handler to forward logs to chrome's handler.
75 logging::SetLogMessageHandler(log_handler
);
76 webrtc::SetupEventTracer(trace_get_category_enabled
,
77 trace_add_trace_event
);