• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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       try {
21         System.loadLibrary(name);
22       } catch (UnsatisfiedLinkError e) {
23         Logging.e(TAG, "Failed to load native library: " + name, e);
24         return false;
25       }
26       return true;
27     }
28   }
29 
30   private static Object lock = new Object();
31   private static boolean libraryLoaded;
32 
33   /**
34    * Loads the native library. Clients should call PeerConnectionFactory.initialize. It will call
35    * this method for them.
36    */
initialize(NativeLibraryLoader loader, String libraryName)37   static void initialize(NativeLibraryLoader loader, String libraryName) {
38     synchronized (lock) {
39       if (libraryLoaded) {
40         Logging.d(TAG, "Native library has already been loaded.");
41         return;
42       }
43       Logging.d(TAG, "Loading native library: " + libraryName);
44       libraryLoaded = loader.load(libraryName);
45     }
46   }
47 
48   /** Returns true if the library has been loaded successfully. */
isLoaded()49   static boolean isLoaded() {
50     synchronized (lock) {
51       return libraryLoaded;
52     }
53   }
54 }
55