Mercurial > hg > pulseaudio
changeset 124:7ad349ee575d
2008-09-15 Omair Majid <omajid@redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java
(connectLine): May throw LineUnavailableException now.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
(open): Now rethrows exceptions from connectLine.
(connectLine): Throws LineUnavailableException.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java
(connectLine): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(connectLine): Likewise.
* src/java/org/classpath/icedtea/pulseaudio/Stream.java
(connectForPlayback): Throws an exception if pa_stream_connect_playback
fails.
(connectForRecording): Throws an exception if pa_stream_connect_record
fails.
* src/native/org_classpath_icedtea_pulseaudio_Stream.c
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1connect_1playback):
Dont assert out and die if call to pa_stream_connect_playback fails.
(Java_org_classpath_icedtea_pulseaudio_Stream_native_1pa_1stream_1connect_1record):
Dont assert out and die if the call to pa_stream_connect_record fails.
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerRawTest.java
(setUp): Close the mixer if it was open before.
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java
(testStartNotificationOnCork): Added a note explaining that this test is
broken.
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java
(testDrainTwice): New function. This test drains a mixer twice.
(testFlushTwice): New function. This test flushes a mixer twice.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Mon, 15 Sep 2008 16:52:31 -0400 |
parents | cd7041f7a655 |
children | 3c5c586cf5f3 |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java src/java/org/classpath/icedtea/pulseaudio/Stream.java src/native/org_classpath_icedtea_pulseaudio_Stream.c unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerRawTest.java unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java |
diffstat | 9 files changed, 60 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Fri Sep 12 16:28:22 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioClip.java Mon Sep 15 16:52:31 2008 -0400 @@ -173,7 +173,7 @@ } - protected void connectLine(int bufferSize) { + protected void connectLine(int bufferSize) throws LineUnavailableException { StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( bufferSize, bufferSize / 2, bufferSize / 2, bufferSize / 2, 0);
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Fri Sep 12 16:28:22 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Mon Sep 15 16:52:31 2008 -0400 @@ -153,8 +153,15 @@ stream.addPlaybackStartedListener(startedListener); - synchronized (eventLoop.threadLock) { - connectLine(bufferSize); + try { + synchronized (eventLoop.threadLock) { + connectLine(bufferSize); + } + + } catch (LineUnavailableException e) { + // error connecting to the server! + // FIXME clean up + throw e; } this.bufferSize = bufferSize; try { @@ -231,7 +238,8 @@ return isEngagedInIo; } - protected abstract void connectLine(int bufferSize); + protected abstract void connectLine(int bufferSize) + throws LineUnavailableException; public abstract void drain();
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Fri Sep 12 16:28:22 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLine.java Mon Sep 15 16:52:31 2008 -0400 @@ -103,7 +103,7 @@ } - protected void connectLine(int bufferSize) { + protected void connectLine(int bufferSize) throws LineUnavailableException { StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( bufferSize, bufferSize / 4, bufferSize / 4, bufferSize / 10, 0);
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Fri Sep 12 16:28:22 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Sep 15 16:52:31 2008 -0400 @@ -74,7 +74,7 @@ parentMixer.addTargetLine(this); } - protected void connectLine(int bufferSize) { + protected void connectLine(int bufferSize) throws LineUnavailableException { StreamBufferAttributes bufferAttributes = new StreamBufferAttributes( bufferSize, 0, 0, 0, bufferSize / 10); synchronized (eventLoop.threadLock) {
--- a/src/java/org/classpath/icedtea/pulseaudio/Stream.java Fri Sep 12 16:28:22 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/Stream.java Mon Sep 15 16:52:31 2008 -0400 @@ -41,6 +41,8 @@ import java.util.LinkedList; import java.util.List; +import javax.sound.sampled.LineUnavailableException; + /** * * This class encapsulates a pa_stream object and provides easier access to the @@ -421,31 +423,42 @@ * @param deviceName * the device to connect to. use * <code>null</code for the default device + * @throws LineUnavailableException */ public void connectForPlayback(String deviceName, - StreamBufferAttributes bufferAttributes) { + StreamBufferAttributes bufferAttributes) + throws LineUnavailableException { int returnValue = native_pa_stream_connect_playback(deviceName, bufferAttributes.getMaxLength(), bufferAttributes .getTargetLength(), bufferAttributes.getPreBuffering(), bufferAttributes.getMinimumRequest(), bufferAttributes .getFragmentSize(), 0, null, null); - assert (returnValue == 0); + if (returnValue < 0) { + throw new LineUnavailableException( + "Unable To connect a line for playback"); + } } /** * Connect the stream to a source. * + * @throws LineUnavailableException + * */ public void connectForRecording(String deviceName, - StreamBufferAttributes bufferAttributes) { + StreamBufferAttributes bufferAttributes) + throws LineUnavailableException { int returnValue = native_pa_stream_connect_record(deviceName, bufferAttributes.getMaxLength(), bufferAttributes .getTargetLength(), bufferAttributes.getPreBuffering(), bufferAttributes.getMinimumRequest(), bufferAttributes .getFragmentSize(), 0, null, null); - assert (returnValue == 0); + if (returnValue < 0) { + throw new LineUnavailableException( + "Unable to connect line for recording"); + } } /**
--- a/src/native/org_classpath_icedtea_pulseaudio_Stream.c Fri Sep 12 16:28:22 2008 -0400 +++ b/src/native/org_classpath_icedtea_pulseaudio_Stream.c Mon Sep 15 16:52:31 2008 -0400 @@ -412,7 +412,7 @@ } } int value = pa_stream_connect_playback(stream, dev, &buffer_attr, 0, NULL, NULL); - assert(value >= 0); + if (dev != NULL) { (*env)->ReleaseStringUTFChars(env, device, dev); dev = NULL; @@ -456,7 +456,6 @@ } int value = pa_stream_connect_record(stream, dev, &buffer_attr, flags); - assert(value >= 0); if (dev != NULL) { (*env)->ReleaseStringUTFChars(env, device, dev);
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerRawTest.java Fri Sep 12 16:28:22 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerRawTest.java Mon Sep 15 16:52:31 2008 -0400 @@ -52,6 +52,9 @@ @Before public void setUp() { mixer = PulseAudioMixer.getInstance(); + if (mixer.isOpen()) { + mixer.close(); + } } @Test
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java Fri Sep 12 16:28:22 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineRawTest.java Mon Sep 15 16:52:31 2008 -0400 @@ -84,6 +84,7 @@ } + // FIXME this test is BROKEN! @Test public void testStartNotificationOnCork() throws UnsupportedAudioFileException, IOException,
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java Fri Sep 12 16:28:22 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java Mon Sep 15 16:52:31 2008 -0400 @@ -548,6 +548,30 @@ } @Test + public void testDrainTwice() throws LineUnavailableException { + SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, aSupportedFormat, 1000)); + + line.open(); + line.drain(); + line.drain(); + line.close(); + + } + + @Test + public void testFlushTwice() throws LineUnavailableException { + SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, aSupportedFormat, 1000)); + + line.open(); + line.flush(); + line.flush(); + line.close(); + + } + + @Test public void testMixerKnowsAboutOpenLines() throws LineUnavailableException { SourceDataLine sourceDataLine = (SourceDataLine) mixer .getLine(new Line.Info(SourceDataLine.class));