changeset 43:0caab9aa95b1

more refactoring; started work on controls
author Omair Majid <omajid@redhat.com>
date Tue, 05 Aug 2008 17:30:50 -0400
parents 8dada78f3620
children 4a01f1203d48
files makefile src/jni-common.h src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine$1.class src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.class src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java src/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java src/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.class src/org/classpath/icedtea/pulseaudio/StreamVolume.java src/org_classpath_icedtea_pulseaudio_EventLoop.c src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c src/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeMuteControl.c src/org_classpath_icedtea_pulseaudio_PulseStreamAudioVolumeControl.c unittests/org/openjdk/sound/OtherSoundProvidersAvailableTest.java unittests/org/openjdk/sound/PulseAudioMixerProviderTest.java unittests/org/openjdk/sound/PulseAudioMixerRawTest.java unittests/org/openjdk/sound/PulseAudioMixerTest.java unittests/org/openjdk/sound/PulseSourceDataLineTest.java
diffstat 18 files changed, 196 insertions(+), 803 deletions(-) [+]
line wrap: on
line diff
--- a/makefile	Tue Aug 05 15:47:11 2008 -0400
+++ b/makefile	Tue Aug 05 17:30:50 2008 -0400
@@ -9,8 +9,8 @@
 
 PLATFORM_FLAGS=-DWITH_32BIT_PLATFORM
 
-CFLAGS=-g
-LDFLAGS=-g
+CFLAGS=-g -Wall -Werror
+LDFLAGS=-g -Wall -Werror
 
 # Standard targets
 
@@ -18,7 +18,7 @@
 
 
 clean:
-	-rm src/org_*.h src/org/openjdk/sound/*.class
+	-rm src/org_*.h src/org/classpath/icedtea/pulseaudio/*.class
 	-rm -r bin
 	-rm -r lib
 	mkdir -p lib
@@ -43,22 +43,22 @@
 # Object files
 
 bin/org_classpath_icedtea_pulseaudio_EventLoop.o: src/org_classpath_icedtea_pulseaudio_EventLoop.c src/org_classpath_icedtea_pulseaudio_EventLoop.h bin
-	gcc -g $(PLATFORM_FLAGS) -c -o $@ $<
+	gcc $(CFLAGS) $(PLATFORM_FLAGS) -c -o $@ $<
 
 bin/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.o: src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.h bin
-	gcc -g $(PLATFORM_FLAGS) -c -o $@ $<
+	gcc $(CFLAGS) $(PLATFORM_FLAGS) -c -o $@ $<
 
 bin/org_classpath_icedtea_pulseaudio_PulseAudioTargetDataLine.o: src/org_classpath_icedtea_pulseaudio_PulseAudioTargetDataLine.c src/org_classpath_icedtea_pulseaudio_PulseAudioTargetDataLine.h bin
-	gcc -g $(PLATFORM_FLAGS) -c -o $@ $<
+	gcc $(CFLAGS) $(PLATFORM_FLAGS) -c -o $@ $<
 
 bin/org_classpath_icedtea_pulseaudio_PulseAudioVolumeControl.o: src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeControl.c src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeControl.h
-	gcc -g $(PLATFORM_FLAGS) -c -o $@ $<
+	gcc $(CFLAGS) $(PLATFORM_FLAGS) -c -o $@ $<
 
 bin/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.o: src/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c src/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.h
-	gcc -g $(PLATFORM_FLAGS) -c -o $@ $<
+	gcc $(CFLAGS) $(PLATFORM_FLAGS) -c -o $@ $<
 
 bin/jni-common.o: src/jni-common.c src/jni-common.h
-	gcc -g $(PLATFORM_FLAGS) -c -o $@ $<
+	gcc $(CFLAGS) $(PLATFORM_FLAGS) -c -o $@ $<
 
 # Java headers
 
--- a/src/jni-common.h	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/jni-common.h	Tue Aug 05 17:30:50 2008 -0400
@@ -53,6 +53,11 @@
 # 	error Unsupported Platform
 #endif
 
+typedef struct java_context_t {
+	JNIEnv* env;
+	jobject obj;
+} java_context_t;
+
 
 jint getJavaIntField(JNIEnv* env, jobject obj, char* fieldName);
 void setJavaIntField(JNIEnv* env, jobject obj, char* fieldName, jint value);
Binary file src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine$1.class has changed
Binary file src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.class has changed
--- a/src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java	Tue Aug 05 17:30:50 2008 -0400
@@ -33,7 +33,7 @@
 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.
-*/
+ */
 
 package org.classpath.icedtea.pulseaudio;
 
