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.
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"
15 #if !defined(LIBPEERCONNECTION_IMPLEMENTATION) || defined(LIBPEERCONNECTION_LIB)
16 #error "Only compile the allocator proxy with the shared_library implementation"
20 #define ALLOC_EXPORT __declspec(dllexport)
22 #define ALLOC_EXPORT __attribute__((visibility("default")))
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
;
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
);
40 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface
* media_engine
);
43 // Provide webrtc with a field trial and metrics implementations.
44 // The implementations are provided by the loader via the InitializeModule.
46 // Defines webrtc::field_trial::FindFullName.
47 FieldTrialFindFullName g_field_trial_find_
= NULL
;
48 // Defines webrtc::metrics::RtcFactoryGetCounts.
49 RtcHistogramFactoryGetCounts g_factory_get_counts
= NULL
;
50 // Defines webrtc::metrics::RtcFactoryGetEnumeration.
51 RtcHistogramFactoryGetEnumeration g_factory_get_enumeration
= NULL
;
52 // Defines webrtc::metrics::RtcAdd.
53 RtcHistogramAdd g_histogram_add
= NULL
;
57 namespace field_trial
{
58 std::string
FindFullName(const std::string
& trial_name
) {
59 return g_field_trial_find_(trial_name
);
61 } // namespace field_trial
64 Histogram
* HistogramFactoryGetCounts(
65 const std::string
& name
, int min
, int max
, int bucket_count
) {
66 return g_factory_get_counts(name
, min
, max
, bucket_count
);
69 Histogram
* HistogramFactoryGetEnumeration(
70 const std::string
& name
, int boundary
) {
71 return g_factory_get_enumeration(name
, boundary
);
75 Histogram
* histogram_pointer
, const std::string
& name
, int sample
) {
76 g_histogram_add(histogram_pointer
, name
, sample
);
78 } // namespace metrics
83 // Initialize logging, set the forward allocator functions (not on mac), and
84 // return pointers to libjingle's WebRTC factory methods.
85 // Called from init_webrtc.cc.
87 bool InitializeModule(const CommandLine
& command_line
,
88 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
89 AllocateFunction alloc
,
90 DellocateFunction dealloc
,
92 FieldTrialFindFullName field_trial_find
,
93 RtcHistogramFactoryGetCounts factory_get_counts
,
94 RtcHistogramFactoryGetEnumeration factory_get_enumeration
,
95 RtcHistogramAdd histogram_add
,
96 logging::LogMessageHandlerFunction log_handler
,
97 webrtc::GetCategoryEnabledPtr trace_get_category_enabled
,
98 webrtc::AddTraceEventPtr trace_add_trace_event
,
99 CreateWebRtcMediaEngineFunction
* create_media_engine
,
100 DestroyWebRtcMediaEngineFunction
* destroy_media_engine
,
101 InitDiagnosticLoggingDelegateFunctionFunction
*
102 init_diagnostic_logging
,
103 CreateWebRtcAudioProcessingFunction
*
104 create_audio_processing
) {
105 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
110 g_field_trial_find_
= field_trial_find
;
111 g_factory_get_counts
= factory_get_counts
;
112 g_factory_get_enumeration
= factory_get_enumeration
;
113 g_histogram_add
= histogram_add
;
115 *create_media_engine
= &CreateWebRtcMediaEngine
;
116 *destroy_media_engine
= &DestroyWebRtcMediaEngine
;
117 *init_diagnostic_logging
= &rtc::InitDiagnosticLoggingDelegateFunction
;
118 *create_audio_processing
= &webrtc::AudioProcessing::Create
;
120 if (CommandLine::Init(0, NULL
)) {
122 // This is not needed on Windows since CommandLine::Init has already
123 // done the equivalent thing via the GetCommandLine() API.
124 CommandLine::ForCurrentProcess()->AppendArguments(command_line
, true);
126 logging::LoggingSettings settings
;
127 settings
.logging_dest
= logging::LOG_TO_SYSTEM_DEBUG_LOG
;
128 logging::InitLogging(settings
);
130 // Override the log message handler to forward logs to chrome's handler.
131 logging::SetLogMessageHandler(log_handler
);
132 webrtc::SetupEventTracer(trace_get_category_enabled
,
133 trace_add_trace_event
);