OpenAL: Moved more library loading from native to java
This commit is contained in:
parent
5e98b4fda6
commit
7251a38930
|
@ -35,6 +35,9 @@ import java.io.File;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
import org.lwjgl.Sys;
|
import org.lwjgl.Sys;
|
||||||
|
|
||||||
|
@ -130,49 +133,49 @@ public final class AL {
|
||||||
|
|
||||||
private static String[] getOALPaths() throws LWJGLException {
|
private static String[] getOALPaths() throws LWJGLException {
|
||||||
// need to pass path of possible locations of OAL to native side
|
// need to pass path of possible locations of OAL to native side
|
||||||
String libpath = System.getProperty("java.library.path");
|
List possible_paths = new ArrayList();
|
||||||
String seperator = System.getProperty("path.separator");
|
|
||||||
String jwsLibname;
|
|
||||||
|
|
||||||
String osName = System.getProperty("os.name");
|
String osName = System.getProperty("os.name");
|
||||||
|
|
||||||
|
String libname;
|
||||||
if (osName.startsWith("Win")) {
|
if (osName.startsWith("Win")) {
|
||||||
jwsLibname = "lwjglaudio";
|
libname = "lwjglaudio";
|
||||||
} else if (osName.startsWith("Lin")) {
|
} else if (osName.startsWith("Lin")) {
|
||||||
jwsLibname = "openal";
|
libname = "openal";
|
||||||
} else if (osName.startsWith("Mac")) {
|
} else if (osName.startsWith("Mac")) {
|
||||||
jwsLibname = "openal";
|
libname = "openal";
|
||||||
} else {
|
} else {
|
||||||
throw new LWJGLException("Unknown platform: "+osName);
|
throw new LWJGLException("Unknown platform: "+osName);
|
||||||
}
|
}
|
||||||
|
|
||||||
String jwsPath = getPathFromClassLoader(jwsLibname);
|
String platform_lib_name = System.mapLibraryName(libname);
|
||||||
if (jwsPath != null) {
|
|
||||||
Sys.log("getPathFromClassLoader: Path found: " + jwsPath);
|
|
||||||
libpath += seperator
|
|
||||||
+ jwsPath.substring(0, jwsPath.lastIndexOf(File.separator));
|
|
||||||
}
|
|
||||||
String lwjgl_jws_path = getPathFromClassLoader("lwjgl");
|
|
||||||
if (lwjgl_jws_path != null) {
|
|
||||||
Sys.log("getPathFromClassLoader: Path found: " + lwjgl_jws_path);
|
|
||||||
libpath += seperator
|
|
||||||
+ lwjgl_jws_path.substring(0, lwjgl_jws_path.lastIndexOf(File.separator));
|
|
||||||
}
|
|
||||||
StringTokenizer st = new StringTokenizer(libpath, seperator);
|
|
||||||
|
|
||||||
//create needed string array
|
// Add all possible paths from java.library.path
|
||||||
String[] oalPaths = new String[st.countTokens() + 1];
|
String java_library_path = System.getProperty("java.library.path");
|
||||||
|
StringTokenizer st = new StringTokenizer(System.getProperty("java.library.path"), File.pathSeparator);
|
||||||
//build paths
|
while (st.hasMoreTokens()) {
|
||||||
for (int i = 0; i < oalPaths.length - 1; i++) {
|
String path = st.nextToken();
|
||||||
oalPaths[i] = st.nextToken() + File.separator;
|
possible_paths.add(path + File.separator + platform_lib_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i=0 ; i<oalPaths.length; i++) {
|
String classloader_path = getPathFromClassLoader(libname);
|
||||||
Sys.log("Will search " + oalPaths[i] + " for " + jwsLibname);
|
if (classloader_path != null) {
|
||||||
|
Sys.log("getPathFromClassLoader: Path found: " + classloader_path);
|
||||||
|
possible_paths.add(classloader_path);
|
||||||
|
}
|
||||||
|
String lwjgl_classloader_path = getPathFromClassLoader("lwjgl");
|
||||||
|
if (lwjgl_classloader_path != null) {
|
||||||
|
Sys.log("getPathFromClassLoader: Path found: " + lwjgl_classloader_path);
|
||||||
|
possible_paths.add(lwjgl_classloader_path.substring(0, lwjgl_classloader_path.lastIndexOf(File.separator))
|
||||||
|
+ File.separator + platform_lib_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//add cwd path
|
//add cwd path
|
||||||
oalPaths[oalPaths.length - 1] = "";
|
possible_paths.add(platform_lib_name);
|
||||||
|
//create needed string array
|
||||||
|
String[] oalPaths = new String[possible_paths.size()];
|
||||||
|
possible_paths.toArray(oalPaths);
|
||||||
|
|
||||||
return oalPaths;
|
return oalPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,22 +50,20 @@
|
||||||
*/
|
*/
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Handle to OpenAL Library */
|
/* Handle to OpenAL Library */
|
||||||
HMODULE handleOAL;
|
static HMODULE handleOAL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef _X11
|
#ifdef _X11
|
||||||
void* handleOGG;
|
static void* handleOAL;
|
||||||
void* handleVorbis;
|
|
||||||
void* handleVorbisFile;
|
|
||||||
void* handleOAL;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _MACOSX
|
#ifdef _MACOSX
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
const struct mach_header* handleOAL = NULL;
|
static const struct mach_header* handleOAL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
alGetProcAddressPROC alGetProcAddress = NULL;
|
typedef ALvoid* (ALAPIENTRY *alGetProcAddressPROC)( ALubyte* fname );
|
||||||
|
static alGetProcAddressPROC alGetProcAddress = NULL;
|
||||||
|
|
||||||
/* Loads OpenAL */
|
/* Loads OpenAL */
|
||||||
static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths);
|
static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths);
|
||||||
|
@ -108,35 +106,6 @@ static void* extal_GetProcAddress(const char* function) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Concatenate two strings
|
|
||||||
*/
|
|
||||||
static char *concatenate(const char *str1, const char *str2) {
|
|
||||||
int length1 = strlen(str1);
|
|
||||||
int length2 = strlen(str2);
|
|
||||||
char *str = (char *)calloc(length1 + length2 + 1, sizeof(char));
|
|
||||||
strncpy(str, str1, length1);
|
|
||||||
strncpy(str + length1, str2, length2 + 1);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef _X11
|
|
||||||
static void closeVorbisLibs(void) {
|
|
||||||
if (handleOGG != NULL) {
|
|
||||||
dlclose(handleOGG);
|
|
||||||
handleOGG = NULL;
|
|
||||||
}
|
|
||||||
if (handleVorbis != NULL) {
|
|
||||||
dlclose(handleVorbis);
|
|
||||||
handleVorbis = NULL;
|
|
||||||
}
|
|
||||||
if (handleVorbisFile != NULL) {
|
|
||||||
dlclose(handleVorbisFile);
|
|
||||||
handleVorbisFile = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the OpenAL Library
|
* Loads the OpenAL Library
|
||||||
*/
|
*/
|
||||||
|
@ -145,7 +114,6 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) {
|
||||||
int i;
|
int i;
|
||||||
jstring path;
|
jstring path;
|
||||||
char *path_str;
|
char *path_str;
|
||||||
char *lib_str;
|
|
||||||
|
|
||||||
printfDebug("Found %d OpenAL paths\n", (int)pathcount);
|
printfDebug("Found %d OpenAL paths\n", (int)pathcount);
|
||||||
for(i=0;i<pathcount;i++) {
|
for(i=0;i<pathcount;i++) {
|
||||||
|
@ -153,35 +121,13 @@ static bool LoadOpenAL(JNIEnv *env, jobjectArray oalPaths) {
|
||||||
path_str = GetStringNativeChars(env, path);
|
path_str = GetStringNativeChars(env, path);
|
||||||
printfDebug("Testing '%s'\n", path_str);
|
printfDebug("Testing '%s'\n", path_str);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
lib_str = concatenate(path_str, "lwjglaudio.dll");
|
handleOAL = LoadLibrary(path_str);
|
||||||
handleOAL = LoadLibrary(lib_str);
|
|
||||||
free(lib_str);
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _X11
|
#ifdef _X11
|
||||||
lib_str = concatenate(path_str, "libogg.so.0");
|
handleOAL = dlopen(path_str, RTLD_LAZY);
|
||||||
handleOGG = dlopen(lib_str, RTLD_LAZY);
|
|
||||||
free(lib_str);
|
|
||||||
|
|
||||||
lib_str = concatenate(path_str, "libvorbis.so.0");
|
|
||||||
handleVorbis = dlopen(lib_str, RTLD_LAZY);
|
|
||||||
free(lib_str);
|
|
||||||
|
|
||||||
lib_str = concatenate(path_str, "libvorbisfile.so.3");
|
|
||||||
handleVorbisFile = dlopen(lib_str, RTLD_LAZY);
|
|
||||||
free(lib_str);
|
|
||||||
|
|
||||||
lib_str = concatenate(path_str, "libopenal.so");
|
|
||||||
handleOAL = dlopen(lib_str, RTLD_LAZY);
|
|
||||||
free(lib_str);
|
|
||||||
|
|
||||||
if (handleOAL == NULL) {
|
|
||||||
closeVorbisLibs();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _MACOSX
|
#ifdef _MACOSX
|
||||||
lib_str = concatenate(path_str, "openal.dylib");
|
handleOAL = NSAddImage(path_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
||||||
handleOAL = NSAddImage(lib_str, NSADDIMAGE_OPTION_RETURN_ON_ERROR);
|
|
||||||
free(lib_str);
|
|
||||||
#endif
|
#endif
|
||||||
if (handleOAL != NULL) {
|
if (handleOAL != NULL) {
|
||||||
printfDebug("Found OpenAL at '%s'\n", path_str);
|
printfDebug("Found OpenAL at '%s'\n", path_str);
|
||||||
|
@ -207,7 +153,6 @@ static void UnLoadOpenAL() {
|
||||||
dlclose(handleOAL);
|
dlclose(handleOAL);
|
||||||
handleOAL = NULL;
|
handleOAL = NULL;
|
||||||
}
|
}
|
||||||
closeVorbisLibs();
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _MACOSX
|
#ifdef _MACOSX
|
||||||
// Cannot remove the image
|
// Cannot remove the image
|
||||||
|
|
|
@ -96,8 +96,7 @@ extern "C" {
|
||||||
void InitializeOpenAL(JNIEnv *env, jobjectArray oalPaths);
|
void InitializeOpenAL(JNIEnv *env, jobjectArray oalPaths);
|
||||||
void DeInitializeOpenAL();
|
void DeInitializeOpenAL();
|
||||||
|
|
||||||
typedef ALvoid* (ALAPIENTRY *alGetProcAddressPROC)( ALubyte* fname );
|
//extern alGetProcAddressPROC alGetProcAddress;
|
||||||
extern alGetProcAddressPROC alGetProcAddress;
|
|
||||||
|
|
||||||
typedef ALCcontext* (ALCAPIENTRY *alcGetCurrentContextPROC)(ALCvoid);
|
typedef ALCcontext* (ALCAPIENTRY *alcGetCurrentContextPROC)(ALCvoid);
|
||||||
extern alcGetCurrentContextPROC alcGetCurrentContext;
|
extern alcGetCurrentContextPROC alcGetCurrentContext;
|
||||||
|
|
Loading…
Reference in New Issue