Path: blob/master/src/java.desktop/share/classes/javax/sound/sampled/Port.java
41159 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.sound.sampled;2627/**28* Ports are simple lines for input or output of audio to or from audio devices.29* Common examples of ports that act as source lines (mixer inputs) include the30* microphone, line input, and CD-ROM drive. Ports that act as target lines31* (mixer outputs) include the speaker, headphone, and line output. You can32* access port using a {@link Port.Info} object.33*34* @author Kara Kytle35* @since 1.336*/37public interface Port extends Line {3839/**40* The {@code Port.Info} class extends {@code Line.Info} with additional41* information specific to ports, including the port's name and whether it42* is a source or a target for its mixer. By definition, a port acts as43* either a source or a target to its mixer, but not both. (Audio input44* ports are sources; audio output ports are targets.)45* <p>46* To learn what ports are available, you can retrieve port info objects47* through the {@link Mixer#getSourceLineInfo getSourceLineInfo} and48* {@link Mixer#getTargetLineInfo getTargetLineInfo} methods of the49* {@code Mixer} interface. Instances of the {@code Port.Info} class may50* also be constructed and used to obtain lines matching the parameters51* specified in the {@code Port.Info} object.52*53* @author Kara Kytle54* @since 1.355*/56class Info extends Line.Info {5758// AUDIO PORT TYPE DEFINES5960// SOURCE PORTS6162/**63* A type of port that gets audio from a built-in microphone or a64* microphone jack.65*/66public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true);6768/**69* A type of port that gets audio from a line-level audio input jack.70*/71public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true);7273/**74* A type of port that gets audio from a CD-ROM drive.75*/76public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true);7778// TARGET PORTS7980/**81* A type of port that sends audio to a built-in speaker or a speaker82* jack.83*/84public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false);8586/**87* A type of port that sends audio to a headphone jack.88*/89public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false);9091/**92* A type of port that sends audio to a line-level audio output jack.93*/94public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false);9596// FUTURE DIRECTIONS...9798// telephone99// DAT100// DVD101102/**103* The string that names the port.104*/105private final String name;106107/**108* Whether this port is source or not.109*/110private final boolean isSource;111112/**113* Constructs a port's info object from the information given. This114* constructor is typically used by an implementation of Java Sound to115* describe a supported line.116*117* @param lineClass the class of the port described by the info object118* @param name the string that names the port119* @param isSource {@code true} if the port is a source port (such as a120* microphone), {@code false} if the port is a target port (such121* as a speaker)122*/123public Info(Class<?> lineClass, String name, boolean isSource) {124125super(lineClass);126this.name = name;127this.isSource = isSource;128}129130/**131* Obtains the name of the port.132*133* @return the string that names the port134*/135public String getName() {136return name;137}138139/**140* Indicates whether the port is a source or a target for its mixer.141*142* @return {@code true} if the port is a source port (such as a143* microphone), {@code false} if the port is a target port (such144* as a speaker)145*/146public boolean isSource() {147return isSource;148}149150/**151* Indicates whether this info object specified matches this one. To152* match, the match requirements of the superclass must be met and the153* types must be equal.154*155* @param info the info object for which the match is queried156* @return {@code true} if the specified object matches this one,157* {@code false} otherwise158*/159@Override160public boolean matches(Line.Info info) {161162if (! (super.matches(info)) ) {163return false;164}165166if (!(name.equals(((Info)info).getName())) ) {167return false;168}169170if (! (isSource == ((Info)info).isSource()) ) {171return false;172}173174return true;175}176177/**178* Indicates whether the specified object is equal to this info object,179* returning {@code true} if the objects are the same.180*181* @param obj the reference object with which to compare182* @return {@code true} if the specified object is equal to this info183* object; {@code false} otherwise184*/185@Override186public final boolean equals(Object obj) {187return super.equals(obj);188}189190/**191* Returns a hash code value for this info object.192*193* @return a hash code value for this info object194*/195@Override196public final int hashCode() {197return super.hashCode();198}199200/**201* Returns a string representation of the info object.202*203* @return a string representation of the info object204*/205@Override206public final String toString() {207return String.format("%s %s port", getName(),208isSource() ? "source" : "target");209}210}211}212213214