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

Omair Majid omajid at redhat.com
Fri Aug 29 13:26:28 PDT 2008


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

	    * build.xml: Removed header generation for classes with no native methods.

	    * src/java/org/classpath/icedtea/pulseaudio/EventLoop.java
	    Parameterized {target,source}PortNameList. Gets rid of a few warnings.

	    * src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
	    (writeFrames): Commented out debug output.

	    * src/java/org/claspath/icedtea/pulseaudio/PulseAudioSourcePort.java
	    (addLineListener): Implemented method.
	    (close): Commented out unimplemented stuff.
	    (nativeClose): Changed return type to long (since it can return a 64 bit
	    pointer).
	    (getControl): Implemented function.
	    (getControls): Likewise.
	    (getName): New function.
	    (isOpen): Implemented function.
	    (open): Commented out unimplemented stuff.
	    (nativeOpen): Changed return type to long.
	    (removeLineListener): Implemented function.

	    * src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c
	    (Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_nativeClose):
	    Added stub for future implementeation.
	    (Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_nativeOpen):
	    Likewise.

	    * unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
	    (testPlayTwoClips): New function. Tests
	    http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=173 .

	    * unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java
	    (testSourceLinesExist): Fixed function to work with SourcePorts as well as
	    SourceDataLines.
	    (testTargetLinesExist): Fixed function to work with
	    Target{Ports,DataLines}.
	    (testSourceLinesOpenAndClose): Fixed to work with ports and
	    sourcedatalines.
	    (testTargetLinesOpenAndClose): Fixed to work with ports and target data
	    lines.

diffstat:

8 files changed, 148 insertions(+), 67 deletions(-)
build.xml                                                           |    4 
src/java/org/classpath/icedtea/pulseaudio/EventLoop.java            |    4 
src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java       |   15 +
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java |   77 ++++++----
src/native/Makefile.am                                              |    4 
src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c  |   25 +++
unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java  |   31 ++++
unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java |   55 ++++---

diffs (417 lines):

diff -r cf375df7c7b7 -r e99d53a7bcfa build.xml
--- a/build.xml	Thu Aug 28 16:16:38 2008 -0400
+++ b/build.xml	Fri Aug 29 16:26:10 2008 -0400
@@ -38,12 +38,8 @@
 			<class name="org.classpath.icedtea.pulseaudio.EventLoop"/>
 			<class name="org.classpath.icedtea.pulseaudio.Operation"/>
 			<class name="org.classpath.icedtea.pulseaudio.Stream"/>
-			<class name="org.classpath.icedtea.pulseaudio.PulseAudioTargetDataLine"/>
-			<class name="org.classpath.icedtea.pulseaudio.PulseAudioStreamVolumeControl"/>
-			<class name="org.classpath.icedtea.pulseaudio.PulseAudioDataLine"/>
 			<class name="org.classpath.icedtea.pulseaudio.PulseAudioSourcePort"/>
 			<class name="org.classpath.icedtea.pulseaudio.PulseAudioTargetPort"/>
-			<class name="org.classpath.icedtea.pulseaudio.PulseAudioTargetPortVolumeControl"/>
 		</javah>
 	</target>
 
diff -r cf375df7c7b7 -r e99d53a7bcfa src/java/org/classpath/icedtea/pulseaudio/EventLoop.java
--- a/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java	Thu Aug 28 16:16:38 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java	Fri Aug 29 16:26:10 2008 -0400
@@ -72,8 +72,8 @@ public class EventLoop implements Runnab
 
 	public Semaphore finished = new Semaphore(0);
 	
