changeset in /hg/pulseaudio: ports added

iivan at town.yyz.redhat.com iivan at town.yyz.redhat.com
Thu Aug 28 12:57:02 PDT 2008


changeset f489a16be6f1 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=f489a16be6f1
description:
	ports added

diffstat:

22 files changed, 642 insertions(+), 208 deletions(-)
ChangeLog                                                                    |    9 
build.xml                                                                    |    3 
src/java/org/classpath/icedtea/pulseaudio/EventLoop.java                     |   46 +++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java                |   46 +++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java            |   26 -
src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java                |   43 +++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java               |   52 +++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMuteControl.java         |   36 ++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioPlaybackLine.java        |   17 +
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java      |   69 ++--
src/java/org/classpath/icedtea/pulseaudio/PulseAudioStreamMuteControl.java   |   68 ----
src/java/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java |   66 ----
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java      |    2 
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java          |  140 ++++++++++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.java       |   67 ++++
src/java/org/classpath/icedtea/pulseaudio/Stream.java                        |    6 
src/native/Makefile.am                                                       |   11 
src/native/org_classpath_icedtea_pulseaudio_EventLoop.c                      |   38 ++
src/native/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c  |    1 
src/native/org_classpath_icedtea_pulseaudio_PulseAudioTargetPort.c           |   77 +++++
src/native/org_classpath_icedtea_pulseaudio_Stream.c                         |   17 +
unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java      |   10 

diffs (truncated from 1233 to 500 lines):

diff -r 1a1a426b17cc -r f489a16be6f1 ChangeLog
--- a/ChangeLog	Wed Aug 27 14:22:14 2008 -0400
+++ b/ChangeLog	Thu Aug 28 15:57:05 2008 -0400
@@ -1,3 +1,12 @@ 2008-08-13 Ioana Ivan  <iivan at redhat.com
+2008-08-13 Ioana Ivan  <iivan at redhat.com>
+
+        * src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetPort.java:
+	new class representing a targetport
+	* some refactoring in the control classes (controls for the target
+	port are now supported)
+	                
+
+
 2008-08-13 Ioana Ivan  <iivan at redhat.com>
 
         * src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java:
diff -r 1a1a426b17cc -r f489a16be6f1 build.xml
--- a/build.xml	Wed Aug 27 14:22:14 2008 -0400
+++ b/build.xml	Thu Aug 28 15:57:05 2008 -0400
@@ -41,6 +41,9 @@
 			<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 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/EventLoop.java
--- a/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java	Wed Aug 27 14:22:14 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/EventLoop.java	Thu Aug 28 15:57:05 2008 -0400
@@ -71,6 +71,9 @@ public class EventLoop implements Runnab
 	// private boolean eventLoopIsRunning = false;
 
 	public Semaphore finished = new Semaphore(0);
