changeset in /hg/pulseaudio: 2008-10-08 Omair Majid <omajid at redh...

Omair Majid omajid at redhat.com
Wed Oct 8 12:27:47 PDT 2008


changeset 66bcf656c0fb in /hg/pulseaudio
details: http://icedtea.classpath.org/hg/pulseaudio?cmd=changeset;node=66bcf656c0fb
description:
	2008-10-08 Omair Majid <omajid at redhat.com>

	    Merged changes

diffstat:

4 files changed, 72 insertions(+), 20 deletions(-)
src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java            |   26 ++++++++
src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java               |   30 ++++++----
unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java          |   20 +++++-
unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java |   16 ++++-

diffs (223 lines):

diff -r 4260a476a101 -r 66bcf656c0fb src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Wed Oct 08 14:27:39 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioDataLine.java	Wed Oct 08 15:27:58 2008 -0400
@@ -95,11 +95,31 @@ public abstract class PulseAudioDataLine
 
 		for (AudioFormat myFormat : supportedFormats) {
 			if (format.matches(myFormat)) {
+				/*
+				 * A few issues with format:
+				 * 
+				 * To match: SAME encoding: safe because its a java enum. SAME
+				 * number of channels: safe because myFormat has specific
+				 * values. SAME bits per sample (aka sampleSize) and bytes per
+				 * frame (aka frameSize): safe because myFormat has specific
+				 * values. SAME sample rate: _not_ safe because myFormat uses
+				 * AudioSystem.NOT_SPECIFIED. SAME frame rate: safe because we
+				 * _ignore_ it completely ;)
+				 * 
+				 * 
+				 */
+
+				float sampleRate = format.getSampleRate();
+				if (sampleRate == (float) AudioSystem.NOT_SPECIFIED) {
+					/* pick a random sample rate */
+					sampleRate = 44100.0f;
+				}
+
 				synchronized (eventLoop.threadLock) {
 					stream = new Stream(eventLoop.getContextPointer(),
 							streamName, Stream.Format.valueOf((String) myFormat
 									.getProperty(PULSEAUDIO_FORMAT_KEY)),
-							(int) format.getSampleRate(), format.getChannels());
+							(int) sampleRate, myFormat.getChannels());
 
 				}
 				currentFormat = format;
@@ -372,7 +392,9 @@ public abstract class PulseAudioDataLine
 	 * underrun/overflow.
 	 * 
 	 * 
-	 * HOWEVER, the javadocs say the opposite thing!
+	 * HOWEVER, the javadocs say the opposite thing! (need help from the jck =
+	 * official spec)
+	 * 
 	 * 
 	 */
 
diff -r 4260a476a101 -r 66bcf656c0fb src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java
--- a/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Oct 08 14:27:39 2008 -0400
+++ b/src/java/org/classpath/icedtea/pulseaudio/PulseAudioMixer.java	Wed Oct 08 15:27:58 2008 -0400
@@ -103,6 +103,8 @@ public class PulseAudioMixer implements 
 				formats, StreamBufferAttributes.MIN_VALUE,
 				StreamBufferAttributes.MAX_VALUE));
 
+		refreshSourceAndTargetLines();
+
 	}
 
 	synchronized public static PulseAudioMixer getInstance() {
@@ -119,12 +121,21 @@ public class PulseAudioMixer implements 
 		Map<String, Object> properties;
 
 		/*
-		 * frameSize = sample size (in bytes, not bits) x # of channels ^ From
-		 * PulseAudio's sources
+		 * frameSize = sample size (in bytes, not bits) x # of channels
+		 * 
+		 * From PulseAudio's sources
 		 * http://git.0pointer.de/?p=pulseaudio.git;a=blob;f=src/pulse/sample.c;h=93da2465f4301e27af4976e82737c3a048124a68;hb=82ea8dde8abc51165a781c69bc3b38034d62d969#l63
 		 */
 
-		int[] channelSizes = new int[] { 1, 2, 5, 6, 8 };
+		/*
+		 * technically, PulseAudio supports up to 16 channels, but things get
+		 * interesting with channel maps
+		 * 
+		 * PA_CHANNEL_MAP_DEFAULT (=PA_CHANNEL_MAP_AIFF) supports 1,2,3,4,5 or 6
+		 * channels only
+		 * 
+		 */
+		int[] channelSizes = new int[] { 1, 2, 3, 4, 5, 6 };
 		for (int channelSize : channelSizes) {
 			properties = new HashMap<String, Object>();
 			properties.put(PULSEAUDIO_FORMAT_KEY, "PA_SAMPLE_U8");
@@ -252,15 +263,14 @@ public class PulseAudioMixer implements 
 	}
 
 	@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;
@@ -324,7 +334,7 @@ public class PulseAudioMixer implements 
 		if (isLineSupported(info)) {
 			return AudioSystem.NOT_SPECIFIED;
 		}
-		
+
 		return 0;
 	}
 
