changeset in /hg/pulseaudio: 2008-08-27 Omair Majid <omajid at redh...

Omair Majid omajid at redhat.com
Wed Aug 27 09:05:26 PDT 2008


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

	    * src/java/org/classpath/icedtea/pusleaudio/PulseAudioDataLine.java
	    Inherit from DataLine instead of line.
	    (isRunning): Return isEngagedInIo to indicate what the function is doing.
	    (connectLine): changed modifier to protected.
	    (drain): Made method public.

	    * src/java/org/classapth/icedtea/pulseaudio/PulseAudioMixer.java
	    (getSourceLines): Changed the call to the toArray function to fix the
	    ClassCastException.
	    (getTargetLines): Likewise.
	    (addSourceDataLine): New function.
	    (removeSourceDataLine): Likewise.
	    (addTargetDataLine): Likewise.
	    (removeTargetDataLine): Likewise.
	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
	    (open): Tell the mixer that the line has been opened.
	    (close): Tell the mixer that the line has been closed.
	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
	    (open): New function. Tell the mixer that the line has been opened.
	    (closed): New function. Tell the mixer that the line has been closed.

	    * unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java:
	    Remove uneeded imports.

	    * unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java
	    (testMixerKnowsAboutOpenLines): New funtion. Tests if the mixer knows
	    about open lines.
	    (testAllTargetLinesClosed): New funciton. Tests if all the TargetLines
	    have been closed.
	    * unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java
	    (testPlay): Drain instead of flush.
	    (testPlayLessThanFrameSize): Added a finally clause to close the line.
	    (testOpenFormat): Close the line. Fixes a resource leak.
	    (testFindLineWithFormat): Likewise.
	    (testFindLineWithWrongFormat): Likewise.
	    (testVolumeAndMute): Likewise.
	    (testVolumeChanging): Likewise.
	    (testFramePosition): Likewise.
	    (testMixerKnowsAboutOpenLines): New function. Tests if the mixer knows
	    about open SourceDataLines.
	    (testAllSourceLinesClosed): New function. Test if all SourceDataLines have
	    been closed.
	    (messWithStreams): Fixed resource leaks

diffstat:

7 files changed, 117 insertions(+), 24 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java            |   13 +-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java               |   22 +++-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java      |   13 ++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java      |   18 +++
unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java           |    2 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java |   20 +++
unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java      |   53 +++++++---

diffs (321 lines):

diff -r 220882a984dd -r 548fa22ff716 src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Wed Aug 27 12:04:55 2008 -0400
@@ -6,12 +6,12 @@ import java.util.concurrent.Semaphore;
 
 import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.Line;
+import javax.sound.sampled.DataLine;
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
 
-public abstract class PulseAudioDataLine implements Line {
+public abstract class PulseAudioDataLine implements DataLine {
 
 	protected static final int DEFAULT_BUFFER_SIZE = StreamBufferAttributes.SANE_DEFAULT;
 	protected static final String PULSEAUDIO_FORMAT_KEY = "PulseAudioFormatKey";
@@ -182,8 +182,7 @@ public abstract class PulseAudioDataLine
 	}
 
 	public boolean isRunning() {
-		// FIXME Auto-generated method stub
-		return false;
+		return isEngagedInIo;
 	}
 
 	public void addLineListener(LineListener listener) {
@@ -200,9 +199,9 @@ public abstract class PulseAudioDataLine
 		}
 	}
 
-	abstract void connectLine(int bufferSize);
-
-	abstract void drain();
+	protected abstract void connectLine(int bufferSize);
+
+	public abstract void drain();
 
 	public boolean isOpen() {
 		return isOpen;
diff -r 220882a984dd -r 548fa22ff716 src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Aug 27 12:04:55 2008 -0400
@@ -364,8 +364,7 @@ public class PulseAudioMixer implements 
 
 	@Override
 	public Line[] getSourceLines() {
-		// return (Line[]) _sourceLines.toArray();
-		return null;
+		return (Line[]) sourceLines.toArray(new PulseAudioSourceDataLine[0]);
 
 	}
 
@@ -392,8 +391,7 @@ public class PulseAudioMixer implements 
 
 	@Override
 	public Line[] getTargetLines() {
-		// return (Line[]) _targetLines.toArray();
-		return null;
+		return (Line[]) targetLines.toArray(new TargetDataLine[0]);
 	}
 
 	@Override
@@ -663,4 +661,20 @@ public class PulseAudioMixer implements 
 
 	}
 
