jdk/src/java.desktop/share/classes/com/sun/media/sound/PortMixer.java
author serb
Thu, 18 Feb 2016 22:11:29 +0300
changeset 36454 d2853d1fc614
parent 32865 f9cb6e427f9e
child 40444 afabcfc2f3ef
permissions -rw-r--r--
8038139: AudioInputStream.getFrameLength() returns wrong value for floating-point WAV Reviewed-by: prr, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18215
diff changeset
     2
 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.media.sound;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.sound.sampled.Control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.sound.sampled.Line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.sound.sampled.LineUnavailableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.sound.sampled.Port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.sound.sampled.BooleanControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.sound.sampled.CompoundControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.sound.sampled.FloatControl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * A Mixer which only provides Ports.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Florian Bomers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
    44
final class PortMixer extends AbstractMixer {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // CONSTANTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private static final int SRC_UNKNOWN      = 0x01;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final int SRC_MICROPHONE   = 0x02;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final int SRC_LINE_IN      = 0x03;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private static final int SRC_COMPACT_DISC = 0x04;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final int SRC_MASK         = 0xFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final int DST_UNKNOWN      = 0x0100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private static final int DST_SPEAKER      = 0x0200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private static final int DST_HEADPHONE    = 0x0300;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private static final int DST_LINE_OUT     = 0x0400;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private static final int DST_MASK         = 0xFF00;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // INSTANCE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private Port.Info[] portInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // cache of instantiated ports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private PortMixerPort[] ports;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // instance ID of the native implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private long id = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // CONSTRUCTOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    PortMixer(PortMixerProvider.PortMixerInfo portMixerInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        // pass in Line.Info, mixer, controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        super(portMixerInfo,              // Mixer.Info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
              null,                       // Control[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
              null,                       // Line.Info[] sourceLineInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
              null);                      // Line.Info[] targetLineInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        if (Printer.trace) Printer.trace(">> PortMixer: constructor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        int srcLineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        int dstLineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                id = nOpen(getMixerIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    count = nGetPortCount(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    if (count < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        if (Printer.trace) Printer.trace("nGetPortCount() returned error code: " + count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            } catch (Exception e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            portInfos = new Port.Info[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                int type = nGetPortType(id, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                srcLineCount += ((type & SRC_MASK) != 0)?1:0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                dstLineCount += ((type & DST_MASK) != 0)?1:0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                portInfos[i] = getPortInfo(i, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            if (id != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                nClose(id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            id = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // fill sourceLineInfo and targetLineInfos with copies of the ones in portInfos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        sourceLineInfo = new Port.Info[srcLineCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        targetLineInfo = new Port.Info[dstLineCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        srcLineCount = 0; dstLineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            if (portInfos[i].isSource()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                sourceLineInfo[srcLineCount++] = portInfos[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                targetLineInfo[dstLineCount++] = portInfos[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (Printer.trace) Printer.trace("<< PortMixer: constructor completed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // ABSTRACT MIXER: ABSTRACT METHOD IMPLEMENTATIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public Line getLine(Line.Info info) throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        Line.Info fullInfo = getLineInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if ((fullInfo != null) && (fullInfo instanceof Port.Info)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            for (int i = 0; i < portInfos.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                if (fullInfo.equals(portInfos[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    return getPort(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        throw new IllegalArgumentException("Line unsupported: " + info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public int getMaxLines(Line.Info info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        Line.Info fullInfo = getLineInfo(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // if it's not supported at all, return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (fullInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (fullInfo instanceof Port.Info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            //return AudioSystem.NOT_SPECIFIED; // if several instances of PortMixerPort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    protected void implOpen() throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (Printer.trace) Printer.trace(">> PortMixer: implOpen (id="+id+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // open the mixer device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        id = nOpen(getMixerIndex());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (Printer.trace) Printer.trace("<< PortMixer: implOpen succeeded.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    protected void implClose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (Printer.trace) Printer.trace(">> PortMixer: implClose");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        // close the mixer device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        long thisID = id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        id = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        nClose(thisID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if (ports != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            for (int i = 0; i < ports.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (ports[i] != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    ports[i].disposeControls();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (Printer.trace) Printer.trace("<< PortMixer: implClose succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    protected void implStart() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    protected void implStop() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    // IMPLEMENTATION HELPERS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private Port.Info getPortInfo(int portIndex, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        case SRC_UNKNOWN:      return new PortInfo(nGetPortName(getID(), portIndex), true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        case SRC_MICROPHONE:   return Port.Info.MICROPHONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        case SRC_LINE_IN:      return Port.Info.LINE_IN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        case SRC_COMPACT_DISC: return Port.Info.COMPACT_DISC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        case DST_UNKNOWN:      return new PortInfo(nGetPortName(getID(), portIndex), false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        case DST_SPEAKER:      return Port.Info.SPEAKER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        case DST_HEADPHONE:    return Port.Info.HEADPHONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        case DST_LINE_OUT:     return Port.Info.LINE_OUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        // should never happen...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (Printer.debug) Printer.debug("unknown port type: "+type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    int getMixerIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return ((PortMixerProvider.PortMixerInfo) getMixerInfo()).getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    Port getPort(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (ports == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            ports = new PortMixerPort[portInfos.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (ports[index] == null) {
