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