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/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/native_library.h" | 10 #include "base/native_library.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 .Append(FILE_PATH_LITERAL("libpeerconnection.so")); | 44 .Append(FILE_PATH_LITERAL("libpeerconnection.so")); |
45 #else | 45 #else |
46 base::FilePath path; | 46 base::FilePath path; |
47 CHECK(PathService::Get(base::DIR_MODULE, &path)); | 47 CHECK(PathService::Get(base::DIR_MODULE, &path)); |
48 path = path.Append(FILE_PATH_LITERAL("lib")) | 48 path = path.Append(FILE_PATH_LITERAL("lib")) |
49 .Append(FILE_PATH_LITERAL("libpeerconnection.so")); | 49 .Append(FILE_PATH_LITERAL("libpeerconnection.so")); |
50 #endif | 50 #endif |
51 return path; | 51 return path; |
52 } | 52 } |
53 | 53 |
54 #if !defined(OS_WIN) | |
55 // On platforms other than Windows (i.e. mac and linux based ones), | |
56 // the location of the .so in the installed layout will be different relative | |
57 // to the loading module than it is in the build directory. | |
58 // GetLibPeerConnectionPath returns the path as it will be in the installed | |
59 // layout, but to support isolated tests, we need to also support loading the | |
60 // so in the build layout, which we do here. | |
61 // On Windows, these layouts are the same. | |
62 static base::FilePath GetLibPeerConnectionPathForTests() { | |
63 base::FilePath path; | |
64 CHECK(PathService::Get(base::DIR_MODULE, &path)); | |
65 return path.Append(FILE_PATH_LITERAL("libpeerconnection.so")); | |
66 } | |
67 #endif | |
68 | |
69 bool InitializeWebRtcModule() { | 54 bool InitializeWebRtcModule() { |
70 if (g_create_webrtc_media_engine) | 55 if (g_create_webrtc_media_engine) |
71 return true; // InitializeWebRtcModule has already been called. | 56 return true; // InitializeWebRtcModule has already been called. |
72 | 57 |
73 base::FilePath path(GetLibPeerConnectionPath()); | 58 base::FilePath path(GetLibPeerConnectionPath()); |
74 DVLOG(1) << "Loading WebRTC module: " << path.value(); | 59 DVLOG(1) << "Loading WebRTC module: " << path.value(); |
75 | 60 |
76 std::string error; | 61 std::string error; |
77 static base::NativeLibrary lib = | 62 static base::NativeLibrary lib = |
78 base::LoadNativeLibrary(path, &error); | 63 base::LoadNativeLibrary(path, &error); |
79 #if !defined(OS_WIN) | |
80 if (!lib) | |
81 lib = base::LoadNativeLibrary(GetLibPeerConnectionPathForTests(), &error); | |
82 #endif | |
83 CHECK(lib); | 64 CHECK(lib); |
84 | 65 |
85 InitializeModuleFunction initialize_module = | 66 InitializeModuleFunction initialize_module = |
86 reinterpret_cast<InitializeModuleFunction>( | 67 reinterpret_cast<InitializeModuleFunction>( |
87 base::GetFunctionPointerFromNativeLibrary( | 68 base::GetFunctionPointerFromNativeLibrary( |
88 lib, "InitializeModule")); | 69 lib, "InitializeModule")); |
89 | 70 |
90 // Initialize the proxy by supplying it with a pointer to our | 71 // Initialize the proxy by supplying it with a pointer to our |
91 // allocator/deallocator routines. | 72 // allocator/deallocator routines. |
92 // On mac we use malloc zones, which are global, so we provide NULLs for | 73 // On mac we use malloc zones, which are global, so we provide NULLs for |
(...skipping 17 matching lines...) Expand all Loading... |
110 // effectively a noop. | 91 // effectively a noop. |
111 InitializeWebRtcModule(); | 92 InitializeWebRtcModule(); |
112 return g_create_webrtc_media_engine(adm, adm_sc, decoder_factory); | 93 return g_create_webrtc_media_engine(adm, adm_sc, decoder_factory); |
113 } | 94 } |
114 | 95 |
115 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { | 96 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { |
116 g_destroy_webrtc_media_engine(media_engine); | 97 g_destroy_webrtc_media_engine(media_engine); |
117 } | 98 } |
118 | 99 |
119 #endif // LIBPEERCONNECTION_LIB | 100 #endif // LIBPEERCONNECTION_LIB |
OLD | NEW |