changeset in /hg/pulseaudio: fixed the problem with listeners re...

Omair Majid omajid at redhat.com
Fri Aug 8 08:19:51 PDT 2008


changeset 2331da2e5f6a in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=2331da2e5f6a
description:
	fixed the problem with listeners remaining attached to a eventloop even after shutting down the eventloop; removed extra printing

diffstat:

9 files changed, 158 insertions(+), 155 deletions(-)
.hgignore                                                          |    2 
src/jni-common.c                                                   |   99 ++++++----
src/org/classpath/icedtea/pulseaudio/EventLoop.java                |   29 +-
src/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java          |   53 +----
src/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java      |    2 
src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java |    7 
src/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java |    4 
src/org_classpath_icedtea_pulseaudio_EventLoop.c                   |   91 ++++-----
src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c    |   26 +-

diffs (truncated from 653 to 500 lines):

diff -r c3802b8ed541 -r 2331da2e5f6a .hgignore
--- a/.hgignore	Wed Aug 06 14:55:15 2008 -0400
+++ b/.hgignore	Wed Aug 06 16:30:43 2008 -0400
@@ -6,3 +6,5 @@ syntax: glob
 *~
 org_classpath_icedtea_*.h
 *.log
+bin/*
+lib/*
diff -r c3802b8ed541 -r 2331da2e5f6a src/jni-common.c
--- a/src/jni-common.c	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/jni-common.c	Wed Aug 06 16:30:43 2008 -0400
@@ -1,40 +1,39 @@
 /* jni-common.c
-   Copyright (C) 2008 Red Hat, Inc.
+ Copyright (C) 2008 Red Hat, Inc.
 
-This file is part of IcedTea.
+ This file is part of IcedTea.
 
-IcedTea is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 2.
+ IcedTea is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 2.
 
-IcedTea is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
+ IcedTea is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with IcedTea; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
+ You should have received a copy of the GNU General Public License
+ along with IcedTea; see the file COPYING.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
 
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library.  Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
 
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so.  If you do not wish to do so, delete this
-exception statement from your version.
-*/
-
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module.  An independent module is a module which is not derived from
+ or based on this library.  If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so.  If you do not wish to do so, delete this
+ exception statement from your version.
+ */
 
 #include "jni-common.h"
 
