summaryrefslogtreecommitdiff
path: root/gnu/javax
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2007-07-09 16:32:20 +0000
committerMario Torre <neugens@limasoftware.net>2007-07-09 16:32:20 +0000
commit9afb84648bf4fc9cfa9dd2ee4dd5937a71338e4d (patch)
tree82b0e55156d12b1b8e5d816975ac3687b9967d02 /gnu/javax
parentde78d5b68527b0c5028826b5a4e98790be2b6fd9 (diff)
downloadclasspath-9afb84648bf4fc9cfa9dd2ee4dd5937a71338e4d.tar.gz
2007-07-08 Mario Torre <neugens@limasoftware.net>
* gnu/javax/sound/sampled/gstreamer: new package hierarchy. * gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java: new file. * gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java: likewise. * gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java: likewise. * gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java: likewise. * gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java: likewise. * gnu/javax/sound/AudioSecurityManager.java: likewise. * gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java: likewise. * gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java: likewise. * gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java: likewise. * gnu/javax/sound/sampled/gstreamer/io/GstAudioFileWriter.java: likewise. * resource/META-INF/services/javax.sound.sampled.spi.AudioFileReader.in: likewise. * resource/META-INF/services/javax.sound.sampled.spi.MixerProvider.in: likewise. * resource/META-INF/services/javax.sound.sampled.spi.MixerProvider: likewise. * native/jni/gstreamer-peer/gstclasspathsrc.c: likewise. * native/jni/gstreamer-peer/gstclasspathsrc.h: likewise. * native/jni/gstreamer-peer/gstinputstream.c: likewise. * native/jni/gstreamer-peer/gstinputstream.h: likewise. * native/jni/gstreamer-peer/GStreamerIOPeer.c: likewise. * native/jni/gstreamer-peer/Makefile.am: likewise. * native/jni/gstreamer-peer/.cvsignore: likewise. * include/gnu_javax_sound_sampled_gstreamer_io_GstAudioFileReaderNativePeer.h: likewise. * include/Makefile.am: add gstreamer generated headers. * configure.ac: add gstreamer sound backend configuration. The backend is currently disabled by default. * native/jni/Makefile.am: code to allow compilation of the gstreamer sound backend. * javax/sound/sampled/spi/MixerProvider.java (isMixerSupported): indentation fixes. * javax/sound/sampled/AudioFormat.java (toString): fix method to display informations only when available. * javax/sound/sampled/DataLine.java: (Info.isFormatSupported): indentation fixes. (Info): indentation fixes. (Info.toString): indentation fixes. (Info.matches): indentation fixes.
Diffstat (limited to 'gnu/javax')
-rw-r--r--gnu/javax/sound/AudioSecurityManager.java41
-rw-r--r--gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java270
-rw-r--r--gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java71
-rw-r--r--gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java139
-rw-r--r--gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java276
-rw-r--r--gnu/javax/sound/sampled/gstreamer/io/GstAudioFileWriter.java80
-rw-r--r--gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java145
-rw-r--r--gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java48
-rw-r--r--gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java57
-rw-r--r--gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java134
10 files changed, 1261 insertions, 0 deletions
diff --git a/gnu/javax/sound/AudioSecurityManager.java b/gnu/javax/sound/AudioSecurityManager.java
new file mode 100644
index 000000000..cd10e5106
--- /dev/null
+++ b/gnu/javax/sound/AudioSecurityManager.java
@@ -0,0 +1,41 @@
+package gnu.javax.sound;
+
+import javax.sound.sampled.AudioPermission;
+
+public class AudioSecurityManager
+{
+ public static enum Permission
+ {
+ PLAY, RECORD, ALL
+ }
+
+ public static final void checkPermissions()
+ {
+ checkPermissions(Permission.ALL);
+ }
+
+ public static final void checkPermissions(Permission permission)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ {
+ String perm = null;
+ switch (permission)
+ {
+ case PLAY:
+ perm = "play";
+ break;
+
+ case RECORD:
+ perm = "record";
+ break;
+
+ case ALL: default:
+ perm = "*";
+ break;
+ }
+
+ sm.checkPermission(new AudioPermission(perm));
+ }
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java b/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java
new file mode 100644
index 000000000..b32db0f35
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/GStreamerMixer.java
@@ -0,0 +1,270 @@
+/* GStreamerMixer.java -- Mixer implementation.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer;
+
+import java.awt.AWTPermission;
+
+import gnu.javax.sound.sampled.gstreamer.lines.GstSourceDataLine;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioPermission;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.Control;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.Line;
+import javax.sound.sampled.LineListener;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Mixer;
+import javax.sound.sampled.SourceDataLine;
+import javax.sound.sampled.Control.Type;
+import javax.sound.sampled.Line.Info;
+
+/**
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class GStreamerMixer
+ implements Mixer
+{
+ public static class GstInfo extends Info
+ {
+ /* Mixer Properties */
+
+ /** Name */
+ private static final String name = "Classpath GStreamer Sound Audio Engine";
+
+ /** Vendor */
+ private static final String vendor = "GNU Classpath";
+
+ /** Description */
+ private static final String desc = "GStreamer-based software mixer";
+
+ /** Version */
+ private static final String vers = "0.0.1";
+
+ protected GstInfo()
+ {
+ super(name, vendor, desc, vers);
+ }
+ }
+
+ public static final String GST_BACKEND = GstInfo.name;
+ public static final String GST_DECODER = "decoder";
+
+ private static AudioFormat[] BASIC_FORMATS =
+ {
+ new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ true),
+
+ new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ AudioSystem.NOT_SPECIFIED,
+ false),
+ };
+
+ /** Mixer Info */
+ private static final Mixer.Info INFO = new GStreamerMixer.GstInfo();
+
+ public Line getLine(Line.Info info)
+ throws LineUnavailableException
+ {
+ // get all the lines formats supported by this mixer and
+ // and see if there is one matching the given line
+ // if the format comes from the gstreamer backend
+ // gstreamer will be able to deal with it
+ Class clazz = info.getLineClass();
+ DataLine.Info _info = (DataLine.Info) info;
+
+ if (clazz == SourceDataLine.class)
+ {
+ for (AudioFormat format : _info.getFormats())
+ {
+ // see if we are a gstreamer child :)
+ if (format.properties().containsKey(GST_BACKEND));
+ {
+ // we got it
+ return new GstSourceDataLine(format);
+ }
+ }
+ }
+
+ // TODO: we also support basic PCM
+
+ throw new LineUnavailableException("Cannot open a line");
+ }
+
+ public int getMaxLines(Line.Info info)
+ {
+ // TODO
+ return 1;
+ }
+
+ public Info getMixerInfo()
+ {
+ return INFO;
+ }
+
+ public javax.sound.sampled.Line.Info[] getSourceLineInfo()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Line.Info[] getSourceLineInfo(Line.Info info)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Line[] getSourceLines()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public javax.sound.sampled.Line.Info[] getTargetLineInfo()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Line.Info[] getTargetLineInfo(Line.Info info)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Line[] getTargetLines()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isLineSupported(Line.Info info)
+ {
+ // We support any kind of mixer that comes
+ // from our gstreamer backend.
+ // In addition, we support PCM based audio streams for
+ // direct playback.
+ if (info instanceof DataLine.Info)
+ {
+ DataLine.Info _dinfo = (DataLine.Info) info;
+ _dinfo.getFormats();
+ }
+
+ return true;
+ }
+
+ public boolean isSynchronizationSupported(Line[] lines, boolean sync)
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void synchronize(Line[] lines, boolean sync)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void unsynchronize(Line[] lines)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void addLineListener(LineListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void close()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Control getControl(Type what)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Control[] getControls()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public javax.sound.sampled.Line.Info getLineInfo()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isControlSupported(Type what)
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isOpen()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void open() throws LineUnavailableException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeLineListener(LineListener listener)
+ {
+ // TODO Auto-generated method stub
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java b/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java
new file mode 100644
index 000000000..61a8940e2
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/GStreamerMixerProvider.java
@@ -0,0 +1,71 @@
+/*GStreamerMixerProvider -- GNU Classpath GStreamer Mixer provider.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer;
+
+import javax.sound.sampled.Mixer;
+import javax.sound.sampled.Mixer.Info;
+import javax.sound.sampled.spi.MixerProvider;
+
+/**
+ * Concrete provider class for GStreamerMixer.
+ *
+ * @author Mario Torre
+ */
+public class GStreamerMixerProvider
+ extends MixerProvider
+{
+ private static final GStreamerMixer mixer = new GStreamerMixer();
+
+ @Override
+ public Mixer getMixer(Info info)
+ {
+ if (info.equals(mixer.getMixerInfo()))
+ return mixer;
+
+ throw new
+ IllegalArgumentException("This provider cannot handle a mixer or type: "
+ + info.getName());
+ }
+
+ @Override
+ public Info[] getMixerInfo()
+ {
+ Info[] info = { mixer.getMixerInfo() };
+ return info;
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java b/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java
new file mode 100644
index 000000000..53b2155d8
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReader.java
@@ -0,0 +1,139 @@
+/*GstAudioFileReader -- GNU Classpath GStreamer AudioFileReader.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer.io;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.sound.sampled.AudioFileFormat;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.UnsupportedAudioFileException;
+import javax.sound.sampled.spi.AudioFileReader;
+
+/**
+ * An implementation of a general AudioFileReader. Uses GStreamer to
+ * parse and retrieve informations about the file passed as input.
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class GstAudioFileReader
+ extends AudioFileReader
+{
+ @Override
+ public AudioFileFormat getAudioFileFormat(File file)
+ throws UnsupportedAudioFileException, IOException
+ {
+ throw new UnsupportedAudioFileException("Unsupported encoding.");
+ }
+
+ @Override
+ public AudioFileFormat getAudioFileFormat(InputStream is)
+ throws UnsupportedAudioFileException, IOException
+ {
+ throw new UnsupportedAudioFileException("Unsupported encoding.");
+ }
+
+ @Override
+ public AudioFileFormat getAudioFileFormat(URL url)
+ throws UnsupportedAudioFileException, IOException
+ {
+ return getAudioFileFormat(new BufferedInputStream(url.openStream()));
+ }
+
+ @Override
+ public AudioInputStream getAudioInputStream(File file)
+ throws UnsupportedAudioFileException, IOException
+ {
+ InputStream stream = new FileInputStream(file);
+ long length = file.length();
+
+ AudioFormat format = null;
+
+ try
+ {
+ format = GstAudioFileReaderNativePeer.getAudioFormat(file);
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // get the header size
+ if (format == null)
+ throw new UnsupportedAudioFileException("Unsupported encoding.");
+
+ return new AudioInputStream(stream, format, length);
+ }
+
+ @Override
+ public AudioInputStream getAudioInputStream(InputStream is)
+ throws UnsupportedAudioFileException, IOException
+ {
+ AudioFormat format = null;
+
+ try
+ {
+ format = GstAudioFileReaderNativePeer.getAudioFormat(is);
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ // get the header size
+ if (format == null)
+ throw new UnsupportedAudioFileException("Unsupported encoding.");
+
+ return new AudioInputStream(is, format, AudioSystem.NOT_SPECIFIED);
+ }
+
+ @Override
+ public AudioInputStream getAudioInputStream(URL url)
+ throws UnsupportedAudioFileException, IOException
+ {
+ return getAudioInputStream(new BufferedInputStream(url.openStream()));
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java b/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java
new file mode 100644
index 000000000..45ae4ff85
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileReaderNativePeer.java
@@ -0,0 +1,276 @@
+/*GstAudioFileReaderNativePeer -- GNU Classpath GStreamer AudioFileReader
+ native peer class.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer.io;
+
+import gnu.javax.sound.sampled.gstreamer.GStreamerMixer;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.AudioFormat.Encoding;
+
+/**
+ * GStreamer native peer for GstAudioFileReader.
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+final class GstAudioFileReaderNativePeer
+{
+ private static final String GST_ENCODING = "GStreamer Generic Audio Reader";
+
+ private static class GstHeader
+ {
+ /*
+ * NOTE: these properties are accessed by the native code, be careful
+ * if you change them.
+ * Not all the fields are necessarily set.
+ *
+ */
+ public String file = null;
+
+ public String suffix = null;
+
+ public String name = null;
+
+ public String mimetype = null;
+
+ public String endianness = null;
+
+ public String channels = null;
+
+ public String rate = null;
+
+ public String width = null;
+
+ public String depth = null;
+
+ public String isSigned = null;
+
+ public String layer = null;
+ public String bitrate = null;
+ public String framed = null;
+ public String type = null;
+ }
+
+ public static AudioFormat getAudioFormat(File file) throws Exception
+ {
+ GstHeader header = new GstHeader();
+ header.file = file.getAbsolutePath();
+
+ if (!gstreamer_get_audio_format_file(header))
+ return null;
+
+ return getAudioFormat(header);
+ }
+
+ public static AudioFormat getAudioFormat(InputStream is) throws Exception
+ {
+ GstHeader header = new GstHeader();
+
+ BufferedInputStream stream = new BufferedInputStream(is);
+ if(!stream.markSupported())
+ throw new IOException("Stream must support marking.");
+
+ stream.mark(0);
+
+ if (!gstreamer_get_audio_format_stream(header, stream))
+ return null;
+
+ return getAudioFormat(header);
+ }
+
+ public static AudioFormat getAudioFormat(URL url) throws Exception
+ {
+ GstHeader header = new GstHeader();
+ header.file = url.toExternalForm();
+
+ BufferedInputStream stream = new BufferedInputStream(url.openStream());
+ if(!stream.markSupported())
+ throw new IOException("Stream must support marking.");
+
+ stream.mark(0);
+
+ if (!gstreamer_get_audio_format_stream(header, stream))
+ return null;
+
+ return getAudioFormat(header);
+ }
+
+ private static Encoding getEncoding(GstHeader header)
+ {
+ StringBuilder buffer = new StringBuilder();
+
+ if (header.name == null)
+ {
+ buffer.append(GST_ENCODING);
+ if (header.mimetype != null)
+ {
+ buffer.append(" ");
+ buffer.append(header.mimetype);
+ }
+
+ header.name = buffer.toString();
+ }
+ else
+ {
+ // strip the "decoder" word from the name, if any
+ // this is a bit ugly, the alternative would be to still output the
+ // full name of the decoder/demuxer
+ String lowerCase = header.name.toLowerCase();
+ int index = lowerCase.indexOf("decoder");
+ if (index == -1)
+ {
+ index = lowerCase.indexOf("demuxer");
+ }
+
+ if (index == -1)
+ index = lowerCase.length();
+
+ buffer.append(header.name.substring(0, index));
+
+ }
+
+ return new Encoding(buffer.toString().trim());
+ }
+
+ private static AudioFormat getAudioFormat(GstHeader header)
+ throws Exception
+ {
+ int na = AudioSystem.NOT_SPECIFIED;
+
+ /* we use mimetype as an header, but this could have some side effects */
+ Encoding encoding = getEncoding(header);
+
+ float sampleRate = ((header.rate != null) ?
+ new Float(header.rate).floatValue() : na);
+
+ int sampleSizeInBits = ((header.depth != null) ?
+ new Integer(header.depth).intValue() : na);
+
+ int channels = ((header.channels != null) ?
+ new Integer(header.channels).intValue() : na);
+
+ boolean bigEndian = false;
+ if (header.endianness != null)
+ {
+ if (header.endianness.compareTo("4321") == 0)
+ bigEndian = true;
+ }
+
+ int frameSize = na;
+ float frameRate = na;
+ String lowerCase = header.name.toLowerCase();
+
+ // FIXME: frameRate = sampleRate in these cases under all the tests so far
+ // but I'm not sure if this is always correct...
+ if (lowerCase.contains("law") || lowerCase.contains("au") ||
+ lowerCase.contains("x-au"))
+ {
+ frameSize = (sampleSizeInBits >> 3) * channels;
+ frameRate = sampleRate;
+ }
+ else if (lowerCase.contains("wav"))
+ {
+ frameSize = ((sampleSizeInBits + 7) / 8) * channels;
+ frameRate = sampleRate;
+ }
+ else if (lowerCase.contains("iff"))
+ {
+ frameSize = (sampleSizeInBits * channels) / 8;
+ frameRate = sampleRate;
+ }
+
+ // write all the additional properties we got to identify
+ // the gstreamer plugin actually used to deal with this stream
+ Map<String, Object> properties = new HashMap<String, Object>();
+ properties.put(GStreamerMixer.GST_BACKEND, true);
+ properties.put(GStreamerMixer.GST_DECODER, header.name);
+
+ /* now we put in some of the additional properties if we have them */
+ if (header.type != null) properties.put("type", header.type);
+ if (header.framed != null) properties.put("framed", header.framed);
+ if (header.bitrate != null) properties.put("bitrate", header.bitrate);
+ if (header.isSigned != null) properties.put("isSigned", header.isSigned);
+ if (header.depth != null) properties.put("depth", header.depth);
+ if (header.mimetype != null) properties.put("mimetype", header.mimetype);
+
+ AudioFormat format = new AudioFormat(encoding,
+ sampleRate,
+ sampleSizeInBits,
+ channels,
+ frameSize,
+ frameRate,
+ bigEndian,
+ properties);
+ return format;
+ }
+
+ /* ***** native methods ***** */
+
+ /**
+ * Retrieve header information about the file being played.
+ *
+ * @param info
+ * @return
+ */
+ native static final
+ protected boolean gstreamer_get_audio_format_stream(GstHeader info,
+ BufferedInputStream istream);
+
+ /**
+ * Retrieve header information about the file being played.
+ *
+ * @param info
+ * @return
+ */
+ native static final
+ protected boolean gstreamer_get_audio_format_file(GstHeader info);
+
+ static
+ {
+ System.loadLibrary("gstreamerpeer"); //$NON-NLS-1$
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileWriter.java b/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileWriter.java
new file mode 100644
index 000000000..9b395dca2
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/io/GstAudioFileWriter.java
@@ -0,0 +1,80 @@
+/*GstAudioFileWriter -- GNU Classpath GStreamer AudioFileReader.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+package gnu.javax.sound.sampled.gstreamer.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioFileFormat.Type;
+import javax.sound.sampled.spi.AudioFileWriter;
+
+public class GstAudioFileWriter
+ extends AudioFileWriter
+{
+ @Override
+ public Type[] getAudioFileTypes()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Type[] getAudioFileTypes(AudioInputStream ais)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int write(AudioInputStream ais, Type type, File out)
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public int write(AudioInputStream ais, Type type, OutputStream os)
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java b/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java
new file mode 100644
index 000000000..0467c9559
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/lines/GstDataLine.java
@@ -0,0 +1,145 @@
+/* GstDataLine.java -- Abstract DataLine.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer.lines;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.Control;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineListener;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.Control.Type;
+
+public abstract class GstDataLine
+ implements DataLine
+{
+ public static enum State
+ {
+ PLAY, PAUSE, STOP
+ }
+
+ public static final int DEFAULT_BUFFER_SIZE = 1024;
+
+ /** Represents the playing state of this Line. */
+ protected State state = State.STOP;
+
+ /** Represents if this Line is opened or not. */
+ protected Boolean open = false;
+
+ private AudioFormat format = null;
+ private int bufferSize = 0;
+
+ public GstDataLine(AudioFormat format)
+ {
+ this.format = format;
+ this.bufferSize = DEFAULT_BUFFER_SIZE;
+ }
+
+ public GstDataLine(AudioFormat format, int bufferSize)
+ {
+ this.format = format;
+ this.bufferSize = bufferSize;
+ }
+
+ public int getBufferSize()
+ {
+ return this.bufferSize;
+ }
+
+ public AudioFormat getFormat()
+ {
+ return this.format;
+ }
+
+ public float getLevel()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public boolean isRunning()
+ {
+ return (state == State.PLAY || state == State.PAUSE);
+ }
+
+ public void addLineListener(LineListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Control getControl(Type what)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Control[] getControls()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public javax.sound.sampled.Line.Info getLineInfo()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isControlSupported(Type what)
+ {
+ return false;
+ }
+
+ public boolean isOpen()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void open() throws LineUnavailableException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void removeLineListener(LineListener listener)
+ {
+ // TODO Auto-generated method stub
+
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java b/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java
new file mode 100644
index 000000000..2b41a1186
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/lines/GstNativeDataLine.java
@@ -0,0 +1,48 @@
+/* GstNativeDataLine.java -- SourceDataLine implementation.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer.lines;
+
+public class GstNativeDataLine
+{
+
+
+ static
+ {
+ System.loadLibrary("gstreamerpeer"); //$NON-NLS-1$
+ }
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java b/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java
new file mode 100644
index 000000000..d1460e509
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/lines/GstPipeline.java
@@ -0,0 +1,57 @@
+/* GstPipeline.java -- Represents a Gstreamer Pipeline.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+package gnu.javax.sound.sampled.gstreamer.lines;
+
+import gnu.classpath.Pointer;
+
+/**
+ *
+ * @author Mario Torre <neugens@limasoftware.net>
+ */
+public class GstPipeline
+{
+ /**
+ * This is the native GStreamer Pipeline.
+ *
+ * This field is used by the native code, so any change to it must be
+ * followed by similar changes in the native peer.
+ */
+ private Pointer pipeline;
+
+ native private void setState();
+
+}
diff --git a/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java b/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java
new file mode 100644
index 000000000..d1a0262e5
--- /dev/null
+++ b/gnu/javax/sound/sampled/gstreamer/lines/GstSourceDataLine.java
@@ -0,0 +1,134 @@
+/* GstSourceDataLine.java -- SourceDataLine implementation.
+ Copyright (C) 2007 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.sound.sampled.gstreamer.lines;
+
+import gnu.javax.sound.AudioSecurityManager;
+
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.SourceDataLine;
+
+import static gnu.javax.sound.AudioSecurityManager.Permission;
+
+public class GstSourceDataLine
+ extends GstDataLine implements SourceDataLine
+{
+ public GstSourceDataLine(AudioFormat format)
+ {
+ super(format);
+ }
+
+ public void open(AudioFormat fmt) throws LineUnavailableException
+ {
+ AudioSecurityManager.checkPermissions(Permission.PLAY);
+ throw new LineUnavailableException("Line unavailable");
+ }
+
+ public void open(AudioFormat fmt, int size) throws LineUnavailableException
+ {
+ AudioSecurityManager.checkPermissions(Permission.PLAY);
+ throw new LineUnavailableException("Line unavailable");
+ }
+
+ public int write(byte[] buf, int offset, int length)
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int available()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public void drain()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void flush()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public int getFramePosition()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getLongFramePosition()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getMicrosecondPosition()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public boolean isActive()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void start()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void stop()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void close()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}