author | darcy |
Mon, 05 May 2014 23:19:00 -0700 | |
changeset 24548 | 9c007a986347 |
parent 18215 | b2afd66ce6db |
child 26030 | 576ffa819e23 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
18215 | 2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package com.sun.media.sound; |
|
27 |
||
18215 | 28 |
import java.security.AccessController; |
29 |
import java.security.PrivilegedAction; |
|
2 | 30 |
import java.util.StringTokenizer; |
31 |
||
32 |
||
33 |
||
34 |
/** |
|
35 |
* Audio configuration class for exposing attributes specific to the platform or system. |
|
36 |
* |
|
37 |
* @author Kara Kytle |
|
38 |
* @author Florian Bomers |
|
39 |
*/ |
|
18215 | 40 |
final class Platform { |
2 | 41 |
|
42 |
||
43 |
// STATIC FINAL CHARACTERISTICS |
|
44 |
||
45 |
// native library we need to load |
|
46 |
private static final String libNameMain = "jsound"; |
|
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 |
// this is the value of the "java.home" system property. i am looking it up here |
|
78 |
// for use when trying to load the soundbank, just so |
|
79 |
// that all the privileged code is localized in this file.... |
|
80 |
private static String javahome; |
|
81 |
||
82 |
// this is the value of the "java.class.path" system property |
|
83 |
private static String classpath; |
|
84 |
||
85 |
||
86 |
||
87 |
||
88 |
static { |
|
89 |
if(Printer.trace)Printer.trace(">> Platform.java: static"); |
|
90 |
||
91 |
loadLibraries(); |
|
92 |
readProperties(); |
|
93 |
} |
|
94 |
||
95 |
||
96 |
/** |
|
97 |
* Private constructor. |
|
98 |
*/ |
|
99 |
private Platform() { |
|
100 |
} |
|
101 |
||
102 |
||
103 |
// METHODS FOR INTERNAL IMPLEMENTATION USE |
|
104 |
||
105 |
||
106 |
/** |
|
107 |
* Dummy method for forcing initialization. |
|
108 |
*/ |
|
109 |
static void initialize() { |
|
110 |
||
111 |
if(Printer.trace)Printer.trace("Platform: initialize()"); |
|
112 |
} |
|
113 |
||
114 |
||
115 |
/** |
|
116 |
* Determine whether the system is big-endian. |
|
117 |
*/ |
|
118 |
static boolean isBigEndian() { |
|
119 |
||
120 |
return bigEndian; |
|
121 |
} |
|
122 |
||
123 |
||
124 |
/** |
|
125 |
* Determine whether the system takes signed 8-bit data. |
|
126 |
*/ |
|
127 |
static boolean isSigned8() { |
|
128 |
||
129 |
return signed8; |
|
130 |
} |
|
131 |
||
132 |
||
133 |
/** |
|
134 |
* Obtain javahome. |
|
135 |
* $$kk: 04.16.99: this is *bad*!! |
|
136 |
*/ |
|
137 |
static String getJavahome() { |
|
138 |
||
139 |
return javahome; |
|
140 |
} |
|
141 |
||
142 |
/** |
|
143 |
* Obtain classpath. |
|
144 |
* $$jb: 04.21.99: this is *bad* too!! |
|
145 |
*/ |
|
146 |
static String getClasspath() { |
|
147 |
||
148 |
return classpath; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
// PRIVATE METHODS |
|
153 |
||
154 |
/** |
|
155 |
* Load the native library or libraries. |
|
156 |
*/ |
|
157 |
private static void loadLibraries() { |
|
158 |
if(Printer.trace)Printer.trace(">>Platform.loadLibraries"); |
|
159 |
||
160 |
try { |
|
1846
4a53d636e2f4
6702956: OpenJDK: replace encumbered code (software synthesizer)
amenkov
parents:
2
diff
changeset
|
161 |
// load the main library |
18215 | 162 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
163 |
@Override |
|
164 |
public Void run() { |
|
165 |
System.loadLibrary(libNameMain); |
|
166 |
return null; |
|
167 |
} |
|
168 |
}); |
|
2 | 169 |
// just for the heck of it... |
170 |
loadedLibs |= LIB_MAIN; |
|
171 |
} catch (SecurityException e) { |
|
172 |
if(Printer.err)Printer.err("Security exception loading main native library. JavaSound requires access to these resources."); |
|
173 |
throw(e); |
|
174 |
} |
|
175 |
||
176 |
// now try to load extra libs. They are defined at compile time in the Makefile |
|
177 |
// with the define EXTRA_SOUND_JNI_LIBS |
|
178 |
String extraLibs = nGetExtraLibraries(); |
|
179 |
// the string is the libraries, separated by white space |
|
180 |
StringTokenizer st = new StringTokenizer(extraLibs); |
|
181 |
while (st.hasMoreTokens()) { |
|
18215 | 182 |
final String lib = st.nextToken(); |
2 | 183 |
try { |
18215 | 184 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
185 |
@Override |
|
186 |
public Void run() { |
|
187 |
System.loadLibrary(lib); |
|
188 |
return null; |
|
189 |
} |
|
190 |
}); |
|
191 |
||
2 | 192 |
if (lib.equals(libNameALSA)) { |
193 |
loadedLibs |= LIB_ALSA; |
|
194 |
if (Printer.debug) Printer.debug("Loaded ALSA lib successfully."); |
|
195 |
} else if (lib.equals(libNameDSound)) { |
|
196 |
loadedLibs |= LIB_DSOUND; |
|
197 |
if (Printer.debug) Printer.debug("Loaded DirectSound lib successfully."); |
|
198 |
} else { |
|
199 |
if (Printer.err) Printer.err("Loaded unknown lib '"+lib+"' successfully."); |
|
200 |
} |
|
201 |
} catch (Throwable t) { |
|
202 |
if (Printer.err) Printer.err("Couldn't load library "+lib+": "+t.toString()); |
|
203 |
} |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
||
208 |
static boolean isMidiIOEnabled() { |
|
209 |
return isFeatureLibLoaded(FEATURE_MIDIIO); |
|
210 |
} |
|
211 |
||
212 |
static boolean isPortsEnabled() { |
|
213 |
return isFeatureLibLoaded(FEATURE_PORTS); |
|
214 |
} |
|
215 |
||
216 |
static boolean isDirectAudioEnabled() { |
|
217 |
return isFeatureLibLoaded(FEATURE_DIRECT_AUDIO); |
|
218 |
} |
|
219 |
||
220 |
private static boolean isFeatureLibLoaded(int feature) { |
|
221 |
if (Printer.debug) Printer.debug("Platform: Checking for feature "+feature+"..."); |
|
222 |
int requiredLib = nGetLibraryForFeature(feature); |
|
223 |
boolean isLoaded = (requiredLib != 0) && ((loadedLibs & requiredLib) == requiredLib); |
|
224 |
if (Printer.debug) Printer.debug(" ...needs library "+requiredLib+". Result is loaded="+isLoaded); |
|
225 |
return isLoaded; |
|
226 |
} |
|
227 |
||
228 |
// the following native methods are implemented in Platform.c |
|
229 |
private native static boolean nIsBigEndian(); |
|
230 |
private native static boolean nIsSigned8(); |
|
231 |
private native static String nGetExtraLibraries(); |
|
232 |
private native static int nGetLibraryForFeature(int feature); |
|
233 |
||
234 |
||
235 |
/** |
|
236 |
* Read the required system properties. |
|
237 |
*/ |
|
238 |
private static void readProperties() { |
|
239 |
// $$fb 2002-03-06: implement check for endianness in native. Facilitates porting ! |
|
240 |
bigEndian = nIsBigEndian(); |
|
241 |
signed8 = nIsSigned8(); // Solaris on Sparc: signed, all others unsigned |
|
242 |
javahome = JSSecurityManager.getProperty("java.home"); |
|
243 |
classpath = JSSecurityManager.getProperty("java.class.path"); |
|
244 |
} |
|
245 |
} |