# HG changeset patch # User Omair Majid # Date 1221843393 14400 # Node ID da120992e52b6a2bff0a2e39cf697fdda8d1430f # Parent fe9c2599d07d051e42954a4da205ffeb3c4f15b6 2008-09-19 Omair Majid * src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java (close): Check that the line is open. (drain): Likewise. (flush): Likewise. (getFrameLength): Likewise. (getFramePosition): Likewise. (getLongFramePosition): Likewise. (getMicrosecondPosition): Likewise. (loop): Likewise. (setFramePosition): Likewise. (setLoopPoints): Likewise. (setMicrosecondPosition): Likewise. (start): Likewise. (stop): Likewise. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java (close): Likewise. (start): Likewise. (stop): Likewise. (getStream): Likewise. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java (write): Removed the check for isStarted. This function should block if the line hasnt been started. (drain): Check that the line is open. (flush): Likewise. (close): Likewise. * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java (close): Likewise. (open): Check that the line isnt already open. (read): Removed check for line being started before a call to read. (drain): Check that the line is open. (flush): Likewise. (available): Likewise. * unittests/org/classpath/icedtea/pulseaudio/OtherSoundProvidersAvailableTest.java (suite): Removed function. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java (suite): Likewise. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioEventLoopOverhead.java (suite): Likewise. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerProviderTest.java (suite): Likewise. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java (suite): Likewise. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java (testStartAndStopEventsOnCork): Ignore this function in running the junit test. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java (suite): Removed function. (testStartOnClosedLine): New function. (testStopOnClosedLine): Likewise. (testDrainWithoutOpen): Likewise. (testFlushWihtoutOpen): Likewise. (testMixerKnowsAboutOpen2Lines): Likewise. (testMixerKnowsAboutOpen3Lines): Likewise. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java (suite): Removed function. (testDrainWithoutOpen): New function. (testFlush): Likewise. (testFlushWithoutOpen): Likewise. diff -r fe9c2599d07d -r da120992e52b src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Thu Sep 18 11:37:51 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Sep 19 12:56:33 2008 -0400 @@ -187,6 +187,10 @@ @Override public void close() { + if (!isOpen) { + throw new IllegalStateException("line already closed"); + } + try { clipThread.join(); } catch (InterruptedException e) { @@ -202,6 +206,10 @@ @Override public void drain() { + if (!isOpen) { + throw new IllegalStateException("line not open"); + } + Operation operation; synchronized (eventLoop.threadLock) { @@ -215,6 +223,10 @@ @Override public void flush() { + if (!isOpen) { + throw new IllegalStateException("line not open"); + } + Operation operation; synchronized (eventLoop.threadLock) { operation = stream.flush(); @@ -226,16 +238,28 @@ @Override public int getFrameLength() { + if (!isOpen) { + return AudioSystem.NOT_SPECIFIED; + } + return frameCount; } @Override public int getFramePosition() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + return (int) framesSinceOpen; } @Override public long getLongFramePosition() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + synchronized (clipLock) { return framesSinceOpen; } @@ -253,6 +277,10 @@ @Override public long getMicrosecondPosition() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + synchronized (clipLock) { return framesSinceOpen / currentFormat.getFrameSize(); } @@ -260,6 +288,9 @@ @Override public void loop(int count) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } System.out.println("Loop " + count + " called"); @@ -346,6 +377,9 @@ @Override public void setFramePosition(int frames) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } if (frames > frameCount) { throw new IllegalArgumentException("incorreft frame value"); @@ -359,6 +393,10 @@ @Override public void setLoopPoints(int start, int end) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + if (end == -1) { end = frameCount; } @@ -377,6 +415,10 @@ @Override public void setMicrosecondPosition(long microseconds) { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + float frameIndex = microseconds * currentFormat.getFrameRate(); synchronized (clipLock) { currentFrame = (int) frameIndex; @@ -386,6 +428,10 @@ @Override public void start() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + if (isStarted) { throw new IllegalStateException("already started"); } @@ -402,6 +448,10 @@ } public void stop() { + if (!isOpen) { + throw new IllegalStateException("Line not open"); + } + if (!isStarted) { throw new IllegalStateException("not started, so cant stop"); } diff -r fe9c2599d07d -r da120992e52b src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Thu Sep 18 11:37:51 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Sep 19 12:56:33 2008 -0400 @@ -160,7 +160,7 @@ } catch (LineUnavailableException e) { // error connecting to the server! - // FIXME clean up + // FIXME clean up throw e; } this.bufferSize = bufferSize; @@ -191,6 +191,10 @@ } public void close() { + if (!isOpen) { + throw new IllegalStateException( + "Line must be open for close() to work"); + } synchronized (eventLoop.threadLock) { drain(); @@ -208,10 +212,19 @@ } public void start() { + if (!isOpen) { + throw new IllegalStateException( + "Line must be open()ed before it can be start()ed"); + } + isStarted = true; } public void stop() { + if (!isOpen) { + throw new IllegalStateException( + "Line must be open()ed before it can be start()ed"); + } isStarted = false; } @@ -244,6 +257,10 @@ public abstract void drain(); public Stream getStream() { + if (!isOpen) { + throw new IllegalStateException("Line must be open"); + } + return stream; } diff -r fe9c2599d07d -r da120992e52b src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Thu Sep 18 11:37:51 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Sep 19 12:56:33 2008 -0400 @@ -67,6 +67,7 @@ this.volume = PulseAudioVolumeControl.MAX_VOLUME; } + @Override public void open(AudioFormat format, int bufferSize) throws LineUnavailableException { @@ -114,15 +115,12 @@ @Override public int write(byte[] data, int offset, int length) { - + // can't call write() without open()ing first, but can call write() + // without start()ing if (!isOpen) { throw new IllegalStateException("must call open() before write()"); } - if (!isStarted) { - throw new IllegalStateException("must call start() before write()"); - } - int frameSize = currentFormat.getFrameSize(); if (length % frameSize != 0) { throw new IllegalArgumentException( @@ -224,6 +222,12 @@ @Override public void drain() { + if (!isOpen) { + throw new IllegalStateException( + "Line must be open before it can be drain()ed"); + + } + Operation operation; synchronized (eventLoop.threadLock) { @@ -237,6 +241,11 @@ @Override public void flush() { + if (!isOpen) { + throw new IllegalStateException( + "Line must be open before it can be flush()ed"); + } + Operation operation; synchronized (eventLoop.threadLock) { operation = stream.flush(); @@ -249,6 +258,10 @@ @Override public void close() { + if (!isOpen) { + throw new IllegalStateException("not open so cant close"); + } + PulseAudioMixer parent = PulseAudioMixer.getInstance(); parent.removeSourceLine(this); diff -r fe9c2599d07d -r da120992e52b src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Thu Sep 18 11:37:51 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Sep 19 12:56:33 2008 -0400 @@ -59,6 +59,11 @@ @Override public void close() { + if (!isOpen) { + throw new IllegalStateException( + "Line cant be closed if it isnt open"); + } + PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); parentMixer.removeTargetLine(this); @@ -68,6 +73,10 @@ @Override public void open(AudioFormat format, int bufferSize) throws LineUnavailableException { + if (isOpen) { + throw new IllegalStateException("already open"); + } + super.open(format, bufferSize); PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); @@ -89,10 +98,6 @@ throw new IllegalStateException("must call open() before read()"); } - if (!isStarted) { - throw new IllegalStateException("must call start() before read()"); - } - int frameSize = currentFormat.getFrameSize(); if (length % frameSize != 0) { @@ -141,22 +146,36 @@ @Override public void drain() { + + if (!isOpen) { + throw new IllegalStateException("must call open() before drain()"); + } + // blocks when there is data on the line // http://www.jsresources.org/faq_audio.html#stop_drain_tdl while (isStarted) { try { Thread.sleep(100); - } catch (InterruptedException e) { } + } catch (InterruptedException e) { + } } } @Override public void flush() { + if (!isOpen) { + throw new IllegalStateException("Line must be open"); + } + // FIXME how to flush a target data line } public int available() { + if (!isOpen) { + throw new IllegalStateException("Line must be open"); + } + synchronized (eventLoop.threadLock) { return stream.getReableSize(); } diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/OtherSoundProvidersAvailableTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/OtherSoundProvidersAvailableTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/OtherSoundProvidersAvailableTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -43,16 +43,10 @@ import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; -import junit.framework.JUnit4TestAdapter; - import org.junit.Test; public class OtherSoundProvidersAvailableTest { - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(OtherSoundProvidersAvailableTest.class); - } - @Test public void testOtherSoundProviders() { System.out.println("This tests if alsa mixers are still available"); diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -53,8 +53,6 @@ import javax.sound.sampled.Mixer; import javax.sound.sampled.UnsupportedAudioFileException; -import junit.framework.JUnit4TestAdapter; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -66,10 +64,6 @@ AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 44100f, true); - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PulseAudioClipTest.class); - } - @Before public void setUp() throws LineUnavailableException { Mixer.Info wantedMixerInfo = null; diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioEventLoopOverhead.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioEventLoopOverhead.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioEventLoopOverhead.java Fri Sep 19 12:56:33 2008 -0400 @@ -43,8 +43,6 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Mixer; -import junit.framework.JUnit4TestAdapter; - import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -52,10 +50,6 @@ public class PulseAudioEventLoopOverhead { - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PulseAudioEventLoopOverhead.class); - } - Mixer mixer; @Before diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerProviderTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerProviderTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerProviderTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -46,16 +46,10 @@ import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; -import junit.framework.JUnit4TestAdapter; - import org.junit.Test; public class PulseAudioMixerProviderTest { - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PulseAudioMixerProviderTest.class); - } - AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 44100f, true); @@ -79,17 +73,17 @@ selectedMixerInfo = info; } } - + assertNotNull(selectedMixerInfo); - System.out.println("Getting information from selected mixer:"); - System.out.println("Name: "+ selectedMixerInfo.getName()); + System.out.println("Name: " + selectedMixerInfo.getName()); System.out.println("Version: " + selectedMixerInfo.getVersion()); - + selectedMixer = AudioSystem.getMixer(selectedMixerInfo); assertNotNull(selectedMixer); - System.out.println("Implemented in class: " + selectedMixer.getClass().toString()); + System.out.println("Implemented in class: " + + selectedMixer.getClass().toString()); selectedMixer.open(); // initialize the mixer @@ -116,7 +110,7 @@ // sourceDataLine.write('a', 0, 2); sourceDataLine.close(); } - + selectedMixer.close(); } diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -47,8 +47,6 @@ import javax.sound.sampled.Port; import javax.sound.sampled.TargetDataLine; -import junit.framework.JUnit4TestAdapter; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -62,10 +60,6 @@ AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 44100f, true); - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PulseAudioMixerTest.class); - } - @Before public void setUp() throws Exception { Mixer.Info mixerInfos[] = AudioSystem.getMixerInfo(); diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -57,6 +57,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; public class PulseAudioSourceDataLineRawTest { @@ -134,6 +135,7 @@ } + @Ignore @Test public void testStartAndStopEventsOnCork() throws UnsupportedAudioFileException, IOException, diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -57,8 +57,6 @@ import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.UnsupportedAudioFileException; -import junit.framework.JUnit4TestAdapter; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -75,10 +73,6 @@ AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true); - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PulseAudioSourceDataLineTest.class); - } - @Before public void setUp() throws Exception { Mixer.Info mixerInfos[] = AudioSystem.getMixerInfo(); @@ -235,6 +229,27 @@ } + @Test(expected = IllegalStateException.class) + public void testStartOnClosedLine() throws LineUnavailableException { + SourceDataLine line; + line = (SourceDataLine) mixer.getLine(new Line.Info( + SourceDataLine.class)); + Assert.assertNotNull(line); + + line.start(); + + } + + @Test(expected = IllegalStateException.class) + public void testStopOnClosedLine() throws LineUnavailableException { + SourceDataLine line; + line = (SourceDataLine) mixer.getLine(new Line.Info( + SourceDataLine.class)); + Assert.assertNotNull(line); + + line.stop(); + } + @Test(expected = IllegalArgumentException.class) public void testPlayLessThanFrameSize() throws LineUnavailableException, UnsupportedAudioFileException, IOException { @@ -559,6 +574,16 @@ } + @Test(expected = IllegalStateException.class) + public void testDrainWithoutOpen() throws LineUnavailableException { + + SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, aSupportedFormat, 1000)); + + line.drain(); + + } + @Test public void testFlushTwice() throws LineUnavailableException { SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info( @@ -571,6 +596,15 @@ } + @Test(expected = IllegalStateException.class) + public void testFlushWithoutOpen() throws LineUnavailableException { + SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, aSupportedFormat, 1000)); + + line.flush(); + + } + @Test public void testMixerKnowsAboutOpenLines() throws LineUnavailableException { SourceDataLine sourceDataLine = (SourceDataLine) mixer @@ -579,7 +613,35 @@ Assert.assertEquals(0, mixer.getSourceLines().length); sourceDataLine.open(); Assert.assertEquals(1, mixer.getSourceLines().length); - Assert.assertEquals(sourceDataLine, mixer.getSourceLines()[0]); + Assert.assertTrue(sourceDataLine == mixer.getSourceLines()[0]); + sourceDataLine.close(); + Assert.assertEquals(0, mixer.getSourceLines().length); + + } + + @Test + public void testMixerKnowsAboutOpen2Lines() throws LineUnavailableException { + SourceDataLine sourceDataLine = (SourceDataLine) mixer + .getLine(new Line.Info(SourceDataLine.class)); + + Assert.assertEquals(0, mixer.getSourceLines().length); + sourceDataLine.open(aSupportedFormat); + Assert.assertEquals(1, mixer.getSourceLines().length); + Assert.assertTrue(sourceDataLine == mixer.getSourceLines()[0]); + sourceDataLine.close(); + Assert.assertEquals(0, mixer.getSourceLines().length); + + } + + @Test + public void testMixerKnowsAboutOpen3Lines() throws LineUnavailableException { + SourceDataLine sourceDataLine = (SourceDataLine) mixer + .getLine(new Line.Info(SourceDataLine.class)); + + Assert.assertEquals(0, mixer.getSourceLines().length); + sourceDataLine.open(aSupportedFormat, 10000); + Assert.assertEquals(1, mixer.getSourceLines().length); + Assert.assertTrue(sourceDataLine == mixer.getSourceLines()[0]); sourceDataLine.close(); Assert.assertEquals(0, mixer.getSourceLines().length); diff -r fe9c2599d07d -r da120992e52b unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java Thu Sep 18 11:37:51 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java Fri Sep 19 12:56:33 2008 -0400 @@ -52,11 +52,10 @@ import javax.sound.sampled.TargetDataLine; import javax.sound.sampled.UnsupportedAudioFileException; -import junit.framework.JUnit4TestAdapter; - import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; public class PulseAudioTargetDataLineTest { @@ -64,13 +63,12 @@ private Mixer mixer; private TargetDataLine targetDataLine; + int started = 0; + int stopped = 0; + AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true); - public static junit.framework.Test suite() { - return new JUnit4TestAdapter(PulseAudioTargetDataLineTest.class); - } - @Before public void setUp() throws LineUnavailableException { Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo(); @@ -85,6 +83,8 @@ Assert.assertNotNull(mixer); mixer.open(); targetDataLine = null; + started = 0; + stopped = 0; } @@ -179,6 +179,37 @@ } } + @Test(expected = IllegalStateException.class) + public void testDrainWihtoutOpen() throws LineUnavailableException { + System.out + .println("This test checks that drain() fails on a line not opened"); + + targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info( + TargetDataLine.class)); + Assert.assertNotNull(targetDataLine); + + targetDataLine.drain(); + + } + + @Ignore + @Test + public void testFlush() { + + } + + @Test(expected = IllegalStateException.class) + public void testFlushWithoutOpen() throws LineUnavailableException { + System.out + .println("This test checks that drain() fails on a line not opened"); + + targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info( + TargetDataLine.class)); + Assert.assertNotNull(targetDataLine); + + targetDataLine.flush(); + } + @Test public void testCloseEvents() throws LineUnavailableException { targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info( @@ -204,9 +235,6 @@ } - int started = 0; - int stopped = 0; - @Test public void testStartedStopped() throws LineUnavailableException, UnsupportedAudioFileException, IOException, InterruptedException { @@ -256,9 +284,6 @@ Assert.assertEquals(1, started); Assert.assertEquals(1, stopped); - started = 0; - stopped = 0; - } @Test