# HG changeset patch # User Omair Majid # Date 1223483400 14400 # Node ID 0a46fbaa018e9d84b30fb4279fbd854f704c4dd1 # Parent a3a8e9e199670ce557d76352bc73850d256b51a6 2008-10-08 Omair Majid * src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java (PulseAudioMixer): Call refreshSourceAndTargetLines to initialize sourceLines and targetLines. (getLine): Check that a line is supported before worrying about whether the mixer is open. * unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java New variable aNotSupportedFormat that represents a known format that does not work with PulseAudio*DataLine. (testLineSupportedWorksWithoutOpeningMixer): New test. Checks that isLineSupported works without depending on the mixer to be open. diff -r a3a8e9e19967 -r 0a46fbaa018e src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java --- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Wed Oct 08 10:38:29 2008 -0400 +++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java Wed Oct 08 12:30:00 2008 -0400 @@ -103,6 +103,8 @@ formats, StreamBufferAttributes.MIN_VALUE, StreamBufferAttributes.MAX_VALUE)); + refreshSourceAndTargetLines(); + } synchronized public static PulseAudioMixer getInstance() { @@ -252,17 +254,16 @@ } @Override - public Line getLine(javax.sound.sampled.Line.Info info) - throws LineUnavailableException { + public Line getLine(Line.Info info) throws LineUnavailableException { + + if (!isLineSupported(info)) { + throw new IllegalArgumentException("Line unsupported: " + info); + } if (!isOpen) { throw new LineUnavailableException("The mixer isnt open"); } - if (!isLineSupported(info)) { - throw new IllegalArgumentException("Line unsupported: " + info); - } - AudioFormat[] formats = null; AudioFormat defaultFormat = null; @@ -324,7 +325,7 @@ if (isLineSupported(info)) { return AudioSystem.NOT_SPECIFIED; } - + return 0; } diff -r a3a8e9e19967 -r 0a46fbaa018e unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java --- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java Wed Oct 08 10:38:29 2008 -0400 +++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java Wed Oct 08 12:30:00 2008 -0400 @@ -39,6 +39,7 @@ import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.DataLine; import javax.sound.sampled.Line; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineListener; @@ -60,6 +61,8 @@ AudioFormat aSupportedFormat = new AudioFormat( AudioFormat.Encoding.PCM_UNSIGNED, 44100f, 8, 1, 1, 44100f, true); + AudioFormat aNotSupportedFormat = new AudioFormat( + AudioFormat.Encoding.ULAW, 44100, 32, 10, 10, 44100f, true); @Before public void setUp() throws Exception { @@ -367,6 +370,19 @@ } @Test + public void testLineSupportedWorksWithoutOpeningMixer() { + + Assert.assertFalse(selectedMixer.isOpen()); + + Assert.assertFalse(selectedMixer.isLineSupported(new DataLine.Info( + SourceDataLine.class, aNotSupportedFormat))); + + Assert.assertTrue(selectedMixer.isLineSupported(new DataLine.Info( + SourceDataLine.class, aSupportedFormat))); + + } + + @Test public void testSynchronizationNotSupported() throws LineUnavailableException { selectedMixer.open();