changeset in /hg/pulseaudio: 2008-08-15 Omair Majid <omajid at redh...
Omair Majid
omajid at redhat.com
Fri Aug 15 14:11:05 PDT 2008
changeset d3ed87d80d16 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=d3ed87d80d16
description:
2008-08-15 Omair Majid <omajid at redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/Stream.java: implemented
drop() and peek()
* src/native/org_classpath_icedtea_pulseaudio_Stream.c: added a prototype
for stream_started_callback(), more cleanup on an error in new().
implmeneted peek() and drop()
diffstat:
2 files changed, 71 insertions(+), 18 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/Stream.java | 26 ++-----
src/native/org_classpath_icedtea_pulseaudio_Stream.c | 63 ++++++++++++++++-
diffs (179 lines):
diff -r 543d5b1cef67 -r d3ed87d80d16 src/java/org/classpath/icedtea/pulseaudio/Stream.java
--- a/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Aug 15 15:46:53 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Aug 15 17:09:53 2008 -0400
@@ -97,13 +97,9 @@ public class Stream {
private native int native_pa_stream_write(byte[] data, int offset,
int length);
- /*
- * private native int native_pa_stream_peek (pa_stream *p, const void
- * **data, size_t *nbytes) Read the next fragment from the buffer (for
- * recording). int pa_stream_drop (pa_stream *p) Remove the current fragment
- * on record streams.
- *
- */
+ private native byte[] native_pa_stream_peek();
+
+ private native int native_pa_stream_drop();
private native int native_pa_stream_writable_size();
@@ -336,7 +332,7 @@ public class Stream {
int returnValue = native_pa_stream_connect_playback(deviceName, 0, 0,
0, 0);
- assert(returnValue == 0);
+ assert (returnValue == 0);
}
/**
@@ -345,7 +341,7 @@ public class Stream {
*/
public void connectForRecording(String deviceName) {
int returnValue = native_pa_stream_connect_record(deviceName, 0, 0);
- assert(returnValue == 0);
+ assert (returnValue == 0);
}
/**
@@ -353,8 +349,8 @@ public class Stream {
*/
public void disconnect() {
int returnValue = native_pa_stream_disconnect();
- assert(returnValue == 0);
- }
+ assert (returnValue == 0);
+ }
/**
* Write data to the server
@@ -373,8 +369,8 @@ public class Stream {
*
* @param data
*/
- public void peek(byte[] data) {
-
+ public byte[] peek() {
+ return native_pa_stream_peek();
}
/**
@@ -382,7 +378,7 @@ public class Stream {
* Remove the current fragment on record streams.
*/
public void drop() {
-
+ native_pa_stream_drop();
}
/**
@@ -467,7 +463,7 @@ public class Stream {
*/
@SuppressWarnings("unused")
private void playbackStartedCallback() {
- assert(false);
+ assert (false);
synchronized (playbackStartedListeners) {
for (PlaybackStartedListener listener : playbackStartedListeners) {
listener.update();
diff -r 543d5b1cef67 -r d3ed87d80d16 src/native/org_classpath_icedtea_pulseaudio_Stream.c
--- a/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Aug 15 15:46:53 2008 -0400
+++ b/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Aug 15 17:09:53 2008 -0400
@@ -96,9 +96,23 @@ static void stream_underflow_callback(pa
}
// requires pulseaudio 0.9.11 :(
-//static void stream_started_callback(pa_stream *p, void *userdata) {
-// printf("stream_started_callback called\n");
-//}
+/*
+ static void stream_started_callback(pa_stream *p, void *userdata) {
+ printf("stream_started_callback called\n");
+ java_context* context = userdata;
+ assert(stream);
+ assert(context);
+ assert(context->env);
+ assert(context->obj);
+
+ if (pa_stream_get_state(stream) == PA_STREAM_CREATING) {
+ callJavaVoidMethod(context->env, context->obj, "playbackStartedCallback");
+ } else {
+ callJavaVoidMethod(pulse_thread_env, context->obj, "playbackStartedCallback");
+ }
+
+ }
+ */
static void stream_latency_update_callback(pa_stream *stream, void *userdata) {
printf("stream_latency_update_callback called\n");
@@ -160,6 +174,7 @@ JNIEXPORT void JNICALL Java_org_classpat
(JNIEnv* env, jobject obj, jlong contextPointer, jstring nameString, jstring encodingString, jint sampleRate, jint channels) {
java_context* j_context = malloc(sizeof(java_context));
+ assert(j_context);
j_context->env = env;
j_context->obj = (*env)->NewGlobalRef(env, obj);
@@ -169,6 +184,8 @@ JNIEXPORT void JNICALL Java_org_classpat
if (nameString) {
name = (*env)->GetStringUTFChars(env,nameString, NULL);
if (name == NULL) {
+ (*env)->DeleteGlobalRef(env, obj);
+ free(j_context);
return; // oome thrown
}
}
@@ -199,6 +216,8 @@ JNIEXPORT void JNICALL Java_org_classpat
throwByName(env, "java/lang/IllegalArgumentException", "Invalid format");
/* clean up */
(*env)->ReleaseStringUTFChars(env, encodingString, encoding);
+ free(j_context);
+ (*env)->DeleteGlobalRef(env, obj);
return;
}
@@ -400,6 +419,44 @@ JNIEXPORT jint JNICALL Java_org_classpat
/*
* Class: org_classpath_icedtea_pulseaudio_Stream
+ * Method: native_pa_stream_peek
+ * Signature: ()[B
+ */
+JNIEXPORT jbyteArray JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1peek
+(JNIEnv* env, jobject obj) {
+
+ pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer");
+ const void* startLocation;
+ size_t count;
+
+ if ( pa_stream_peek(stream, &startLocation, &count) < 0 ) {
+ return NULL;
+ }
+
+ jsize length = count;
+ jbyteArray data = (*env)->NewByteArray(env, length);
+
+ if ( data == NULL) {
+ return NULL; // oome thrown
+ }
+
+ (*env)->SetByteArrayRegion(env, data, 0, count, startLocation);
+ return data;
+}
+
+/*
+ * Class: org_classpath_icedtea_pulseaudio_Stream
+ * Method: native_pa_stream_drop
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1drop
+(JNIEnv* env, jobject obj) {
+ pa_stream* stream = (pa_stream*) getJavaPointer(env, obj, "streamPointer");
+ return pa_stream_drop(stream);
+}
+
+/*
+ * Class: org_classpath_icedtea_pulseaudio_Stream
* Method: native_pa_stream_writable_size
* Signature: ()I
*/
More information about the distro-pkg-dev
mailing list