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 |
54 bool InitializeWebRtcModule() { | 69 bool InitializeWebRtcModule() { |
55 if (g_create_webrtc_media_engine) | 70 if (g_create_webrtc_media_engine) |
56 return true; // InitializeWebRtcModule has already been called. | 71 return true; // InitializeWebRtcModule has already been called. |
57 | 72 |
58 base::FilePath path(GetLibPeerConnectionPath()); | 73 base::FilePath path(GetLibPeerConnectionPath()); |
59 DVLOG(1) << "Loading WebRTC module: " << path.value(); | 74 DVLOG(1) << "Loading WebRTC module: " << path.value(); |
60 | 75 |
61 std::string error; | 76 std::string error; |
62 static base::NativeLibrary lib = | 77 static base::NativeLibrary lib = |
63 base::LoadNativeLibrary(path, &error); | 78 base::LoadNativeLibrary(path, &error); |
| 79 #if !defined(OS_WIN) |
| 80 if (!lib) |
| 81 lib = base::LoadNativeLibrary(GetLibPeerConnectionPathForTests(), &error); |
| 82 #endif |
64 CHECK(lib); | 83 CHECK(lib); |
65 | 84 |
66 InitializeModuleFunction initialize_module = | 85 InitializeModuleFunction initialize_module = |
67 reinterpret_cast<InitializeModuleFunction>( | 86 reinterpret_cast<InitializeModuleFunction>( |
68 base::GetFunctionPointerFromNativeLibrary( | 87 base::GetFunctionPointerFromNativeLibrary( |
69 lib, "InitializeModule")); | 88 lib, "InitializeModule")); |
70 | 89 |
71 // Initialize the proxy by supplying it with a pointer to our | 90 // Initialize the proxy by supplying it with a pointer to our |
72 // allocator/deallocator routines. | 91 // allocator/deallocator routines. |
73 // On mac we use malloc zones, which are global, so we provide NULLs for | 92 // On mac we use malloc zones, which are global, so we provide NULLs for |
(...skipping 17 matching lines...) Expand all Loading... |
91 // effectively a noop. | 110 // effectively a noop. |
92 InitializeWebRtcModule(); | 111 InitializeWebRtcModule(); |
93 return g_create_webrtc_media_engine(adm, adm_sc, decoder_factory); | 112 return g_create_webrtc_media_engine(adm, adm_sc, decoder_factory); |
94 } | 113 } |
95 | 114 |
96 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { | 115 void DestroyWebRtcMediaEngine(cricket::MediaEngineInterface* media_engine) { |
97 g_destroy_webrtc_media_engine(media_engine); | 116 g_destroy_webrtc_media_engine(media_engine); |
98 } | 117 } |
99 | 118 |
100 #endif // LIBPEERCONNECTION_LIB | 119 #endif // LIBPEERCONNECTION_LIB |
OLD | NEW |