-	private List<String> targetPortNameList = new ArrayList();
-	private List<String> sourcePortNameList = new ArrayList();
+	private List<String> targetPortNameList = new ArrayList<String>();
+	private List<String> sourcePortNameList = new ArrayList<String>();
 
 	/*
 	 * JNI stuff
diff -r cf375df7c7b7 -r e99d53a7bcfa src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java	Thu Aug 28 16:16:38 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java	Fri Aug 29 16:26:10 2008 -0400
@@ -54,7 +54,8 @@ import javax.sound.sampled.LineUnavailab
 import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.Control.Type;
 
-public class PulseAudioClip extends PulseAudioDataLine implements Clip, PulseAudioPlaybackLine {
+public class PulseAudioClip extends PulseAudioDataLine implements Clip,
+		PulseAudioPlaybackLine {
 
 	private byte[] data = null;
 
@@ -130,7 +131,7 @@ public class PulseAudioClip extends Puls
 					Thread.currentThread().interrupt();
 					break;
 				}
-				System.out.println("remaining frames" + remainingFrames);
+				// System.out.println("remaining frames" + remainingFrames);
 			}
 		}
 	}
@@ -213,7 +214,7 @@ public class PulseAudioClip extends Puls
 			if (control.getClass() == BooleanControl.Type.MUTE.getClass()) {
 				return controls.get(1);
 			}
-			
+
 			if (control.getClass() == FloatControl.Type.VOLUME.getClass()) {
 				return controls.get(0);
 			}
@@ -344,17 +345,17 @@ public class PulseAudioClip extends Puls
 
 		PulseAudioVolumeControl volumeControl = new PulseAudioVolumeControl(
 				this, eventLoop);
-		PulseAudioMuteControl muteControl = new PulseAudioMuteControl(
-				this, volumeControl);
+		PulseAudioMuteControl muteControl = new PulseAudioMuteControl(this,
+				volumeControl);
 		controls.add(volumeControl);
 		controls.add(muteControl);
 
 	}
-	
+
 	public int native_setVolume(float value) {
 		return stream.native_setVolume(value);
 	}
-	
+
 	public boolean isMuted() {
 		return muted;
 	}
diff -r cf375df7c7b7 -r e99d53a7bcfa src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java	Thu Aug 28 16:16:38 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourcePort.java	Fri Aug 29 16:26:10 2008 -0400
@@ -1,4 +1,7 @@ package org.classpath.icedtea.pulseaudio
 package org.classpath.icedtea.pulseaudio;
+
+import java.util.LinkedList;
+import java.util.List;
 
 import javax.sound.sampled.Control;
 import javax.sound.sampled.LineListener;
@@ -7,48 +10,58 @@ import javax.sound.sampled.Control.Type;
 import javax.sound.sampled.Control.Type;
 
 public class PulseAudioSourcePort implements Port {
-	
+
 	private String name;
+
+	@SuppressWarnings("unused")
 	private long contextPointer;
+
 	private EventLoop eventLoop;
-	
+
+	private boolean isOpen;
+
+	private List<LineListener> lineListeners = new LinkedList<LineListener>();
+
 	public PulseAudioSourcePort(String name, EventLoop eventLoop) {
+		System.out.println("new SourcePort constructed");
 		this.name = name;
 		this.contextPointer = eventLoop.getContextPointer();
 		this.eventLoop = eventLoop;
-		System.out.println("Opened Source Port" + name);
+		System.out.println("Opened Source Port: " + name);
 	}
 
 	@Override
 	public void addLineListener(LineListener listener) {
-		// TODO Auto-generated method stub
+		synchronized (lineListeners) {
+			lineListeners.add(listener);
+		}
 	}
 
 	@Override
 	public void close() {
 		Operation operation;
 
-		synchronized (eventLoop.threadLock) {
-			operation = new Operation(nativeClose());
-		}
+//		synchronized (eventLoop.threadLock) {
+//			operation = new Operation(nativeClose());
+//		}
+//
+//		operation.waitForCompletion();
+//		operation.releaseReference();
 
-		operation.waitForCompletion();
-		operation.releaseReference();
-		
+		isOpen = false;
 	}
-	
-	private native int nativeClose();
+
+	private native long nativeClose();
 
 	@Override
 	public Control getControl(Type control) {
-		// TODO Auto-generated method stub
-		return null;
+		throw new IllegalArgumentException(control.toString()
+				+ " not supported");
 	}
 
 	@Override
 	public Control[] getControls() {
-		// TODO Auto-generated method stub
-		return null;
+		return new Control[] {};
 	}
 
 	@Override
@@ -57,36 +70,44 @@ public class PulseAudioSourcePort implem
 		return null;
 	}
 
+	public String getName() {
+		return this.name;
+
+	}
+
 	@Override
 	public boolean isControlSupported(Type control) {
-		// TODO Auto-generated method stub
 		return false;
 	}
 
 	@Override
 	public boolean isOpen() {
-		// TODO Auto-generated method stub
-		return false;
+		return isOpen;
 	}
 
 	@Override
 	public void open() throws LineUnavailableException {
+		System.out.println("SourcePort opened");
 		Operation operation;
 
-		synchronized (eventLoop.threadLock) {
-			operation = new Operation(nativeOpen());
-		}
+//		synchronized (eventLoop.threadLock) {
+//			operation = new Operation(nativeOpen());
+//		}
+//
+//		operation.waitForCompletion();
+//		operation.releaseReference();
 
-		operation.waitForCompletion();
-		operation.releaseReference();
+		isOpen = true;
 	}
-	
-	private native int nativeOpen();
+
+	private native long nativeOpen();
 
 	@Override
 	public void removeLineListener(LineListener listener) {
-		// TODO Auto-generated method stub
-		
+		synchronized (lineListeners) {
+			lineListeners.remove(listener);
+		}
+
 	}
 
 }
diff -r cf375df7c7b7 -r e99d53a7bcfa src/native/Makefile.am
--- a/src/native/Makefile.am	Thu Aug 28 16:16:38 2008 -0400
+++ b/src/native/Makefile.am	Fri Aug 29 16:26:10 2008 -0400
@@ -9,10 +9,10 @@ libpulse_java_la_SOURCES = \
 	org_classpath_icedtea_pulseaudio_Operation.c \
 	org_classpath_icedtea_pulseaudio_Stream.c \
 	org_classpath_icedtea_pulseaudio_Stream.h \
+	org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.h \
 	org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c \
-        org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.h \
 	org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.c \
-        org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.h 
+    org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.h 
 
 
  
diff -r cf375df7c7b7 -r e99d53a7bcfa src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/native/org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.c	Fri Aug 29 16:26:10 2008 -0400
@@ -0,0 +1,25 @@
+#include "org_classpath_icedtea_pulseaudio_PulseAudioSourcePort.h"
+
+#include "jni-common.h"
+
+/*
+ * Class:     org_classpath_icedtea_pulseaudio_PulseAudioSourcePort
+ * Method:    nativeClose
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_nativeClose
+(JNIEnv* env, jobject obj) {
+	return convertPointerToJavaLong(NULL);
+}
+
+/*
+ * Class:     org_classpath_icedtea_pulseaudio_PulseAudioSourcePort
+ * Method:    nativeOpen
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourcePort_nativeOpen
+(JNIEnv* env, jobject obj) {
+	return convertPointerToJavaLong(NULL);
+
+}
+
diff -r cf375df7c7b7 -r e99d53a7bcfa unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java	Thu Aug 28 16:16:38 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioClipTest.java	Fri Aug 29 16:26:10 2008 -0400
@@ -184,6 +184,37 @@ public class PulseAudioClipTest {
 
 	}
 
+	/*
+	 * 
+	 * modified version of the sample code at
+	 * http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=173
+	 * 
+	 */
+
+	@Test
+	public void testPlayTwoClips() {
+		try {
+			Clip clip1 = (Clip) mixer.getLine(new Line.Info(Clip.class));
+			File soundFile1 = new File("testsounds/startup.wav");
+			AudioInputStream audioInputStream1 = AudioSystem
+					.getAudioInputStream(soundFile1);
+			clip1.open(audioInputStream1);
+
+			Clip clip2 = (Clip) mixer.getLine(new Line.Info(Clip.class));
+			File soundFile2 = new File("testsounds/logout.wav");
+			AudioInputStream audioInputStream2 = AudioSystem
+					.getAudioInputStream(soundFile2);
+			clip2.open(audioInputStream2);
+
+			clip1.start();
+			clip2.start();
+			
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+	}
+
 	@After
 	public void tearDown() {
 
diff -r cf375df7c7b7 -r e99d53a7bcfa unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Thu Aug 28 16:16:38 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Fri Aug 29 16:26:10 2008 -0400
@@ -49,7 +49,6 @@ import javax.sound.sampled.LineUnavailab
 import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.Mixer;
 import javax.sound.sampled.Port;
-import javax.sound.sampled.SourceDataLine;
 import javax.sound.sampled.TargetDataLine;
 
 import junit.framework.JUnit4TestAdapter;
@@ -62,6 +61,9 @@ public class PulseAudioMixerTest {
 public class PulseAudioMixerTest {
 
 	PulseAudioMixer selectedMixer;
+
+	AudioFormat aSupportedFormat = new AudioFormat(
+			AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true);
 
 	public static junit.framework.Test suite() {
 		return new JUnit4TestAdapter(PulseAudioMixerTest.class);
@@ -152,9 +154,8 @@ public class PulseAudioMixerTest {
 		for (Line.Info lineInfo : allLineInfo) {
 			System.out.println("Source Line " + j++ + ": "
 					+ lineInfo.getLineClass());
-			SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer
-					.getLine(lineInfo);
-			assertNotNull(sourceDataLine);
+			Line sourceLine = (Line) selectedMixer.getLine(lineInfo);
+			assertNotNull(sourceLine);
 
 		}
 
@@ -170,9 +171,8 @@ public class PulseAudioMixerTest {
 		for (Line.Info lineInfo : allLineInfo) {
 			System.out.println("Target Line " + j++ + ": "
 					+ lineInfo.getLineClass());
-			TargetDataLine targetDataLine = (TargetDataLine) selectedMixer
-					.getLine(lineInfo);
-			assertNotNull(targetDataLine);
+			Line targetLine = (Line) selectedMixer.getLine(lineInfo);
+			assertNotNull(targetLine);
 
 		}
 
@@ -263,17 +263,17 @@ public class PulseAudioMixerTest {
 		System.out.println("This test checks if source lines open and close");
 		selectedMixer.open();
 
-		AudioFormat wantedFormat = new AudioFormat(
-				AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true);
-
 		Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
 		for (Line.Info lineInfo : allLineInfo) {
-			SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer
-					.getLine(lineInfo);
+			Line sourceLine = (Line) selectedMixer.getLine(lineInfo);
 			System.out.println("opening line");
-			sourceDataLine.open(wantedFormat);
-			System.out.println("closing line");
-			sourceDataLine.close();
+			try {
+				sourceLine.open();
+				System.out.println("closing line");
+				sourceLine.close();
+			} catch (IllegalArgumentException e) {
+				assert (sourceLine.getClass() == PulseAudioClip.class);
+			}
 		}
 	}
 
@@ -282,17 +282,24 @@ public class PulseAudioMixerTest {
 		System.out.println("This test checks if source lines open and close");
 		selectedMixer.open();
 
-		AudioFormat wantedFormat = new AudioFormat(
-				AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true);
-
 		Line.Info allLineInfo[] = selectedMixer.getTargetLineInfo();
 		for (Line.Info lineInfo : allLineInfo) {
-			TargetDataLine targetDataLine = (TargetDataLine) selectedMixer
-					.getLine(lineInfo);
-			System.out.println("opening line");
-			targetDataLine.open(wantedFormat);
-			System.out.println("closing line");
-			targetDataLine.close();
+			try {
+				TargetDataLine targetLine = (TargetDataLine) selectedMixer
+						.getLine(lineInfo);
+				Assert.assertNotNull(targetLine);
+				System.out.println("opening line");
+				targetLine.open(aSupportedFormat);
+				System.out.println("closing line");
+				targetLine.close();
+			} catch (ClassCastException cce) {
+				Port targetLine = (Port) selectedMixer.getLine(lineInfo);
+				Assert.assertNotNull(targetLine);
+				targetLine.open();
+				System.out.println("closing line");
+				targetLine.close();
+			}
+
 		}
 	}
 



More information about the distro-pkg-dev mailing list