summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-02-22 07:53:29 +0100
committerSven Gothel <[email protected]>2014-02-22 07:53:29 +0100
commit13d850c7bf93648dc24e3f01f6f8c9550fba0d97 (patch)
tree8a8ea6c775a6050a64f32bbb74a086c3823f1c24
parentb9e89c35dac3c19e026d2a0161649a065b3dceee (diff)
Bug 927 - Multithreading (MT) issues ALAudioSink
Add global synchronization around ALAudioSink constructor code, which 'magically' solves the openal-soft multithreading issues .. This is a workaround.
-rw-r--r--src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java107
1 files changed, 54 insertions, 53 deletions
diff --git a/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java b/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java
index 287b3081c..3caf340b9 100644
--- a/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java
+++ b/src/jogl/classes/jogamp/opengl/openal/av/ALAudioSink.java
@@ -140,70 +140,71 @@ public class ALAudioSink implements AudioSink {
if( !staticAvailable ) {
return;
}
+ synchronized(ALAudioSink.class) {
+ try {
+ // Get handle to default device.
+ device = alc.alcOpenDevice(null);
+ if (device == null) {
+ throw new RuntimeException(getThreadName()+": ALAudioSink: Error opening default OpenAL device");
+ }
- try {
- // Get handle to default device.
- device = alc.alcOpenDevice(null);
- if (device == null) {
- throw new RuntimeException("ALAudioSink: Error opening default OpenAL device");
- }
+ // Get the device specifier.
+ deviceSpecifier = alc.alcGetString(device, ALC.ALC_DEVICE_SPECIFIER);
+ if (deviceSpecifier == null) {
+ throw new RuntimeException(getThreadName()+": ALAudioSink: Error getting specifier for default OpenAL device");
+ }
- // Get the device specifier.
- deviceSpecifier = alc.alcGetString(device, ALC.ALC_DEVICE_SPECIFIER);
- if (deviceSpecifier == null) {
- throw new RuntimeException("ALAudioSink: Error getting specifier for default OpenAL device");
- }
+ // Create audio context.
+ context = alc.alcCreateContext(device, null);
+ if (context == null) {
+ throw new RuntimeException(getThreadName()+": ALAudioSink: Error creating OpenAL context for "+deviceSpecifier);
+ }
- // Create audio context.
- context = alc.alcCreateContext(device, null);
- if (context == null) {
- throw new RuntimeException("ALAudioSink: Error creating OpenAL context for "+deviceSpecifier);
- }
+ lockContext();
+ try {
+ // Check for an error.
+ if ( alc.alcGetError(device) != ALC.ALC_NO_ERROR ) {
+ throw new RuntimeException(getThreadName()+": ALAudioSink: Error making OpenAL context current");
+ }
- lockContext();
- try {
- // Check for an error.
- if ( alc.alcGetError(device) != ALC.ALC_NO_ERROR ) {
- throw new RuntimeException("ALAudioSink: Error making OpenAL context current");
- }
+ hasSOFTBufferSamples = al.alIsExtensionPresent(AL_SOFT_buffer_samples);
+ hasALC_thread_local_context = alc.alcIsExtensionPresent(null, ALC_EXT_thread_local_context) ||
+ alc.alcIsExtensionPresent(device, ALC_EXT_thread_local_context) ;
+ preferredAudioFormat = queryPreferredAudioFormat();
+ if( DEBUG ) {
+ System.out.println("ALAudioSink: OpenAL Extensions:"+al.alGetString(AL.AL_EXTENSIONS));
+ System.out.println("ALAudioSink: Null device OpenAL Extensions:"+alc.alcGetString(null, ALC.ALC_EXTENSIONS));
+ System.out.println("ALAudioSink: Device "+deviceSpecifier+" OpenAL Extensions:"+alc.alcGetString(device, ALC.ALC_EXTENSIONS));
+ System.out.println("ALAudioSink: hasSOFTBufferSamples "+hasSOFTBufferSamples);
+ System.out.println("ALAudioSink: hasALC_thread_local_context "+hasALC_thread_local_context);
+ System.out.println("ALAudioSink: preferredAudioFormat "+preferredAudioFormat);
+ }
- hasSOFTBufferSamples = al.alIsExtensionPresent(AL_SOFT_buffer_samples);
- hasALC_thread_local_context = alc.alcIsExtensionPresent(null, ALC_EXT_thread_local_context) ||
- alc.alcIsExtensionPresent(device, ALC_EXT_thread_local_context) ;
- preferredAudioFormat = queryPreferredAudioFormat();
- if( DEBUG ) {
- System.out.println("ALAudioSink: OpenAL Extensions:"+al.alGetString(AL.AL_EXTENSIONS));
- System.out.println("ALAudioSink: Null device OpenAL Extensions:"+alc.alcGetString(null, ALC.ALC_EXTENSIONS));
- System.out.println("ALAudioSink: Device "+deviceSpecifier+" OpenAL Extensions:"+alc.alcGetString(device, ALC.ALC_EXTENSIONS));
- System.out.println("ALAudioSink: hasSOFTBufferSamples "+hasSOFTBufferSamples);
- System.out.println("ALAudioSink: hasALC_thread_local_context "+hasALC_thread_local_context);
- System.out.println("ALAudioSink: preferredAudioFormat "+preferredAudioFormat);
- }
+ // Create source
+ {
+ alSource = new int[1];
+ al.alGenSources(1, alSource, 0);
+ final int err = al.alGetError();
+ if( AL.AL_NO_ERROR != err ) {
+ alSource = null;
+ throw new RuntimeException(getThreadName()+": ALAudioSink: Error generating Source: 0x"+Integer.toHexString(err));
+ }
+ }
- // Create source
- {
- alSource = new int[1];
- al.alGenSources(1, alSource, 0);
- final int err = al.alGetError();
- if( AL.AL_NO_ERROR != err ) {
- alSource = null;
- throw new RuntimeException("ALAudioSink: Error generating Source: 0x"+Integer.toHexString(err));
+ if( DEBUG ) {
+ System.err.println("ALAudioSink: Using device: " + deviceSpecifier);
}
+ initialized = true;
+ } finally {
+ unlockContext();
}
-
+ return;
+ } catch ( Exception e ) {
if( DEBUG ) {
- System.err.println("ALAudioSink: Using device: " + deviceSpecifier);
+ System.err.println(e.getMessage());
}
- initialized = true;
- } finally {
- unlockContext();
- }
- return;
- } catch ( Exception e ) {
- if( DEBUG ) {
- System.err.println(e.getMessage());
+ destroy();
}
- destroy();
}
}