Mercurial > hg > pulseaudio
changeset 116:29f7e9dc42dd
2009-09-11 Omair Majid <omajid@redhat.com>
* unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java
(setUp): Initialize started and stopped to 0.
(testStartNotificationOnCork): New test. Tests if cork/uncork fire START
and STOP events.
(tearDown): set started/stopped to 0.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Thu, 11 Sep 2008 14:40:42 -0400 |
parents | c2664adb0201 |
children | 850570c7af31 |
files | unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java |
diffstat | 1 files changed, 94 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java Thu Sep 11 10:42:34 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseSourceDataLineTest.java Thu Sep 11 14:40:42 2008 -0400 @@ -54,7 +54,6 @@ 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; @@ -68,6 +67,9 @@ private int listenerCalled = 0; + int started = 0; + int stopped = 0; + AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 10, true); @@ -80,6 +82,9 @@ mixer = PulseAudioMixer.getInstance(); mixer.open(); + started = 0; + stopped = 0; + } @Test @@ -156,9 +161,6 @@ } - int started = 0; - int stopped = 0; - @Test public void testStartedStopped() throws LineUnavailableException, UnsupportedAudioFileException, IOException { @@ -173,9 +175,6 @@ SourceDataLine.class, audioFormat)); Assert.assertNotNull(line); - started = 0; - stopped = 0; - line.open(audioFormat); LineListener startStopListener = new LineListener() { @@ -216,8 +215,91 @@ Assert.assertEquals(1, started); Assert.assertEquals(1, stopped); - started = 0; - stopped = 0; + } + + @Test + public void testStartNotificationOnCork() + throws UnsupportedAudioFileException, IOException, + LineUnavailableException { + + File soundFile = new File("testsounds/startup.wav"); + AudioInputStream audioInputStream = AudioSystem + .getAudioInputStream(soundFile); + AudioFormat audioFormat = audioInputStream.getFormat(); + + PulseAudioSourceDataLine line; + line = (PulseAudioSourceDataLine) mixer.getLine(new DataLine.Info( + SourceDataLine.class, audioFormat)); + Assert.assertNotNull(line); + + line.open(audioFormat); + + LineListener startStopListener = new LineListener() { + + @Override + public void update(LineEvent event) { + if (event.getType() == LineEvent.Type.START) { + started++; + } + + if (event.getType() == LineEvent.Type.STOP) { + stopped++; + } + } + + }; + + line.addLineListener(startStopListener); + + byte[] abData = new byte[1000]; + int bytesRead = 0; + + line.start(); + int count = 0; + + while (bytesRead >= 0) { + bytesRead = audioInputStream.read(abData, 0, abData.length); + if (bytesRead > 0) { + line.write(abData, 0, bytesRead); + count++; + /* + * keep count high. if it is too low, the line wont even start + * playing so stopping is out of the question + */ + if (count == 100) { + Operation o; + synchronized (EventLoop.getEventLoop().threadLock) { + o = line.getStream().cork(); + } + + o.waitForCompletion(); + o.releaseReference(); + + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + synchronized (EventLoop.getEventLoop().threadLock) { + o = line.getStream().unCork(); + } + + o.waitForCompletion(); + o.releaseReference(); + + } + } + } + + line.drain(); + + line.stop(); + line.close(); + + Assert.assertEquals(2, started); + Assert.assertEquals(2, stopped); } @@ -617,6 +699,9 @@ @After public void tearDown() throws Exception { + started = 0; + stopped = 0; + if (mixer.isOpen()) { mixer.close(); }