1 /* 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 package org.webrtc; 12 13 class NativeLibrary { 14 private static String TAG = "NativeLibrary"; 15 16 static class DefaultLoader implements NativeLibraryLoader { 17 @Override load(String name)18 public boolean load(String name) { 19 Logging.d(TAG, "Loading library: " + name); 20 System.loadLibrary(name); 21 22 // Not relevant, but kept for API compatibility. 23 return true; 24 } 25 } 26 27 private static Object lock = new Object(); 28 private static boolean libraryLoaded; 29 30 /** 31 * Loads the native library. Clients should call PeerConnectionFactory.initialize. It will call 32 * this method for them. 33 */ initialize(NativeLibraryLoader loader, String libraryName)34 static void initialize(NativeLibraryLoader loader, String libraryName) { 35 synchronized (lock) { 36 if (libraryLoaded) { 37 Logging.d(TAG, "Native library has already been loaded."); 38 return; 39 } 40 Logging.d(TAG, "Loading native library: " + libraryName); 41 libraryLoaded = loader.load(libraryName); 42 } 43 } 44 45 /** Returns true if the library has been loaded successfully. */ isLoaded()46 static boolean isLoaded() { 47 synchronized (lock) { 48 return libraryLoaded; 49 } 50 } 51 } 52