changeset in /hg/pulseaudio: 2008-09-19 Omair Majid <omajid at redh...
Omair Majid
omajid at redhat.com
Mon Sep 22 11:44:45 PDT 2008
changeset 3fc512ee667f in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=3fc512ee667f
description:
2008-09-19 Omair Majid <omajid at redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
(close): Free the stream only after we are done with it.
* src/java/org/classpath/icedtea/pulseaudio/Stream.java
(native_pa_stream_unref): New function.
(free): New function. Frees the memory used by the stream.
* src/native/org_classpath_icedtea_pulseaudio_Stream.c
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1unref):
New function. Free the stream.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1disconnect):
Doesnt deallocate the stream anymore.
* src/native/jni-common.c
(getJavaPointer): Allow returning NULL values.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
(write): Only wait for a little bit.
diffstat:
5 files changed, 31 insertions(+), 11 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java | 6 ++--
src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java | 2 -
src/java/org/classpath/icedtea/pulseaudio/Stream.java | 11 +++++--
src/native/jni-common.c | 8 ++---
src/native/org_classpath_icedtea_pulseaudio_Stream.c | 15 +++++++++-
diffs (172 lines):
diff -r 3a9c7727be22 -r 3fc512ee667f src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Sep 19 13:42:34 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Sep 19 17:13:44 2008 -0400
@@ -176,7 +176,6 @@ public abstract class PulseAudioDataLine
} catch (InterruptedException e) {
throw new LineUnavailableException("unable to prepare stream");
}
-
}
public void open(AudioFormat format) throws LineUnavailableException {
@@ -197,7 +196,6 @@ public abstract class PulseAudioDataLine
}
synchronized (eventLoop.threadLock) {
- drain();
stream.disconnect();
}
@@ -205,6 +203,10 @@ public abstract class PulseAudioDataLine
semaphore.acquire();
} catch (InterruptedException e) {
throw new RuntimeException("unable to prepare stream");
+ }
+
+ synchronized (eventLoop.threadLock) {
+ stream.free();
}
super.close();
diff -r 3a9c7727be22 -r 3fc512ee667f src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Sep 19 13:42:34 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Sep 19 17:13:44 2008 -0400
@@ -162,7 +162,7 @@ public class PulseAudioSourceDataLine ex
if (availableSize == 0) {
try {
- eventLoop.threadLock.wait();
+ eventLoop.threadLock.wait(100);
} catch (InterruptedException e) {
// FIXME
assert (false);
diff -r 3a9c7727be22 -r 3fc512ee667f src/java/org/classpath/icedtea/pulseaudio/Stream.java
--- a/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Sep 19 13:42:34 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Sep 19 17:13:44 2008 -0400
@@ -128,6 +128,8 @@ public class Stream {
private native void native_pa_stream_new(byte[] contextPointer,
String name, String format, int sampleRate, int channels);
+ private native void native_pa_stream_unref();
+
private native int native_pa_stream_get_state();
private native byte[] native_pa_stream_get_context();
@@ -177,7 +179,7 @@ public class Stream {
*/
private native int native_pa_stream_is_corked();
-
+
private native byte[] native_pa_stream_cork(int b);
private native byte[] native_pa_stream_flush();
@@ -631,7 +633,6 @@ public class Stream {
}
}
-
public boolean isCorked() {
int corked = native_pa_stream_is_corked();
if (corked < 0) {
@@ -639,7 +640,7 @@ public class Stream {
}
return corked == 0 ? false : true;
}
-
+
/**
* Pause (or resume) playback of this stream temporarily.
*
@@ -745,4 +746,8 @@ public class Stream {
return streamPointer;
}
+ public void free() {
+ native_pa_stream_unref();
+ }
+
}
diff -r 3a9c7727be22 -r 3fc512ee667f src/native/jni-common.c
--- a/src/native/jni-common.c Fri Sep 19 13:42:34 2008 -0400
+++ b/src/native/jni-common.c Fri Sep 19 17:13:44 2008 -0400
@@ -177,12 +177,13 @@ void* getJavaPointer(JNIEnv* env, jobjec
jbyteArray array = getJavaByteArrayField(env, obj, name);
assert(array);
void* value = convertJavaPointerToNative(env, array);
- assert(value);
+ // allow returning NULL values
return value;
}
void setJavaPointer(JNIEnv* env, jobject obj, char* name, void* value) {
+ // allow NULL for value
jbyteArray array = convertNativePointerToJava(env, value);
assert(array);
setJavaByteArrayField(env, obj, name, array);
@@ -194,6 +195,7 @@ void* convertJavaPointerToNative(JNIEnv*
void* returnPointer = NULL;
+ // this is not the pointer, but the container of the pointer
assert(pointer);
jsize len = (*env)->GetArrayLength(env, pointer);
@@ -214,8 +216,6 @@ jbyteArray convertNativePointerToJava(JN
jbyteArray convertNativePointerToJava(JNIEnv* env, void* pointer) {
// printf("convertNativePointerToJava(): entering method\n");
- // assert(pointer);
-
jbyteArray array = (*env)->NewByteArray(env, sizeof(pointer));
if (array == NULL) {
return 0; // oome?
@@ -223,7 +223,7 @@ jbyteArray convertNativePointerToJava(JN
jbyte* data = (*env)->GetByteArrayElements(env, array, NULL);
if (data == NULL) {
- return 0;
+ return 0; // oome
}
memcpy(data, &pointer, sizeof(pointer));
diff -r 3a9c7727be22 -r 3fc512ee667f src/native/org_classpath_icedtea_pulseaudio_Stream.c
--- a/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Sep 19 13:42:34 2008 -0400
+++ b/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Sep 19 17:13:44 2008 -0400
@@ -3,6 +3,8 @@
#include "jni-common.h"
#include <pulse/pulseaudio.h>
#include <string.h>
+
+#define STREAM_POINTER "streamPointer"
typedef struct java_context {
JNIEnv* env;
@@ -299,6 +301,17 @@ JNIEXPORT void JNICALL Java_org_classpat
/*
* Class: org_classpath_icedtea_pulseaudio_Stream
+ * Method: native_pa_stream_unref
+ * Signature: ()V
+ */
+JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1unref
+(JNIEnv* env, jobject obj) {
+ pa_stream* stream = getJavaPointer(env, obj, "streamPointer");
+ pa_stream_unref(stream);
+}
+
+/*
+ * Class: org_classpath_icedtea_pulseaudio_Stream
* Method: native_pa_stream_get_state
* Signature: ()I
*/
@@ -475,7 +488,7 @@ JNIEXPORT jint JNICALL Java_org_classpat
pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer");
assert(stream);
int return_value = pa_stream_disconnect(stream);
- pa_stream_unref(stream);
+
return return_value;
}
More information about the distro-pkg-dev
mailing list