changeset in /hg/pulseaudio: more refactoring; started work on c...
Omair Majid
omajid at redhat.com
Fri Aug 8 08:19:50 PDT 2008
changeset 0caab9aa95b1 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=0caab9aa95b1
description:
more refactoring; started work on controls
diffstat:
15 files changed, 198 insertions(+), 805 deletions(-)
makefile | 18
src/jni-common.h | 5
src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java | 35 +
src/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java | 113 -----
src/org/classpath/icedtea/pulseaudio/StreamVolume.java | 114 +++++
src/org_classpath_icedtea_pulseaudio_EventLoop.c | 15
src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c | 25 -
src/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c | 38 -
src/org_classpath_icedtea_pulseaudio_PulseAudioVolumeMuteControl.c | 8
src/org_classpath_icedtea_pulseaudio_PulseStreamAudioVolumeControl.c | 8
unittests/org/openjdk/sound/OtherSoundProvidersAvailableTest.java | 105 ----
unittests/org/openjdk/sound/PulseAudioMixerProviderTest.java | 93 ----
unittests/org/openjdk/sound/PulseAudioMixerRawTest.java | 71 ---
unittests/org/openjdk/sound/PulseAudioMixerTest.java | 222 ----------
unittests/org/openjdk/sound/PulseSourceDataLineTest.java | 133 -----
diffs (truncated from 1269 to 500 lines):
diff -r 8dada78f3620 -r 0caab9aa95b1 makefile
--- a/makefile Tue Aug 05 15:47:11 2008 -0400
+++ b/makefile Tue Aug 05 17:30:50 2008 -0400
@@ -9,8 +9,8 @@ CC=gcc
PLATFORM_FLAGS=-DWITH_32BIT_PLATFORM
-CFLAGS=-g
-LDFLAGS=-g
+CFLAGS=-g -Wall -Werror
+LDFLAGS=-g -Wall -Werror
# Standard targets
@@ -18,7 +18,7 @@ all: lib/libpulse-java.so
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 @@ lib/libpulse-java.so: \
# 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
diff -r 8dada78f3620 -r 0caab9aa95b1 src/jni-common.h
--- 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 @@ exception statement from your version.
# 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);
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine$1.class
Binary file src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine$1.class has changed
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.class
Binary file src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.class has changed
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- 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 li
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 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;
@@ -63,6 +65,10 @@ public class PulseAudioSourceDataLine im
private boolean isPaused = false;
private AudioFormat format = null;
+
+ private Control[] controls;
+ private Mute muteControl;
+ private StreamVolume volumeControl;
private List<LineListener> listeners;
@@ -112,6 +118,10 @@ public class PulseAudioSourceDataLine im
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 class PulseAudioSourceDataLine im
}
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 @@ public class PulseAudioSourceDataLine im
}
}
+ private class Mute extends BooleanControl {
+
+ protected Mute() {
+ super(BooleanControl.Type.MUTE, false, "TRUE", "FALSE");
+
+ }
+
+ }
+
+ public long getStreamPointer() {
+ return streamPointer;
+ }
+
}
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org/classpath/icedtea/pulseaudio/PulseAudioStreamVolumeControl.java
--- 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);
- }
-
-}
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.class
Binary file src/org/classpath/icedtea/pulseaudio/PulseAudioVolumeControl.class has changed
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org/classpath/icedtea/pulseaudio/StreamVolume.java
--- /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);
+ }
+
+}
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org_classpath_icedtea_pulseaudio_EventLoop.c
--- 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_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 @@ JNIEXPORT void JNICALL Java_org_classpat
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 @@ JNIEXPORT void JNICALL Java_org_classpat
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 @@ JNIEXPORT void JNICALL Java_org_classpat
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 @@ JNIEXPORT void JNICALL Java_org_classpat
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);
diff -r 8dada78f3620 -r 0caab9aa95b1 src/org_classpath_icedtea_pulseaudio_PulseAudioSourceDataLine.c
--- 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>
@@ -43,13 +44,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 @@ JNIEXPORT void JNICALL Java_org_classpat
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 @@ JNIEXPORT jint JNICALL Java_org_classpat
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_classpat
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);
+ }
+
More information about the distro-pkg-dev
mailing list