- add sources.
[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/base/basictypes.h"
11 #include "talk/media/webrtc/webrtcmediaengine.h"
12
13 #if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
14 #error "Only compile the allocator proxy with the shared_library implementation"
15 #endif
16
17 #if defined(OS_WIN)
18 #define ALLOC_EXPORT __declspec(dllexport)
19 #else
20 #define ALLOC_EXPORT __attribute__((visibility("default")))
21 #endif
22
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;
28 #endif
29
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);
37
38 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine);
39
40 extern "C" {
41
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.
45 ALLOC_EXPORT
46 bool InitializeModule(const CommandLine& command_line,
47 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
48                       AllocateFunction alloc,
49                       DellocateFunction dealloc,
50 #endif
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)
57   g_alloc = alloc;
58   g_dealloc = dealloc;
59 #endif
60
61   *create_media_engine = &CreateWebRtcMediaEngine;
62   *destroy_media_engine = &DestroyWebRtcMediaEngine;
63
64   if (CommandLine::Init(0, NULL)) {
65 #if !defined(OS_WIN)
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);
69 #endif
70     logging::LoggingSettings settings;
71     settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
72     logging::InitLogging(settings);
73
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);
78   }
79
80   return true;
81 }
82 }  // extern "C"