changeset 22:68e6a71e97f3

for debugging committer: Ioana Ivan <iivan@redhat.com>
author Ioana Ivan <iivan@redhat.com>
date Tue, 29 Jul 2008 11:24:24 -0400
parents 46ff89811ea6
children 9ce846af2c4d
files src/org/openjdk/sound/PulseAudioMixer.java src/org/openjdk/sound/PulseAudioSourceDataLine.java
diffstat 2 files changed, 105 insertions(+), 81 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/openjdk/sound/PulseAudioMixer.java	Tue Jul 29 11:22:44 2008 -0400
+++ b/src/org/openjdk/sound/PulseAudioMixer.java	Tue Jul 29 11:24:24 2008 -0400
@@ -1,5 +1,9 @@
 package org.openjdk.sound;
 
+
+
+
+
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -12,6 +16,7 @@
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineListener;
 import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Mixer;
 import javax.sound.sampled.SourceDataLine;
 import javax.sound.sampled.TargetDataLine;
 import javax.sound.sampled.Control.Type;
@@ -52,12 +57,9 @@
 	 */
 
 	static {
-		try {
-			System.load( new java.io.File(".").getCanonicalPath() + java.io.File.separatorChar + "lib" + java.io.File.separatorChar +  System.mapLibraryName("PulseAudio"));	
-		} catch (IOException e)  {
-			assert("Loading failed".endsWith("library"));
-		}
-	}
+		
+			System.load( "/home/iivan/workspace/pulse-java" + java.io.File.separatorChar + "lib" + java.io.File.separatorChar +  System.mapLibraryName("PulseAudioMixer"));	
+			}
 	
 	private PulseAudioMixer(){
 		lineListeners = new ArrayList<LineListener>();
@@ -79,7 +81,7 @@
 		}
 		
 		if ( info.matches(_sourceDataLineInfo)) {
-			PulseAudioSourceDataLine sourceLine = new PulseAudioSourceDataLine();
+			PulseAudioSourceDataLine sourceLine = new PulseAudioSourceDataLine(contextPointer, mainloopPointer);
 			_sourceLines.add(sourceLine);
 			return sourceLine;
 		}
@@ -191,7 +193,10 @@
 		
 		// close all source/target lines
 		for (SourceDataLine sl: _sourceLines) {
-			sl.close();
+			if(sl.isOpen()) {
+				sl.close();	
+			}
+			
 		}
 		_sourceLines = null;
 		
@@ -203,7 +208,7 @@
 		native_shutdown();
 		_isOpen = false;
 		
-		fireEvent(new LineEvent(this,LineEvent.Type.CLOSE,AudioSystem.NOT_SPECIFIED));
+		//fireEvent(new LineEvent(this,LineEvent.Type.CLOSE,AudioSystem.NOT_SPECIFIED));
 	}
 
 	@Override
@@ -279,10 +284,13 @@
 		try {
 			native_initialize(appName, host );
 			_isOpen = true;
+			System.out.println("INITIALIZED");
 			fireEvent(new LineEvent(this, LineEvent.Type.OPEN, AudioSystem.NOT_SPECIFIED));
+			System.out.println("FIRED EVENT");
 
 		} catch (UnsupportedOperationException e) {
 			_isOpen = false;
+			System.out.println("EXCEPTION CATCHED");
 			throw e;
 		}
 
@@ -309,5 +317,33 @@
 		System.out.println("JAVA Callback called!");
 		System.out.println("JAVA CALLBACK: status = " + native_getStatus());
 	}
+	 
+	public static void main(String[] args) throws Exception{
+		Mixer.Info mixerInfos [] = AudioSystem.getMixerInfo();
+		Mixer.Info selectedMixerInfo = null;
+		int i = 0;
+		for ( Mixer.Info info: mixerInfos) {
+			//System.out.println("Mixer Line " + i++ + ": " + info.getName() + " " + info.getDescription());
+			if ( info.getName().contains("PulseAudio")) {
+				selectedMixerInfo =	info; 
+				System.out.println(selectedMixerInfo);
+			}
+		}
+		
+		PulseAudioMixer selectedMixer = (PulseAudioMixer) AudioSystem.getMixer(selectedMixerInfo);
+	
+		selectedMixer.open();
+		Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
+		int j = 0;
+		for ( Line.Info lineInfo : allLineInfo) {
+			System.out.println("Source Line " + j++ + ": " + lineInfo.getLineClass());
+			SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer.getLine(lineInfo);
+			System.out.println(sourceDataLine);
+			
+		}
+		if (selectedMixer.isOpen())
+			selectedMixer.close();
+		
+	}
 	
 }
--- a/src/org/openjdk/sound/PulseAudioSourceDataLine.java	Tue Jul 29 11:22:44 2008 -0400
+++ b/src/org/openjdk/sound/PulseAudioSourceDataLine.java	Tue Jul 29 11:24:24 2008 -0400
@@ -1,38 +1,41 @@
 package org.openjdk.sound;
 
 
