Source for gnu.javax.sound.sampled.gstreamer.GStreamerMixer

   1: /* GStreamerMixer.java -- Mixer implementation.
   2:  Copyright (C) 2007 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package gnu.javax.sound.sampled.gstreamer;
  39: 
  40: import java.awt.AWTPermission;
  41: 
  42: import gnu.javax.sound.sampled.gstreamer.lines.GstSourceDataLine;
  43: 
  44: import javax.sound.sampled.AudioFormat;
  45: import javax.sound.sampled.AudioPermission;
  46: import javax.sound.sampled.AudioSystem;
  47: import javax.sound.sampled.Control;
  48: import javax.sound.sampled.DataLine;
  49: import javax.sound.sampled.Line;
  50: import javax.sound.sampled.LineListener;
  51: import javax.sound.sampled.LineUnavailableException;
  52: import javax.sound.sampled.Mixer;
  53: import javax.sound.sampled.SourceDataLine;
  54: import javax.sound.sampled.Control.Type;
  55: import javax.sound.sampled.Line.Info;
  56: 
  57: /**
  58:  * @author Mario Torre <neugens@limasoftware.net>
  59:  */
  60: public class GStreamerMixer
  61:     implements Mixer
  62: {
  63:   public static class GstInfo extends Info
  64:   {
  65:     /* Mixer Properties */
  66:     
  67:     /** Name */
  68:     private static final String name = "Classpath GStreamer Sound Audio Engine";
  69:     
  70:     /** Vendor */
  71:     private static final String vendor = "GNU Classpath";
  72:     
  73:     /** Description */
  74:     private static final String desc = "GStreamer-based software mixer";
  75:     
  76:     /** Version */
  77:     private static final String vers = "0.0.1";
  78:     
  79:     protected GstInfo()
  80:     {
  81:       super(name, vendor, desc, vers);
  82:     }
  83:   }
  84:   
  85:   public static final String GST_BACKEND = GstInfo.name;
  86:   public static final String GST_DECODER = "decoder";
  87:   
  88:   private static AudioFormat[] BASIC_FORMATS =
  89:   {
  90:      new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
  91:                      AudioSystem.NOT_SPECIFIED,
  92:                      AudioSystem.NOT_SPECIFIED,
  93:                      AudioSystem.NOT_SPECIFIED,
  94:                      AudioSystem.NOT_SPECIFIED,
  95:                      AudioSystem.NOT_SPECIFIED,
  96:                      true),
  97: 
  98:      new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
  99:                      AudioSystem.NOT_SPECIFIED,
 100:                      AudioSystem.NOT_SPECIFIED,
 101:                      AudioSystem.NOT_SPECIFIED,
 102:                      AudioSystem.NOT_SPECIFIED,
 103:                      AudioSystem.NOT_SPECIFIED,
 104:                      false),
 105:   };
 106:   
 107:   /** Mixer Info */
 108:   private static final Mixer.Info INFO = new GStreamerMixer.GstInfo();
 109: 
 110:   public Line getLine(Line.Info info)
 111:       throws LineUnavailableException
 112:   {
 113:     // get all the lines formats supported by this mixer and
 114:     // and see if there is one matching the given line
 115:     // if the format comes from the gstreamer backend 
 116:     // gstreamer will be able to deal with it
 117:     Class clazz = info.getLineClass();
 118:     DataLine.Info _info = (DataLine.Info) info;
 119:     
 120:     if (clazz == SourceDataLine.class)
 121:       {
 122:         for (AudioFormat format : _info.getFormats())
 123:           {
 124:             // see if we are a gstreamer child :)
 125:             if (format.properties().containsKey(GST_BACKEND));
 126:               {
 127:                 // we got it
 128:                 return new GstSourceDataLine(format);
 129:               }
 130:           }
 131:       }
 132:    
 133:     // TODO: we also support basic PCM
 134:     
 135:     throw new LineUnavailableException("Cannot open a line");
 136:   }
 137: 
 138:   public int getMaxLines(Line.Info info)
 139:   {
 140:     // TODO
 141:     return 1;
 142:   }
 143: 
 144:   public Info getMixerInfo()
 145:   {
 146:     return INFO;
 147:   }
 148: 
 149:   public javax.sound.sampled.Line.Info[] getSourceLineInfo()
 150:   {
 151:     // TODO Auto-generated method stub
 152:     return null;
 153:   }
 154: 
 155:   public Line.Info[] getSourceLineInfo(Line.Info info)
 156:   {
 157:     // TODO Auto-generated method stub
 158:     return null;
 159:   }
 160: 
 161:   public Line[] getSourceLines()
 162:   {
 163:     // TODO Auto-generated method stub
 164:     return null;
 165:   }
 166: 
 167:   public javax.sound.sampled.Line.Info[] getTargetLineInfo()
 168:   {
 169:     // TODO Auto-generated method stub
 170:     return null;
 171:   }
 172: 
 173:   public Line.Info[] getTargetLineInfo(Line.Info info)
 174:   {
 175:     // TODO Auto-generated method stub
 176:     return null;
 177:   }
 178: 
 179:   public Line[] getTargetLines()
 180:   {
 181:     // TODO Auto-generated method stub
 182:     return null;
 183:   }
 184: 
 185:   public boolean isLineSupported(Line.Info info)
 186:   {
 187:     // We support any kind of mixer that comes 
 188:     // from our gstreamer backend.
 189:     // In addition, we support PCM based audio streams for
 190:     // direct playback.
 191:     if (info instanceof DataLine.Info)
 192:       {
 193:         DataLine.Info _dinfo = (DataLine.Info) info;
 194:         _dinfo.getFormats();
 195:       }
 196:     
 197:     return true;
 198:   }
 199: 
 200:   public boolean isSynchronizationSupported(Line[] lines, boolean sync)
 201:   {
 202:     // TODO Auto-generated method stub
 203:     return false;
 204:   }
 205: 
 206:   public void synchronize(Line[] lines, boolean sync)
 207:   {
 208:     // TODO Auto-generated method stub
 209: 
 210:   }
 211: 
 212:   public void unsynchronize(Line[] lines)
 213:   {
 214:     // TODO Auto-generated method stub
 215: 
 216:   }
 217: 
 218:   public void addLineListener(LineListener listener)
 219:   {
 220:     // TODO Auto-generated method stub
 221: 
 222:   }
 223: 
 224:   public void close()
 225:   {
 226:     // TODO Auto-generated method stub
 227: 
 228:   }
 229: 
 230:   public Control getControl(Type what)
 231:   {
 232:     // TODO Auto-generated method stub
 233:     return null;
 234:   }
 235: 
 236:   public Control[] getControls()
 237:   {
 238:     // TODO Auto-generated method stub
 239:     return null;
 240:   }
 241: 
 242:   public javax.sound.sampled.Line.Info getLineInfo()
 243:   {
 244:     // TODO Auto-generated method stub
 245:     return null;
 246:   }
 247: 
 248:   public boolean isControlSupported(Type what)
 249:   {
 250:     // TODO Auto-generated method stub
 251:     return false;
 252:   }
 253:  
 254:   public boolean isOpen()
 255:   {
 256:     // TODO Auto-generated method stub
 257:     return false;
 258:   }
 259: 
 260:   public void open() throws LineUnavailableException
 261:   {
 262:     // TODO Auto-generated method stub
 263: 
 264:   }
 265: 
 266:   public void removeLineListener(LineListener listener)
 267:   {
 268:     // TODO Auto-generated method stub
 269:   }
 270: }