changeset in /hg/pulseaudio: 2008-10-07 Omair Majid <omajid at redh...

Omair Majid omajid at redhat.com
Tue Oct 7 09:06:26 PDT 2008


changeset e688b471726e in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=e688b471726e
description:
	2008-10-07 Omair Majid <omajid at redhat.com>

	    * src/native/jni-common.h
	    Grouped related functions together. Added sections in file. Added two
	    constants ILLEGAL_STATE_EXCEPTION and ILLEGAL_ARGUMENT_EXCEPTION to make
	    it easiser to throw exceptions.

	    * src/native/org_classpath_icedtea_pulseaudio_Stream.c
	    (Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1read):
	    Removed commented function.
	    (drain_callback): Throw an exception instaed of an assert if the operation
	    failed.
	    (cork_callback): Likewise.
	    (flush_callback): Likewise.
	    (trigger_callback): Likewise.
	    (set_name_callback): Likewise.
	    (set_buffer_attr_callback): Likewise.
	    (update_sample_rate_callback): Likewise

diffstat:

2 files changed, 100 insertions(+), 83 deletions(-)
src/native/jni-common.h                              |   27 ++-
src/native/org_classpath_icedtea_pulseaudio_Stream.c |  156 +++++++++---------

diffs (302 lines):

diff -r 6695cbc7fe43 -r e688b471726e src/native/jni-common.h
--- a/src/native/jni-common.h	Mon Oct 06 17:03:22 2008 -0400
+++ b/src/native/jni-common.h	Tue Oct 07 11:31:39 2008 -0400
@@ -49,6 +49,21 @@ typedef struct java_context_t {
 	jobject obj;
 } java_context_t;
 
+/* Exception Handling */
+
+void throwByName(JNIEnv* const env, const char* const name,
+		const char* const msg);
+
+#define ILLEGAL_ARGUMENT_EXCEPTION "java/lang/IllegalArgumentException"
+#define ILLEGAL_STATE_EXCEPTION "java/lang/IllegalStateException"
+
+/* Threading and Synchronization */
+
+jobject getLockObject(JNIEnv* env);
+void notifyWaitingOperations(JNIEnv* env);
+
+/* Storing and Loading Values */
+
 jint getJavaIntField(JNIEnv* env, jobject obj, char* fieldName);
 void setJavaIntField(JNIEnv* env, jobject obj, char* fieldName, jint value);
 
@@ -59,13 +74,7 @@ void setJavaByteArrayField(JNIEnv* env, 
 void setJavaByteArrayField(JNIEnv* env, jobject obj, char* name,
 		jbyteArray array);
 
-void callJavaVoidMethod(JNIEnv* env, jobject obj, const char* method_name);
-
-void throwByName(JNIEnv* const env, const char* const name,
-		const char* const msg);
-
-jobject getLockObject(JNIEnv* env);
-void notifyWaitingOperations(JNIEnv* env);
+/* Pointers and Java */
 
 void* getJavaPointer(JNIEnv* env, jobject obj, char* name);
 void setJavaPointer(JNIEnv* env, jobject obj, char*name, void* pointer_value);
@@ -73,5 +82,9 @@ void* convertJavaPointerToNative(JNIEnv*
 void* convertJavaPointerToNative(JNIEnv* env, jbyteArray pointer);
 jbyteArray convertNativePointerToJava(JNIEnv* env, void* pointer);
 
+/* Calling Java Functions */
+
+void callJavaVoidMethod(JNIEnv* env, jobject obj, const char* method_name);
+
 #endif
 
diff -r 6695cbc7fe43 -r e688b471726e src/native/org_classpath_icedtea_pulseaudio_Stream.c
--- a/src/native/org_classpath_icedtea_pulseaudio_Stream.c	Mon Oct 06 17:03:22 2008 -0400
+++ b/src/native/org_classpath_icedtea_pulseaudio_Stream.c	Tue Oct 07 11:31:39 2008 -0400
@@ -401,15 +401,14 @@ JNIEXPORT jint JNICALL Java_org_classpat
 		jbyteArray volumePointer, jbyteArray sync_streamPointer) {
 
 	pa_stream *sync_stream;
-        if(sync_streamPointer != NULL) {
-        	sync_stream = convertJavaPointerToNative(env, sync_streamPointer);
-        	printf("Master stream is %p\n", sync_stream);
-        } else {
-        	sync_stream = NULL;
-        }
-
-	pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER);
-
+	if(sync_streamPointer != NULL) {
+		sync_stream = convertJavaPointerToNative(env, sync_streamPointer);
+		printf("Master stream is %p\n", sync_stream);
+	} else {
+		sync_stream = NULL;
+	}
+
+	pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER);
 
 	pa_buffer_attr buffer_attr;
 
