ce11567d4650cb6b4078f3063c60c3a19d274b14
[platform/framework/web/crosswalk.git] / src / third_party / libjingle / overrides / initialize_module.cc
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.
4
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/media/webrtc/webrtcmediaengine.h"
11 #include "webrtc/base/basictypes.h"
12 #include "webrtc/base/logging.h"
13
14 #if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
15 #error "Only compile the allocator proxy with the shared_library implementation"
16 #endif
17
18 #if defined(OS_WIN)
19 #define ALLOC_EXPORT __declspec(dllexport)
20 #else
21 #define ALLOC_EXPORT __attribute__((visibility("default")))
22 #endif
23
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;
29 #endif
30
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);
38
39 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine);
40
41 // Define webrtc:field_trial::FindFullName to provide webrtc with a field trial
42 // implementation. The implementation is provided by the loader via the
43 // InitializeModule.
44 namespace {
45 FieldTrialFindFullName g_field_trial_find_ = NULL;
46 }
47
48 namespace webrtc {
49 namespace field_trial {
50 std::string FindFullName(const std::string& trial_name) {
51   return g_field_trial_find_(trial_name);
52 }
53 }  // namespace field_trial
54 }  // namespace webrtc
55
56 extern "C" {
57
58 // Initialize logging, set the forward allocator functions (not on mac), and
59 // return pointers to libjingle's WebRTC factory methods.
60 // Called from init_webrtc.cc.
61 ALLOC_EXPORT
62 bool InitializeModule(const CommandLine& command_line,
63 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
64                       AllocateFunction alloc,
65                       DellocateFunction dealloc,
66 #endif
67                       FieldTrialFindFullName field_trial_find,
68                       logging::LogMessageHandlerFunction log_handler,
69                       webrtc::GetCategoryEnabledPtr trace_get_category_enabled,
70                       webrtc::AddTraceEventPtr trace_add_trace_event,
71                       CreateWebRtcMediaEngineFunction* create_media_engine,
72                       DestroyWebRtcMediaEngineFunction* destroy_media_engine,
73                       InitDiagnosticLoggingDelegateFunctionFunction*
74                           init_diagnostic_logging) {
75 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
76   g_alloc = alloc;
77   g_dealloc = dealloc;
78 #endif
79
80   g_field_trial_find_ = field_trial_find;
81
82   *create_media_engine = &CreateWebRtcMediaEngine;
83   *destroy_media_engine = &DestroyWebRtcMediaEngine;
84   *init_diagnostic_logging = &rtc::InitDiagnosticLoggingDelegateFunction;
85
86   if (CommandLine::Init(0, NULL)) {
87 #if !defined(OS_WIN)
88     // This is not needed on Windows since CommandLine::Init has already
89     // done the equivalent thing via the GetCommandLine() API.
90     CommandLine::ForCurrentProcess()->AppendArguments(command_line, true);
91 #endif
92     logging::LoggingSettings settings;
93     settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
94     logging::InitLogging(settings);
95
96     // Override the log message handler to forward logs to chrome's handler.
97     logging::SetLogMessageHandler(log_handler);
98     webrtc::SetupEventTracer(trace_get_category_enabled,
99                              trace_add_trace_event);
100   }
101
102   return true;
103 }
104 }  // extern "C"