changeset 847:bb8988602259

Allow directaudio to reopen hardware device for line. 2008-05-04 Mark Wielaard <mwielaard@redhat.com> * Makefile.am (ICEDTEA_PATCHES): Add patches/icedtea-directaudio-close-trick.patch. * Makefile.in: Regenerated. * patches/icedtea-directaudio-close-trick.patch: New patch.
author Mark Wielaard <mark@klomp.org>
date Sun, 04 May 2008 18:47:31 +0200
parents 8810f9b6e357
children 8e665e78cbfe
files ChangeLog Makefile.am Makefile.in patches/icedtea-directaudio-close-trick.patch
diffstat 4 files changed, 94 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri May 02 01:30:56 2008 +0200
+++ b/ChangeLog	Sun May 04 18:47:31 2008 +0200
@@ -1,3 +1,10 @@
+2008-05-04  Mark Wielaard  <mwielaard@redhat.com>
+
+	* Makefile.am (ICEDTEA_PATCHES): Add
+	patches/icedtea-directaudio-close-trick.patch.
+	* Makefile.in: Regenerated.
+	* patches/icedtea-directaudio-close-trick.patch: New patch.
+
 2008-05-01  Mark Wielaard  <mwielaard@redhat.com>
 
 	* overlays/openjdk/jdk/src/share/classes/com/sun/media/sound/
--- a/Makefile.am	Fri May 02 01:30:56 2008 +0200
+++ b/Makefile.am	Sun May 04 18:47:31 2008 +0200
@@ -310,6 +310,7 @@
 	patches/icedtea-color-profiles.patch \
 	patches/icedtea-fonts.patch \
 	patches/icedtea-gervill.patch \
+	patches/icedtea-directaudio-close-trick.patch \
 	$(GCC_PATCH) \
 	$(DISTRIBUTION_PATCHES)
 
--- a/Makefile.in	Fri May 02 01:30:56 2008 +0200
+++ b/Makefile.in	Sun May 04 18:47:31 2008 +0200
@@ -413,7 +413,8 @@
 	patches/icedtea-color-createcontext.patch \
 	patches/icedtea-color-profiles.patch \
 	patches/icedtea-fonts.patch patches/icedtea-gervill.patch \
-	$(GCC_PATCH) $(DISTRIBUTION_PATCHES) $(am__append_7)
+	patches/icedtea-directaudio-close-trick.patch $(GCC_PATCH) \
+	$(DISTRIBUTION_PATCHES) $(am__append_7)
 
 # Patch OpenJDK for plug replacements and ecj.
 ICEDTEA_ECJ_PATCH = patches/icedtea-ecj.patch
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patches/icedtea-directaudio-close-trick.patch	Sun May 04 18:47:31 2008 +0200
@@ -0,0 +1,84 @@
+--- /home/mark/src/openjdk/jdk/src/share/classes/com/sun/media/sound/DirectAudioDevice.java	2008-04-13 01:05:30.000000000 +0200
++++ openjdk/jdk/src/share/classes/com/sun/media/sound/DirectAudioDevice.java	2008-05-04 18:42:39.000000000 +0200
+@@ -394,7 +394,10 @@
+         private float leftGain, rightGain;
+         protected volatile boolean noService = false; // do not run the nService method
+ 
+-        protected Object lockNative = new Object();
++        // Guards all native calls and the lastOpened static variable.
++        protected static Object lockNative = new Object();
++        // Keeps track of last opened line, see implOpen "trick".
++        protected static DirectDL lastOpened;
+ 
+         // CONSTRUCTOR
+         protected DirectDL(DataLine.Info info,
+@@ -496,20 +499,47 @@
+             // align buffer to full frames
+             bufferSize = ((int) bufferSize / format.getFrameSize()) * format.getFrameSize();
+ 
+-            id = nOpen(mixerIndex, deviceID, isSource,
+-                       encoding,
+-                       hardwareFormat.getSampleRate(),
+-                       hardwareFormat.getSampleSizeInBits(),
+-                       hardwareFormat.getFrameSize(),
+-                       hardwareFormat.getChannels(),
+-                       hardwareFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
+-                       hardwareFormat.isBigEndian(),
+-                       bufferSize);
++	    synchronized(lockNative) {
++	      id = nOpen(mixerIndex, deviceID, isSource,
++			 encoding,
++			 hardwareFormat.getSampleRate(),
++			 hardwareFormat.getSampleSizeInBits(),
++			 hardwareFormat.getFrameSize(),
++			 hardwareFormat.getChannels(),
++			 hardwareFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
++			 hardwareFormat.isBigEndian(),
++			 bufferSize);
++	      
++	      if (id == 0) {
++		// Bah... Dirty trick. The most likely cause is an application
++		// already having a line open for this particular hardware
++		// format and forgetting about it. If so, silently close that
++		// implementation and try again. Unfortuantely we can only
++		// open one line per hardware format currently.
++		if (lastOpened != null
++		    && hardwareFormat.matches(lastOpened.hardwareFormat)) {
++		  lastOpened.implClose();
++		  lastOpened = null;
++		  
++		  id = nOpen(mixerIndex, deviceID, isSource,
++			     encoding,
++			     hardwareFormat.getSampleRate(),
++			     hardwareFormat.getSampleSizeInBits(),
++			     hardwareFormat.getFrameSize(),
++			     hardwareFormat.getChannels(),
++			     hardwareFormat.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
++			     hardwareFormat.isBigEndian(),
++			     bufferSize);
++		}
++		
++		if (id == 0) {
++		    // TODO: nicer error messages...
++		    throw new LineUnavailableException("line with format "+format+" not supported.");
++                }
++	      }
++	      lastOpened = this;
++	    }
+ 
+-            if (id == 0) {
+-                // TODO: nicer error messages...
+-                throw new LineUnavailableException("line with format "+format+" not supported.");
+-            }
+             this.bufferSize = nGetBufferSize(id, isSource);
+             if (this.bufferSize < 1) {
+                 // this is an error!
+@@ -616,6 +646,8 @@
+             id = 0;
+             synchronized (lockNative) {
+                 nClose(oldID, isSource);
++                if (lastOpened == this)
++                  lastOpened = null;
+             }
+             bytePosition = 0;
+             softwareConversionSize = 0;