22584
eed64ee05369 8032733: Fix cast lint warnings in client libraries
darcy
parents: 18215
diff changeset
   215
            ports[index] = new PortMixerPort(portInfos[index], this, index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return ports[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // $$fb TODO: return (Port) (ports[index].clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return ports[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    long getID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    // INNER CLASSES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Private inner class representing a Port for the PortMixer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   231
    private static final class PortMixerPort extends AbstractLine
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   232
            implements Port {
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   233
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   234
        private final int portIndex;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        private long id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        // CONSTRUCTOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        private PortMixerPort(Port.Info info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                              PortMixer mixer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                              int portIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            super(info, mixer, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (Printer.trace) Printer.trace("PortMixerPort CONSTRUCTOR: info: " + info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            this.portIndex = portIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // ABSTRACT METHOD IMPLEMENTATIONS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        // ABSTRACT LINE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        void implOpen() throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (Printer.trace) Printer.trace(">> PortMixerPort: implOpen().");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            long newID = ((PortMixer) mixer).getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if ((id == 0) || (newID != id) || (controls.length == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                id = newID;
24548
9c007a986347 8042256: Fix raw and unchecked lint warnings in com.sun.media.sound
darcy
parents: 22584
diff changeset
   256
                Vector<Control> vector = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                synchronized (vector) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    nGetControls(id, portIndex, vector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    controls = new Control[vector.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                    for (int i = 0; i < controls.length; i++) {
24548
9c007a986347 8042256: Fix raw and unchecked lint warnings in com.sun.media.sound
darcy
parents: 22584
diff changeset
   261
                        controls[i] = vector.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                enableControls(controls, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (Printer.trace) Printer.trace("<< PortMixerPort: implOpen() succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        private void enableControls(Control[] controls, boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            for (int i = 0; i < controls.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                if (controls[i] instanceof BoolCtrl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    ((BoolCtrl) controls[i]).closed = !enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                else if (controls[i] instanceof FloatCtrl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    ((FloatCtrl) controls[i]).closed = !enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                else if (controls[i] instanceof CompoundControl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    enableControls(((CompoundControl) controls[i]).getMemberControls(), enable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        private void disposeControls() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            enableControls(controls, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            controls = new Control[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        void implClose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (Printer.trace) Printer.trace(">> PortMixerPort: implClose()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // get rid of controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            enableControls(controls, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (Printer.trace) Printer.trace("<< PortMixerPort: implClose() succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // METHOD OVERRIDES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        // this is very similar to open(AudioFormat, int) in AbstractDataLine...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        public void open() throws LineUnavailableException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            synchronized (mixer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                // if the line is not currently open, try to open it with this format and buffer size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                if (!isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    if (Printer.trace) Printer.trace("> PortMixerPort: open");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    // reserve mixer resources for this line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    mixer.open(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                        // open the line.  may throw LineUnavailableException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                        implOpen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        // if we succeeded, set the open state to true and send events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        setOpen(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    } catch (LineUnavailableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        // release mixer resources for this line and then throw the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        mixer.close(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    if (Printer.trace) Printer.trace("< PortMixerPort: open succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        // this is very similar to close() in AbstractDataLine...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        public void close() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            synchronized (mixer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                if (isOpen()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                    if (Printer.trace) Printer.trace("> PortMixerPort.close()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    // set the open state to false and send events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    setOpen(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    // close resources for this line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                    implClose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    // release mixer resources for this line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    mixer.close(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    if (Printer.trace) Printer.trace("< PortMixerPort.close() succeeded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    } // class PortMixerPort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Private inner class representing a BooleanControl for PortMixerPort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   347
    private static final class BoolCtrl extends BooleanControl {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        // the handle to the native control function
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   349
        private final long controlID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        private boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        private static BooleanControl.Type createType(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            if (name.equals("Mute")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                return BooleanControl.Type.MUTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            else if (name.equals("Select")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                // $$fb add as new static type?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                //return BooleanControl.Type.SELECT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return new BCT(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        private BoolCtrl(long controlID, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            this(controlID, createType(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        private BoolCtrl(long controlID, BooleanControl.Type typ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            super(typ, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            this.controlID = controlID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        public void setValue(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                nControlSetIntValue(controlID, value?1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        public boolean getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                // never use any cached values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                return (nControlGetIntValue(controlID)!=0)?true:false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            // ??
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
         * inner class for custom types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   391
        private static final class BCT extends BooleanControl.Type {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            private BCT(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * Private inner class representing a CompoundControl for PortMixerPort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   401
    private static final class CompCtrl extends CompoundControl {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        private CompCtrl(String name, Control[] controls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            super(new CCT(name), controls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * inner class for custom compound control types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   409
        private static final class CCT extends CompoundControl.Type {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            private CCT(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Private inner class representing a BooleanControl for PortMixerPort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   419
    private static final class FloatCtrl extends FloatControl {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        // the handle to the native control function
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   421
        private final long controlID;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        private boolean closed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        // predefined float control types. See also Ports.h
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
   425
        private static final FloatControl.Type[] FLOAT_CONTROL_TYPES = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            FloatControl.Type.BALANCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            FloatControl.Type.MASTER_GAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            FloatControl.Type.PAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            FloatControl.Type.VOLUME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        private FloatCtrl(long controlID, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                          float min, float max, float precision, String units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            this(controlID, new FCT(name), min, max, precision, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        private FloatCtrl(long controlID, int type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                          float min, float max, float precision, String units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            this(controlID, FLOAT_CONTROL_TYPES[type], min, max, precision, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        private FloatCtrl(long controlID, FloatControl.Type typ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                         float min, float max, float precision, String units) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            super(typ, min, max, precision, 1000, min, units);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            this.controlID = controlID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        public void setValue(float value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                nControlSetFloatValue(controlID, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        public float getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (!closed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                // never use any cached values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                return nControlGetFloatValue(controlID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            // ??
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return getMinimum();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
         * inner class for custom types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
         */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   467
        private static final class FCT extends FloatControl.Type {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            private FCT(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * Private inner class representing a port info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
18215
b2afd66ce6db 8006328: Improve robustness of sound classes
serb
parents: 5506
diff changeset
   477
    private static final class PortInfo extends Port.Info {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        private PortInfo(String name, boolean isSource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            super(Port.class, name, isSource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    // open the mixer with the given index. Returns a handle ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    private static native long nOpen(int mixerIndex) throws LineUnavailableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    private static native void nClose(long id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    // gets the number of ports for this mixer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    private static native int nGetPortCount(long id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    // gets the type of the port with this index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    private static native int nGetPortType(long id, int portIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    // gets the name of the port with this index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    private static native String nGetPortName(long id, int portIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    // fills the vector with the controls for this port
24548
9c007a986347 8042256: Fix raw and unchecked lint warnings in com.sun.media.sound
darcy
parents: 22584
diff changeset
   497
    @SuppressWarnings("rawtypes")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    private static native void nGetControls(long id, int portIndex, Vector vector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    // getters/setters for controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    private static native void nControlSetIntValue(long controlID, int value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    private static native int nControlGetIntValue(long controlID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    private static native void nControlSetFloatValue(long controlID, float value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    private static native float nControlGetFloatValue(long controlID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
}