# HG changeset patch # User Omair Majid # Date 1222365241 14400 # Node ID 9c11cbf114f3895453d667ab59a2e598c5b08357 # Parent 4e1873a3f88f03aa5900673165f7de8731594b8a 2008-09-25 Omair Majid * src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fixed code formatting. (open): Changed modifier from public to protected. PulseAudioClip wont expose this meaningless (for a Clip) function. (createStream): Changed modifier from public to private. Dont want this function exposed. (addStreamListeners): Likewise. (connect): Likewise. (open): Changed modifier from public to proected. Dont want this method exposed for all subclasses of PulseAudioDataLine. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java (open): Removed redundant method. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java (open): New function. Implements a required function for SourceDataLine interface. Previous implementation was through DataLine.open which was made protected. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java (open): New function. Implements a required function for TargetDataLine interface. Previous implementation was through DataLine.open which was made protected. (connectLine): Change modifier to protected. diff -r 4e1873a3f88f -r 9c11cbf114f3 src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Thu Sep 25 11:44:25 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Thu Sep 25 13:54:01 2008 -0400 @@ -77,21 +77,19 @@ protected Stream stream; private ArrayList synchronizedLines; - public void open(AudioFormat format, int bufferSize) + protected void open(AudioFormat format, int bufferSize) throws LineUnavailableException { if (isOpen) { - throw new IllegalStateException("DataLine is already open"); + throw new IllegalStateException("Line is already open"); } createStream(format); - addStreamListeners(); connect(null, bufferSize); - } - public void createStream(AudioFormat format) + private void createStream(AudioFormat format) throws LineUnavailableException { for (AudioFormat myFormat : supportedFormats) { @@ -104,7 +102,7 @@ } currentFormat = format; - super.open(); + isOpen = true; } } @@ -112,11 +110,11 @@ throw new IllegalArgumentException("Invalid format"); } - System.out.println("Stream " + stream + " created"); + // System.out.println("Stream " + stream + " created"); } - public void addStreamListeners() { + private void addStreamListeners() { Stream.StateListener openCloseListener = new Stream.StateListener() { @Override @@ -124,7 +122,7 @@ synchronized (eventLoop.threadLock) { /* - * Not the order: first we notify all the listeners, and + * Note the order: first we notify all the listeners, and * then return. this means no race conditions when the * listeners are removed before they get called by close * @@ -166,7 +164,7 @@ @Override public void update() { dataWritten = false; - + if (!corked) { fireLineEvent(new LineEvent(PulseAudioDataLine.this, LineEvent.Type.STOP, AudioSystem.NOT_SPECIFIED)); @@ -214,7 +212,7 @@ stream.addCorkListener(corkListener); } - public void connect(Stream masterStream, int bufferSize) + private void connect(Stream masterStream, int bufferSize) throws LineUnavailableException { try { @@ -223,9 +221,9 @@ } } catch (LineUnavailableException e) { // error connecting to the server! - //stream.removePlaybackStartedListener(startedListener); - //stream.removeUnderflowListener(stoppedListener); - //stream.removeStateListener(openCloseListener); + // stream.removePlaybackStartedListener(startedListener); + // stream.removeUnderflowListener(stoppedListener); + // stream.removeStateListener(openCloseListener); stream.free(); stream = null; throw e; @@ -248,7 +246,7 @@ } } - public void open(AudioFormat format) throws LineUnavailableException { + protected void open(AudioFormat format) throws LineUnavailableException { open(format, DEFAULT_BUFFER_SIZE); } @@ -333,11 +331,12 @@ op.waitForCompletion(); op.releaseReference(); isStarted = true; - - /*if (dataWritten) { - fireLineEvent(new LineEvent(PulseAudioDataLine.this, - LineEvent.Type.START, AudioSystem.NOT_SPECIFIED)); - }*/ + + /* + * if (dataWritten) { fireLineEvent(new + * LineEvent(PulseAudioDataLine.this, LineEvent.Type.START, + * AudioSystem.NOT_SPECIFIED)); } + */ } diff -r 4e1873a3f88f -r 9c11cbf114f3 src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java Thu Sep 25 11:44:25 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java Thu Sep 25 13:54:01 2008 -0400 @@ -44,7 +44,6 @@ import javax.sound.sampled.Line; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineListener; -import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Control.Type; abstract class PulseAudioLine implements Line { @@ -112,13 +111,7 @@ return isOpen; } - @Override - public void open() throws LineUnavailableException { - /*if (isOpen) { - throw new IllegalStateException("Line is already open"); - }*/ - isOpen = true; - } + public void removeLineListener(LineListener listener) { lineListeners.remove(listener); diff -r 4e1873a3f88f -r 9c11cbf114f3 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Thu Sep 25 11:44:25 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Thu Sep 25 13:54:01 2008 -0400 @@ -84,6 +84,11 @@ } + @Override + public void open(AudioFormat format) throws LineUnavailableException { + open(format, DEFAULT_BUFFER_SIZE); + } + public byte[] native_setVolume(float value) { return stream.native_setVolume(value); } @@ -105,25 +110,25 @@ } - protected void connectLine(int bufferSize, Stream masterStream) throws LineUnavailableException { + protected void connectLine(int bufferSize, Stream masterStream) + throws LineUnavailableException { StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( - bufferSize, bufferSize / 4, bufferSize / 8, + bufferSize, bufferSize / 4, bufferSize / 8, ((bufferSize / 10) > 100 ? bufferSize / 10 : 100), 0); - - if(masterStream != null) { + if (masterStream != null) { synchronized (eventLoop.threadLock) { - stream.connectForPlayback(Stream.DEFAULT_DEVICE, bufferAttributes, masterStream.getStreamPointer()); + stream.connectForPlayback(Stream.DEFAULT_DEVICE, + bufferAttributes, masterStream.getStreamPointer()); } } else { synchronized (eventLoop.threadLock) { - stream.connectForPlayback(Stream.DEFAULT_DEVICE, bufferAttributes, null); + stream.connectForPlayback(Stream.DEFAULT_DEVICE, + bufferAttributes, null); } } } - - @Override public int write(byte[] data, int offset, int length) { @@ -133,11 +138,10 @@ throw new IllegalStateException("must call open() before write()"); } - - /*if (!isStarted) { - throw new IllegalStateException("must call start() before write()"); - }*/ - + /* + * if (!isStarted) { throw new IllegalStateException("must call start() + * before write()"); } + */ int frameSize = currentFormat.getFrameSize(); if (length % frameSize != 0) { @@ -158,15 +162,13 @@ int sizeWritten = 0; - - boolean interrupted = false; while (remainingLength != 0) { synchronized (eventLoop.threadLock) { availableSize = stream.getWritableSize(); - + do { if (availableSize < 0) { return sizeWritten; @@ -181,29 +183,25 @@ } } - + availableSize = stream.getWritableSize(); - //System.out.println(availableSize); - + // System.out.println(availableSize); } while (availableSize == 0); - if (availableSize > remainingLength) { availableSize = remainingLength; } /* write a little bit of the buffer */ - - stream.write(data, position, availableSize); - //System.out.println("written " + availableSize); - + + stream.write(data, position, availableSize); + // System.out.println("written " + availableSize); sizeWritten += availableSize; position += availableSize; remainingLength -= availableSize; - } } - + } // all the data should have been played by now assert (sizeWritten == length); diff -r 4e1873a3f88f -r 9c11cbf114f3 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Thu Sep 25 11:44:25 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Thu Sep 25 13:54:01 2008 -0400 @@ -80,12 +80,18 @@ super.open(format, bufferSize); currentFramePosition = 0; - + PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); parentMixer.addTargetLine(this); } - protected void connectLine(int bufferSize, Stream masterStream) throws LineUnavailableException{ + @Override + public void open(AudioFormat format) throws LineUnavailableException { + open(format, DEFAULT_BUFFER_SIZE); + } + + protected void connectLine(int bufferSize, Stream masterStream) + throws LineUnavailableException { StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( bufferSize, 0, 0, 0, bufferSize / 10); synchronized (eventLoop.threadLock) { @@ -130,7 +136,8 @@ sizeRead += bytesRead; position += bytesRead; remainingLength -= bytesRead; - currentFramePosition += bytesRead / currentFormat.getFrameSize(); + currentFramePosition += bytesRead + / currentFormat.getFrameSize(); } }