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

Omair Majid omajid at redhat.com
Fri Sep 12 13:40:24 PDT 2008


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

	    * src/java/org/classpath/icedtea/pulseaudio/Eventloop.java
	    Fixed static initializer. Removed debug output from static initializer.
	    * src/java/org/classpath/icedtea/pulseaudio/Operation.java
	    Likewise.
	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java
	    Likewise.
	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java
	    Likewise.
	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java
	    Likewise.
	    * src/java/org/classpath/icedtea/pulseaudio/Stream.java
	    Likewise.
	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java
	    Likewise.

	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
	    Added staticSourceLineInfos and staticTargetLineInfos to store Line.Info
	    objects which are initialized only in the constructor. sourceLineInfos and
	    targetLineInfos are now rebuilt whenever the mixer is opened.
	    (PulseAudioMixer): Initialize static{Source,Target}LineInfos.
	    (close): Call refreshSourceAndTargetLines to remove the Ports.
	    (open): Likewise.
	    (refreshSourceAndTargetLines): clear the {source,target}LineInfos and use
	    the static version to initialize new ones.

	    * unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java
	    (testTargetLinesExist): Now tests for the existance of Port and
	    TargetDataLine.
	    (testSaneNumberOfPorts): New test. Checks that not too many ports are
	    exported (which whould be a bug).
	    (testGetTargetPortInfo): Now checks that the object is a Port and is not a
	    source port.
	    (testGetSourcePortInfo): Now checks that the ojbect is a Port ans is not a
	    target port.

diffstat:

9 files changed, 177 insertions(+), 61 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/EventLoop.java               |    4 
src/java/org/classpath/icedtea/pulseaudio/Operation.java               |    4 
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java         |   32 +-
src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java          |   17 +
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java    |   15 +
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java    |   15 +
src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java |    4 
src/java/org/classpath/icedtea/pulseaudio/Stream.java                  |    4 
unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java    |  143 ++++++----

diffs (439 lines):

diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/EventLoop.java
--- a/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java	Fri Sep 12 12:44:34 2008 -0400
@@ -110,8 +110,8 @@ public class EventLoop implements Runnab
 			String library = new java.io.File(".").getCanonicalPath()
 					+ java.io.File.separatorChar
 					+ System.mapLibraryName("pulse-java");
