OLD | NEW |
| (Empty) |
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 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
6 #include <math.h> // needed for _set_FMA3_enable | |
7 #endif // WIN && ARCH_CPU_X86_64 | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/files/file_path.h" | |
11 #include "base/logging.h" | |
12 #include "third_party/libjingle/source/talk/media/webrtc/webrtcmediaengine.h" | |
13 #include "third_party/libjingle/allocator_shim/allocator_stub.h" | |
14 #include "third_party/libjingle/overrides/init_webrtc.h" | |
15 #include "third_party/webrtc/base/basictypes.h" | |
16 #include "third_party/webrtc/base/logging.h" | |
17 | |
18 #if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB) | |
19 #error "Only compile the allocator proxy with the shared_library implementation" | |
20 #endif | |
21 | |
22 #if defined(OS_WIN) | |
23 #define ALLOC_EXPORT __declspec(dllexport) | |
24 #else | |
25 #define ALLOC_EXPORT __attribute__((visibility("default"))) | |
26 #endif | |
27 | |
28 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | |
29 // These are used by our new/delete overrides in | |
30 // allocator_shim/allocator_proxy.cc | |
31 AllocateFunction g_alloc = NULL; | |
32 DellocateFunction g_dealloc = NULL; | |
33 #endif | |
34 | |
35 // Forward declare of the libjingle internal factory and destroy methods for the | |
36 // WebRTC media engine. | |
37 cricket::MediaEngineInterface* CreateWebRtcMediaEngine( | |
38 webrtc::AudioDeviceModule* adm, | |
39 webrtc::AudioDeviceModule* adm_sc, | |
40 cricket::WebRtcVideoEncoderFactory* encoder_factory, | |
41 cricket::WebRtcVideoDecoderFactory* decoder_factory); | |
42 | |
43 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine); | |
44 | |
45 namespace { | |
46 // Provide webrtc with a field trial and metrics implementations. | |
47 // The implementations are provided by the loader via the InitializeModule. | |
48 | |
49 // Defines webrtc::field_trial::FindFullName. | |
50 FieldTrialFindFullName g_field_trial_find_ = NULL; | |
51 // Defines webrtc::metrics::RtcFactoryGetCounts. | |
52 RtcHistogramFactoryGetCounts g_factory_get_counts = NULL; | |
53 // Defines webrtc::metrics::RtcFactoryGetEnumeration. | |
54 RtcHistogramFactoryGetEnumeration g_factory_get_enumeration = NULL; | |
55 // Defines webrtc::metrics::RtcAdd. | |
56 RtcHistogramAdd g_histogram_add = NULL; | |
57 } | |
58 | |
59 namespace webrtc { | |
60 namespace field_trial { | |
61 std::string FindFullName(const std::string& trial_name) { | |
62 return g_field_trial_find_(trial_name); | |
63 } | |
64 } // namespace field_trial | |
65 | |
66 namespace metrics { | |
67 Histogram* HistogramFactoryGetCounts( | |
68 const std::string& name, int min, int max, int bucket_count) { | |
69 return g_factory_get_counts(name, min, max, bucket_count); | |
70 } | |
71 | |
72 Histogram* HistogramFactoryGetEnumeration( | |
73 const std::string& name, int boundary) { | |
74 return g_factory_get_enumeration(name, boundary); | |
75 } | |
76 | |
77 void HistogramAdd( | |
78 Histogram* histogram_pointer, const std::string& name, int sample) { | |
79 g_histogram_add(histogram_pointer, name, sample); | |
80 } | |
81 } // namespace metrics | |
82 } // namespace webrtc | |
83 | |
84 extern "C" { | |
85 | |
86 // Initialize logging, set the forward allocator functions (not on mac), and | |
87 // return pointers to libjingle's WebRTC factory methods. | |
88 // Called from init_webrtc.cc. | |
89 ALLOC_EXPORT | |
90 bool InitializeModule(const base::CommandLine& command_line, | |
91 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | |
92 AllocateFunction alloc, | |
93 DellocateFunction dealloc, | |
94 #endif | |
95 FieldTrialFindFullName field_trial_find, | |
96 RtcHistogramFactoryGetCounts factory_get_counts, | |
97 RtcHistogramFactoryGetEnumeration factory_get_enumeration, | |
98 RtcHistogramAdd histogram_add, | |
99 logging::LogMessageHandlerFunction log_handler, | |
100 webrtc::GetCategoryEnabledPtr trace_get_category_enabled, | |
101 webrtc::AddTraceEventPtr trace_add_trace_event, | |
102 CreateWebRtcMediaEngineFunction* create_media_engine, | |
103 DestroyWebRtcMediaEngineFunction* destroy_media_engine, | |
104 InitDiagnosticLoggingDelegateFunctionFunction* | |
105 init_diagnostic_logging) { | |
106 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | |
107 g_alloc = alloc; | |
108 g_dealloc = dealloc; | |
109 #endif | |
110 | |
111 g_field_trial_find_ = field_trial_find; | |
112 g_factory_get_counts = factory_get_counts; | |
113 g_factory_get_enumeration = factory_get_enumeration; | |
114 g_histogram_add = histogram_add; | |
115 | |
116 *create_media_engine = &CreateWebRtcMediaEngine; | |
117 *destroy_media_engine = &DestroyWebRtcMediaEngine; | |
118 *init_diagnostic_logging = &rtc::InitDiagnosticLoggingDelegateFunction; | |
119 | |
120 #if defined(OS_WIN) && defined(ARCH_CPU_X86_64) | |
121 // VS2013 only checks the existence of FMA3 instructions, not the enabled-ness | |
122 // of them at the OS level (this is fixed in VS2015). We force off usage of | |
123 // FMA3 instructions in the CRT to avoid using that path and hitting illegal | |
124 // instructions when running on CPUs that support FMA3, but OSs that don't. | |
125 // See http://crbug.com/436603 and http://crbug.com/446983. | |
126 _set_FMA3_enable(0); | |
127 #endif // WIN && ARCH_CPU_X86_64 | |
128 | |
129 if (base::CommandLine::Init(0, NULL)) { | |
130 #if !defined(OS_WIN) | |
131 // This is not needed on Windows since CommandLine::Init has already | |
132 // done the equivalent thing via the GetCommandLine() API. | |
133 base::CommandLine::ForCurrentProcess()->AppendArguments(command_line, true); | |
134 #endif | |
135 logging::LoggingSettings settings; | |
136 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
137 logging::InitLogging(settings); | |
138 | |
139 // Override the log message handler to forward logs to chrome's handler. | |
140 logging::SetLogMessageHandler(log_handler); | |
141 webrtc::SetupEventTracer(trace_get_category_enabled, | |
142 trace_add_trace_event); | |
143 } | |
144 | |
145 return true; | |
146 } | |
147 } // extern "C" | |
OLD | NEW |