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