@@ -436,8 +435,8 @@ JNIEXPORT jint JNICALL Java_org_classpat
 		}
 	}
 	/* Set flags to 0 to fix problem with draining before calling start, might need to
-	be changed back to PA_STREAM_START_CORKED in the future, if we'll be able to implement
-	synchronization*/ 
+	 be changed back to PA_STREAM_START_CORKED in the future, if we'll be able to implement
+	 synchronization*/
 	int value = pa_stream_connect_playback(stream, dev, &buffer_attr, 0, NULL, sync_stream);
 
 	if (dev != NULL) {
@@ -526,24 +525,6 @@ JNIEXPORT jint JNICALL Java_org_classpat
 }
 
 /*
-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, STREAM_POINTER);
-	assert(stream);
-	const void *read_data = NULL;
-	size_t read_length = 0;
-	pa_stream_peek(stream, &read_data, &read_length);
-	if (length < read_length) {
-		read_length = length;
-	}
-
-	(*env)->SetByteArrayRegion(env, array, offset, read_length, read_data);
-	pa_stream_drop(stream);
-	return read_length;
-}
-*/
-
-/*
  * Class:     org_classpath_icedtea_pulseaudio_Stream
  * Method:    native_pa_stream_peek
  * Signature: ()[B
@@ -564,7 +545,7 @@ JNIEXPORT jbyteArray JNICALL Java_org_cl
 	if (startLocation == NULL) {
 		return NULL;
 	}
-	
+
 	jsize length = count;
 	jbyteArray data = (*env)->NewByteArray(env, length);
 
@@ -616,48 +597,56 @@ JNIEXPORT jint JNICALL Java_org_classpat
 
 static void drain_callback(pa_stream* stream, int success, void* userdata) {
 
-	assert(success);
+	assert(stream);
+	JNIEnv* env = pulse_thread_env;
+	assert(env);
+
+	notifyWaitingOperations(env);
+
+	if (success == 0) {
+		throwByName(env, ILLEGA_STATE_EXCEPTION, "drain failed");
+	}
+
+}
+
+/*
+ * Class:     org_classpath_icedtea_pulseaudio_Stream
+ * Method:    native_pa_stream_drain
+ * Signature: ()[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drain
+(JNIEnv* env, jobject obj) {
+	pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER);
+	assert(stream);
+	pa_operation* operation = pa_stream_drain(stream, drain_callback, NULL);
+	assert(operation);
+	return convertNativePointerToJava(env, operation);
+}
+
+/*
+ * Class:     org_classpath_icedtea_pulseaudio_Stream
+ * Method:    native_pa_stream_is_corked
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1is_1corked
+(JNIEnv* env, jobject obj) {
+	pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER);
+	assert(stream);
+	return pa_stream_is_corked(stream);
+}
+
+static void cork_callback(pa_stream* stream, int success, void* userdata) {
+
+	java_context* context = userdata;
+	assert(stream);
+	assert(context);
 	JNIEnv* env = pulse_thread_env;
 	assert(env);
 	notifyWaitingOperations(env);
 
-}
-
-/*
- * Class:     org_classpath_icedtea_pulseaudio_Stream
- * Method:    native_pa_stream_drain
- * Signature: ()[B
- */
-JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drain
-(JNIEnv* env, jobject obj) {
-	pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, STREAM_POINTER);
-	assert(stream);
-	pa_operation* operation = pa_stream_drain(stream, drain_callback, NULL);
-	assert(operation);
-	return convertNativePointerToJava(env, operation);
-}
-
-/*
- * Class:     org_classpath_icedtea_pulseaudio_Stream
- * Method:    native_pa_stream_is_corked
- * Signature: ()I
- */
-JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1is_1corked
-(JNIEnv* env, jobject obj) {
-	pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, STREAM_POINTER);
-	assert(stream);
-	return pa_stream_is_corked(stream);
-}
-
-static void cork_callback(pa_stream* stream, int success, void* userdata) {
-
-	java_context* context = userdata;
-	assert(stream);
-	assert(context);
-	assert(success);
-	JNIEnv* env = pulse_thread_env;
-	assert(env);
-	notifyWaitingOperations(env);
+	if (success == 0) {
+		throwByName(env, ILLEGAL_STATE_EXCEPTION, "cork failed");
+	}
 
 }
 
