changeset in /hg/pulseaudio: 2008-09-19 Omair Majid <omajid at redh...

Omair Majid omajid at redhat.com
Fri Sep 19 09:57:02 PDT 2008


changeset da120992e52b in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=da120992e52b
description:
	2008-09-19 Omair Majid <omajid at redhat.com>

	    * 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.

diffstat:

12 files changed, 225 insertions(+), 67 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java                    |   50 ++++++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java                |   19 ++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java          |   23 ++-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java          |   29 +++
unittests/org/classpath/icedtea/pulseaudio/OtherSoundProvidersAvailableTest.java |    6 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java               |    6 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioEventLoopOverhead.java      |    6 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerProviderTest.java      |   20 --
unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java              |    6 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java  |    2 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java     |   76 +++++++++-
unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java     |   49 ++++--

diffs (truncated from 711 to 500 lines):

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 @@ public class PulseAudioClip extends Puls
 
 	@Override
 	public void close() {
+		if (!isOpen) {
+			throw new IllegalStateException("line already closed");
+		}
+
 		try {
 			clipThread.join();
 		} catch (InterruptedException e) {
@@ -202,6 +206,10 @@ public class PulseAudioClip extends Puls
 
 	@Override
 	public void drain() {
+		if (!isOpen) {
+			throw new IllegalStateException("line not open");
+		}
+
 		Operation operation;
 
 		synchronized (eventLoop.threadLock) {
@@ -215,6 +223,10 @@ public class PulseAudioClip extends Puls
 
 	@Override
 	public void flush() {
+		if (!isOpen) {
+			throw new IllegalStateException("line not open");
+		}
+
 		Operation operation;
 		synchronized (eventLoop.threadLock) {
 			operation = stream.flush();
@@ -226,16 +238,28 @@ public class PulseAudioClip extends Puls
 
 	@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 @@ public class PulseAudioClip extends Puls
 
 	@Override
 	public long getMicrosecondPosition() {
+		if (!isOpen) {
+			throw new IllegalStateException("Line not open");
+		}
+
 		synchronized (clipLock) {
 			return framesSinceOpen / currentFormat.getFrameSize();
 		}
@@ -260,6 +288,9 @@ public class PulseAudioClip extends Puls
 
 	@Override
 	public void loop(int count) {
+		if (!isOpen) {
+			throw new IllegalStateException("Line not open");
+		}
 
 		System.out.println("Loop " + count + " called");
 
@@ -346,6 +377,9 @@ public class PulseAudioClip extends Puls
 
 	@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 @@ public class PulseAudioClip extends Puls
 
 	@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 @@ public class PulseAudioClip extends Puls
 
 	@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 @@ public class PulseAudioClip extends Puls
 
 	@Override
 	public void start() {
+		if (!isOpen) {
+			throw new IllegalStateException("Line not open");
+		}
+
 		if (isStarted) {
 			throw new IllegalStateException("already started");
 		}
@@ -402,6 +448,10 @@ public class PulseAudioClip extends Puls
 	}
 
 	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 @@ public abstract class PulseAudioDataLine
 
 		} catch (LineUnavailableException e) {
 			// error connecting to the server!
-			// FIXME clean up 
+			// FIXME clean up
 			throw e;
 		}
 		this.bufferSize = bufferSize;
@@ -191,6 +191,10 @@ public abstract class PulseAudioDataLine
 	}
 
 	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 abstract class PulseAudioDataLine
 	}
 
 	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 class PulseAudioDataLine
 	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 @@ public class PulseAudioSourceDataLine ex
 		this.volume = PulseAudioVolumeControl.MAX_VOLUME;
 	}
 
+	@Override
 	public void open(AudioFormat format, int bufferSize)
 			throws LineUnavailableException {
 
@@ -114,13 +115,10 @@ public class PulseAudioSourceDataLine ex
 
 	@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();
@@ -224,6 +222,12 @@ public class PulseAudioSourceDataLine ex
 
 	@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 @@ public class PulseAudioSourceDataLine ex
 
 	@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 @@ public class PulseAudioSourceDataLine ex
 
 	@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 @@ public class PulseAudioTargetDataLine ex
 
 	@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 @@ public class PulseAudioTargetDataLine ex
 	@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();
@@ -87,10 +96,6 @@ public class PulseAudioTargetDataLine ex
 
 		if (!isOpen) {
 			throw new IllegalStateException("must call open() before read()");
-		}
-
-		if (!isStarted) {
-			throw new IllegalStateException("must call start() before read()");
 		}
 
 		int frameSize = currentFormat.getFrameSize();
@@ -141,22 +146,36 @@ public class PulseAudioTargetDataLine ex
 
 	@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,15 +43,9 @@ import javax.sound.sampled.Mixer;
 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() {
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.Mixer;
 import javax.sound.sampled.UnsupportedAudioFileException;
 
-import junit.framework.JUnit4TestAdapter;
-
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -65,10 +63,6 @@ public class PulseAudioClipTest {
 	Mixer mixer;
 	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 {
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,18 +43,12 @@ import javax.sound.sampled.LineUnavailab
 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;
 import org.junit.Test;
 
 public class PulseAudioEventLoopOverhead {
-
-	public static junit.framework.Test suite() {
-		return new JUnit4TestAdapter(PulseAudioEventLoopOverhead.class);
-	}
 
 	Mixer mixer;
 
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.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 @@ public class PulseAudioMixerProviderTest
 				selectedMixerInfo = info;
 			}
 		}
-		
+
 		assertNotNull(selectedMixerInfo);
 
+		System.out.println("Getting information from selected mixer:");
+		System.out.println("Name: " + selectedMixerInfo.getName());
+		System.out.println("Version: " + selectedMixerInfo.getVersion());
 
-		System.out.println("Getting information from selected mixer:");
-		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 @@ public class PulseAudioMixerProviderTest
 			// 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.Port;
 import javax.sound.sampled.TargetDataLine;
 
-import junit.framework.JUnit4TestAdapter;
-
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -61,10 +59,6 @@ public class PulseAudioMixerTest {
 
 	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 {
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.After;
 import org.junit.Assert;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class PulseAudioSourceDataLineRawTest {
@@ -134,6 +135,7 @@ public class PulseAudioSourceDataLineRaw
 
 	}
 
+	@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.SourceDataLin
 import javax.sound.sampled.SourceDataLine;
 import javax.sound.sampled.UnsupportedAudioFileException;
 
-import junit.framework.JUnit4TestAdapter;
-



More information about the distro-pkg-dev mailing list