changeset in /hg/pulseaudio: 2008-09-16 Omair Majid <omajid at redh...
Omair Majid
omajid at redhat.com
Tue Sep 16 11:05:54 PDT 2008
changeset 3c5c586cf5f3 in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=3c5c586cf5f3
description:
2008-09-16 Omair Majid <omajid at redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
(getLine): Throw the exception with a more meaningful description.
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(drain): Implemented drain. Blocks while the TargetDataLine remains started.
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java
(testIsActiveAndIsOpen): Fixed thinko. Now tests a TargetDataLine instead
of a SourceDataLine.
(testDrain): New function. Tests if drain() blocks between calls to
start() and stop().
(testStartedStopped): Removed call to drain. Instead wait a bit.
(tearDown): Clean up a bit more if possible.
diffstat:
3 files changed, 60 insertions(+), 8 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java | 2
src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java | 9 +
unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java | 57 ++++++++--
diffs (133 lines):
diff -r 7ad349ee575d -r 3c5c586cf5f3 src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Mon Sep 15 16:52:31 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Tue Sep 16 14:05:45 2008 -0400
@@ -255,7 +255,7 @@ public class PulseAudioMixer implements
throws LineUnavailableException {
if (!isOpen) {
- throw new LineUnavailableException();
+ throw new LineUnavailableException("The mixer isnt open");
}
if (!isLineSupported(info)) {
diff -r 7ad349ee575d -r 3c5c586cf5f3 src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Mon Sep 15 16:52:31 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Tue Sep 16 14:05:45 2008 -0400
@@ -141,7 +141,14 @@ public class PulseAudioTargetDataLine ex
@Override
public void drain() {
- // FIXME how do we drain a target data line?
+ // blocks when there is data on the line
+ // http://www.jsresources.org/faq_audio.html#stop_drain_tdl
+ while (isStarted) {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) { }
+ }
+
}
@Override
diff -r 7ad349ee575d -r 3c5c586cf5f3 unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java Mon Sep 15 16:52:31 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java Tue Sep 16 14:05:45 2008 -0400
@@ -49,7 +49,6 @@ import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineListener;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.Mixer;
-import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
@@ -101,8 +100,8 @@ public class PulseAudioTargetDataLineTes
@Test
public void testIsActiveAndIsOpen() throws LineUnavailableException {
- SourceDataLine line = (SourceDataLine) mixer.getLine(new DataLine.Info(
- SourceDataLine.class, aSupportedFormat, 1000));
+ TargetDataLine line = (TargetDataLine) mixer.getLine(new DataLine.Info(
+ TargetDataLine.class, aSupportedFormat, 1000));
Assert.assertFalse(line.isActive());
Assert.assertFalse(line.isOpen());
@@ -147,6 +146,40 @@ public class PulseAudioTargetDataLineTes
}
@Test
+ public void testDrain() throws LineUnavailableException,
+ InterruptedException {
+ System.out
+ .println("This test checks that drain() on a start()ed TargetDataLine hangs");
+
+ targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info(
+ TargetDataLine.class));
+ Assert.assertNotNull(targetDataLine);
+
+ targetDataLine.open();
+ targetDataLine.start();
+
+ Thread th = new Thread(new Runnable() {
+
+ @Override
+ public void run() {
+ targetDataLine.drain();
+ }
+
+ });
+
+ th.start();
+
+ th.join(5000);
+
+ if (!th.isAlive()) {
+ targetDataLine.stop();
+ th.join();
+ targetDataLine.close();
+ Assert.fail("drain() on a opened TargetDataLine should hang");
+ }
+ }
+
+ @Test
public void testCloseEvents() throws LineUnavailableException {
targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info(
TargetDataLine.class));
@@ -176,7 +209,7 @@ public class PulseAudioTargetDataLineTes
@Test
public void testStartedStopped() throws LineUnavailableException,
- UnsupportedAudioFileException, IOException {
+ UnsupportedAudioFileException, IOException, InterruptedException {
File soundFile = new File("testsounds/startup.wav");
AudioInputStream audioInputStream = AudioSystem
@@ -215,7 +248,7 @@ public class PulseAudioTargetDataLineTes
line.start();
- line.drain();
+ Thread.sleep(100);
line.stop();
line.close();
@@ -261,7 +294,19 @@ public class PulseAudioTargetDataLineTes
@After
public void tearDown() {
- mixer.close();
+ if (targetDataLine != null) {
+ if (targetDataLine.isActive()) {
+ targetDataLine.stop();
+ }
+
+ if (targetDataLine.isOpen()) {
+ targetDataLine.close();
+ }
+ }
+
+ if (mixer.isOpen()) {
+ mixer.close();
+ }
}
}
More information about the distro-pkg-dev
mailing list