@@ -43,7 +43,9 @@
 import java.util.concurrent.Semaphore;
 
 import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.BooleanControl;
 import javax.sound.sampled.Control;
+import javax.sound.sampled.FloatControl;
 import javax.sound.sampled.Line;
 import javax.sound.sampled.LineEvent;
 import javax.sound.sampled.LineListener;
@@ -64,6 +66,10 @@
 
 	private AudioFormat format = null;
 
+	private Control[] controls;
+	private Mute muteControl;
+	private StreamVolume volumeControl;
+
 	private List<LineListener> listeners;
 
 	/*
@@ -112,6 +118,10 @@
 	public PulseAudioSourceDataLine(EventLoop eventLoop) {
 		this.eventLoop = eventLoop;
 		this.listeners = new ArrayList<LineListener>();
+
+		volumeControl = new StreamVolume(this);
+		muteControl = new Mute();
+		controls = new Control[] { volumeControl, muteControl };
 	}
 
 	public void open(AudioFormat format, int bufferSize)
@@ -305,12 +315,16 @@
 	}
 
 	public Control getControl(Type control) {
-		return null;
+		for (int i = 0; i < controls.length; i++) {
+			if (controls[i].getType() == control){
+				return controls[i];
+			}
+		}
+		throw new IllegalArgumentException("Unsupported control type");
 	}
 
 	public Control[] getControls() {
-		// TODO Auto-generated method stub
-		return null;
+		return controls;
 	}
 
 	public javax.sound.sampled.Line.Info getLineInfo() {
@@ -386,4 +400,17 @@
 		}
 	}
 
+	private class Mute extends BooleanControl {
+
+		protected Mute() {
+			super(BooleanControl.Type.MUTE, false, "TRUE", "FALSE");
+
+		}
+
+	}
+
+	public long getStreamPointer() {
+		return streamPointer;
+	}
+
 }
--- a/src/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java	Tue Aug 05 15:47:11 2008 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,113 +0,0 @@
-/* PulseAudioStreamVolumeControl.java
-   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.
-*/
-
-
-package org.classpath.icedtea.pulseaudio;
-
-import java.io.IOException;
-
-import javax.sound.sampled.FloatControl;
-
-public class PulseAudioStreamVolumeControl extends FloatControl {
-
-	private FloatControl.Type type;
-
-	static {
-		try {
-			String library = new java.io.File(".").getCanonicalPath()
-					+ java.io.File.separatorChar + "lib"
-					+ java.io.File.separatorChar
-					+ System.mapLibraryName("pulse-java");
-			System.out.println(library);
-			System.load(library);
-		} catch (IOException e) {
-			assert ("Loading failed".endsWith("library"));
-		}
-	}
-
-	@SuppressWarnings("unused")
-	private long streamPointer;
-	@SuppressWarnings("unused")
-	private long mainLoopPointer;
-
-	protected PulseAudioStreamVolumeControl(Type type, float minimum,
-			float maximum, float precision, int updatePeriod,
-			float initialValue, String units, long streamPointer,
-			long mainLoopPointer) {
-		super(type, minimum, maximum, precision, updatePeriod, initialValue,
-				units);
-		assert (type.equals(Type.VOLUME));
-		this.streamPointer = streamPointer;
-		this.mainLoopPointer = mainLoopPointer;
-
-	}
-
-	@Override
-	public float getMaximum() {
-		// TODO Auto-generated method stub
-		return super.getMaximum();
-	}
-
-	@Override
-	public float getMinimum() {
-		// TODO Auto-generated method stub
-		return super.getMinimum();
-	}
-
-	@Override
-	public Type getType() {
-		// TODO Auto-generated method stub
-		return type;
-	}
-
-	@Override
-	public String getUnits() {
-		// TODO Auto-generated method stub
-		return super.getUnits();
-	}
-
-	public native float getValue();
-
-	public native void setValue(float newValue);
-
-	@Override
-	public void shift(float from, float to, int microseconds) {
-		// TODO Auto-generated method stub
-		super.shift(from, to, microseconds);
-	}
-
-}
Binary file src/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.class has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/org/classpath/icedtea/pulseaudio/StreamVolume.java	Tue Aug 05 17:30:50 2008 -0400
@@ -0,0 +1,114 @@
+/* PulseAudioStreamVolumeControl.java
+   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.
+ */
+
+package org.classpath.icedtea.pulseaudio;
+
+import java.io.IOException;
+
+import javax.sound.sampled.FloatControl;
+
+public class StreamVolume extends FloatControl {
+
+	private FloatControl.Type type;
+	private PulseAudioSourceDataLine stream;
+	
+	private static final int MIN_PULSE_VOLUME = 0x0;
+	private static final int MAX_PULSE_VOLUME = 0x10000;
+
+	static {
+		try {
+			String library = new java.io.File(".").getCanonicalPath()
+					+ java.io.File.separatorChar + "lib"
+					+ java.io.File.separatorChar
+					+ System.mapLibraryName("pulse-java");
+			System.out.println(library);
+			System.load(library);
+		} catch (IOException e) {
+			assert ("Loading failed".endsWith("library"));
+		}
+	}
+
+	private native void native_set_volume(int volume, long streamPointer, long contextPointer);
+	
+	protected StreamVolume(PulseAudioSourceDataLine stream) {
+		super(FloatControl.Type.VOLUME, 0f, 100f, 0.1f, 1, 100f, "percent",
+				"mute", "medium", "max");
+		this.type = FloatControl.Type.VOLUME;
+		this.stream = stream;
+	}
+
+	@Override
+	public float getMaximum() {
+		return super.getMaximum();
+	}
+
+	@Override
+	public float getMinimum() {
+		return super.getMinimum();
+	}
+
+	@Override
+	public Type getType() {
+		return type;
+	}
+
+	@Override
+	public String getUnits() {
+		return super.getUnits();
+	}
+
+	public float getValue() {
+		return super.getValue();
+	}
+
+	public void setValue(float newValue) {
+		/*
+		 * Set value of pulseaudio
+		 * 
+		 */
+		int value = (int) (newValue/100f * MAX_PULSE_VOLUME);
+//		native_set_volume(value, stream.getStreamPointer());
+		
+		super.setValue(newValue);
+	}
+
+	@Override
+	public void shift(float from, float to, int microseconds) {
+		super.shift(from, to, microseconds);
+	}
+
+}
--- a/src/org_classpath_icedtea_pulseaudio_EventLoop.c	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/org_classpath_icedtea_pulseaudio_EventLoop.c	Tue Aug 05 17:30:50 2008 -0400
@@ -44,11 +44,6 @@
 const int PA_ITERATE_BLOCK = 1;
 const int PA_ITERATE_NOBLOCK = 0;
 
