jdk/test/javax/sound/sampled/Mixers/PhantomMixers.java
changeset 41905 e8e5df013c6e
equal deleted inserted replaced
41904:524d908e49ea 41905:e8e5df013c6e
       
     1 /*
       
     2  * Copyright (c) 2003, 2016, 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.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 import javax.sound.sampled.AudioSystem;
       
    25 import javax.sound.sampled.DataLine;
       
    26 import javax.sound.sampled.Line;
       
    27 import javax.sound.sampled.Mixer;
       
    28 import javax.sound.sampled.SourceDataLine;
       
    29 import javax.sound.sampled.TargetDataLine;
       
    30 
       
    31 /**
       
    32  * @test
       
    33  * @bug 4794104
       
    34  * @summary mixers are always present, independent of available soundcards
       
    35  * @run main/manual PhantomMixers
       
    36  */
       
    37 public class PhantomMixers {
       
    38 
       
    39     public static void main(String args[]) throws Exception {
       
    40         int SDLformats = 0;
       
    41         int TDLformats = 0;
       
    42         Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
       
    43         for(int i=0; i<mixerInfo.length; i++){
       
    44             Mixer.Info thisMixerInfo = mixerInfo[i];
       
    45             System.out.println("Mixer #"+i+": "
       
    46                                + thisMixerInfo.getName()
       
    47                                + ": " + thisMixerInfo.getDescription());
       
    48             Mixer mixer = AudioSystem.getMixer(thisMixerInfo);
       
    49             Line.Info[] srcLineInfo = mixer.getSourceLineInfo();
       
    50             Line.Info[] dstLineInfo = mixer.getTargetLineInfo();
       
    51             int count = srcLineInfo.length + dstLineInfo.length;
       
    52             System.out.print(" -> " + (srcLineInfo.length + dstLineInfo.length) + " line");
       
    53             switch (count) {
       
    54                 case 0: System.out.println("s"); break;
       
    55                 case 1: System.out.println(""); break;
       
    56                 default: System.out.println("s:"); break;
       
    57             }
       
    58             int l;
       
    59             for (l = 0; l < srcLineInfo.length; l++) {
       
    60                 System.out.println("    "+srcLineInfo[l].toString());
       
    61                 if (srcLineInfo[l].getLineClass() == SourceDataLine.class
       
    62                     && (srcLineInfo[l] instanceof DataLine.Info)) {
       
    63                     SDLformats += ((DataLine.Info) srcLineInfo[l]).getFormats().length;
       
    64                 }
       
    65             }
       
    66             for (l = 0; l < dstLineInfo.length; l++) {
       
    67                 System.out.println("    "+dstLineInfo[l].toString());
       
    68                 if (dstLineInfo[l].getLineClass() == TargetDataLine.class
       
    69                     && (dstLineInfo[l] instanceof DataLine.Info)) {
       
    70                     TDLformats += ((DataLine.Info) dstLineInfo[l]).getFormats().length;
       
    71                 }
       
    72             }
       
    73         }
       
    74         if (mixerInfo.length == 0) {
       
    75             System.out.println("[no mixers present]");
       
    76         }
       
    77         System.out.println(""+SDLformats+" total formats for SourceDataLines");
       
    78         System.out.println(""+TDLformats+" total formats for TargetDataLines");
       
    79         System.out.println("");
       
    80         System.out.println("If there are audio devices correctly installed on your");
       
    81         System.out.println("system, you should see at least one Mixer, and in total");
       
    82         System.out.println("at least each one SourceDataLine and TargetDataLine, both");
       
    83         System.out.println("providing at least one format.");
       
    84         System.out.println("");
       
    85         System.out.println("Now disable your soundcard and repeat the test.");
       
    86         System.out.println("The corresponding mixer(s) should not provide any formats");
       
    87         System.out.println("anymore. If you disable all available soundcards");
       
    88         System.out.println("on your computer, the number of formats above should be");
       
    89         System.out.println("0 for both line types (although mixers are allowed to exist).");
       
    90     }
       
    91 }