aboutsummaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/jogamp/openal/JoalVersion.java123
-rw-r--r--src/java/com/jogamp/openal/sound3d/Context.java72
-rw-r--r--src/java/com/jogamp/openal/util/ALHelpers.java3
-rw-r--r--src/java/jogamp/openal/ALCImpl.java50
-rw-r--r--src/java/jogamp/openal/ALDynamicLibraryBundleInfo.java3
5 files changed, 182 insertions, 69 deletions
diff --git a/src/java/com/jogamp/openal/JoalVersion.java b/src/java/com/jogamp/openal/JoalVersion.java
index f2ffc48..77dcabf 100644
--- a/src/java/com/jogamp/openal/JoalVersion.java
+++ b/src/java/com/jogamp/openal/JoalVersion.java
@@ -33,6 +33,7 @@ import com.jogamp.common.GlueGenVersion;
import com.jogamp.common.os.Platform;
import com.jogamp.common.util.VersionUtil;
import com.jogamp.common.util.JogampVersion;
+import com.jogamp.openal.util.ALHelpers;
import java.util.jar.Manifest;
@@ -110,29 +111,62 @@ public class JoalVersion extends JogampVersion {
sb.append("ALC null");
return sb;
}
- final ALCdevice device = alc.alcOpenDevice(null);
- final ALCcontext context = alc.alcCreateContext(device, null);
- alc.alcMakeContextCurrent(context);
+ final ALCcontext initialContext = alc.alcGetCurrentContext();
+
+ final ALCcontext context;
+ final ALCdevice device;
+ if( null == initialContext) {
+ device = alc.alcOpenDevice(null);
+ context = alc.alcCreateContext(device, null);
+ alc.alcMakeContextCurrent(context);
+ } else {
+ context = initialContext;
+ device = alc.alcGetContextsDevice(initialContext);
+ }
final AL al = ALFactory.getAL(); // valid after makeContextCurrent(..)
final ALVersion alv = new ALVersion(al);
alv.toString(true, sb);
sb.append("AL_EXTENSIONS ").append(al.alGetString(ALConstants.AL_EXTENSIONS));
sb.append(Platform.getNewline());
+ final boolean enumerationExtIsPresent = alc.aclEnumerationExtIsPresent();
+ final boolean enumerateAllExtIsPresent = alc.aclEnumerateAllExtIsPresent();
+ final String enumExtAvailInfo = "(enumExt[def "+enumerationExtIsPresent+", all "+enumerateAllExtIsPresent+"])";
{
final int[] iversion = { 0, 0 };
alc.alcGetIntegerv(device, ALCConstants.ALC_MAJOR_VERSION, 1, iversion, 0);
alc.alcGetIntegerv(device, ALCConstants.ALC_MINOR_VERSION, 1, iversion, 1);
sb.append("ALC_VERSION ").append(iversion[0]).append(".").append(iversion[1]);
sb.append(Platform.getNewline());
- sb.append("ALC_DEF_OUTPUT ").append(alc.alcGetString(device, ALCConstants.ALC_DEFAULT_DEVICE_SPECIFIER));
- sb.append(Platform.getNewline());
- sb.append("ALC_DEF_CAPTURE ").append(alc.alcGetString(device, ALCConstants.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
+ if (!enumerationExtIsPresent && !enumerateAllExtIsPresent) {
+ sb.append("ALC_DEF_OUTPUT Unknown ").append(enumExtAvailInfo);
+ sb.append(Platform.getNewline());
+ } else {
+ if (enumerationExtIsPresent) {
+ sb.append("ALC_DEF_OUTPUT (With " + ALHelpers.ALC_ENUMERATION_EXT + ") ")
+ .append(alc.alcGetString(device, ALCConstants.ALC_DEFAULT_DEVICE_SPECIFIER));
+ sb.append(Platform.getNewline());
+ }
+ if (enumerateAllExtIsPresent) {
+ sb.append("ALC_DEF_OUTPUT (With " + ALHelpers.ALC_ENUMERATE_ALL_EXT + ") ")
+ .append(alc.alcGetString(device, ALCConstants.ALC_DEFAULT_ALL_DEVICES_SPECIFIER));
+ sb.append(Platform.getNewline());
+ }
+ }
+ if (enumerationExtIsPresent) {
+ sb.append("ALC_DEF_CAPTURE ").append(alc.alcGetString(device, ALCConstants.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER));
+ } else {
+ sb.append("ALC_DEF_CAPTURE Unknown ").append(enumExtAvailInfo);
+ }
sb.append(Platform.getNewline());
}
- alc.alcMakeContextCurrent(null);
- alc.alcDestroyContext(context);
- alc.alcCloseDevice(device);
+
+ if( null == initialContext ) {
+ alc.alcMakeContextCurrent(null);
+ alc.alcDestroyContext(context);
+ alc.alcCloseDevice(device);
+ }
+
devicesToString(sb, alc);
return sb;
}
@@ -157,6 +191,8 @@ public class JoalVersion extends JogampVersion {
final String inOutStr = "output";
final int mixerFrequency, mixerRefresh, monoSourceCount, stereoSourceCount;
final int[] val = { 0 };
+ final ALCcontext initialContext = alc.alcGetCurrentContext();
+ final ALCdevice initialDevice = initialContext != null ? alc.alcGetContextsDevice(initialContext) : null;
final ALCdevice d = alc.alcOpenDevice(devName);
if( null == d ) {
System.err.println("Error: Failed to open "+defStr+inOutStr+" device "+devName);
@@ -216,30 +252,65 @@ public class JoalVersion extends JogampVersion {
" (min latency "+(1000f/mixerRefresh)+" ms)], sources[mono "+monoSourceCount+", stereo "+stereoSourceCount+"]"+
System.lineSeparator());
- alc.alcMakeContextCurrent(null);
- alc.alcDestroyContext(c);
- alc.alcCloseDevice(d);
+ if( null != initialContext ) {
+ alc.alcMakeContextCurrent(initialContext);
+ if( initialContext.getDirectBufferAddress() != c.getDirectBufferAddress() ) {
+ alc.alcDestroyContext(c);
+ }
+ } else {
+ alc.alcMakeContextCurrent(null);
+ alc.alcDestroyContext(c);
+ }
+ if( initialDevice == null || initialDevice.getDirectBufferAddress() != d.getDirectBufferAddress() ) {
+ alc.alcCloseDevice(d);
+ }
}
}
public static void devicesToString(final StringBuilder sb, final ALC alc) {
- final String defOutDeviceName = alc.alcGetString(null, ALCConstants.ALC_DEFAULT_DEVICE_SPECIFIER);
- final String defInDeviceName = alc.alcGetString(null, ALCConstants.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
- sb.append("Output devices:"+System.lineSeparator());
- {
- final String[] outDevices = alc.alcGetDeviceSpecifiers();
- if( null != outDevices ) {
- for (final String devName : outDevices) {
- deviceToString(sb, alc, devName, false, defOutDeviceName, defInDeviceName);
+ final boolean enumerationExtIsPresent = alc.aclEnumerationExtIsPresent();
+ final boolean enumerateAllExtIsPresent = alc.aclEnumerateAllExtIsPresent();
+ final String enumExtAvailInfo = "(enumExt[def "+enumerationExtIsPresent+", all "+enumerateAllExtIsPresent+"])";
+
+ if (!enumerationExtIsPresent && !enumerateAllExtIsPresent) {
+ sb.append("No output devices infos available ").append(enumExtAvailInfo);
+ } else {
+ if (enumerateAllExtIsPresent) {
+ final String defOutAllDeviceName = alc.alcGetString(null, ALCConstants.ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
+ sb.append("Output devices (With " + ALHelpers.ALC_ENUMERATE_ALL_EXT + "):" + System.lineSeparator());
+ {
+ final String[] outDevices = alc.alcGetAllDeviceSpecifiers();
+ if (null != outDevices) {
+ for (final String devName : outDevices) {
+ deviceToString(sb, alc, devName, false, defOutAllDeviceName, null);
+ }
+ }
+ }
+ }
+ if (enumerationExtIsPresent) {
+ final String defOutDeviceName = alc.alcGetString(null, ALCConstants.ALC_DEFAULT_DEVICE_SPECIFIER);
+ sb.append("Output devices (With " + ALHelpers.ALC_ENUMERATION_EXT + "):" + System.lineSeparator());
+ {
+ final String[] outDevices = alc.alcGetDeviceSpecifiers();
+ if (null != outDevices) {
+ for (final String devName : outDevices) {
+ deviceToString(sb, alc, devName, false, defOutDeviceName, null);
+ }
+ }
}
}
}
- sb.append("Capture devices:"+System.lineSeparator());
- {
- final String[] inDevices = alc.alcGetCaptureDeviceSpecifiers();
- if( null != inDevices ) {
- for (final String devName : inDevices) {
- deviceToString(sb, alc, devName, true, defOutDeviceName, defInDeviceName);
+ if (!enumerationExtIsPresent) {
+ sb.append("No capture devices infos available ").append(enumExtAvailInfo);
+ } else {
+ final String defInDeviceName = alc.alcGetString(null, ALCConstants.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
+ sb.append("Capture devices:" + System.lineSeparator());
+ {
+ final String[] inDevices = alc.alcGetCaptureDeviceSpecifiers();
+ if (null != inDevices) {
+ for (final String devName : inDevices) {
+ deviceToString(sb, alc, devName, true, null, defInDeviceName);
+ }
}
}
}
diff --git a/src/java/com/jogamp/openal/sound3d/Context.java b/src/java/com/jogamp/openal/sound3d/Context.java
index e42f9dc..7e20263 100644
--- a/src/java/com/jogamp/openal/sound3d/Context.java
+++ b/src/java/com/jogamp/openal/sound3d/Context.java
@@ -34,6 +34,7 @@
package com.jogamp.openal.sound3d;
+import com.jogamp.common.util.locks.Lock;
import com.jogamp.common.util.locks.LockFactory;
import com.jogamp.common.util.locks.RecursiveLock;
import com.jogamp.openal.*;
@@ -203,6 +204,9 @@ public final class Context {
return lock.getHoldCount();
}
+ public boolean tryMakeCurrent(final boolean throwException, final long timeoutMS) throws RuntimeException {
+ return makeCurrentImpl(false /* throwTryLockException */, throwException, timeoutMS);
+ }
/**
* Makes the audio context current on the calling thread.
* <p>
@@ -217,40 +221,52 @@ public final class Context {
* @see #release()
*/
public boolean makeCurrent(final boolean throwException) throws ALException {
- lock.lock();
-
- if( null == alCtx ) {
- lock.unlock();
- if( throwException ) {
- throw new ALException("Invalid "+this);
- }
- return false;
- }
+ return makeCurrentImpl(true /* throwTryLockException */, throwException, Lock.TIMEOUT);
+ }
+ private boolean makeCurrentImpl(final boolean throwTryLockException, final boolean throwException, final long timeoutMS) throws RuntimeException {
+ try {
+ if( lock.tryLock(timeoutMS) ) {
+ if( null == alCtx ) {
+ lock.unlock();
+ if( throwException ) {
+ throw new ALException("Invalid "+this);
+ }
+ return false;
+ }
- // One context can only be current on one thread,
- // and one thread can only have one context current!
- final Context current = getCurrentContext();
- if (current != null) {
- if (current == this) { // implicit recursive locking, lock.getHoldCount() > 1
- return true;
+ // One context can only be current on one thread,
+ // and one thread can only have one context current!
+ final Context current = getCurrentContext();
+ if (current != null) {
+ if (current == this) { // implicit recursive locking, lock.getHoldCount() > 1
+ return true;
+ } else {
+ lock.unlock();
+ if( throwException ) {
+ throw new ALException("Current thread "+Thread.currentThread()+" holds another "+current+" while claiming this "+this);
+ }
+ return false;
+ }
+ }
+ final boolean r = makeCurrentImpl();
+ if( r ) {
+ currentContext.set(this);
+ } else {
+ lock.unlock();
+ if( throwException ) {
+ throw new ALException("Context make current failed "+this);
+ }
+ }
+ return r;
} else {
- lock.unlock();
- if( throwException ) {
- throw new ALException("Current thread "+Thread.currentThread()+" holds another "+current+" while claiming this "+this);
+ if( throwTryLockException ) {
+ throw new RuntimeException("Waited "+timeoutMS+"ms for: "+lock.toString()+" - "+Thread.currentThread().getName());
}
return false;
}
+ } catch (final InterruptedException ie) {
+ throw new RuntimeException(ie);
}
- final boolean r = makeCurrentImpl();
- if( r ) {
- currentContext.set(this);
- } else {
- lock.unlock();
- if( throwException ) {
- throw new ALException("Context make current failed "+this);
- }
- }
- return r;
}
private boolean makeCurrentImpl() {
if( hasALC_thread_local_context ) {
diff --git a/src/java/com/jogamp/openal/util/ALHelpers.java b/src/java/com/jogamp/openal/util/ALHelpers.java
index 93dfa6e..fda3167 100644
--- a/src/java/com/jogamp/openal/util/ALHelpers.java
+++ b/src/java/com/jogamp/openal/util/ALHelpers.java
@@ -52,6 +52,9 @@ public class ALHelpers {
public static final String ALC_EXT_thread_local_context = "ALC_EXT_thread_local_context";
+ public static final String ALC_ENUMERATION_EXT = "ALC_ENUMERATION_EXT";
+ public static final String ALC_ENUMERATE_ALL_EXT = "ALC_ENUMERATE_ALL_EXT";
+
/**
* Returns a compatible {@link AudioFormat} based on given OpenAL channel-layout, sample-type and format,
* as well as the generic sample-rate and sample-size.
diff --git a/src/java/jogamp/openal/ALCImpl.java b/src/java/jogamp/openal/ALCImpl.java
index 99494ca..cdde31b 100644
--- a/src/java/jogamp/openal/ALCImpl.java
+++ b/src/java/jogamp/openal/ALCImpl.java
@@ -4,21 +4,39 @@
package jogamp.openal;
import com.jogamp.common.nio.Buffers;
+import com.jogamp.openal.ALCConstants;
import com.jogamp.openal.ALException;
import com.jogamp.openal.ALCdevice;
+import com.jogamp.openal.util.ALHelpers;
+
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
/**
* ALC implementation.
- * @author Michael Bien
*/
public class ALCImpl extends ALCAbstractImpl {
+ public boolean aclEnumerationExtIsPresent() {
+ return alcIsExtensionPresent(null, ALHelpers.ALC_ENUMERATION_EXT);
+ }
+
+ public boolean aclEnumerateAllExtIsPresent() {
+ return alcIsExtensionPresent(null, ALHelpers.ALC_ENUMERATE_ALL_EXT);
+ }
+
+ public boolean alcIsDoubleNullTerminatedString(final ALCdevice device, final int param) {
+ return ( null == device || 0 == device.getDirectBufferAddress() ) &&
+ ( param == ALC_DEVICE_SPECIFIER ||
+ param == ALC_CAPTURE_DEVICE_SPECIFIER ||
+ param == ALC_ALL_DEVICES_SPECIFIER
+ );
+ }
+ @Override
public String alcGetString(final ALCdevice device, final int param) {
- if (device == null && param == ALC_DEVICE_SPECIFIER) {
- throw new ALException("Call alcGetDeviceSpecifiers to fetch all available device names");
+ if (alcIsDoubleNullTerminatedString(device, param)) {
+ throw new ALException("Call alcGetString to get double null terminated string");
}
final ByteBuffer buf = alcGetStringImpl(device, param);
@@ -51,24 +69,26 @@ public class ALCImpl extends ALCAbstractImpl {
}
private native java.nio.ByteBuffer dispatch_alcGetStringImpl1(ByteBuffer deviceBuffer, int param, long addr);
- /**
- * Fetches the names of the available ALC device specifiers.
- * Equivalent to the C call alcGetString(NULL, ALC_DEVICE_SPECIFIER).
- */
+ @Override
public String[] alcGetDeviceSpecifiers() {
- return getDoubleNullTerminatedString(ALC_DEVICE_SPECIFIER);
+ return alcGetStringAsDoubleNullTerminatedString(null, ALC_DEVICE_SPECIFIER);
}
- /**
- * Fetches the names of the available ALC capture device specifiers.
- * Equivalent to the C call alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER).
- */
+ @Override
public String[] alcGetCaptureDeviceSpecifiers() {
- return getDoubleNullTerminatedString(ALC_CAPTURE_DEVICE_SPECIFIER);
+ return alcGetStringAsDoubleNullTerminatedString(null, ALC_CAPTURE_DEVICE_SPECIFIER);
}
- private String[] getDoubleNullTerminatedString(final int which) {
- final ByteBuffer buf = alcGetStringImpl(null, which);
+ public String[] alcGetAllDeviceSpecifiers() {
+ return alcGetStringAsDoubleNullTerminatedString(null, ALC_ALL_DEVICES_SPECIFIER);
+ }
+
+ public String[] alcGetStringAsDoubleNullTerminatedString(final ALCdevice device, final int param) {
+ if (!alcIsDoubleNullTerminatedString(device, param)) {
+ throw new ALException("Call alcGetString to get string");
+ }
+
+ final ByteBuffer buf = alcGetStringImpl(device, param);
if (buf == null) {
return null;
}
diff --git a/src/java/jogamp/openal/ALDynamicLibraryBundleInfo.java b/src/java/jogamp/openal/ALDynamicLibraryBundleInfo.java
index e58e34c..1a2ed3f 100644
--- a/src/java/jogamp/openal/ALDynamicLibraryBundleInfo.java
+++ b/src/java/jogamp/openal/ALDynamicLibraryBundleInfo.java
@@ -44,6 +44,7 @@ public final class ALDynamicLibraryBundleInfo implements DynamicLibraryBundleInf
private static final List<String> glueLibNames;
static {
SecurityUtil.doPrivileged(new PrivilegedAction<Object>() {
+ @Override
public Object run() {
Platform.initSingleton();
@@ -140,6 +141,8 @@ public final class ALDynamicLibraryBundleInfo implements DynamicLibraryBundleInf
return libNamesList;
}
+ @Override
+ public List<String> getSymbolForToolLibPath() { return Arrays.asList("alGetString"); }
@Override
public final List<String> getToolGetProcAddressFuncNameList() {