src/java.desktop/share/classes/com/sun/media/sound/Platform.java
changeset 49289 148e29df1644
parent 47216 71c04702a3d5
child 54860 1372fbbde8dd
--- a/src/java.desktop/share/classes/com/sun/media/sound/Platform.java	Fri Mar 23 09:26:59 2018 +0100
+++ b/src/java.desktop/share/classes/com/sun/media/sound/Platform.java	Fri Mar 23 09:51:02 2018 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,23 +38,9 @@
 final class Platform {
 
     // native library we need to load
-    private static final String libNameMain     = "jsound";
-    private static final String libNameALSA     = "jsoundalsa";
-    private static final String libNameDSound   = "jsoundds";
-
-    // extra libs handling: bit flags for each different library
-    public static final int LIB_MAIN     = 1;
-    public static final int LIB_ALSA     = 2;
-    public static final int LIB_DSOUND   = 4;
+    private static final String libName = "jsound";
 
-    // bit field of the constants above. Willbe set in loadLibraries
-    private static int loadedLibs = 0;
-
-    // features: the main native library jsound reports which feature is
-    // contained in which lib
-    public static final int FEATURE_MIDIIO       = 1;
-    public static final int FEATURE_PORTS        = 2;
-    public static final int FEATURE_DIRECT_AUDIO = 3;
+    private static boolean isNativeLibLoaded;
 
     // SYSTEM CHARACTERISTICS
     // vary according to hardware architecture
@@ -66,7 +52,6 @@
         if(Printer.trace)Printer.trace(">> Platform.java: static");
 
         loadLibraries();
-        readProperties();
     }
 
     /**
@@ -95,72 +80,37 @@
     private static void loadLibraries() {
         if(Printer.trace)Printer.trace(">>Platform.loadLibraries");
 
-        // load the main library
-        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
-            System.loadLibrary(libNameMain);
-            return null;
-        });
-        // just for the heck of it...
-        loadedLibs |= LIB_MAIN;
-
-        // now try to load extra libs. They are defined at compile time in the Makefile
-        // with the define EXTRA_SOUND_JNI_LIBS
-        String extraLibs = nGetExtraLibraries();
-        // the string is the libraries, separated by white space
-        StringTokenizer st = new StringTokenizer(extraLibs);
-        while (st.hasMoreTokens()) {
-            final String lib = st.nextToken();
-            try {
-                AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
-                    System.loadLibrary(lib);
-                    return null;
-                });
-
-                if (lib.equals(libNameALSA)) {
-                    loadedLibs |= LIB_ALSA;
-                    if (Printer.debug) Printer.debug("Loaded ALSA lib successfully.");
-                } else if (lib.equals(libNameDSound)) {
-                    loadedLibs |= LIB_DSOUND;
-                    if (Printer.debug) Printer.debug("Loaded DirectSound lib successfully.");
-                } else {
-                    if (Printer.err) Printer.err("Loaded unknown lib '"+lib+"' successfully.");
-                }
-            } catch (Throwable t) {
-                if (Printer.err) Printer.err("Couldn't load library "+lib+": "+t.toString());
-            }
+        // load the native library
+        isNativeLibLoaded = true;
+        try {
+            AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+                System.loadLibrary(libName);
+                return null;
+            });
+        } catch (Throwable t) {
+            if (Printer.err) Printer.err("Couldn't load library "+libName+": "+t.toString());
+            isNativeLibLoaded = false;
+        }
+        if (isNativeLibLoaded) {
+            bigEndian = nIsBigEndian();
         }
     }
 
     static boolean isMidiIOEnabled() {
-        return isFeatureLibLoaded(FEATURE_MIDIIO);
+        if (Printer.debug) Printer.debug("Platform: Checking for MidiIO; library is loaded=" + isNativeLibLoaded);
+        return isNativeLibLoaded;
     }
 
     static boolean isPortsEnabled() {
-        return isFeatureLibLoaded(FEATURE_PORTS);
+        if (Printer.debug) Printer.debug("Platform: Checking for Ports; library is loaded=" + isNativeLibLoaded);
+        return isNativeLibLoaded;
     }
 
     static boolean isDirectAudioEnabled() {
-        return isFeatureLibLoaded(FEATURE_DIRECT_AUDIO);
-    }
-
-    private static boolean isFeatureLibLoaded(int feature) {
-        if (Printer.debug) Printer.debug("Platform: Checking for feature "+feature+"...");
-        int requiredLib = nGetLibraryForFeature(feature);
-        boolean isLoaded = (requiredLib != 0) && ((loadedLibs & requiredLib) == requiredLib);
-        if (Printer.debug) Printer.debug("          ...needs library "+requiredLib+". Result is loaded="+isLoaded);
-        return isLoaded;
+        if (Printer.debug) Printer.debug("Platform: Checking for DirectAudio; library is loaded=" + isNativeLibLoaded);
+        return isNativeLibLoaded;
     }
 
-    // the following native methods are implemented in Platform.c
+    // the following native method is implemented in Platform.c
     private static native boolean nIsBigEndian();
-    private static native String nGetExtraLibraries();
-    private static native int nGetLibraryForFeature(int feature);
-
-    /**
-     * Read the required system properties.
-     */
-    private static void readProperties() {
-        // $$fb 2002-03-06: implement check for endianness in native. Facilitates porting !
-        bigEndian = nIsBigEndian();
-    }
 }