src/java.desktop/share/classes/com/sun/media/sound/Platform.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  47     private static final String libNameALSA     = "jsoundalsa";
  48     private static final String libNameDSound   = "jsoundds";
  49 
  50     // extra libs handling: bit flags for each different library
  51     public static final int LIB_MAIN     = 1;
  52     public static final int LIB_ALSA     = 2;
  53     public static final int LIB_DSOUND   = 4;
  54 
  55     // bit field of the constants above. Willbe set in loadLibraries
  56     private static int loadedLibs = 0;
  57 
  58     // features: the main native library jsound reports which feature is
  59     // contained in which lib
  60     public static final int FEATURE_MIDIIO       = 1;
  61     public static final int FEATURE_PORTS        = 2;
  62     public static final int FEATURE_DIRECT_AUDIO = 3;
  63 
  64     // SYSTEM CHARACTERISTICS
  65     // vary according to hardware architecture
  66 
  67     // signed8 (use signed 8-bit values) is true for everything we support except for
  68     // the solaris sbpro card.
  69     // we'll leave it here as a variable; in the future we may need this in java.
  70     // wait, is that true?  i'm not sure.  i think solaris takes unsigned data?
  71     // $$kk: 03.11.99: i think solaris takes unsigned 8-bit or signed 16-bit data....
  72     private static boolean signed8;
  73 
  74     // intel is little-endian.  sparc is big-endian.
  75     private static boolean bigEndian;
  76 
  77     static {
  78         if(Printer.trace)Printer.trace(">> Platform.java: static");
  79 
  80         loadLibraries();
  81         readProperties();
  82     }
  83 
  84 
  85     /**
  86      * Private constructor.
  87      */
  88     private Platform() {
  89     }
  90 
  91 
  92     // METHODS FOR INTERNAL IMPLEMENTATION USE
  93 
  94 
  95     /**
  96      * Dummy method for forcing initialization.
  97      */
  98     static void initialize() {
  99 
 100         if(Printer.trace)Printer.trace("Platform: initialize()");
 101     }
 102 
 103 
 104     /**
 105      * Determine whether the system is big-endian.
 106      */
 107     static boolean isBigEndian() {
 108 
 109         return bigEndian;
 110     }
 111 
 112 
 113     /**
 114      * Determine whether the system takes signed 8-bit data.
 115      */
 116     static boolean isSigned8() {
 117 
 118         return signed8;
 119     }
 120 
 121     // PRIVATE METHODS
 122 
 123     /**
 124      * Load the native library or libraries.
 125      */
 126     private static void loadLibraries() {
 127         if(Printer.trace)Printer.trace(">>Platform.loadLibraries");
 128 
 129         // load the main library
 130         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 131             System.loadLibrary(libNameMain);
 132             return null;
 133         });
 134         // just for the heck of it...
 135         loadedLibs |= LIB_MAIN;
 136 
 137         // now try to load extra libs. They are defined at compile time in the Makefile
 138         // with the define EXTRA_SOUND_JNI_LIBS
 139         String extraLibs = nGetExtraLibraries();
 140         // the string is the libraries, separated by white space


 168     }
 169 
 170     static boolean isPortsEnabled() {
 171         return isFeatureLibLoaded(FEATURE_PORTS);
 172     }
 173 
 174     static boolean isDirectAudioEnabled() {
 175         return isFeatureLibLoaded(FEATURE_DIRECT_AUDIO);
 176     }
 177 
 178     private static boolean isFeatureLibLoaded(int feature) {
 179         if (Printer.debug) Printer.debug("Platform: Checking for feature "+feature+"...");
 180         int requiredLib = nGetLibraryForFeature(feature);
 181         boolean isLoaded = (requiredLib != 0) && ((loadedLibs & requiredLib) == requiredLib);
 182         if (Printer.debug) Printer.debug("          ...needs library "+requiredLib+". Result is loaded="+isLoaded);
 183         return isLoaded;
 184     }
 185 
 186     // the following native methods are implemented in Platform.c
 187     private native static boolean nIsBigEndian();
 188     private native static boolean nIsSigned8();
 189     private native static String nGetExtraLibraries();
 190     private native static int nGetLibraryForFeature(int feature);
 191 
 192 
 193     /**
 194      * Read the required system properties.
 195      */
 196     private static void readProperties() {
 197         // $$fb 2002-03-06: implement check for endianness in native. Facilitates porting !
 198         bigEndian = nIsBigEndian();
 199         signed8 = nIsSigned8(); // Solaris on Sparc: signed, all others unsigned
 200     }
 201 }
   1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  47     private static final String libNameALSA     = "jsoundalsa";
  48     private static final String libNameDSound   = "jsoundds";
  49 
  50     // extra libs handling: bit flags for each different library
  51     public static final int LIB_MAIN     = 1;
  52     public static final int LIB_ALSA     = 2;
  53     public static final int LIB_DSOUND   = 4;
  54 
  55     // bit field of the constants above. Willbe set in loadLibraries
  56     private static int loadedLibs = 0;
  57 
  58     // features: the main native library jsound reports which feature is
  59     // contained in which lib
  60     public static final int FEATURE_MIDIIO       = 1;
  61     public static final int FEATURE_PORTS        = 2;
  62     public static final int FEATURE_DIRECT_AUDIO = 3;
  63 
  64     // SYSTEM CHARACTERISTICS
  65     // vary according to hardware architecture
  66 







  67     // intel is little-endian.  sparc is big-endian.
  68     private static boolean bigEndian;
  69 
  70     static {
  71         if(Printer.trace)Printer.trace(">> Platform.java: static");
  72 
  73         loadLibraries();
  74         readProperties();
  75     }
  76 
  77 
  78     /**
  79      * Private constructor.
  80      */
  81     private Platform() {
  82     }
  83 
  84 
  85     // METHODS FOR INTERNAL IMPLEMENTATION USE
  86 
  87 
  88     /**
  89      * Dummy method for forcing initialization.
  90      */
  91     static void initialize() {
  92 
  93         if(Printer.trace)Printer.trace("Platform: initialize()");
  94     }
  95 
  96 
  97     /**
  98      * Determine whether the system is big-endian.
  99      */
 100     static boolean isBigEndian() {
 101 
 102         return bigEndian;
 103     }
 104 
 105 








 106     // PRIVATE METHODS
 107 
 108     /**
 109      * Load the native library or libraries.
 110      */
 111     private static void loadLibraries() {
 112         if(Printer.trace)Printer.trace(">>Platform.loadLibraries");
 113 
 114         // load the main library
 115         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 116             System.loadLibrary(libNameMain);
 117             return null;
 118         });
 119         // just for the heck of it...
 120         loadedLibs |= LIB_MAIN;
 121 
 122         // now try to load extra libs. They are defined at compile time in the Makefile
 123         // with the define EXTRA_SOUND_JNI_LIBS
 124         String extraLibs = nGetExtraLibraries();
 125         // the string is the libraries, separated by white space


 153     }
 154 
 155     static boolean isPortsEnabled() {
 156         return isFeatureLibLoaded(FEATURE_PORTS);
 157     }
 158 
 159     static boolean isDirectAudioEnabled() {
 160         return isFeatureLibLoaded(FEATURE_DIRECT_AUDIO);
 161     }
 162 
 163     private static boolean isFeatureLibLoaded(int feature) {
 164         if (Printer.debug) Printer.debug("Platform: Checking for feature "+feature+"...");
 165         int requiredLib = nGetLibraryForFeature(feature);
 166         boolean isLoaded = (requiredLib != 0) && ((loadedLibs & requiredLib) == requiredLib);
 167         if (Printer.debug) Printer.debug("          ...needs library "+requiredLib+". Result is loaded="+isLoaded);
 168         return isLoaded;
 169     }
 170 
 171     // the following native methods are implemented in Platform.c
 172     private native static boolean nIsBigEndian();

 173     private native static String nGetExtraLibraries();
 174     private native static int nGetLibraryForFeature(int feature);
 175 

 176     /**
 177      * Read the required system properties.
 178      */
 179     private static void readProperties() {
 180         // $$fb 2002-03-06: implement check for endianness in native. Facilitates porting !
 181         bigEndian = nIsBigEndian();

 182     }
 183 }