Mercurial > hg > pulseaudio
changeset 130:3fc512ee667f
2008-09-19 Omair Majid <omajid@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.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 19 Sep 2008 17:13:44 -0400 |
parents | 3a9c7727be22 |
children | 11a52266951f |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java src/java/org/classpath/icedtea/pulseaudio/Stream.java src/native/jni-common.c src/native/org_classpath_icedtea_pulseaudio_Stream.c |
diffstat | 5 files changed, 31 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ } catch (InterruptedException e) { throw new LineUnavailableException("unable to prepare stream"); } - } public void open(AudioFormat format) throws LineUnavailableException { @@ -197,7 +196,6 @@ } synchronized (eventLoop.threadLock) { - drain(); stream.disconnect(); } @@ -207,6 +205,10 @@ throw new RuntimeException("unable to prepare stream"); } + synchronized (eventLoop.threadLock) { + stream.free(); + } + super.close(); }
--- 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 @@ if (availableSize == 0) { try { - eventLoop.threadLock.wait(); + eventLoop.threadLock.wait(100); } catch (InterruptedException e) { // FIXME assert (false);
--- 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 @@ 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 @@ */ 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 boolean isCorked() { int corked = native_pa_stream_is_corked(); if (corked < 0) { @@ -639,7 +640,7 @@ } return corked == 0 ? false : true; } - + /** * Pause (or resume) playback of this stream temporarily. * @@ -745,4 +746,8 @@ return streamPointer; } + public void free() { + native_pa_stream_unref(); + } + }
--- 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 @@ 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* 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(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 @@ jbyte* data = (*env)->GetByteArrayElements(env, array, NULL); if (data == NULL) { - return 0; + return 0; // oome } memcpy(data, &pointer, sizeof(pointer));
--- 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 @@ -4,6 +4,8 @@ #include <pulse/pulseaudio.h> #include <string.h> +#define STREAM_POINTER "streamPointer" + typedef struct java_context { JNIEnv* env; jobject obj; @@ -299,6 +301,17 @@ /* * 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 @@ 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; }