< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/PortMixerProvider.java

Print this page




  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import javax.sound.sampled.Mixer;
  29 import javax.sound.sampled.spi.MixerProvider;
  30 
  31 
  32 /**
  33  * Port provider.
  34  *
  35  * @author Florian Bomers
  36  */
  37 public final class PortMixerProvider extends MixerProvider {
  38 
  39     // STATIC VARIABLES
  40 
  41     /**
  42      * Set of info objects for all port input devices on the system.
  43      */
  44     private static PortMixerInfo[] infos;
  45 
  46     /**
  47      * Set of all port input devices on the system.
  48      */
  49     private static PortMixer[] devices;
  50 
  51 
  52     // STATIC
  53 
  54     static {
  55         // initialize
  56         Platform.initialize();
  57     }
  58 
  59 
  60     // CONSTRUCTOR
  61 
  62 
  63     /**
  64      * Required public no-arg constructor.
  65      */
  66     public PortMixerProvider() {
  67         synchronized (PortMixerProvider.class) {
  68             if (Platform.isPortsEnabled()) {
  69                 init();
  70             } else {
  71                 infos = new PortMixerInfo[0];
  72                 devices = new PortMixer[0];
  73             }
  74         }
  75     }
  76 
  77     private static void init() {
  78         // get the number of input devices
  79         int numDevices = nGetNumDevices();
  80 
  81         if (infos == null || infos.length != numDevices) {
  82             if (Printer.trace) Printer.trace("PortMixerProvider: init()");
  83             // initialize the arrays
  84             infos = new PortMixerInfo[numDevices];
  85             devices = new PortMixer[numDevices];
  86 
  87             // fill in the info objects now.
  88             // we'll fill in the device objects as they're requested.
  89             for (int i = 0; i < infos.length; i++) {
  90                 infos[i] = nNewPortMixerInfo(i);
  91             }
  92             if (Printer.trace) Printer.trace("PortMixerProvider: init(): found numDevices: " + numDevices);
  93         }
  94     }
  95 

  96     public Mixer.Info[] getMixerInfo() {
  97         synchronized (PortMixerProvider.class) {
  98             Mixer.Info[] localArray = new Mixer.Info[infos.length];
  99             System.arraycopy(infos, 0, localArray, 0, infos.length);
 100             return localArray;
 101         }
 102     }
 103 

 104     public Mixer getMixer(Mixer.Info info) {
 105         synchronized (PortMixerProvider.class) {
 106             for (int i = 0; i < infos.length; i++) {
 107                 if (infos[i].equals(info)) {
 108                     return getDevice(infos[i]);
 109                 }
 110             }
 111         }
 112         throw new IllegalArgumentException(
 113                 String.format("Mixer %s not supported by this provider", info));
 114     }
 115 
 116 
 117     private static Mixer getDevice(PortMixerInfo info) {
 118         int index = info.getIndex();
 119         if (devices[index] == null) {
 120             devices[index] = new PortMixer(info);
 121         }
 122         return devices[index];
 123     }
 124 
 125     // INNER CLASSES
 126 
 127 
 128     /**
 129      * Info class for PortMixers.  Adds an index value for
 130      * making native references to a particular device.
 131      * This constructor is called from native.
 132      */
 133     static final class PortMixerInfo extends Mixer.Info {
 134         private final int index;
 135 
 136         private PortMixerInfo(int index, String name, String vendor, String description, String version) {
 137             super("Port " + name, vendor, description, version);
 138             this.index = index;
 139         }
 140 
 141         int getIndex() {
 142             return index;
 143         }
 144 
 145     } // class PortMixerInfo
 146 
 147     // NATIVE METHODS
 148     private static native int nGetNumDevices();
 149     private static native PortMixerInfo nNewPortMixerInfo(int mixerIndex);
 150 }


  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import javax.sound.sampled.Mixer;
  29 import javax.sound.sampled.spi.MixerProvider;
  30 

  31 /**
  32  * Port provider.
  33  *
  34  * @author Florian Bomers
  35  */
  36 public final class PortMixerProvider extends MixerProvider {
  37 


  38     /**
  39      * Set of info objects for all port input devices on the system.
  40      */
  41     private static PortMixerInfo[] infos;
  42 
  43     /**
  44      * Set of all port input devices on the system.
  45      */
  46     private static PortMixer[] devices;
  47 



  48     static {
  49         // initialize
  50         Platform.initialize();
  51     }
  52 




  53     /**
  54      * Required public no-arg constructor.
  55      */
  56     public PortMixerProvider() {
  57         synchronized (PortMixerProvider.class) {
  58             if (Platform.isPortsEnabled()) {
  59                 init();
  60             } else {
  61                 infos = new PortMixerInfo[0];
  62                 devices = new PortMixer[0];
  63             }
  64         }
  65     }
  66 
  67     private static void init() {
  68         // get the number of input devices
  69         int numDevices = nGetNumDevices();
  70 
  71         if (infos == null || infos.length != numDevices) {
  72             if (Printer.trace) Printer.trace("PortMixerProvider: init()");
  73             // initialize the arrays
  74             infos = new PortMixerInfo[numDevices];
  75             devices = new PortMixer[numDevices];
  76 
  77             // fill in the info objects now.
  78             // we'll fill in the device objects as they're requested.
  79             for (int i = 0; i < infos.length; i++) {
  80                 infos[i] = nNewPortMixerInfo(i);
  81             }
  82             if (Printer.trace) Printer.trace("PortMixerProvider: init(): found numDevices: " + numDevices);
  83         }
  84     }
  85 
  86     @Override
  87     public Mixer.Info[] getMixerInfo() {
  88         synchronized (PortMixerProvider.class) {
  89             Mixer.Info[] localArray = new Mixer.Info[infos.length];
  90             System.arraycopy(infos, 0, localArray, 0, infos.length);
  91             return localArray;
  92         }
  93     }
  94 
  95     @Override
  96     public Mixer getMixer(Mixer.Info info) {
  97         synchronized (PortMixerProvider.class) {
  98             for (int i = 0; i < infos.length; i++) {
  99                 if (infos[i].equals(info)) {
 100                     return getDevice(infos[i]);
 101                 }
 102             }
 103         }
 104         throw new IllegalArgumentException(
 105                 String.format("Mixer %s not supported by this provider", info));
 106     }
 107 

 108     private static Mixer getDevice(PortMixerInfo info) {
 109         int index = info.getIndex();
 110         if (devices[index] == null) {
 111             devices[index] = new PortMixer(info);
 112         }
 113         return devices[index];
 114     }
 115 



 116     /**
 117      * Info class for PortMixers.  Adds an index value for
 118      * making native references to a particular device.
 119      * This constructor is called from native.
 120      */
 121     static final class PortMixerInfo extends Mixer.Info {
 122         private final int index;
 123 
 124         private PortMixerInfo(int index, String name, String vendor, String description, String version) {
 125             super("Port " + name, vendor, description, version);
 126             this.index = index;
 127         }
 128 
 129         int getIndex() {
 130             return index;
 131         }
 132 
 133     } // class PortMixerInfo
 134 

 135     private static native int nGetNumDevices();
 136     private static native PortMixerInfo nNewPortMixerInfo(int mixerIndex);
 137 }
< prev index next >