# HG changeset patch # User Omair Majid # Date 1223321433 14400 # Node ID 86fab9e2bc643a8798044b55d4bec50716742ec4 # Parent eb2d35a91b0db615c4787852547aec42f600e118 2008-10-06 Omair Majid * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java New variables flushed and drained. (write): Synchronized on this. (flush): Set flushed to true. (drain): Set drained to true. diff -r eb2d35a91b0d -r 86fab9e2bc64 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Mon Oct 06 11:31:34 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Mon Oct 06 15:30:33 2008 -0400 @@ -51,6 +51,9 @@ private PulseAudioVolumeControl volumeControl; private boolean muted; private float volume; + + boolean flushed = false; + boolean drained = false; public PulseAudioSourceDataLine(EventLoop eventLoop, AudioFormat[] formats, AudioFormat defaultFormat) { @@ -156,43 +159,56 @@ while (remainingLength != 0) { - synchronized (eventLoop.threadLock) { - - do { - availableSize = stream.getWritableSize(); + synchronized (this) { + + if (!isStarted || !isOpen) { + return sizeWritten; + } + + if (flushed) { + return sizeWritten; + } + - if (availableSize < 0) { - return sizeWritten; - } + synchronized (eventLoop.threadLock) { - if (availableSize == 0) { - try { - eventLoop.threadLock.wait(); - } catch (InterruptedException e) { - // ignore for now - interrupted = true; + do { + availableSize = stream.getWritableSize(); + + if (availableSize < 0) { + return sizeWritten; } + if (availableSize == 0) { + try { + eventLoop.threadLock.wait(); + } catch (InterruptedException e) { + // ignore for now + interrupted = true; + } + + } + + } while (availableSize == 0); + + if (availableSize > remainingLength) { + availableSize = remainingLength; } - } while (availableSize == 0); - - if (availableSize > remainingLength) { - availableSize = remainingLength; - } + // only write entire frames, so round down avialableSize to + // a + // multiple of frameSize + availableSize = (availableSize / frameSize) * frameSize; - // only write entire frames, so round down avialableSize to a - // multiple of frameSize - availableSize = (availableSize / frameSize) * frameSize; + /* write a little bit of the buffer */ + stream.write(data, position, availableSize); - /* write a little bit of the buffer */ - stream.write(data, position, availableSize); + sizeWritten += availableSize; + position += availableSize; + remainingLength -= availableSize; - sizeWritten += availableSize; - position += availableSize; - remainingLength -= availableSize; - - framesSinceOpen += availableSize / frameSize; + framesSinceOpen += availableSize / frameSize; + } } } @@ -248,6 +264,10 @@ operation.waitForCompletion(); operation.releaseReference(); + + synchronized (this) { + drained = true; + } } @@ -266,6 +286,10 @@ operation.waitForCompletion(); operation.releaseReference(); + synchronized (this) { + flushed= true; + } + } @Override diff -r eb2d35a91b0d -r 86fab9e2bc64 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Oct 06 11:31:34 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Oct 06 15:30:33 2008 -0400 @@ -151,6 +151,9 @@ /* bytes read on each iteration of loop */ int bytesRead; + flushed = false; + drained = false; + /* * to read, we first take stuff from the fragmentBuffer */