aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMathieu Féry <[email protected]>2023-11-10 15:50:24 +0100
committerMathieu Féry <[email protected]>2023-11-10 15:50:24 +0100
commitbf09df70444f38424a84fc382498b57498bb5601 (patch)
tree205464e22179c510cf41ad4df19af1ff05366cc5 /src
parent21079539c1f81bae9df328e6487e4d4d174b0b51 (diff)
feat(devices): Allow to retrieve devices specifiers with ALC_ENUMERATE_ALL_EXT
Diffstat (limited to 'src')
-rw-r--r--src/java/com/jogamp/openal/JoalVersion.java84
-rw-r--r--src/java/jogamp/openal/ALCImpl.java42
-rw-r--r--src/native/almisc.c25
-rw-r--r--src/test/com/jogamp/openal/test/manual/Synth01AL.java9
4 files changed, 119 insertions, 41 deletions
diff --git a/src/java/com/jogamp/openal/JoalVersion.java b/src/java/com/jogamp/openal/JoalVersion.java
index f2ffc48..bca175e 100644
--- a/src/java/com/jogamp/openal/JoalVersion.java
+++ b/src/java/com/jogamp/openal/JoalVersion.java
@@ -119,21 +119,42 @@ public class JoalVersion extends JogampVersion {
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 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));
- sb.append(Platform.getNewline());
+ if (!enumerationExtIsPresent && !enumerateAllExtIsPresent) {
+ sb.append("ALC_DEF_OUTPUT Unknown (Missing "+
+ ALCConstants.ALC_ENUMERATION_EXT_NAME+" and "+ALCConstants.ALC_ENUMERATE_ALL_EXT_NAME+")");
+ sb.append(Platform.getNewline());
+ } else {
+ if (enumerationExtIsPresent) {
+ sb.append("ALC_DEF_OUTPUT (With " + ALCConstants.ALC_ENUMERATION_EXT_NAME + ") ")
+ .append(alc.alcGetString(device, ALCConstants.ALC_DEFAULT_DEVICE_SPECIFIER));
+ sb.append(Platform.getNewline());
+ }
+ if (enumerateAllExtIsPresent) {
+ sb.append("ALC_DEF_OUTPUT (With " + ALCConstants.ALC_ENUMERATE_ALL_EXT_NAME + ") ")
+ .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));
+ sb.append(Platform.getNewline());
+ } else {
+ sb.append("ALC_DEF_CAPTURE Unknown (Missing "+ALCConstants.ALC_ENUMERATION_EXT_NAME+")");
+ sb.append(Platform.getNewline());
+ }
}
alc.alcMakeContextCurrent(null);
alc.alcDestroyContext(context);
alc.alcCloseDevice(device);
- devicesToString(sb, alc);
+ devicesToString(sb, alc, enumerationExtIsPresent, enumerateAllExtIsPresent);
return sb;
}
@@ -222,24 +243,47 @@ public class JoalVersion extends JogampVersion {
}
}
- 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);
+ public static void devicesToString(final StringBuilder sb, final ALC alc, final boolean enumerationExtIsPresent, final boolean enumerateAllExtIsPresent) {
+ if (!enumerationExtIsPresent && !enumerateAllExtIsPresent) {
+ sb.append("No output devices infos available (Missing "+
+ ALCConstants.ALC_ENUMERATION_EXT_NAME+" and "+ALCConstants.ALC_ENUMERATE_ALL_EXT_NAME+")");
+ } else {
+ if (enumerateAllExtIsPresent) {
+ final String defOutAllDeviceName = alc.alcGetString(null, ALCConstants.ALC_DEFAULT_ALL_DEVICES_SPECIFIER);
+ sb.append("Output devices (With " + ALCConstants.ALC_ENUMERATE_ALL_EXT_NAME + "):" + 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 " + ALCConstants.ALC_ENUMERATION_EXT_NAME + "):" + 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 (Missing " + ALCConstants.ALC_ENUMERATION_EXT_NAME + ")");
+ } 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/jogamp/openal/ALCImpl.java b/src/java/jogamp/openal/ALCImpl.java
index 99494ca..bdd0a8a 100644
--- a/src/java/jogamp/openal/ALCImpl.java
+++ b/src/java/jogamp/openal/ALCImpl.java
@@ -4,6 +4,7 @@
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 java.io.UnsupportedEncodingException;
@@ -15,10 +16,23 @@ import java.util.ArrayList;
* @author Michael Bien
*/
public class ALCImpl extends ALCAbstractImpl {
+ public boolean aclEnumerationExtIsPresent() {
+ return alcIsExtensionPresent(null, ALCConstants.ALC_ENUMERATION_EXT_NAME);
+ }
+
+ public boolean aclEnumerateAllExtIsPresent() {
+ return alcIsExtensionPresent(null, ALCConstants.ALC_ENUMERATE_ALL_EXT_NAME);
+ }
+
+ public boolean alcIsDoubleNullTerminatedString(final ALCdevice device, final int param) {
+ return dispatch_alcIsDoubleNullTerminatedString(((device == null) ? null : device.getBuffer()), param);
+ }
+
+ public native boolean dispatch_alcIsDoubleNullTerminatedString(ByteBuffer deviceBuffer, int param);
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 +65,24 @@ 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).
- */
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).
- */
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/native/almisc.c b/src/native/almisc.c
index ca638d9..06fa794 100644
--- a/src/native/almisc.c
+++ b/src/native/almisc.c
@@ -1,19 +1,21 @@
-
#include <jni.h>
#include <stdlib.h>
#include <assert.h>
- #include "al.h"
- #include "alc.h"
- #ifndef _MSC_VER /* Non-Windows platforms */
+#include "al.h"
+#include "alc.h"
+#ifndef _MSC_VER /* Non-Windows platforms */
#define __cdecl /* Trim non-standard keyword */
- #endif
- #include "efx.h"
- #include <string.h>
+#endif
+#include "efx.h"
+#include <string.h>
+#include <stdbool.h>
extern int strlen_alc(ALCdevice *device, int param, const char* str);
+extern bool alc_is_double_null_terminated_string(ALCdevice *device, int param);
+
/* Java->C glue code:
* Java package: jogamp.openal.ALImpl
* Java method: long dispatch_alGetProcAddressStatic(java.lang.String fname)
@@ -61,3 +63,12 @@ Java_jogamp_openal_ALCImpl_dispatch_1alcGetStringImpl1(JNIEnv *env, jobject _unu
return (*env)->NewDirectByteBuffer(env, _res, strlen_alc(_device_ptr, param, _res));
}
+JNIEXPORT jboolean JNICALL
+Java_jogamp_openal_ALCImpl_dispatch_1alcIsDoubleNullTerminatedString(JNIEnv *env, jobject _unused, jobject device, jint param) {
+ ALCdevice * _device_ptr = NULL;
+ const ALCchar * _res;
+ if ( NULL != device ) {
+ _device_ptr = (ALCdevice *) (((char*) (*env)->GetDirectBufferAddress(env, device)) + 0);
+ }
+ return (jboolean) alc_is_double_null_terminated_string((ALCdevice *) _device_ptr, (ALCenum) param);
+}
diff --git a/src/test/com/jogamp/openal/test/manual/Synth01AL.java b/src/test/com/jogamp/openal/test/manual/Synth01AL.java
index 64da9fa..7bd60c8 100644
--- a/src/test/com/jogamp/openal/test/manual/Synth01AL.java
+++ b/src/test/com/jogamp/openal/test/manual/Synth01AL.java
@@ -101,6 +101,15 @@ public class Synth01AL {
}
}
}
+ System.out.println("Output all devices:");
+ {
+ final String[] outDevices = alc.alcGetAllDeviceSpecifiers();
+ if( null != outDevices ) {
+ for (final String name : outDevices) {
+ System.out.println(" "+name);
+ }
+ }
+ }
alCheckError("setup", true);
al.alGenBuffers(1, buffers, 0);