@@ -89,17 +88,53 @@ void* getJavaPointer(JNIEnv* env, jobjec
 void* getJavaPointer(JNIEnv* env, jobject obj, char* name) {
 
 	/*
+	 * on a 64 bit machine, the value of the long is 64 bits, which should be the pointer
+	 * size and everything should be ok
+	 * 
+	 * So the problem is 32 bit architectures:
+	 * 
 	 * A reference snippet 
 	 * 
 	 int a_int = 0x1020;
 	 long a_long = 0x102030;
 	 long long a_long_long = 0x1020304150607080;
-	 printf("size of int: %d\nsize of long: %d\nsize of long long: %d\n", sizeof(int), sizeof(long), sizeof(long long));
+	 printf("size of int: %d\nsize of long: %d\nsize of long long: %d\n", 
+	         sizeof(int), sizeof(long), sizeof(long long));
 	 printf("int to long long: %X -> %llX\n", a_int, (long long) a_int);
 	 printf("long long to int: %llX -> %X\n", a_long_long, (int)a_long_long); 
 
 	 * this shows that long long -> int does a bitwise mask to get the lower order bits only
-	 * FIXME what about endianness? will it get the opposite bits?
+	 * this is a guess at how it works:
+	 *  
+	 *   raw data in register is 0x 10203040 50607080
+	 *                               32 bits  32 bits
+	 * 
+	 * we are interested in the 50607080 part of data
+	 * 
+	 *	Big endian:
+	 *    	10	<-- Pointer         <	32bit pointer (for an int)
+	 *    	20						<
+	 *    	30          			<
+	 *    	40                     	<
+	 * 		50
+	 * 		60
+	 * 		70
+	 * 		80
+	 * (for big endian, will need to do masking and shifting)
+	 * 
+	 * 
+	 * 	Little Endian
+	 * 		80	<-- Pointer			< 	32bit pointer (for an int)
+	 * 		70						<
+	 * 		60						<
+	 * 		50						<
+	 * 		40
+	 * 		30
+	 * 		20
+	 * 		10
+	 * (so little endian works by default!)
+	 * 
+	 * 
 	 */
 
 	/*
diff -r c3802b8ed541 -r 2331da2e5f6a src/org/classpath/icedtea/pulseaudio/EventLoop.java
--- a/src/org/classpath/icedtea/pulseaudio/EventLoop.java	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/org/classpath/icedtea/pulseaudio/EventLoop.java	Wed Aug 06 16:30:43 2008 -0400
@@ -153,8 +153,14 @@ public class EventLoop implements Runnab
 
 				if (Thread.interrupted()) {
 					native_shutdown();
-					System.out.println(this.getClass().getName()
-							+ ": shutting down");
+					// System.out.println(this.getClass().getName()
+					// + ": shutting down");
+					
+					// clean up the listeners
+					synchronized (contextListeners) {
+						contextListeners.clear();
+					}
+					
 					return;
 
 				}
@@ -181,8 +187,8 @@ public class EventLoop implements Runnab
 
 	public void update(int status) {
 		synchronized (threadLock) {
-			System.out.println(this.getClass().getName()
-					+ ".update() called! status = " + status);
+			// System.out.println(this.getClass().getName()
+			// + ".update() called! status = " + status);
 			this.status = status;
 			switch (status) {
 			case 0:
@@ -196,7 +202,6 @@ public class EventLoop implements Runnab
 			case 3:
 				break;
 			case 4:
-				System.out.println(this.getClass().getName() + " is ready!");
 				fireEvent(new ContextEvent(Type.READY));
 				break;
 			case 5:
@@ -212,26 +217,22 @@ public class EventLoop implements Runnab
 	}
 
 	private void fireEvent(final ContextEvent e) {
-		System.out.println(this.getClass().getName() + "firing event: "
-				+ e.getType().toString());
-		System.out.println("notifying listeners");
-
-		synchronized (contextListeners) {
-			System.out.println(contextListeners.size());
+//		System.out.println(this.getClass().getName() + "firing event: "
+//				+ e.getType().toString());
+
+		synchronized (contextListeners) {
+//			System.out.println(contextListeners.size());
 			for (ContextListener listener : contextListeners) {
 				listener.update(e);
-				System.out.println("updating listeners");
 			}
 		}
 
 	}
 
 	public void setVolume(long streamPointer, int volume) {
-
 		synchronized (threadLock) {
 			native_set_sink_volume(streamPointer, volume);
 		}
-
 	}
 
 	public long getContextPointer() {
diff -r c3802b8ed541 -r 2331da2e5f6a src/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Aug 06 16:30:43 2008 -0400
@@ -224,7 +224,7 @@ public class PulseAudioMixer implements 
 					+ ": interrupted while waiting for eventloop to finish");
 		}
 
-		System.out.println(this.getClass().getName() + ": closed");
+		// System.out.println(this.getClass().getName() + ": closed");
 
 		this.isOpen = false;
 		fireEvent(new LineEvent(this, LineEvent.Type.CLOSE,
@@ -249,7 +249,7 @@ public class PulseAudioMixer implements 
 
 	@Override
 	public javax.sound.sampled.Line.Info getLineInfo() {
-		System.out.println("DEBUG: PulseAudioMixer.getLineInfo() called");
+		// System.out.println("DEBUG: PulseAudioMixer.getLineInfo() called");
 		return new Line.Info(PulseAudioMixer.class);
 	}
 
@@ -308,47 +308,33 @@ public class PulseAudioMixer implements 
 		eventLoop.setAppName(appName);
 		eventLoop.setServer(host);
 
-		
-		ContextListener eventListener = new ContextListener() {
-
+		ContextListener generalEventListener = new ContextListener() {
 			@Override
 			public void update(ContextEvent e) {
-				System.out.println("General listener was notified");
-				System.out.println("  eventType: " + e.getType());
 				if (e.getType() == ContextEvent.Type.READY) {
-					System.out.println("firing event ready..");
 					fireEvent(new LineEvent(PulseAudioMixer.this,
 							LineEvent.Type.OPEN, AudioSystem.NOT_SPECIFIED));
-					System.out.println("done");
 				} else if (e.getType() == ContextEvent.Type.FAILED
 						|| e.getType() == ContextEvent.Type.TERMINATED) {
 					fireEvent(new LineEvent(PulseAudioMixer.this,
 							LineEvent.Type.CLOSE, AudioSystem.NOT_SPECIFIED));
 				}
-				System.out.println("general listener returning");
-			}
-
+			}
 		};
 
-		eventLoop.addContextListener(eventListener);
-		
-		
+		eventLoop.addContextListener(generalEventListener);
+
 		final Semaphore ready = new Semaphore(0);
 
 		ContextListener initListener = new ContextListener() {
 
 			@Override
 			public void update(ContextEvent e) {
-				System.out.println("specific listener notifed");
-				System.out.println(this.getClass().getName()
-						+ ": Event detected " + e.getType().toString());
 				if (e.getType() == ContextEvent.Type.READY
 						|| e.getType() == ContextEvent.Type.FAILED
 						|| e.getType() == ContextEvent.Type.TERMINATED) {
 					ready.release();
-					System.out.println("realeasing semaphore ready");
 				}
-				System.out.println("specific listener returning");
 			}
 
 		};
@@ -361,7 +347,7 @@ public class PulseAudioMixer implements 
 		eventLoopThread.start();
 
 		try {
-			System.out.println("waiting...");
+//			System.out.println("waiting...");
 			ready.acquire();
 			if (eventLoop.getStatus() != 4) {
 				/*
@@ -376,16 +362,14 @@ public class PulseAudioMixer implements 
 				throw new LineUnavailableException();
 			}
 			eventLoop.removeContextListener(initListener);
-			System.out.println("got signal");
+//			System.out.println("got signal");
 		} catch (InterruptedException e) {
-			System.out.println("PROBLEM: got interrupted");
-		}
-
-		System.out.println(this.getClass().getName() + ": ready");
+			System.out.println("PulseAudioMixer: got interrupted while waiting for the EventLoop to initialize");
+		}
+
+//		System.out.println(this.getClass().getName() + ": ready");
 
 		this.isOpen = true;
-
-
 
 	}
 
@@ -395,18 +379,15 @@ public class PulseAudioMixer implements 
 	}
 
 	/*
-	 * Should this method be synchronized? I had a few reasons, but i forgot them
-	 * Pros:
-	 *  - Thread safety?
+	 * Should this method be synchronized? I had a few reasons, but i forgot
+	 * them Pros: - Thread safety?
 	 * 
-	 * Cons:
-	 *  - eventListeners are run from other threads, if those then call fireEvent 
-	 *    while a method is waiting on a listener, this synchronized block wont 
-	 *    be entered: deadlock!
+	 * Cons: - eventListeners are run from other threads, if those then call
+	 * fireEvent while a method is waiting on a listener, this synchronized
+	 * block wont be entered: deadlock!
 	 * 
 	 */
 	private void fireEvent(final LineEvent e) {
-		System.out.println(this.getClass().getName() + "fireEvent(): firing event");
 		synchronized (lineListeners) {
 			for (LineListener lineListener : lineListeners) {
 				lineListener.update(e);
diff -r c3802b8ed541 -r 2331da2e5f6a src/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java
--- a/src/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/org/classpath/icedtea/pulseaudio/PulseAudioMixerInfo.java	Wed Aug 06 16:30:43 2008 -0400
@@ -53,7 +53,7 @@ public class PulseAudioMixerInfo extends
 	// the "getInstance()" method
 	synchronized public static PulseAudioMixerInfo getInfo() {
 		if (_instance == null) {
-			_instance = new PulseAudioMixerInfo("PulseAudio Mixer", "openjdk",
+			_instance = new PulseAudioMixerInfo("PulseAudio Mixer", "icedtea",
 					"the ear-candy mixer", "0.01");
 		}
 
diff -r c3802b8ed541 -r 2331da2e5f6a src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- a/src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Wed Aug 06 16:30:43 2008 -0400
@@ -205,15 +205,12 @@ public class PulseAudioSourceDataLine im
 				this.addStreamListener(new StreamListener() {
 					@Override
 					public void update(StreamEvent e) {
-						System.out.println(this.getClass().getName()
-								+ " waiting to stream to become ready");
 						if (e.getType() == StreamEvent.Type.READY) {
 							semaphore.release();
 						}
 					}
 				});
 
-				System.out.println("about to open stream");
 				native_start();
 			}
 
@@ -223,7 +220,7 @@ public class PulseAudioSourceDataLine im
 				// throw new LineUnavailableException("unable to prepare
 				// stream");
 			}
-			System.out.println(this.getClass().getName() + "stream is ready");
+
 		}
 
 		/*
@@ -369,8 +366,6 @@ public class PulseAudioSourceDataLine im
 
 	public void update(int status) {
 		synchronized (eventLoop.threadLock) {
-			System.out.println(this.getClass().getCanonicalName()
-					+ ".update() called! status = " + status);
 			switch (status) {
 			case 0:
 				fireEvent(new StreamEvent(StreamEvent.Type.UNCONNECTED));
diff -r c3802b8ed541 -r 2331da2e5f6a src/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
--- a/src/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java	Wed Aug 06 16:30:43 2008 -0400
@@ -90,10 +90,6 @@ public class PulseAudioTargetDataLine im
 	private native void openStream(String encoding, float rate, int size,
 			int channels, boolean bigEndian, int bufferSize);
 
-	static {
-		System.loadLibrary("PulseAudioSourceDataLine");
-	}
-
 	@Override
 	public int read(byte[] b, int off, int len) {
 		readFromStream(b, off, len);
diff -r c3802b8ed541 -r 2331da2e5f6a src/org_classpath_icedtea_pulseaudio_EventLoop.c
--- a/src/org_classpath_icedtea_pulseaudio_EventLoop.c	Wed Aug 06 14:55:15 2008 -0400
+++ b/src/org_classpath_icedtea_pulseaudio_EventLoop.c	Wed Aug 06 16:30:43 2008 -0400
@@ -1,40 +1,39 @@
 /* org_classpath_icedtea_pulseaudio_EventLoop.c
-   Copyright (C) 2008 Red Hat, Inc.
-
-This file is part of IcedTea.
-
-IcedTea is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 2.
-
-IcedTea is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with IcedTea; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so.  If you do not wish to do so, delete this
-exception statement from your version.
-*/
-
+ Copyright (C) 2008 Red Hat, Inc.
+
+ This file is part of IcedTea.
+
+ IcedTea is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 2.
+
+ IcedTea is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with IcedTea; see the file COPYING.  If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library.  Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module.  An independent module is a module which is not derived from
+ or based on this library.  If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so.  If you do not wish to do so, delete this
+ exception statement from your version.
+ */
 
 #include <pulse/pulseaudio.h>
 
@@ -52,13 +51,11 @@ static void context_change_callback(pa_c
 	assert(context);
 	assert(userdata == NULL);
 
-	printf("context state changed\n");
-	
 	//java_context_t* java_context = (java_context_t*)userdata;
 	JNIEnv* env = java_context->env;
 	jobject obj = java_context->obj;
 
-	printf("context state changed to %d\n", pa_context_get_state(context));
+	//	printf("context state changed to %d\n", pa_context_get_state(context));
 
 	/* Call the 'update' method in java
 	 * to handle all java-side events
@@ -89,7 +86,7 @@ JNIEXPORT void JNICALL Java_org_classpat
 
 	assert(appName != NULL);
 
-	printf("native_setup() called\n");
+	//	printf("native_setup() called\n");



More information about the distro-pkg-dev mailing list