+
+
+
 import java.util.ArrayList;
 
 import javax.sound.sampled.*;
 import javax.sound.sampled.Control.Type;
 
-public class PulseAudioSourceDataLine implements SourceDataLine{
-	
+public class PulseAudioSourceDataLine  implements SourceDataLine {
+
 	protected long contextPointer;
 	protected long mainLoopPointer;
 	protected long streamPointer;
-	private boolean isOpen = false;
-	private boolean isPaused = false;
-	private int defaultBufferSize;
-	private ArrayList<LineListener> listeners;
+	protected boolean isOpen = false;
+	protected boolean isPaused = false;
+	protected int defaultBufferSize;
+	protected ArrayList<LineListener> listeners;
+	
+	static {
+		
+			String library = "/home/iivan/workspace/pulse-java" + java.io.File.separatorChar + "lib" + java.io.File.separatorChar +  System.mapLibraryName("PulseAudioSourceDataLine");
+			System.out.println(library);
+			System.load(library) ;	
+		
+	}
 	
 	PulseAudioSourceDataLine() {
 		this.contextPointer = 1;
 		this.mainLoopPointer = 1;
-		System.out.println(contextPointer);
-		System.out.println(mainLoopPointer);
 	}
 	
 	
 	public PulseAudioSourceDataLine(long context, long mainLoop) {
 		this.contextPointer = context;
 		this.mainLoopPointer = mainLoop;
-		System.out.println(contextPointer);
-		System.out.println(mainLoopPointer);
-	}
-	
-	public boolean isOpen() {
-		return isOpen;
 	}
 	
 	public void open(AudioFormat format, int bufferSize) throws LineUnavailableException {
@@ -56,10 +59,17 @@
 		openStream("PCM_SIGNED", 44100, 16, 2, false, defaultBufferSize);
 	}
 
+	private native void openStream(String encoding, float rate, int size, int channels, boolean bigEndian, int bufferSize);
+
+	public int write(byte[] b, int off, int len) {
+		writeToStream(b, len, off);
+		return len;
+	}
 	
-	private native void openStream(String encoding, float rate, int size, int channels, boolean bigEndian, int bufferSize);
+	private native void writeToStream(byte[]data, int bytes, int off);
+
 	
-	
+
 	public void start() {
 		if (isPaused) {
 			resumeStream();
@@ -67,51 +77,52 @@
 		} else {
 			startStream();
 		}
-		
-		for(LineListener l :listeners) {
+		System.out.println(mainLoopPointer);
+		System.out.println(streamPointer);
+		/*for(LineListener l :listeners) {
 			l.update(new LineEvent(this, LineEvent.Type.START, 0));
-		}
+		}*/
 	}
 	
 	public void stop() {
 		pauseStream();
 		isPaused = true;
 		
+		
 	}
 	
-	public native void startStream();
+	private native void startStream();
 	private native void pauseStream();
 	private native void resumeStream();
-	
-	
-	
-	public native void writeToStream(byte[]data, int bytes, int off);
-	public native void closeConnection();
-	
-	
-
-	
-	static {
-		System.loadLibrary("PulseAudioSourceDataLine");
-	}
-
-
-
-
-
-
-	public int write(byte[] b, int off, int len) {
-		writeToStream(b, len, off);
-		return len;
-	}
-
-	public native int available();
-
 
 	public native void drain() ;
 	public native void flush();
 
 
+	public void addLineListener(LineListener listener){
+		listeners.add(listener);
+	}
+	
+	public void removeLineListener(LineListener listener){
+		listeners.remove(listener);
+	}
+	
+	public boolean isOpen() {
+		return isOpen;
+	}
+	
+	public native int available();
+	
+	public void close() {
+		closeStream();
+		for (LineListener l : listeners) {
+			l.update(new LineEvent(this, LineEvent.Type.CLOSE, 0));
+		}
+		
+	}
+	
+	private native void closeStream();
+	
 	public int getBufferSize() {
 		// TODO Auto-generated method stub
 		return 0;
@@ -129,13 +140,13 @@
 		return 0;
 	}
 
-
+	
 	public float getLevel() {
 		// TODO Auto-generated method stub
 		return 0;
 	}
 
-
+	
 	public long getLongFramePosition() {
 		// TODO Auto-generated method stub
 		return 0;
@@ -153,32 +164,11 @@
 		return false;
 	}
 
-
 	public boolean isRunning() {
 		// TODO Auto-generated method stub
 		return false;
 	}
-
-
 	
-
-
-	public void addLineListener(LineListener listener){
-		listeners.add(listener);
-	}
-
-
-	public void close() {
-		closeStream();
-		for (LineListener l : listeners) {
-			l.update(new LineEvent(this, LineEvent.Type.CLOSE, 0));
-		}
-		
-	}
-	
-	private native void closeStream();
-
-
 	public Control getControl(Type control) {
 		// TODO Auto-generated method stub
 		return null;
@@ -202,12 +192,10 @@
 	}
 
 
-	@Override
-	public void removeLineListener(LineListener listener){
-		listeners.remove(listener);
-	}
 
 
 	
 
+	
+
 }