author | ihse |
Fri, 23 Mar 2018 09:51:02 +0100 | |
changeset 49289 | 148e29df1644 |
parent 47216 | 71c04702a3d5 |
child 54860 | 1372fbbde8dd |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1999, 2018, 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 |
* Audio configuration class for exposing attributes specific to the platform or system. |
|
34 |
* |
|
35 |
* @author Kara Kytle |
|
36 |
* @author Florian Bomers |
|
37 |
*/ |
|
18215 | 38 |
final class Platform { |
2 | 39 |
|
40 |
// native library we need to load |
|
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
41 |
private static final String libName = "jsound"; |
2 | 42 |
|
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
43 |
private static boolean isNativeLibLoaded; |
2 | 44 |
|
45 |
// SYSTEM CHARACTERISTICS |
|
46 |
// vary according to hardware architecture |
|
47 |
||
48 |
// intel is little-endian. sparc is big-endian. |
|
49 |
private static boolean bigEndian; |
|
50 |
||
51 |
static { |
|
52 |
if(Printer.trace)Printer.trace(">> Platform.java: static"); |
|
53 |
||
54 |
loadLibraries(); |
|
55 |
} |
|
56 |
||
57 |
/** |
|
58 |
* Private constructor. |
|
59 |
*/ |
|
60 |
private Platform() { |
|
61 |
} |
|
62 |
||
63 |
/** |
|
64 |
* Dummy method for forcing initialization. |
|
65 |
*/ |
|
66 |
static void initialize() { |
|
67 |
if(Printer.trace)Printer.trace("Platform: initialize()"); |
|
68 |
} |
|
69 |
||
70 |
/** |
|
71 |
* Determine whether the system is big-endian. |
|
72 |
*/ |
|
73 |
static boolean isBigEndian() { |
|
74 |
return bigEndian; |
|
75 |
} |
|
76 |
||
77 |
/** |
|
78 |
* Load the native library or libraries. |
|
79 |
*/ |
|
80 |
private static void loadLibraries() { |
|
81 |
if(Printer.trace)Printer.trace(">>Platform.loadLibraries"); |
|
82 |
||
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
83 |
// load the native library |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
84 |
isNativeLibLoaded = true; |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
85 |
try { |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
86 |
AccessController.doPrivileged((PrivilegedAction<Void>) () -> { |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
87 |
System.loadLibrary(libName); |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
88 |
return null; |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
89 |
}); |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
90 |
} catch (Throwable t) { |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
91 |
if (Printer.err) Printer.err("Couldn't load library "+libName+": "+t.toString()); |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
92 |
isNativeLibLoaded = false; |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
93 |
} |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
94 |
if (isNativeLibLoaded) { |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
95 |
bigEndian = nIsBigEndian(); |
2 | 96 |
} |
97 |
} |
|
98 |
||
99 |
static boolean isMidiIOEnabled() { |
|
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
100 |
if (Printer.debug) Printer.debug("Platform: Checking for MidiIO; library is loaded=" + isNativeLibLoaded); |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
101 |
return isNativeLibLoaded; |
2 | 102 |
} |
103 |
||
104 |
static boolean isPortsEnabled() { |
|
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
105 |
if (Printer.debug) Printer.debug("Platform: Checking for Ports; library is loaded=" + isNativeLibLoaded); |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
106 |
return isNativeLibLoaded; |
2 | 107 |
} |
108 |
||
109 |
static boolean isDirectAudioEnabled() { |
|
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
110 |
if (Printer.debug) Printer.debug("Platform: Checking for DirectAudio; library is loaded=" + isNativeLibLoaded); |
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
111 |
return isNativeLibLoaded; |
2 | 112 |
} |
113 |
||
49289
148e29df1644
8071469: Cleanup include and exclude of sound native libraries
ihse
parents:
47216
diff
changeset
|
114 |
// the following native method is implemented in Platform.c |
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
29261
diff
changeset
|
115 |
private static native boolean nIsBigEndian(); |
2 | 116 |
} |