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