Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/sound/sampled/Port.java
38918 views
/*1* Copyright (c) 1999, 2004, 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;262728/**29* Ports are simple lines for input or output of audio to or from audio devices.30* Common examples of ports that act as source lines (mixer inputs) include the microphone,31* line input, and CD-ROM drive. Ports that act as target lines (mixer outputs) include the32* speaker, headphone, and line output. You can access port using a <code>{@link Port.Info}</code>33* object.34*35* @author Kara Kytle36* @since 1.337*/38public interface Port extends Line {394041// INNER CLASSES424344/**45* The <code>Port.Info</code> class extends <code>{@link Line.Info}</code>46* with additional information specific to ports, including the port's name47* and whether it is a source or a target for its mixer.48* By definition, a port acts as either a source or a target to its mixer,49* but not both. (Audio input ports are sources; audio output ports are targets.)50* <p>51* To learn what ports are available, you can retrieve port info objects through the52* <code>{@link Mixer#getSourceLineInfo getSourceLineInfo}</code> and53* <code>{@link Mixer#getTargetLineInfo getTargetLineInfo}</code>54* methods of the <code>Mixer</code> interface. Instances of the55* <code>Port.Info</code> class may also be constructed and used to obtain56* lines matching the parameters specified in the <code>Port.Info</code> object.57*58* @author Kara Kytle59* @since 1.360*/61public static class Info extends Line.Info {626364// AUDIO PORT TYPE DEFINES656667// SOURCE PORTS6869/**70* A type of port that gets audio from a built-in microphone or a microphone jack.71*/72public static final Info MICROPHONE = new Info(Port.class,"MICROPHONE", true);7374/**75* A type of port that gets audio from a line-level audio input jack.76*/77public static final Info LINE_IN = new Info(Port.class,"LINE_IN", true);7879/**80* A type of port that gets audio from a CD-ROM drive.81*/82public static final Info COMPACT_DISC = new Info(Port.class,"COMPACT_DISC", true);838485// TARGET PORTS8687/**88* A type of port that sends audio to a built-in speaker or a speaker jack.89*/90public static final Info SPEAKER = new Info(Port.class,"SPEAKER", false);9192/**93* A type of port that sends audio to a headphone jack.94*/95public static final Info HEADPHONE = new Info(Port.class,"HEADPHONE", false);9697/**98* A type of port that sends audio to a line-level audio output jack.99*/100public static final Info LINE_OUT = new Info(Port.class,"LINE_OUT", false);101102103// FUTURE DIRECTIONS...104105// telephone106// DAT107// DVD108109110// INSTANCE VARIABLES111112private String name;113private boolean isSource;114115116// CONSTRUCTOR117118/**119* Constructs a port's info object from the information given.120* This constructor is typically used by an implementation121* of Java Sound to describe a supported line.122*123* @param lineClass the class of the port described by the info object.124* @param name the string that names the port125* @param isSource <code>true</code> if the port is a source port (such126* as a microphone), <code>false</code> if the port is a target port127* (such as a speaker).128*/129public Info(Class<?> lineClass, String name, boolean isSource) {130131super(lineClass);132this.name = name;133this.isSource = isSource;134}135136137// METHODS138139/**140* Obtains the name of the port.141* @return the string that names the port142*/143public String getName() {144return name;145}146147/**148* Indicates whether the port is a source or a target for its mixer.149* @return <code>true</code> if the port is a source port (such150* as a microphone), <code>false</code> if the port is a target port151* (such as a speaker).152*/153public boolean isSource() {154return isSource;155}156157/**158* Indicates whether this info object specified matches this one.159* To match, the match requirements of the superclass must be160* met and the types must be equal.161* @param info the info object for which the match is queried162*/163public boolean matches(Line.Info info) {164165if (! (super.matches(info)) ) {166return false;167}168169if (!(name.equals(((Info)info).getName())) ) {170return false;171}172173if (! (isSource == ((Info)info).isSource()) ) {174return false;175}176177return true;178}179180181/**182* Finalizes the equals method183*/184public final boolean equals(Object obj) {185return super.equals(obj);186}187188/**189* Finalizes the hashCode method190*/191public final int hashCode() {192return super.hashCode();193}194195196197/**198* Provides a <code>String</code> representation199* of the port.200* @return a string that describes the port201*/202public final String toString() {203return (name + ((isSource == true) ? " source" : " target") + " port");204}205206} // class Info207}208209210