OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "init_webrtc.h" | 5 #include "init_webrtc.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/metrics/histogram.h" |
12 #include "base/native_library.h" | 13 #include "base/native_library.h" |
13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
14 #include "webrtc/base/basictypes.h" | 15 #include "webrtc/base/basictypes.h" |
15 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
16 | 17 |
17 const unsigned char* GetCategoryGroupEnabled(const char* category_group) { | 18 const unsigned char* GetCategoryGroupEnabled(const char* category_group) { |
18 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); | 19 return TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(category_group); |
19 } | 20 } |
20 | 21 |
21 void AddTraceEvent(char phase, | 22 void AddTraceEvent(char phase, |
22 const unsigned char* category_group_enabled, | 23 const unsigned char* category_group_enabled, |
23 const char* name, | 24 const char* name, |
24 unsigned long long id, | 25 unsigned long long id, |
25 int num_args, | 26 int num_args, |
26 const char** arg_names, | 27 const char** arg_names, |
27 const unsigned char* arg_types, | 28 const unsigned char* arg_types, |
28 const unsigned long long* arg_values, | 29 const unsigned long long* arg_values, |
29 unsigned char flags) { | 30 unsigned char flags) { |
30 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id, | 31 TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name, id, |
31 num_args, arg_names, arg_types, arg_values, | 32 num_args, arg_names, arg_types, arg_values, |
32 NULL, flags); | 33 NULL, flags); |
33 } | 34 } |
34 | 35 |
35 // Define webrtc:field_trial::FindFullName to provide webrtc with a field trial | 36 namespace webrtc { |
| 37 // Define webrtc::field_trial::FindFullName to provide webrtc with a field trial |
36 // implementation. | 38 // implementation. |
37 namespace webrtc { | |
38 namespace field_trial { | 39 namespace field_trial { |
39 std::string FindFullName(const std::string& trial_name) { | 40 std::string FindFullName(const std::string& trial_name) { |
40 return base::FieldTrialList::FindFullName(trial_name); | 41 return base::FieldTrialList::FindFullName(trial_name); |
41 } | 42 } |
42 } // namespace field_trial | 43 } // namespace field_trial |
| 44 |
| 45 // Define webrtc::metrics functions to provide webrtc with implementations. |
| 46 namespace metrics { |
| 47 Histogram* HistogramFactoryGetCounts( |
| 48 const std::string& name, int min, int max, int bucket_count) { |
| 49 return reinterpret_cast<Histogram*>( |
| 50 base::Histogram::FactoryGet(name, min, max, bucket_count, |
| 51 base::HistogramBase::kUmaTargetedHistogramFlag)); |
| 52 } |
| 53 |
| 54 Histogram* HistogramFactoryGetEnumeration( |
| 55 const std::string& name, int boundary) { |
| 56 return reinterpret_cast<Histogram*>( |
| 57 base::LinearHistogram::FactoryGet(name, 1, boundary, boundary + 1, |
| 58 base::HistogramBase::kUmaTargetedHistogramFlag)); |
| 59 } |
| 60 |
| 61 void HistogramAdd( |
| 62 Histogram* histogram_pointer, const std::string& name, int sample) { |
| 63 base::HistogramBase* ptr = |
| 64 reinterpret_cast<base::HistogramBase*>(histogram_pointer); |
| 65 // The name should not vary. |
| 66 DCHECK(ptr->histogram_name() == name); |
| 67 ptr->Add(sample); |
| 68 } |
| 69 } // namespace metrics |
43 } // namespace webrtc | 70 } // namespace webrtc |
44 | 71 |
45 #if defined(LIBPEERCONNECTION_LIB) | 72 #if defined(LIBPEERCONNECTION_LIB) |
46 | 73 |
47 // libpeerconnection is being compiled as a static lib. In this case | 74 // libpeerconnection is being compiled as a static lib. In this case |
48 // we don't need to do any initializing but to keep things simple we | 75 // we don't need to do any initializing but to keep things simple we |
49 // provide an empty intialization routine so that this #ifdef doesn't | 76 // provide an empty intialization routine so that this #ifdef doesn't |
50 // have to be in other places. | 77 // have to be in other places. |
51 bool InitializeWebRtcModule() { | 78 bool InitializeWebRtcModule() { |
52 webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent); | 79 webrtc::SetupEventTracer(&GetCategoryGroupEnabled, &AddTraceEvent); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 146 |
120 // Initialize the proxy by supplying it with a pointer to our | 147 // Initialize the proxy by supplying it with a pointer to our |
121 // allocator/deallocator routines. | 148 // allocator/deallocator routines. |
122 // On mac we use malloc zones, which are global, so we provide NULLs for | 149 // On mac we use malloc zones, which are global, so we provide NULLs for |
123 // the alloc/dealloc functions. | 150 // the alloc/dealloc functions. |
124 // PS: This function is actually implemented in allocator_proxy.cc with the | 151 // PS: This function is actually implemented in allocator_proxy.cc with the |
125 // new/delete overrides. | 152 // new/delete overrides. |
126 InitDiagnosticLoggingDelegateFunctionFunction init_diagnostic_logging = NULL; | 153 InitDiagnosticLoggingDelegateFunctionFunction init_diagnostic_logging = NULL; |
127 bool init_ok = initialize_module(*CommandLine::ForCurrentProcess(), | 154 bool init_ok = initialize_module(*CommandLine::ForCurrentProcess(), |
128 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 155 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
129 &Allocate, | 156 &Allocate, |
130 &Dellocate, | 157 &Dellocate, |
131 #endif | 158 #endif |
132 &webrtc::field_trial::FindFullName, | 159 &webrtc::field_trial::FindFullName, |
133 logging::GetLogMessageHandler(), | 160 &webrtc::metrics::HistogramFactoryGetCounts, |
134 &GetCategoryGroupEnabled, | 161 &webrtc::metrics::HistogramFactoryGetEnumeration, |
135 &AddTraceEvent, | 162 &webrtc::metrics::HistogramAdd, |
136 &g_create_webrtc_media_engine, | 163 logging::GetLogMessageHandler(), |
137 &g_destroy_webrtc_media_engine, | 164 &GetCategoryGroupEnabled, |
138 &init_diagnostic_logging); | 165 &AddTraceEvent, |
| 166 &g_create_webrtc_media_engine, |
| 167 &g_destroy_webrtc_media_engine, |
| 168 &init_diagnostic_logging); |
139 | 169 |
140 if (init_ok) | 170 if (init_ok) |
141 rtc::SetExtraLoggingInit(init_diagnostic_logging); | 171 rtc::SetExtraLoggingInit(init_diagnostic_logging); |
142 return init_ok; | 172 return init_ok; |
143 } | 173 } |
144 | 174 |
145 cricket::MediaEngineInterface* CreateWebRtcMediaEngine( | 175 cricket::MediaEngineInterface* CreateWebRtcMediaEngine( |
146 webrtc::AudioDeviceModule* adm, | 176 webrtc::AudioDeviceModule* adm, |
147 webrtc::AudioDeviceModule* adm_sc, | 177 webrtc::AudioDeviceModule* adm_sc, |
148 cricket::WebRtcVideoEncoderFactory* encoder_factory, | 178 cricket::WebRtcVideoEncoderFactory* encoder_factory, |
149 cricket::WebRtcVideoDecoderFactory* decoder_factory) { | 179 cricket::WebRtcVideoDecoderFactory* decoder_factory) { |
150 // For convenience of tests etc, we call InitializeWebRtcModule here. | 180 // For convenience of tests etc, we call InitializeWebRtcModule here. |
151 // For Chrome however, InitializeWebRtcModule must be called | 181 // For Chrome however, InitializeWebRtcModule must be called |
152 // explicitly before the sandbox is initialized. In that case, this call is | 182 // explicitly before the sandbox is initialized. In that case, this call is |
153 // effectively a noop. | 183 // effectively a noop. |
154 InitializeWebRtcModule(); | 184 InitializeWebRtcModule(); |
155 return g_create_webrtc_media_engine(adm, adm_sc, encoder_factory, | 185 return g_create_webrtc_media_engine(adm, adm_sc, encoder_factory, |
156 decoder_factory); | 186 decoder_factory); |
157 } | 187 } |
158 | 188 |
159 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { | 189 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { |
160 g_destroy_webrtc_media_engine(media_engine); | 190 g_destroy_webrtc_media_engine(media_engine); |
161 } | 191 } |
162 | 192 |
163 #endif // LIBPEERCONNECTION_LIB | 193 #endif // LIBPEERCONNECTION_LIB |
OLD | NEW |