-			System.out.println(EventLoop.class.getCanonicalName() + ": "
-					+ library);
+			// System.out.println(EventLoop.class.getCanonicalName() + ": "
+			//					+ library);
 			System.load(library);
 		} catch (IOException e) {
 			assert ("Loading failed".endsWith("library"));
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/Operation.java
--- a/src/java/org/classpath/icedtea/pulseaudio/Operation.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/Operation.java	Fri Sep 12 12:44:34 2008 -0400
@@ -63,8 +63,8 @@ public class Operation {
 			String library = new java.io.File(".").getCanonicalPath()
 					+ java.io.File.separatorChar
 					+ System.mapLibraryName("pulse-java");
-			System.out.println(Operation.class.getCanonicalName() + ": "
-					+ library);
+			// System.out.println(Operation.class.getCanonicalName() + ": "
+			// + library);
 			System.load(library);
 		} catch (IOException e) {
 			assert ("Loading failed".endsWith("library"));
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Fri Sep 12 12:44:34 2008 -0400
@@ -71,7 +71,10 @@ public class PulseAudioMixer implements 
 	public Thread eventLoopThread;
 
 	private List<Line.Info> sourceLineInfos = new ArrayList<Line.Info>();
+	private List<Line.Info> staticSourceLineInfos = new ArrayList<Line.Info>();
+
 	private List<Line.Info> targetLineInfos = new ArrayList<Line.Info>();
+	private List<Line.Info> staticTargetLineInfos = new ArrayList<Line.Info>();
 
 	private static PulseAudioMixer _instance = null;
 
@@ -88,15 +91,15 @@ public class PulseAudioMixer implements 
 	private PulseAudioMixer() {
 		AudioFormat[] formats = getSupportedFormats();
 
-		sourceLineInfos.add(new DataLine.Info(SourceDataLine.class, formats,
+		staticSourceLineInfos.add(new DataLine.Info(SourceDataLine.class,
+				formats, StreamBufferAttributes.MIN_VALUE,
+				StreamBufferAttributes.MAX_VALUE));
+		staticSourceLineInfos.add(new DataLine.Info(Clip.class, formats,
 				StreamBufferAttributes.MIN_VALUE,
 				StreamBufferAttributes.MAX_VALUE));
-		sourceLineInfos.add(new DataLine.Info(Clip.class, formats,
-				StreamBufferAttributes.MIN_VALUE,
-				StreamBufferAttributes.MAX_VALUE));
-
-		targetLineInfos.add(new DataLine.Info(TargetDataLine.class, formats,
-				StreamBufferAttributes.MIN_VALUE,
+
+		staticTargetLineInfos.add(new DataLine.Info(TargetDataLine.class,
+				formats, StreamBufferAttributes.MIN_VALUE,
 				StreamBufferAttributes.MAX_VALUE));
 
 	}
@@ -442,6 +445,8 @@ public class PulseAudioMixer implements 
 		synchronized (lineListeners) {
 			lineListeners.clear();
 		}
+		
+		refreshSourceAndTargetLines();
 
 	}
 
@@ -592,6 +597,8 @@ public class PulseAudioMixer implements 
 		// sourceLineInfo and targetLineInfo need to be updated with
 		// port infos, which can only be obtained after EventLoop had started
 
+		refreshSourceAndTargetLines();
+
 		for (String portName : eventLoop.updateSourcePortNameList()) {
 			sourceLineInfos.add(new Port.Info(Port.class, portName, true));
 		}
@@ -680,4 +687,15 @@ public class PulseAudioMixer implements 
 		targetLines.remove(line);
 	}
 
+	void refreshSourceAndTargetLines() {
+
+		sourceLineInfos.clear();
+		targetLineInfos.clear();
+
+		sourceLineInfos.addAll(staticSourceLineInfos);
+
+		targetLineInfos.addAll(staticTargetLineInfos);
+
+	}
+
 }
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPort.java	Fri Sep 12 12:44:34 2008 -0400
@@ -37,6 +37,8 @@ exception statement from your version.
 
 package org.classpath.icedtea.pulseaudio;
 
+import java.io.IOException;
+
 import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineUnavailableException;
@@ -63,6 +65,19 @@ public abstract class PulseAudioPort ext
 	private PulseAudioMuteControl muteControl;
 	private PulseAudioVolumeControl volumeControl;
 
+	static {
+		try {
+			String library = new java.io.File(".").getCanonicalPath()
+					+ java.io.File.separatorChar
+					+ System.mapLibraryName("pulse-java");
+			// System.out.println(PulseAudioVolumeControl.class.getCanonicalName()
+			// + ": " + library);
+			System.load(library);
+		} catch (IOException e) {
+			assert ("Loading failed".endsWith("library"));
+		}
+	}
+
 	public PulseAudioPort(String name, EventLoop eventLoop) {
 		this.name = name;
 		this.contextPointer = eventLoop.getContextPointer();
@@ -75,7 +90,7 @@ public abstract class PulseAudioPort ext
 		controls.add(muteControl);
 		isOpen = true;
 
-		System.out.println("Opened Target Port " + name);
+		// System.out.println("Opened Target Port " + name);
 	}
 
 	public abstract byte[] native_setVolume(float newValue);
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java	Fri Sep 12 12:44:34 2008 -0400
@@ -37,9 +37,24 @@ exception statement from your version.
 
 package org.classpath.icedtea.pulseaudio;
 
+import java.io.IOException;
+
 import javax.sound.sampled.Port;
 
 public class PulseAudioSourcePort extends PulseAudioPort {
+
+	static {
+		try {
+			String library = new java.io.File(".").getCanonicalPath()
+					+ java.io.File.separatorChar
+					+ System.mapLibraryName("pulse-java");
+			// System.out.println(PulseAudioVolumeControl.class.getCanonicalName()
+			// + ": " + library);
+			System.load(library);
+		} catch (IOException e) {
+			assert ("Loading failed".endsWith("library"));
+		}
+	}
 
 	public PulseAudioSourcePort(String name, EventLoop eventLoop) {
 		super(name, eventLoop);
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java	Fri Sep 12 12:44:34 2008 -0400
@@ -37,9 +37,24 @@ exception statement from your version.
 
 package org.classpath.icedtea.pulseaudio;
 
+import java.io.IOException;
+
 import javax.sound.sampled.Port;
 
 public class PulseAudioTargetPort extends PulseAudioPort {
+
+	static {
+		try {
+			String library = new java.io.File(".").getCanonicalPath()
+					+ java.io.File.separatorChar
+					+ System.mapLibraryName("pulse-java");
+			// System.out.println(PulseAudioVolumeControl.class.getCanonicalName()
+			// + ": " + library);
+			System.load(library);
+		} catch (IOException e) {
+			assert ("Loading failed".endsWith("library"));
+		}
+	}
 
 	public PulseAudioTargetPort(String name, EventLoop eventLoop) {
 		super(name, eventLoop);
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java	Fri Sep 12 12:44:34 2008 -0400
@@ -66,8 +66,8 @@ class PulseAudioVolumeControl extends Fl
 			String library = new java.io.File(".").getCanonicalPath()
 					+ java.io.File.separatorChar
 					+ System.mapLibraryName("pulse-java");
-			System.out.println(PulseAudioVolumeControl.class.getCanonicalName()
-					+ ": " + library);
+			// System.out.println(PulseAudioVolumeControl.class.getCanonicalName()
+			// + ": " + library);
 			System.load(library);
 		} catch (IOException e) {
 			assert ("Loading failed".endsWith("library"));
diff -r b10eef873d2d -r d4bb2fa0df23 src/java/org/classpath/icedtea/pulseaudio/Stream.java
--- a/src/java/org/classpath/icedtea/pulseaudio/Stream.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/Stream.java	Fri Sep 12 12:44:34 2008 -0400
@@ -103,8 +103,8 @@ public class Stream {
 			String library = new java.io.File(".").getCanonicalPath()
 					+ java.io.File.separatorChar
 					+ System.mapLibraryName("pulse-java");
-			System.out
-					.println(Stream.class.getCanonicalName() + ": " + library);
+			// System.out
+			// .println(Stream.class.getCanonicalName() + ": " + library);
 			System.load(library);
 		} catch (IOException e) {
 			assert ("Loading failed".endsWith("library"));
diff -r b10eef873d2d -r d4bb2fa0df23 unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Fri Sep 12 11:26:43 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Fri Sep 12 12:44:34 2008 -0400
@@ -50,6 +50,7 @@ import javax.sound.sampled.Mixer;
 import javax.sound.sampled.Mixer;
 import javax.sound.sampled.Port;
 import javax.sound.sampled.TargetDataLine;
+import javax.sound.sampled.DataLine.Info;
 
 import junit.framework.JUnit4TestAdapter;
 
@@ -152,11 +153,11 @@ public class PulseAudioMixerTest {
 		Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
 		Assert.assertNotNull(allLineInfo);
 		Assert.assertTrue(allLineInfo.length > 0);
-		
+
 		boolean foundSourceDataLine = false;
 		boolean foundClip = false;
 		boolean foundPort = false;
-		
+
 		int j = 0;
 		for (Line.Info lineInfo : allLineInfo) {
 			System.out.println("Source Line " + j++ + ": "
@@ -178,34 +179,125 @@ public class PulseAudioMixerTest {
 		Assert.assertTrue("Couldnt find a SourceDataLine", foundSourceDataLine);
 		Assert.assertTrue("Couldnt find a Clip", foundClip);
 		Assert.assertTrue("Couldnt find a Port", foundPort);
-		
+
 	}
 
 	@Test
 	public void testTargetLinesExist() throws LineUnavailableException {
+		System.out.println("This tests if target Lines exist");
 		selectedMixer.open();
 		Line.Info allLineInfo[] = selectedMixer.getTargetLineInfo();
 		Assert.assertNotNull(allLineInfo);
 		Assert.assertTrue(allLineInfo.length > 0);
+
+		boolean foundTargetDataLine = false;
+		boolean foundPort = false;
+
 		int j = 0;
 		for (Line.Info lineInfo : allLineInfo) {
 			System.out.println("Target Line " + j++ + ": "
 					+ lineInfo.getLineClass());
+			if (lineInfo.getLineClass().toString().contains("TargetDataLine")) {
+				foundTargetDataLine = true;
+			} else if (lineInfo.getLineClass().toString().contains("Port")) {
+				foundPort = true;
+			} else {
+				Assert.assertTrue("Found invalid type of target line", true);
+			}
 			Line targetLine = (Line) selectedMixer.getLine(lineInfo);
 			assertNotNull(targetLine);
 
 		}
 
+		Assert.assertTrue("Couldnt find a TargetDataLine", foundTargetDataLine);
+		Assert.assertTrue("Couldnt find a target Port", foundPort);
+
+	}
+
+	@Ignore
+	@Test
+	public void testHeadphonePortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.HEADPHONE);
+	}
+
+	@Ignore
+	@Test
+	public void testSpeakerPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.SPEAKER);
+	}
+
+	@Ignore
+	@Test
+	public void testLineInPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.LINE_IN);
+	}
+
+	@Ignore
+	@Test
+	public void testCdPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.COMPACT_DISC);
+	}
+
+	@Ignore
+	@Test
+	public void testLineOutPortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.LINE_OUT);
+	}
+
+	@Ignore
+	@Test
+	public void testMicrophonePortExists() throws LineUnavailableException {
+		selectedMixer.open();
+		selectedMixer.getLine(Port.Info.MICROPHONE);
+	}
+
+	@Test
+	public void testSaneNumberOfPorts() throws LineUnavailableException {
+		System.out
+				.println("This test checks that a sane number of ports are detected");
+		selectedMixer.open();
+		Line.Info[] lineInfos = selectedMixer.getSourceLineInfo();
+		Assert.assertNotNull(lineInfos);
+
+		int ports = 0;
+		for (Line.Info info : lineInfos) {
+			if (info instanceof Port.Info) {
+				ports++;
+			}
+		}
+		Assert.assertTrue("Too few Source ports", ports > 0);
+		Assert.assertTrue("Too many Source ports... this looks wrong",
+				ports < 5);
+
+		lineInfos = selectedMixer.getTargetLineInfo();
+		ports = 0;
+		for (Line.Info info : lineInfos) {
+			if (info instanceof Port.Info) {
+				ports++;
+			}
+		}
+		Assert.assertTrue("Too few Target ports", ports > 0);
+		Assert.assertTrue("Too many Target ports... this looks wrong",
+				ports < 5);
+
 	}
 
 	@Test
 	public void testGetTargetPortInfo() throws LineUnavailableException {
+		System.out.println("This test checks target ports");
 		selectedMixer.open();
 		Line.Info[] lineInfos = selectedMixer.getTargetLineInfo();
 		int i = 0;
 		for (Line.Info info : lineInfos) {
 			if (info instanceof Port.Info) {
 				Port.Info portInfo = (Port.Info) info;
+				Assert.assertTrue(portInfo.isSource() == false);
+				Assert.assertTrue(portInfo.getLineClass() == Port.class);
 				System.out.println("Port " + ++i + ": " + portInfo.getName()
 						+ " - " + portInfo.getLineClass());
 			}
@@ -215,59 +307,20 @@ public class PulseAudioMixerTest {
 
 	@Test
 	public void testGetSourcePortInfo() throws LineUnavailableException {
+		System.out.println("This test checks source ports");
 		selectedMixer.open();
 		Line.Info[] lineInfos = selectedMixer.getSourceLineInfo();
 		int i = 0;
 		for (Line.Info info : lineInfos) {
 			if (info instanceof Port.Info) {
 				Port.Info portInfo = (Port.Info) info;
+				Assert.assertTrue(portInfo.isSource() == true);
+				Assert.assertTrue(portInfo.getLineClass() == Port.class);
 				System.out.println("Port " + ++i + ": " + portInfo.getName()
 						+ " - " + portInfo.getLineClass());
 			}
 		}
 
-	}
-
-	@Ignore
-	@Test
-	public void testHeadphonePortExists() throws LineUnavailableException {
-		selectedMixer.open();
-		selectedMixer.getLine(Port.Info.HEADPHONE);
-	}
-
-	@Ignore
-	@Test
-	public void testSpeakerPortExists() throws LineUnavailableException {
-		selectedMixer.open();
-		selectedMixer.getLine(Port.Info.SPEAKER);
-	}
-
-	@Ignore
-	@Test
-	public void testLineInPortExists() throws LineUnavailableException {
-		selectedMixer.open();
-		selectedMixer.getLine(Port.Info.LINE_IN);
-	}
-
-	@Ignore
-	@Test
-	public void testCdPortExists() throws LineUnavailableException {
-		selectedMixer.open();
-		selectedMixer.getLine(Port.Info.COMPACT_DISC);
-	}
-
-	@Ignore
-	@Test
-	public void testLineOutPortExists() throws LineUnavailableException {
-		selectedMixer.open();
-		selectedMixer.getLine(Port.Info.LINE_OUT);
-	}
-
-	@Ignore
-	@Test
-	public void testMicrophonePortExists() throws LineUnavailableException {
-		selectedMixer.open();
-		selectedMixer.getLine(Port.Info.MICROPHONE);
 	}
 
 	@Test(expected = IllegalStateException.class)



More information about the distro-pkg-dev mailing list