Mercurial > hg > pulseaudio
changeset 0:5aa75b5e325b
initial import
committer: Omair Majid <omajid@redhat.com>
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Wed, 16 Jul 2008 15:23:05 -0400 |
parents | |
children | c5141ea18f04 |
files | .classpath .project jar-build.jardesc manifest src/META-INF/services/javax.sound.sampled.spi.MixerProvider src/org/openjdk/sound/PulseMixer.java src/org/openjdk/sound/PulseMixerInfo.java src/org/openjdk/sound/PulseMixerProvider.java src/org/openjdk/sound/PulseSourceDataLine.java src/org/openjdk/sound/PulseTargetDataLine.java unittests/org/openjdk/sound/OtherSoundProvidersAvailableTest.java unittests/org/openjdk/sound/PulseProviderTest.java unittests/org/openjdk/sound/SoundApiTestSuite.java |
diffstat | 13 files changed, 789 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="src" path="unittests"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="output" path="bin"/> +</classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>pulse-java</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jar-build.jardesc Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<jardesc> + <jar path="/home/omajid/workspace/pulse-java.jar"/> + <options buildIfNeeded="true" compress="true" descriptionLocation="/pulse-java/jar-build.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="true" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/> + <storedRefactorings deprecationInfo="true" structuralOnly="false"/> + <selectedProjects/> + <manifest generateManifest="false" manifestLocation="/pulse-java/manifest" manifestVersion="1.0" reuseManifest="true" saveManifest="true" usesManifest="true"> + <sealing sealJar="true"> + <packagesToSeal/> + <packagesToUnSeal/> + </sealing> + </manifest> + <selectedElements exportClassFiles="true" exportJavaFiles="true" exportOutputFolder="false"> + <javaElement handleIdentifier="=pulse-java"/> + </selectedElements> +</jardesc>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/manifest Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Sealed: true +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/META-INF/services/javax.sound.sampled.spi.MixerProvider Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,3 @@ +# Providers of sound mixers + +org.openjdk.sound.PulseMixerProvider
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openjdk/sound/PulseMixer.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,210 @@ +package org.openjdk.sound; + +import java.util.ArrayList; +import java.util.List; + +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Control; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineListener; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.Control.Type; + +public class PulseMixer implements javax.sound.sampled.Mixer { + // singleton + + private static PulseMixer _instance = null; + + private boolean isOpen = false; + + private List<PulseSourceDataLine> _sourceLines = null; + private List<PulseTargetDataLine> _targetLines = null; + + private Line.Info _sourceDataLineInfo = new Line.Info(PulseSourceDataLine.class); + private Line.Info _targetDataLineInfo = new Line.Info(PulseTargetDataLine.class); + + private PulseMixer(){ + + } + + synchronized public static PulseMixer getInstance() { + if ( _instance == null) { + _instance = new PulseMixer(); + } + return _instance; + } + + @Override + public Line getLine(javax.sound.sampled.Line.Info info) + throws LineUnavailableException { + + if (!isOpen) { + throw new LineUnavailableException(); + } + + if ( info.matches(_sourceDataLineInfo)) { + PulseSourceDataLine sourceLine = new PulseSourceDataLine(); + _sourceLines.add(sourceLine); + return sourceLine; + } + + if (info.matches(_targetDataLineInfo)) { + PulseTargetDataLine targetLine = new PulseTargetDataLine(); + _targetLines.add(targetLine); + return targetLine; + } + + throw new IllegalArgumentException(); + } + + @Override + public int getMaxLines(javax.sound.sampled.Line.Info info) { + return AudioSystem.NOT_SPECIFIED; + } + + @Override + public Info getMixerInfo() { + return PulseMixerInfo.getInfo(); + } + + @Override + public javax.sound.sampled.Line.Info[] getSourceLineInfo() { + Line.Info[] info = { new Line.Info(PulseSourceDataLine.class), }; + return info; + } + + @Override + public javax.sound.sampled.Line.Info[] getSourceLineInfo( + javax.sound.sampled.Line.Info info) { + Line.Info sourceInfo = new Line.Info(PulseSourceDataLine.class); + if (info.matches(sourceInfo)){ + Line.Info[] sourceInfos = { sourceInfo, }; + return sourceInfos; + } else { + Line.Info[] sourceInfos = { }; + return sourceInfos; + + } + } + @Override + public Line[] getSourceLines() { + return (Line[]) _sourceLines.toArray(); + + } + + @Override + public javax.sound.sampled.Line.Info[] getTargetLineInfo() { + Line.Info[] info = { new Line.Info(PulseTargetDataLine.class), }; + return info; + } + + @Override + public javax.sound.sampled.Line.Info[] getTargetLineInfo( + javax.sound.sampled.Line.Info info) { + Line.Info sourceInfo = new Line.Info(PulseTargetDataLine.class); + if (info.matches(sourceInfo)){ + Line.Info[] sourceInfos = { sourceInfo, }; + return sourceInfos; + } else { + Line.Info[] sourceInfos = { }; + return sourceInfos; + } + } + + @Override + public Line[] getTargetLines() { + return (Line[]) _targetLines.toArray(); + } + + @Override + public boolean isLineSupported(javax.sound.sampled.Line.Info info) { + if ( _sourceDataLineInfo.matches(info)) { + return true; + } + return false; + } + + @Override + public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) { + // FIXME + return false; + } + + @Override + public void synchronize(Line[] lines, boolean maintainSync) { + //FIXME pulse audio supports this + throw new IllegalArgumentException(); + } + + @Override + public void unsynchronize(Line[] lines) { + // FIXME should be able to implement this + throw new IllegalArgumentException(); + + } + + @Override + public void addLineListener(LineListener listener) { + System.out.println("UNIMPLEMENTED METHOD: PulseMixer.addListener()"); + throw new UnsupportedOperationException("Unimplemented method"); + } + + @Override + public void close() { + isOpen = false; + } + + @Override + public Control getControl(Type control) { + return null; + } + + @Override + public Control[] getControls() { + return null; + } + + @Override + public javax.sound.sampled.Line.Info getLineInfo() { + System.out.println("DEBUG: PulseMixer.getLineInfo() called"); + return null; + } + + @Override + public boolean isControlSupported(Type control) { + // FIXME + return false; + } + + @Override + public boolean isOpen() { + return isOpen; + } + + @Override + public void open() throws LineUnavailableException { + openLocal(); + } + + + + public void openLocal() { + + _sourceLines = new ArrayList<PulseSourceDataLine>(); + _targetLines = new ArrayList<PulseTargetDataLine>(); + + + isOpen = true; + } + + public void openRemote(String url) { + isOpen = true; + } + + @Override + public void removeLineListener(LineListener listener) { + System.out.println("UNIMPLEMENTED"); + throw new UnsupportedOperationException("Unimplemented method"); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openjdk/sound/PulseMixerInfo.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,24 @@ +package org.openjdk.sound; + +import javax.sound.sampled.Mixer; + +public class PulseMixerInfo extends Mixer.Info{ + // singleton + + private static PulseMixerInfo _instance = null; + + protected PulseMixerInfo(String name, String vendor, String description, String version) { + super(name, vendor, description, version); + } + + // the "getInstance()" method + synchronized public static PulseMixerInfo getInfo() { + if ( _instance == null) { + _instance = new PulseMixerInfo("PulseAudioMixer", "openjdk", "the ear-candy mixer", "1.0"); + } + + return _instance; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openjdk/sound/PulseMixerProvider.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,28 @@ + +package org.openjdk.sound; + +import javax.sound.sampled.Mixer; +import javax.sound.sampled.Mixer.Info; + + +public class PulseMixerProvider extends javax.sound.sampled.spi.MixerProvider { + + + @Override + public Mixer getMixer(Info info) { + if (info.equals(PulseMixerInfo.getInfo())) { + return PulseMixer.getInstance(); + } else { + throw new IllegalArgumentException("Mixer type not supported"); + } + } + + @Override + public Info[] getMixerInfo() { + System.out.println("DEBUG: get mixer info called"); + Mixer.Info[] m = { PulseMixerInfo.getInfo()}; + return m; + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openjdk/sound/PulseSourceDataLine.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,163 @@ +package org.openjdk.sound; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.Control; +import javax.sound.sampled.LineListener; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.SourceDataLine; +import javax.sound.sampled.Control.Type; + +public class PulseSourceDataLine implements SourceDataLine{ + + @Override + public void open(AudioFormat format) throws LineUnavailableException { + // TODO Auto-generated method stub + + } + + @Override + public void open(AudioFormat format, int bufferSize) + throws LineUnavailableException { + // TODO Auto-generated method stub + + } + + @Override + public int write(byte[] b, int off, int len) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int available() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void drain() { + // TODO Auto-generated method stub + + } + + @Override + public void flush() { + // TODO Auto-generated method stub + + } + + @Override + public int getBufferSize() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public AudioFormat getFormat() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getFramePosition() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getLevel() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getLongFramePosition() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getMicrosecondPosition() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean isActive() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isRunning() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public void stop() { + // TODO Auto-generated method stub + + } + + @Override + public void addLineListener(LineListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public Control getControl(Type control) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Control[] getControls() { + // TODO Auto-generated method stub + return null; + } + + @Override + public javax.sound.sampled.Line.Info getLineInfo() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isControlSupported(Type control) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isOpen() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void open() throws LineUnavailableException { + // TODO Auto-generated method stub + + } + + @Override + public void removeLineListener(LineListener listener) { + // TODO Auto-generated method stub + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/org/openjdk/sound/PulseTargetDataLine.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,163 @@ +package org.openjdk.sound; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.Control; +import javax.sound.sampled.LineListener; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.TargetDataLine; +import javax.sound.sampled.Control.Type; + +public class PulseTargetDataLine implements TargetDataLine { + + @Override + public void open(AudioFormat format) throws LineUnavailableException { + // TODO Auto-generated method stub + + } + + @Override + public void open(AudioFormat format, int bufferSize) + throws LineUnavailableException { + // TODO Auto-generated method stub + + } + + @Override + public int read(byte[] b, int off, int len) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int available() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void drain() { + // TODO Auto-generated method stub + + } + + @Override + public void flush() { + // TODO Auto-generated method stub + + } + + @Override + public int getBufferSize() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public AudioFormat getFormat() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getFramePosition() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public float getLevel() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getLongFramePosition() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getMicrosecondPosition() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public boolean isActive() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isRunning() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void start() { + // TODO Auto-generated method stub + + } + + @Override + public void stop() { + // TODO Auto-generated method stub + + } + + @Override + public void addLineListener(LineListener listener) { + // TODO Auto-generated method stub + + } + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public Control getControl(Type control) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Control[] getControls() { + // TODO Auto-generated method stub + return null; + } + + @Override + public javax.sound.sampled.Line.Info getLineInfo() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isControlSupported(Type control) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isOpen() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void open() throws LineUnavailableException { + // TODO Auto-generated method stub + + } + + @Override + public void removeLineListener(LineListener listener) { + // TODO Auto-generated method stub + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unittests/org/openjdk/sound/OtherSoundProvidersAvailableTest.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,62 @@ +package org.openjdk.sound; + +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.Mixer; +import javax.sound.sampled.SourceDataLine; + +import junit.framework.TestCase; + + +public class OtherSoundProvidersAvailableTest extends TestCase{ + + + + public void testOtherSoundProvers() { + + Mixer.Info mixerInfos [] = AudioSystem.getMixerInfo(); + Mixer.Info selectedMixerInfo = null; + Mixer selectedMixer; + + int i = 0; + for ( Mixer.Info info: mixerInfos) { + System.out.println("Mixer Line " + i++ + ": " + info.getName() + " " + info.getDescription()); + if ( info.getName().contains("0,4")) { + selectedMixerInfo = info; + } + } + System.out.println(selectedMixerInfo.toString()); + System.out.println("getting information from selected mixer:"); + + // use 0,4 or the default + selectedMixer = AudioSystem.getMixer(selectedMixerInfo); + System.out.println(selectedMixer.toString()); + try { + Line.Info sourceDataLineInfo = null; + + selectedMixer.open(); // initialize the mixer + + Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo(); + int j = 0; + for ( Line.Info lineInfo : allLineInfo) { + System.out.println("Source Line " + j++ + ": " + lineInfo.getLineClass()); + if ( lineInfo.getLineClass().toString().contains("SourceDataLine")) { + sourceDataLineInfo = lineInfo; + } + } + + SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer.getLine(sourceDataLineInfo); + + sourceDataLine.open(); + //sourceDataLine.write('a', 0, 2); + sourceDataLine.close(); + + } catch ( LineUnavailableException e ) { + System.out.println("Line unavailable"); + } + + + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unittests/org/openjdk/sound/PulseProviderTest.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,67 @@ +package org.openjdk.sound; + +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.Mixer; +import javax.sound.sampled.SourceDataLine; + +import junit.framework.TestCase; + + +public class PulseProviderTest extends TestCase { + + + + + public void testPulseMixerProvider() { + + Mixer.Info mixerInfos [] = AudioSystem.getMixerInfo(); + Mixer.Info selectedMixerInfo = null; + Mixer selectedMixer; + + System.out.println("Updated!"); + + int i = 0; + for ( Mixer.Info info: mixerInfos) { + System.out.println("Mixer Line " + i++ + ": " + info.getName() + " " + info.getDescription()); + if ( info.getName().contains("PulseAudio")) { + selectedMixerInfo = info; + } + } + System.out.println(selectedMixerInfo.toString()); + System.out.println("getting information from selected mixer:"); + + // use 0,4 or the default + selectedMixer = AudioSystem.getMixer(selectedMixerInfo); + System.out.println(selectedMixer.toString()); + try { + Line.Info sourceDataLineInfo = null; + + selectedMixer.open(); // initialize the mixer + + Line.Info allLineInfo[] = selectedMixer.getSourceLineInfo(); + int j = 0; + for ( Line.Info lineInfo : allLineInfo) { + System.out.println("Source Line " + j++ + ": " + lineInfo.getLineClass()); + if ( lineInfo.getLineClass().toString().contains("SourceDataLine")) { + sourceDataLineInfo = lineInfo; + } + } + + SourceDataLine sourceDataLine = (SourceDataLine) selectedMixer.getLine(sourceDataLineInfo); + + sourceDataLine.open(); + //sourceDataLine.write('a', 0, 2); + sourceDataLine.close(); + + } catch ( LineUnavailableException e ) { + System.out.println("Line unavailable"); + } + + + + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/unittests/org/openjdk/sound/SoundApiTestSuite.java Wed Jul 16 15:23:05 2008 -0400 @@ -0,0 +1,25 @@ +package org.openjdk.sound; + +import junit.framework.TestSuite; + +public class SoundApiTestSuite extends TestSuite{ + + + + public static TestSuite suite() { + TestSuite suite = new TestSuite(); + + suite.addTestSuite(OtherSoundProvidersAvailableTest.class); + suite.addTestSuite(PulseProviderTest.class); + + // + // Add more tests here + // + + return suite; + + + } + + +}