Mercurial > hg > pulseaudio
changeset 93:c9268e180613
2008-08-20 Omair Majid <omajid@redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
(connectLine): New sane formatting.
(drain): Replaced continuously polling loop with a call to
waitForCompletion.
(flush): Likewise.
* src/native/jni-common.c (notifyWaitingOperations): New function.
* src/native/jni-common.h (notifyWaitingOperations): New function.
* src/native/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c
(set_sink_input_volume_callback): Call notifyWaitingOperations to do the
same thing as before.
* src/native/org_classpath_icedtea_pulseaudio_Stream.c
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1read):
Changed return type from int to jint.
(drain_callback): New function.
(cork_callback): Likewise.
(flush_callback): Likewise.
(trigger_callback): Likewise.
(set_name_callback): Likewise.
(set_buffer_attr_callback): Likewise.
(update_sample_rate_callback): Likewise.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drain):
Added callback.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1cork):
Likewise.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1flush):
Likewise.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1trigger):
Likewise.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1set_1name):
Likewise.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1set_1buffer_1attr):
Likewise.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1update_1sample_1rate):
Likewise.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Wed, 20 Aug 2008 11:53:39 -0400 |
parents | f4ead96961a9 |
children | c1154939ba8b |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java src/native/jni-common.c src/native/jni-common.h src/native/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c src/native/org_classpath_icedtea_pulseaudio_Stream.c |
diffstat | 5 files changed, 109 insertions(+), 60 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Wed Aug 20 11:05:00 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Wed Aug 20 11:53:39 2008 -0400 @@ -102,11 +102,13 @@ protected void connectLine() { StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( - StreamBufferAttributes.SANE_DEFAULT, StreamBufferAttributes.SANE_DEFAULT, - StreamBufferAttributes.SANE_DEFAULT, StreamBufferAttributes.SANE_DEFAULT, + StreamBufferAttributes.SANE_DEFAULT, + StreamBufferAttributes.SANE_DEFAULT, + StreamBufferAttributes.SANE_DEFAULT, + StreamBufferAttributes.SANE_DEFAULT, StreamBufferAttributes.SANE_DEFAULT); - - stream.connectForPlayback(null,bufferAttributes); + + stream.connectForPlayback(null, bufferAttributes); } @Override @@ -254,18 +256,12 @@ @Override public void drain() { Operation operation; - Operation.State operationState; + synchronized (eventLoop.threadLock) { operation = stream.drain(); - operationState = operation.getState(); } - // FIXME need to find a way to do a wait than a busy loop - while (operationState != Operation.State.Done) { - synchronized (eventLoop.threadLock) { - operationState = operation.getState(); - } - } + operation.waitForCompletion(); operation.releaseReference(); } @@ -273,18 +269,11 @@ @Override public void flush() { Operation operation; - Operation.State operationState; synchronized (eventLoop.threadLock) { operation = stream.flush(); - operationState = operation.getState(); - } - // FIXME need to find a way to do a wait than a busy loop - while (operationState != Operation.State.Done) { - synchronized (eventLoop.threadLock) { - operationState = operation.getState(); - } } + operation.waitForCompletion(); operation.releaseReference(); }
--- a/src/native/jni-common.c Wed Aug 20 11:05:00 2008 -0400 +++ b/src/native/jni-common.c Wed Aug 20 11:53:39 2008 -0400 @@ -104,6 +104,44 @@ } +void notifyWaitingOperations(JNIEnv* env) { + + const char* eventLoopClassName = + "Lorg/classpath/icedtea/pulseaudio/EventLoop;"; + jclass eventLoopClass = (*env)->FindClass(env, eventLoopClassName); + assert(eventLoopClass); + + const char* getEventLoopIDSignature = + "()Lorg/classpath/icedtea/pulseaudio/EventLoop;"; + jmethodID getEventLoopID = (*env)->GetStaticMethodID(env, eventLoopClass, "getEventLoop", + getEventLoopIDSignature); + assert(getEventLoopID); + + jobject eventLoop = (*env)->CallStaticObjectMethod(env, eventLoopClass, getEventLoopID); + assert(eventLoop); + + jfieldID lockID = (*env)->GetFieldID(env, eventLoopClass, "threadLock", + "Ljava/lang/Object;"); + assert(lockID); + + jobject lockObject = (*env)->GetObjectField(env, eventLoop, lockID); + assert(lockObject); + + (*env)->MonitorEnter(env, lockObject); + + jclass objectClass = (*env)->FindClass(env, "Ljava/lang/Object;"); + assert(objectClass); + jmethodID notifyAllID = (*env)->GetMethodID(env, objectClass, "notifyAll", "()V"); + assert(notifyAllID); + + (*env)->CallObjectMethod(env, lockObject, notifyAllID); + + (*env)->MonitorExit(env, lockObject); + +} + + + /* * *
--- a/src/native/jni-common.h Wed Aug 20 11:05:00 2008 -0400 +++ b/src/native/jni-common.h Wed Aug 20 11:53:39 2008 -0400 @@ -70,7 +70,7 @@ void throwByName(JNIEnv* const env, const char* const name, const char* const msg); - +void notifyWaitingOperations(JNIEnv* env); void* getJavaPointer(JNIEnv* env, jobject obj, char* name); void setJavaPointer(JNIEnv* env, jobject obj, char*name, void* pointer_value);
--- a/src/native/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c Wed Aug 20 11:05:00 2008 -0400 +++ b/src/native/org_classpath_icedtea_pulseaudio_PulseAudioStreamVolumeControl.c Wed Aug 20 11:53:39 2008 -0400 @@ -48,37 +48,7 @@ JNIEnv* env = pulse_thread_env; - const char* eventLoopClassName = - "Lorg/classpath/icedtea/pulseaudio/EventLoop;"; - jclass eventLoopClass = (*env)->FindClass(env, eventLoopClassName); - assert(eventLoopClass); - - const char* getEventLoopIDSignature = - "()Lorg/classpath/icedtea/pulseaudio/EventLoop;"; - jmethodID getEventLoopID = (*env)->GetStaticMethodID(env, eventLoopClass, "getEventLoop", - getEventLoopIDSignature); - assert(getEventLoopID); - - jobject eventLoop = (*env)->CallStaticObjectMethod(env, eventLoopClass, getEventLoopID); - assert(eventLoop); - - jfieldID lockID = (*env)->GetFieldID(env, eventLoopClass, "threadLock", - "Ljava/lang/Object;"); - assert(lockID); - - jobject lockObject = (*env)->GetObjectField(env, eventLoop, lockID); - assert(lockObject); - - (*env)->MonitorEnter(env, lockObject); - - jclass objectClass = (*env)->FindClass(env,"Ljava/lang/Object;"); - assert(objectClass); - jmethodID notifyAllID = (*env)->GetMethodID(env, objectClass, "notifyAll", "()V"); - assert(notifyAllID); - - (*env)->CallObjectMethod(env, lockObject, notifyAllID); - - (*env)->MonitorExit(env, lockObject); + notifyWaitingOperations(env); }
--- a/src/native/org_classpath_icedtea_pulseaudio_Stream.c Wed Aug 20 11:05:00 2008 -0400 +++ b/src/native/org_classpath_icedtea_pulseaudio_Stream.c Wed Aug 20 11:53:39 2008 -0400 @@ -460,7 +460,7 @@ return value; } -JNIEXPORT int JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1read +JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1read (JNIEnv *env, jobject obj, jbyteArray array, jint length, jint offset) { pa_stream *stream = getJavaPointer(env, obj, "streamPointer"); const void *read_data = NULL; @@ -537,6 +537,14 @@ return pa_stream_readable_size(stream); } +static void drain_callback(pa_stream* stream, int success, void* userdata) { + + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_drain @@ -545,10 +553,17 @@ JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drain (JNIEnv* env, jobject obj) { pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer"); - pa_operation* operation = pa_stream_drain(stream, NULL, NULL); + pa_operation* operation = pa_stream_drain(stream, drain_callback, NULL); return convertPointerToJavaLong(operation); } +static void cork_callback(pa_stream* stream, int success, void* userdata) { + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_cork @@ -557,10 +572,17 @@ JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1cork (JNIEnv* env, jobject obj, jint yes) { pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer"); - pa_operation* operation = pa_stream_cork(stream, yes, NULL, NULL); + pa_operation* operation = pa_stream_cork(stream, yes, cork_callback, NULL); return convertPointerToJavaLong(operation); } +static void flush_callback(pa_stream* stream, int success, void* userdata) { + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_flush @@ -569,10 +591,17 @@ JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1flush (JNIEnv* env, jobject obj) { pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer"); - pa_operation* operation = pa_stream_flush(stream, NULL, NULL); + pa_operation* operation = pa_stream_flush(stream, flush_callback, NULL); return convertPointerToJavaLong(operation); } +static void trigger_callback(pa_stream* stream, int success, void* userdata) { + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_trigger @@ -581,10 +610,17 @@ JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1trigger (JNIEnv* env, jobject obj) { pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer"); - pa_operation* operation = pa_stream_trigger(stream, NULL, NULL); + pa_operation* operation = pa_stream_trigger(stream, trigger_callback, NULL); return convertPointerToJavaLong(operation); } +static void set_name_callback(pa_stream* stream, int success, void* userdata) { + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_set_name @@ -599,7 +635,7 @@ return 0; // OutOfMemoryError already thrown } - pa_operation* operation = pa_stream_set_name(stream, name, NULL, NULL); + pa_operation* operation = pa_stream_set_name(stream, name, set_name_callback, NULL); assert(operation); (*env)->ReleaseStringUTFChars(env, newName, name); @@ -693,6 +729,14 @@ return return_object; } +static void set_buffer_attr_callback(pa_stream* stream, int success, void* userdata) { + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_set_buffer_attr @@ -723,10 +767,18 @@ jmethodID getFragmentSizeID = (*env)->GetMethodID(env,cls,"getFragmentSize","()I"); buffer->fragsize = (*env)->CallIntMethod(env, bufferAttributeObject, getFragmentSizeID ); - pa_operation* operation = pa_stream_set_buffer_attr(stream, buffer, NULL, NULL); + pa_operation* operation = pa_stream_set_buffer_attr(stream, buffer, set_buffer_attr_callback, NULL); assert(operation); return convertPointerToJavaLong(operation); } + +static void update_sample_rate_callback(pa_stream* stream, int success, void* userdata) { + assert(success); + JNIEnv* env = pulse_thread_env; + notifyWaitingOperations(env); + +} + /* * Class: org_classpath_icedtea_pulseaudio_Stream * Method: native_pa_stream_update_sample_rate @@ -739,7 +791,7 @@ pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer"); assert(stream); - pa_operation* operation = pa_stream_update_sample_rate(stream,rate, NULL, NULL); + pa_operation* operation = pa_stream_update_sample_rate(stream,rate, update_sample_rate_callback, NULL); assert(operation); return convertPointerToJavaLong(operation);