+	
+	private List<String> targetPortNameList = new ArrayList();
+	private List<String> sourcePortNameList = new ArrayList();
 
 	/*
 	 * JNI stuff
@@ -240,5 +243,48 @@ public class EventLoop implements Runnab
 	public long getMainLoopPointer() {
 		return mainloopPointer;
 	}
+	
+	private native int nativeUpdateTargetPortNameList();
+	private native int nativeUpdateSourcePortNameList();
+	
+	protected synchronized List<String> updateTargetPortNameList() {
+		targetPortNameList = new ArrayList<String>();
+		Operation op;
+		synchronized (this.threadLock) {
+			op = new Operation(nativeUpdateTargetPortNameList());
+		}
+
+		op.waitForCompletion();
+
+		assert (op.getState() == Operation.State.Done);
+
+		op.releaseReference();
+		return targetPortNameList;
+	}
+	
+	protected synchronized List<String> updateSourcePortNameList() {
+		sourcePortNameList = new ArrayList<String>();
+		Operation op;
+		synchronized (this.threadLock) {
+			op = new Operation(nativeUpdateSourcePortNameList());
+		}
+
+		op.waitForCompletion();
+
+		assert (op.getState() == Operation.State.Done);
+
+		op.releaseReference();
+		return sourcePortNameList;
+	}
+	
+	
+	public void source_callback(String name ) {
+		sourcePortNameList.add(name);
+	}
+
+	
+	public void sink_callback(String name ) {
+		targetPortNameList.add(name);
+	}
 
 }
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java	Wed Aug 27 14:22:14 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java	Thu Aug 28 15:57:05 2008 -0400
@@ -45,16 +45,21 @@ import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioInputStream;
 import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.BooleanControl;
 import javax.sound.sampled.Clip;
 import javax.sound.sampled.Control;
 import javax.sound.sampled.DataLine;
+import javax.sound.sampled.FloatControl;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
 import javax.sound.sampled.Control.Type;
 
-public class PulseAudioClip extends PulseAudioDataLine implements Clip {
+public class PulseAudioClip extends PulseAudioDataLine implements Clip, PulseAudioPlaybackLine {
 
 	private byte[] data = null;
+
+	private boolean muted;
+	private float volume;
 
 	// these are frame indices. so counted from 0
 	private int currentFrame = 0;
@@ -138,6 +143,8 @@ public class PulseAudioClip extends Puls
 		this.defaultFormat = defaultFormat;
 		this.currentFormat = defaultFormat;
 		clipThread = new ClipThread();
+		this.volume = PulseAudioVolumeControl.MAX_VOLUME;
+		controls = new ArrayList<Control>();
 
 	}
 
@@ -203,7 +210,13 @@ public class PulseAudioClip extends Puls
 	@Override
 	public Control getControl(Type control) {
 		if (isOpen) {
-
+			if (control.getClass() == BooleanControl.Type.MUTE.getClass()) {
+				return controls.get(1);
+			}
+			
+			if (control.getClass() == FloatControl.Type.VOLUME.getClass()) {
+				return controls.get(0);
+			}
 		}
 		throw new IllegalArgumentException(control.toString()
 				+ " not supported");
@@ -328,6 +341,35 @@ public class PulseAudioClip extends Puls
 		System.arraycopy(data, offset, this.data, 0, bufferSize);
 		frameCount = bufferSize / format.getFrameSize();
 		isOpen = true;
+
+		PulseAudioVolumeControl volumeControl = new PulseAudioVolumeControl(
+				this, eventLoop);
+		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;
+	}
+
+	public void setMuted(boolean value) {
+		muted = value;
+	}
+
+	public float getVolume() {
+		return this.volume;
+	}
+
+	public void setVolume(float value) {
+		this.volume = value;
+
 	}
 
 	@Override
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Wed Aug 27 14:22:14 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Thu Aug 28 15:57:05 2008 -0400
@@ -11,7 +11,7 @@ import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
 
-public abstract class PulseAudioDataLine implements DataLine {
+public abstract class PulseAudioDataLine extends PulseAudioLine implements DataLine {
 
 	protected static final int DEFAULT_BUFFER_SIZE = StreamBufferAttributes.SANE_DEFAULT;
 	protected static final String PULSEAUDIO_FORMAT_KEY = "PulseAudioFormatKey";
@@ -20,7 +20,7 @@ public abstract class PulseAudioDataLine
 
 	// true between open() and close(). ie represents when a line has acquire
 	// resources
-	protected boolean isOpen = false;
+
 
 	// true between start() and stop()
 	protected boolean isStarted = false;
@@ -35,8 +35,6 @@ public abstract class PulseAudioDataLine
 	protected AudioFormat defaultFormat = null;
 
 	protected int bufferSize = 0;
-
-	protected List<LineListener> lineListeners = new ArrayList<LineListener>();;
 
 	protected EventLoop eventLoop = null;
 	protected Semaphore semaphore = new Semaphore(0);
@@ -185,26 +183,16 @@ public abstract class PulseAudioDataLine
 		return isEngagedInIo;
 	}
 
-	public void addLineListener(LineListener listener) {
-		this.lineListeners.add(listener);
-	}
 
-	public void removeLineListener(LineListener listener) {
-		this.lineListeners.remove(listener);
-	}
-
-	private void fireLineEvent(LineEvent e) {
-		for (LineListener lineListener : lineListeners) {
-			lineListener.update(e);
-		}
-	}
 
 	protected abstract void connectLine(int bufferSize);
 
 	public abstract void drain();
 
-	public boolean isOpen() {
-		return isOpen;
+
+
+	public Stream getStream() {
+		return stream;
 	}
-
+	
 }
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioLine.java	Thu Aug 28 15:57:05 2008 -0400
@@ -0,0 +1,43 @@
+package org.classpath.icedtea.pulseaudio;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.sound.sampled.Control;
+import javax.sound.sampled.Line;
+import javax.sound.sampled.LineEvent;
+import javax.sound.sampled.LineListener;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Control.Type;
+
+
+abstract class PulseAudioLine {
+
+	protected List<LineListener> lineListeners = new ArrayList<LineListener>();
+	protected boolean isOpen = false;
+	
+	
+	public void addLineListener(LineListener listener) {
+		this.lineListeners.add(listener);
+	}
+
+	public void removeLineListener(LineListener listener) {
+		this.lineListeners.remove(listener);
+	}
+
+	protected void fireLineEvent(LineEvent e) {
+		for (LineListener lineListener : lineListeners) {
+			lineListener.update(e);
+		}
+	}
+	
+	public boolean isOpen() {
+		return isOpen;
+	}
+
+
+
+
+	
+
+}
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Aug 27 14:22:14 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Thu Aug 28 15:57:05 2008 -0400
@@ -52,15 +52,18 @@ import javax.sound.sampled.Clip;
 import javax.sound.sampled.Clip;
 import javax.sound.sampled.Control;
 import javax.sound.sampled.DataLine;
+import javax.sound.sampled.FloatControl;
 import javax.sound.sampled.Line;
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineListener;
 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 javax.sound.sampled.AudioFormat.Encoding;
 import javax.sound.sampled.Control.Type;
+import javax.sound.sampled.Port.Info;
 
 public class PulseAudioMixer implements javax.sound.sampled.Mixer {
 	// singleton
@@ -87,6 +90,11 @@ public class PulseAudioMixer implements 
 
 	private PulseAudioMixer() {
 		AudioFormat[] formats = getSupportedFormats();
+		List<Line.Info> sourceLineInfoList = new ArrayList<Line.Info>();
+		sourceLineInfoList.add(new DataLine.Info(
+				SourceDataLine.class, formats,
+				StreamBufferAttributes.MIN_VALUE,
+				StreamBufferAttributes.MAX_VALUE));
 		sourceLineInfos = new Line.Info[] { new DataLine.Info(
 				SourceDataLine.class, formats,
 				StreamBufferAttributes.MIN_VALUE,
@@ -327,6 +335,17 @@ public class PulseAudioMixer implements 
 			clips.add((PulseAudioClip) clip);
 			return clip;
 		}
+		
+		if ((info.getLineClass() == Port.class) ) {
+			Port.Info portInfo = (Port.Info) info;
+			if(portInfo.isSource()){
+				return new PulseAudioSourcePort(portInfo.getName(), eventLoop);
+			} else {
+				return new PulseAudioTargetPort(portInfo.getName(), eventLoop);
+			}
+		}
+		
+		
 
 		throw new IllegalArgumentException();
 
@@ -500,6 +519,23 @@ public class PulseAudioMixer implements 
 	@Override
 	public void open() throws LineUnavailableException {
 		openLocal();
+		//the sourceLineInfo and targetLineInfo arrays need to be updated with
+		//port infos, which can only be obtained after EventLoop had started
+		
+		ArrayList<Line.Info> sourceLineInfoList = new ArrayList<Line.Info>();
+		sourceLineInfoList.add(sourceLineInfos[0]);
+		for(String portName : eventLoop.updateSourcePortNameList()){
+			sourceLineInfoList.add(new Port.Info(Port.class, portName, true));
+		}
+		sourceLineInfos = sourceLineInfoList.toArray(new Line.Info[0]);
+		
+		ArrayList<Line.Info> targetLineInfoList = new ArrayList<Line.Info>();
+		targetLineInfoList.add(targetLineInfos[0]);
+		for(String portName : eventLoop.updateTargetPortNameList()){
+			targetLineInfoList.add(new Port.Info(Port.class, portName, false));
+		}
+		targetLineInfos = targetLineInfoList.toArray(new Line.Info[0]);
+		
 	}
 
 	public void open(String appName, String host) throws UnknownHostException,
@@ -650,16 +686,24 @@ public class PulseAudioMixer implements 
 		AudioInputStream audioInputStream = AudioSystem
 				.getAudioInputStream(soundFile);
 		AudioFormat audioFormat = audioInputStream.getFormat();
-
+		
+		
 		SourceDataLine line;
 		line = (SourceDataLine) mixer.getLine(new DataLine.Info(
 				SourceDataLine.class, audioFormat));
 
 		line.open();
-		System.out.println(line.getFormat().matches(audioFormat));
+		Port.Info info = new Port.Info(Port.class, "alsa_output.pci_8086_24d5_sound_card_0_alsa_playback_0", false);
+		Port port = (Port) mixer.getLine(info);
+		FloatControl control = (FloatControl) port.getControl(FloatControl.Type.VOLUME);
+		control.getValue();
+		control.setValue(0);
+		control.getValue();
+		System.out.println(control.getValue());
 		mixer.close();
-
-	}
+	
+	}
+	
 
 	void addSourceDataLine(PulseAudioSourceDataLine line) {
 		sourceLines.add(line);
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioMuteControl.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMuteControl.java	Wed Aug 27 14:22:14 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMuteControl.java	Thu Aug 28 15:57:05 2008 -0400
@@ -39,10 +39,40 @@ package org.classpath.icedtea.pulseaudio
 
 import javax.sound.sampled.BooleanControl;
 
-abstract class PulseAudioMuteControl extends BooleanControl {
+class PulseAudioMuteControl extends BooleanControl {
+	
+	private PulseAudioVolumeControl volumeControl;
+	private PulseAudioPlaybackLine line;
 
-	protected PulseAudioMuteControl() {
+	protected PulseAudioMuteControl(PulseAudioPlaybackLine line, PulseAudioVolumeControl volumeControl) {
 		super(BooleanControl.Type.MUTE, false, "Volume muted", "Volume on");
+		this.volumeControl = volumeControl;
+		this.line = line;
+	}
+	
+	
+
+
+
+		public synchronized void setValue(boolean value) {
+			if(!line.isOpen()) {
+				return;
+			}
+
+			if (value == true) {
+				line.setMuted(true);
+				volumeControl.setStreamVolume(0);
+			} else {
+				line.setMuted(false);
+				float newValue = volumeControl.getValue();
+				volumeControl.setStreamVolume(newValue);
+			}
+		}
+
+		public synchronized boolean getValue() {
+			return line.isMuted();
+		}
+
 	}
 
-}
+
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioPlaybackLine.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioPlaybackLine.java	Thu Aug 28 15:57:05 2008 -0400
@@ -0,0 +1,17 @@
+package org.classpath.icedtea.pulseaudio;
+
+interface PulseAudioPlaybackLine {
+	
+	public int native_setVolume(float value);
+	
+	boolean isMuted();
+	
+	void setMuted(boolean mute);
+	
+	float getVolume();
+	
+	void setVolume(float volume);
+	
+	boolean isOpen();
+	
+}
diff -r 1a1a426b17cc -r f489a16be6f1 src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Wed Aug 27 14:22:14 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Thu Aug 28 15:57:05 2008 -0400
@@ -45,15 +45,16 @@ import javax.sound.sampled.DataLine;
 import javax.sound.sampled.DataLine;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Port;
 import javax.sound.sampled.SourceDataLine;
 import javax.sound.sampled.Control.Type;
 
 public class PulseAudioSourceDataLine extends PulseAudioDataLine implements
-		SourceDataLine {
+		SourceDataLine, PulseAudioPlaybackLine{
 
 	private Control[] controls = null;
-	private PulseAudioStreamMuteControl muteControl;
-	private PulseAudioStreamVolumeControl volumeControl;
+	private PulseAudioMuteControl muteControl;
+	private PulseAudioVolumeControl volumeControl;
 	private boolean muted;
 	private float volume;
 
@@ -65,44 +66,49 @@ public class PulseAudioSourceDataLine ex
 		this.supportedFormats = formats;
 		this.eventLoop = eventLoop;
 		this.lineListeners = new ArrayList<LineListener>();
-		this.volume = PulseAudioVolumeControl.MAX_VOLUME;
 		this.defaultFormat = defaultFormat;
 		this.currentFormat = defaultFormat;
-
-	}
-
-	protected boolean isMuted() {
-		return muted;
-	}
-
-	protected void setMuted(boolean value) {
-		muted = value;
-	}
-



More information about the distro-pkg-dev mailing list