Mercurial > hg > pulseaudio
changeset 36:73125e09b897
removing obsolete files
committer: Omair Majid <omajid@redhat.com>
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Fri, 01 Aug 2008 12:02:49 -0400 |
parents | 7dbea4cf0170 |
children | 127841aeb6e9 177bc55c9384 |
files | src/PulseAudioMixer.c src/PulseAudioMixer.h src/PulseAudioSourceDataLine.c src/PulseAudioSourceDataLine.h src/PulseAudioTargetDataLine.c src/org/openjdk/sound/PulseAudioSourceDataLine.java src/org_openjdk_sound_PulseAudioSourceDataLine.c_ORIGINAL src/org_openjdk_sound_PulseAudioSourceDataLine.h |
diffstat | 8 files changed, 3 insertions(+), 876 deletions(-) [+] |
line wrap: on
line diff
--- a/src/PulseAudioMixer.c Fri Aug 01 11:59:27 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -#include <jni.h> -#include <pulse/pulseaudio.h> - - - -void setJavaLongField(JNIEnv *env, jobject obj, void *ptr, char *fieldName) { - jclass cls = (*env)->GetObjectClass(env, obj); - jlong value = (long) ptr; - jfieldID fid =(*env)->GetFieldID(env, cls, fieldName, "J"); - (*env)->SetLongField(env, obj, fid, value); - //CHECK No DeleteLocalReference Method? - //(*env)->DeleteLocalReference(cls); -} - -static void context_state_cb(pa_context* context, void* userdata) { - assert(context); - pa_threaded_mainloop *mainloop = userdata; - switch (pa_context_get_state(context)) { - case PA_CONTEXT_READY: - case PA_CONTEXT_TERMINATED: - case PA_CONTEXT_FAILED: - pa_threaded_mainloop_signal(mainloop, 0); - break; - default: - break; - } -} - -JNIEXPORT void JNICALL Java_PulseAudioMixer_initialize(JNIEnv *env, jobject obj) { - - //TO DO :check return value for system calls - pa_threaded_mainloop *mainloop = pa_threaded_mainloop_new(); - pa_mainloop_api *mainloop_api = pa_threaded_mainloop_get_api(mainloop); - pa_context *context = pa_context_new(mainloop_api, "Java app"); - - pa_context_set_state_callback(context, context_state_cb, mainloop); - pa_context_connect(context, NULL, 0, NULL); - - pa_threaded_mainloop_lock(mainloop); - - pa_threaded_mainloop_start(mainloop); - - pa_threaded_mainloop_wait(mainloop); - - if ( pa_context_get_state(context) != PA_CONTEXT_READY ) { - printf("context initialization failed\n"); - } - - pa_threaded_mainloop_unlock(mainloop); - - setJavaLongField(env, obj, context, "contextPointer"); - setJavaLongField(env, obj, mainloop, "mainLoopPointer"); -} - - - - - -
--- a/src/PulseAudioMixer.h Fri Aug 01 11:59:27 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class PulseAudioMixer */ - -#ifndef _Included_PulseAudioMixer -#define _Included_PulseAudioMixer -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: PulseAudioMixer - * Method: initialize - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_PulseAudioMixer_initialize - (JNIEnv *, jobject); - -#ifdef __cplusplus -} -#endif -#endif
--- a/src/PulseAudioSourceDataLine.c Fri Aug 01 11:59:27 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,267 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <jni.h> -#include <pulse/pulseaudio.h> -#include "org_openjdk_sound_PulseAudioSourceDataLine.h" - -void setJavaLongField(JNIEnv *env, jobject obj, void *ptr, char *fieldName) { - jclass cls = (*env)->GetObjectClass(env, obj); - jlong value = (long) ptr; - jfieldID fid =(*env)->GetFieldID(env, cls, fieldName, "J"); - (*env)->SetLongField(env, obj, fid, value); - //CHECK No DeleteLocalReference Method? - //(*env)->DeleteLocalReference(cls); -} - -void *getJavaLongField(JNIEnv *env, jobject obj, char *fieldName) { -jclass cls = (*env)->GetObjectClass(env, obj); - jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J"); - jlong value = (*env)->GetLongField(env, obj, fid); - //(*env)->DeleteLocalReference(cls); - return (void *) value; -} - - - -static void stream_write_cb(pa_stream* stream, size_t length, void* userdata) { - pa_threaded_mainloop *mainloop = userdata; - pa_threaded_mainloop_signal(mainloop,0); -} - -static void stream_operation_complete_cb(pa_stream* stream, int success, void* userdata) { - pa_threaded_mainloop *mainloop = userdata; - pa_threaded_mainloop_signal(mainloop,0); -} - - - -static void stream_state_cb(pa_stream* stream, void* userdata) { - assert(stream); - pa_threaded_mainloop *mainloop = userdata; - printf("stream state changed to %d\n", pa_stream_get_state(stream)); - switch (pa_stream_get_state(stream)) { - case PA_STREAM_READY: - case PA_STREAM_FAILED: - case PA_STREAM_TERMINATED: - pa_threaded_mainloop_signal(mainloop, 0); - break; - - default: - /* do nothing */ - break; - } - } - - - - -JNIEXPORT void JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_openStream - (JNIEnv * env, jobject obj, jstring string, jfloat rate, jint size, jint channels, jboolean bigEndian, jint bufferSize){ - - //TO DO: Need to deal with the buffer size. Currently ignored - - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_context *context = getJavaLongField(env, obj, "contextPointer"); - - - pa_sample_spec sample_spec; - - char *encoding = GetStringUTFChars(env, string, NULL); - - if( (strcmp(encoding, "PCM_UNSIGNED") == 0) && (size == 8)) { - sample_spec.format = PA_SAMPLE_U8; - } else if( (strcmp(encoding, "ALAW") == 0) && (size == 8)) { - sample_spec.format = PA_SAMPLE_ALAW; - } else if( (strcmp(encoding, "ULAW") == 0) && (size == 8)) { - sample_spec.format = PA_SAMPLE_ULAW; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 16) && (bigEndian == 1) { - sample_spec.format = PA_SAMPLE_S16BE; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 16) && (bigEndian == 0) { - sample_spec.format = PA_SAMPLE_S16LE; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 32) && (bigEndian == 1) { - sample_spec.format = PA_SAMPLE_S32BE; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 32) && (bigEndian == 0) { - sample_spec.format = PA_SAMPLE_S32LE; - } else { - //TO DO: Invalid format :throw Exception; - } - - sample_spec.rate = rate; - sample_spec.channels = channels; - - pa_threaded_mainloop_lock(mainloop); - - pa_stream *stream = pa_stream_new(context, "default stream", &sample_spec, NULL); - - pa_stream_set_state_callback(stream, stream_state_cb, mainloop); - pa_stream_set_write_callback(stream, stream_write_cb, mainloop); - - - pa_threaded_mainloop_unlock(mainloop); - - - setJavaLongField(env, obj, stream, "streamPointer"); - return; - -unlock_and_fail: - pa_threaded_mainloop_unlock(mainloop); - -fail: - return; -} - -JNIEXPORT void JNICALL -Java_PulseAudioSourceDataLine_startStream(JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_stream_connect_playback(stream, NULL, NULL, 0, NULL, NULL); - pa_threaded_mainloop_wait(mainloop); - if ( pa_stream_get_state(stream) != PA_STREAM_READY ) { - printf("stream initialization failed\n"); - } - pa_threaded_mainloop_unlock(mainloop); -} - -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_resumeStream(JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_cork(stream, 0, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - -} - -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_pauseStream(JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_cork(stream, 1, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); -} - - - -JNIEXPORT void JNICALL -Java_PulseAudioSourceDataLine_writeToStream(JNIEnv *env, jobject obj, jbyteArray data, jint bytesRead, jint indexJava) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - unsigned char *buffer = (*env)->GetByteArrayElements(env, data, NULL); - int length = bytesRead; - int offset = indexJava; - buffer += offset; - - - pa_threaded_mainloop_lock(mainloop); - - while (length > 0) { - - int available_size = pa_stream_writable_size(stream); - while (available_size == 0) { - pa_threaded_mainloop_wait(mainloop); - available_size = pa_stream_writable_size(stream); - } - - if (available_size > length) { - available_size = length; - } - - if (pa_stream_get_state(stream) != PA_STREAM_READY ) { - printf("stream errored!\n"); - goto unlock_and_fail; - } - - pa_stream_write(stream, buffer, available_size, NULL, 0, PA_SEEK_RELATIVE); - - - buffer += available_size; - length -= available_size; - - } - - pa_operation_unref(pa_stream_drain(stream, NULL, NULL)); - - pa_threaded_mainloop_unlock(mainloop); - - - return; - -unlock_and_fail: - pa_threaded_mainloop_unlock(mainloop); -fail: - return; - -} - -JNIEXPORT void JNICALL -Java_PulseAudioSourceDataLine_closeConnection(JNIEnv *env, jobject obj, jint channels, jfloat rate) { - - - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - - printf("pulse_shutdown() called\n"); - - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_drain(stream, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - - //pa_threaded_mainloop_stop(mainloop); - //pa_threaded_mainloop_free(mainloop); -} - -JNIEXPORT jint JNICALL Java_PulseAudioSourceDataLine_available - (JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - int available = pa_stream_writable_size(stream); - pa_threaded_mainloop_unlock(mainloop); - return available; - } - - -JNIEXPORT jint JNICALL Java_PulseAudioSourceDataLine_drain - (JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_drain(stream, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - } - -JNIEXPORT jint JNICALL Java_PulseAudioSourceDataLine_flush - (JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_flush(stream, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - } - - - - - -
--- a/src/PulseAudioSourceDataLine.h Fri Aug 01 11:59:27 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class PulseAudioSourceDataLine */ - -#ifndef _Included_PulseAudioSourceDataLine -#define _Included_PulseAudioSourceDataLine -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: PulseAudioSourceDataLine - * Method: openStream - * Signature: (IF)V - */ -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_openStream - (JNIEnv *, jobject, jint, jfloat); - -/* - * Class: PulseAudioSourceDataLine - * Method: write - * Signature: ([BIILjava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_write - (JNIEnv *, jobject, jbyteArray, jint, jint, jstring); - -/* - * Class: PulseAudioSourceDataLine - * Method: closeConnection - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_closeConnection - (JNIEnv *, jobject); - -/* - * Class: PulseAudioSourceDataLine - * Method: startStream - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_startStream - (JNIEnv *, jobject); - -/* - * Class: PulseAudioSourceDataLine - * Method: pauseStream - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_pauseStream - (JNIEnv *, jobject); - -/* - * Class: PulseAudioSourceDataLine - * Method: resumeStream - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_PulseAudioSourceDataLine_resumeStream - (JNIEnv *, jobject); - -/* - * Class: PulseAudioSourceDataLine - * Method: available - * Signature: ()I - */ -JNIEXPORT jint JNICALL Java_PulseAudioSourceDataLine_available - (JNIEnv *, jobject); - -#ifdef __cplusplus -} -#endif -#endif
--- a/src/PulseAudioTargetDataLine.c Fri Aug 01 11:59:27 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <jni.h> -#include <pulse/pulseaudio.h> -#include <string.h> - - -const char* const APP_NAME = "simple-rec"; - -pa_threaded_mainloop* _mainloop = NULL; -pa_mainloop_api* _mainloop_api = NULL; -pa_context* _context = NULL; -pa_stream* _stream = NULL; -const void *read_data = NULL; -size_t read_index, read_length; - - -pa_sample_spec _sample_spec; - -static void stream_read_cb(pa_stream* stream, size_t length, void* userdata) { - - pa_threaded_mainloop_signal(_mainloop,0); -} - -static void stream_drain_complete_cb(pa_stream* stream, int success, void* userdata) { - pa_threaded_mainloop_signal(_mainloop,0); -} - - - - -static void stream_state_cb(pa_stream* stream, void* userdata) { - assert(stream); - - printf("stream state changed to %d\n", pa_stream_get_state(stream)); - switch (pa_stream_get_state(stream)) { - case PA_STREAM_READY: - case PA_STREAM_FAILED: - case PA_STREAM_TERMINATED: - pa_threaded_mainloop_signal(_mainloop, 0); - break; - - default: - /* do nothing */ - break; - } - } - -static void context_state_cb(pa_context* context, void* userdata) { - assert(context); - - printf("context state changed to %d\n", pa_context_get_state(context)); - - switch (pa_context_get_state(context)) { - case PA_CONTEXT_READY: - case PA_CONTEXT_TERMINATED: - case PA_CONTEXT_FAILED: - pa_threaded_mainloop_signal(_mainloop, 0); - break; - default: - /* do nothing */ - break; - } -} - -static void init_streams(void) { - _sample_spec.format = PA_SAMPLE_S16LE; - _sample_spec.rate = 44100; - _sample_spec.channels = 2; - - _stream = pa_stream_new(_context, "default stream", &_sample_spec, NULL); - - pa_stream_set_state_callback(_stream, stream_state_cb, NULL); - pa_stream_set_read_callback(_stream, stream_read_cb, NULL); - - - - int check = pa_stream_connect_record(_stream, NULL, NULL, 0); - if(check < 0) { - printf("couldn't connect\n"); - } - - /* wait for stream to initilize */ - pa_threaded_mainloop_wait(_mainloop); - - if (pa_stream_get_state(_stream) != PA_STREAM_READY) { - printf("stream initialization failed\n"); - } -} - -static void pulse_init(void) { - - printf("pulse_init() called\n"); - - - _mainloop = pa_threaded_mainloop_new(); - _mainloop_api = pa_threaded_mainloop_get_api(_mainloop); - _context = pa_context_new(_mainloop_api, APP_NAME); - - pa_context_set_state_callback(_context, context_state_cb, NULL); - pa_context_connect(_context, NULL, 0, NULL); - - pa_threaded_mainloop_lock(_mainloop); - - pa_threaded_mainloop_start(_mainloop); - /* wait for context to be ready */ - pa_threaded_mainloop_wait(_mainloop); - - if ( pa_context_get_state(_context) != PA_CONTEXT_READY ) { - printf("context initialization failed\n"); - goto unlock_and_fail; - } - - - init_streams(); - - pa_threaded_mainloop_unlock(_mainloop); - - printf("pulse_init() returning\n"); - return; - -unlock_and_fail: - pa_threaded_mainloop_unlock(_mainloop); - -fail: - return; -} - -int pulse_read (void *data, size_t length) { - printf("IN READ\n"); - pa_threaded_mainloop_lock(_mainloop); - while(length > 0) { - size_t l; - while(!read_data) { - int r = pa_stream_peek(_stream, &read_data, &read_length); - //printf("read length = %d\n", read_length); - if(!read_data) { - pa_threaded_mainloop_wait(_mainloop); - } else { - read_index = 0; - } - } - - l = read_length < length ? read_length : length; - memcpy(data, read_data+read_index, l); - - data = data + l; - length -= l; - read_index +=l; - read_length-=l; - - if(! read_length) { - int r = pa_stream_drop(_stream); - read_data = NULL; - read_length = 0; - read_index = 0; - - } - - - } - pa_threaded_mainloop_unlock(_mainloop); -} - -void closeConnection() { - printf("pulse_shutdown() called\n"); - - pa_threaded_mainloop_lock(_mainloop); - pa_operation *o = pa_stream_drain(_stream, stream_drain_complete_cb, NULL); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(_mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(_mainloop); - - pa_threaded_mainloop_stop(_mainloop); - pa_threaded_mainloop_free(_mainloop); - - printf("pulse_shutdown() returning\n"); - return; -} - - -int main() { - pulse_init(); - uint8_t buf[10000]; - pulse_read(buf, 10000); - //write(1, buf, 10000); - //closeConnection(); - -} - - - - -
--- a/src/org/openjdk/sound/PulseAudioSourceDataLine.java Fri Aug 01 11:59:27 2008 -0400 +++ b/src/org/openjdk/sound/PulseAudioSourceDataLine.java Fri Aug 01 12:02:49 2008 -0400 @@ -44,7 +44,7 @@ String encoding, float rate, int size, int channels, boolean bigEndian, int bufferSize); - private native void native_write(byte[] data, int length); + private native void native_write(byte[] data,int offset, int length); private native int native_get_writable_size();
--- a/src/org_openjdk_sound_PulseAudioSourceDataLine.c_ORIGINAL Fri Aug 01 11:59:27 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,260 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <fcntl.h> -#include <jni.h> -#include <pulse/pulseaudio.h> -#include "org_openjdk_sound_PulseAudioSourceDataLine.h" - -void setJavaLongField(JNIEnv *env, jobject obj, void *ptr, char *fieldName) { - jclass cls = (*env)->GetObjectClass(env, obj); - jlong value = (long) ptr; - jfieldID fid =(*env)->GetFieldID(env, cls, fieldName, "J"); - (*env)->SetLongField(env, obj, fid, value); - //CHECK No DeleteLocalReference Method? - //(*env)->DeleteLocalReference(cls); -} - -void *getJavaLongField(JNIEnv *env, jobject obj, char *fieldName) { -jclass cls = (*env)->GetObjectClass(env, obj); - jfieldID fid = (*env)->GetFieldID(env, cls, fieldName, "J"); - jlong value = (*env)->GetLongField(env, obj, fid); - //(*env)->DeleteLocalReference(cls); - return (void *) value; -} - - - -static void stream_write_cb(pa_stream* stream, size_t length, void* userdata) { - pa_threaded_mainloop *mainloop = userdata; - pa_threaded_mainloop_signal(mainloop,0); -} - -static void stream_operation_complete_cb(pa_stream* stream, int success, void* userdata) { - pa_threaded_mainloop *mainloop = userdata; - pa_threaded_mainloop_signal(mainloop,0); -} - - - -static void stream_state_cb(pa_stream* stream, void* userdata) { - assert(stream); - pa_threaded_mainloop *mainloop = userdata; - printf("stream state changed to %d\n", pa_stream_get_state(stream)); - switch (pa_stream_get_state(stream)) { - case PA_STREAM_READY: - case PA_STREAM_FAILED: - pa_threaded_mainloop_signal(mainloop, 0); - break; - case PA_STREAM_TERMINATED: - printf("STREAM DISCONNECTING\n"); - pa_threaded_mainloop_signal(mainloop, 0); - break; - - default: - /* do nothing */ - break; - } - } - - - - -JNIEXPORT void JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_openStream - (JNIEnv * env, jobject obj, jstring string, jfloat rate, jint size, jint channels, jboolean bigEndian, jint bufferSize){ - - //TO DO: Need to deal with the buffer size. Currently ignored - - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_context *context = getJavaLongField(env, obj, "contextPointer"); - - - pa_sample_spec sample_spec; - - char *encoding = (*env)->GetStringUTFChars(env, string, NULL); - - if( (strcmp(encoding, "PCM_UNSIGNED") == 0) && (size == 8)) { - sample_spec.format = PA_SAMPLE_U8; - } else if( (strcmp(encoding, "ALAW") == 0) && (size == 8)) { - sample_spec.format = PA_SAMPLE_ALAW; - } else if( (strcmp(encoding, "ULAW") == 0) && (size == 8)) { - sample_spec.format = PA_SAMPLE_ULAW; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 16) && (bigEndian == 1)) { - sample_spec.format = PA_SAMPLE_S16BE; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 16) && (bigEndian == 0)) { - sample_spec.format = PA_SAMPLE_S16LE; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 32) && (bigEndian == 1)) { - sample_spec.format = PA_SAMPLE_S32BE; - } else if ( (strcmp(encoding, "PCM_SIGNED") == 0) && (size == 32) && (bigEndian == 0)) { - sample_spec.format = PA_SAMPLE_S32LE; - } else { - printf("error in open"); - //TO DO: Invalid format :throw Exception; - } - - sample_spec.rate = rate; - sample_spec.channels = channels; - - pa_threaded_mainloop_lock(mainloop); - - pa_stream *stream = pa_stream_new(context, "default stream", &sample_spec, NULL); - - pa_stream_set_state_callback(stream, stream_state_cb, mainloop); - pa_stream_set_write_callback(stream, stream_write_cb, mainloop); - - - pa_threaded_mainloop_unlock(mainloop); - - - setJavaLongField(env, obj, stream, "streamPointer"); - return; - -unlock_and_fail: - pa_threaded_mainloop_unlock(mainloop); - -fail: - return; -} - -JNIEXPORT void JNICALL -Java_org_openjdk_sound_PulseAudioSourceDataLine_startStream(JNIEnv *env, jobject obj) { - printf("start called\n"); - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_stream_connect_playback(stream, NULL, NULL, 0, NULL, NULL); - pa_threaded_mainloop_wait(mainloop); - if ( pa_stream_get_state(stream) != PA_STREAM_READY ) { - printf("stream initialization failed\n"); - } - pa_threaded_mainloop_unlock(mainloop); -} - -JNIEXPORT void Java_org_openjdk_sound_PulseAudioSourceDataLine_resumeStream(JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_cork(stream, 0, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - -} - -JNIEXPORT void Java_org_openjdk_sound_PulseAudioSourceDataLine__pauseStream(JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_cork(stream, 1, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); -} - - - -JNIEXPORT void JNICALL -Java_org_openjdk_sound_PulseAudioSourceDataLine_writeToStream(JNIEnv *env, jobject obj, jbyteArray data, jint bytesRead, jint indexJava) { - printf("write called\n"); - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - unsigned char *buffer = (*env)->GetByteArrayElements(env, data, NULL); - int length = bytesRead; - int offset = indexJava; - buffer += offset; - - - pa_threaded_mainloop_lock(mainloop); - - while (length > 0) { - - int available_size = pa_stream_writable_size(stream); - while (available_size == 0) { - pa_threaded_mainloop_wait(mainloop); - available_size = pa_stream_writable_size(stream); - } - - if (available_size > length) { - available_size = length; - } - - if (pa_stream_get_state(stream) != PA_STREAM_READY ) { - printf("stream errored!\n"); - goto unlock_and_fail; - } - - pa_stream_write(stream, buffer, available_size, NULL, 0, PA_SEEK_RELATIVE); - printf("written%d\n", available_size); - - - buffer += available_size; - length -= available_size; - - } - - pa_operation_unref(pa_stream_drain(stream, NULL, NULL)); - - pa_threaded_mainloop_unlock(mainloop); - - - return; - -unlock_and_fail: - pa_threaded_mainloop_unlock(mainloop); -fail: - return; - -} - -JNIEXPORT void JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_closeStream - (JNIEnv *env, jobject obj) { - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - printf("STREAM POINTER: %d\n", stream); - pa_stream_disconnect(stream); -} - -JNIEXPORT jint JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_available - (JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - int available = pa_stream_writable_size(stream); - pa_threaded_mainloop_unlock(mainloop); - return available; - } - - -JNIEXPORT void JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_drain - (JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_drain(stream, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - } - -JNIEXPORT void JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_flush - (JNIEnv *env, jobject obj) { - pa_threaded_mainloop *mainloop = getJavaLongField (env, obj, "mainLoopPointer"); - pa_stream *stream = getJavaLongField(env, obj, "streamPointer"); - pa_threaded_mainloop_lock(mainloop); - pa_operation *o = pa_stream_flush(stream, stream_operation_complete_cb, mainloop); - while(pa_operation_get_state(o) != PA_OPERATION_DONE) { - pa_threaded_mainloop_wait(mainloop); - } - pa_operation_unref(o); - pa_threaded_mainloop_unlock(mainloop); - } - - - - - -
--- a/src/org_openjdk_sound_PulseAudioSourceDataLine.h Fri Aug 01 11:59:27 2008 -0400 +++ b/src/org_openjdk_sound_PulseAudioSourceDataLine.h Fri Aug 01 12:02:49 2008 -0400 @@ -20,10 +20,10 @@ /* * Class: org_openjdk_sound_PulseAudioSourceDataLine * Method: native_write - * Signature: ([BI)V + * Signature: ([BII)V */ JNIEXPORT void JNICALL Java_org_openjdk_sound_PulseAudioSourceDataLine_native_1write - (JNIEnv *, jobject, jbyteArray, jint); + (JNIEnv *, jobject, jbyteArray, jint, jint); /* * Class: org_openjdk_sound_PulseAudioSourceDataLine