@@ -680,11 +669,15 @@ JNIEXPORT jbyteArray JNICALL Java_org_cl
 }
 
 static void flush_callback(pa_stream* stream, int success, void* userdata) {
-	assert(success);
+	assert(stream);
 	JNIEnv* env = pulse_thread_env;
 	assert(env);
 	notifyWaitingOperations(env);
 
+	if (success == 0) {
+		throwByName(env, ILLEGAL_STATE_EXCEPTION, "flush failed");
+	}
+
 }
 
 /*
@@ -702,11 +695,15 @@ JNIEXPORT jbyteArray JNICALL Java_org_cl
 }
 
 static void trigger_callback(pa_stream* stream, int success, void* userdata) {
-	assert(success);
+	assert(stream);
 	JNIEnv* env = pulse_thread_env;
 	assert(env);
 	notifyWaitingOperations(env);
 
+	if (success == 0) {
+		throwByName(env, ILLEGAL_STATE_EXCEPTION, "trigger failed");
+	}
+
 }
 
 /*
@@ -724,10 +721,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_cl
 }
 
 static void set_name_callback(pa_stream* stream, int success, void* userdata) {
-	assert(success);
+	assert(stream);
 	JNIEnv* env = pulse_thread_env;
 	notifyWaitingOperations(env);
 
+	if (success == 0) {
+		throwByName(env, ILLEGAL_STATE_EXCEPTION, "set_name failed");
+	}
 }
 
 /*
@@ -856,14 +856,14 @@ static void set_buffer_attr_callback(pa_
 static void set_buffer_attr_callback(pa_stream* stream, int success,
 		void* userdata) {
 
-	const pa_buffer_attr* buffer = pa_stream_get_buffer_attr(stream);
-	assert(buffer);
-
-	assert(success);
+	assert(stream);
 	JNIEnv* env = pulse_thread_env;
 	assert(env);
 	notifyWaitingOperations(env);
 
+	if (success == 0) {
+		throwByName(env, ILLEGAL_STATE_EXCEPTION, "set_buffer_attr failed");
+	}
 }
 
 /*
@@ -918,11 +918,15 @@ JNIEXPORT jbyteArray JNICALL Java_org_cl
 
 static void update_sample_rate_callback(pa_stream* stream, int success,
 		void* userdata) {
-	assert(success);
+	assert(stream);
 	JNIEnv* env = pulse_thread_env;
 	assert(env);
 	notifyWaitingOperations(env);
 
+	if (success == 0) {
+		throwByName(eng, ILLEGAL_STATE_EXCEPTION, "update_sampl_rate failed");
+	}
+
 }
 /*
  * Class:     org_classpath_icedtea_pulseaudio_Stream



More information about the distro-pkg-dev mailing list