+	void addSourceDataLine(PulseAudioSourceDataLine line) {
+		sourceLines.add(line);
+	}
+
+	void removeSourceDataLine(PulseAudioSourceDataLine line) {
+		sourceLines.remove(line);
+	}
+
+	void addTargetDataLine(PulseAudioTargetDataLine line) {
+		targetLines.add(line);
+	}
+
+	void removeTargetDataLine(PulseAudioTargetDataLine line) {
+		targetLines.remove(line);
+	}
+
 }
diff -r 220882a984dd -r 548fa22ff716 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Wed Aug 27 12:04:55 2008 -0400
@@ -97,6 +97,10 @@ public class PulseAudioSourceDataLine ex
 		controls[0] = volumeControl;
 		muteControl = new PulseAudioStreamMuteControl(this);
 		controls[1] = muteControl;
+		
+		PulseAudioMixer parentMixer = PulseAudioMixer.getInstance();
+		parentMixer.addSourceDataLine(this);
+		System.out.println("PulseAudioSourceDataLine: adding to mixer");
 
 	}
 
@@ -275,4 +279,13 @@ public class PulseAudioSourceDataLine ex
 		return stream;
 	}
 
+	@Override
+	public void close() {
+		PulseAudioMixer parent = PulseAudioMixer.getInstance();
+		parent.removeSourceDataLine(this);
+		System.out.println("PulseAudioSourceDataLine: removing from mixer");
+
+		super.close();
+	}
+
 }
diff -r 220882a984dd -r 548fa22ff716 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java	Wed Aug 27 12:04:55 2008 -0400
@@ -44,6 +44,7 @@ import javax.sound.sampled.Control;
 import javax.sound.sampled.Control;
 import javax.sound.sampled.DataLine;
 import javax.sound.sampled.LineListener;
+import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.TargetDataLine;
 import javax.sound.sampled.Control.Type;
 
@@ -63,6 +64,23 @@ public class PulseAudioTargetDataLine ex
 		this.defaultFormat = defaultFormat;
 		this.currentFormat = defaultFormat;
 
+	}
+
+	@Override
+	public void close() {
+		PulseAudioMixer parentMixer = PulseAudioMixer.getInstance();
+		parentMixer.removeTargetDataLine(this);
+		
+		super.close();
+	}
+
+	@Override
+	public void open(AudioFormat format, int bufferSize)
+			throws LineUnavailableException {
+		super.open(format, bufferSize);
+		
+		PulseAudioMixer parentMixer = PulseAudioMixer.getInstance();
+		parentMixer.addTargetDataLine(this);
 	}
 
 	protected void connectLine(int bufferSize) {
diff -r 220882a984dd -r 548fa22ff716 unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java	Wed Aug 27 12:04:55 2008 -0400
@@ -44,11 +44,9 @@ import javax.sound.sampled.AudioInputStr
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.Clip;
-import javax.sound.sampled.DataLine;
 import javax.sound.sampled.Line;
 import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.Mixer;
-import javax.sound.sampled.SourceDataLine;
 import javax.sound.sampled.UnsupportedAudioFileException;
 
 import junit.framework.JUnit4TestAdapter;
diff -r 220882a984dd -r 548fa22ff716 unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java	Wed Aug 27 12:04:55 2008 -0400
@@ -127,6 +127,26 @@ public class PulseAudioTargetDataLineTes
 		targetDataLine.removeLineListener(closeListener);
 
 	}
