changeset in /hg/pulseaudio: 2008-08-18 Omair Majid <omajid at redh...
Omair Majid
omajid at redhat.com
Wed Aug 27 09:05:25 PDT 2008
changeset 23ff317f0c99 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=23ff317f0c99
description:
2008-08-18 Omair Majid <omajid at redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java (static):
Removed loading of native library.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(static): Removed obsolete loading of native library.
(read): Fixed code format to eclipse's default.
(available): Find the readable size through the stream class.
* src/java/org/classpath/icedtea/pulseaudio/Stream.java
(native_pa_stream_get_latency): New function.
(native_pa_stream_update_sample_rate): Likewise.
(getLatency): Call native_pa_stream_get_latency to obtain the correct value.
(updateSampleRate): New function.
* src/native/org_classpath_icedtea_pulseaudio_Stream.c (stream_read_callback):
Uncommented function; removed verbose output.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1new):
Enabled calls to stream_read_callback.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1latency):
New function.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1update_1sample_1rate):
Likewise.
diffstat:
4 files changed, 88 insertions(+), 88 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java | 12 -
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java | 52 ++------
src/java/org/classpath/icedtea/pulseaudio/Stream.java | 63 +++++-----
src/native/org_classpath_icedtea_pulseaudio_Stream.c | 49 ++++++-
diffs (360 lines):
diff -r dc7a6d1c130e -r 23ff317f0c99 src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Aug 15 17:11:01 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Mon Aug 18 15:36:12 2008 -0400
@@ -89,18 +89,6 @@ public class PulseAudioClip implements C
};
- static {
- try {
- String library = new java.io.File(".").getCanonicalPath()
- + java.io.File.separatorChar
- + System.mapLibraryName("pulse-java");
- System.out.println(library);
- System.load(library);
- } catch (IOException e) {
- assert ("Loading failed".endsWith("library"));
- }
- }
-
public PulseAudioClip() {
lineListeners = new LinkedList<LineListener>();
}
diff -r dc7a6d1c130e -r 23ff317f0c99 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Aug 15 17:11:01 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Aug 18 15:36:12 2008 -0400
@@ -33,47 +33,30 @@ this exception to your version of the li
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
-*/
+ */
package org.classpath.icedtea.pulseaudio;
-
import java.io.IOException;
import java.util.ArrayList;
import javax.sound.sampled.*;
import javax.sound.sampled.Control.Type;
+public class PulseAudioTargetDataLine extends PulseAudioDataLine implements
+ TargetDataLine {
-public class PulseAudioTargetDataLine extends PulseAudioDataLine implements TargetDataLine {
-
-
-
protected boolean isOpen = false;
protected boolean isPaused = false;
-
+
@SuppressWarnings("unused")
private long streamPointer;
- static {
- try {
- String library = new java.io.File(".").getCanonicalPath() + java.io.File.separatorChar
- + System.mapLibraryName("pulse-java");
- System.out.println(library);
- System.load(library);
- } catch (IOException e) {
- assert ("Loading failed".endsWith("library"));
- }
- }
-
-
- private native int native_get_readable_size();
-
-
- public PulseAudioTargetDataLine(EventLoop eventLoop, AudioFormat[] formats, AudioFormat defaultFormat) {
+ public PulseAudioTargetDataLine(EventLoop eventLoop, AudioFormat[] formats,
+ AudioFormat defaultFormat) {
supportedFormats = formats;
this.eventLoop = eventLoop;
this.lineListeners = new ArrayList<LineListener>();
- this.defaultFormat = defaultFormat;
+ this.defaultFormat = defaultFormat;
this.currentFormat = defaultFormat;
}
@@ -82,16 +65,15 @@ public class PulseAudioTargetDataLine ex
stream.connectForRecording(null);
}
-
@Override
public int read(byte[] data, int offset, int length) {
int frameSize = currentFormat.getFrameSize();
-
+
if (length % frameSize != 0) {
throw new IllegalArgumentException(
"amount of data to write does not represent an integral number of frames");
}
-
+
if (length < 0) {
throw new IllegalArgumentException("length is negative");
}
@@ -112,23 +94,20 @@ public class PulseAudioTargetDataLine ex
sizeRead += bytesRead;
position += bytesRead;
remainingLength -= bytesRead;
-
}
}
// all the data should have been played by now
assert (sizeRead == length);
- //currentFramePosition += (sizeWritten/getFormat().getFrameSize());
+ // currentFramePosition += (sizeWritten/getFormat().getFrameSize());
/*
* FIXME when the stream is flushed() etc, instead of returning length
* this should unblock and return the the size of data written so far
*/
return sizeRead;
-
+
}
-
-
@Override
public void drain() {
@@ -144,10 +123,9 @@ public class PulseAudioTargetDataLine ex
public int available() {
synchronized (eventLoop.threadLock) {
- return native_get_readable_size();
+ return stream.getReableSize();
}
}
-
public int getBufferSize() {
// TODO Auto-generated method stub
@@ -205,11 +183,7 @@ public class PulseAudioTargetDataLine ex
public boolean isControlSupported(Type control) {
// TODO Auto-generated method stub
return false;
-
+
}
-
-
-
-
}
\ No newline at end of file
diff -r dc7a6d1c130e -r 23ff317f0c99 src/java/org/classpath/icedtea/pulseaudio/Stream.java
--- a/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Aug 15 17:11:01 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/Stream.java Mon Aug 18 15:36:12 2008 -0400
@@ -96,8 +96,9 @@ public class Stream {
private native int native_pa_stream_write(byte[] data, int offset,
int length);
-
- private native int native_pa_stream_read(byte[] array, int length, int position);
+
+ private native int native_pa_stream_read(byte[] array, int length,
+ int position);
private native byte[] native_pa_stream_peek();
@@ -110,9 +111,9 @@ public class Stream {
private native long native_pa_stream_drain();
/*
- * Drain a playback stream. pa_operation pa_stream_update_timing_info
- * (pa_stream *p, pa_stream_success_cb_t cb, void *userdata) Request a
- * timing info structure update for a stream.
+ * pa_operation pa_stream_update_timing_info (pa_stream *p,
+ * pa_stream_success_cb_t cb, void *userdata) Request a timing info
+ * structure update for a stream.
*/
private native long native_pa_stream_cork(int b);
@@ -135,10 +136,9 @@ public class Stream {
* native_pa_stream_get_time (pa_usec_t r_usec);
*/
- /*
- * Return the total stream latency private native int
- * native_pa_stream_get_latency ( pa_usec_t *r_usec, int *negative);
- */
+ /* Return the total stream latency */
+ private native long native_pa_stream_get_latency();
+
/*
* const pa_timing_info * pa_stream_get_timing_info (pa_stream *s) Return
@@ -150,16 +150,19 @@ public class Stream {
* per-stream server-side buffer metrics of the stream. pa_operation *
* pa_stream_set_buffer_attr (pa_stream *s, const pa_buffer_attr *attr,
* pa_stream_success_cb_t cb, void *userdata) Change the buffer metrics of
- * the stream during playback. pa_operation * pa_stream_update_sample_rate
- * (pa_stream *s, uint32_t rate, pa_stream_success_cb_t cb, void *userdata)
- * Change the stream sampling rate during playback. pa_operation *
- * pa_stream_proplist_update (pa_stream *s, pa_update_mode_t mode,
- * pa_proplist *p, pa_stream_success_cb_t cb, void *userdata) Update the
- * property list of the sink input/source output of this stream, adding new
- * entries. pa_operation * pa_stream_proplist_remove (pa_stream *s, const
- * char *const keys[], pa_stream_success_cb_t cb, void *userdata) Update the
- * property list of the sink input/source output of this stream, remove
- * entries. int pa_stream_set_monitor_stream (pa_stream *s, uint32_t
+ * the stream during playback.
+ */
+
+ private native long native_pa_stream_update_sample_rate(int rate);
+
+ /*
+ * pa_operation pa_stream_proplist_update (pa_stream *s, pa_update_mode_t
+ * mode, pa_proplist *p, pa_stream_success_cb_t cb, void *userdata) Update
+ * the property list of the sink input/source output of this stream, adding
+ * new entries. pa_operation * pa_stream_proplist_remove (pa_stream *s,
+ * const char *const keys[], pa_stream_success_cb_t cb, void *userdata)
+ * Update the property list of the sink input/source output of this stream,
+ * remove entries. int pa_stream_set_monitor_stream (pa_stream *s, uint32_t
* sink_input_idx) For record streams connected to a monitor source: monitor
* only a very specific sink input of the sink. uint32_t
* pa_stream_get_monitor_stream (pa_stream *s) Return what has been set with
@@ -364,7 +367,7 @@ public class Stream {
public int write(byte[] data, int offset, int length) {
return native_pa_stream_write(data, offset, length);
}
-
+
public int read(byte[] array, int length, int position) {
return native_pa_stream_read(array, length, position);
}
@@ -575,12 +578,11 @@ public class Stream {
return -1;
}
- // TODO: huh?
- /**
- * @returns the total stream latency
- */
- public int getLatency() {
- return -1;
+ /**
+ * @returns the total stream latency in microseconds
+ */
+ public long getLatency() {
+ return native_pa_stream_get_latency();
}
/*
@@ -615,10 +617,11 @@ public class Stream {
* Change the stream sampling rate during playback.
*
*/
- /*
- * Operation updateSampleRate(int rate) { Operation updateOp = new
- * Operation(native_pa_stream_) }
- */
+
+ Operation updateSampleRate(int rate) {
+ return new Operation(native_pa_stream_update_sample_rate(rate));
+
+ }
public long getStreamPointer() {
return streamPointer;
diff -r dc7a6d1c130e -r 23ff317f0c99 src/native/org_classpath_icedtea_pulseaudio_Stream.c
--- a/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Aug 15 17:11:01 2008 -0400
+++ b/src/native/org_classpath_icedtea_pulseaudio_Stream.c Mon Aug 18 15:36:12 2008 -0400
@@ -45,9 +45,9 @@ static void stream_write_callback(pa_str
}
}
-/*static void stream_read_callback(pa_stream *stream, size_t length,
+static void stream_read_callback(pa_stream *stream, size_t length,
void *userdata) {
- printf("stream_read_callback called\n");
+ // printf("stream_read_callback called\n");
java_context* context = userdata;
assert(stream);
@@ -61,7 +61,7 @@ static void stream_write_callback(pa_str
callJavaVoidMethod(pulse_thread_env, context->obj, "readCallback");
}
-}*/
+}
static void stream_overflow_callback(pa_stream *stream, void *userdata) {
printf("stream_overflow_callback called\n");
@@ -172,7 +172,7 @@ static void stream_suspended_callback(pa
*/
JNIEXPORT void JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1new
(JNIEnv* env, jobject obj, jlong contextPointer, jstring nameString, jstring encodingString, jint sampleRate, jint channels) {
-
+ printf("creating a new PulseAudio stream\n");
java_context* j_context = malloc(sizeof(java_context));
assert(j_context);
j_context->env = env;
@@ -250,7 +250,7 @@ JNIEXPORT void JNICALL Java_org_classpat
pa_stream_set_state_callback (stream, stream_state_callback, j_context);
pa_stream_set_write_callback (stream, stream_write_callback, j_context);
- //pa_stream_set_read_callback (stream, stream_read_callback, j_context);
+ pa_stream_set_read_callback (stream, stream_read_callback, j_context);
pa_stream_set_overflow_callback (stream, stream_overflow_callback, j_context);
pa_stream_set_underflow_callback (stream, stream_underflow_callback, j_context);
// pa_stream_set_started_callback (stream, stream_started_callback, j_context);
@@ -418,10 +418,10 @@ JNIEXPORT jint JNICALL Java_org_classpat
}
JNIEXPORT int JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1read
- (JNIEnv *env, jobject obj, jbyteArray array, jint length, jint offset) {
+(JNIEnv *env, jobject obj, jbyteArray array, jint length, jint offset) {
pa_stream *stream = getJavaPointer(env, obj, "streamPointer");
const void *read_data = NULL;
- size_t read_length = 0;
+ size_t read_length = 0;
pa_stream_peek(stream, &read_data, &read_length);
if (length < read_length) {
read_length = length;
@@ -563,3 +563,38 @@ JNIEXPORT jlong JNICALL Java_org_classpa
return convertPointerToJavaLong(operation);
}
+/*
+ * Class: org_classpath_icedtea_pulseaudio_Stream
+ * Method: native_pa_stream_get_latency
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1get_1latency
+(JNIEnv* env, jobject obj) {
+ pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer");
+ assert(stream);
+ pa_usec_t returnValue = 0;
+ int negative = 0;
+ int result = pa_stream_get_latency ( stream, &returnValue, &negative);
+ assert(result == 0);
+ assert(negative == 0);
+ return returnValue;
+}
+
+/*
+ * Class: org_classpath_icedtea_pulseaudio_Stream
+ * Method: native_pa_stream_update_sample_rate
+ * Signature: (I)J
+ */
+JNIEXPORT jlong JNICALL Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1update_1sample_1rate
+(JNIEnv* env, jobject obj, jint newRate) {
+
+ uint32_t rate = (uint32_t) newRate;
+
+ pa_stream* stream = (pa_stream*)getJavaPointer(env, obj, "streamPointer");
+ assert(stream);
+ pa_operation* operation = pa_stream_update_sample_rate(stream,rate, NULL, NULL);
+ assert(operation);
+ return convertPointerToJavaLong(operation);
+
+}
+
More information about the distro-pkg-dev
mailing list