< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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


  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 
 105     public Mixer getMixer(Mixer.Info info) {
 106         synchronized (PortMixerProvider.class) {












 107             for (int i = 0; i < infos.length; i++) {
 108                 if (infos[i].equals(info)) {
 109                     return getDevice(infos[i]);
 110                 }
 111             }
 112         }
 113         throw new IllegalArgumentException("Mixer " + info.toString()
 114                                            + " not supported by this provider.");
 115     }
 116 
 117 
 118     private static Mixer getDevice(PortMixerInfo info) {
 119         int index = info.getIndex();
 120         if (devices[index] == null) {
 121             devices[index] = new PortMixer(info);
 122         }
 123         return devices[index];
 124     }
 125 
 126     // INNER CLASSES
 127 
 128 
 129     /**
 130      * Info class for PortMixers.  Adds an index value for
 131      * making native references to a particular device.
 132      * This constructor is called from native.
 133      */
 134     static final class PortMixerInfo extends Mixer.Info {
   1 /*
   2  * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  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


  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 
 105     public Mixer getMixer(Mixer.Info info) {
 106         synchronized (PortMixerProvider.class) {
 107             // if the default device is asked, we provide the mixer
 108             // with SourceDataLine's
 109             if (info == null) {
 110                 for (int i = 0; i < infos.length; i++) {
 111                     Mixer mixer = getDevice(infos[i]);
 112                     if (mixer.getSourceLineInfo().length > 0) {
 113                         return mixer;
 114                     }
 115                 }
 116             }
 117             // otherwise get the first mixer that matches
 118             // the requested info object
 119             for (int i = 0; i < infos.length; i++) {
 120                 if (infos[i].equals(info)) {
 121                     return getDevice(infos[i]);
 122                 }
 123             }
 124         }
 125         throw new IllegalArgumentException(
 126                 String.format("Mixer %s not supported by this provider", info));
 127     }
 128 
 129 
 130     private static Mixer getDevice(PortMixerInfo info) {
 131         int index = info.getIndex();
 132         if (devices[index] == null) {
 133             devices[index] = new PortMixer(info);
 134         }
 135         return devices[index];
 136     }
 137 
 138     // INNER CLASSES
 139 
 140 
 141     /**
 142      * Info class for PortMixers.  Adds an index value for
 143      * making native references to a particular device.
 144      * This constructor is called from native.
 145      */
 146     static final class PortMixerInfo extends Mixer.Info {
< prev index next >