+	
+	
+	@Test
+	public void testMixerKnowsAboutOpenLines() throws LineUnavailableException {
+		targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info(
+				TargetDataLine.class));
+		
+		Assert.assertEquals(0, mixer.getTargetLines().length);
+		targetDataLine.open();
+		Assert.assertEquals(1, mixer.getTargetLines().length);
+		targetDataLine.close();
+		Assert.assertEquals(0, mixer.getTargetLines().length);
+		
+	}
+	
+	@Test
+	public void testAllTargetLinesClosed() {
+		Assert.assertEquals(0, mixer.getTargetLines().length);
+		
+	}
 
 	@After
 	public void tearDown() {
diff -r 220882a984dd -r 548fa22ff716 unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java	Mon Aug 25 17:27:52 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java	Wed Aug 27 12:04:55 2008 -0400
@@ -147,8 +147,9 @@ public class PulseSourceDataLineTest {
 		}
 		System.out.println("done");
 
-		line.flush();
-		System.out.println("flushed");
+		line.drain();
+		System.out.println("drained");
+		line.stop();
 		line.close();
 		System.out.println("closed");
 
@@ -172,10 +173,13 @@ public class PulseSourceDataLineTest {
 
 		line.open();
 		line.start();
-		line.write(data, 0, 1);
-		line.stop();
-		line.close();
-
+		try {
+			line.write(data, 0, 1);
+		} finally {
+			line.drain();
+			line.stop();
+			line.close();
+		}
 	}
 
 	@Test
@@ -198,6 +202,7 @@ public class PulseSourceDataLineTest {
 		Assert.assertNotNull(line);
 		line.open();
 		Assert.assertTrue(line.getFormat().matches(audioFormat));
+		line.close();
 	}
 
 	@Test
@@ -211,6 +216,7 @@ public class PulseSourceDataLineTest {
 				SourceDataLine.class, wantedFormat));
 		line.open();
 		System.out.println(line.getFormat());
+		line.close();
 
 	}
 
@@ -223,7 +229,7 @@ public class PulseSourceDataLineTest {
 						AudioFormat.Encoding.PCM_UNSIGNED, 44100, 10000, 1, 13,
 						10, true)));
 		line.open();
-
+		line.close();
 	}
 
 	@Test
@@ -263,7 +269,8 @@ public class PulseSourceDataLineTest {
 			}
 		}
 
-		line.flush();
+		line.drain();
+		line.close();
 		selectedMixer.close();
 
 	}
@@ -302,7 +309,8 @@ public class PulseSourceDataLineTest {
 			}
 		}
 
-		line.flush();
+		line.drain();
+		line.close();
 		selectedMixer.close();
 
 	}
@@ -421,7 +429,8 @@ public class PulseSourceDataLineTest {
 			}
 		}
 
-		line.flush();
+		line.drain();
+		line.stop();
 		System.out.println("time position: " + line.getMicrosecondPosition());
 		Assert.assertEquals(6199, line.getMicrosecondPosition());
 		line.close();
@@ -462,9 +471,28 @@ public class PulseSourceDataLineTest {
 	}
 
 	@Test
+	public void testMixerKnowsAboutOpenLines() throws LineUnavailableException {
+		SourceDataLine sourceDataLine = (SourceDataLine) mixer
+				.getLine(new Line.Info(SourceDataLine.class));
+
+		Assert.assertEquals(0, mixer.getSourceLines().length);
+		sourceDataLine.open();
+		Assert.assertEquals(1, mixer.getSourceLines().length);
+		sourceDataLine.close();
+		Assert.assertEquals(0, mixer.getSourceLines().length);
+
+	}
+
+	@Test
+	public void testAllSourceLinesClosed() {
+		Assert.assertEquals(0, mixer.getSourceLines().length);
+
+	}
+
+	@Test
 	public void messWithStreams() throws LineUnavailableException {
 		System.out
-				.println("This test tries to cork(false) a stream which hasnt been corked");
+				.println("This test tries to unCork a stream which hasnt been corked");
 
 		PulseAudioSourceDataLine line = (PulseAudioSourceDataLine) mixer
 				.getLine(new DataLine.Info(SourceDataLine.class,
@@ -478,6 +506,9 @@ public class PulseSourceDataLineTest {
 			o = s.unCork();
 		}
 		o.waitForCompletion();
+		o.releaseReference();
+		line.stop();
+		line.close();
 	}
 
 	@After



More information about the distro-pkg-dev mailing list