diff -r 4260a476a101 -r 66bcf656c0fb unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Wed Oct 08 14:27:39 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioMixerTest.java	Wed Oct 08 15:27:58 2008 -0400
@@ -39,6 +39,7 @@ package org.classpath.icedtea.pulseaudio
 
 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 @@ public class PulseAudioMixerTest {
 
 	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 {
@@ -289,7 +292,6 @@ public class PulseAudioMixerTest {
 			try {
 				Line sourceLine = selectedMixer.getLine(lineInfo);
 				sourceLine.open();
-				System.out.println("closing line");
 				sourceLine.close();
 			} catch (IllegalArgumentException e) {
 				// ignore this
@@ -308,15 +310,12 @@ public class PulseAudioMixerTest {
 				TargetDataLine targetLine = (TargetDataLine) selectedMixer
 						.getLine(lineInfo);
 				Assert.assertNotNull(targetLine);
-				System.out.println("opening line");
 				targetLine.open(aSupportedFormat);
-				System.out.println("closing line");
 				targetLine.close();
 			} catch (ClassCastException cce) {
 				Port targetLine = (Port) selectedMixer.getLine(lineInfo);
 				Assert.assertNotNull(targetLine);
 				targetLine.open();
-				System.out.println("closing line");
 				targetLine.close();
 			}
 
@@ -367,6 +366,19 @@ public class PulseAudioMixerTest {
 	}
 
 	@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();
diff -r 4260a476a101 -r 66bcf656c0fb unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java
--- a/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java	Wed Oct 08 14:27:39 2008 -0400
+++ b/unittests/org/classpath/icedtea/pulseaudio/PulseAudioSourceDataLineTest.java	Wed Oct 08 15:27:58 2008 -0400
@@ -36,8 +36,6 @@ exception statement from your version.
  */
 
 package org.classpath.icedtea.pulseaudio;
-
-import static org.junit.Assert.assertNotNull;
 
 import java.io.File;
 import java.io.IOException;
@@ -138,9 +136,9 @@ public class PulseAudioSourceDataLineTes
 				selectedMixerInfo = info;
 			}
 		}
-		assertNotNull(selectedMixerInfo);
+		Assert.assertNotNull(selectedMixerInfo);
 		mixer = AudioSystem.getMixer(selectedMixerInfo);
-		assertNotNull(mixer);
+		Assert.assertNotNull(mixer);
 		if (mixer.isOpen()) {
 			mixer.close();
 		}
@@ -1029,10 +1027,20 @@ public class PulseAudioSourceDataLineTes
 
 	@Test
 	public void testHasADefaultFormat() throws LineUnavailableException {
+		System.out.println("This test checks that a SourceDataLine has "
+				+ " a default format, and it can be opened with"
+				+ " that format");
+
 		sourceDataLine = (SourceDataLine) mixer.getLine(new Line.Info(
 				SourceDataLine.class));
+
+		/* check that there is a default format */
 		Assert.assertNotNull(sourceDataLine.getFormat());
 		System.out.println(sourceDataLine.getFormat());
+
+		/* check that the line can be opened with the default format */
+		sourceDataLine.open();
+		sourceDataLine.close();
 
 	}
 



More information about the distro-pkg-dev mailing list