Mercurial > hg > pulseaudio
changeset 140:e29a9eb84a4e
2008-09-24 Omair Majid <omajid@redhat.com>
* src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(open): Reset currentFramePosition to 0.
(read): Add to currentFramePosition.
* unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java
(testOpenEvents): Print OPEN on an OPEN event.
(testCloseEvents): Output CLOSE on a CLOSE event.
(testStartedStopped): Output START on a START event and STOP on a STOP
event.
(testFramePosition): New function. Tests the getFramePosition for a
TargetDataLine.
(testFramePositionWithStartAndStop): New function. Tests frame position of
a TargetDataLine while pausing it for a bit.
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Wed, 24 Sep 2008 10:51:53 -0400 |
parents | 438aa072a80d |
children | 6201d96f7b94 4e1873a3f88f |
files | src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java |
diffstat | 2 files changed, 73 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Tue Sep 23 17:23:27 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLine.java Wed Sep 24 10:51:53 2008 -0400 @@ -79,6 +79,8 @@ super.open(format, bufferSize); + currentFramePosition = 0; + PulseAudioMixer parentMixer = PulseAudioMixer.getInstance(); parentMixer.addTargetLine(this); } @@ -128,7 +130,7 @@ sizeRead += bytesRead; position += bytesRead; remainingLength -= bytesRead; - currentFramePosition = bytesRead / currentFormat.getFrameSize(); + currentFramePosition += bytesRead / currentFormat.getFrameSize(); } }
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java Tue Sep 23 17:23:27 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioTargetDataLineTest.java Wed Sep 24 10:51:53 2008 -0400 @@ -132,6 +132,7 @@ @Override public void update(LineEvent event) { Assert.assertEquals(LineEvent.Type.OPEN, event.getType()); + System.out.println("OPEN"); calledCount++; Assert.assertEquals(1, calledCount); } @@ -222,6 +223,7 @@ @Override public void update(LineEvent event) { Assert.assertEquals(LineEvent.Type.CLOSE, event.getType()); + System.out.println("CLOSE"); calledCount++; Assert.assertEquals(1, calledCount); } @@ -259,12 +261,13 @@ @Override public void update(LineEvent event) { if (event.getType() == LineEvent.Type.START) { + System.out.println("START"); started++; Assert.assertEquals(1, started); } if (event.getType() == LineEvent.Type.STOP) { - System.out.println("Stopped event"); + System.out.println("STOP"); stopped++; Assert.assertEquals(1, stopped); } @@ -317,6 +320,72 @@ targetDataLine.close(); } + @Test + public void testFramePosition() throws LineUnavailableException { + System.out + .println("This test tests frame position for a target data line"); + + final int CHUNCKS = 100; + final int BUFFER_SIZE = 1000; + targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info( + TargetDataLine.class)); + + targetDataLine.open(); + targetDataLine.start(); + byte[] data = new byte[BUFFER_SIZE]; + + for (int i = 0; i < CHUNCKS; i++) { + targetDataLine.read(data, 0, data.length); + } + + targetDataLine.stop(); + long pos = targetDataLine.getLongFramePosition(); + System.out.println("Frames read: " + pos); + long expected = BUFFER_SIZE * CHUNCKS + / targetDataLine.getFormat().getFrameSize(); + System.out.println("Expected: " + expected); + long granularity = 2; + Assert.assertTrue(Math.abs(expected - pos) < granularity); + targetDataLine.close(); + } + + @Test + public void testFramePositionWithStartAndStop() + throws LineUnavailableException, InterruptedException { + System.out + .println("This test tests frame position for a target data line"); + + final int CHUNCKS = 100; + final int BUFFER_SIZE = 1000; + targetDataLine = (TargetDataLine) mixer.getLine(new Line.Info( + TargetDataLine.class)); + + targetDataLine.open(); + targetDataLine.start(); + byte[] data = new byte[BUFFER_SIZE]; + + for (int i = 0; i < CHUNCKS; i++) { + if (i == CHUNCKS / 2) { + targetDataLine.stop(); + Thread.sleep(1000); + targetDataLine.start(); + } + + targetDataLine.read(data, 0, data.length); + } + + targetDataLine.stop(); + long pos = targetDataLine.getLongFramePosition(); + System.out.println("Frames read: " + pos); + long expected = BUFFER_SIZE * CHUNCKS + / targetDataLine.getFormat().getFrameSize(); + System.out.println("Expected: " + expected); + long granularity = 2; + Assert.assertTrue(Math.abs(expected - pos) < granularity); + targetDataLine.close(); + + } + @After public void tearDown() { if (targetDataLine != null) {