-typedef struct java_context_t {
-	JNIEnv* env;
-	jobject obj;
-} java_context_t;
-
 static java_context_t* java_context = NULL;
 
 JNIEnv* pulse_thread_env = NULL;
@@ -92,9 +87,6 @@
 
 	assert(appName != NULL);
 
-	jfieldID fid; /* the field id */
-	jclass cls = (*env)->GetObjectClass(env,obj);
-
 	printf("native_setup() called\n");
 	pa_mainloop *mainloop = pa_mainloop_new();
 	assert(mainloop != NULL);
@@ -103,7 +95,7 @@
 
 	pa_context *context = NULL;
 
-	const jbyte* string_appName;
+	const char* string_appName;
 	string_appName = (*env)->GetStringUTFChars(env, appName, NULL);
 	if (string_appName == NULL) {
 		return; /* a OutOfMemoryError thrown by vm */
@@ -124,7 +116,7 @@
 
 	if (server != NULL) {
 		/* obtain the server from the caller */
-		const jbyte* string_server = NULL;
+		const char* string_server = NULL;
 		string_server = (*env)->GetStringUTFChars(env, server, NULL);
 		if (string_server == NULL) {
 			/* error, so clean up */
@@ -192,9 +184,6 @@
 
 	printf("native_shutdown() starting\n");
 
-	jfieldID fid; /* the field id */
-	jclass cls = (*env)->GetObjectClass(env,obj);
-
 	pa_mainloop* mainloop = (pa_mainloop*) getJavaPointer(env, obj, "mainloopPointer");
 	assert(mainloop != NULL);
 
--- a/src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c	Tue Aug 05 17:30:50 2008 -0400
@@ -36,6 +36,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <jni.h>
@@ -44,13 +45,6 @@
 #include "org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.h"
 #include "jni-common.h"
 
-typedef struct java_context_t {
-	JNIEnv* env;
-	jobject obj;
-} java_context_t;
-
-static java_context_t* java_context;
-
 /* defined in EventLoop.c */
 extern JNIEnv* pulse_thread_env;
 
@@ -156,7 +150,7 @@
 	sample_spec.channels = channels;
 
 	/* obtain the server from the caller */
-	const jbyte* stream_name = NULL;
+	const char* stream_name = NULL;
 	stream_name = (*env)->GetStringUTFChars(env, name, NULL);
 	if (stream_name == NULL) {
 		return; /* OutOfMemoryError */
@@ -199,7 +193,7 @@
 
 	pa_stream *stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer");
 	int available = pa_stream_writable_size(stream);
-
+	return available;
 }
 
 /*
@@ -282,5 +276,14 @@
 JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine_native_1close
 (JNIEnv* env, jobject obj) {
 
+	pa_stream *stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer");
+	pa_operation *o = pa_stream_drain(stream, stream_drain_complete_callback, NULL);
+	if (o == NULL) {
+		pa_stream_disconnect(stream);
+	} else {
+		pa_operation_unref(o);
+	}
+	
+	
 }
 
--- a/src/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c	Tue Aug 05 17:30:50 2008 -0400
@@ -37,16 +37,20 @@
 
 #include <jni.h>
 #include <pulse/pulseaudio.h>
+
+#include "jni-common.h"
 #include "org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.h"
 
 typedef struct {
-	pa_threaded_mainloop *mainloop;
+	pa_mainloop *mainloop;
 	pa_cvolume *volume;
 } userdata_info;
 
-static void sink_input_change_volume(pa_context* context,
+static void sink_input_info_available(pa_context* context,
 		const pa_sink_input_info* sink_input_info, int eol, void* userdata) {
+	
 	assert(context);
+	
 	if (eol) {
 		return;
 	}
@@ -59,8 +63,8 @@
 		(((userdata_info *)userdata)->volume)->values[j]
 				= sink_input_info->volume.values[j];
 	}
-	pa_threaded_mainloop_signal(((userdata_info *) userdata)->mainloop, 0);
-
+//	pa_threaded_mainloop_signal(((userdata_info *) userdata)->mainloop, 0);
+ 
 }
 
 /*
@@ -70,23 +74,23 @@
  */
 JNIEXPORT jfloat JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl_getValue
 (JNIEnv *env, jobject obj) {
-	pa_stream *stream = getJavaLongField(env, obj, "streamPointer");
-	pa_threaded_mainloop *mainloop = getJavaLongField(env, obj, "mainLoopPointer");
+	pa_stream *stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer");
+	pa_mainloop *mainloop = (pa_mainloop*) getJavaPointer(env, obj, "mainLoopPointer");
 	pa_context *context = pa_stream_get_context(stream);
 	int stream_id = pa_stream_get_index(stream);
 
 	userdata_info *userdata = malloc(sizeof(userdata_info));
 	userdata->mainloop = mainloop;
 	userdata->volume = malloc(sizeof(pa_cvolume));
-	pa_threaded_mainloop_lock(mainloop);
-	pa_operation *o = pa_context_get_sink_input_info((pa_context*) context ,stream_id,sink_input_change_volume, userdata);
-	while(pa_operation_get_state(o) != PA_OPERATION_DONE) {
-		pa_threaded_mainloop_wait(mainloop);
-	}
-	pa_operation_unref(o);
-	pa_threaded_mainloop_unlock(mainloop);
-	return pa_sw_volume_to_dB(userdata->volume->values[0]);
-
+//	pa_threaded_mainloop_lock(mainloop);
+	/* pa_operation *o = */ pa_context_get_sink_input_info(context ,stream_id,sink_input_info_available, userdata);
+//	while(pa_operation_get_state(o) != PA_OPERATION_DONE) {
+//		pa_threaded_mainloop_wait(mainloop);
+//	}
+//	pa_operation_unref(o);
+//	pa_threaded_mainloop_unlock(mainloop);
+//	return pa_sw_volume_to_dB(userdata->volume->values[0]);
+	return -0.1;
 }
 
 /*
@@ -96,11 +100,11 @@
  */
 JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl_setValue
 (JNIEnv *env, jobject obj, jfloat new_volume) {
-	pa_stream *stream = getJavaLongField(env, obj, "streamPointer");
+	pa_stream *stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer");
 	pa_context *context = pa_stream_get_context(stream);
 	int stream_id = pa_stream_get_index(stream);
 	int channels = pa_stream_get_sample_spec(stream)->channels;
 	pa_cvolume cv;
-	pa_context_set_sink_input_by_index(context, stream_id, pa_cvolume_set(&cv, channels, pa_sw_volume_from_dB(new_volume)), NULL, NULL);
+	pa_context_set_sink_input_volume(context, stream_id, pa_cvolume_set(&cv, channels, pa_sw_volume_from_dB(new_volume)), NULL, NULL);
 }
 
--- a/src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeMuteControl.c	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeMuteControl.c	Tue Aug 05 17:30:50 2008 -0400
@@ -36,13 +36,7 @@
 */
 
 
-void *getJavaLongField(JNIEnv *env, jobject obj, char *fieldName) {
-	jclass cls = (*env)->GetObjectClass(env, obj);
-	jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J");
-	jlong value = (*env)->GetLongField(env, obj, fid);
-	//(*env)->DeleteLocalReference(cls);
-	return (void *) value;
-}
+#include "jni-common.h"
 
 static void sink_input_change_volume(pa_context* context,
 		const pa_sink_input_info* input_info, int eol, void* userdata) {
--- a/src/org_classpath_icedtea_pulseaudio_PulseStreamAudioVolumeControl.c	Tue Aug 05 15:47:11 2008 -0400
+++ b/src/org_classpath_icedtea_pulseaudio_PulseStreamAudioVolumeControl.c	Tue Aug 05 17:30:50 2008 -0400
@@ -35,13 +35,7 @@
 exception statement from your version.
 */
 
- void *getJavaLongField(JNIEnv *env, jobject obj, char *fieldName) {
-	jclass cls = (*env)->GetObjectClass(env, obj);
-	jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J");
-	jlong value = (*env)->GetLongField(env, obj, fid);
-	//(*env)->DeleteLocalReference(cls);
-	return (void *) value;
-}
+#include "jni-common.h"
 
 static void sink_input_change_volume(pa_context* context, const pa_sink_input_info* input_info, int eol, void* userdata) {
 	assert(context);
--- a/unittests/org/openjdk/sound/OtherSoundProvidersAvailableTest.java	Tue Aug 05 15:47:11 2008 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-/* PulseAudioStreamVolumeControl.java
-   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.
-*/
-
-
-package org.openjdk.sound;
-
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.Line;
-import javax.sound.sampled.LineUnavailableException;
-import javax.sound.sampled.Mixer;
-import javax.sound.sampled.SourceDataLine;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.junit.Test;
-
-
-public class OtherSoundProvidersAvailableTest {
-	
-	public static junit.framework.Test suite() { 
-	    return new JUnit4TestAdapter(OtherSoundProvidersAvailableTest.class); 
-	}
-	
-	@Test
-	public void testOtherSoundProviders() {
-
-		Mixer.Info mixerInfos [] = AudioSystem.getMixerInfo();
-		Mixer.Info selectedMixerInfo = null;
-		Mixer selectedMixer;
-		
-		int i = 0;
-		for ( Mixer.Info info: mixerInfos) {
-			System.out.println("Mixer Line " + i++ + ": " + info.getName() + " " + info.getDescription());
-			if ( info.getName().contains("0,4")) {
-				selectedMixerInfo =	info; 
-			}
-		}
-		System.out.println(selectedMixerInfo.toString());
-		System.out.println("getting information from selected mixer:");
-		
-		// use 0,4 or the default
-		selectedMixer = AudioSystem.getMixer(selectedMixerInfo);
-		System.out.println(selectedMixer.toString());
-		try {
-			Line.Info sourceDataLineInfo = null;
-			
-			selectedMixer.open();	// initialize the mixer
-			
-			Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
-			int j = 0;
-			for ( Line.Info lineInfo : allLineInfo) {
-				System.out.println("Source Line " + j++ + ": " + lineInfo.getLineClass());
-				if ( lineInfo.getLineClass().toString().contains("SourceDataLine")) {
-					sourceDataLineInfo = lineInfo;
-				}
-			}
-			
-			SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer.getLine(sourceDataLineInfo);
-
-			sourceDataLine.open();
-			//sourceDataLine.write('a',  0, 2);
-			sourceDataLine.close();
-			
-		} catch ( LineUnavailableException e ) {
-			System.out.println("Line unavailable");
-		}
-		
-		
-		
-	}
-}
--- a/unittests/org/openjdk/sound/PulseAudioMixerProviderTest.java	Tue Aug 05 15:47:11 2008 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,93 +0,0 @@
-/* PulseAudioMixerProviderTest.java
-   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.
-*/
-
-package org.openjdk.sound;
-
-import static org.junit.Assert.*;
-
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.LineUnavailableException;
-import javax.sound.sampled.Mixer;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class PulseAudioMixerProviderTest {
-
-	private Mixer selectedMixer;
-	private Mixer.Info selectedMixerInfo;
-
-	public static junit.framework.Test suite() { 
-	    return new JUnit4TestAdapter(PulseAudioMixerProviderTest.class); 
-	}
-
-	@Before
-	public void setUp() throws Exception {
-
-		Mixer.Info mixerInfos [] = AudioSystem.getMixerInfo();
-
-		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; 
-			}
-		}
-		assertNotNull(selectedMixerInfo);
-	}
-
-	@Test 
-	public void testMixerProvider() throws LineUnavailableException {
-		System.out.println(selectedMixerInfo.toString());
-		System.out.println("getting information from selected mixer:");
-
-		selectedMixer = AudioSystem.getMixer(selectedMixerInfo);
-		assertNotNull(selectedMixer);
-		System.out.println(selectedMixer.toString());
-	}
-
-
-	@After
-	public void tearDown() throws Exception {
-
-	}
-
-
-}
--- a/unittests/org/openjdk/sound/PulseAudioMixerRawTest.java	Tue Aug 05 15:47:11 2008 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-/* PulseAudioMixerRawTest.java
-   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.
-*/
-
-package org.openjdk.sound;
-
-import javax.sound.sampled.LineUnavailableException;
-import javax.sound.sampled.Mixer;
-
-import org.classpath.icedtea.pulseaudio.PulseAudioMixer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class PulseAudioMixerRawTest {
-
-	Mixer mixer = null;
-	
-	@Before
-	public void setUp() {
-		mixer = PulseAudioMixer.getInstance();
-	}
-	
-	
-	@Test
-	public void testOpen() throws LineUnavailableException {
-		mixer.open();
-		
-	}
-	
-	
-	
-	@After
-	public void tearDown() {
-		
-	}
-	
-}
--- a/unittests/org/openjdk/sound/PulseAudioMixerTest.java	Tue Aug 05 15:47:11 2008 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,222 +0,0 @@
-/* PulseAudioStreamVolumeControl.java
-   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.
-*/
-
-
-package org.openjdk.sound;
-
-
-import static org.junit.Assert.assertNotNull;
-
-import java.net.UnknownHostException;
-
-import javax.sound.sampled.AudioSystem;
-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.SourceDataLine;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.classpath.icedtea.pulseaudio.PulseAudioMixer;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class PulseAudioMixerTest {
-
-	PulseAudioMixer selectedMixer;
-	
-	public static junit.framework.Test suite() { 
-	    return new JUnit4TestAdapter(PulseAudioMixerTest.class); 
-	}
-
-	
-	@Before
-	public void setUp() 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; 
-			}
-		}
-		assertNotNull(selectedMixerInfo);
-		selectedMixer = (PulseAudioMixer) AudioSystem.getMixer(selectedMixerInfo);
-		assertNotNull(selectedMixer);
-		
-	}
-	
-	@Test 
-	public void testLocalOpen() throws LineUnavailableException {
-		selectedMixer.openLocal();
-	}
-	
-	@Test
-	public void testLocalOpenAppName() throws LineUnavailableException {
-		selectedMixer.openLocal("JunitTest");
-	}
-	
-	
-	@Test (expected=LineUnavailableException.class)
-	public void testRemoteOpenWithInvalidPort() throws UnknownHostException, LineUnavailableException {
-		selectedMixer.openRemote("JUnitTest", "128.0.0.1", 10);
-	}
-	
-
-	/*
-	 * This test assumes a computer named 'town' is in the network with pulseaudio
-	 * listening on port 4173
-	 */
-	@Test 
-	public void testRemoteOpenWithValidPort() throws UnknownHostException, LineUnavailableException {
-		selectedMixer.openRemote("JUnitTest", "town", 4713);
-		selectedMixer.close();
-	}
-
-	
-	/*
-	 * This test assumes a computer named 'town' is in the network with pulseaudio
-	 * listening 
-	 */
-	@Test 
-	public void testRemoteOpen() throws UnknownHostException, LineUnavailableException {
-		selectedMixer.openRemote("JUnitTest", "town");
-	}
-
-	@Test (expected=LineUnavailableException.class)
-	public void testInvalidRemoteOpen() throws UnknownHostException, LineUnavailableException {
-		selectedMixer.openRemote("JUnitTest", "127.0.0.1");
-	}
-
-	
-
-	@Test 
-	public void testSourceLinesExist() throws LineUnavailableException {
-		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);
-			assertNotNull(sourceDataLine);
-			
-		}
-
-	}
-
-	@Test
-	public void testOpeningAgain() throws LineUnavailableException, UnsupportedOperationException {
-		selectedMixer.open();
-		selectedMixer.open();
-	}
-	
-	@Test
-	public void testClosingAgain() throws LineUnavailableException, UnsupportedOperationException {
-		selectedMixer.close();
-		selectedMixer.close();
-	}
-	
-	
-	@Test 
-	public void testSourceLinesOpenAndClose() throws LineUnavailableException {
-		selectedMixer.open();
-		Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo();
-		for (Line.Info lineInfo: allLineInfo) {
-			SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer.getLine(lineInfo);
-			sourceDataLine.open();
-			sourceDataLine.close();
-		}
-	}
-	
-	
-	@Test
-	public void testOpenEvent() throws LineUnavailableException {
-		LineListener listener = new LineListener() {
-			@Override
-			public void update(LineEvent event) {
-				assert(event.getType() == LineEvent.Type.OPEN);
-			}
-		};
-		
-		selectedMixer.addLineListener(listener);
-		selectedMixer.open();
-		selectedMixer.removeLineListener(listener);
-		selectedMixer.close();
-		
-	}
-	
-	
-	@Test
-	public void testCloseEvent() throws LineUnavailableException {
-		LineListener listener = new LineListener() {
-			@Override
-			public void update(LineEvent event) {
-				assert(event.getType() == LineEvent.Type.CLOSE);
-			}
-		};
-		
-		selectedMixer.open();
-		selectedMixer.addLineListener(listener);
-		selectedMixer.close();
-		selectedMixer.removeLineListener(listener);
-		
-	}
-	
-	
-	@Test 
-	public void testLongWait() throws LineUnavailableException {
-		selectedMixer.open();
-		try {
-			Thread.sleep(1000);
-		} catch (InterruptedException e) {
-			System.out.println("thread interrupted");
-		}
-		
-	}
-	
-	
-	@After
-	public void tearDown() throws Exception {
-		if (selectedMixer.isOpen())
-			selectedMixer.close();
-	}
-
-}
--- a/unittests/org/openjdk/sound/PulseSourceDataLineTest.java	Tue Aug 05 15:47:11 2008 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,133 +0,0 @@
-/* PulseSourceDataLineTest.java
-   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.
-*/
-
-package org.openjdk.sound;
-
-
-import java.io.File;
-import java.io.IOException;
-
-import javax.sound.sampled.AudioFormat;
-import javax.sound.sampled.AudioInputStream;
-import javax.sound.sampled.AudioSystem;
-import javax.sound.sampled.Line;
-import javax.sound.sampled.LineUnavailableException;
-import javax.sound.sampled.Mixer;
-import javax.sound.sampled.SourceDataLine;
-import javax.sound.sampled.UnsupportedAudioFileException;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.classpath.icedtea.pulseaudio.PulseAudioMixer;
-import org.classpath.icedtea.pulseaudio.PulseAudioSourceDataLine;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class PulseSourceDataLineTest {
-	Mixer mixer;
-	SourceDataLine line;
-	
-	public static junit.framework.Test suite() { 
-	    return new JUnit4TestAdapter(PulseSourceDataLineTest.class); 
-	}
-	
-	@Before
-	public void setUp() throws Exception {
-		mixer = PulseAudioMixer.getInstance();
-		mixer.open();
-		line = (PulseAudioSourceDataLine) mixer.getLine(new Line.Info(PulseAudioSourceDataLine.class));
-		Assert.assertNotNull(line);
-		
-	}
-	
-	@Test
-	public void testPlay() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
-		File soundFile = new File("new.wav");
-		AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile);
-		AudioFormat audioFormat = audioInputStream.getFormat();
-		line.open(audioFormat);
-		line.start();
-
-		byte[] abData = new byte[1000];
-		int bytesRead = 0;
-
-		while (bytesRead >= 0) {
-			bytesRead = audioInputStream.read(abData, 0, abData.length);
-			if (bytesRead > 0) {
-				line.write(abData, 0, bytesRead);
-			}
-		}
-
-		line.flush();
-		line.close();
-
-	}
-
-	@Test
-	public void testPlayLoud() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
-		File soundFile = new File("new.wav");
-		AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(soundFile);
-		AudioFormat audioFormat = audioInputStream.getFormat();
-		line.open(audioFormat);
-		
-	
-		line.start();
-
-		byte[] abData = new byte[1000];
-		int bytesRead = 0;
-
-		while (bytesRead >= 0) {
-			bytesRead = audioInputStream.read(abData, 0, abData.length);
-			if (bytesRead > 0) {
-				line.write(abData, 0, bytesRead);
-			}
-		}
-
-		line.flush();
-		line.close();
-		
-	}
-	
-	@After
-	public void tearDown() throws Exception {
-		
-		mixer.close();
-	}
-
-}