Mercurial > hg > pulseaudio
changeset 115:c2664adb0201
2008-09-11 Omair Majid <omajid@redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
(setName): New function. Sets the name of a stream.
(getName): New function. Rerturns the name of a stream.
* unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java
(testSettingStreamName): New funtion. Tests if the name of a stream can be
set. For more correct testing, this needs to use introspection to ask the
PulseAudio daemon about the sink input name.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Thu, 11 Sep 2008 10:42:34 -0400 |
parents | 81eff60b8606 |
children | 29f7e9dc42dd |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java |
diffstat | 2 files changed, 66 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Wed Sep 10 11:00:26 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java Thu Sep 11 10:42:34 2008 -0400 @@ -265,4 +265,29 @@ return AudioSystem.NOT_SPECIFIED; } + public void setName(String streamName) { + if (isOpen) { + /* + * Note: setting the name of the stream after it's created wont + * work. In fact, it sets the name of the application! This is a bug + * in PulseAudio 0.9.12 but fixed in git. + */ + + Operation o; + synchronized (eventLoop.threadLock) { + o = stream.setName(streamName); + } + o.waitForCompletion(); + o.releaseReference(); + + } + + this.streamName = streamName; + + } + + public String getName() { + return streamName; + } + }
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java Wed Sep 10 11:00:26 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java Thu Sep 11 10:42:34 2008 -0400 @@ -54,6 +54,7 @@ import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.UnsupportedAudioFileException; +import javax.sound.sampled.DataLine.Info; import junit.framework.JUnit4TestAdapter; @@ -553,6 +554,46 @@ } @Test + public void testSettingStreamName() throws LineUnavailableException, + UnsupportedAudioFileException, IOException { + File soundFile = new File("testsounds/logout.wav"); + AudioInputStream audioInputStream = AudioSystem + .getAudioInputStream(soundFile); + AudioFormat audioFormat = audioInputStream.getFormat(); + + PulseAudioSourceDataLine line; + line = (PulseAudioSourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, audioFormat)); + + String name = "Knights Who Say ... Oh my god, i am so sorry, i didnt mean it..."; + line.setName(name); + + line.open(audioFormat); + line.start(); + + byte[] abData = new byte[1000]; + int bytesRead = 0; + + while (bytesRead >= 0) { + bytesRead = audioInputStream.read(abData, 0, abData.length); + if (bytesRead > 0) { + line.write(abData, 0, bytesRead); + } + } + + Assert.assertTrue(line.getName() == name); + /* + * FIXME test that PulseAudio also knows this correctly using + * introspection + */ + + line.drain(); + line.stop(); + line.close(); + + } + + @Test public void messWithStreams() throws LineUnavailableException { System.out .println("This test tries to unCork a stream which hasnt been corked");